Wittyshare
0.2
|
The core of wittyshare is the WsFileSystemTree. This tree represents the files hierarchy on disk. When the application starts, it will scan all the directories starting from [root_path] and builds the tree. It will also search for config files for each directory and parse them. The main advantage of this solution is the speed. The FsTree will be stored in memory for fast access. This tree does not takes permissions in account because it does not represent any user, it will only be used to generate other trees.
It uses the WsDirectoryCrawler class to crawl over the directories. The WsFileSystemTree inherits form the WsDirectoryCrawler and each time a dir is found, it calls the virtual method WsFileSystemTree::applyDirectory() which is overriden in WsFileSystemTree class. This method creates a new Node and adds it to the current node and the current node is set to this node. The same is done for WsFileSystemTree::applyFile(), but the current node is not changed.(we dont crawl deeper because it's a file). When all the subdirs of a directory are crawled, the WsDirectoryCrawler class calls the WsFileSystemTree::endChild() method to notify the subclass so it can set the current node to the current.parent()
Each node has an properties (WsNodeProperties) object attached by the WsFileSystemTree that contains the properties of the node. The properties are parsed from the $NODE_PATH/.config/properties.json for the directories or $NODE_PATH/.config/nodes/$FILENAME.json for the nodes. It is not mandatory for a node to have a config file. The access rights for a node can also depend from the parent (see the inherit_rights_from_parent property). Each node also has the method isAllowed taking a list of groups that will return true if at least one of the groups has access. The FileNode checks access against its containing directory. The DirNode checks if it has a properties object setting groups. If yes, it checks against these groups. It not, it does up to the parent and goes through the same procedure.
Each node has an properties object attached by the WsFileSystemTree. Each WsNode also has the method isAllowed taking a list of groups that will return true if at least one of the groups has access. The WsFileNode checks access against its containing directory. The DirNode checks if it has a properties object setting groups. If yes, it checks against these groups. It not, it does up to the parent and goes through the same procedure is the inherit_from_parent is ste to true in the configuration of the node or in the WsGlobalConfiguration.
The WsMenuTree is used to build the menu of the application. The MenuTree is created from the WsFileSystemTree tree by crawling over it and applying the following rules:
The WsMenuTree class inherit from WsAbstractTree, builds the menu of a user based on a the WsFileSystemTree representing all the files on the server and a set of gids, which are the names of the groups where the user belongs.
The WsAbstractTree class inherits from the WsTreeTraversal class that runs through the WsFileSystemTree and, for each WsNode found, it calls a virtual function overridden in the child class. The WsAbstractTree class tests for each Node if the user is allowed to access it or no. If the user is allowed, a new Node is created whith the same Properties, but without any children. The new Node is added to the MenuTree. If the user does not have access, the Node and all its children are skipped.
The WsAbstractTree class contains 3 overriden functions of the parent class which are:
WsAbstractTree::beginTraverseDir is called by the WsTreeTraversal each time a WsDirNode is found. It Creates the new Node with the properties, connects the current Node to this new Node and sets the new Node as the current Node.
WsAbstractTree::endTraverseDir is called by the WsTreeTraversal each time the WsTreeTraversal finish to browse a WsDirNode and all its children. It sets the current Node as the Parent of the current Node.
WsAbstractTree::traverseFile is called by the WsTreeTraversal each time a WsFileNode is found. it does the same things as WsAbstractTree::beginTraverseDir but creates a WsFileNode instead of a WsDirNode. The current Node is not changed.
Requests to the WsFilesystemtree are sent thanks to an WsAbstractFsClient that allows multiple implementations (at time of writing: daemon and in object directly)
The WsAccessTree is the same as the WsMenuTree but does not take in consideration the [in_menu], [in_parent], [max_menu_depth] properties.