@@ -23,11 +23,11 @@ |
||
| 23 | 23 | |
| 24 | 24 | class PublicCalendarObject extends CalendarObject { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * public calendars are always shared |
|
| 28 | - * @return bool |
|
| 29 | - */ |
|
| 30 | - protected function isShared() { |
|
| 31 | - return true; |
|
| 32 | - } |
|
| 26 | + /** |
|
| 27 | + * public calendars are always shared |
|
| 28 | + * @return bool |
|
| 29 | + */ |
|
| 30 | + protected function isShared() { |
|
| 31 | + return true; |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -27,17 +27,17 @@ |
||
| 27 | 27 | |
| 28 | 28 | class SearchTermFilter implements XmlDeserializable { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @param Reader $reader |
|
| 32 | - * @throws BadRequest |
|
| 33 | - * @return string |
|
| 34 | - */ |
|
| 35 | - public static function xmlDeserialize(Reader $reader) { |
|
| 36 | - $value = $reader->parseInnerTree(); |
|
| 37 | - if (!is_string($value)) { |
|
| 38 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}search-term has illegal value'); |
|
| 39 | - } |
|
| 30 | + /** |
|
| 31 | + * @param Reader $reader |
|
| 32 | + * @throws BadRequest |
|
| 33 | + * @return string |
|
| 34 | + */ |
|
| 35 | + public static function xmlDeserialize(Reader $reader) { |
|
| 36 | + $value = $reader->parseInnerTree(); |
|
| 37 | + if (!is_string($value)) { |
|
| 38 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}search-term has illegal value'); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - return $value; |
|
| 42 | - } |
|
| 41 | + return $value; |
|
| 42 | + } |
|
| 43 | 43 | } |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | public static function xmlDeserialize(Reader $reader) { |
| 36 | 36 | $value = $reader->parseInnerTree(); |
| 37 | 37 | if (!is_string($value)) { |
| 38 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}search-term has illegal value'); |
|
| 38 | + throw new BadRequest('The {'.SearchPlugin::NS_Nextcloud.'}search-term has illegal value'); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | return $value; |
@@ -35,144 +35,144 @@ |
||
| 35 | 35 | |
| 36 | 36 | class SystemTagsByIdCollection implements ICollection { |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @var ISystemTagManager |
|
| 40 | - */ |
|
| 41 | - private $tagManager; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var IGroupManager |
|
| 45 | - */ |
|
| 46 | - private $groupManager; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var IUserSession |
|
| 50 | - */ |
|
| 51 | - private $userSession; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * SystemTagsByIdCollection constructor. |
|
| 55 | - * |
|
| 56 | - * @param ISystemTagManager $tagManager |
|
| 57 | - * @param IUserSession $userSession |
|
| 58 | - * @param IGroupManager $groupManager |
|
| 59 | - */ |
|
| 60 | - public function __construct( |
|
| 61 | - ISystemTagManager $tagManager, |
|
| 62 | - IUserSession $userSession, |
|
| 63 | - IGroupManager $groupManager |
|
| 64 | - ) { |
|
| 65 | - $this->tagManager = $tagManager; |
|
| 66 | - $this->userSession = $userSession; |
|
| 67 | - $this->groupManager = $groupManager; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Returns whether the currently logged in user is an administrator |
|
| 72 | - * |
|
| 73 | - * @return bool true if the user is an admin |
|
| 74 | - */ |
|
| 75 | - private function isAdmin() { |
|
| 76 | - $user = $this->userSession->getUser(); |
|
| 77 | - if ($user !== null) { |
|
| 78 | - return $this->groupManager->isAdmin($user->getUID()); |
|
| 79 | - } |
|
| 80 | - return false; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @param string $name |
|
| 85 | - * @param resource|string $data Initial payload |
|
| 86 | - * @throws Forbidden |
|
| 87 | - */ |
|
| 88 | - public function createFile($name, $data = null) { |
|
| 89 | - throw new Forbidden('Cannot create tags by id'); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @param string $name |
|
| 94 | - */ |
|
| 95 | - public function createDirectory($name) { |
|
| 96 | - throw new Forbidden('Permission denied to create collections'); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @param string $name |
|
| 101 | - */ |
|
| 102 | - public function getChild($name) { |
|
| 103 | - try { |
|
| 104 | - $tag = $this->tagManager->getTagsByIds([$name]); |
|
| 105 | - $tag = current($tag); |
|
| 106 | - if (!$this->tagManager->canUserSeeTag($tag, $this->userSession->getUser())) { |
|
| 107 | - throw new NotFound('Tag with id ' . $name . ' not found'); |
|
| 108 | - } |
|
| 109 | - return $this->makeNode($tag); |
|
| 110 | - } catch (\InvalidArgumentException $e) { |
|
| 111 | - throw new BadRequest('Invalid tag id', 0, $e); |
|
| 112 | - } catch (TagNotFoundException $e) { |
|
| 113 | - throw new NotFound('Tag with id ' . $name . ' not found', 0, $e); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - public function getChildren() { |
|
| 118 | - $visibilityFilter = true; |
|
| 119 | - if ($this->isAdmin()) { |
|
| 120 | - $visibilityFilter = null; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - $tags = $this->tagManager->getAllTags($visibilityFilter); |
|
| 124 | - return array_map(function ($tag) { |
|
| 125 | - return $this->makeNode($tag); |
|
| 126 | - }, $tags); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @param string $name |
|
| 131 | - */ |
|
| 132 | - public function childExists($name) { |
|
| 133 | - try { |
|
| 134 | - $tag = $this->tagManager->getTagsByIds([$name]); |
|
| 135 | - $tag = current($tag); |
|
| 136 | - if (!$this->tagManager->canUserSeeTag($tag, $this->userSession->getUser())) { |
|
| 137 | - return false; |
|
| 138 | - } |
|
| 139 | - return true; |
|
| 140 | - } catch (\InvalidArgumentException $e) { |
|
| 141 | - throw new BadRequest('Invalid tag id', 0, $e); |
|
| 142 | - } catch (TagNotFoundException $e) { |
|
| 143 | - return false; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - public function delete() { |
|
| 148 | - throw new Forbidden('Permission denied to delete this collection'); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - public function getName() { |
|
| 152 | - return 'systemtags'; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - public function setName($name) { |
|
| 156 | - throw new Forbidden('Permission denied to rename this collection'); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Returns the last modification time, as a unix timestamp |
|
| 161 | - * |
|
| 162 | - * @return int |
|
| 163 | - */ |
|
| 164 | - public function getLastModified() { |
|
| 165 | - return null; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Create a sabre node for the given system tag |
|
| 170 | - * |
|
| 171 | - * @param ISystemTag $tag |
|
| 172 | - * |
|
| 173 | - * @return SystemTagNode |
|
| 174 | - */ |
|
| 175 | - private function makeNode(ISystemTag $tag) { |
|
| 176 | - return new SystemTagNode($tag, $this->userSession->getUser(), $this->isAdmin(), $this->tagManager); |
|
| 177 | - } |
|
| 38 | + /** |
|
| 39 | + * @var ISystemTagManager |
|
| 40 | + */ |
|
| 41 | + private $tagManager; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var IGroupManager |
|
| 45 | + */ |
|
| 46 | + private $groupManager; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var IUserSession |
|
| 50 | + */ |
|
| 51 | + private $userSession; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * SystemTagsByIdCollection constructor. |
|
| 55 | + * |
|
| 56 | + * @param ISystemTagManager $tagManager |
|
| 57 | + * @param IUserSession $userSession |
|
| 58 | + * @param IGroupManager $groupManager |
|
| 59 | + */ |
|
| 60 | + public function __construct( |
|
| 61 | + ISystemTagManager $tagManager, |
|
| 62 | + IUserSession $userSession, |
|
| 63 | + IGroupManager $groupManager |
|
| 64 | + ) { |
|
| 65 | + $this->tagManager = $tagManager; |
|
| 66 | + $this->userSession = $userSession; |
|
| 67 | + $this->groupManager = $groupManager; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Returns whether the currently logged in user is an administrator |
|
| 72 | + * |
|
| 73 | + * @return bool true if the user is an admin |
|
| 74 | + */ |
|
| 75 | + private function isAdmin() { |
|
| 76 | + $user = $this->userSession->getUser(); |
|
| 77 | + if ($user !== null) { |
|
| 78 | + return $this->groupManager->isAdmin($user->getUID()); |
|
| 79 | + } |
|
| 80 | + return false; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @param string $name |
|
| 85 | + * @param resource|string $data Initial payload |
|
| 86 | + * @throws Forbidden |
|
| 87 | + */ |
|
| 88 | + public function createFile($name, $data = null) { |
|
| 89 | + throw new Forbidden('Cannot create tags by id'); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @param string $name |
|
| 94 | + */ |
|
| 95 | + public function createDirectory($name) { |
|
| 96 | + throw new Forbidden('Permission denied to create collections'); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @param string $name |
|
| 101 | + */ |
|
| 102 | + public function getChild($name) { |
|
| 103 | + try { |
|
| 104 | + $tag = $this->tagManager->getTagsByIds([$name]); |
|
| 105 | + $tag = current($tag); |
|
| 106 | + if (!$this->tagManager->canUserSeeTag($tag, $this->userSession->getUser())) { |
|
| 107 | + throw new NotFound('Tag with id ' . $name . ' not found'); |
|
| 108 | + } |
|
| 109 | + return $this->makeNode($tag); |
|
| 110 | + } catch (\InvalidArgumentException $e) { |
|
| 111 | + throw new BadRequest('Invalid tag id', 0, $e); |
|
| 112 | + } catch (TagNotFoundException $e) { |
|
| 113 | + throw new NotFound('Tag with id ' . $name . ' not found', 0, $e); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + public function getChildren() { |
|
| 118 | + $visibilityFilter = true; |
|
| 119 | + if ($this->isAdmin()) { |
|
| 120 | + $visibilityFilter = null; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + $tags = $this->tagManager->getAllTags($visibilityFilter); |
|
| 124 | + return array_map(function ($tag) { |
|
| 125 | + return $this->makeNode($tag); |
|
| 126 | + }, $tags); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @param string $name |
|
| 131 | + */ |
|
| 132 | + public function childExists($name) { |
|
| 133 | + try { |
|
| 134 | + $tag = $this->tagManager->getTagsByIds([$name]); |
|
| 135 | + $tag = current($tag); |
|
| 136 | + if (!$this->tagManager->canUserSeeTag($tag, $this->userSession->getUser())) { |
|
| 137 | + return false; |
|
| 138 | + } |
|
| 139 | + return true; |
|
| 140 | + } catch (\InvalidArgumentException $e) { |
|
| 141 | + throw new BadRequest('Invalid tag id', 0, $e); |
|
| 142 | + } catch (TagNotFoundException $e) { |
|
| 143 | + return false; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + public function delete() { |
|
| 148 | + throw new Forbidden('Permission denied to delete this collection'); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + public function getName() { |
|
| 152 | + return 'systemtags'; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + public function setName($name) { |
|
| 156 | + throw new Forbidden('Permission denied to rename this collection'); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Returns the last modification time, as a unix timestamp |
|
| 161 | + * |
|
| 162 | + * @return int |
|
| 163 | + */ |
|
| 164 | + public function getLastModified() { |
|
| 165 | + return null; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Create a sabre node for the given system tag |
|
| 170 | + * |
|
| 171 | + * @param ISystemTag $tag |
|
| 172 | + * |
|
| 173 | + * @return SystemTagNode |
|
| 174 | + */ |
|
| 175 | + private function makeNode(ISystemTag $tag) { |
|
| 176 | + return new SystemTagNode($tag, $this->userSession->getUser(), $this->isAdmin(), $this->tagManager); |
|
| 177 | + } |
|
| 178 | 178 | } |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | $tag = $this->tagManager->getTagsByIds([$name]); |
| 105 | 105 | $tag = current($tag); |
| 106 | 106 | if (!$this->tagManager->canUserSeeTag($tag, $this->userSession->getUser())) { |
| 107 | - throw new NotFound('Tag with id ' . $name . ' not found'); |
|
| 107 | + throw new NotFound('Tag with id '.$name.' not found'); |
|
| 108 | 108 | } |
| 109 | 109 | return $this->makeNode($tag); |
| 110 | 110 | } catch (\InvalidArgumentException $e) { |
| 111 | 111 | throw new BadRequest('Invalid tag id', 0, $e); |
| 112 | 112 | } catch (TagNotFoundException $e) { |
| 113 | - throw new NotFound('Tag with id ' . $name . ' not found', 0, $e); |
|
| 113 | + throw new NotFound('Tag with id '.$name.' not found', 0, $e); |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | $tags = $this->tagManager->getAllTags($visibilityFilter); |
| 124 | - return array_map(function ($tag) { |
|
| 124 | + return array_map(function($tag) { |
|
| 125 | 125 | return $this->makeNode($tag); |
| 126 | 126 | }, $tags); |
| 127 | 127 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | if ($node instanceof SystemTagsObjectMappingCollection) { |
| 134 | 134 | // also add to collection |
| 135 | 135 | $node->createFile($tag->getId()); |
| 136 | - $url = $request->getBaseUrl() . 'systemtags/'; |
|
| 136 | + $url = $request->getBaseUrl().'systemtags/'; |
|
| 137 | 137 | } else { |
| 138 | 138 | $url = $request->getUrl(); |
| 139 | 139 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | $url .= '/'; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - $response->setHeader('Content-Location', $url . $tag->getId()); |
|
| 145 | + $response->setHeader('Content-Location', $url.$tag->getId()); |
|
| 146 | 146 | |
| 147 | 147 | // created |
| 148 | 148 | $response->setStatus(201); |
@@ -177,11 +177,11 @@ discard block |
||
| 177 | 177 | $userAssignable = true; |
| 178 | 178 | |
| 179 | 179 | if (isset($data['userVisible'])) { |
| 180 | - $userVisible = (bool)$data['userVisible']; |
|
| 180 | + $userVisible = (bool) $data['userVisible']; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | if (isset($data['userAssignable'])) { |
| 184 | - $userAssignable = (bool)$data['userAssignable']; |
|
| 184 | + $userAssignable = (bool) $data['userAssignable']; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | $groups = []; |
@@ -224,29 +224,29 @@ discard block |
||
| 224 | 224 | return; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - $propFind->handle(self::ID_PROPERTYNAME, function () use ($node) { |
|
| 227 | + $propFind->handle(self::ID_PROPERTYNAME, function() use ($node) { |
|
| 228 | 228 | return $node->getSystemTag()->getId(); |
| 229 | 229 | }); |
| 230 | 230 | |
| 231 | - $propFind->handle(self::DISPLAYNAME_PROPERTYNAME, function () use ($node) { |
|
| 231 | + $propFind->handle(self::DISPLAYNAME_PROPERTYNAME, function() use ($node) { |
|
| 232 | 232 | return $node->getSystemTag()->getName(); |
| 233 | 233 | }); |
| 234 | 234 | |
| 235 | - $propFind->handle(self::USERVISIBLE_PROPERTYNAME, function () use ($node) { |
|
| 235 | + $propFind->handle(self::USERVISIBLE_PROPERTYNAME, function() use ($node) { |
|
| 236 | 236 | return $node->getSystemTag()->isUserVisible() ? 'true' : 'false'; |
| 237 | 237 | }); |
| 238 | 238 | |
| 239 | - $propFind->handle(self::USERASSIGNABLE_PROPERTYNAME, function () use ($node) { |
|
| 239 | + $propFind->handle(self::USERASSIGNABLE_PROPERTYNAME, function() use ($node) { |
|
| 240 | 240 | // this is the tag's inherent property "is user assignable" |
| 241 | 241 | return $node->getSystemTag()->isUserAssignable() ? 'true' : 'false'; |
| 242 | 242 | }); |
| 243 | 243 | |
| 244 | - $propFind->handle(self::CANASSIGN_PROPERTYNAME, function () use ($node) { |
|
| 244 | + $propFind->handle(self::CANASSIGN_PROPERTYNAME, function() use ($node) { |
|
| 245 | 245 | // this is the effective permission for the current user |
| 246 | 246 | return $this->tagManager->canUserAssignTag($node->getSystemTag(), $this->userSession->getUser()) ? 'true' : 'false'; |
| 247 | 247 | }); |
| 248 | 248 | |
| 249 | - $propFind->handle(self::GROUPS_PROPERTYNAME, function () use ($node) { |
|
| 249 | + $propFind->handle(self::GROUPS_PROPERTYNAME, function() use ($node) { |
|
| 250 | 250 | if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { |
| 251 | 251 | // property only available for admins |
| 252 | 252 | throw new Forbidden(); |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | self::USERVISIBLE_PROPERTYNAME, |
| 280 | 280 | self::USERASSIGNABLE_PROPERTYNAME, |
| 281 | 281 | self::GROUPS_PROPERTYNAME, |
| 282 | - ], function ($props) use ($node) { |
|
| 282 | + ], function($props) use ($node) { |
|
| 283 | 283 | $tag = $node->getSystemTag(); |
| 284 | 284 | $name = $tag->getName(); |
| 285 | 285 | $userVisible = $tag->isUserVisible(); |
@@ -48,278 +48,278 @@ |
||
| 48 | 48 | */ |
| 49 | 49 | class SystemTagPlugin extends \Sabre\DAV\ServerPlugin { |
| 50 | 50 | |
| 51 | - // namespace |
|
| 52 | - public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 53 | - public const ID_PROPERTYNAME = '{http://owncloud.org/ns}id'; |
|
| 54 | - public const DISPLAYNAME_PROPERTYNAME = '{http://owncloud.org/ns}display-name'; |
|
| 55 | - public const USERVISIBLE_PROPERTYNAME = '{http://owncloud.org/ns}user-visible'; |
|
| 56 | - public const USERASSIGNABLE_PROPERTYNAME = '{http://owncloud.org/ns}user-assignable'; |
|
| 57 | - public const GROUPS_PROPERTYNAME = '{http://owncloud.org/ns}groups'; |
|
| 58 | - public const CANASSIGN_PROPERTYNAME = '{http://owncloud.org/ns}can-assign'; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @var \Sabre\DAV\Server $server |
|
| 62 | - */ |
|
| 63 | - private $server; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @var ISystemTagManager |
|
| 67 | - */ |
|
| 68 | - protected $tagManager; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @var IUserSession |
|
| 72 | - */ |
|
| 73 | - protected $userSession; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @var IGroupManager |
|
| 77 | - */ |
|
| 78 | - protected $groupManager; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @param ISystemTagManager $tagManager tag manager |
|
| 82 | - * @param IGroupManager $groupManager |
|
| 83 | - * @param IUserSession $userSession |
|
| 84 | - */ |
|
| 85 | - public function __construct(ISystemTagManager $tagManager, |
|
| 86 | - IGroupManager $groupManager, |
|
| 87 | - IUserSession $userSession) { |
|
| 88 | - $this->tagManager = $tagManager; |
|
| 89 | - $this->userSession = $userSession; |
|
| 90 | - $this->groupManager = $groupManager; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * This initializes the plugin. |
|
| 95 | - * |
|
| 96 | - * This function is called by \Sabre\DAV\Server, after |
|
| 97 | - * addPlugin is called. |
|
| 98 | - * |
|
| 99 | - * This method should set up the required event subscriptions. |
|
| 100 | - * |
|
| 101 | - * @param \Sabre\DAV\Server $server |
|
| 102 | - * @return void |
|
| 103 | - */ |
|
| 104 | - public function initialize(\Sabre\DAV\Server $server) { |
|
| 105 | - $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
| 106 | - |
|
| 107 | - $server->protectedProperties[] = self::ID_PROPERTYNAME; |
|
| 108 | - |
|
| 109 | - $server->on('propFind', [$this, 'handleGetProperties']); |
|
| 110 | - $server->on('propPatch', [$this, 'handleUpdateProperties']); |
|
| 111 | - $server->on('method:POST', [$this, 'httpPost']); |
|
| 112 | - |
|
| 113 | - $this->server = $server; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * POST operation on system tag collections |
|
| 118 | - * |
|
| 119 | - * @param RequestInterface $request request object |
|
| 120 | - * @param ResponseInterface $response response object |
|
| 121 | - * @return null|false |
|
| 122 | - */ |
|
| 123 | - public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
| 124 | - $path = $request->getPath(); |
|
| 125 | - |
|
| 126 | - // Making sure the node exists |
|
| 127 | - $node = $this->server->tree->getNodeForPath($path); |
|
| 128 | - if ($node instanceof SystemTagsByIdCollection || $node instanceof SystemTagsObjectMappingCollection) { |
|
| 129 | - $data = $request->getBodyAsString(); |
|
| 130 | - |
|
| 131 | - $tag = $this->createTag($data, $request->getHeader('Content-Type')); |
|
| 132 | - |
|
| 133 | - if ($node instanceof SystemTagsObjectMappingCollection) { |
|
| 134 | - // also add to collection |
|
| 135 | - $node->createFile($tag->getId()); |
|
| 136 | - $url = $request->getBaseUrl() . 'systemtags/'; |
|
| 137 | - } else { |
|
| 138 | - $url = $request->getUrl(); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - if ($url[strlen($url) - 1] !== '/') { |
|
| 142 | - $url .= '/'; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - $response->setHeader('Content-Location', $url . $tag->getId()); |
|
| 146 | - |
|
| 147 | - // created |
|
| 148 | - $response->setStatus(201); |
|
| 149 | - return false; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Creates a new tag |
|
| 155 | - * |
|
| 156 | - * @param string $data JSON encoded string containing the properties of the tag to create |
|
| 157 | - * @param string $contentType content type of the data |
|
| 158 | - * @return ISystemTag newly created system tag |
|
| 159 | - * |
|
| 160 | - * @throws BadRequest if a field was missing |
|
| 161 | - * @throws Conflict if a tag with the same properties already exists |
|
| 162 | - * @throws UnsupportedMediaType if the content type is not supported |
|
| 163 | - */ |
|
| 164 | - private function createTag($data, $contentType = 'application/json') { |
|
| 165 | - if (explode(';', $contentType)[0] === 'application/json') { |
|
| 166 | - $data = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 167 | - } else { |
|
| 168 | - throw new UnsupportedMediaType(); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - if (!isset($data['name'])) { |
|
| 172 | - throw new BadRequest('Missing "name" attribute'); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - $tagName = $data['name']; |
|
| 176 | - $userVisible = true; |
|
| 177 | - $userAssignable = true; |
|
| 178 | - |
|
| 179 | - if (isset($data['userVisible'])) { |
|
| 180 | - $userVisible = (bool)$data['userVisible']; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - if (isset($data['userAssignable'])) { |
|
| 184 | - $userAssignable = (bool)$data['userAssignable']; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - $groups = []; |
|
| 188 | - if (isset($data['groups'])) { |
|
| 189 | - $groups = $data['groups']; |
|
| 190 | - if (is_string($groups)) { |
|
| 191 | - $groups = explode('|', $groups); |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - if ($userVisible === false || $userAssignable === false || !empty($groups)) { |
|
| 196 | - if (!$this->userSession->isLoggedIn() || !$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { |
|
| 197 | - throw new BadRequest('Not sufficient permissions'); |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - try { |
|
| 202 | - $tag = $this->tagManager->createTag($tagName, $userVisible, $userAssignable); |
|
| 203 | - if (!empty($groups)) { |
|
| 204 | - $this->tagManager->setTagGroups($tag, $groups); |
|
| 205 | - } |
|
| 206 | - return $tag; |
|
| 207 | - } catch (TagAlreadyExistsException $e) { |
|
| 208 | - throw new Conflict('Tag already exists', 0, $e); |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Retrieves system tag properties |
|
| 215 | - * |
|
| 216 | - * @param PropFind $propFind |
|
| 217 | - * @param \Sabre\DAV\INode $node |
|
| 218 | - */ |
|
| 219 | - public function handleGetProperties( |
|
| 220 | - PropFind $propFind, |
|
| 221 | - \Sabre\DAV\INode $node |
|
| 222 | - ) { |
|
| 223 | - if (!($node instanceof SystemTagNode) && !($node instanceof SystemTagMappingNode)) { |
|
| 224 | - return; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - $propFind->handle(self::ID_PROPERTYNAME, function () use ($node) { |
|
| 228 | - return $node->getSystemTag()->getId(); |
|
| 229 | - }); |
|
| 230 | - |
|
| 231 | - $propFind->handle(self::DISPLAYNAME_PROPERTYNAME, function () use ($node) { |
|
| 232 | - return $node->getSystemTag()->getName(); |
|
| 233 | - }); |
|
| 234 | - |
|
| 235 | - $propFind->handle(self::USERVISIBLE_PROPERTYNAME, function () use ($node) { |
|
| 236 | - return $node->getSystemTag()->isUserVisible() ? 'true' : 'false'; |
|
| 237 | - }); |
|
| 238 | - |
|
| 239 | - $propFind->handle(self::USERASSIGNABLE_PROPERTYNAME, function () use ($node) { |
|
| 240 | - // this is the tag's inherent property "is user assignable" |
|
| 241 | - return $node->getSystemTag()->isUserAssignable() ? 'true' : 'false'; |
|
| 242 | - }); |
|
| 243 | - |
|
| 244 | - $propFind->handle(self::CANASSIGN_PROPERTYNAME, function () use ($node) { |
|
| 245 | - // this is the effective permission for the current user |
|
| 246 | - return $this->tagManager->canUserAssignTag($node->getSystemTag(), $this->userSession->getUser()) ? 'true' : 'false'; |
|
| 247 | - }); |
|
| 248 | - |
|
| 249 | - $propFind->handle(self::GROUPS_PROPERTYNAME, function () use ($node) { |
|
| 250 | - if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { |
|
| 251 | - // property only available for admins |
|
| 252 | - throw new Forbidden(); |
|
| 253 | - } |
|
| 254 | - $groups = []; |
|
| 255 | - // no need to retrieve groups for namespaces that don't qualify |
|
| 256 | - if ($node->getSystemTag()->isUserVisible() && !$node->getSystemTag()->isUserAssignable()) { |
|
| 257 | - $groups = $this->tagManager->getTagGroups($node->getSystemTag()); |
|
| 258 | - } |
|
| 259 | - return implode('|', $groups); |
|
| 260 | - }); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * Updates tag attributes |
|
| 265 | - * |
|
| 266 | - * @param string $path |
|
| 267 | - * @param PropPatch $propPatch |
|
| 268 | - * |
|
| 269 | - * @return void |
|
| 270 | - */ |
|
| 271 | - public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
| 272 | - $node = $this->server->tree->getNodeForPath($path); |
|
| 273 | - if (!($node instanceof SystemTagNode)) { |
|
| 274 | - return; |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - $propPatch->handle([ |
|
| 278 | - self::DISPLAYNAME_PROPERTYNAME, |
|
| 279 | - self::USERVISIBLE_PROPERTYNAME, |
|
| 280 | - self::USERASSIGNABLE_PROPERTYNAME, |
|
| 281 | - self::GROUPS_PROPERTYNAME, |
|
| 282 | - ], function ($props) use ($node) { |
|
| 283 | - $tag = $node->getSystemTag(); |
|
| 284 | - $name = $tag->getName(); |
|
| 285 | - $userVisible = $tag->isUserVisible(); |
|
| 286 | - $userAssignable = $tag->isUserAssignable(); |
|
| 287 | - |
|
| 288 | - $updateTag = false; |
|
| 289 | - |
|
| 290 | - if (isset($props[self::DISPLAYNAME_PROPERTYNAME])) { |
|
| 291 | - $name = $props[self::DISPLAYNAME_PROPERTYNAME]; |
|
| 292 | - $updateTag = true; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - if (isset($props[self::USERVISIBLE_PROPERTYNAME])) { |
|
| 296 | - $propValue = $props[self::USERVISIBLE_PROPERTYNAME]; |
|
| 297 | - $userVisible = ($propValue !== 'false' && $propValue !== '0'); |
|
| 298 | - $updateTag = true; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - if (isset($props[self::USERASSIGNABLE_PROPERTYNAME])) { |
|
| 302 | - $propValue = $props[self::USERASSIGNABLE_PROPERTYNAME]; |
|
| 303 | - $userAssignable = ($propValue !== 'false' && $propValue !== '0'); |
|
| 304 | - $updateTag = true; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - if (isset($props[self::GROUPS_PROPERTYNAME])) { |
|
| 308 | - if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { |
|
| 309 | - // property only available for admins |
|
| 310 | - throw new Forbidden(); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - $propValue = $props[self::GROUPS_PROPERTYNAME]; |
|
| 314 | - $groupIds = explode('|', $propValue); |
|
| 315 | - $this->tagManager->setTagGroups($tag, $groupIds); |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - if ($updateTag) { |
|
| 319 | - $node->update($name, $userVisible, $userAssignable); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - return true; |
|
| 323 | - }); |
|
| 324 | - } |
|
| 51 | + // namespace |
|
| 52 | + public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 53 | + public const ID_PROPERTYNAME = '{http://owncloud.org/ns}id'; |
|
| 54 | + public const DISPLAYNAME_PROPERTYNAME = '{http://owncloud.org/ns}display-name'; |
|
| 55 | + public const USERVISIBLE_PROPERTYNAME = '{http://owncloud.org/ns}user-visible'; |
|
| 56 | + public const USERASSIGNABLE_PROPERTYNAME = '{http://owncloud.org/ns}user-assignable'; |
|
| 57 | + public const GROUPS_PROPERTYNAME = '{http://owncloud.org/ns}groups'; |
|
| 58 | + public const CANASSIGN_PROPERTYNAME = '{http://owncloud.org/ns}can-assign'; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @var \Sabre\DAV\Server $server |
|
| 62 | + */ |
|
| 63 | + private $server; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @var ISystemTagManager |
|
| 67 | + */ |
|
| 68 | + protected $tagManager; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @var IUserSession |
|
| 72 | + */ |
|
| 73 | + protected $userSession; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @var IGroupManager |
|
| 77 | + */ |
|
| 78 | + protected $groupManager; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @param ISystemTagManager $tagManager tag manager |
|
| 82 | + * @param IGroupManager $groupManager |
|
| 83 | + * @param IUserSession $userSession |
|
| 84 | + */ |
|
| 85 | + public function __construct(ISystemTagManager $tagManager, |
|
| 86 | + IGroupManager $groupManager, |
|
| 87 | + IUserSession $userSession) { |
|
| 88 | + $this->tagManager = $tagManager; |
|
| 89 | + $this->userSession = $userSession; |
|
| 90 | + $this->groupManager = $groupManager; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * This initializes the plugin. |
|
| 95 | + * |
|
| 96 | + * This function is called by \Sabre\DAV\Server, after |
|
| 97 | + * addPlugin is called. |
|
| 98 | + * |
|
| 99 | + * This method should set up the required event subscriptions. |
|
| 100 | + * |
|
| 101 | + * @param \Sabre\DAV\Server $server |
|
| 102 | + * @return void |
|
| 103 | + */ |
|
| 104 | + public function initialize(\Sabre\DAV\Server $server) { |
|
| 105 | + $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
| 106 | + |
|
| 107 | + $server->protectedProperties[] = self::ID_PROPERTYNAME; |
|
| 108 | + |
|
| 109 | + $server->on('propFind', [$this, 'handleGetProperties']); |
|
| 110 | + $server->on('propPatch', [$this, 'handleUpdateProperties']); |
|
| 111 | + $server->on('method:POST', [$this, 'httpPost']); |
|
| 112 | + |
|
| 113 | + $this->server = $server; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * POST operation on system tag collections |
|
| 118 | + * |
|
| 119 | + * @param RequestInterface $request request object |
|
| 120 | + * @param ResponseInterface $response response object |
|
| 121 | + * @return null|false |
|
| 122 | + */ |
|
| 123 | + public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
| 124 | + $path = $request->getPath(); |
|
| 125 | + |
|
| 126 | + // Making sure the node exists |
|
| 127 | + $node = $this->server->tree->getNodeForPath($path); |
|
| 128 | + if ($node instanceof SystemTagsByIdCollection || $node instanceof SystemTagsObjectMappingCollection) { |
|
| 129 | + $data = $request->getBodyAsString(); |
|
| 130 | + |
|
| 131 | + $tag = $this->createTag($data, $request->getHeader('Content-Type')); |
|
| 132 | + |
|
| 133 | + if ($node instanceof SystemTagsObjectMappingCollection) { |
|
| 134 | + // also add to collection |
|
| 135 | + $node->createFile($tag->getId()); |
|
| 136 | + $url = $request->getBaseUrl() . 'systemtags/'; |
|
| 137 | + } else { |
|
| 138 | + $url = $request->getUrl(); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + if ($url[strlen($url) - 1] !== '/') { |
|
| 142 | + $url .= '/'; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + $response->setHeader('Content-Location', $url . $tag->getId()); |
|
| 146 | + |
|
| 147 | + // created |
|
| 148 | + $response->setStatus(201); |
|
| 149 | + return false; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Creates a new tag |
|
| 155 | + * |
|
| 156 | + * @param string $data JSON encoded string containing the properties of the tag to create |
|
| 157 | + * @param string $contentType content type of the data |
|
| 158 | + * @return ISystemTag newly created system tag |
|
| 159 | + * |
|
| 160 | + * @throws BadRequest if a field was missing |
|
| 161 | + * @throws Conflict if a tag with the same properties already exists |
|
| 162 | + * @throws UnsupportedMediaType if the content type is not supported |
|
| 163 | + */ |
|
| 164 | + private function createTag($data, $contentType = 'application/json') { |
|
| 165 | + if (explode(';', $contentType)[0] === 'application/json') { |
|
| 166 | + $data = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 167 | + } else { |
|
| 168 | + throw new UnsupportedMediaType(); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + if (!isset($data['name'])) { |
|
| 172 | + throw new BadRequest('Missing "name" attribute'); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + $tagName = $data['name']; |
|
| 176 | + $userVisible = true; |
|
| 177 | + $userAssignable = true; |
|
| 178 | + |
|
| 179 | + if (isset($data['userVisible'])) { |
|
| 180 | + $userVisible = (bool)$data['userVisible']; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + if (isset($data['userAssignable'])) { |
|
| 184 | + $userAssignable = (bool)$data['userAssignable']; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + $groups = []; |
|
| 188 | + if (isset($data['groups'])) { |
|
| 189 | + $groups = $data['groups']; |
|
| 190 | + if (is_string($groups)) { |
|
| 191 | + $groups = explode('|', $groups); |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + if ($userVisible === false || $userAssignable === false || !empty($groups)) { |
|
| 196 | + if (!$this->userSession->isLoggedIn() || !$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { |
|
| 197 | + throw new BadRequest('Not sufficient permissions'); |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + try { |
|
| 202 | + $tag = $this->tagManager->createTag($tagName, $userVisible, $userAssignable); |
|
| 203 | + if (!empty($groups)) { |
|
| 204 | + $this->tagManager->setTagGroups($tag, $groups); |
|
| 205 | + } |
|
| 206 | + return $tag; |
|
| 207 | + } catch (TagAlreadyExistsException $e) { |
|
| 208 | + throw new Conflict('Tag already exists', 0, $e); |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Retrieves system tag properties |
|
| 215 | + * |
|
| 216 | + * @param PropFind $propFind |
|
| 217 | + * @param \Sabre\DAV\INode $node |
|
| 218 | + */ |
|
| 219 | + public function handleGetProperties( |
|
| 220 | + PropFind $propFind, |
|
| 221 | + \Sabre\DAV\INode $node |
|
| 222 | + ) { |
|
| 223 | + if (!($node instanceof SystemTagNode) && !($node instanceof SystemTagMappingNode)) { |
|
| 224 | + return; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + $propFind->handle(self::ID_PROPERTYNAME, function () use ($node) { |
|
| 228 | + return $node->getSystemTag()->getId(); |
|
| 229 | + }); |
|
| 230 | + |
|
| 231 | + $propFind->handle(self::DISPLAYNAME_PROPERTYNAME, function () use ($node) { |
|
| 232 | + return $node->getSystemTag()->getName(); |
|
| 233 | + }); |
|
| 234 | + |
|
| 235 | + $propFind->handle(self::USERVISIBLE_PROPERTYNAME, function () use ($node) { |
|
| 236 | + return $node->getSystemTag()->isUserVisible() ? 'true' : 'false'; |
|
| 237 | + }); |
|
| 238 | + |
|
| 239 | + $propFind->handle(self::USERASSIGNABLE_PROPERTYNAME, function () use ($node) { |
|
| 240 | + // this is the tag's inherent property "is user assignable" |
|
| 241 | + return $node->getSystemTag()->isUserAssignable() ? 'true' : 'false'; |
|
| 242 | + }); |
|
| 243 | + |
|
| 244 | + $propFind->handle(self::CANASSIGN_PROPERTYNAME, function () use ($node) { |
|
| 245 | + // this is the effective permission for the current user |
|
| 246 | + return $this->tagManager->canUserAssignTag($node->getSystemTag(), $this->userSession->getUser()) ? 'true' : 'false'; |
|
| 247 | + }); |
|
| 248 | + |
|
| 249 | + $propFind->handle(self::GROUPS_PROPERTYNAME, function () use ($node) { |
|
| 250 | + if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { |
|
| 251 | + // property only available for admins |
|
| 252 | + throw new Forbidden(); |
|
| 253 | + } |
|
| 254 | + $groups = []; |
|
| 255 | + // no need to retrieve groups for namespaces that don't qualify |
|
| 256 | + if ($node->getSystemTag()->isUserVisible() && !$node->getSystemTag()->isUserAssignable()) { |
|
| 257 | + $groups = $this->tagManager->getTagGroups($node->getSystemTag()); |
|
| 258 | + } |
|
| 259 | + return implode('|', $groups); |
|
| 260 | + }); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * Updates tag attributes |
|
| 265 | + * |
|
| 266 | + * @param string $path |
|
| 267 | + * @param PropPatch $propPatch |
|
| 268 | + * |
|
| 269 | + * @return void |
|
| 270 | + */ |
|
| 271 | + public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
| 272 | + $node = $this->server->tree->getNodeForPath($path); |
|
| 273 | + if (!($node instanceof SystemTagNode)) { |
|
| 274 | + return; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + $propPatch->handle([ |
|
| 278 | + self::DISPLAYNAME_PROPERTYNAME, |
|
| 279 | + self::USERVISIBLE_PROPERTYNAME, |
|
| 280 | + self::USERASSIGNABLE_PROPERTYNAME, |
|
| 281 | + self::GROUPS_PROPERTYNAME, |
|
| 282 | + ], function ($props) use ($node) { |
|
| 283 | + $tag = $node->getSystemTag(); |
|
| 284 | + $name = $tag->getName(); |
|
| 285 | + $userVisible = $tag->isUserVisible(); |
|
| 286 | + $userAssignable = $tag->isUserAssignable(); |
|
| 287 | + |
|
| 288 | + $updateTag = false; |
|
| 289 | + |
|
| 290 | + if (isset($props[self::DISPLAYNAME_PROPERTYNAME])) { |
|
| 291 | + $name = $props[self::DISPLAYNAME_PROPERTYNAME]; |
|
| 292 | + $updateTag = true; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + if (isset($props[self::USERVISIBLE_PROPERTYNAME])) { |
|
| 296 | + $propValue = $props[self::USERVISIBLE_PROPERTYNAME]; |
|
| 297 | + $userVisible = ($propValue !== 'false' && $propValue !== '0'); |
|
| 298 | + $updateTag = true; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + if (isset($props[self::USERASSIGNABLE_PROPERTYNAME])) { |
|
| 302 | + $propValue = $props[self::USERASSIGNABLE_PROPERTYNAME]; |
|
| 303 | + $userAssignable = ($propValue !== 'false' && $propValue !== '0'); |
|
| 304 | + $updateTag = true; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + if (isset($props[self::GROUPS_PROPERTYNAME])) { |
|
| 308 | + if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { |
|
| 309 | + // property only available for admins |
|
| 310 | + throw new Forbidden(); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + $propValue = $props[self::GROUPS_PROPERTYNAME]; |
|
| 314 | + $groupIds = explode('|', $propValue); |
|
| 315 | + $this->tagManager->setTagGroups($tag, $groupIds); |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + if ($updateTag) { |
|
| 319 | + $node->update($name, $userVisible, $userAssignable); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + return true; |
|
| 323 | + }); |
|
| 324 | + } |
|
| 325 | 325 | } |
@@ -39,7 +39,7 @@ |
||
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | public function createDirectory($name) { |
| 42 | - throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
| 42 | + throw new Forbidden('Permission denied to create file (filename '.$name.')'); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | public function getChild($name) { |
@@ -32,92 +32,92 @@ |
||
| 32 | 32 | use Sabre\DAV\ICollection; |
| 33 | 33 | |
| 34 | 34 | class UploadFolder implements ICollection { |
| 35 | - /** @var Directory */ |
|
| 36 | - private $node; |
|
| 37 | - /** @var CleanupService */ |
|
| 38 | - private $cleanupService; |
|
| 39 | - /** @var IStorage */ |
|
| 40 | - private $storage; |
|
| 41 | - |
|
| 42 | - public function __construct(Directory $node, CleanupService $cleanupService, IStorage $storage) { |
|
| 43 | - $this->node = $node; |
|
| 44 | - $this->cleanupService = $cleanupService; |
|
| 45 | - $this->storage = $storage; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - public function createFile($name, $data = null) { |
|
| 49 | - // TODO: verify name - should be a simple number |
|
| 50 | - $this->node->createFile($name, $data); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - public function createDirectory($name) { |
|
| 54 | - throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - public function getChild($name) { |
|
| 58 | - if ($name === '.file') { |
|
| 59 | - return new FutureFile($this->node, '.file'); |
|
| 60 | - } |
|
| 61 | - return new UploadFile($this->node->getChild($name)); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - public function getChildren() { |
|
| 65 | - $tmpChildren = $this->node->getChildren(); |
|
| 66 | - |
|
| 67 | - $children = []; |
|
| 68 | - $children[] = new FutureFile($this->node, '.file'); |
|
| 69 | - |
|
| 70 | - foreach ($tmpChildren as $child) { |
|
| 71 | - $children[] = new UploadFile($child); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - if ($this->storage->instanceOfStorage(ObjectStoreStorage::class)) { |
|
| 75 | - /** @var ObjectStoreStorage $storage */ |
|
| 76 | - $objectStore = $this->storage->getObjectStore(); |
|
| 77 | - if ($objectStore instanceof IObjectStoreMultiPartUpload) { |
|
| 78 | - $cache = \OC::$server->getMemCacheFactory()->createDistributed(ChunkingV2Plugin::CACHE_KEY); |
|
| 79 | - $uploadSession = $cache->get($this->getName()); |
|
| 80 | - if ($uploadSession) { |
|
| 81 | - $uploadId = $uploadSession[ChunkingV2Plugin::UPLOAD_ID]; |
|
| 82 | - $id = $uploadSession[ChunkingV2Plugin::UPLOAD_TARGET_ID]; |
|
| 83 | - $parts = $objectStore->getMultipartUploads($this->storage->getURN($id), $uploadId); |
|
| 84 | - foreach ($parts as $part) { |
|
| 85 | - $children[] = new PartFile($this->node, $part); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - return $children; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - public function childExists($name) { |
|
| 95 | - if ($name === '.file') { |
|
| 96 | - return true; |
|
| 97 | - } |
|
| 98 | - return $this->node->childExists($name); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - public function delete() { |
|
| 102 | - $this->node->delete(); |
|
| 103 | - |
|
| 104 | - // Background cleanup job is not needed anymore |
|
| 105 | - $this->cleanupService->removeJob($this->getName()); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - public function getName() { |
|
| 109 | - return $this->node->getName(); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - public function setName($name) { |
|
| 113 | - throw new Forbidden('Permission denied to rename this folder'); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - public function getLastModified() { |
|
| 117 | - return $this->node->getLastModified(); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - public function getStorage() { |
|
| 121 | - return $this->storage; |
|
| 122 | - } |
|
| 35 | + /** @var Directory */ |
|
| 36 | + private $node; |
|
| 37 | + /** @var CleanupService */ |
|
| 38 | + private $cleanupService; |
|
| 39 | + /** @var IStorage */ |
|
| 40 | + private $storage; |
|
| 41 | + |
|
| 42 | + public function __construct(Directory $node, CleanupService $cleanupService, IStorage $storage) { |
|
| 43 | + $this->node = $node; |
|
| 44 | + $this->cleanupService = $cleanupService; |
|
| 45 | + $this->storage = $storage; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + public function createFile($name, $data = null) { |
|
| 49 | + // TODO: verify name - should be a simple number |
|
| 50 | + $this->node->createFile($name, $data); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + public function createDirectory($name) { |
|
| 54 | + throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + public function getChild($name) { |
|
| 58 | + if ($name === '.file') { |
|
| 59 | + return new FutureFile($this->node, '.file'); |
|
| 60 | + } |
|
| 61 | + return new UploadFile($this->node->getChild($name)); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + public function getChildren() { |
|
| 65 | + $tmpChildren = $this->node->getChildren(); |
|
| 66 | + |
|
| 67 | + $children = []; |
|
| 68 | + $children[] = new FutureFile($this->node, '.file'); |
|
| 69 | + |
|
| 70 | + foreach ($tmpChildren as $child) { |
|
| 71 | + $children[] = new UploadFile($child); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + if ($this->storage->instanceOfStorage(ObjectStoreStorage::class)) { |
|
| 75 | + /** @var ObjectStoreStorage $storage */ |
|
| 76 | + $objectStore = $this->storage->getObjectStore(); |
|
| 77 | + if ($objectStore instanceof IObjectStoreMultiPartUpload) { |
|
| 78 | + $cache = \OC::$server->getMemCacheFactory()->createDistributed(ChunkingV2Plugin::CACHE_KEY); |
|
| 79 | + $uploadSession = $cache->get($this->getName()); |
|
| 80 | + if ($uploadSession) { |
|
| 81 | + $uploadId = $uploadSession[ChunkingV2Plugin::UPLOAD_ID]; |
|
| 82 | + $id = $uploadSession[ChunkingV2Plugin::UPLOAD_TARGET_ID]; |
|
| 83 | + $parts = $objectStore->getMultipartUploads($this->storage->getURN($id), $uploadId); |
|
| 84 | + foreach ($parts as $part) { |
|
| 85 | + $children[] = new PartFile($this->node, $part); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + return $children; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + public function childExists($name) { |
|
| 95 | + if ($name === '.file') { |
|
| 96 | + return true; |
|
| 97 | + } |
|
| 98 | + return $this->node->childExists($name); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + public function delete() { |
|
| 102 | + $this->node->delete(); |
|
| 103 | + |
|
| 104 | + // Background cleanup job is not needed anymore |
|
| 105 | + $this->cleanupService->removeJob($this->getName()); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + public function getName() { |
|
| 109 | + return $this->node->getName(); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + public function setName($name) { |
|
| 113 | + throw new Forbidden('Permission denied to rename this folder'); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + public function getLastModified() { |
|
| 117 | + return $this->node->getLastModified(); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + public function getStorage() { |
|
| 121 | + return $this->storage; |
|
| 122 | + } |
|
| 123 | 123 | } |
@@ -62,7 +62,7 @@ |
||
| 62 | 62 | |
| 63 | 63 | $requestUri = \OC::$server->getRequest()->getRequestUri(); |
| 64 | 64 | |
| 65 | -$server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function () { |
|
| 65 | +$server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function() { |
|
| 66 | 66 | // use the view for the logged in user |
| 67 | 67 | return \OC\Files\Filesystem::getView(); |
| 68 | 68 | }); |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | // no php execution timeout for webdav |
| 34 | 34 | if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
| 35 | - @set_time_limit(0); |
|
| 35 | + @set_time_limit(0); |
|
| 36 | 36 | } |
| 37 | 37 | ignore_user_abort(true); |
| 38 | 38 | |
@@ -40,40 +40,40 @@ discard block |
||
| 40 | 40 | \OC_Util::obEnd(); |
| 41 | 41 | |
| 42 | 42 | $serverFactory = new \OCA\DAV\Connector\Sabre\ServerFactory( |
| 43 | - \OC::$server->getConfig(), |
|
| 44 | - \OC::$server->get(LoggerInterface::class), |
|
| 45 | - \OC::$server->getDatabaseConnection(), |
|
| 46 | - \OC::$server->getUserSession(), |
|
| 47 | - \OC::$server->getMountManager(), |
|
| 48 | - \OC::$server->getTagManager(), |
|
| 49 | - \OC::$server->getRequest(), |
|
| 50 | - \OC::$server->getPreviewManager(), |
|
| 51 | - \OC::$server->getEventDispatcher(), |
|
| 52 | - \OC::$server->getL10N('dav') |
|
| 43 | + \OC::$server->getConfig(), |
|
| 44 | + \OC::$server->get(LoggerInterface::class), |
|
| 45 | + \OC::$server->getDatabaseConnection(), |
|
| 46 | + \OC::$server->getUserSession(), |
|
| 47 | + \OC::$server->getMountManager(), |
|
| 48 | + \OC::$server->getTagManager(), |
|
| 49 | + \OC::$server->getRequest(), |
|
| 50 | + \OC::$server->getPreviewManager(), |
|
| 51 | + \OC::$server->getEventDispatcher(), |
|
| 52 | + \OC::$server->getL10N('dav') |
|
| 53 | 53 | ); |
| 54 | 54 | |
| 55 | 55 | // Backends |
| 56 | 56 | $authBackend = new \OCA\DAV\Connector\Sabre\Auth( |
| 57 | - \OC::$server->getSession(), |
|
| 58 | - \OC::$server->getUserSession(), |
|
| 59 | - \OC::$server->getRequest(), |
|
| 60 | - \OC::$server->getTwoFactorAuthManager(), |
|
| 61 | - \OC::$server->getBruteForceThrottler(), |
|
| 62 | - 'principals/' |
|
| 57 | + \OC::$server->getSession(), |
|
| 58 | + \OC::$server->getUserSession(), |
|
| 59 | + \OC::$server->getRequest(), |
|
| 60 | + \OC::$server->getTwoFactorAuthManager(), |
|
| 61 | + \OC::$server->getBruteForceThrottler(), |
|
| 62 | + 'principals/' |
|
| 63 | 63 | ); |
| 64 | 64 | $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend); |
| 65 | 65 | $bearerAuthPlugin = new \OCA\DAV\Connector\Sabre\BearerAuth( |
| 66 | - \OC::$server->getUserSession(), |
|
| 67 | - \OC::$server->getSession(), |
|
| 68 | - \OC::$server->getRequest() |
|
| 66 | + \OC::$server->getUserSession(), |
|
| 67 | + \OC::$server->getSession(), |
|
| 68 | + \OC::$server->getRequest() |
|
| 69 | 69 | ); |
| 70 | 70 | $authPlugin->addBackend($bearerAuthPlugin); |
| 71 | 71 | |
| 72 | 72 | $requestUri = \OC::$server->getRequest()->getRequestUri(); |
| 73 | 73 | |
| 74 | 74 | $server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function () { |
| 75 | - // use the view for the logged in user |
|
| 76 | - return \OC\Files\Filesystem::getView(); |
|
| 75 | + // use the view for the logged in user |
|
| 76 | + return \OC\Files\Filesystem::getView(); |
|
| 77 | 77 | }); |
| 78 | 78 | |
| 79 | 79 | $dispatcher = \OC::$server->getEventDispatcher(); |
@@ -55,8 +55,8 @@ |
||
| 55 | 55 | $logger = \OC::$server->getLogger(); |
| 56 | 56 | |
| 57 | 57 | $sql = |
| 58 | - 'DELETE FROM `*PREFIX*share` ' . |
|
| 59 | - 'WHERE `item_type` in (\'file\', \'folder\') ' . |
|
| 58 | + 'DELETE FROM `*PREFIX*share` '. |
|
| 59 | + 'WHERE `item_type` in (\'file\', \'folder\') '. |
|
| 60 | 60 | 'AND NOT EXISTS (SELECT `fileid` FROM `*PREFIX*filecache` WHERE `file_source` = `fileid`)'; |
| 61 | 61 | |
| 62 | 62 | $deletedEntries = $connection->executeUpdate($sql); |
@@ -31,37 +31,37 @@ |
||
| 31 | 31 | * Delete all share entries that have no matching entries in the file cache table. |
| 32 | 32 | */ |
| 33 | 33 | class DeleteOrphanedSharesJob extends TimedJob { |
| 34 | - /** |
|
| 35 | - * Default interval in minutes |
|
| 36 | - * |
|
| 37 | - * @var int $defaultIntervalMin |
|
| 38 | - **/ |
|
| 39 | - protected $defaultIntervalMin = 15; |
|
| 34 | + /** |
|
| 35 | + * Default interval in minutes |
|
| 36 | + * |
|
| 37 | + * @var int $defaultIntervalMin |
|
| 38 | + **/ |
|
| 39 | + protected $defaultIntervalMin = 15; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * sets the correct interval for this timed job |
|
| 43 | - */ |
|
| 44 | - public function __construct(ITimeFactory $time) { |
|
| 45 | - parent::__construct($time); |
|
| 41 | + /** |
|
| 42 | + * sets the correct interval for this timed job |
|
| 43 | + */ |
|
| 44 | + public function __construct(ITimeFactory $time) { |
|
| 45 | + parent::__construct($time); |
|
| 46 | 46 | |
| 47 | - $this->interval = $this->defaultIntervalMin * 60; |
|
| 48 | - } |
|
| 47 | + $this->interval = $this->defaultIntervalMin * 60; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Makes the background job do its work |
|
| 52 | - * |
|
| 53 | - * @param array $argument unused argument |
|
| 54 | - */ |
|
| 55 | - public function run($argument) { |
|
| 56 | - $connection = \OC::$server->getDatabaseConnection(); |
|
| 57 | - $logger = \OC::$server->getLogger(); |
|
| 50 | + /** |
|
| 51 | + * Makes the background job do its work |
|
| 52 | + * |
|
| 53 | + * @param array $argument unused argument |
|
| 54 | + */ |
|
| 55 | + public function run($argument) { |
|
| 56 | + $connection = \OC::$server->getDatabaseConnection(); |
|
| 57 | + $logger = \OC::$server->getLogger(); |
|
| 58 | 58 | |
| 59 | - $sql = |
|
| 60 | - 'DELETE FROM `*PREFIX*share` ' . |
|
| 61 | - 'WHERE `item_type` in (\'file\', \'folder\') ' . |
|
| 62 | - 'AND NOT EXISTS (SELECT `fileid` FROM `*PREFIX*filecache` WHERE `file_source` = `fileid`)'; |
|
| 59 | + $sql = |
|
| 60 | + 'DELETE FROM `*PREFIX*share` ' . |
|
| 61 | + 'WHERE `item_type` in (\'file\', \'folder\') ' . |
|
| 62 | + 'AND NOT EXISTS (SELECT `fileid` FROM `*PREFIX*filecache` WHERE `file_source` = `fileid`)'; |
|
| 63 | 63 | |
| 64 | - $deletedEntries = $connection->executeUpdate($sql); |
|
| 65 | - $logger->debug("$deletedEntries orphaned share(s) deleted", ['app' => 'DeleteOrphanedSharesJob']); |
|
| 66 | - } |
|
| 64 | + $deletedEntries = $connection->executeUpdate($sql); |
|
| 65 | + $logger->debug("$deletedEntries orphaned share(s) deleted", ['app' => 'DeleteOrphanedSharesJob']); |
|
| 66 | + } |
|
| 67 | 67 | } |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | if (isset($parameters[$key])) { |
| 221 | 221 | switch ($parameters[$key]->getType()) { |
| 222 | 222 | case \OCA\Files_External\Lib\DefinitionParameter::VALUE_BOOLEAN: |
| 223 | - $value = (bool)$value; |
|
| 223 | + $value = (bool) $value; |
|
| 224 | 224 | break; |
| 225 | 225 | } |
| 226 | 226 | $backendOptions[$key] = $value; |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | $result['statusMessage'] = $this->statusMessage; |
| 427 | 427 | } |
| 428 | 428 | $result['userProvided'] = $this->authMechanism instanceof IUserProvided; |
| 429 | - $result['type'] = ($this->getType() === self::MOUNT_TYPE_PERSONAl) ? 'personal': 'system'; |
|
| 429 | + $result['type'] = ($this->getType() === self::MOUNT_TYPE_PERSONAl) ? 'personal' : 'system'; |
|
| 430 | 430 | return $result; |
| 431 | 431 | } |
| 432 | 432 | } |
@@ -36,396 +36,396 @@ |
||
| 36 | 36 | * External storage configuration |
| 37 | 37 | */ |
| 38 | 38 | class StorageConfig implements \JsonSerializable { |
| 39 | - public const MOUNT_TYPE_ADMIN = 1; |
|
| 40 | - public const MOUNT_TYPE_PERSONAl = 2; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Storage config id |
|
| 44 | - * |
|
| 45 | - * @var int |
|
| 46 | - */ |
|
| 47 | - private $id; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Backend |
|
| 51 | - * |
|
| 52 | - * @var Backend |
|
| 53 | - */ |
|
| 54 | - private $backend; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Authentication mechanism |
|
| 58 | - * |
|
| 59 | - * @var AuthMechanism |
|
| 60 | - */ |
|
| 61 | - private $authMechanism; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Backend options |
|
| 65 | - * |
|
| 66 | - * @var array |
|
| 67 | - */ |
|
| 68 | - private $backendOptions = []; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Mount point path, relative to the user's "files" folder |
|
| 72 | - * |
|
| 73 | - * @var string |
|
| 74 | - */ |
|
| 75 | - private $mountPoint; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Storage status |
|
| 79 | - * |
|
| 80 | - * @var int |
|
| 81 | - */ |
|
| 82 | - private $status; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Status message |
|
| 86 | - * |
|
| 87 | - * @var string |
|
| 88 | - */ |
|
| 89 | - private $statusMessage; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Priority |
|
| 93 | - * |
|
| 94 | - * @var int |
|
| 95 | - */ |
|
| 96 | - private $priority; |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * List of users who have access to this storage |
|
| 100 | - * |
|
| 101 | - * @var string[] |
|
| 102 | - */ |
|
| 103 | - private $applicableUsers = []; |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * List of groups that have access to this storage |
|
| 107 | - * |
|
| 108 | - * @var string[] |
|
| 109 | - */ |
|
| 110 | - private $applicableGroups = []; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Mount-specific options |
|
| 114 | - * |
|
| 115 | - * @var array |
|
| 116 | - */ |
|
| 117 | - private $mountOptions = []; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Whether it's a personal or admin mount |
|
| 121 | - * |
|
| 122 | - * @var int |
|
| 123 | - */ |
|
| 124 | - private $type; |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Creates a storage config |
|
| 128 | - * |
|
| 129 | - * @param int|string $id config id or null for a new config |
|
| 130 | - */ |
|
| 131 | - public function __construct($id = null) { |
|
| 132 | - $this->id = $id ?? -1; |
|
| 133 | - $this->mountOptions['enable_sharing'] = false; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Returns the configuration id |
|
| 138 | - * |
|
| 139 | - * @retun int |
|
| 140 | - */ |
|
| 141 | - public function getId() { |
|
| 142 | - return $this->id; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Sets the configuration id |
|
| 147 | - * |
|
| 148 | - * @param int $id configuration id |
|
| 149 | - */ |
|
| 150 | - public function setId(int $id): void { |
|
| 151 | - $this->id = $id; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Returns mount point path relative to the user's |
|
| 156 | - * "files" folder. |
|
| 157 | - * |
|
| 158 | - * @return string path |
|
| 159 | - */ |
|
| 160 | - public function getMountPoint() { |
|
| 161 | - return $this->mountPoint; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Sets mount point path relative to the user's |
|
| 166 | - * "files" folder. |
|
| 167 | - * The path will be normalized. |
|
| 168 | - * |
|
| 169 | - * @param string $mountPoint path |
|
| 170 | - */ |
|
| 171 | - public function setMountPoint($mountPoint) { |
|
| 172 | - $this->mountPoint = \OC\Files\Filesystem::normalizePath($mountPoint); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * @return Backend |
|
| 177 | - */ |
|
| 178 | - public function getBackend() { |
|
| 179 | - return $this->backend; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * @param Backend $backend |
|
| 184 | - */ |
|
| 185 | - public function setBackend(Backend $backend) { |
|
| 186 | - $this->backend = $backend; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * @return AuthMechanism |
|
| 191 | - */ |
|
| 192 | - public function getAuthMechanism() { |
|
| 193 | - return $this->authMechanism; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * @param AuthMechanism $authMechanism |
|
| 198 | - */ |
|
| 199 | - public function setAuthMechanism(AuthMechanism $authMechanism) { |
|
| 200 | - $this->authMechanism = $authMechanism; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Returns the external storage backend-specific options |
|
| 205 | - * |
|
| 206 | - * @return array backend options |
|
| 207 | - */ |
|
| 208 | - public function getBackendOptions() { |
|
| 209 | - return $this->backendOptions; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Sets the external storage backend-specific options |
|
| 214 | - * |
|
| 215 | - * @param array $backendOptions backend options |
|
| 216 | - */ |
|
| 217 | - public function setBackendOptions($backendOptions) { |
|
| 218 | - if ($this->getBackend() instanceof Backend) { |
|
| 219 | - $parameters = $this->getBackend()->getParameters(); |
|
| 220 | - foreach ($backendOptions as $key => $value) { |
|
| 221 | - if (isset($parameters[$key])) { |
|
| 222 | - switch ($parameters[$key]->getType()) { |
|
| 223 | - case \OCA\Files_External\Lib\DefinitionParameter::VALUE_BOOLEAN: |
|
| 224 | - $value = (bool)$value; |
|
| 225 | - break; |
|
| 226 | - } |
|
| 227 | - $backendOptions[$key] = $value; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - $this->backendOptions = $backendOptions; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * @param string $key |
|
| 237 | - * @return mixed |
|
| 238 | - */ |
|
| 239 | - public function getBackendOption($key) { |
|
| 240 | - if (isset($this->backendOptions[$key])) { |
|
| 241 | - return $this->backendOptions[$key]; |
|
| 242 | - } |
|
| 243 | - return null; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * @param string $key |
|
| 248 | - * @param mixed $value |
|
| 249 | - */ |
|
| 250 | - public function setBackendOption($key, $value) { |
|
| 251 | - $this->backendOptions[$key] = $value; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Returns the mount priority |
|
| 256 | - * |
|
| 257 | - * @return int priority |
|
| 258 | - */ |
|
| 259 | - public function getPriority() { |
|
| 260 | - return $this->priority; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * Sets the mount priority |
|
| 265 | - * |
|
| 266 | - * @param int $priority priority |
|
| 267 | - */ |
|
| 268 | - public function setPriority($priority) { |
|
| 269 | - $this->priority = $priority; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Returns the users for which to mount this storage |
|
| 274 | - * |
|
| 275 | - * @return string[] applicable users |
|
| 276 | - */ |
|
| 277 | - public function getApplicableUsers() { |
|
| 278 | - return $this->applicableUsers; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * Sets the users for which to mount this storage |
|
| 283 | - * |
|
| 284 | - * @param string[]|null $applicableUsers applicable users |
|
| 285 | - */ |
|
| 286 | - public function setApplicableUsers($applicableUsers) { |
|
| 287 | - if (is_null($applicableUsers)) { |
|
| 288 | - $applicableUsers = []; |
|
| 289 | - } |
|
| 290 | - $this->applicableUsers = $applicableUsers; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * Returns the groups for which to mount this storage |
|
| 295 | - * |
|
| 296 | - * @return string[] applicable groups |
|
| 297 | - */ |
|
| 298 | - public function getApplicableGroups() { |
|
| 299 | - return $this->applicableGroups; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Sets the groups for which to mount this storage |
|
| 304 | - * |
|
| 305 | - * @param string[]|null $applicableGroups applicable groups |
|
| 306 | - */ |
|
| 307 | - public function setApplicableGroups($applicableGroups) { |
|
| 308 | - if (is_null($applicableGroups)) { |
|
| 309 | - $applicableGroups = []; |
|
| 310 | - } |
|
| 311 | - $this->applicableGroups = $applicableGroups; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * Returns the mount-specific options |
|
| 316 | - * |
|
| 317 | - * @return array mount specific options |
|
| 318 | - */ |
|
| 319 | - public function getMountOptions() { |
|
| 320 | - return $this->mountOptions; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * Sets the mount-specific options |
|
| 325 | - * |
|
| 326 | - * @param array $mountOptions applicable groups |
|
| 327 | - */ |
|
| 328 | - public function setMountOptions($mountOptions) { |
|
| 329 | - if (is_null($mountOptions)) { |
|
| 330 | - $mountOptions = []; |
|
| 331 | - } |
|
| 332 | - $this->mountOptions = $mountOptions; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * @param string $key |
|
| 337 | - * @return mixed |
|
| 338 | - */ |
|
| 339 | - public function getMountOption($key) { |
|
| 340 | - if (isset($this->mountOptions[$key])) { |
|
| 341 | - return $this->mountOptions[$key]; |
|
| 342 | - } |
|
| 343 | - return null; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * @param string $key |
|
| 348 | - * @param mixed $value |
|
| 349 | - */ |
|
| 350 | - public function setMountOption($key, $value) { |
|
| 351 | - $this->mountOptions[$key] = $value; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * Gets the storage status, whether the config worked last time |
|
| 356 | - * |
|
| 357 | - * @return int $status status |
|
| 358 | - */ |
|
| 359 | - public function getStatus() { |
|
| 360 | - return $this->status; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Gets the message describing the storage status |
|
| 365 | - * |
|
| 366 | - * @return string|null |
|
| 367 | - */ |
|
| 368 | - public function getStatusMessage() { |
|
| 369 | - return $this->statusMessage; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Sets the storage status, whether the config worked last time |
|
| 374 | - * |
|
| 375 | - * @param int $status status |
|
| 376 | - * @param string|null $message optional message |
|
| 377 | - */ |
|
| 378 | - public function setStatus($status, $message = null) { |
|
| 379 | - $this->status = $status; |
|
| 380 | - $this->statusMessage = $message; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * @return int self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl |
|
| 385 | - */ |
|
| 386 | - public function getType() { |
|
| 387 | - return $this->type; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl |
|
| 392 | - */ |
|
| 393 | - public function setType($type) { |
|
| 394 | - $this->type = $type; |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Serialize config to JSON |
|
| 399 | - */ |
|
| 400 | - public function jsonSerialize(): array { |
|
| 401 | - $result = []; |
|
| 402 | - if (!is_null($this->id)) { |
|
| 403 | - $result['id'] = $this->id; |
|
| 404 | - } |
|
| 405 | - $result['mountPoint'] = $this->mountPoint; |
|
| 406 | - $result['backend'] = $this->backend->getIdentifier(); |
|
| 407 | - $result['authMechanism'] = $this->authMechanism->getIdentifier(); |
|
| 408 | - $result['backendOptions'] = $this->backendOptions; |
|
| 409 | - if (!is_null($this->priority)) { |
|
| 410 | - $result['priority'] = $this->priority; |
|
| 411 | - } |
|
| 412 | - if (!empty($this->applicableUsers)) { |
|
| 413 | - $result['applicableUsers'] = $this->applicableUsers; |
|
| 414 | - } |
|
| 415 | - if (!empty($this->applicableGroups)) { |
|
| 416 | - $result['applicableGroups'] = $this->applicableGroups; |
|
| 417 | - } |
|
| 418 | - if (!empty($this->mountOptions)) { |
|
| 419 | - $result['mountOptions'] = $this->mountOptions; |
|
| 420 | - } |
|
| 421 | - if (!is_null($this->status)) { |
|
| 422 | - $result['status'] = $this->status; |
|
| 423 | - } |
|
| 424 | - if (!is_null($this->statusMessage)) { |
|
| 425 | - $result['statusMessage'] = $this->statusMessage; |
|
| 426 | - } |
|
| 427 | - $result['userProvided'] = $this->authMechanism instanceof IUserProvided; |
|
| 428 | - $result['type'] = ($this->getType() === self::MOUNT_TYPE_PERSONAl) ? 'personal': 'system'; |
|
| 429 | - return $result; |
|
| 430 | - } |
|
| 39 | + public const MOUNT_TYPE_ADMIN = 1; |
|
| 40 | + public const MOUNT_TYPE_PERSONAl = 2; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Storage config id |
|
| 44 | + * |
|
| 45 | + * @var int |
|
| 46 | + */ |
|
| 47 | + private $id; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Backend |
|
| 51 | + * |
|
| 52 | + * @var Backend |
|
| 53 | + */ |
|
| 54 | + private $backend; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Authentication mechanism |
|
| 58 | + * |
|
| 59 | + * @var AuthMechanism |
|
| 60 | + */ |
|
| 61 | + private $authMechanism; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Backend options |
|
| 65 | + * |
|
| 66 | + * @var array |
|
| 67 | + */ |
|
| 68 | + private $backendOptions = []; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Mount point path, relative to the user's "files" folder |
|
| 72 | + * |
|
| 73 | + * @var string |
|
| 74 | + */ |
|
| 75 | + private $mountPoint; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Storage status |
|
| 79 | + * |
|
| 80 | + * @var int |
|
| 81 | + */ |
|
| 82 | + private $status; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Status message |
|
| 86 | + * |
|
| 87 | + * @var string |
|
| 88 | + */ |
|
| 89 | + private $statusMessage; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Priority |
|
| 93 | + * |
|
| 94 | + * @var int |
|
| 95 | + */ |
|
| 96 | + private $priority; |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * List of users who have access to this storage |
|
| 100 | + * |
|
| 101 | + * @var string[] |
|
| 102 | + */ |
|
| 103 | + private $applicableUsers = []; |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * List of groups that have access to this storage |
|
| 107 | + * |
|
| 108 | + * @var string[] |
|
| 109 | + */ |
|
| 110 | + private $applicableGroups = []; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Mount-specific options |
|
| 114 | + * |
|
| 115 | + * @var array |
|
| 116 | + */ |
|
| 117 | + private $mountOptions = []; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Whether it's a personal or admin mount |
|
| 121 | + * |
|
| 122 | + * @var int |
|
| 123 | + */ |
|
| 124 | + private $type; |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Creates a storage config |
|
| 128 | + * |
|
| 129 | + * @param int|string $id config id or null for a new config |
|
| 130 | + */ |
|
| 131 | + public function __construct($id = null) { |
|
| 132 | + $this->id = $id ?? -1; |
|
| 133 | + $this->mountOptions['enable_sharing'] = false; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Returns the configuration id |
|
| 138 | + * |
|
| 139 | + * @retun int |
|
| 140 | + */ |
|
| 141 | + public function getId() { |
|
| 142 | + return $this->id; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Sets the configuration id |
|
| 147 | + * |
|
| 148 | + * @param int $id configuration id |
|
| 149 | + */ |
|
| 150 | + public function setId(int $id): void { |
|
| 151 | + $this->id = $id; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Returns mount point path relative to the user's |
|
| 156 | + * "files" folder. |
|
| 157 | + * |
|
| 158 | + * @return string path |
|
| 159 | + */ |
|
| 160 | + public function getMountPoint() { |
|
| 161 | + return $this->mountPoint; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Sets mount point path relative to the user's |
|
| 166 | + * "files" folder. |
|
| 167 | + * The path will be normalized. |
|
| 168 | + * |
|
| 169 | + * @param string $mountPoint path |
|
| 170 | + */ |
|
| 171 | + public function setMountPoint($mountPoint) { |
|
| 172 | + $this->mountPoint = \OC\Files\Filesystem::normalizePath($mountPoint); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * @return Backend |
|
| 177 | + */ |
|
| 178 | + public function getBackend() { |
|
| 179 | + return $this->backend; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * @param Backend $backend |
|
| 184 | + */ |
|
| 185 | + public function setBackend(Backend $backend) { |
|
| 186 | + $this->backend = $backend; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * @return AuthMechanism |
|
| 191 | + */ |
|
| 192 | + public function getAuthMechanism() { |
|
| 193 | + return $this->authMechanism; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * @param AuthMechanism $authMechanism |
|
| 198 | + */ |
|
| 199 | + public function setAuthMechanism(AuthMechanism $authMechanism) { |
|
| 200 | + $this->authMechanism = $authMechanism; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Returns the external storage backend-specific options |
|
| 205 | + * |
|
| 206 | + * @return array backend options |
|
| 207 | + */ |
|
| 208 | + public function getBackendOptions() { |
|
| 209 | + return $this->backendOptions; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Sets the external storage backend-specific options |
|
| 214 | + * |
|
| 215 | + * @param array $backendOptions backend options |
|
| 216 | + */ |
|
| 217 | + public function setBackendOptions($backendOptions) { |
|
| 218 | + if ($this->getBackend() instanceof Backend) { |
|
| 219 | + $parameters = $this->getBackend()->getParameters(); |
|
| 220 | + foreach ($backendOptions as $key => $value) { |
|
| 221 | + if (isset($parameters[$key])) { |
|
| 222 | + switch ($parameters[$key]->getType()) { |
|
| 223 | + case \OCA\Files_External\Lib\DefinitionParameter::VALUE_BOOLEAN: |
|
| 224 | + $value = (bool)$value; |
|
| 225 | + break; |
|
| 226 | + } |
|
| 227 | + $backendOptions[$key] = $value; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + $this->backendOptions = $backendOptions; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * @param string $key |
|
| 237 | + * @return mixed |
|
| 238 | + */ |
|
| 239 | + public function getBackendOption($key) { |
|
| 240 | + if (isset($this->backendOptions[$key])) { |
|
| 241 | + return $this->backendOptions[$key]; |
|
| 242 | + } |
|
| 243 | + return null; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * @param string $key |
|
| 248 | + * @param mixed $value |
|
| 249 | + */ |
|
| 250 | + public function setBackendOption($key, $value) { |
|
| 251 | + $this->backendOptions[$key] = $value; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Returns the mount priority |
|
| 256 | + * |
|
| 257 | + * @return int priority |
|
| 258 | + */ |
|
| 259 | + public function getPriority() { |
|
| 260 | + return $this->priority; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * Sets the mount priority |
|
| 265 | + * |
|
| 266 | + * @param int $priority priority |
|
| 267 | + */ |
|
| 268 | + public function setPriority($priority) { |
|
| 269 | + $this->priority = $priority; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Returns the users for which to mount this storage |
|
| 274 | + * |
|
| 275 | + * @return string[] applicable users |
|
| 276 | + */ |
|
| 277 | + public function getApplicableUsers() { |
|
| 278 | + return $this->applicableUsers; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * Sets the users for which to mount this storage |
|
| 283 | + * |
|
| 284 | + * @param string[]|null $applicableUsers applicable users |
|
| 285 | + */ |
|
| 286 | + public function setApplicableUsers($applicableUsers) { |
|
| 287 | + if (is_null($applicableUsers)) { |
|
| 288 | + $applicableUsers = []; |
|
| 289 | + } |
|
| 290 | + $this->applicableUsers = $applicableUsers; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * Returns the groups for which to mount this storage |
|
| 295 | + * |
|
| 296 | + * @return string[] applicable groups |
|
| 297 | + */ |
|
| 298 | + public function getApplicableGroups() { |
|
| 299 | + return $this->applicableGroups; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Sets the groups for which to mount this storage |
|
| 304 | + * |
|
| 305 | + * @param string[]|null $applicableGroups applicable groups |
|
| 306 | + */ |
|
| 307 | + public function setApplicableGroups($applicableGroups) { |
|
| 308 | + if (is_null($applicableGroups)) { |
|
| 309 | + $applicableGroups = []; |
|
| 310 | + } |
|
| 311 | + $this->applicableGroups = $applicableGroups; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * Returns the mount-specific options |
|
| 316 | + * |
|
| 317 | + * @return array mount specific options |
|
| 318 | + */ |
|
| 319 | + public function getMountOptions() { |
|
| 320 | + return $this->mountOptions; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * Sets the mount-specific options |
|
| 325 | + * |
|
| 326 | + * @param array $mountOptions applicable groups |
|
| 327 | + */ |
|
| 328 | + public function setMountOptions($mountOptions) { |
|
| 329 | + if (is_null($mountOptions)) { |
|
| 330 | + $mountOptions = []; |
|
| 331 | + } |
|
| 332 | + $this->mountOptions = $mountOptions; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * @param string $key |
|
| 337 | + * @return mixed |
|
| 338 | + */ |
|
| 339 | + public function getMountOption($key) { |
|
| 340 | + if (isset($this->mountOptions[$key])) { |
|
| 341 | + return $this->mountOptions[$key]; |
|
| 342 | + } |
|
| 343 | + return null; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * @param string $key |
|
| 348 | + * @param mixed $value |
|
| 349 | + */ |
|
| 350 | + public function setMountOption($key, $value) { |
|
| 351 | + $this->mountOptions[$key] = $value; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * Gets the storage status, whether the config worked last time |
|
| 356 | + * |
|
| 357 | + * @return int $status status |
|
| 358 | + */ |
|
| 359 | + public function getStatus() { |
|
| 360 | + return $this->status; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Gets the message describing the storage status |
|
| 365 | + * |
|
| 366 | + * @return string|null |
|
| 367 | + */ |
|
| 368 | + public function getStatusMessage() { |
|
| 369 | + return $this->statusMessage; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Sets the storage status, whether the config worked last time |
|
| 374 | + * |
|
| 375 | + * @param int $status status |
|
| 376 | + * @param string|null $message optional message |
|
| 377 | + */ |
|
| 378 | + public function setStatus($status, $message = null) { |
|
| 379 | + $this->status = $status; |
|
| 380 | + $this->statusMessage = $message; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * @return int self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl |
|
| 385 | + */ |
|
| 386 | + public function getType() { |
|
| 387 | + return $this->type; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl |
|
| 392 | + */ |
|
| 393 | + public function setType($type) { |
|
| 394 | + $this->type = $type; |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Serialize config to JSON |
|
| 399 | + */ |
|
| 400 | + public function jsonSerialize(): array { |
|
| 401 | + $result = []; |
|
| 402 | + if (!is_null($this->id)) { |
|
| 403 | + $result['id'] = $this->id; |
|
| 404 | + } |
|
| 405 | + $result['mountPoint'] = $this->mountPoint; |
|
| 406 | + $result['backend'] = $this->backend->getIdentifier(); |
|
| 407 | + $result['authMechanism'] = $this->authMechanism->getIdentifier(); |
|
| 408 | + $result['backendOptions'] = $this->backendOptions; |
|
| 409 | + if (!is_null($this->priority)) { |
|
| 410 | + $result['priority'] = $this->priority; |
|
| 411 | + } |
|
| 412 | + if (!empty($this->applicableUsers)) { |
|
| 413 | + $result['applicableUsers'] = $this->applicableUsers; |
|
| 414 | + } |
|
| 415 | + if (!empty($this->applicableGroups)) { |
|
| 416 | + $result['applicableGroups'] = $this->applicableGroups; |
|
| 417 | + } |
|
| 418 | + if (!empty($this->mountOptions)) { |
|
| 419 | + $result['mountOptions'] = $this->mountOptions; |
|
| 420 | + } |
|
| 421 | + if (!is_null($this->status)) { |
|
| 422 | + $result['status'] = $this->status; |
|
| 423 | + } |
|
| 424 | + if (!is_null($this->statusMessage)) { |
|
| 425 | + $result['statusMessage'] = $this->statusMessage; |
|
| 426 | + } |
|
| 427 | + $result['userProvided'] = $this->authMechanism instanceof IUserProvided; |
|
| 428 | + $result['type'] = ($this->getType() === self::MOUNT_TYPE_PERSONAl) ? 'personal': 'system'; |
|
| 429 | + return $result; |
|
| 430 | + } |
|
| 431 | 431 | } |
@@ -50,7 +50,7 @@ |
||
| 50 | 50 | ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
| 51 | 51 | ]) |
| 52 | 52 | ->addAuthScheme(AuthMechanism::SCHEME_OPENSTACK) |
| 53 | - ->setLegacyAuthMechanismCallback(function (array $params) use ($openstackAuth, $rackspaceAuth) { |
|
| 53 | + ->setLegacyAuthMechanismCallback(function(array $params) use ($openstackAuth, $rackspaceAuth) { |
|
| 54 | 54 | if (isset($params['options']['key']) && $params['options']['key']) { |
| 55 | 55 | return $rackspaceAuth; |
| 56 | 56 | } |
@@ -33,29 +33,29 @@ |
||
| 33 | 33 | use OCP\IL10N; |
| 34 | 34 | |
| 35 | 35 | class Swift extends Backend { |
| 36 | - use LegacyDependencyCheckPolyfill; |
|
| 36 | + use LegacyDependencyCheckPolyfill; |
|
| 37 | 37 | |
| 38 | - public function __construct(IL10N $l, OpenStackV2 $openstackAuth, Rackspace $rackspaceAuth) { |
|
| 39 | - $this |
|
| 40 | - ->setIdentifier('swift') |
|
| 41 | - ->addIdentifierAlias('\OC\Files\Storage\Swift') // legacy compat |
|
| 42 | - ->setStorageClass('\OCA\Files_External\Lib\Storage\Swift') |
|
| 43 | - ->setText($l->t('OpenStack Object Storage')) |
|
| 44 | - ->addParameters([ |
|
| 45 | - (new DefinitionParameter('service_name', $l->t('Service name'))) |
|
| 46 | - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
| 47 | - new DefinitionParameter('region', $l->t('Region')), |
|
| 48 | - new DefinitionParameter('bucket', $l->t('Bucket')), |
|
| 49 | - (new DefinitionParameter('timeout', $l->t('Request timeout (seconds)'))) |
|
| 50 | - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
| 51 | - ]) |
|
| 52 | - ->addAuthScheme(AuthMechanism::SCHEME_OPENSTACK) |
|
| 53 | - ->setLegacyAuthMechanismCallback(function (array $params) use ($openstackAuth, $rackspaceAuth) { |
|
| 54 | - if (isset($params['options']['key']) && $params['options']['key']) { |
|
| 55 | - return $rackspaceAuth; |
|
| 56 | - } |
|
| 57 | - return $openstackAuth; |
|
| 58 | - }) |
|
| 59 | - ; |
|
| 60 | - } |
|
| 38 | + public function __construct(IL10N $l, OpenStackV2 $openstackAuth, Rackspace $rackspaceAuth) { |
|
| 39 | + $this |
|
| 40 | + ->setIdentifier('swift') |
|
| 41 | + ->addIdentifierAlias('\OC\Files\Storage\Swift') // legacy compat |
|
| 42 | + ->setStorageClass('\OCA\Files_External\Lib\Storage\Swift') |
|
| 43 | + ->setText($l->t('OpenStack Object Storage')) |
|
| 44 | + ->addParameters([ |
|
| 45 | + (new DefinitionParameter('service_name', $l->t('Service name'))) |
|
| 46 | + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
| 47 | + new DefinitionParameter('region', $l->t('Region')), |
|
| 48 | + new DefinitionParameter('bucket', $l->t('Bucket')), |
|
| 49 | + (new DefinitionParameter('timeout', $l->t('Request timeout (seconds)'))) |
|
| 50 | + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
| 51 | + ]) |
|
| 52 | + ->addAuthScheme(AuthMechanism::SCHEME_OPENSTACK) |
|
| 53 | + ->setLegacyAuthMechanismCallback(function (array $params) use ($openstackAuth, $rackspaceAuth) { |
|
| 54 | + if (isset($params['options']['key']) && $params['options']['key']) { |
|
| 55 | + return $rackspaceAuth; |
|
| 56 | + } |
|
| 57 | + return $openstackAuth; |
|
| 58 | + }) |
|
| 59 | + ; |
|
| 60 | + } |
|
| 61 | 61 | } |