Wittyshare  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WsUser.cpp
Go to the documentation of this file.
1 
2 #include "WsUser.h"
4 #include <fstream>
5 
6 
7 WsUser::WsUser(const string& strUid, const string& pass, const string& ip)
8  : m_uid(strUid),
9  m_pass(pass),
10  m_ip(ip)
11 {
12 }
13 
15 {
16  LOG(DEBUG) << "WsUser::~WsUser() : Deleting WsUser Object";
17  if (m_client != 0)
18  delete m_client;
19  m_client = 0;
20 }
21 
23 {
24  /* load the conf */
26  m_conf = prop;
27  /* Enable daemon */
28 #ifdef HAS_DAEMON
29  if (m_conf->get("global", "daemon", "false") == "true") {
30  /* Daemon enabled */
31  LOG(INFO) << "WsUser::load() : Using FsDaemon" << endl;
32  /* m_client will be a WsFsDaemonClient because we are using the daemon */
34  } else {
35 #endif //HAS_DAEMON
36  /* Tree enabled */
37  LOG(DEBUG) << "WsUser::load() : Using local FsTree" << endl;
38  /* m_client will be a WsFsTreeClient because we are using the daemon */
40 #ifdef HAS_DAEMON
41  }
42  LOG(DEBUG) << "WsUser::load() : Getting PropertiesConfig::Daemon property OK";
43 #endif //HAS_DAEMON
44  /* load */
46  return ErrorCode::Failure;
47  return ErrorCode::Success;
48 }
49 
51 {
52  return m_client->getAccessRoot();
53 }
54 
55 const string WsUser::getRootPath()
56 {
57  string s = m_client->getRootPath();
58  return s;
59 }
60 
61 const string& WsUser::getSurname() const
62 {
63  return m_client->getSurname();
64 }
65 
66 const string& WsUser::getFirstName() const
67 {
68  return m_client->getFirstName();
69 }
70 
71 const string& WsUser::getEmail() const
72 {
73  return m_client->getEmail();
74 }
75 
76 const string& WsUser::getUid() const
77 {
78  return m_uid;
79 }
80 
81 int WsUser::getPermissions(const string& p)
82 {
83  return m_client->getPermissions(cleanPath(p));
84 }
85 
86 const WsNodeProperties* WsUser::getProperties(const string& p)
87 {
88  return m_client->getProperties(cleanPath(p));
89 }
90 
91 string WsUser::getProperty(const string& path, const string& section, const string& attr, const string& def)
92 {
93  /* Return the property found if not empty string otherwise return def */
94  string ret = m_client->getProperty(section, cleanPath(path), attr);
95  if ( ret.size() > 0 ) return ret;
96  return def;
97 }
98 
99 int WsUser::saveProperty(const string& path, const string& section, const string& attr, const string& val)
100 {
101  return m_client->saveProperty(cleanPath(path), section, attr, val);
102 }
103 
104 
105 int WsUser::createNode(const string& path, NodeType type)
106 {
107  switch (type) {
108  case File:
109  return m_client->createNode(cleanPath(path), 0);
110  case Directory:
111  return m_client->createNode(cleanPath(path), 1);
112  }
113 }
114 
115 int WsUser::deleteNode(const string& path)
116 {
117  return m_client->deleteNode(cleanPath(path));
118 }
119 
120 int WsUser::renameNode(const string& path, const string& newPath)
121 {
122  return m_client->renameNode(cleanPath(path), cleanPath(newPath));
123 }
124 
125 int WsUser::getLock(const std::string& path)
126 {
127  return m_client->getLock(cleanPath(path));
128 }
129 
130 int WsUser::putLock(const std::string& path)
131 {
132  return m_client->putLock(cleanPath(path));
133 }
134 
135 int WsUser::isLocked(const std::string& path, std::string& uid)
136 {
137  return m_client->isLocked(cleanPath(path), uid);
138 }
139 
140 const string WsUser::getHomePage()
141 {
142  //FIXME get property from here ?
143  return m_conf->get("global", "home_page", "");
144 }
145 
146 vector<WsResultItem> WsUser::getSearchResults(const string& terms)
147 {
148  return m_client->getSearchResults(terms);
149 }
150 
151 set<string> WsUser::getAllGroups()
152 {
153  return m_client->getAllGroups();
154 }
155 
156 int WsUser::saveProperties(WsNodeProperties* props, const string& path)
157 {
158  return m_client->saveProperties(props, cleanPath(path));
159 }
160 
161 int WsUser::writeFile(const std::string path, const std::string& text){
162  int ret = getPermissions(path);
163  if(ret == ErrorCode::NotFound)
164  return ret;
165  if(ret != GlobalConfig::ReadWrite)
166  return ErrorCode::NoAccess;
167 
168  ofstream myfile;
169  std::string p = getRootPath() + "/"+path;
170  myfile.open (p.c_str());
171  if(myfile.is_open()){
172  myfile << text;
173  myfile.close();
174  return ErrorCode::Success;
175  }
176  return ErrorCode::Failure;
177 }
178 
180 {
181  return m_client->isEditor();
182 }
183 
185 {
186  return m_client->isAdministrator();
187 }
188 
189 vector<string> WsUser::getTemplatesList(const string& path)
190 {
191  return m_client->getTemplatesList(cleanPath(path));
192 }
193 
194 std::string WsUser::cleanPath(const std::string& path)
195 {
196  string newPath = path;
197  boost::algorithm::replace_all(newPath, "//", "/");
198  return newPath;
199 }
int isLocked(const std::string &path, std::string &uid)
check is the path is already locked
Definition: WsUser.cpp:135
boost::shared_ptr< WsAbstractNode > NodePtr
std::string m_ip
Definition: WsUser.h:241
std::string cleanPath(const std::string &path)
Definition: WsUser.cpp:194
~WsUser()
Destructor.
Definition: WsUser.cpp:14
int getPermissions(const std::string &p)
return the permissions on specific node
Definition: WsUser.cpp:81
#define DEBUG
Definition: WsLogger.h:27
virtual std::vector< WsResultItem > getSearchResults(const std::string &terms)=0
search for all matching results of terms using WsSearch class
int saveProperty(const std::string &path, const std::string &section, const std::string &attr, const std::string &val)
sets one property of the node and save it on disk.
Definition: WsUser.cpp:99
std::string getProperty(const std::string &path, const std::string &section, const string &attr, const std::string &def)
returns one property of a node If the property does not exist, a empty string is returned.
Definition: WsUser.cpp:91
Global properties class.
const int ReadWrite
virtual bool isEditor()=0
const int Failure
virtual const WsNodeProperties * getProperties(const std::string &p)=0
return the permissions on specific node
virtual NodePtr getAccessRoot(const bool &forceUpdate=false)=0
return the root node of the access tree starting from the root
int saveProperties(WsNodeProperties *props, const std::string &path)
save the properties of the node on disk. The user must have access and edit rights for the node...
Definition: WsUser.cpp:156
Properties of a WsNode.
WsAbstractFsClient * m_client
this will be an instance of WsFsTreeClient if not using daemon or WsFsDaemonClient if using daemon ...
Definition: WsUser.h:233
int putLock(const std::string &path)
releases the lock for the path.
Definition: WsUser.cpp:130
std::vector< WsResultItem > getSearchResults(const std::string &terms)
search for all matching results of terms using WsSearch class
Definition: WsUser.cpp:146
virtual int putLock(const std::string &path)=0
releases the lock for the path.
std::vector< std::string > getTemplatesList(const std::string &path)
return all the templates contained in a directory and parents If two templates have the same name...
Definition: WsUser.cpp:189
virtual std::string getProperty(const std::string &section, const std::string &p, const std::string &prop)=0
returns the properties of a node
std::string m_pass
Definition: WsUser.h:240
int writeFile(const std::string path, const std::string &text)
writes the text to the file
Definition: WsUser.cpp:161
WsUser(const std::string &strUid, const std::string &pass="", const std::string &ip="")
Constructor.
Definition: WsUser.cpp:7
virtual int isLocked(const std::string &path, std::string &uid)=0
check is the path is already locked
const std::string getHomePage()
return the home page
Definition: WsUser.cpp:140
const int NotFound
#define LOG
Definition: WsLogger.h:22
virtual int getLock(const std::string &path)=0
tries to acquire the lock for the path. @ return ErrorCode::Locked if the lock cannot be aquired beca...
std::set< std::string > getAllGroups()
Definition: WsUser.cpp:151
#define INFO
Definition: WsLogger.h:32
const int NoAccess
int load()
Load infos of the user.
Definition: WsUser.cpp:22
virtual int renameNode(const string &path, const string &newPath)=0
renames a node In case of a WsDirNode, all the contents of the directory and the directory will be mo...
const std::string & getEmail() const
return the email of the person
Definition: WsUser.cpp:71
virtual int saveProperties(WsNodeProperties *props, const std::string &path)=0
save the properties of the node on disk. The user must have access and edit rights for the node...
bool isEditor()
Definition: WsUser.cpp:179
virtual int saveProperty(const std::string &path, const std::string &section, const std::string &attr, const std::string &val)=0
sets one property of the node and save it on disk.
const std::string & getFirstName() const
return the name of the person
Definition: WsUser.cpp:66
virtual std::set< string > getAllGroups()=0
virtual int createNode(const string &path, int type)=0
create a directory or File. If the node is a WsDirNode than it will be only accessible to the Admin a...
std::string m_uid
Definition: WsUser.h:239
std::string get(const std::string &section, const std::string &id, const std::string &def)
const std::string getRootPath()
return the root path of the filesystem tree, example : /var/www/demo_site
Definition: WsUser.cpp:55
const std::string & getSurname() const
return the surname of the person
Definition: WsUser.cpp:61
Interface between the User class and the fsdaemon.
virtual int load()=0
loads the user info
int createNode(const string &path, NodeType type)
create a directory or File. If the node is a WsDirNode than it will be only accessible to the Admin a...
Definition: WsUser.cpp:105
const WsNodeProperties * getProperties(const std::string &p)
returns the properties of a node
Definition: WsUser.cpp:86
virtual bool isAdministrator()=0
static WsGlobalProperties * instance()
virtual std::vector< std::string > getTemplatesList(const std::string &path)=0
virtual int getPermissions(const std::string &p)=0
Load infos of the user.
virtual const std::string getRootPath()=0
return the root path of the filesystem tree, example : /var/www/demo_site
virtual const std::string & getSurname() const =0
return the surname of the person
bool isAdministrator()
Definition: WsUser.cpp:184
NodePtr getAccessRoot()
return the root node of the access tree starting from the root
Definition: WsUser.cpp:50
int renameNode(const string &path, const string &newPath)
renames a node In case of a WsDirNode, all the contents of the directory and the directory will be mo...
Definition: WsUser.cpp:120
NodeType
Definition: WsUser.h:35
Interface between WsUser class and local tree.
const int Success
const std::string & getUid() const
Definition: WsUser.cpp:76
virtual const std::string & getFirstName() const =0
return the name of the person
int getLock(const std::string &path)
tries to acquire the lock for the path. @ return ErrorCode::Locked if the lock cannot be aquired beca...
Definition: WsUser.cpp:125
int deleteNode(const string &path)
delete a node. The user must be an Admin on editor to remove the node In case of a WsDirNode...
Definition: WsUser.cpp:115
User class.
WsGlobalProperties * m_conf
Definition: WsUser.h:242
virtual const std::string & getEmail() const =0
return the email of the person
virtual int deleteNode(const string &path)=0
delete a node. The user must be an Admin on editor to remove the node In case of a WsDirNode...