@@ -37,134 +37,134 @@ |
||
| 37 | 37 | * Mapping node for system tag to object id |
| 38 | 38 | */ |
| 39 | 39 | class SystemTagMappingNode implements \Sabre\DAV\INode { |
| 40 | - /** |
|
| 41 | - * @var ISystemTag |
|
| 42 | - */ |
|
| 43 | - protected $tag; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 48 | - private $objectId; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var string |
|
| 52 | - */ |
|
| 53 | - private $objectType; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * User |
|
| 57 | - * |
|
| 58 | - * @var IUser |
|
| 59 | - */ |
|
| 60 | - protected $user; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @var ISystemTagManager |
|
| 64 | - */ |
|
| 65 | - protected $tagManager; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @var ISystemTagObjectMapper |
|
| 69 | - */ |
|
| 70 | - private $tagMapper; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Sets up the node, expects a full path name |
|
| 74 | - * |
|
| 75 | - * @param ISystemTag $tag system tag |
|
| 76 | - * @param string $objectId |
|
| 77 | - * @param string $objectType |
|
| 78 | - * @param IUser $user user |
|
| 79 | - * @param ISystemTagManager $tagManager |
|
| 80 | - * @param ISystemTagObjectMapper $tagMapper |
|
| 81 | - */ |
|
| 82 | - public function __construct( |
|
| 83 | - ISystemTag $tag, |
|
| 84 | - $objectId, |
|
| 85 | - $objectType, |
|
| 86 | - IUser $user, |
|
| 87 | - ISystemTagManager $tagManager, |
|
| 88 | - ISystemTagObjectMapper $tagMapper |
|
| 89 | - ) { |
|
| 90 | - $this->tag = $tag; |
|
| 91 | - $this->objectId = $objectId; |
|
| 92 | - $this->objectType = $objectType; |
|
| 93 | - $this->user = $user; |
|
| 94 | - $this->tagManager = $tagManager; |
|
| 95 | - $this->tagMapper = $tagMapper; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Returns the object id of the relationship |
|
| 100 | - * |
|
| 101 | - * @return string object id |
|
| 102 | - */ |
|
| 103 | - public function getObjectId() { |
|
| 104 | - return $this->objectId; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Returns the object type of the relationship |
|
| 109 | - * |
|
| 110 | - * @return string object type |
|
| 111 | - */ |
|
| 112 | - public function getObjectType() { |
|
| 113 | - return $this->objectType; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Returns the system tag represented by this node |
|
| 118 | - * |
|
| 119 | - * @return ISystemTag system tag |
|
| 120 | - */ |
|
| 121 | - public function getSystemTag() { |
|
| 122 | - return $this->tag; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Returns the id of the tag |
|
| 127 | - * |
|
| 128 | - * @return string |
|
| 129 | - */ |
|
| 130 | - public function getName() { |
|
| 131 | - return $this->tag->getId(); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Renames the node |
|
| 136 | - * |
|
| 137 | - * @param string $name The new name |
|
| 138 | - * |
|
| 139 | - * @throws MethodNotAllowed not allowed to rename node |
|
| 140 | - */ |
|
| 141 | - public function setName($name) { |
|
| 142 | - throw new MethodNotAllowed(); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Returns null, not supported |
|
| 147 | - * |
|
| 148 | - */ |
|
| 149 | - public function getLastModified() { |
|
| 150 | - return null; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Delete tag to object association |
|
| 155 | - */ |
|
| 156 | - public function delete() { |
|
| 157 | - try { |
|
| 158 | - if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) { |
|
| 159 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found'); |
|
| 160 | - } |
|
| 161 | - if (!$this->tagManager->canUserAssignTag($this->tag, $this->user)) { |
|
| 162 | - throw new Forbidden('No permission to unassign tag ' . $this->tag->getId()); |
|
| 163 | - } |
|
| 164 | - $this->tagMapper->unassignTags($this->objectId, $this->objectType, $this->tag->getId()); |
|
| 165 | - } catch (TagNotFoundException $e) { |
|
| 166 | - // can happen if concurrent deletion occurred |
|
| 167 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found', 0, $e); |
|
| 168 | - } |
|
| 169 | - } |
|
| 40 | + /** |
|
| 41 | + * @var ISystemTag |
|
| 42 | + */ |
|
| 43 | + protected $tag; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | + private $objectId; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var string |
|
| 52 | + */ |
|
| 53 | + private $objectType; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * User |
|
| 57 | + * |
|
| 58 | + * @var IUser |
|
| 59 | + */ |
|
| 60 | + protected $user; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @var ISystemTagManager |
|
| 64 | + */ |
|
| 65 | + protected $tagManager; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @var ISystemTagObjectMapper |
|
| 69 | + */ |
|
| 70 | + private $tagMapper; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Sets up the node, expects a full path name |
|
| 74 | + * |
|
| 75 | + * @param ISystemTag $tag system tag |
|
| 76 | + * @param string $objectId |
|
| 77 | + * @param string $objectType |
|
| 78 | + * @param IUser $user user |
|
| 79 | + * @param ISystemTagManager $tagManager |
|
| 80 | + * @param ISystemTagObjectMapper $tagMapper |
|
| 81 | + */ |
|
| 82 | + public function __construct( |
|
| 83 | + ISystemTag $tag, |
|
| 84 | + $objectId, |
|
| 85 | + $objectType, |
|
| 86 | + IUser $user, |
|
| 87 | + ISystemTagManager $tagManager, |
|
| 88 | + ISystemTagObjectMapper $tagMapper |
|
| 89 | + ) { |
|
| 90 | + $this->tag = $tag; |
|
| 91 | + $this->objectId = $objectId; |
|
| 92 | + $this->objectType = $objectType; |
|
| 93 | + $this->user = $user; |
|
| 94 | + $this->tagManager = $tagManager; |
|
| 95 | + $this->tagMapper = $tagMapper; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Returns the object id of the relationship |
|
| 100 | + * |
|
| 101 | + * @return string object id |
|
| 102 | + */ |
|
| 103 | + public function getObjectId() { |
|
| 104 | + return $this->objectId; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Returns the object type of the relationship |
|
| 109 | + * |
|
| 110 | + * @return string object type |
|
| 111 | + */ |
|
| 112 | + public function getObjectType() { |
|
| 113 | + return $this->objectType; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Returns the system tag represented by this node |
|
| 118 | + * |
|
| 119 | + * @return ISystemTag system tag |
|
| 120 | + */ |
|
| 121 | + public function getSystemTag() { |
|
| 122 | + return $this->tag; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Returns the id of the tag |
|
| 127 | + * |
|
| 128 | + * @return string |
|
| 129 | + */ |
|
| 130 | + public function getName() { |
|
| 131 | + return $this->tag->getId(); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Renames the node |
|
| 136 | + * |
|
| 137 | + * @param string $name The new name |
|
| 138 | + * |
|
| 139 | + * @throws MethodNotAllowed not allowed to rename node |
|
| 140 | + */ |
|
| 141 | + public function setName($name) { |
|
| 142 | + throw new MethodNotAllowed(); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Returns null, not supported |
|
| 147 | + * |
|
| 148 | + */ |
|
| 149 | + public function getLastModified() { |
|
| 150 | + return null; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Delete tag to object association |
|
| 155 | + */ |
|
| 156 | + public function delete() { |
|
| 157 | + try { |
|
| 158 | + if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) { |
|
| 159 | + throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found'); |
|
| 160 | + } |
|
| 161 | + if (!$this->tagManager->canUserAssignTag($this->tag, $this->user)) { |
|
| 162 | + throw new Forbidden('No permission to unassign tag ' . $this->tag->getId()); |
|
| 163 | + } |
|
| 164 | + $this->tagMapper->unassignTags($this->objectId, $this->objectType, $this->tag->getId()); |
|
| 165 | + } catch (TagNotFoundException $e) { |
|
| 166 | + // can happen if concurrent deletion occurred |
|
| 167 | + throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found', 0, $e); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | 170 | } |
@@ -156,15 +156,15 @@ |
||
| 156 | 156 | public function delete() { |
| 157 | 157 | try { |
| 158 | 158 | if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) { |
| 159 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found'); |
|
| 159 | + throw new NotFound('Tag with id '.$this->tag->getId().' not found'); |
|
| 160 | 160 | } |
| 161 | 161 | if (!$this->tagManager->canUserAssignTag($this->tag, $this->user)) { |
| 162 | - throw new Forbidden('No permission to unassign tag ' . $this->tag->getId()); |
|
| 162 | + throw new Forbidden('No permission to unassign tag '.$this->tag->getId()); |
|
| 163 | 163 | } |
| 164 | 164 | $this->tagMapper->unassignTags($this->objectId, $this->objectType, $this->tag->getId()); |
| 165 | 165 | } catch (TagNotFoundException $e) { |
| 166 | 166 | // can happen if concurrent deletion occurred |
| 167 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found', 0, $e); |
|
| 167 | + throw new NotFound('Tag with id '.$this->tag->getId().' not found', 0, $e); |
|
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | } |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | if ($node instanceof SystemTagsObjectMappingCollection) { |
| 136 | 136 | // also add to collection |
| 137 | 137 | $node->createFile($tag->getId()); |
| 138 | - $url = $request->getBaseUrl() . 'systemtags/'; |
|
| 138 | + $url = $request->getBaseUrl().'systemtags/'; |
|
| 139 | 139 | } else { |
| 140 | 140 | $url = $request->getUrl(); |
| 141 | 141 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | $url .= '/'; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - $response->setHeader('Content-Location', $url . $tag->getId()); |
|
| 147 | + $response->setHeader('Content-Location', $url.$tag->getId()); |
|
| 148 | 148 | |
| 149 | 149 | // created |
| 150 | 150 | $response->setStatus(201); |
@@ -179,11 +179,11 @@ discard block |
||
| 179 | 179 | $userAssignable = true; |
| 180 | 180 | |
| 181 | 181 | if (isset($data['userVisible'])) { |
| 182 | - $userVisible = (bool)$data['userVisible']; |
|
| 182 | + $userVisible = (bool) $data['userVisible']; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | if (isset($data['userAssignable'])) { |
| 186 | - $userAssignable = (bool)$data['userAssignable']; |
|
| 186 | + $userAssignable = (bool) $data['userAssignable']; |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | $groups = []; |
@@ -194,8 +194,8 @@ discard block |
||
| 194 | 194 | } |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - if($userVisible === false || $userAssignable === false || !empty($groups)) { |
|
| 198 | - if(!$this->userSession->isLoggedIn() || !$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { |
|
| 197 | + if ($userVisible === false || $userAssignable === false || !empty($groups)) { |
|
| 198 | + if (!$this->userSession->isLoggedIn() || !$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { |
|
| 199 | 199 | throw new BadRequest('Not sufficient permissions'); |
| 200 | 200 | } |
| 201 | 201 | } |
@@ -46,280 +46,280 @@ |
||
| 46 | 46 | */ |
| 47 | 47 | class SystemTagPlugin extends \Sabre\DAV\ServerPlugin { |
| 48 | 48 | |
| 49 | - // namespace |
|
| 50 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 51 | - const ID_PROPERTYNAME = '{http://owncloud.org/ns}id'; |
|
| 52 | - const DISPLAYNAME_PROPERTYNAME = '{http://owncloud.org/ns}display-name'; |
|
| 53 | - const USERVISIBLE_PROPERTYNAME = '{http://owncloud.org/ns}user-visible'; |
|
| 54 | - const USERASSIGNABLE_PROPERTYNAME = '{http://owncloud.org/ns}user-assignable'; |
|
| 55 | - const GROUPS_PROPERTYNAME = '{http://owncloud.org/ns}groups'; |
|
| 56 | - const CANASSIGN_PROPERTYNAME = '{http://owncloud.org/ns}can-assign'; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var \Sabre\DAV\Server $server |
|
| 60 | - */ |
|
| 61 | - private $server; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @var ISystemTagManager |
|
| 65 | - */ |
|
| 66 | - protected $tagManager; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @var IUserSession |
|
| 70 | - */ |
|
| 71 | - protected $userSession; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @var IGroupManager |
|
| 75 | - */ |
|
| 76 | - protected $groupManager; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @param ISystemTagManager $tagManager tag manager |
|
| 80 | - * @param IGroupManager $groupManager |
|
| 81 | - * @param IUserSession $userSession |
|
| 82 | - */ |
|
| 83 | - public function __construct(ISystemTagManager $tagManager, |
|
| 84 | - IGroupManager $groupManager, |
|
| 85 | - IUserSession $userSession) { |
|
| 86 | - $this->tagManager = $tagManager; |
|
| 87 | - $this->userSession = $userSession; |
|
| 88 | - $this->groupManager = $groupManager; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * This initializes the plugin. |
|
| 93 | - * |
|
| 94 | - * This function is called by \Sabre\DAV\Server, after |
|
| 95 | - * addPlugin is called. |
|
| 96 | - * |
|
| 97 | - * This method should set up the required event subscriptions. |
|
| 98 | - * |
|
| 99 | - * @param \Sabre\DAV\Server $server |
|
| 100 | - * @return void |
|
| 101 | - */ |
|
| 102 | - public function initialize(\Sabre\DAV\Server $server) { |
|
| 103 | - |
|
| 104 | - $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
| 105 | - |
|
| 106 | - $server->protectedProperties[] = self::ID_PROPERTYNAME; |
|
| 107 | - |
|
| 108 | - $server->on('propFind', array($this, 'handleGetProperties')); |
|
| 109 | - $server->on('propPatch', array($this, 'handleUpdateProperties')); |
|
| 110 | - $server->on('method:POST', [$this, 'httpPost']); |
|
| 111 | - |
|
| 112 | - $this->server = $server; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * POST operation on system tag collections |
|
| 117 | - * |
|
| 118 | - * @param RequestInterface $request request object |
|
| 119 | - * @param ResponseInterface $response response object |
|
| 120 | - * @return null|false |
|
| 121 | - */ |
|
| 122 | - public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
| 123 | - $path = $request->getPath(); |
|
| 124 | - |
|
| 125 | - // Making sure the node exists |
|
| 126 | - $node = $this->server->tree->getNodeForPath($path); |
|
| 127 | - if ($node instanceof SystemTagsByIdCollection || $node instanceof SystemTagsObjectMappingCollection) { |
|
| 128 | - $data = $request->getBodyAsString(); |
|
| 129 | - |
|
| 130 | - $tag = $this->createTag($data, $request->getHeader('Content-Type')); |
|
| 131 | - |
|
| 132 | - if ($node instanceof SystemTagsObjectMappingCollection) { |
|
| 133 | - // also add to collection |
|
| 134 | - $node->createFile($tag->getId()); |
|
| 135 | - $url = $request->getBaseUrl() . 'systemtags/'; |
|
| 136 | - } else { |
|
| 137 | - $url = $request->getUrl(); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - if ($url[strlen($url) - 1] !== '/') { |
|
| 141 | - $url .= '/'; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - $response->setHeader('Content-Location', $url . $tag->getId()); |
|
| 145 | - |
|
| 146 | - // created |
|
| 147 | - $response->setStatus(201); |
|
| 148 | - return false; |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Creates a new tag |
|
| 154 | - * |
|
| 155 | - * @param string $data JSON encoded string containing the properties of the tag to create |
|
| 156 | - * @param string $contentType content type of the data |
|
| 157 | - * @return ISystemTag newly created system tag |
|
| 158 | - * |
|
| 159 | - * @throws BadRequest if a field was missing |
|
| 160 | - * @throws Conflict if a tag with the same properties already exists |
|
| 161 | - * @throws UnsupportedMediaType if the content type is not supported |
|
| 162 | - */ |
|
| 163 | - private function createTag($data, $contentType = 'application/json') { |
|
| 164 | - if (explode(';', $contentType)[0] === 'application/json') { |
|
| 165 | - $data = json_decode($data, true); |
|
| 166 | - } else { |
|
| 167 | - throw new UnsupportedMediaType(); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - if (!isset($data['name'])) { |
|
| 171 | - throw new BadRequest('Missing "name" attribute'); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - $tagName = $data['name']; |
|
| 175 | - $userVisible = true; |
|
| 176 | - $userAssignable = true; |
|
| 177 | - |
|
| 178 | - if (isset($data['userVisible'])) { |
|
| 179 | - $userVisible = (bool)$data['userVisible']; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if (isset($data['userAssignable'])) { |
|
| 183 | - $userAssignable = (bool)$data['userAssignable']; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $groups = []; |
|
| 187 | - if (isset($data['groups'])) { |
|
| 188 | - $groups = $data['groups']; |
|
| 189 | - if (is_string($groups)) { |
|
| 190 | - $groups = explode('|', $groups); |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if($userVisible === false || $userAssignable === false || !empty($groups)) { |
|
| 195 | - if(!$this->userSession->isLoggedIn() || !$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { |
|
| 196 | - throw new BadRequest('Not sufficient permissions'); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - try { |
|
| 201 | - $tag = $this->tagManager->createTag($tagName, $userVisible, $userAssignable); |
|
| 202 | - if (!empty($groups)) { |
|
| 203 | - $this->tagManager->setTagGroups($tag, $groups); |
|
| 204 | - } |
|
| 205 | - return $tag; |
|
| 206 | - } catch (TagAlreadyExistsException $e) { |
|
| 207 | - throw new Conflict('Tag already exists', 0, $e); |
|
| 208 | - } |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Retrieves system tag properties |
|
| 214 | - * |
|
| 215 | - * @param PropFind $propFind |
|
| 216 | - * @param \Sabre\DAV\INode $node |
|
| 217 | - */ |
|
| 218 | - public function handleGetProperties( |
|
| 219 | - PropFind $propFind, |
|
| 220 | - \Sabre\DAV\INode $node |
|
| 221 | - ) { |
|
| 222 | - if (!($node instanceof SystemTagNode) && !($node instanceof SystemTagMappingNode)) { |
|
| 223 | - return; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - $propFind->handle(self::ID_PROPERTYNAME, function() use ($node) { |
|
| 227 | - return $node->getSystemTag()->getId(); |
|
| 228 | - }); |
|
| 229 | - |
|
| 230 | - $propFind->handle(self::DISPLAYNAME_PROPERTYNAME, function() use ($node) { |
|
| 231 | - return $node->getSystemTag()->getName(); |
|
| 232 | - }); |
|
| 233 | - |
|
| 234 | - $propFind->handle(self::USERVISIBLE_PROPERTYNAME, function() use ($node) { |
|
| 235 | - return $node->getSystemTag()->isUserVisible() ? 'true' : 'false'; |
|
| 236 | - }); |
|
| 237 | - |
|
| 238 | - $propFind->handle(self::USERASSIGNABLE_PROPERTYNAME, function() use ($node) { |
|
| 239 | - // this is the tag's inherent property "is user assignable" |
|
| 240 | - return $node->getSystemTag()->isUserAssignable() ? 'true' : 'false'; |
|
| 241 | - }); |
|
| 242 | - |
|
| 243 | - $propFind->handle(self::CANASSIGN_PROPERTYNAME, function() use ($node) { |
|
| 244 | - // this is the effective permission for the current user |
|
| 245 | - return $this->tagManager->canUserAssignTag($node->getSystemTag(), $this->userSession->getUser()) ? 'true' : 'false'; |
|
| 246 | - }); |
|
| 247 | - |
|
| 248 | - $propFind->handle(self::GROUPS_PROPERTYNAME, function() use ($node) { |
|
| 249 | - if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { |
|
| 250 | - // property only available for admins |
|
| 251 | - throw new Forbidden(); |
|
| 252 | - } |
|
| 253 | - $groups = []; |
|
| 254 | - // no need to retrieve groups for namespaces that don't qualify |
|
| 255 | - if ($node->getSystemTag()->isUserVisible() && !$node->getSystemTag()->isUserAssignable()) { |
|
| 256 | - $groups = $this->tagManager->getTagGroups($node->getSystemTag()); |
|
| 257 | - } |
|
| 258 | - return implode('|', $groups); |
|
| 259 | - }); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Updates tag attributes |
|
| 264 | - * |
|
| 265 | - * @param string $path |
|
| 266 | - * @param PropPatch $propPatch |
|
| 267 | - * |
|
| 268 | - * @return void |
|
| 269 | - */ |
|
| 270 | - public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
| 271 | - $node = $this->server->tree->getNodeForPath($path); |
|
| 272 | - if (!($node instanceof SystemTagNode)) { |
|
| 273 | - return; |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - $propPatch->handle([ |
|
| 277 | - self::DISPLAYNAME_PROPERTYNAME, |
|
| 278 | - self::USERVISIBLE_PROPERTYNAME, |
|
| 279 | - self::USERASSIGNABLE_PROPERTYNAME, |
|
| 280 | - self::GROUPS_PROPERTYNAME, |
|
| 281 | - ], function($props) use ($node) { |
|
| 282 | - $tag = $node->getSystemTag(); |
|
| 283 | - $name = $tag->getName(); |
|
| 284 | - $userVisible = $tag->isUserVisible(); |
|
| 285 | - $userAssignable = $tag->isUserAssignable(); |
|
| 286 | - |
|
| 287 | - $updateTag = false; |
|
| 288 | - |
|
| 289 | - if (isset($props[self::DISPLAYNAME_PROPERTYNAME])) { |
|
| 290 | - $name = $props[self::DISPLAYNAME_PROPERTYNAME]; |
|
| 291 | - $updateTag = true; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - if (isset($props[self::USERVISIBLE_PROPERTYNAME])) { |
|
| 295 | - $propValue = $props[self::USERVISIBLE_PROPERTYNAME]; |
|
| 296 | - $userVisible = ($propValue !== 'false' && $propValue !== '0'); |
|
| 297 | - $updateTag = true; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - if (isset($props[self::USERASSIGNABLE_PROPERTYNAME])) { |
|
| 301 | - $propValue = $props[self::USERASSIGNABLE_PROPERTYNAME]; |
|
| 302 | - $userAssignable = ($propValue !== 'false' && $propValue !== '0'); |
|
| 303 | - $updateTag = true; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - if (isset($props[self::GROUPS_PROPERTYNAME])) { |
|
| 307 | - if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { |
|
| 308 | - // property only available for admins |
|
| 309 | - throw new Forbidden(); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - $propValue = $props[self::GROUPS_PROPERTYNAME]; |
|
| 313 | - $groupIds = explode('|', $propValue); |
|
| 314 | - $this->tagManager->setTagGroups($tag, $groupIds); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - if ($updateTag) { |
|
| 318 | - $node->update($name, $userVisible, $userAssignable); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - return true; |
|
| 322 | - }); |
|
| 323 | - |
|
| 324 | - } |
|
| 49 | + // namespace |
|
| 50 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 51 | + const ID_PROPERTYNAME = '{http://owncloud.org/ns}id'; |
|
| 52 | + const DISPLAYNAME_PROPERTYNAME = '{http://owncloud.org/ns}display-name'; |
|
| 53 | + const USERVISIBLE_PROPERTYNAME = '{http://owncloud.org/ns}user-visible'; |
|
| 54 | + const USERASSIGNABLE_PROPERTYNAME = '{http://owncloud.org/ns}user-assignable'; |
|
| 55 | + const GROUPS_PROPERTYNAME = '{http://owncloud.org/ns}groups'; |
|
| 56 | + const CANASSIGN_PROPERTYNAME = '{http://owncloud.org/ns}can-assign'; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var \Sabre\DAV\Server $server |
|
| 60 | + */ |
|
| 61 | + private $server; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @var ISystemTagManager |
|
| 65 | + */ |
|
| 66 | + protected $tagManager; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @var IUserSession |
|
| 70 | + */ |
|
| 71 | + protected $userSession; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @var IGroupManager |
|
| 75 | + */ |
|
| 76 | + protected $groupManager; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @param ISystemTagManager $tagManager tag manager |
|
| 80 | + * @param IGroupManager $groupManager |
|
| 81 | + * @param IUserSession $userSession |
|
| 82 | + */ |
|
| 83 | + public function __construct(ISystemTagManager $tagManager, |
|
| 84 | + IGroupManager $groupManager, |
|
| 85 | + IUserSession $userSession) { |
|
| 86 | + $this->tagManager = $tagManager; |
|
| 87 | + $this->userSession = $userSession; |
|
| 88 | + $this->groupManager = $groupManager; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * This initializes the plugin. |
|
| 93 | + * |
|
| 94 | + * This function is called by \Sabre\DAV\Server, after |
|
| 95 | + * addPlugin is called. |
|
| 96 | + * |
|
| 97 | + * This method should set up the required event subscriptions. |
|
| 98 | + * |
|
| 99 | + * @param \Sabre\DAV\Server $server |
|
| 100 | + * @return void |
|
| 101 | + */ |
|
| 102 | + public function initialize(\Sabre\DAV\Server $server) { |
|
| 103 | + |
|
| 104 | + $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
| 105 | + |
|
| 106 | + $server->protectedProperties[] = self::ID_PROPERTYNAME; |
|
| 107 | + |
|
| 108 | + $server->on('propFind', array($this, 'handleGetProperties')); |
|
| 109 | + $server->on('propPatch', array($this, 'handleUpdateProperties')); |
|
| 110 | + $server->on('method:POST', [$this, 'httpPost']); |
|
| 111 | + |
|
| 112 | + $this->server = $server; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * POST operation on system tag collections |
|
| 117 | + * |
|
| 118 | + * @param RequestInterface $request request object |
|
| 119 | + * @param ResponseInterface $response response object |
|
| 120 | + * @return null|false |
|
| 121 | + */ |
|
| 122 | + public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
| 123 | + $path = $request->getPath(); |
|
| 124 | + |
|
| 125 | + // Making sure the node exists |
|
| 126 | + $node = $this->server->tree->getNodeForPath($path); |
|
| 127 | + if ($node instanceof SystemTagsByIdCollection || $node instanceof SystemTagsObjectMappingCollection) { |
|
| 128 | + $data = $request->getBodyAsString(); |
|
| 129 | + |
|
| 130 | + $tag = $this->createTag($data, $request->getHeader('Content-Type')); |
|
| 131 | + |
|
| 132 | + if ($node instanceof SystemTagsObjectMappingCollection) { |
|
| 133 | + // also add to collection |
|
| 134 | + $node->createFile($tag->getId()); |
|
| 135 | + $url = $request->getBaseUrl() . 'systemtags/'; |
|
| 136 | + } else { |
|
| 137 | + $url = $request->getUrl(); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + if ($url[strlen($url) - 1] !== '/') { |
|
| 141 | + $url .= '/'; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + $response->setHeader('Content-Location', $url . $tag->getId()); |
|
| 145 | + |
|
| 146 | + // created |
|
| 147 | + $response->setStatus(201); |
|
| 148 | + return false; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Creates a new tag |
|
| 154 | + * |
|
| 155 | + * @param string $data JSON encoded string containing the properties of the tag to create |
|
| 156 | + * @param string $contentType content type of the data |
|
| 157 | + * @return ISystemTag newly created system tag |
|
| 158 | + * |
|
| 159 | + * @throws BadRequest if a field was missing |
|
| 160 | + * @throws Conflict if a tag with the same properties already exists |
|
| 161 | + * @throws UnsupportedMediaType if the content type is not supported |
|
| 162 | + */ |
|
| 163 | + private function createTag($data, $contentType = 'application/json') { |
|
| 164 | + if (explode(';', $contentType)[0] === 'application/json') { |
|
| 165 | + $data = json_decode($data, true); |
|
| 166 | + } else { |
|
| 167 | + throw new UnsupportedMediaType(); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + if (!isset($data['name'])) { |
|
| 171 | + throw new BadRequest('Missing "name" attribute'); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + $tagName = $data['name']; |
|
| 175 | + $userVisible = true; |
|
| 176 | + $userAssignable = true; |
|
| 177 | + |
|
| 178 | + if (isset($data['userVisible'])) { |
|
| 179 | + $userVisible = (bool)$data['userVisible']; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if (isset($data['userAssignable'])) { |
|
| 183 | + $userAssignable = (bool)$data['userAssignable']; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $groups = []; |
|
| 187 | + if (isset($data['groups'])) { |
|
| 188 | + $groups = $data['groups']; |
|
| 189 | + if (is_string($groups)) { |
|
| 190 | + $groups = explode('|', $groups); |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if($userVisible === false || $userAssignable === false || !empty($groups)) { |
|
| 195 | + if(!$this->userSession->isLoggedIn() || !$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { |
|
| 196 | + throw new BadRequest('Not sufficient permissions'); |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + try { |
|
| 201 | + $tag = $this->tagManager->createTag($tagName, $userVisible, $userAssignable); |
|
| 202 | + if (!empty($groups)) { |
|
| 203 | + $this->tagManager->setTagGroups($tag, $groups); |
|
| 204 | + } |
|
| 205 | + return $tag; |
|
| 206 | + } catch (TagAlreadyExistsException $e) { |
|
| 207 | + throw new Conflict('Tag already exists', 0, $e); |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Retrieves system tag properties |
|
| 214 | + * |
|
| 215 | + * @param PropFind $propFind |
|
| 216 | + * @param \Sabre\DAV\INode $node |
|
| 217 | + */ |
|
| 218 | + public function handleGetProperties( |
|
| 219 | + PropFind $propFind, |
|
| 220 | + \Sabre\DAV\INode $node |
|
| 221 | + ) { |
|
| 222 | + if (!($node instanceof SystemTagNode) && !($node instanceof SystemTagMappingNode)) { |
|
| 223 | + return; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + $propFind->handle(self::ID_PROPERTYNAME, function() use ($node) { |
|
| 227 | + return $node->getSystemTag()->getId(); |
|
| 228 | + }); |
|
| 229 | + |
|
| 230 | + $propFind->handle(self::DISPLAYNAME_PROPERTYNAME, function() use ($node) { |
|
| 231 | + return $node->getSystemTag()->getName(); |
|
| 232 | + }); |
|
| 233 | + |
|
| 234 | + $propFind->handle(self::USERVISIBLE_PROPERTYNAME, function() use ($node) { |
|
| 235 | + return $node->getSystemTag()->isUserVisible() ? 'true' : 'false'; |
|
| 236 | + }); |
|
| 237 | + |
|
| 238 | + $propFind->handle(self::USERASSIGNABLE_PROPERTYNAME, function() use ($node) { |
|
| 239 | + // this is the tag's inherent property "is user assignable" |
|
| 240 | + return $node->getSystemTag()->isUserAssignable() ? 'true' : 'false'; |
|
| 241 | + }); |
|
| 242 | + |
|
| 243 | + $propFind->handle(self::CANASSIGN_PROPERTYNAME, function() use ($node) { |
|
| 244 | + // this is the effective permission for the current user |
|
| 245 | + return $this->tagManager->canUserAssignTag($node->getSystemTag(), $this->userSession->getUser()) ? 'true' : 'false'; |
|
| 246 | + }); |
|
| 247 | + |
|
| 248 | + $propFind->handle(self::GROUPS_PROPERTYNAME, function() use ($node) { |
|
| 249 | + if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { |
|
| 250 | + // property only available for admins |
|
| 251 | + throw new Forbidden(); |
|
| 252 | + } |
|
| 253 | + $groups = []; |
|
| 254 | + // no need to retrieve groups for namespaces that don't qualify |
|
| 255 | + if ($node->getSystemTag()->isUserVisible() && !$node->getSystemTag()->isUserAssignable()) { |
|
| 256 | + $groups = $this->tagManager->getTagGroups($node->getSystemTag()); |
|
| 257 | + } |
|
| 258 | + return implode('|', $groups); |
|
| 259 | + }); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Updates tag attributes |
|
| 264 | + * |
|
| 265 | + * @param string $path |
|
| 266 | + * @param PropPatch $propPatch |
|
| 267 | + * |
|
| 268 | + * @return void |
|
| 269 | + */ |
|
| 270 | + public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
| 271 | + $node = $this->server->tree->getNodeForPath($path); |
|
| 272 | + if (!($node instanceof SystemTagNode)) { |
|
| 273 | + return; |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + $propPatch->handle([ |
|
| 277 | + self::DISPLAYNAME_PROPERTYNAME, |
|
| 278 | + self::USERVISIBLE_PROPERTYNAME, |
|
| 279 | + self::USERASSIGNABLE_PROPERTYNAME, |
|
| 280 | + self::GROUPS_PROPERTYNAME, |
|
| 281 | + ], function($props) use ($node) { |
|
| 282 | + $tag = $node->getSystemTag(); |
|
| 283 | + $name = $tag->getName(); |
|
| 284 | + $userVisible = $tag->isUserVisible(); |
|
| 285 | + $userAssignable = $tag->isUserAssignable(); |
|
| 286 | + |
|
| 287 | + $updateTag = false; |
|
| 288 | + |
|
| 289 | + if (isset($props[self::DISPLAYNAME_PROPERTYNAME])) { |
|
| 290 | + $name = $props[self::DISPLAYNAME_PROPERTYNAME]; |
|
| 291 | + $updateTag = true; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + if (isset($props[self::USERVISIBLE_PROPERTYNAME])) { |
|
| 295 | + $propValue = $props[self::USERVISIBLE_PROPERTYNAME]; |
|
| 296 | + $userVisible = ($propValue !== 'false' && $propValue !== '0'); |
|
| 297 | + $updateTag = true; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + if (isset($props[self::USERASSIGNABLE_PROPERTYNAME])) { |
|
| 301 | + $propValue = $props[self::USERASSIGNABLE_PROPERTYNAME]; |
|
| 302 | + $userAssignable = ($propValue !== 'false' && $propValue !== '0'); |
|
| 303 | + $updateTag = true; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + if (isset($props[self::GROUPS_PROPERTYNAME])) { |
|
| 307 | + if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { |
|
| 308 | + // property only available for admins |
|
| 309 | + throw new Forbidden(); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + $propValue = $props[self::GROUPS_PROPERTYNAME]; |
|
| 313 | + $groupIds = explode('|', $propValue); |
|
| 314 | + $this->tagManager->setTagGroups($tag, $groupIds); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + if ($updateTag) { |
|
| 318 | + $node->update($name, $userVisible, $userAssignable); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + return true; |
|
| 322 | + }); |
|
| 323 | + |
|
| 324 | + } |
|
| 325 | 325 | } |
@@ -95,15 +95,15 @@ discard block |
||
| 95 | 95 | $tags = $this->tagManager->getTagsByIds([$tagId]); |
| 96 | 96 | $tag = current($tags); |
| 97 | 97 | if (!$this->tagManager->canUserSeeTag($tag, $this->user)) { |
| 98 | - throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign'); |
|
| 98 | + throw new PreconditionFailed('Tag with id '.$tagId.' does not exist, cannot assign'); |
|
| 99 | 99 | } |
| 100 | 100 | if (!$this->tagManager->canUserAssignTag($tag, $this->user)) { |
| 101 | - throw new Forbidden('No permission to assign tag ' . $tagId); |
|
| 101 | + throw new Forbidden('No permission to assign tag '.$tagId); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | $this->tagMapper->assignTags($this->objectId, $this->objectType, $tagId); |
| 105 | 105 | } catch (TagNotFoundException $e) { |
| 106 | - throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign'); |
|
| 106 | + throw new PreconditionFailed('Tag with id '.$tagId.' does not exist, cannot assign'); |
|
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | |
@@ -120,11 +120,11 @@ discard block |
||
| 120 | 120 | return $this->makeNode($tag); |
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | - throw new NotFound('Tag with id ' . $tagId . ' not present for object ' . $this->objectId); |
|
| 123 | + throw new NotFound('Tag with id '.$tagId.' not present for object '.$this->objectId); |
|
| 124 | 124 | } catch (\InvalidArgumentException $e) { |
| 125 | 125 | throw new BadRequest('Invalid tag id', 0, $e); |
| 126 | 126 | } catch (TagNotFoundException $e) { |
| 127 | - throw new NotFound('Tag with id ' . $tagId . ' not found', 0, $e); |
|
| 127 | + throw new NotFound('Tag with id '.$tagId.' not found', 0, $e); |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | |
@@ -39,169 +39,169 @@ |
||
| 39 | 39 | */ |
| 40 | 40 | class SystemTagsObjectMappingCollection implements ICollection { |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - private $objectId; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var string |
|
| 49 | - */ |
|
| 50 | - private $objectType; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var ISystemTagManager |
|
| 54 | - */ |
|
| 55 | - private $tagManager; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @var ISystemTagObjectMapper |
|
| 59 | - */ |
|
| 60 | - private $tagMapper; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * User |
|
| 64 | - * |
|
| 65 | - * @var IUser |
|
| 66 | - */ |
|
| 67 | - private $user; |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Constructor |
|
| 72 | - * |
|
| 73 | - * @param string $objectId object id |
|
| 74 | - * @param string $objectType object type |
|
| 75 | - * @param IUser $user user |
|
| 76 | - * @param ISystemTagManager $tagManager tag manager |
|
| 77 | - * @param ISystemTagObjectMapper $tagMapper tag mapper |
|
| 78 | - */ |
|
| 79 | - public function __construct( |
|
| 80 | - $objectId, |
|
| 81 | - $objectType, |
|
| 82 | - IUser $user, |
|
| 83 | - ISystemTagManager $tagManager, |
|
| 84 | - ISystemTagObjectMapper $tagMapper |
|
| 85 | - ) { |
|
| 86 | - $this->tagManager = $tagManager; |
|
| 87 | - $this->tagMapper = $tagMapper; |
|
| 88 | - $this->objectId = $objectId; |
|
| 89 | - $this->objectType = $objectType; |
|
| 90 | - $this->user = $user; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - function createFile($tagId, $data = null) { |
|
| 94 | - try { |
|
| 95 | - $tags = $this->tagManager->getTagsByIds([$tagId]); |
|
| 96 | - $tag = current($tags); |
|
| 97 | - if (!$this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
| 98 | - throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign'); |
|
| 99 | - } |
|
| 100 | - if (!$this->tagManager->canUserAssignTag($tag, $this->user)) { |
|
| 101 | - throw new Forbidden('No permission to assign tag ' . $tagId); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $this->tagMapper->assignTags($this->objectId, $this->objectType, $tagId); |
|
| 105 | - } catch (TagNotFoundException $e) { |
|
| 106 | - throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign'); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - function createDirectory($name) { |
|
| 111 | - throw new Forbidden('Permission denied to create collections'); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - function getChild($tagId) { |
|
| 115 | - try { |
|
| 116 | - if ($this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true)) { |
|
| 117 | - $tag = $this->tagManager->getTagsByIds([$tagId]); |
|
| 118 | - $tag = current($tag); |
|
| 119 | - if ($this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
| 120 | - return $this->makeNode($tag); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - throw new NotFound('Tag with id ' . $tagId . ' not present for object ' . $this->objectId); |
|
| 124 | - } catch (\InvalidArgumentException $e) { |
|
| 125 | - throw new BadRequest('Invalid tag id', 0, $e); |
|
| 126 | - } catch (TagNotFoundException $e) { |
|
| 127 | - throw new NotFound('Tag with id ' . $tagId . ' not found', 0, $e); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - function getChildren() { |
|
| 132 | - $tagIds = current($this->tagMapper->getTagIdsForObjects([$this->objectId], $this->objectType)); |
|
| 133 | - if (empty($tagIds)) { |
|
| 134 | - return []; |
|
| 135 | - } |
|
| 136 | - $tags = $this->tagManager->getTagsByIds($tagIds); |
|
| 137 | - |
|
| 138 | - // filter out non-visible tags |
|
| 139 | - $tags = array_filter($tags, function($tag) { |
|
| 140 | - return $this->tagManager->canUserSeeTag($tag, $this->user); |
|
| 141 | - }); |
|
| 142 | - |
|
| 143 | - return array_values(array_map(function($tag) { |
|
| 144 | - return $this->makeNode($tag); |
|
| 145 | - }, $tags)); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - function childExists($tagId) { |
|
| 149 | - try { |
|
| 150 | - $result = $this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true); |
|
| 151 | - |
|
| 152 | - if ($result) { |
|
| 153 | - $tags = $this->tagManager->getTagsByIds([$tagId]); |
|
| 154 | - $tag = current($tags); |
|
| 155 | - if (!$this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
| 156 | - return false; |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - return $result; |
|
| 161 | - } catch (\InvalidArgumentException $e) { |
|
| 162 | - throw new BadRequest('Invalid tag id', 0, $e); |
|
| 163 | - } catch (TagNotFoundException $e) { |
|
| 164 | - return false; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - function delete() { |
|
| 169 | - throw new Forbidden('Permission denied to delete this collection'); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - function getName() { |
|
| 173 | - return $this->objectId; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - function setName($name) { |
|
| 177 | - throw new Forbidden('Permission denied to rename this collection'); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Returns the last modification time, as a unix timestamp |
|
| 182 | - * |
|
| 183 | - * @return int |
|
| 184 | - */ |
|
| 185 | - function getLastModified() { |
|
| 186 | - return null; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Create a sabre node for the mapping of the |
|
| 191 | - * given system tag to the collection's object |
|
| 192 | - * |
|
| 193 | - * @param ISystemTag $tag |
|
| 194 | - * |
|
| 195 | - * @return SystemTagMappingNode |
|
| 196 | - */ |
|
| 197 | - private function makeNode(ISystemTag $tag) { |
|
| 198 | - return new SystemTagMappingNode( |
|
| 199 | - $tag, |
|
| 200 | - $this->objectId, |
|
| 201 | - $this->objectType, |
|
| 202 | - $this->user, |
|
| 203 | - $this->tagManager, |
|
| 204 | - $this->tagMapper |
|
| 205 | - ); |
|
| 206 | - } |
|
| 42 | + /** |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + private $objectId; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var string |
|
| 49 | + */ |
|
| 50 | + private $objectType; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var ISystemTagManager |
|
| 54 | + */ |
|
| 55 | + private $tagManager; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @var ISystemTagObjectMapper |
|
| 59 | + */ |
|
| 60 | + private $tagMapper; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * User |
|
| 64 | + * |
|
| 65 | + * @var IUser |
|
| 66 | + */ |
|
| 67 | + private $user; |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Constructor |
|
| 72 | + * |
|
| 73 | + * @param string $objectId object id |
|
| 74 | + * @param string $objectType object type |
|
| 75 | + * @param IUser $user user |
|
| 76 | + * @param ISystemTagManager $tagManager tag manager |
|
| 77 | + * @param ISystemTagObjectMapper $tagMapper tag mapper |
|
| 78 | + */ |
|
| 79 | + public function __construct( |
|
| 80 | + $objectId, |
|
| 81 | + $objectType, |
|
| 82 | + IUser $user, |
|
| 83 | + ISystemTagManager $tagManager, |
|
| 84 | + ISystemTagObjectMapper $tagMapper |
|
| 85 | + ) { |
|
| 86 | + $this->tagManager = $tagManager; |
|
| 87 | + $this->tagMapper = $tagMapper; |
|
| 88 | + $this->objectId = $objectId; |
|
| 89 | + $this->objectType = $objectType; |
|
| 90 | + $this->user = $user; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + function createFile($tagId, $data = null) { |
|
| 94 | + try { |
|
| 95 | + $tags = $this->tagManager->getTagsByIds([$tagId]); |
|
| 96 | + $tag = current($tags); |
|
| 97 | + if (!$this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
| 98 | + throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign'); |
|
| 99 | + } |
|
| 100 | + if (!$this->tagManager->canUserAssignTag($tag, $this->user)) { |
|
| 101 | + throw new Forbidden('No permission to assign tag ' . $tagId); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $this->tagMapper->assignTags($this->objectId, $this->objectType, $tagId); |
|
| 105 | + } catch (TagNotFoundException $e) { |
|
| 106 | + throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign'); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + function createDirectory($name) { |
|
| 111 | + throw new Forbidden('Permission denied to create collections'); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + function getChild($tagId) { |
|
| 115 | + try { |
|
| 116 | + if ($this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true)) { |
|
| 117 | + $tag = $this->tagManager->getTagsByIds([$tagId]); |
|
| 118 | + $tag = current($tag); |
|
| 119 | + if ($this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
| 120 | + return $this->makeNode($tag); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + throw new NotFound('Tag with id ' . $tagId . ' not present for object ' . $this->objectId); |
|
| 124 | + } catch (\InvalidArgumentException $e) { |
|
| 125 | + throw new BadRequest('Invalid tag id', 0, $e); |
|
| 126 | + } catch (TagNotFoundException $e) { |
|
| 127 | + throw new NotFound('Tag with id ' . $tagId . ' not found', 0, $e); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + function getChildren() { |
|
| 132 | + $tagIds = current($this->tagMapper->getTagIdsForObjects([$this->objectId], $this->objectType)); |
|
| 133 | + if (empty($tagIds)) { |
|
| 134 | + return []; |
|
| 135 | + } |
|
| 136 | + $tags = $this->tagManager->getTagsByIds($tagIds); |
|
| 137 | + |
|
| 138 | + // filter out non-visible tags |
|
| 139 | + $tags = array_filter($tags, function($tag) { |
|
| 140 | + return $this->tagManager->canUserSeeTag($tag, $this->user); |
|
| 141 | + }); |
|
| 142 | + |
|
| 143 | + return array_values(array_map(function($tag) { |
|
| 144 | + return $this->makeNode($tag); |
|
| 145 | + }, $tags)); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + function childExists($tagId) { |
|
| 149 | + try { |
|
| 150 | + $result = $this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true); |
|
| 151 | + |
|
| 152 | + if ($result) { |
|
| 153 | + $tags = $this->tagManager->getTagsByIds([$tagId]); |
|
| 154 | + $tag = current($tags); |
|
| 155 | + if (!$this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
| 156 | + return false; |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + return $result; |
|
| 161 | + } catch (\InvalidArgumentException $e) { |
|
| 162 | + throw new BadRequest('Invalid tag id', 0, $e); |
|
| 163 | + } catch (TagNotFoundException $e) { |
|
| 164 | + return false; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + function delete() { |
|
| 169 | + throw new Forbidden('Permission denied to delete this collection'); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + function getName() { |
|
| 173 | + return $this->objectId; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + function setName($name) { |
|
| 177 | + throw new Forbidden('Permission denied to rename this collection'); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Returns the last modification time, as a unix timestamp |
|
| 182 | + * |
|
| 183 | + * @return int |
|
| 184 | + */ |
|
| 185 | + function getLastModified() { |
|
| 186 | + return null; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Create a sabre node for the mapping of the |
|
| 191 | + * given system tag to the collection's object |
|
| 192 | + * |
|
| 193 | + * @param ISystemTag $tag |
|
| 194 | + * |
|
| 195 | + * @return SystemTagMappingNode |
|
| 196 | + */ |
|
| 197 | + private function makeNode(ISystemTag $tag) { |
|
| 198 | + return new SystemTagMappingNode( |
|
| 199 | + $tag, |
|
| 200 | + $this->objectId, |
|
| 201 | + $this->objectType, |
|
| 202 | + $this->user, |
|
| 203 | + $this->tagManager, |
|
| 204 | + $this->tagMapper |
|
| 205 | + ); |
|
| 206 | + } |
|
| 207 | 207 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | require '../../../../3rdparty/autoload.php'; |
| 24 | 24 | |
| 25 | 25 | if ($argc !== 6) { |
| 26 | - echo "Invalid number of arguments" . PHP_EOL; |
|
| 26 | + echo "Invalid number of arguments".PHP_EOL; |
|
| 27 | 27 | exit; |
| 28 | 28 | } |
| 29 | 29 | |
@@ -37,9 +37,9 @@ discard block |
||
| 37 | 37 | $t0 = microtime(true); |
| 38 | 38 | $result = $client->request($method, $uploadUrl, $data, $headers); |
| 39 | 39 | $t1 = microtime(true); |
| 40 | - echo $result['statusCode'] . " - " . ($t1 - $t0) . ' seconds' . PHP_EOL; |
|
| 41 | - if (!in_array($result['statusCode'], [200, 201])) { |
|
| 42 | - echo $result['body'] . PHP_EOL; |
|
| 40 | + echo $result['statusCode']." - ".($t1 - $t0).' seconds'.PHP_EOL; |
|
| 41 | + if (!in_array($result['statusCode'], [200, 201])) { |
|
| 42 | + echo $result['body'].PHP_EOL; |
|
| 43 | 43 | } |
| 44 | 44 | return $result; |
| 45 | 45 | } |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | $stream = fopen($file, 'r'); |
| 66 | 66 | |
| 67 | 67 | $index = 0; |
| 68 | -while(!feof($stream)) { |
|
| 68 | +while (!feof($stream)) { |
|
| 69 | 69 | request($client, 'PUT', "$uploadUrl/$index", fread($stream, $chunkSize)); |
| 70 | 70 | $index++; |
| 71 | 71 | } |
@@ -23,8 +23,8 @@ discard block |
||
| 23 | 23 | require '../../../../3rdparty/autoload.php'; |
| 24 | 24 | |
| 25 | 25 | if ($argc !== 6) { |
| 26 | - echo "Invalid number of arguments" . PHP_EOL; |
|
| 27 | - exit; |
|
| 26 | + echo "Invalid number of arguments" . PHP_EOL; |
|
| 27 | + exit; |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -33,15 +33,15 @@ discard block |
||
| 33 | 33 | * @return mixed |
| 34 | 34 | */ |
| 35 | 35 | function request($client, $method, $uploadUrl, $data = null, $headers = []) { |
| 36 | - echo "$method $uploadUrl ... "; |
|
| 37 | - $t0 = microtime(true); |
|
| 38 | - $result = $client->request($method, $uploadUrl, $data, $headers); |
|
| 39 | - $t1 = microtime(true); |
|
| 40 | - echo $result['statusCode'] . " - " . ($t1 - $t0) . ' seconds' . PHP_EOL; |
|
| 41 | - if (!in_array($result['statusCode'], [200, 201])) { |
|
| 42 | - echo $result['body'] . PHP_EOL; |
|
| 43 | - } |
|
| 44 | - return $result; |
|
| 36 | + echo "$method $uploadUrl ... "; |
|
| 37 | + $t0 = microtime(true); |
|
| 38 | + $result = $client->request($method, $uploadUrl, $data, $headers); |
|
| 39 | + $t1 = microtime(true); |
|
| 40 | + echo $result['statusCode'] . " - " . ($t1 - $t0) . ' seconds' . PHP_EOL; |
|
| 41 | + if (!in_array($result['statusCode'], [200, 201])) { |
|
| 42 | + echo $result['body'] . PHP_EOL; |
|
| 43 | + } |
|
| 44 | + return $result; |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | $baseUri = $argv[1]; |
@@ -51,9 +51,9 @@ discard block |
||
| 51 | 51 | $chunkSize = $argv[5] * 1024 * 1024; |
| 52 | 52 | |
| 53 | 53 | $client = new \Sabre\DAV\Client([ |
| 54 | - 'baseUri' => $baseUri, |
|
| 55 | - 'userName' => $userName, |
|
| 56 | - 'password' => $password |
|
| 54 | + 'baseUri' => $baseUri, |
|
| 55 | + 'userName' => $userName, |
|
| 56 | + 'password' => $password |
|
| 57 | 57 | ]); |
| 58 | 58 | |
| 59 | 59 | $transfer = uniqid('transfer', true); |
@@ -66,14 +66,14 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | $index = 0; |
| 68 | 68 | while(!feof($stream)) { |
| 69 | - request($client, 'PUT', "$uploadUrl/$index", fread($stream, $chunkSize)); |
|
| 70 | - $index++; |
|
| 69 | + request($client, 'PUT', "$uploadUrl/$index", fread($stream, $chunkSize)); |
|
| 70 | + $index++; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | $destination = pathinfo($file, PATHINFO_BASENAME); |
| 74 | 74 | //echo "Moving $uploadUrl/.file to it's final destination $baseUri/files/$userName/$destination" . PHP_EOL; |
| 75 | 75 | request($client, 'MOVE', "$uploadUrl/.file", null, [ |
| 76 | - 'Destination' => "$baseUri/files/$userName/$destination", |
|
| 77 | - 'OC-Total-Length' => filesize($file), |
|
| 78 | - 'X-OC-MTime' => filemtime($file) |
|
| 76 | + 'Destination' => "$baseUri/files/$userName/$destination", |
|
| 77 | + 'OC-Total-Length' => filesize($file), |
|
| 78 | + 'X-OC-MTime' => filemtime($file) |
|
| 79 | 79 | ]); |
@@ -115,7 +115,7 @@ |
||
| 115 | 115 | \OC_Util::setupFS($user); |
| 116 | 116 | |
| 117 | 117 | // Check if this user has a version directory |
| 118 | - $view = new \OC\Files\View('/' . $user); |
|
| 118 | + $view = new \OC\Files\View('/'.$user); |
|
| 119 | 119 | if (!$view->is_dir('/files_versions')) { |
| 120 | 120 | return false; |
| 121 | 121 | } |
@@ -35,93 +35,93 @@ |
||
| 35 | 35 | |
| 36 | 36 | class ExpireVersions extends Command { |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @var Expiration |
|
| 40 | - */ |
|
| 41 | - private $expiration; |
|
| 38 | + /** |
|
| 39 | + * @var Expiration |
|
| 40 | + */ |
|
| 41 | + private $expiration; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @var IUserManager |
|
| 45 | - */ |
|
| 46 | - private $userManager; |
|
| 43 | + /** |
|
| 44 | + * @var IUserManager |
|
| 45 | + */ |
|
| 46 | + private $userManager; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @param IUserManager $userManager |
|
| 50 | - * @param Expiration $expiration |
|
| 51 | - */ |
|
| 52 | - public function __construct(IUserManager $userManager, |
|
| 53 | - Expiration $expiration) { |
|
| 54 | - parent::__construct(); |
|
| 48 | + /** |
|
| 49 | + * @param IUserManager $userManager |
|
| 50 | + * @param Expiration $expiration |
|
| 51 | + */ |
|
| 52 | + public function __construct(IUserManager $userManager, |
|
| 53 | + Expiration $expiration) { |
|
| 54 | + parent::__construct(); |
|
| 55 | 55 | |
| 56 | - $this->userManager = $userManager; |
|
| 57 | - $this->expiration = $expiration; |
|
| 58 | - } |
|
| 56 | + $this->userManager = $userManager; |
|
| 57 | + $this->expiration = $expiration; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - protected function configure() { |
|
| 61 | - $this |
|
| 62 | - ->setName('versions:expire') |
|
| 63 | - ->setDescription('Expires the users file versions') |
|
| 64 | - ->addArgument( |
|
| 65 | - 'user_id', |
|
| 66 | - InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
| 67 | - 'expire file versions of the given user(s), if no user is given file versions for all users will be expired.' |
|
| 68 | - ); |
|
| 69 | - } |
|
| 60 | + protected function configure() { |
|
| 61 | + $this |
|
| 62 | + ->setName('versions:expire') |
|
| 63 | + ->setDescription('Expires the users file versions') |
|
| 64 | + ->addArgument( |
|
| 65 | + 'user_id', |
|
| 66 | + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
| 67 | + 'expire file versions of the given user(s), if no user is given file versions for all users will be expired.' |
|
| 68 | + ); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 71 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 72 | 72 | |
| 73 | - $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
| 74 | - if (!$maxAge) { |
|
| 75 | - $output->writeln("No expiry configured."); |
|
| 76 | - return; |
|
| 77 | - } |
|
| 73 | + $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
| 74 | + if (!$maxAge) { |
|
| 75 | + $output->writeln("No expiry configured."); |
|
| 76 | + return; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - $users = $input->getArgument('user_id'); |
|
| 80 | - if (!empty($users)) { |
|
| 81 | - foreach ($users as $user) { |
|
| 82 | - if ($this->userManager->userExists($user)) { |
|
| 83 | - $output->writeln("Remove deleted files of <info>$user</info>"); |
|
| 84 | - $userObject = $this->userManager->get($user); |
|
| 85 | - $this->expireVersionsForUser($userObject); |
|
| 86 | - } else { |
|
| 87 | - $output->writeln("<error>Unknown user $user</error>"); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - } else { |
|
| 91 | - $p = new ProgressBar($output); |
|
| 92 | - $p->start(); |
|
| 93 | - $this->userManager->callForSeenUsers(function(IUser $user) use ($p) { |
|
| 94 | - $p->advance(); |
|
| 95 | - $this->expireVersionsForUser($user); |
|
| 96 | - }); |
|
| 97 | - $p->finish(); |
|
| 98 | - $output->writeln(''); |
|
| 99 | - } |
|
| 100 | - } |
|
| 79 | + $users = $input->getArgument('user_id'); |
|
| 80 | + if (!empty($users)) { |
|
| 81 | + foreach ($users as $user) { |
|
| 82 | + if ($this->userManager->userExists($user)) { |
|
| 83 | + $output->writeln("Remove deleted files of <info>$user</info>"); |
|
| 84 | + $userObject = $this->userManager->get($user); |
|
| 85 | + $this->expireVersionsForUser($userObject); |
|
| 86 | + } else { |
|
| 87 | + $output->writeln("<error>Unknown user $user</error>"); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + } else { |
|
| 91 | + $p = new ProgressBar($output); |
|
| 92 | + $p->start(); |
|
| 93 | + $this->userManager->callForSeenUsers(function(IUser $user) use ($p) { |
|
| 94 | + $p->advance(); |
|
| 95 | + $this->expireVersionsForUser($user); |
|
| 96 | + }); |
|
| 97 | + $p->finish(); |
|
| 98 | + $output->writeln(''); |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - function expireVersionsForUser(IUser $user) { |
|
| 103 | - $uid = $user->getUID(); |
|
| 104 | - if (!$this->setupFS($uid)) { |
|
| 105 | - return; |
|
| 106 | - } |
|
| 107 | - Storage::expireOlderThanMaxForUser($uid); |
|
| 108 | - } |
|
| 102 | + function expireVersionsForUser(IUser $user) { |
|
| 103 | + $uid = $user->getUID(); |
|
| 104 | + if (!$this->setupFS($uid)) { |
|
| 105 | + return; |
|
| 106 | + } |
|
| 107 | + Storage::expireOlderThanMaxForUser($uid); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Act on behalf on versions item owner |
|
| 112 | - * @param string $user |
|
| 113 | - * @return boolean |
|
| 114 | - */ |
|
| 115 | - protected function setupFS($user) { |
|
| 116 | - \OC_Util::tearDownFS(); |
|
| 117 | - \OC_Util::setupFS($user); |
|
| 110 | + /** |
|
| 111 | + * Act on behalf on versions item owner |
|
| 112 | + * @param string $user |
|
| 113 | + * @return boolean |
|
| 114 | + */ |
|
| 115 | + protected function setupFS($user) { |
|
| 116 | + \OC_Util::tearDownFS(); |
|
| 117 | + \OC_Util::setupFS($user); |
|
| 118 | 118 | |
| 119 | - // Check if this user has a version directory |
|
| 120 | - $view = new \OC\Files\View('/' . $user); |
|
| 121 | - if (!$view->is_dir('/files_versions')) { |
|
| 122 | - return false; |
|
| 123 | - } |
|
| 119 | + // Check if this user has a version directory |
|
| 120 | + $view = new \OC\Files\View('/' . $user); |
|
| 121 | + if (!$view->is_dir('/files_versions')) { |
|
| 122 | + return false; |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - return true; |
|
| 126 | - } |
|
| 125 | + return true; |
|
| 126 | + } |
|
| 127 | 127 | } |
@@ -33,83 +33,83 @@ |
||
| 33 | 33 | |
| 34 | 34 | class CleanUp extends Command { |
| 35 | 35 | |
| 36 | - /** @var IUserManager */ |
|
| 37 | - protected $userManager; |
|
| 38 | - |
|
| 39 | - /** @var IRootFolder */ |
|
| 40 | - protected $rootFolder; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @param IRootFolder $rootFolder |
|
| 44 | - * @param IUserManager $userManager |
|
| 45 | - */ |
|
| 46 | - function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
|
| 47 | - parent::__construct(); |
|
| 48 | - $this->userManager = $userManager; |
|
| 49 | - $this->rootFolder = $rootFolder; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - protected function configure() { |
|
| 53 | - $this |
|
| 54 | - ->setName('versions:cleanup') |
|
| 55 | - ->setDescription('Delete versions') |
|
| 56 | - ->addArgument( |
|
| 57 | - 'user_id', |
|
| 58 | - InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
| 59 | - 'delete versions of the given user(s), if no user is given all versions will be deleted' |
|
| 60 | - ); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 65 | - |
|
| 66 | - $users = $input->getArgument('user_id'); |
|
| 67 | - if (!empty($users)) { |
|
| 68 | - foreach ($users as $user) { |
|
| 69 | - if ($this->userManager->userExists($user)) { |
|
| 70 | - $output->writeln("Delete versions of <info>$user</info>"); |
|
| 71 | - $this->deleteVersions($user); |
|
| 72 | - } else { |
|
| 73 | - $output->writeln("<error>Unknown user $user</error>"); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - } else { |
|
| 77 | - $output->writeln('Delete all versions'); |
|
| 78 | - foreach ($this->userManager->getBackends() as $backend) { |
|
| 79 | - $name = get_class($backend); |
|
| 80 | - |
|
| 81 | - if ($backend instanceof IUserBackend) { |
|
| 82 | - $name = $backend->getBackendName(); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - $output->writeln("Delete versions for users on backend <info>$name</info>"); |
|
| 86 | - |
|
| 87 | - $limit = 500; |
|
| 88 | - $offset = 0; |
|
| 89 | - do { |
|
| 90 | - $users = $backend->getUsers('', $limit, $offset); |
|
| 91 | - foreach ($users as $user) { |
|
| 92 | - $output->writeln(" <info>$user</info>"); |
|
| 93 | - $this->deleteVersions($user); |
|
| 94 | - } |
|
| 95 | - $offset += $limit; |
|
| 96 | - } while (count($users) >= $limit); |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * delete versions for the given user |
|
| 104 | - * |
|
| 105 | - * @param string $user |
|
| 106 | - */ |
|
| 107 | - protected function deleteVersions($user) { |
|
| 108 | - \OC_Util::tearDownFS(); |
|
| 109 | - \OC_Util::setupFS($user); |
|
| 110 | - if ($this->rootFolder->nodeExists('/' . $user . '/files_versions')) { |
|
| 111 | - $this->rootFolder->get('/' . $user . '/files_versions')->delete(); |
|
| 112 | - } |
|
| 113 | - } |
|
| 36 | + /** @var IUserManager */ |
|
| 37 | + protected $userManager; |
|
| 38 | + |
|
| 39 | + /** @var IRootFolder */ |
|
| 40 | + protected $rootFolder; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @param IRootFolder $rootFolder |
|
| 44 | + * @param IUserManager $userManager |
|
| 45 | + */ |
|
| 46 | + function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
|
| 47 | + parent::__construct(); |
|
| 48 | + $this->userManager = $userManager; |
|
| 49 | + $this->rootFolder = $rootFolder; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + protected function configure() { |
|
| 53 | + $this |
|
| 54 | + ->setName('versions:cleanup') |
|
| 55 | + ->setDescription('Delete versions') |
|
| 56 | + ->addArgument( |
|
| 57 | + 'user_id', |
|
| 58 | + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
| 59 | + 'delete versions of the given user(s), if no user is given all versions will be deleted' |
|
| 60 | + ); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 65 | + |
|
| 66 | + $users = $input->getArgument('user_id'); |
|
| 67 | + if (!empty($users)) { |
|
| 68 | + foreach ($users as $user) { |
|
| 69 | + if ($this->userManager->userExists($user)) { |
|
| 70 | + $output->writeln("Delete versions of <info>$user</info>"); |
|
| 71 | + $this->deleteVersions($user); |
|
| 72 | + } else { |
|
| 73 | + $output->writeln("<error>Unknown user $user</error>"); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + } else { |
|
| 77 | + $output->writeln('Delete all versions'); |
|
| 78 | + foreach ($this->userManager->getBackends() as $backend) { |
|
| 79 | + $name = get_class($backend); |
|
| 80 | + |
|
| 81 | + if ($backend instanceof IUserBackend) { |
|
| 82 | + $name = $backend->getBackendName(); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + $output->writeln("Delete versions for users on backend <info>$name</info>"); |
|
| 86 | + |
|
| 87 | + $limit = 500; |
|
| 88 | + $offset = 0; |
|
| 89 | + do { |
|
| 90 | + $users = $backend->getUsers('', $limit, $offset); |
|
| 91 | + foreach ($users as $user) { |
|
| 92 | + $output->writeln(" <info>$user</info>"); |
|
| 93 | + $this->deleteVersions($user); |
|
| 94 | + } |
|
| 95 | + $offset += $limit; |
|
| 96 | + } while (count($users) >= $limit); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * delete versions for the given user |
|
| 104 | + * |
|
| 105 | + * @param string $user |
|
| 106 | + */ |
|
| 107 | + protected function deleteVersions($user) { |
|
| 108 | + \OC_Util::tearDownFS(); |
|
| 109 | + \OC_Util::setupFS($user); |
|
| 110 | + if ($this->rootFolder->nodeExists('/' . $user . '/files_versions')) { |
|
| 111 | + $this->rootFolder->get('/' . $user . '/files_versions')->delete(); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | 115 | } |
@@ -107,8 +107,8 @@ |
||
| 107 | 107 | protected function deleteVersions($user) { |
| 108 | 108 | \OC_Util::tearDownFS(); |
| 109 | 109 | \OC_Util::setupFS($user); |
| 110 | - if ($this->rootFolder->nodeExists('/' . $user . '/files_versions')) { |
|
| 111 | - $this->rootFolder->get('/' . $user . '/files_versions')->delete(); |
|
| 110 | + if ($this->rootFolder->nodeExists('/'.$user.'/files_versions')) { |
|
| 111 | + $this->rootFolder->get('/'.$user.'/files_versions')->delete(); |
|
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
@@ -29,16 +29,16 @@ |
||
| 29 | 29 | |
| 30 | 30 | class Capabilities implements ICapability { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Return this classes capabilities |
|
| 34 | - * |
|
| 35 | - * @return array |
|
| 36 | - */ |
|
| 37 | - public function getCapabilities() { |
|
| 38 | - return [ |
|
| 39 | - 'files' => [ |
|
| 40 | - 'versioning' => true |
|
| 41 | - ] |
|
| 42 | - ]; |
|
| 43 | - } |
|
| 32 | + /** |
|
| 33 | + * Return this classes capabilities |
|
| 34 | + * |
|
| 35 | + * @return array |
|
| 36 | + */ |
|
| 37 | + public function getCapabilities() { |
|
| 38 | + return [ |
|
| 39 | + 'files' => [ |
|
| 40 | + 'versioning' => true |
|
| 41 | + ] |
|
| 42 | + ]; |
|
| 43 | + } |
|
| 44 | 44 | } |
@@ -86,7 +86,7 @@ |
||
| 86 | 86 | \OC_Util::setupFS($user); |
| 87 | 87 | |
| 88 | 88 | // Check if this user has a versions directory |
| 89 | - $view = new \OC\Files\View('/' . $user); |
|
| 89 | + $view = new \OC\Files\View('/'.$user); |
|
| 90 | 90 | if (!$view->is_dir('/files_versions')) { |
| 91 | 91 | return false; |
| 92 | 92 | } |
@@ -32,56 +32,56 @@ |
||
| 32 | 32 | |
| 33 | 33 | class ExpireVersions extends \OC\BackgroundJob\TimedJob { |
| 34 | 34 | |
| 35 | - const ITEMS_PER_SESSION = 1000; |
|
| 35 | + const ITEMS_PER_SESSION = 1000; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var Expiration |
|
| 39 | - */ |
|
| 40 | - private $expiration; |
|
| 37 | + /** |
|
| 38 | + * @var Expiration |
|
| 39 | + */ |
|
| 40 | + private $expiration; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var IUserManager |
|
| 44 | - */ |
|
| 45 | - private $userManager; |
|
| 42 | + /** |
|
| 43 | + * @var IUserManager |
|
| 44 | + */ |
|
| 45 | + private $userManager; |
|
| 46 | 46 | |
| 47 | - public function __construct(IUserManager $userManager, Expiration $expiration) { |
|
| 48 | - // Run once per 30 minutes |
|
| 49 | - $this->setInterval(60 * 30); |
|
| 47 | + public function __construct(IUserManager $userManager, Expiration $expiration) { |
|
| 48 | + // Run once per 30 minutes |
|
| 49 | + $this->setInterval(60 * 30); |
|
| 50 | 50 | |
| 51 | - $this->expiration = $expiration; |
|
| 52 | - $this->userManager = $userManager; |
|
| 53 | - } |
|
| 51 | + $this->expiration = $expiration; |
|
| 52 | + $this->userManager = $userManager; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - protected function run($argument) { |
|
| 56 | - $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
| 57 | - if (!$maxAge) { |
|
| 58 | - return; |
|
| 59 | - } |
|
| 55 | + protected function run($argument) { |
|
| 56 | + $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
| 57 | + if (!$maxAge) { |
|
| 58 | + return; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $this->userManager->callForSeenUsers(function(IUser $user) { |
|
| 62 | - $uid = $user->getUID(); |
|
| 63 | - if (!$this->setupFS($uid)) { |
|
| 64 | - return; |
|
| 65 | - } |
|
| 66 | - Storage::expireOlderThanMaxForUser($uid); |
|
| 67 | - }); |
|
| 68 | - } |
|
| 61 | + $this->userManager->callForSeenUsers(function(IUser $user) { |
|
| 62 | + $uid = $user->getUID(); |
|
| 63 | + if (!$this->setupFS($uid)) { |
|
| 64 | + return; |
|
| 65 | + } |
|
| 66 | + Storage::expireOlderThanMaxForUser($uid); |
|
| 67 | + }); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Act on behalf on trash item owner |
|
| 72 | - * @param string $user |
|
| 73 | - * @return boolean |
|
| 74 | - */ |
|
| 75 | - protected function setupFS($user) { |
|
| 76 | - \OC_Util::tearDownFS(); |
|
| 77 | - \OC_Util::setupFS($user); |
|
| 70 | + /** |
|
| 71 | + * Act on behalf on trash item owner |
|
| 72 | + * @param string $user |
|
| 73 | + * @return boolean |
|
| 74 | + */ |
|
| 75 | + protected function setupFS($user) { |
|
| 76 | + \OC_Util::tearDownFS(); |
|
| 77 | + \OC_Util::setupFS($user); |
|
| 78 | 78 | |
| 79 | - // Check if this user has a versions directory |
|
| 80 | - $view = new \OC\Files\View('/' . $user); |
|
| 81 | - if (!$view->is_dir('/files_versions')) { |
|
| 82 | - return false; |
|
| 83 | - } |
|
| 79 | + // Check if this user has a versions directory |
|
| 80 | + $view = new \OC\Files\View('/' . $user); |
|
| 81 | + if (!$view->is_dir('/files_versions')) { |
|
| 82 | + return false; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - return true; |
|
| 86 | - } |
|
| 85 | + return true; |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -31,20 +31,20 @@ |
||
| 31 | 31 | |
| 32 | 32 | $application = new Application(); |
| 33 | 33 | $application->registerRoutes($this, [ |
| 34 | - 'routes' => [ |
|
| 35 | - [ |
|
| 36 | - 'name' => 'Preview#getPreview', |
|
| 37 | - 'url' => '/preview', |
|
| 38 | - 'verb' => 'GET', |
|
| 39 | - ], |
|
| 40 | - ], |
|
| 34 | + 'routes' => [ |
|
| 35 | + [ |
|
| 36 | + 'name' => 'Preview#getPreview', |
|
| 37 | + 'url' => '/preview', |
|
| 38 | + 'verb' => 'GET', |
|
| 39 | + ], |
|
| 40 | + ], |
|
| 41 | 41 | ]); |
| 42 | 42 | |
| 43 | 43 | /** @var $this \OCP\Route\IRouter */ |
| 44 | 44 | $this->create('files_versions_download', 'download.php') |
| 45 | - ->actionInclude('files_versions/download.php'); |
|
| 45 | + ->actionInclude('files_versions/download.php'); |
|
| 46 | 46 | $this->create('files_versions_ajax_getVersions', 'ajax/getVersions.php') |
| 47 | - ->actionInclude('files_versions/ajax/getVersions.php'); |
|
| 47 | + ->actionInclude('files_versions/ajax/getVersions.php'); |
|
| 48 | 48 | $this->create('files_versions_ajax_rollbackVersion', 'ajax/rollbackVersion.php') |
| 49 | - ->actionInclude('files_versions/ajax/rollbackVersion.php'); |
|
| 49 | + ->actionInclude('files_versions/ajax/rollbackVersion.php'); |
|
| 50 | 50 | |