19 #include <boost/lexical_cast.hpp>
35 LOG(
INFO) <<
"WsFsTreeConsultation::getPermissions() : No such file or directory :" << p;
38 if (groups.count(
m_conf->
get(
"global",
"admin_group",
"administrator")) > 0) {
43 if (n.get()->isAllowed(groups)) {
45 if (groups.count(
m_conf->
get(
"global",
"editor_group",
"editor")) > 0) {
54 if (props->
get(
"global",
"public_site",
"false") ==
"true") {
71 LOG(
INFO) <<
"WsFsTreeConsultation::getProperties() : No such file or directory :" << p;
75 if (!n.get()->isAllowed(groups)) {
78 return n.get()->getProperties().get();
86 return props->
get(section, prop,
"");
94 ld = boost::lexical_cast<
int>(
m_conf->
get(
"global",
"lock_duration",
"3600"));
95 }
catch (boost::bad_lexical_cast&) {
96 LOG(
ERROR) <<
"WsFsTreeConsultation::getLock() : Cannot cast lock_duration to int. Check conf value";
101 n = ft->eatPath(path);
104 LOG(
INFO) <<
"WsFsTreeConsultation::getLock : No such file or directory :" << path;
109 boost::filesystem::path p;
110 if (n.get()->isDirectory())
return -1;
111 else p = n.get()->getPath().parent_path();
112 std::string name = n.get()->getName() +
".lock";
113 n.get()->getProperties()->createPropertiesDirectories();
120 if (boost::filesystem::exists(p)) {
121 std::ifstream lock(p.c_str(), std::ifstream::binary);
122 bool bOk = reader.parse(lock, v,
false);
125 boost::filesystem::remove(p);
127 id = v[
"uid"].asString();
128 ts = v[
"timestamp"].asString();
131 if (boost::lexical_cast<long>(ts) >
getTimeMs() - (ld * 1000) )
133 else boost::filesystem::remove(p);
138 ts = boost::lexical_cast<
string>(millis);
142 out.open(p.string().c_str(), ios::out | ios::trunc | ios::binary);
144 out << v.toStyledString();
155 ld = boost::lexical_cast<
int>(
m_conf->
get(
"global",
"lock_duration",
"3600"));
156 }
catch (boost::bad_lexical_cast&) {
157 LOG(
ERROR) <<
"WsFsTreeConsultation::getLock() : Cannot cast lock_duration to int. Check conf value";
162 n = ft->eatPath(path);
165 LOG(
INFO) <<
"WsFsTreeConsultation::putLock : No such file or directory :" << path;
170 boost::filesystem::path p;
171 if (n.get()->isDirectory())
return -1;
172 else p = n.get()->getPath().parent_path();
173 std::string name = n.get()->getName() +
".lock";
175 LOG(
DEBUG) <<
"WsFsTreeConsultation::putLock() : path is " << p.string();
181 if (boost::filesystem::exists(p)) {
182 std::ifstream lock(p.c_str(), std::ifstream::binary);
183 bool bOk = reader.parse(lock, v,
false);
186 boost::filesystem::remove(p);
189 id = v[
"uid"].asString();
190 ts = v[
"timestamp"].asString();
193 if (boost::lexical_cast<long>(ts) >
getTimeMs() - (ld * 1000) )
196 boost::filesystem::remove(p);
200 boost::filesystem::remove(p);
214 ld = boost::lexical_cast<
int>(
m_conf->
get(
"global",
"lock_duration",
"3600"));
215 }
catch (boost::bad_lexical_cast&) {
216 LOG(
ERROR) <<
"WsFsTreeConsultation::isLocked() : Cannot cast lock_duration to int. Check conf value";
221 n = ft->eatPath(path);
224 LOG(
INFO) <<
"WsFsTreeConsultation:isLocked : No such file or directory :" << path;
229 boost::filesystem::path p;
230 if (n.get()->isDirectory())
return -1;
231 else p = n.get()->getPath().parent_path();
232 std::string name = n.get()->getName() +
".lock";
233 n.get()->getProperties()->createPropertiesDirectories();
235 std::string lid =
"";
240 if (boost::filesystem::exists(p)) {
241 std::ifstream lock(p.c_str(), std::ifstream::binary);
242 bool bOk = reader.parse(lock, v,
false);
245 boost::filesystem::remove(p);
248 lid = v[
"uid"].asString();
249 ts = v[
"timestamp"].asString();
252 if (boost::lexical_cast<long>(ts) >
getTimeMs() - (ld * 1000) ) {
256 boost::filesystem::remove(p);
260 boost::filesystem::remove(p);
271 gettimeofday(&time, 0);
272 return (time.tv_sec * 1000) + (time.tv_usec / 1000);
281 depth = boost::lexical_cast<
int>(
m_conf->
get(
"global",
"max_menu_depth",
"0"));
282 }
catch (boost::bad_lexical_cast&) {
283 LOG(
ERROR) <<
"WsFsTreeConsultation::getAccessTree() : Cannot cast depth to int. Check conf value. Assuming depth is unlimited";
301 return vector<WsResultItem>();
307 return m_conf->
get(
"global",
"root_path",
".");
const std::string & getFsTreeStamp()
Get the stamp of the last WsFileSystemTree.
boost::shared_ptr< WsAbstractNode > NodePtr
std::vector< std::string > getTemplatesList(const std::set< std::string > &groups, const std::string &path)
TODO.
WsGlobalProperties * m_conf
WsFsTreeUpdater * m_updater
std::vector< WsResultItem > getSearchResults(const std::set< std::string > &groups, const std::string &terms)
Get the results for searching for "terms".
WsNodeProperties * getProperties(const std::set< std::string > &groups, const std::string &p)
get properties of a node corresponding to the path
Reprensents an access tree.
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...
handles the update of the FileSystemTree
virtual int build()
Parses the fileSystemTree and builds the Tree containing only the nodes where the user has access...
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...
FileSystemTreePtr getLastTree()
returns the last created tree
const std::string getRootPath()
boost::shared_ptr< WsFileSystemTree > FileSystemTreePtr
int load()
Loads all search results.
WsFsTreeConsultation(WsFsTreeUpdater *updater)
Constructor.
std::string get(const std::string §ion, const std::string &id, const std::string &def)
const std::string PathToNodeLock
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
static WsGlobalProperties * instance()
int getPermissions(const std::set< std::string > &groups, const std::string &p)
Get the permissions for a path for a set of groups.
WsAccessTree * getAccessTree(const std::set< std::string > &groups)
Get the access tree starting from rootPath.
boost::mutex m_lockEditMutex
vector< WsResultItem > getResults(const std::set< std::string > &groups)
Get list of documents readable by person member of all groups passed in parameter.
std::string get(const std::string §ion, const std::string &id, const std::string &def)
std::string getProperty(const std::set< std::string > &groups, const std::string §ion, const std::string &p, const std::string &prop)
get a property for a node corresponding to the path