@@ -26,60 +26,60 @@ |
||
26 | 26 | use OCP\ITagManager; |
27 | 27 | |
28 | 28 | class Helper { |
29 | - /** If a user has a lot of favorites the query might get too slow and long */ |
|
30 | - public const FAVORITE_LIMIT = 50; |
|
29 | + /** If a user has a lot of favorites the query might get too slow and long */ |
|
30 | + public const FAVORITE_LIMIT = 50; |
|
31 | 31 | |
32 | - /** @var ITagManager */ |
|
33 | - protected $tagManager; |
|
32 | + /** @var ITagManager */ |
|
33 | + protected $tagManager; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param ITagManager $tagManager |
|
37 | - */ |
|
38 | - public function __construct(ITagManager $tagManager) { |
|
39 | - $this->tagManager = $tagManager; |
|
40 | - } |
|
35 | + /** |
|
36 | + * @param ITagManager $tagManager |
|
37 | + */ |
|
38 | + public function __construct(ITagManager $tagManager) { |
|
39 | + $this->tagManager = $tagManager; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Returns an array with the favorites |
|
44 | - * |
|
45 | - * @param string $user |
|
46 | - * @return array |
|
47 | - * @throws \RuntimeException when too many or no favorites where found |
|
48 | - */ |
|
49 | - public function getFavoriteFilePaths($user) { |
|
50 | - $tags = $this->tagManager->load('files', [], false, $user); |
|
51 | - $favorites = $tags->getFavorites(); |
|
42 | + /** |
|
43 | + * Returns an array with the favorites |
|
44 | + * |
|
45 | + * @param string $user |
|
46 | + * @return array |
|
47 | + * @throws \RuntimeException when too many or no favorites where found |
|
48 | + */ |
|
49 | + public function getFavoriteFilePaths($user) { |
|
50 | + $tags = $this->tagManager->load('files', [], false, $user); |
|
51 | + $favorites = $tags->getFavorites(); |
|
52 | 52 | |
53 | - if (empty($favorites)) { |
|
54 | - throw new \RuntimeException('No favorites', 1); |
|
55 | - } elseif (isset($favorites[self::FAVORITE_LIMIT])) { |
|
56 | - throw new \RuntimeException('Too many favorites', 2); |
|
57 | - } |
|
53 | + if (empty($favorites)) { |
|
54 | + throw new \RuntimeException('No favorites', 1); |
|
55 | + } elseif (isset($favorites[self::FAVORITE_LIMIT])) { |
|
56 | + throw new \RuntimeException('Too many favorites', 2); |
|
57 | + } |
|
58 | 58 | |
59 | - // Can not DI because the user is not known on instantiation |
|
60 | - $rootFolder = \OC::$server->getUserFolder($user); |
|
61 | - $folders = $items = []; |
|
62 | - foreach ($favorites as $favorite) { |
|
63 | - $nodes = $rootFolder->getById($favorite); |
|
64 | - if (!empty($nodes)) { |
|
65 | - /** @var \OCP\Files\Node $node */ |
|
66 | - $node = array_shift($nodes); |
|
67 | - $path = substr($node->getPath(), strlen($user . '/files/')); |
|
59 | + // Can not DI because the user is not known on instantiation |
|
60 | + $rootFolder = \OC::$server->getUserFolder($user); |
|
61 | + $folders = $items = []; |
|
62 | + foreach ($favorites as $favorite) { |
|
63 | + $nodes = $rootFolder->getById($favorite); |
|
64 | + if (!empty($nodes)) { |
|
65 | + /** @var \OCP\Files\Node $node */ |
|
66 | + $node = array_shift($nodes); |
|
67 | + $path = substr($node->getPath(), strlen($user . '/files/')); |
|
68 | 68 | |
69 | - $items[] = $path; |
|
70 | - if ($node instanceof Folder) { |
|
71 | - $folders[] = $path; |
|
72 | - } |
|
73 | - } |
|
74 | - } |
|
69 | + $items[] = $path; |
|
70 | + if ($node instanceof Folder) { |
|
71 | + $folders[] = $path; |
|
72 | + } |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | - if (empty($items)) { |
|
77 | - throw new \RuntimeException('No favorites', 1); |
|
78 | - } |
|
76 | + if (empty($items)) { |
|
77 | + throw new \RuntimeException('No favorites', 1); |
|
78 | + } |
|
79 | 79 | |
80 | - return [ |
|
81 | - 'items' => $items, |
|
82 | - 'folders' => $folders, |
|
83 | - ]; |
|
84 | - } |
|
80 | + return [ |
|
81 | + 'items' => $items, |
|
82 | + 'folders' => $folders, |
|
83 | + ]; |
|
84 | + } |
|
85 | 85 | } |
@@ -26,51 +26,51 @@ |
||
26 | 26 | use Sabre\DAV\Exception; |
27 | 27 | |
28 | 28 | class InvalidPath extends Exception { |
29 | - public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
29 | + public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @var bool |
|
33 | - */ |
|
34 | - private $retry; |
|
31 | + /** |
|
32 | + * @var bool |
|
33 | + */ |
|
34 | + private $retry; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param string $message |
|
38 | - * @param bool $retry |
|
39 | - * @param \Exception|null $previous |
|
40 | - */ |
|
41 | - public function __construct($message, $retry = false, \Exception $previous = null) { |
|
42 | - parent::__construct($message, 0, $previous); |
|
43 | - $this->retry = $retry; |
|
44 | - } |
|
36 | + /** |
|
37 | + * @param string $message |
|
38 | + * @param bool $retry |
|
39 | + * @param \Exception|null $previous |
|
40 | + */ |
|
41 | + public function __construct($message, $retry = false, \Exception $previous = null) { |
|
42 | + parent::__construct($message, 0, $previous); |
|
43 | + $this->retry = $retry; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Returns the HTTP status code for this exception |
|
48 | - * |
|
49 | - * @return int |
|
50 | - */ |
|
51 | - public function getHTTPCode() { |
|
52 | - return 400; |
|
53 | - } |
|
46 | + /** |
|
47 | + * Returns the HTTP status code for this exception |
|
48 | + * |
|
49 | + * @return int |
|
50 | + */ |
|
51 | + public function getHTTPCode() { |
|
52 | + return 400; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * This method allows the exception to include additional information |
|
57 | - * into the WebDAV error response |
|
58 | - * |
|
59 | - * @param \Sabre\DAV\Server $server |
|
60 | - * @param \DOMElement $errorNode |
|
61 | - * @return void |
|
62 | - */ |
|
63 | - public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
55 | + /** |
|
56 | + * This method allows the exception to include additional information |
|
57 | + * into the WebDAV error response |
|
58 | + * |
|
59 | + * @param \Sabre\DAV\Server $server |
|
60 | + * @param \DOMElement $errorNode |
|
61 | + * @return void |
|
62 | + */ |
|
63 | + public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
64 | 64 | |
65 | - // set ownCloud namespace |
|
66 | - $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
65 | + // set ownCloud namespace |
|
66 | + $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
67 | 67 | |
68 | - // adding the retry node |
|
69 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
70 | - $errorNode->appendChild($error); |
|
68 | + // adding the retry node |
|
69 | + $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
70 | + $errorNode->appendChild($error); |
|
71 | 71 | |
72 | - // adding the message node |
|
73 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
74 | - $errorNode->appendChild($error); |
|
75 | - } |
|
72 | + // adding the message node |
|
73 | + $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
74 | + $errorNode->appendChild($error); |
|
75 | + } |
|
76 | 76 | } |
@@ -29,26 +29,26 @@ |
||
29 | 29 | use Sabre\DAV\Server; |
30 | 30 | |
31 | 31 | class PasswordLoginForbidden extends NotAuthenticated { |
32 | - public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
32 | + public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
33 | 33 | |
34 | - public function getHTTPCode() { |
|
35 | - return 401; |
|
36 | - } |
|
34 | + public function getHTTPCode() { |
|
35 | + return 401; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * This method allows the exception to include additional information |
|
40 | - * into the WebDAV error response |
|
41 | - * |
|
42 | - * @param Server $server |
|
43 | - * @param DOMElement $errorNode |
|
44 | - * @return void |
|
45 | - */ |
|
46 | - public function serialize(Server $server, DOMElement $errorNode) { |
|
38 | + /** |
|
39 | + * This method allows the exception to include additional information |
|
40 | + * into the WebDAV error response |
|
41 | + * |
|
42 | + * @param Server $server |
|
43 | + * @param DOMElement $errorNode |
|
44 | + * @return void |
|
45 | + */ |
|
46 | + public function serialize(Server $server, DOMElement $errorNode) { |
|
47 | 47 | |
48 | - // set ownCloud namespace |
|
49 | - $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
48 | + // set ownCloud namespace |
|
49 | + $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
50 | 50 | |
51 | - $error = $errorNode->ownerDocument->createElementNS('o:', 'o:hint', 'password login forbidden'); |
|
52 | - $errorNode->appendChild($error); |
|
53 | - } |
|
51 | + $error = $errorNode->ownerDocument->createElementNS('o:', 'o:hint', 'password login forbidden'); |
|
52 | + $errorNode->appendChild($error); |
|
53 | + } |
|
54 | 54 | } |
@@ -23,42 +23,42 @@ |
||
23 | 23 | namespace OCA\DAV\Connector\Sabre\Exception; |
24 | 24 | |
25 | 25 | class Forbidden extends \Sabre\DAV\Exception\Forbidden { |
26 | - public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
26 | + public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @var bool |
|
30 | - */ |
|
31 | - private $retry; |
|
28 | + /** |
|
29 | + * @var bool |
|
30 | + */ |
|
31 | + private $retry; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @param string $message |
|
35 | - * @param bool $retry |
|
36 | - * @param \Exception $previous |
|
37 | - */ |
|
38 | - public function __construct($message, $retry = false, \Exception $previous = null) { |
|
39 | - parent::__construct($message, 0, $previous); |
|
40 | - $this->retry = $retry; |
|
41 | - } |
|
33 | + /** |
|
34 | + * @param string $message |
|
35 | + * @param bool $retry |
|
36 | + * @param \Exception $previous |
|
37 | + */ |
|
38 | + public function __construct($message, $retry = false, \Exception $previous = null) { |
|
39 | + parent::__construct($message, 0, $previous); |
|
40 | + $this->retry = $retry; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * This method allows the exception to include additional information |
|
45 | - * into the WebDAV error response |
|
46 | - * |
|
47 | - * @param \Sabre\DAV\Server $server |
|
48 | - * @param \DOMElement $errorNode |
|
49 | - * @return void |
|
50 | - */ |
|
51 | - public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
43 | + /** |
|
44 | + * This method allows the exception to include additional information |
|
45 | + * into the WebDAV error response |
|
46 | + * |
|
47 | + * @param \Sabre\DAV\Server $server |
|
48 | + * @param \DOMElement $errorNode |
|
49 | + * @return void |
|
50 | + */ |
|
51 | + public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
52 | 52 | |
53 | - // set ownCloud namespace |
|
54 | - $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
53 | + // set ownCloud namespace |
|
54 | + $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
55 | 55 | |
56 | - // adding the retry node |
|
57 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
58 | - $errorNode->appendChild($error); |
|
56 | + // adding the retry node |
|
57 | + $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
58 | + $errorNode->appendChild($error); |
|
59 | 59 | |
60 | - // adding the message node |
|
61 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
62 | - $errorNode->appendChild($error); |
|
63 | - } |
|
60 | + // adding the message node |
|
61 | + $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
62 | + $errorNode->appendChild($error); |
|
63 | + } |
|
64 | 64 | } |
@@ -43,59 +43,59 @@ |
||
43 | 43 | * @package OCA\DAV\Connector\Sabre |
44 | 44 | */ |
45 | 45 | class DavAclPlugin extends \Sabre\DAVACL\Plugin { |
46 | - public function __construct() { |
|
47 | - $this->hideNodesFromListings = true; |
|
48 | - $this->allowUnauthenticatedAccess = false; |
|
49 | - } |
|
46 | + public function __construct() { |
|
47 | + $this->hideNodesFromListings = true; |
|
48 | + $this->allowUnauthenticatedAccess = false; |
|
49 | + } |
|
50 | 50 | |
51 | - public function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) { |
|
52 | - $access = parent::checkPrivileges($uri, $privileges, $recursion, false); |
|
53 | - if ($access === false && $throwExceptions) { |
|
54 | - /** @var INode $node */ |
|
55 | - $node = $this->server->tree->getNodeForPath($uri); |
|
51 | + public function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) { |
|
52 | + $access = parent::checkPrivileges($uri, $privileges, $recursion, false); |
|
53 | + if ($access === false && $throwExceptions) { |
|
54 | + /** @var INode $node */ |
|
55 | + $node = $this->server->tree->getNodeForPath($uri); |
|
56 | 56 | |
57 | - switch (get_class($node)) { |
|
58 | - case AddressBook::class: |
|
59 | - $type = 'Addressbook'; |
|
60 | - break; |
|
61 | - default: |
|
62 | - $type = 'Node'; |
|
63 | - break; |
|
64 | - } |
|
65 | - throw new NotFound( |
|
66 | - sprintf( |
|
67 | - "%s with name '%s' could not be found", |
|
68 | - $type, |
|
69 | - $node->getName() |
|
70 | - ) |
|
71 | - ); |
|
72 | - } |
|
57 | + switch (get_class($node)) { |
|
58 | + case AddressBook::class: |
|
59 | + $type = 'Addressbook'; |
|
60 | + break; |
|
61 | + default: |
|
62 | + $type = 'Node'; |
|
63 | + break; |
|
64 | + } |
|
65 | + throw new NotFound( |
|
66 | + sprintf( |
|
67 | + "%s with name '%s' could not be found", |
|
68 | + $type, |
|
69 | + $node->getName() |
|
70 | + ) |
|
71 | + ); |
|
72 | + } |
|
73 | 73 | |
74 | - return $access; |
|
75 | - } |
|
74 | + return $access; |
|
75 | + } |
|
76 | 76 | |
77 | - public function propFind(PropFind $propFind, INode $node) { |
|
78 | - // If the node is neither readable nor writable then fail unless its of |
|
79 | - // the standard user-principal |
|
80 | - if (!($node instanceof User)) { |
|
81 | - $path = $propFind->getPath(); |
|
82 | - $readPermissions = $this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, false); |
|
83 | - $writePermissions = $this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, false); |
|
84 | - if ($readPermissions === false && $writePermissions === false) { |
|
85 | - $this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, true); |
|
86 | - $this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, true); |
|
87 | - } |
|
88 | - } |
|
77 | + public function propFind(PropFind $propFind, INode $node) { |
|
78 | + // If the node is neither readable nor writable then fail unless its of |
|
79 | + // the standard user-principal |
|
80 | + if (!($node instanceof User)) { |
|
81 | + $path = $propFind->getPath(); |
|
82 | + $readPermissions = $this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, false); |
|
83 | + $writePermissions = $this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, false); |
|
84 | + if ($readPermissions === false && $writePermissions === false) { |
|
85 | + $this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, true); |
|
86 | + $this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, true); |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - return parent::propFind($propFind, $node); |
|
91 | - } |
|
90 | + return parent::propFind($propFind, $node); |
|
91 | + } |
|
92 | 92 | |
93 | - public function beforeMethod(RequestInterface $request, ResponseInterface $response) { |
|
94 | - $path = $request->getPath(); |
|
93 | + public function beforeMethod(RequestInterface $request, ResponseInterface $response) { |
|
94 | + $path = $request->getPath(); |
|
95 | 95 | |
96 | - // prevent the plugin from causing an unneeded overhead for file requests |
|
97 | - if (strpos($path, 'files/') !== 0) { |
|
98 | - parent::beforeMethod($request, $response); |
|
99 | - } |
|
100 | - } |
|
96 | + // prevent the plugin from causing an unneeded overhead for file requests |
|
97 | + if (strpos($path, 'files/') !== 0) { |
|
98 | + parent::beforeMethod($request, $response); |
|
99 | + } |
|
100 | + } |
|
101 | 101 | } |
@@ -37,58 +37,58 @@ |
||
37 | 37 | |
38 | 38 | class SystemTagsRelationsCollection extends SimpleCollection { |
39 | 39 | |
40 | - /** |
|
41 | - * SystemTagsRelationsCollection constructor. |
|
42 | - * |
|
43 | - * @param ISystemTagManager $tagManager |
|
44 | - * @param ISystemTagObjectMapper $tagMapper |
|
45 | - * @param IUserSession $userSession |
|
46 | - * @param IGroupManager $groupManager |
|
47 | - * @param EventDispatcherInterface $dispatcher |
|
48 | - */ |
|
49 | - public function __construct( |
|
50 | - ISystemTagManager $tagManager, |
|
51 | - ISystemTagObjectMapper $tagMapper, |
|
52 | - IUserSession $userSession, |
|
53 | - IGroupManager $groupManager, |
|
54 | - EventDispatcherInterface $dispatcher |
|
55 | - ) { |
|
56 | - $children = [ |
|
57 | - new SystemTagsObjectTypeCollection( |
|
58 | - 'files', |
|
59 | - $tagManager, |
|
60 | - $tagMapper, |
|
61 | - $userSession, |
|
62 | - $groupManager, |
|
63 | - function ($name) { |
|
64 | - $nodes = \OC::$server->getUserFolder()->getById((int)$name); |
|
65 | - return !empty($nodes); |
|
66 | - } |
|
67 | - ), |
|
68 | - ]; |
|
40 | + /** |
|
41 | + * SystemTagsRelationsCollection constructor. |
|
42 | + * |
|
43 | + * @param ISystemTagManager $tagManager |
|
44 | + * @param ISystemTagObjectMapper $tagMapper |
|
45 | + * @param IUserSession $userSession |
|
46 | + * @param IGroupManager $groupManager |
|
47 | + * @param EventDispatcherInterface $dispatcher |
|
48 | + */ |
|
49 | + public function __construct( |
|
50 | + ISystemTagManager $tagManager, |
|
51 | + ISystemTagObjectMapper $tagMapper, |
|
52 | + IUserSession $userSession, |
|
53 | + IGroupManager $groupManager, |
|
54 | + EventDispatcherInterface $dispatcher |
|
55 | + ) { |
|
56 | + $children = [ |
|
57 | + new SystemTagsObjectTypeCollection( |
|
58 | + 'files', |
|
59 | + $tagManager, |
|
60 | + $tagMapper, |
|
61 | + $userSession, |
|
62 | + $groupManager, |
|
63 | + function ($name) { |
|
64 | + $nodes = \OC::$server->getUserFolder()->getById((int)$name); |
|
65 | + return !empty($nodes); |
|
66 | + } |
|
67 | + ), |
|
68 | + ]; |
|
69 | 69 | |
70 | - $event = new SystemTagsEntityEvent(SystemTagsEntityEvent::EVENT_ENTITY); |
|
71 | - $dispatcher->dispatch(SystemTagsEntityEvent::EVENT_ENTITY, $event); |
|
70 | + $event = new SystemTagsEntityEvent(SystemTagsEntityEvent::EVENT_ENTITY); |
|
71 | + $dispatcher->dispatch(SystemTagsEntityEvent::EVENT_ENTITY, $event); |
|
72 | 72 | |
73 | - foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) { |
|
74 | - $children[] = new SystemTagsObjectTypeCollection( |
|
75 | - $entity, |
|
76 | - $tagManager, |
|
77 | - $tagMapper, |
|
78 | - $userSession, |
|
79 | - $groupManager, |
|
80 | - $entityExistsFunction |
|
81 | - ); |
|
82 | - } |
|
73 | + foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) { |
|
74 | + $children[] = new SystemTagsObjectTypeCollection( |
|
75 | + $entity, |
|
76 | + $tagManager, |
|
77 | + $tagMapper, |
|
78 | + $userSession, |
|
79 | + $groupManager, |
|
80 | + $entityExistsFunction |
|
81 | + ); |
|
82 | + } |
|
83 | 83 | |
84 | - parent::__construct('root', $children); |
|
85 | - } |
|
84 | + parent::__construct('root', $children); |
|
85 | + } |
|
86 | 86 | |
87 | - public function getName() { |
|
88 | - return 'systemtags-relations'; |
|
89 | - } |
|
87 | + public function getName() { |
|
88 | + return 'systemtags-relations'; |
|
89 | + } |
|
90 | 90 | |
91 | - public function setName($name) { |
|
92 | - throw new Forbidden('Permission denied to rename this collection'); |
|
93 | - } |
|
91 | + public function setName($name) { |
|
92 | + throw new Forbidden('Permission denied to rename this collection'); |
|
93 | + } |
|
94 | 94 | } |
@@ -49,278 +49,278 @@ |
||
49 | 49 | */ |
50 | 50 | class SystemTagPlugin extends \Sabre\DAV\ServerPlugin { |
51 | 51 | |
52 | - // namespace |
|
53 | - public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
54 | - public const ID_PROPERTYNAME = '{http://owncloud.org/ns}id'; |
|
55 | - public const DISPLAYNAME_PROPERTYNAME = '{http://owncloud.org/ns}display-name'; |
|
56 | - public const USERVISIBLE_PROPERTYNAME = '{http://owncloud.org/ns}user-visible'; |
|
57 | - public const USERASSIGNABLE_PROPERTYNAME = '{http://owncloud.org/ns}user-assignable'; |
|
58 | - public const GROUPS_PROPERTYNAME = '{http://owncloud.org/ns}groups'; |
|
59 | - public const CANASSIGN_PROPERTYNAME = '{http://owncloud.org/ns}can-assign'; |
|
60 | - |
|
61 | - /** |
|
62 | - * @var \Sabre\DAV\Server $server |
|
63 | - */ |
|
64 | - private $server; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var ISystemTagManager |
|
68 | - */ |
|
69 | - protected $tagManager; |
|
70 | - |
|
71 | - /** |
|
72 | - * @var IUserSession |
|
73 | - */ |
|
74 | - protected $userSession; |
|
75 | - |
|
76 | - /** |
|
77 | - * @var IGroupManager |
|
78 | - */ |
|
79 | - protected $groupManager; |
|
80 | - |
|
81 | - /** |
|
82 | - * @param ISystemTagManager $tagManager tag manager |
|
83 | - * @param IGroupManager $groupManager |
|
84 | - * @param IUserSession $userSession |
|
85 | - */ |
|
86 | - public function __construct(ISystemTagManager $tagManager, |
|
87 | - IGroupManager $groupManager, |
|
88 | - IUserSession $userSession) { |
|
89 | - $this->tagManager = $tagManager; |
|
90 | - $this->userSession = $userSession; |
|
91 | - $this->groupManager = $groupManager; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * This initializes the plugin. |
|
96 | - * |
|
97 | - * This function is called by \Sabre\DAV\Server, after |
|
98 | - * addPlugin is called. |
|
99 | - * |
|
100 | - * This method should set up the required event subscriptions. |
|
101 | - * |
|
102 | - * @param \Sabre\DAV\Server $server |
|
103 | - * @return void |
|
104 | - */ |
|
105 | - public function initialize(\Sabre\DAV\Server $server) { |
|
106 | - $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
107 | - |
|
108 | - $server->protectedProperties[] = self::ID_PROPERTYNAME; |
|
109 | - |
|
110 | - $server->on('propFind', [$this, 'handleGetProperties']); |
|
111 | - $server->on('propPatch', [$this, 'handleUpdateProperties']); |
|
112 | - $server->on('method:POST', [$this, 'httpPost']); |
|
113 | - |
|
114 | - $this->server = $server; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * POST operation on system tag collections |
|
119 | - * |
|
120 | - * @param RequestInterface $request request object |
|
121 | - * @param ResponseInterface $response response object |
|
122 | - * @return null|false |
|
123 | - */ |
|
124 | - public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
125 | - $path = $request->getPath(); |
|
126 | - |
|
127 | - // Making sure the node exists |
|
128 | - $node = $this->server->tree->getNodeForPath($path); |
|
129 | - if ($node instanceof SystemTagsByIdCollection || $node instanceof SystemTagsObjectMappingCollection) { |
|
130 | - $data = $request->getBodyAsString(); |
|
131 | - |
|
132 | - $tag = $this->createTag($data, $request->getHeader('Content-Type')); |
|
133 | - |
|
134 | - if ($node instanceof SystemTagsObjectMappingCollection) { |
|
135 | - // also add to collection |
|
136 | - $node->createFile($tag->getId()); |
|
137 | - $url = $request->getBaseUrl() . 'systemtags/'; |
|
138 | - } else { |
|
139 | - $url = $request->getUrl(); |
|
140 | - } |
|
141 | - |
|
142 | - if ($url[strlen($url) - 1] !== '/') { |
|
143 | - $url .= '/'; |
|
144 | - } |
|
145 | - |
|
146 | - $response->setHeader('Content-Location', $url . $tag->getId()); |
|
147 | - |
|
148 | - // created |
|
149 | - $response->setStatus(201); |
|
150 | - return false; |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Creates a new tag |
|
156 | - * |
|
157 | - * @param string $data JSON encoded string containing the properties of the tag to create |
|
158 | - * @param string $contentType content type of the data |
|
159 | - * @return ISystemTag newly created system tag |
|
160 | - * |
|
161 | - * @throws BadRequest if a field was missing |
|
162 | - * @throws Conflict if a tag with the same properties already exists |
|
163 | - * @throws UnsupportedMediaType if the content type is not supported |
|
164 | - */ |
|
165 | - private function createTag($data, $contentType = 'application/json') { |
|
166 | - if (explode(';', $contentType)[0] === 'application/json') { |
|
167 | - $data = json_decode($data, true); |
|
168 | - } else { |
|
169 | - throw new UnsupportedMediaType(); |
|
170 | - } |
|
171 | - |
|
172 | - if (!isset($data['name'])) { |
|
173 | - throw new BadRequest('Missing "name" attribute'); |
|
174 | - } |
|
175 | - |
|
176 | - $tagName = $data['name']; |
|
177 | - $userVisible = true; |
|
178 | - $userAssignable = true; |
|
179 | - |
|
180 | - if (isset($data['userVisible'])) { |
|
181 | - $userVisible = (bool)$data['userVisible']; |
|
182 | - } |
|
183 | - |
|
184 | - if (isset($data['userAssignable'])) { |
|
185 | - $userAssignable = (bool)$data['userAssignable']; |
|
186 | - } |
|
187 | - |
|
188 | - $groups = []; |
|
189 | - if (isset($data['groups'])) { |
|
190 | - $groups = $data['groups']; |
|
191 | - if (is_string($groups)) { |
|
192 | - $groups = explode('|', $groups); |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - if ($userVisible === false || $userAssignable === false || !empty($groups)) { |
|
197 | - if (!$this->userSession->isLoggedIn() || !$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { |
|
198 | - throw new BadRequest('Not sufficient permissions'); |
|
199 | - } |
|
200 | - } |
|
201 | - |
|
202 | - try { |
|
203 | - $tag = $this->tagManager->createTag($tagName, $userVisible, $userAssignable); |
|
204 | - if (!empty($groups)) { |
|
205 | - $this->tagManager->setTagGroups($tag, $groups); |
|
206 | - } |
|
207 | - return $tag; |
|
208 | - } catch (TagAlreadyExistsException $e) { |
|
209 | - throw new Conflict('Tag already exists', 0, $e); |
|
210 | - } |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * Retrieves system tag properties |
|
216 | - * |
|
217 | - * @param PropFind $propFind |
|
218 | - * @param \Sabre\DAV\INode $node |
|
219 | - */ |
|
220 | - public function handleGetProperties( |
|
221 | - PropFind $propFind, |
|
222 | - \Sabre\DAV\INode $node |
|
223 | - ) { |
|
224 | - if (!($node instanceof SystemTagNode) && !($node instanceof SystemTagMappingNode)) { |
|
225 | - return; |
|
226 | - } |
|
227 | - |
|
228 | - $propFind->handle(self::ID_PROPERTYNAME, function () use ($node) { |
|
229 | - return $node->getSystemTag()->getId(); |
|
230 | - }); |
|
231 | - |
|
232 | - $propFind->handle(self::DISPLAYNAME_PROPERTYNAME, function () use ($node) { |
|
233 | - return $node->getSystemTag()->getName(); |
|
234 | - }); |
|
235 | - |
|
236 | - $propFind->handle(self::USERVISIBLE_PROPERTYNAME, function () use ($node) { |
|
237 | - return $node->getSystemTag()->isUserVisible() ? 'true' : 'false'; |
|
238 | - }); |
|
239 | - |
|
240 | - $propFind->handle(self::USERASSIGNABLE_PROPERTYNAME, function () use ($node) { |
|
241 | - // this is the tag's inherent property "is user assignable" |
|
242 | - return $node->getSystemTag()->isUserAssignable() ? 'true' : 'false'; |
|
243 | - }); |
|
244 | - |
|
245 | - $propFind->handle(self::CANASSIGN_PROPERTYNAME, function () use ($node) { |
|
246 | - // this is the effective permission for the current user |
|
247 | - return $this->tagManager->canUserAssignTag($node->getSystemTag(), $this->userSession->getUser()) ? 'true' : 'false'; |
|
248 | - }); |
|
249 | - |
|
250 | - $propFind->handle(self::GROUPS_PROPERTYNAME, function () use ($node) { |
|
251 | - if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { |
|
252 | - // property only available for admins |
|
253 | - throw new Forbidden(); |
|
254 | - } |
|
255 | - $groups = []; |
|
256 | - // no need to retrieve groups for namespaces that don't qualify |
|
257 | - if ($node->getSystemTag()->isUserVisible() && !$node->getSystemTag()->isUserAssignable()) { |
|
258 | - $groups = $this->tagManager->getTagGroups($node->getSystemTag()); |
|
259 | - } |
|
260 | - return implode('|', $groups); |
|
261 | - }); |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Updates tag attributes |
|
266 | - * |
|
267 | - * @param string $path |
|
268 | - * @param PropPatch $propPatch |
|
269 | - * |
|
270 | - * @return void |
|
271 | - */ |
|
272 | - public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
273 | - $node = $this->server->tree->getNodeForPath($path); |
|
274 | - if (!($node instanceof SystemTagNode)) { |
|
275 | - return; |
|
276 | - } |
|
277 | - |
|
278 | - $propPatch->handle([ |
|
279 | - self::DISPLAYNAME_PROPERTYNAME, |
|
280 | - self::USERVISIBLE_PROPERTYNAME, |
|
281 | - self::USERASSIGNABLE_PROPERTYNAME, |
|
282 | - self::GROUPS_PROPERTYNAME, |
|
283 | - ], function ($props) use ($node) { |
|
284 | - $tag = $node->getSystemTag(); |
|
285 | - $name = $tag->getName(); |
|
286 | - $userVisible = $tag->isUserVisible(); |
|
287 | - $userAssignable = $tag->isUserAssignable(); |
|
288 | - |
|
289 | - $updateTag = false; |
|
290 | - |
|
291 | - if (isset($props[self::DISPLAYNAME_PROPERTYNAME])) { |
|
292 | - $name = $props[self::DISPLAYNAME_PROPERTYNAME]; |
|
293 | - $updateTag = true; |
|
294 | - } |
|
295 | - |
|
296 | - if (isset($props[self::USERVISIBLE_PROPERTYNAME])) { |
|
297 | - $propValue = $props[self::USERVISIBLE_PROPERTYNAME]; |
|
298 | - $userVisible = ($propValue !== 'false' && $propValue !== '0'); |
|
299 | - $updateTag = true; |
|
300 | - } |
|
301 | - |
|
302 | - if (isset($props[self::USERASSIGNABLE_PROPERTYNAME])) { |
|
303 | - $propValue = $props[self::USERASSIGNABLE_PROPERTYNAME]; |
|
304 | - $userAssignable = ($propValue !== 'false' && $propValue !== '0'); |
|
305 | - $updateTag = true; |
|
306 | - } |
|
307 | - |
|
308 | - if (isset($props[self::GROUPS_PROPERTYNAME])) { |
|
309 | - if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { |
|
310 | - // property only available for admins |
|
311 | - throw new Forbidden(); |
|
312 | - } |
|
313 | - |
|
314 | - $propValue = $props[self::GROUPS_PROPERTYNAME]; |
|
315 | - $groupIds = explode('|', $propValue); |
|
316 | - $this->tagManager->setTagGroups($tag, $groupIds); |
|
317 | - } |
|
318 | - |
|
319 | - if ($updateTag) { |
|
320 | - $node->update($name, $userVisible, $userAssignable); |
|
321 | - } |
|
322 | - |
|
323 | - return true; |
|
324 | - }); |
|
325 | - } |
|
52 | + // namespace |
|
53 | + public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
54 | + public const ID_PROPERTYNAME = '{http://owncloud.org/ns}id'; |
|
55 | + public const DISPLAYNAME_PROPERTYNAME = '{http://owncloud.org/ns}display-name'; |
|
56 | + public const USERVISIBLE_PROPERTYNAME = '{http://owncloud.org/ns}user-visible'; |
|
57 | + public const USERASSIGNABLE_PROPERTYNAME = '{http://owncloud.org/ns}user-assignable'; |
|
58 | + public const GROUPS_PROPERTYNAME = '{http://owncloud.org/ns}groups'; |
|
59 | + public const CANASSIGN_PROPERTYNAME = '{http://owncloud.org/ns}can-assign'; |
|
60 | + |
|
61 | + /** |
|
62 | + * @var \Sabre\DAV\Server $server |
|
63 | + */ |
|
64 | + private $server; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var ISystemTagManager |
|
68 | + */ |
|
69 | + protected $tagManager; |
|
70 | + |
|
71 | + /** |
|
72 | + * @var IUserSession |
|
73 | + */ |
|
74 | + protected $userSession; |
|
75 | + |
|
76 | + /** |
|
77 | + * @var IGroupManager |
|
78 | + */ |
|
79 | + protected $groupManager; |
|
80 | + |
|
81 | + /** |
|
82 | + * @param ISystemTagManager $tagManager tag manager |
|
83 | + * @param IGroupManager $groupManager |
|
84 | + * @param IUserSession $userSession |
|
85 | + */ |
|
86 | + public function __construct(ISystemTagManager $tagManager, |
|
87 | + IGroupManager $groupManager, |
|
88 | + IUserSession $userSession) { |
|
89 | + $this->tagManager = $tagManager; |
|
90 | + $this->userSession = $userSession; |
|
91 | + $this->groupManager = $groupManager; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * This initializes the plugin. |
|
96 | + * |
|
97 | + * This function is called by \Sabre\DAV\Server, after |
|
98 | + * addPlugin is called. |
|
99 | + * |
|
100 | + * This method should set up the required event subscriptions. |
|
101 | + * |
|
102 | + * @param \Sabre\DAV\Server $server |
|
103 | + * @return void |
|
104 | + */ |
|
105 | + public function initialize(\Sabre\DAV\Server $server) { |
|
106 | + $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
107 | + |
|
108 | + $server->protectedProperties[] = self::ID_PROPERTYNAME; |
|
109 | + |
|
110 | + $server->on('propFind', [$this, 'handleGetProperties']); |
|
111 | + $server->on('propPatch', [$this, 'handleUpdateProperties']); |
|
112 | + $server->on('method:POST', [$this, 'httpPost']); |
|
113 | + |
|
114 | + $this->server = $server; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * POST operation on system tag collections |
|
119 | + * |
|
120 | + * @param RequestInterface $request request object |
|
121 | + * @param ResponseInterface $response response object |
|
122 | + * @return null|false |
|
123 | + */ |
|
124 | + public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
125 | + $path = $request->getPath(); |
|
126 | + |
|
127 | + // Making sure the node exists |
|
128 | + $node = $this->server->tree->getNodeForPath($path); |
|
129 | + if ($node instanceof SystemTagsByIdCollection || $node instanceof SystemTagsObjectMappingCollection) { |
|
130 | + $data = $request->getBodyAsString(); |
|
131 | + |
|
132 | + $tag = $this->createTag($data, $request->getHeader('Content-Type')); |
|
133 | + |
|
134 | + if ($node instanceof SystemTagsObjectMappingCollection) { |
|
135 | + // also add to collection |
|
136 | + $node->createFile($tag->getId()); |
|
137 | + $url = $request->getBaseUrl() . 'systemtags/'; |
|
138 | + } else { |
|
139 | + $url = $request->getUrl(); |
|
140 | + } |
|
141 | + |
|
142 | + if ($url[strlen($url) - 1] !== '/') { |
|
143 | + $url .= '/'; |
|
144 | + } |
|
145 | + |
|
146 | + $response->setHeader('Content-Location', $url . $tag->getId()); |
|
147 | + |
|
148 | + // created |
|
149 | + $response->setStatus(201); |
|
150 | + return false; |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Creates a new tag |
|
156 | + * |
|
157 | + * @param string $data JSON encoded string containing the properties of the tag to create |
|
158 | + * @param string $contentType content type of the data |
|
159 | + * @return ISystemTag newly created system tag |
|
160 | + * |
|
161 | + * @throws BadRequest if a field was missing |
|
162 | + * @throws Conflict if a tag with the same properties already exists |
|
163 | + * @throws UnsupportedMediaType if the content type is not supported |
|
164 | + */ |
|
165 | + private function createTag($data, $contentType = 'application/json') { |
|
166 | + if (explode(';', $contentType)[0] === 'application/json') { |
|
167 | + $data = json_decode($data, true); |
|
168 | + } else { |
|
169 | + throw new UnsupportedMediaType(); |
|
170 | + } |
|
171 | + |
|
172 | + if (!isset($data['name'])) { |
|
173 | + throw new BadRequest('Missing "name" attribute'); |
|
174 | + } |
|
175 | + |
|
176 | + $tagName = $data['name']; |
|
177 | + $userVisible = true; |
|
178 | + $userAssignable = true; |
|
179 | + |
|
180 | + if (isset($data['userVisible'])) { |
|
181 | + $userVisible = (bool)$data['userVisible']; |
|
182 | + } |
|
183 | + |
|
184 | + if (isset($data['userAssignable'])) { |
|
185 | + $userAssignable = (bool)$data['userAssignable']; |
|
186 | + } |
|
187 | + |
|
188 | + $groups = []; |
|
189 | + if (isset($data['groups'])) { |
|
190 | + $groups = $data['groups']; |
|
191 | + if (is_string($groups)) { |
|
192 | + $groups = explode('|', $groups); |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + if ($userVisible === false || $userAssignable === false || !empty($groups)) { |
|
197 | + if (!$this->userSession->isLoggedIn() || !$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { |
|
198 | + throw new BadRequest('Not sufficient permissions'); |
|
199 | + } |
|
200 | + } |
|
201 | + |
|
202 | + try { |
|
203 | + $tag = $this->tagManager->createTag($tagName, $userVisible, $userAssignable); |
|
204 | + if (!empty($groups)) { |
|
205 | + $this->tagManager->setTagGroups($tag, $groups); |
|
206 | + } |
|
207 | + return $tag; |
|
208 | + } catch (TagAlreadyExistsException $e) { |
|
209 | + throw new Conflict('Tag already exists', 0, $e); |
|
210 | + } |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * Retrieves system tag properties |
|
216 | + * |
|
217 | + * @param PropFind $propFind |
|
218 | + * @param \Sabre\DAV\INode $node |
|
219 | + */ |
|
220 | + public function handleGetProperties( |
|
221 | + PropFind $propFind, |
|
222 | + \Sabre\DAV\INode $node |
|
223 | + ) { |
|
224 | + if (!($node instanceof SystemTagNode) && !($node instanceof SystemTagMappingNode)) { |
|
225 | + return; |
|
226 | + } |
|
227 | + |
|
228 | + $propFind->handle(self::ID_PROPERTYNAME, function () use ($node) { |
|
229 | + return $node->getSystemTag()->getId(); |
|
230 | + }); |
|
231 | + |
|
232 | + $propFind->handle(self::DISPLAYNAME_PROPERTYNAME, function () use ($node) { |
|
233 | + return $node->getSystemTag()->getName(); |
|
234 | + }); |
|
235 | + |
|
236 | + $propFind->handle(self::USERVISIBLE_PROPERTYNAME, function () use ($node) { |
|
237 | + return $node->getSystemTag()->isUserVisible() ? 'true' : 'false'; |
|
238 | + }); |
|
239 | + |
|
240 | + $propFind->handle(self::USERASSIGNABLE_PROPERTYNAME, function () use ($node) { |
|
241 | + // this is the tag's inherent property "is user assignable" |
|
242 | + return $node->getSystemTag()->isUserAssignable() ? 'true' : 'false'; |
|
243 | + }); |
|
244 | + |
|
245 | + $propFind->handle(self::CANASSIGN_PROPERTYNAME, function () use ($node) { |
|
246 | + // this is the effective permission for the current user |
|
247 | + return $this->tagManager->canUserAssignTag($node->getSystemTag(), $this->userSession->getUser()) ? 'true' : 'false'; |
|
248 | + }); |
|
249 | + |
|
250 | + $propFind->handle(self::GROUPS_PROPERTYNAME, function () use ($node) { |
|
251 | + if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { |
|
252 | + // property only available for admins |
|
253 | + throw new Forbidden(); |
|
254 | + } |
|
255 | + $groups = []; |
|
256 | + // no need to retrieve groups for namespaces that don't qualify |
|
257 | + if ($node->getSystemTag()->isUserVisible() && !$node->getSystemTag()->isUserAssignable()) { |
|
258 | + $groups = $this->tagManager->getTagGroups($node->getSystemTag()); |
|
259 | + } |
|
260 | + return implode('|', $groups); |
|
261 | + }); |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Updates tag attributes |
|
266 | + * |
|
267 | + * @param string $path |
|
268 | + * @param PropPatch $propPatch |
|
269 | + * |
|
270 | + * @return void |
|
271 | + */ |
|
272 | + public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
273 | + $node = $this->server->tree->getNodeForPath($path); |
|
274 | + if (!($node instanceof SystemTagNode)) { |
|
275 | + return; |
|
276 | + } |
|
277 | + |
|
278 | + $propPatch->handle([ |
|
279 | + self::DISPLAYNAME_PROPERTYNAME, |
|
280 | + self::USERVISIBLE_PROPERTYNAME, |
|
281 | + self::USERASSIGNABLE_PROPERTYNAME, |
|
282 | + self::GROUPS_PROPERTYNAME, |
|
283 | + ], function ($props) use ($node) { |
|
284 | + $tag = $node->getSystemTag(); |
|
285 | + $name = $tag->getName(); |
|
286 | + $userVisible = $tag->isUserVisible(); |
|
287 | + $userAssignable = $tag->isUserAssignable(); |
|
288 | + |
|
289 | + $updateTag = false; |
|
290 | + |
|
291 | + if (isset($props[self::DISPLAYNAME_PROPERTYNAME])) { |
|
292 | + $name = $props[self::DISPLAYNAME_PROPERTYNAME]; |
|
293 | + $updateTag = true; |
|
294 | + } |
|
295 | + |
|
296 | + if (isset($props[self::USERVISIBLE_PROPERTYNAME])) { |
|
297 | + $propValue = $props[self::USERVISIBLE_PROPERTYNAME]; |
|
298 | + $userVisible = ($propValue !== 'false' && $propValue !== '0'); |
|
299 | + $updateTag = true; |
|
300 | + } |
|
301 | + |
|
302 | + if (isset($props[self::USERASSIGNABLE_PROPERTYNAME])) { |
|
303 | + $propValue = $props[self::USERASSIGNABLE_PROPERTYNAME]; |
|
304 | + $userAssignable = ($propValue !== 'false' && $propValue !== '0'); |
|
305 | + $updateTag = true; |
|
306 | + } |
|
307 | + |
|
308 | + if (isset($props[self::GROUPS_PROPERTYNAME])) { |
|
309 | + if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { |
|
310 | + // property only available for admins |
|
311 | + throw new Forbidden(); |
|
312 | + } |
|
313 | + |
|
314 | + $propValue = $props[self::GROUPS_PROPERTYNAME]; |
|
315 | + $groupIds = explode('|', $propValue); |
|
316 | + $this->tagManager->setTagGroups($tag, $groupIds); |
|
317 | + } |
|
318 | + |
|
319 | + if ($updateTag) { |
|
320 | + $node->update($name, $userVisible, $userAssignable); |
|
321 | + } |
|
322 | + |
|
323 | + return true; |
|
324 | + }); |
|
325 | + } |
|
326 | 326 | } |
@@ -39,102 +39,102 @@ |
||
39 | 39 | * @package OCA\DAV\CalDAV\BirthdayCalendar |
40 | 40 | */ |
41 | 41 | class EnablePlugin extends ServerPlugin { |
42 | - public const NS_Nextcloud = 'http://nextcloud.com/ns'; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var IConfig |
|
46 | - */ |
|
47 | - protected $config; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var BirthdayService |
|
51 | - */ |
|
52 | - protected $birthdayService; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var Server |
|
56 | - */ |
|
57 | - protected $server; |
|
58 | - |
|
59 | - /** |
|
60 | - * PublishPlugin constructor. |
|
61 | - * |
|
62 | - * @param IConfig $config |
|
63 | - * @param BirthdayService $birthdayService |
|
64 | - */ |
|
65 | - public function __construct(IConfig $config, BirthdayService $birthdayService) { |
|
66 | - $this->config = $config; |
|
67 | - $this->birthdayService = $birthdayService; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * This method should return a list of server-features. |
|
72 | - * |
|
73 | - * This is for example 'versioning' and is added to the DAV: header |
|
74 | - * in an OPTIONS response. |
|
75 | - * |
|
76 | - * @return string[] |
|
77 | - */ |
|
78 | - public function getFeatures() { |
|
79 | - return ['nc-enable-birthday-calendar']; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Returns a plugin name. |
|
84 | - * |
|
85 | - * Using this name other plugins will be able to access other plugins |
|
86 | - * using Sabre\DAV\Server::getPlugin |
|
87 | - * |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function getPluginName() { |
|
91 | - return 'nc-enable-birthday-calendar'; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * This initializes the plugin. |
|
96 | - * |
|
97 | - * This function is called by Sabre\DAV\Server, after |
|
98 | - * addPlugin is called. |
|
99 | - * |
|
100 | - * This method should set up the required event subscriptions. |
|
101 | - * |
|
102 | - * @param Server $server |
|
103 | - */ |
|
104 | - public function initialize(Server $server) { |
|
105 | - $this->server = $server; |
|
106 | - |
|
107 | - $this->server->on('method:POST', [$this, 'httpPost']); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * We intercept this to handle POST requests on calendar homes. |
|
112 | - * |
|
113 | - * @param RequestInterface $request |
|
114 | - * @param ResponseInterface $response |
|
115 | - * |
|
116 | - * @return bool|void |
|
117 | - */ |
|
118 | - public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
119 | - $node = $this->server->tree->getNodeForPath($this->server->getRequestUri()); |
|
120 | - if (!($node instanceof CalendarHome)) { |
|
121 | - return; |
|
122 | - } |
|
123 | - |
|
124 | - $requestBody = $request->getBodyAsString(); |
|
125 | - $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
126 | - if ($documentType !== '{'.self::NS_Nextcloud.'}enable-birthday-calendar') { |
|
127 | - return; |
|
128 | - } |
|
129 | - |
|
130 | - $principalUri = $node->getOwner(); |
|
131 | - $userId = substr($principalUri, 17); |
|
132 | - |
|
133 | - $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
134 | - $this->birthdayService->syncUser($userId); |
|
135 | - |
|
136 | - $this->server->httpResponse->setStatus(204); |
|
137 | - |
|
138 | - return false; |
|
139 | - } |
|
42 | + public const NS_Nextcloud = 'http://nextcloud.com/ns'; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var IConfig |
|
46 | + */ |
|
47 | + protected $config; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var BirthdayService |
|
51 | + */ |
|
52 | + protected $birthdayService; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var Server |
|
56 | + */ |
|
57 | + protected $server; |
|
58 | + |
|
59 | + /** |
|
60 | + * PublishPlugin constructor. |
|
61 | + * |
|
62 | + * @param IConfig $config |
|
63 | + * @param BirthdayService $birthdayService |
|
64 | + */ |
|
65 | + public function __construct(IConfig $config, BirthdayService $birthdayService) { |
|
66 | + $this->config = $config; |
|
67 | + $this->birthdayService = $birthdayService; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * This method should return a list of server-features. |
|
72 | + * |
|
73 | + * This is for example 'versioning' and is added to the DAV: header |
|
74 | + * in an OPTIONS response. |
|
75 | + * |
|
76 | + * @return string[] |
|
77 | + */ |
|
78 | + public function getFeatures() { |
|
79 | + return ['nc-enable-birthday-calendar']; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Returns a plugin name. |
|
84 | + * |
|
85 | + * Using this name other plugins will be able to access other plugins |
|
86 | + * using Sabre\DAV\Server::getPlugin |
|
87 | + * |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function getPluginName() { |
|
91 | + return 'nc-enable-birthday-calendar'; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * This initializes the plugin. |
|
96 | + * |
|
97 | + * This function is called by Sabre\DAV\Server, after |
|
98 | + * addPlugin is called. |
|
99 | + * |
|
100 | + * This method should set up the required event subscriptions. |
|
101 | + * |
|
102 | + * @param Server $server |
|
103 | + */ |
|
104 | + public function initialize(Server $server) { |
|
105 | + $this->server = $server; |
|
106 | + |
|
107 | + $this->server->on('method:POST', [$this, 'httpPost']); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * We intercept this to handle POST requests on calendar homes. |
|
112 | + * |
|
113 | + * @param RequestInterface $request |
|
114 | + * @param ResponseInterface $response |
|
115 | + * |
|
116 | + * @return bool|void |
|
117 | + */ |
|
118 | + public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
119 | + $node = $this->server->tree->getNodeForPath($this->server->getRequestUri()); |
|
120 | + if (!($node instanceof CalendarHome)) { |
|
121 | + return; |
|
122 | + } |
|
123 | + |
|
124 | + $requestBody = $request->getBodyAsString(); |
|
125 | + $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
126 | + if ($documentType !== '{'.self::NS_Nextcloud.'}enable-birthday-calendar') { |
|
127 | + return; |
|
128 | + } |
|
129 | + |
|
130 | + $principalUri = $node->getOwner(); |
|
131 | + $userId = substr($principalUri, 17); |
|
132 | + |
|
133 | + $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
134 | + $this->birthdayService->syncUser($userId); |
|
135 | + |
|
136 | + $this->server->httpResponse->setStatus(204); |
|
137 | + |
|
138 | + return false; |
|
139 | + } |
|
140 | 140 | } |
@@ -30,13 +30,13 @@ |
||
30 | 30 | */ |
31 | 31 | class Collection extends \Sabre\CalDAV\Principal\Collection { |
32 | 32 | |
33 | - /** |
|
34 | - * Returns a child object based on principal information |
|
35 | - * |
|
36 | - * @param array $principalInfo |
|
37 | - * @return User |
|
38 | - */ |
|
39 | - public function getChildForPrincipal(array $principalInfo) { |
|
40 | - return new User($this->principalBackend, $principalInfo); |
|
41 | - } |
|
33 | + /** |
|
34 | + * Returns a child object based on principal information |
|
35 | + * |
|
36 | + * @param array $principalInfo |
|
37 | + * @return User |
|
38 | + */ |
|
39 | + public function getChildForPrincipal(array $principalInfo) { |
|
40 | + return new User($this->principalBackend, $principalInfo); |
|
41 | + } |
|
42 | 42 | } |