Wittyshare  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WsFsTreeClient.cpp
Go to the documentation of this file.
1 
14 #include "WsFsTreeClient.h"
15 #include <Include/WsGlobalConfig.h>
16 #include <fstream>
18 
19 using namespace std;
20 using namespace boost;
21 using namespace boost::filesystem;
22 
23 WsFsTreeClient::WsFsTreeClient(const string& id, const string& pass, const string& ip):
24  m_uid(id),
25  m_pass(pass),
26  m_ip(ip)
27 {
28 }
29 
31 {
32  LOG(DEBUG) < "WsFsTreeClient :: destructor called";
33 }
34 
36 {
40  return ErrorCode::Failure;
41  int refresh;
43  return ErrorCode::Failure;
44 }
45 
46 int WsFsTreeClient::getPermissions(const string& p)
47 {
49 }
50 
52 {
54 }
55 
56 string WsFsTreeClient::getProperty(const std::string& section, const string& p, const string& prop)
57 {
58  return m_operation->getProperty(m_groups, section, p, prop);
59 }
60 
61 const string& WsFsTreeClient::getSurname() const
62 {
63  return m_sn;
64 }
65 
66 const string& WsFsTreeClient::getFirstName() const
67 {
68  return m_givenName;
69 }
70 
71 const string& WsFsTreeClient::getEmail() const
72 {
73  return this->m_email;
74 }
75 
77 {
78  WsAuthenticator connector;
79  if (connector.authentify(m_uid, m_pass, m_ip) != ErrorCode::Success)
80  return ErrorCode::Failure;
81  m_uid = connector.getUid();
82  m_sn = connector.getSurname();
83  m_givenName = connector.getFirstName();
84  m_groups = connector.getUserGroups();
85  /* We add the uid to the groups, it allows to give access to a dir to only one user */
86  m_groups.insert(m_uid);
87  m_email = connector.getEmail();
88  return ErrorCode::Success;
89 }
90 
91 int WsFsTreeClient::getLock(const std::string& path)
92 {
93  return m_operation->getLock(m_groups, m_uid, path);
94 }
95 
96 int WsFsTreeClient::putLock(const std::string& path)
97 {
98  return m_operation->putLock(m_groups, m_uid, path);
99 }
100 
101 int WsFsTreeClient::isLocked(const std::string& path, std::string& uid)
102 {
103  return m_operation->isLocked(m_groups, m_uid, path, uid);
104 }
105 
106 NodePtr WsFsTreeClient::getAccessRoot(const bool& forceUpdate)
107 {
109 }
110 
111 vector<WsResultItem> WsFsTreeClient::getSearchResults(const string& terms)
112 {
113  return m_operation->getSearchResults(m_groups, terms);
114 }
115 
117 {
118  WsAuthenticator c;
119  return c.getAllGroups();
120 }
121 
123 {
124  return m_operation->getRootPath();
125 }
126 
128 {
129  return m_operation->saveProperties(m_groups, props->getRoot().toStyledString(), p);
130 }
131 
132 int WsFsTreeClient::saveProperty(const string& path, const string& section, const string& attr, const string& val)
133 {
134  return m_operation->saveProperty(m_groups, path, section, attr, val);
135 }
136 
137 int WsFsTreeClient::createNode(const string& p, int type)
138 {
139  return m_operation->createNode(m_groups, m_uid, p, type);
140 }
141 
142 int WsFsTreeClient::deleteNode(const string& p)
143 {
144  return m_operation->deleteNode(m_groups, m_uid, p);
145 }
146 
147 int WsFsTreeClient::renameNode(const string& path, const string& newPath)
148 {
149  return m_operation->renameNode(m_groups, m_uid, path, newPath);
150 }
151 
153 {
154  return m_groups.count(m_conf->get("global", "editor_group", "editor")) > 0;
155 }
156 
158 {
159  return m_groups.count(m_conf->get("global", "admin_group", "administrator")) > 0;
160 }
161 
162 vector<string> WsFsTreeClient::getTemplatesList(const string& path)
163 {
164 }
WsFsTreeOperations * m_operation
const std::string getRootPath()
return the root path of the filesystem tree, example : /var/www/demo_site
int putLock(const std::set< std::string > groups, const std::string &uid, const std::string &path)
unlocks the file by deleting the .config/locks/filename.lock file Only the owner of the lock can unlo...
int authentify()
authenticate the user and load it's params
boost::shared_ptr< WsAbstractNode > NodePtr
std::string getProperty(const std::set< std::string > &groups, const std::string &section, const std::string &p, const std::string &prop)
get a property for a node corresponding to the path
std::string m_ip
WsGlobalProperties * m_conf
int load()
loads the user info
std::string getUid()
return the user uid WsAuthenticator::authentify must be called before
#define DEBUG
Definition: WsLogger.h:27
std::string getSurname()
return the user surname WsAuthenticator::authentify must be called before
int saveProperty(const std::set< std::string > &groups, const std::string &path, const std::string &section, const std::string &attr, const std::string &val)
save a property of the node. The user must have access and edit rights for the node.
int saveProperties(const std::set< std::string > &groups, const std::string &json, const std::string &path)
save the properties of the node. The user must have access and edit rights for the node...
std::string m_pass
std::string m_givenName
const int Failure
std::string getEmail()
return the user email WsAuthenticator::authentify must be called before
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.
Redirect operations to adequate class.
Loads Authentification module and acts as an interface.
std::string getProperty(const std::string &section, const std::string &p, const std::string &prop)
returns the properties of a node
std::set< string > m_groups
Properties of a WsNode.
WsAccessTree * getAccessTree(const std::set< std::string > &groups)
Get the access tree starting from rootPath.
std::set< string > getAllGroups()
virtual ~WsFsTreeClient()
desctrutor
WsFsTreeClient(const std::string &id, const std::string &pass, const std::string &ip)
constructor
std::vector< WsResultItem > getSearchResults(const std::set< std::string > &groups, const std::string &terms)
Get the results for searching for "terms".
const std::string & getFirstName() const
return the name of the person
Interacts directly with the menuTree and the fsTree.
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...
int renameNode(const std::set< std::string > &groups, const std::string &uid, const string &path, const string &newPath)
renames a node
const WsNodeProperties * getProperties(const std::string &p)
int getLock(const std::set< std::string > groups, const std::string &uid, const std::string &path)
tries to acquire the lock for the path. @ return ErrorCode::Locked if the lock cannot be aquired beca...
WsNodeProperties * getProperties(const std::set< std::string > &groups, const std::string &p)
get properties of a node corresponding to the path
std::string m_uid
vector< WsResultItem > getSearchResults(const std::string &terms)
search for all matching results of terms using WsSearch class
#define LOG
Definition: WsLogger.h:22
std::string m_email
Json::Value getRoot()
Return the root of the Json tree.
int getPermissions(const std::set< std::string > &groups, const std::string &p)
Get the permissions for a path for a set of groups.
const std::string & getEmail() const
return the email of the person
int isLocked(const std::string &path, std::string &uid)
int getPermissions(const std::string &p)
Load infos of the user.
int getLock(const std::string &path)
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...
virtual NodePtr getRoot()
Returns the root node of the menuTree.
int putLock(const std::string &path)
int deleteNode(const std::set< std::string > &groups, const std::string &uid, const string &path)
delete a node. The user must be an Admin on editor to remove the node
std::vector< std::string > getTemplatesList(const std::string &path)
int isLocked(const std::set< std::string > groups, const std::string &uid, const std::string &path, std::string &id)
check is the path is already locked
std::set< std::string > getUserGroups()
return the user groups WsAuthenticator::authentify must be called before
std::set< std::string > getAllGroups()
return all the possible groups WsAuthenticator::authentify must be called before
std::string get(const std::string &section, const std::string &id, const std::string &def)
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...
const std::string getRootPath()
int createNode(const string &path, int type)
create a directory or File. If the node is a WsDirNode than it will be only accessible to the Admin a...
static WsGlobalProperties * instance()
NodePtr getAccessRoot(const bool &forceUpdate=false)
return the root node of the access tree starting from the root
int authentify(const std::string &uid, const std::string &pass="", const std::string &ip="")
authentify the user.
std::string m_sn
const std::string & getSurname() const
return the surname of the person
const int Success
std::string getFirstName()
return the user name WsAuthenticator::authentify must be called before
int createNode(const std::set< std::string > &groups, const std::string &uid, const string &path, int type)
create a directory or File. If the node is a WsDirNode than it will be only accessible to the Admin a...
int update()
Update the WsFileSystemTree.