@@ -35,21 +35,21 @@ |
||
35 | 35 | * Auto-generated migration step: Please modify to your needs! |
36 | 36 | */ |
37 | 37 | class Version22000Date20210216084241 extends SimpleMigrationStep { |
38 | - /** |
|
39 | - * @param IOutput $output |
|
40 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
41 | - * @param array $options |
|
42 | - * @return null|ISchemaWrapper |
|
43 | - */ |
|
44 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
45 | - /** @var ISchemaWrapper $schema */ |
|
46 | - $schema = $schemaClosure(); |
|
38 | + /** |
|
39 | + * @param IOutput $output |
|
40 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
41 | + * @param array $options |
|
42 | + * @return null|ISchemaWrapper |
|
43 | + */ |
|
44 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
45 | + /** @var ISchemaWrapper $schema */ |
|
46 | + $schema = $schemaClosure(); |
|
47 | 47 | |
48 | - $table = $schema->getTable('share_external'); |
|
49 | - if ($table->hasIndex('sh_external_user')) { |
|
50 | - $table->dropIndex('sh_external_user'); |
|
51 | - } |
|
48 | + $table = $schema->getTable('share_external'); |
|
49 | + if ($table->hasIndex('sh_external_user')) { |
|
50 | + $table->dropIndex('sh_external_user'); |
|
51 | + } |
|
52 | 52 | |
53 | - return $schema; |
|
54 | - } |
|
53 | + return $schema; |
|
54 | + } |
|
55 | 55 | } |
@@ -25,28 +25,28 @@ |
||
25 | 25 | use OCP\IDBConnection; |
26 | 26 | |
27 | 27 | class HomePropagator extends Propagator { |
28 | - private $ignoredBaseFolders; |
|
28 | + private $ignoredBaseFolders; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param \OC\Files\Storage\Storage $storage |
|
32 | - */ |
|
33 | - public function __construct(\OC\Files\Storage\Storage $storage, IDBConnection $connection) { |
|
34 | - parent::__construct($storage, $connection); |
|
35 | - $this->ignoredBaseFolders = ['files_encryption']; |
|
36 | - } |
|
30 | + /** |
|
31 | + * @param \OC\Files\Storage\Storage $storage |
|
32 | + */ |
|
33 | + public function __construct(\OC\Files\Storage\Storage $storage, IDBConnection $connection) { |
|
34 | + parent::__construct($storage, $connection); |
|
35 | + $this->ignoredBaseFolders = ['files_encryption']; |
|
36 | + } |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * @param string $internalPath |
|
41 | - * @param int $time |
|
42 | - * @param int $sizeDifference number of bytes the file has grown |
|
43 | - */ |
|
44 | - public function propagateChange($internalPath, $time, $sizeDifference = 0) { |
|
45 | - [$baseFolder] = explode('/', $internalPath, 2); |
|
46 | - if (in_array($baseFolder, $this->ignoredBaseFolders)) { |
|
47 | - return []; |
|
48 | - } else { |
|
49 | - parent::propagateChange($internalPath, $time, $sizeDifference); |
|
50 | - } |
|
51 | - } |
|
39 | + /** |
|
40 | + * @param string $internalPath |
|
41 | + * @param int $time |
|
42 | + * @param int $sizeDifference number of bytes the file has grown |
|
43 | + */ |
|
44 | + public function propagateChange($internalPath, $time, $sizeDifference = 0) { |
|
45 | + [$baseFolder] = explode('/', $internalPath, 2); |
|
46 | + if (in_array($baseFolder, $this->ignoredBaseFolders)) { |
|
47 | + return []; |
|
48 | + } else { |
|
49 | + parent::propagateChange($internalPath, $time, $sizeDifference); |
|
50 | + } |
|
51 | + } |
|
52 | 52 | } |
@@ -28,19 +28,19 @@ |
||
28 | 28 | use OC\Files\Storage\Wrapper\Jail; |
29 | 29 | |
30 | 30 | class JailPropagator extends Propagator { |
31 | - /** |
|
32 | - * @var Jail |
|
33 | - */ |
|
34 | - protected $storage; |
|
31 | + /** |
|
32 | + * @var Jail |
|
33 | + */ |
|
34 | + protected $storage; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param string $internalPath |
|
38 | - * @param int $time |
|
39 | - * @param int $sizeDifference |
|
40 | - */ |
|
41 | - public function propagateChange($internalPath, $time, $sizeDifference = 0) { |
|
42 | - /** @var \OC\Files\Storage\Storage $storage */ |
|
43 | - [$storage, $sourceInternalPath] = $this->storage->resolvePath($internalPath); |
|
44 | - $storage->getPropagator()->propagateChange($sourceInternalPath, $time, $sizeDifference); |
|
45 | - } |
|
36 | + /** |
|
37 | + * @param string $internalPath |
|
38 | + * @param int $time |
|
39 | + * @param int $sizeDifference |
|
40 | + */ |
|
41 | + public function propagateChange($internalPath, $time, $sizeDifference = 0) { |
|
42 | + /** @var \OC\Files\Storage\Storage $storage */ |
|
43 | + [$storage, $sourceInternalPath] = $this->storage->resolvePath($internalPath); |
|
44 | + $storage->getPropagator()->propagateChange($sourceInternalPath, $time, $sizeDifference); |
|
45 | + } |
|
46 | 46 | } |
@@ -61,7 +61,7 @@ |
||
61 | 61 | if ($this->enabled && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) { |
62 | 62 | [$remoteGroup, $serverUrl] = $this->splitGroupRemote($search); |
63 | 63 | $result['exact'][] = [ |
64 | - 'label' => $remoteGroup . " ($serverUrl)", |
|
64 | + 'label' => $remoteGroup." ($serverUrl)", |
|
65 | 65 | 'guid' => $remoteGroup, |
66 | 66 | 'name' => $remoteGroup, |
67 | 67 | 'value' => [ |
@@ -14,59 +14,59 @@ |
||
14 | 14 | use OCP\Share\IShare; |
15 | 15 | |
16 | 16 | class RemoteGroupPlugin implements ISearchPlugin { |
17 | - private bool $enabled = false; |
|
17 | + private bool $enabled = false; |
|
18 | 18 | |
19 | - public function __construct( |
|
20 | - ICloudFederationProviderManager $cloudFederationProviderManager, |
|
21 | - private ICloudIdManager $cloudIdManager, |
|
22 | - ) { |
|
23 | - try { |
|
24 | - $fileSharingProvider = $cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
25 | - $supportedShareTypes = $fileSharingProvider->getSupportedShareTypes(); |
|
26 | - if (in_array('group', $supportedShareTypes)) { |
|
27 | - $this->enabled = true; |
|
28 | - } |
|
29 | - } catch (\Exception $e) { |
|
30 | - // do nothing, just don't enable federated group shares |
|
31 | - } |
|
32 | - } |
|
19 | + public function __construct( |
|
20 | + ICloudFederationProviderManager $cloudFederationProviderManager, |
|
21 | + private ICloudIdManager $cloudIdManager, |
|
22 | + ) { |
|
23 | + try { |
|
24 | + $fileSharingProvider = $cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
25 | + $supportedShareTypes = $fileSharingProvider->getSupportedShareTypes(); |
|
26 | + if (in_array('group', $supportedShareTypes)) { |
|
27 | + $this->enabled = true; |
|
28 | + } |
|
29 | + } catch (\Exception $e) { |
|
30 | + // do nothing, just don't enable federated group shares |
|
31 | + } |
|
32 | + } |
|
33 | 33 | |
34 | - public function search($search, $limit, $offset, ISearchResult $searchResult): bool { |
|
35 | - $result = ['wide' => [], 'exact' => []]; |
|
36 | - $resultType = new SearchResultType('remote_groups'); |
|
34 | + public function search($search, $limit, $offset, ISearchResult $searchResult): bool { |
|
35 | + $result = ['wide' => [], 'exact' => []]; |
|
36 | + $resultType = new SearchResultType('remote_groups'); |
|
37 | 37 | |
38 | - if ($this->enabled && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) { |
|
39 | - [$remoteGroup, $serverUrl] = $this->splitGroupRemote($search); |
|
40 | - $result['exact'][] = [ |
|
41 | - 'label' => $remoteGroup . " ($serverUrl)", |
|
42 | - 'guid' => $remoteGroup, |
|
43 | - 'name' => $remoteGroup, |
|
44 | - 'value' => [ |
|
45 | - 'shareType' => IShare::TYPE_REMOTE_GROUP, |
|
46 | - 'shareWith' => $search, |
|
47 | - 'server' => $serverUrl, |
|
48 | - ], |
|
49 | - ]; |
|
50 | - } |
|
38 | + if ($this->enabled && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) { |
|
39 | + [$remoteGroup, $serverUrl] = $this->splitGroupRemote($search); |
|
40 | + $result['exact'][] = [ |
|
41 | + 'label' => $remoteGroup . " ($serverUrl)", |
|
42 | + 'guid' => $remoteGroup, |
|
43 | + 'name' => $remoteGroup, |
|
44 | + 'value' => [ |
|
45 | + 'shareType' => IShare::TYPE_REMOTE_GROUP, |
|
46 | + 'shareWith' => $search, |
|
47 | + 'server' => $serverUrl, |
|
48 | + ], |
|
49 | + ]; |
|
50 | + } |
|
51 | 51 | |
52 | - $searchResult->addResultSet($resultType, $result['wide'], $result['exact']); |
|
52 | + $searchResult->addResultSet($resultType, $result['wide'], $result['exact']); |
|
53 | 53 | |
54 | - return true; |
|
55 | - } |
|
54 | + return true; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * split group and remote from federated cloud id |
|
59 | - * |
|
60 | - * @param string $address federated share address |
|
61 | - * @return array [user, remoteURL] |
|
62 | - * @throws \InvalidArgumentException |
|
63 | - */ |
|
64 | - public function splitGroupRemote($address): array { |
|
65 | - try { |
|
66 | - $cloudId = $this->cloudIdManager->resolveCloudId($address); |
|
67 | - return [$cloudId->getUser(), $cloudId->getRemote()]; |
|
68 | - } catch (\InvalidArgumentException $e) { |
|
69 | - throw new \InvalidArgumentException('Invalid Federated Cloud ID', 0, $e); |
|
70 | - } |
|
71 | - } |
|
57 | + /** |
|
58 | + * split group and remote from federated cloud id |
|
59 | + * |
|
60 | + * @param string $address federated share address |
|
61 | + * @return array [user, remoteURL] |
|
62 | + * @throws \InvalidArgumentException |
|
63 | + */ |
|
64 | + public function splitGroupRemote($address): array { |
|
65 | + try { |
|
66 | + $cloudId = $this->cloudIdManager->resolveCloudId($address); |
|
67 | + return [$cloudId->getUser(), $cloudId->getRemote()]; |
|
68 | + } catch (\InvalidArgumentException $e) { |
|
69 | + throw new \InvalidArgumentException('Invalid Federated Cloud ID', 0, $e); |
|
70 | + } |
|
71 | + } |
|
72 | 72 | } |
@@ -31,46 +31,46 @@ |
||
31 | 31 | use Sabre\DAV\Server; |
32 | 32 | |
33 | 33 | class Plugin extends \Sabre\CardDAV\Plugin { |
34 | - public function initialize(Server $server) { |
|
35 | - $server->on('propFind', [$this, 'propFind']); |
|
36 | - parent::initialize($server); |
|
37 | - } |
|
34 | + public function initialize(Server $server) { |
|
35 | + $server->on('propFind', [$this, 'propFind']); |
|
36 | + parent::initialize($server); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Returns the addressbook home for a given principal |
|
41 | - * |
|
42 | - * @param string $principal |
|
43 | - * @return string|null |
|
44 | - */ |
|
45 | - protected function getAddressbookHomeForPrincipal($principal) { |
|
46 | - if (strrpos($principal, 'principals/users', -strlen($principal)) !== false) { |
|
47 | - [, $principalId] = \Sabre\Uri\split($principal); |
|
48 | - return self::ADDRESSBOOK_ROOT . '/users/' . $principalId; |
|
49 | - } |
|
50 | - if (strrpos($principal, 'principals/groups', -strlen($principal)) !== false) { |
|
51 | - [, $principalId] = \Sabre\Uri\split($principal); |
|
52 | - return self::ADDRESSBOOK_ROOT . '/groups/' . $principalId; |
|
53 | - } |
|
54 | - if (strrpos($principal, 'principals/system', -strlen($principal)) !== false) { |
|
55 | - [, $principalId] = \Sabre\Uri\split($principal); |
|
56 | - return self::ADDRESSBOOK_ROOT . '/system/' . $principalId; |
|
57 | - } |
|
58 | - } |
|
39 | + /** |
|
40 | + * Returns the addressbook home for a given principal |
|
41 | + * |
|
42 | + * @param string $principal |
|
43 | + * @return string|null |
|
44 | + */ |
|
45 | + protected function getAddressbookHomeForPrincipal($principal) { |
|
46 | + if (strrpos($principal, 'principals/users', -strlen($principal)) !== false) { |
|
47 | + [, $principalId] = \Sabre\Uri\split($principal); |
|
48 | + return self::ADDRESSBOOK_ROOT . '/users/' . $principalId; |
|
49 | + } |
|
50 | + if (strrpos($principal, 'principals/groups', -strlen($principal)) !== false) { |
|
51 | + [, $principalId] = \Sabre\Uri\split($principal); |
|
52 | + return self::ADDRESSBOOK_ROOT . '/groups/' . $principalId; |
|
53 | + } |
|
54 | + if (strrpos($principal, 'principals/system', -strlen($principal)) !== false) { |
|
55 | + [, $principalId] = \Sabre\Uri\split($principal); |
|
56 | + return self::ADDRESSBOOK_ROOT . '/system/' . $principalId; |
|
57 | + } |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Adds all CardDAV-specific properties |
|
62 | - * |
|
63 | - * @param PropFind $propFind |
|
64 | - * @param INode $node |
|
65 | - * @return void |
|
66 | - */ |
|
67 | - public function propFind(PropFind $propFind, INode $node) { |
|
68 | - $ns = '{http://owncloud.org/ns}'; |
|
60 | + /** |
|
61 | + * Adds all CardDAV-specific properties |
|
62 | + * |
|
63 | + * @param PropFind $propFind |
|
64 | + * @param INode $node |
|
65 | + * @return void |
|
66 | + */ |
|
67 | + public function propFind(PropFind $propFind, INode $node) { |
|
68 | + $ns = '{http://owncloud.org/ns}'; |
|
69 | 69 | |
70 | - if ($node instanceof AddressBook) { |
|
71 | - $propFind->handle($ns . 'groups', function () use ($node) { |
|
72 | - return new Groups($node->getContactsGroups()); |
|
73 | - }); |
|
74 | - } |
|
75 | - } |
|
70 | + if ($node instanceof AddressBook) { |
|
71 | + $propFind->handle($ns . 'groups', function () use ($node) { |
|
72 | + return new Groups($node->getContactsGroups()); |
|
73 | + }); |
|
74 | + } |
|
75 | + } |
|
76 | 76 | } |
@@ -45,15 +45,15 @@ discard block |
||
45 | 45 | protected function getAddressbookHomeForPrincipal($principal) { |
46 | 46 | if (strrpos($principal, 'principals/users', -strlen($principal)) !== false) { |
47 | 47 | [, $principalId] = \Sabre\Uri\split($principal); |
48 | - return self::ADDRESSBOOK_ROOT . '/users/' . $principalId; |
|
48 | + return self::ADDRESSBOOK_ROOT.'/users/'.$principalId; |
|
49 | 49 | } |
50 | 50 | if (strrpos($principal, 'principals/groups', -strlen($principal)) !== false) { |
51 | 51 | [, $principalId] = \Sabre\Uri\split($principal); |
52 | - return self::ADDRESSBOOK_ROOT . '/groups/' . $principalId; |
|
52 | + return self::ADDRESSBOOK_ROOT.'/groups/'.$principalId; |
|
53 | 53 | } |
54 | 54 | if (strrpos($principal, 'principals/system', -strlen($principal)) !== false) { |
55 | 55 | [, $principalId] = \Sabre\Uri\split($principal); |
56 | - return self::ADDRESSBOOK_ROOT . '/system/' . $principalId; |
|
56 | + return self::ADDRESSBOOK_ROOT.'/system/'.$principalId; |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | $ns = '{http://owncloud.org/ns}'; |
69 | 69 | |
70 | 70 | if ($node instanceof AddressBook) { |
71 | - $propFind->handle($ns . 'groups', function () use ($node) { |
|
71 | + $propFind->handle($ns.'groups', function() use ($node) { |
|
72 | 72 | return new Groups($node->getContactsGroups()); |
73 | 73 | }); |
74 | 74 | } |
@@ -36,190 +36,190 @@ |
||
36 | 36 | */ |
37 | 37 | trait PrincipalProxyTrait { |
38 | 38 | |
39 | - /** |
|
40 | - * Returns the list of members for a group-principal |
|
41 | - * |
|
42 | - * @param string $principal |
|
43 | - * @return string[] |
|
44 | - * @throws Exception |
|
45 | - */ |
|
46 | - public function getGroupMemberSet($principal) { |
|
47 | - $members = []; |
|
48 | - |
|
49 | - if ($this->isProxyPrincipal($principal)) { |
|
50 | - $realPrincipal = $this->getPrincipalUriFromProxyPrincipal($principal); |
|
51 | - $principalArray = $this->getPrincipalByPath($realPrincipal); |
|
52 | - if (!$principalArray) { |
|
53 | - throw new Exception('Principal not found'); |
|
54 | - } |
|
55 | - |
|
56 | - $proxies = $this->proxyMapper->getProxiesOf($principalArray['uri']); |
|
57 | - foreach ($proxies as $proxy) { |
|
58 | - if ($this->isReadProxyPrincipal($principal) && $proxy->getPermissions() === ProxyMapper::PERMISSION_READ) { |
|
59 | - $members[] = $proxy->getProxyId(); |
|
60 | - } |
|
61 | - |
|
62 | - if ($this->isWriteProxyPrincipal($principal) && $proxy->getPermissions() === (ProxyMapper::PERMISSION_READ | ProxyMapper::PERMISSION_WRITE)) { |
|
63 | - $members[] = $proxy->getProxyId(); |
|
64 | - } |
|
65 | - } |
|
66 | - } |
|
67 | - |
|
68 | - return $members; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Returns the list of groups a principal is a member of |
|
73 | - * |
|
74 | - * @param string $principal |
|
75 | - * @param bool $needGroups |
|
76 | - * @return array |
|
77 | - * @throws Exception |
|
78 | - */ |
|
79 | - public function getGroupMembership($principal, $needGroups = false) { |
|
80 | - [$prefix, $name] = \Sabre\Uri\split($principal); |
|
81 | - |
|
82 | - if ($prefix !== $this->principalPrefix) { |
|
83 | - return []; |
|
84 | - } |
|
85 | - |
|
86 | - $principalArray = $this->getPrincipalByPath($principal); |
|
87 | - if (!$principalArray) { |
|
88 | - throw new Exception('Principal not found'); |
|
89 | - } |
|
90 | - |
|
91 | - $groups = []; |
|
92 | - $proxies = $this->proxyMapper->getProxiesFor($principal); |
|
93 | - foreach ($proxies as $proxy) { |
|
94 | - if ($proxy->getPermissions() === ProxyMapper::PERMISSION_READ) { |
|
95 | - $groups[] = $proxy->getOwnerId() . '/calendar-proxy-read'; |
|
96 | - } |
|
97 | - |
|
98 | - if ($proxy->getPermissions() === (ProxyMapper::PERMISSION_READ | ProxyMapper::PERMISSION_WRITE)) { |
|
99 | - $groups[] = $proxy->getOwnerId() . '/calendar-proxy-write'; |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - return $groups; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Updates the list of group members for a group principal. |
|
108 | - * |
|
109 | - * The principals should be passed as a list of uri's. |
|
110 | - * |
|
111 | - * @param string $principal |
|
112 | - * @param string[] $members |
|
113 | - * @throws Exception |
|
114 | - */ |
|
115 | - public function setGroupMemberSet($principal, array $members) { |
|
116 | - [$principalUri, $target] = \Sabre\Uri\split($principal); |
|
117 | - |
|
118 | - if ($target !== 'calendar-proxy-write' && $target !== 'calendar-proxy-read') { |
|
119 | - throw new Exception('Setting members of the group is not supported yet'); |
|
120 | - } |
|
121 | - |
|
122 | - $masterPrincipalArray = $this->getPrincipalByPath($principalUri); |
|
123 | - if (!$masterPrincipalArray) { |
|
124 | - throw new Exception('Principal not found'); |
|
125 | - } |
|
126 | - |
|
127 | - $permission = ProxyMapper::PERMISSION_READ; |
|
128 | - if ($target === 'calendar-proxy-write') { |
|
129 | - $permission |= ProxyMapper::PERMISSION_WRITE; |
|
130 | - } |
|
131 | - |
|
132 | - [$prefix, $owner] = \Sabre\Uri\split($principalUri); |
|
133 | - $proxies = $this->proxyMapper->getProxiesOf($principalUri); |
|
134 | - |
|
135 | - foreach ($members as $member) { |
|
136 | - [$prefix, $name] = \Sabre\Uri\split($member); |
|
137 | - |
|
138 | - if ($prefix !== $this->principalPrefix) { |
|
139 | - throw new Exception('Invalid member group prefix: ' . $prefix); |
|
140 | - } |
|
141 | - |
|
142 | - $principalArray = $this->getPrincipalByPath($member); |
|
143 | - if (!$principalArray) { |
|
144 | - throw new Exception('Principal not found'); |
|
145 | - } |
|
146 | - |
|
147 | - $found = false; |
|
148 | - foreach ($proxies as $proxy) { |
|
149 | - if ($proxy->getProxyId() === $member) { |
|
150 | - $found = true; |
|
151 | - $proxy->setPermissions($proxy->getPermissions() | $permission); |
|
152 | - $this->proxyMapper->update($proxy); |
|
153 | - |
|
154 | - $proxies = array_filter($proxies, function (Proxy $p) use ($proxy) { |
|
155 | - return $p->getId() !== $proxy->getId(); |
|
156 | - }); |
|
157 | - break; |
|
158 | - } |
|
159 | - } |
|
160 | - |
|
161 | - if ($found === false) { |
|
162 | - $proxy = new Proxy(); |
|
163 | - $proxy->setOwnerId($principalUri); |
|
164 | - $proxy->setProxyId($member); |
|
165 | - $proxy->setPermissions($permission); |
|
166 | - $this->proxyMapper->insert($proxy); |
|
167 | - } |
|
168 | - } |
|
169 | - |
|
170 | - // Delete all remaining proxies |
|
171 | - foreach ($proxies as $proxy) { |
|
172 | - // Write and Read Proxies have individual requests, |
|
173 | - // so only delete proxies of this permission |
|
174 | - if ($proxy->getPermissions() === $permission) { |
|
175 | - $this->proxyMapper->delete($proxy); |
|
176 | - } |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * @param string $principalUri |
|
182 | - * @return bool |
|
183 | - */ |
|
184 | - private function isProxyPrincipal(string $principalUri):bool { |
|
185 | - [$realPrincipalUri, $proxy] = \Sabre\Uri\split($principalUri); |
|
186 | - [$prefix, $userId] = \Sabre\Uri\split($realPrincipalUri); |
|
187 | - |
|
188 | - if (!isset($prefix) || !isset($userId)) { |
|
189 | - return false; |
|
190 | - } |
|
191 | - if ($prefix !== $this->principalPrefix) { |
|
192 | - return false; |
|
193 | - } |
|
194 | - |
|
195 | - return $proxy === 'calendar-proxy-read' |
|
196 | - || $proxy === 'calendar-proxy-write'; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * @param string $principalUri |
|
201 | - * @return bool |
|
202 | - */ |
|
203 | - private function isReadProxyPrincipal(string $principalUri):bool { |
|
204 | - [, $proxy] = \Sabre\Uri\split($principalUri); |
|
205 | - return $proxy === 'calendar-proxy-read'; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * @param string $principalUri |
|
210 | - * @return bool |
|
211 | - */ |
|
212 | - private function isWriteProxyPrincipal(string $principalUri):bool { |
|
213 | - [, $proxy] = \Sabre\Uri\split($principalUri); |
|
214 | - return $proxy === 'calendar-proxy-write'; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * @param string $principalUri |
|
219 | - * @return string |
|
220 | - */ |
|
221 | - private function getPrincipalUriFromProxyPrincipal(string $principalUri):string { |
|
222 | - [$realPrincipalUri, ] = \Sabre\Uri\split($principalUri); |
|
223 | - return $realPrincipalUri; |
|
224 | - } |
|
39 | + /** |
|
40 | + * Returns the list of members for a group-principal |
|
41 | + * |
|
42 | + * @param string $principal |
|
43 | + * @return string[] |
|
44 | + * @throws Exception |
|
45 | + */ |
|
46 | + public function getGroupMemberSet($principal) { |
|
47 | + $members = []; |
|
48 | + |
|
49 | + if ($this->isProxyPrincipal($principal)) { |
|
50 | + $realPrincipal = $this->getPrincipalUriFromProxyPrincipal($principal); |
|
51 | + $principalArray = $this->getPrincipalByPath($realPrincipal); |
|
52 | + if (!$principalArray) { |
|
53 | + throw new Exception('Principal not found'); |
|
54 | + } |
|
55 | + |
|
56 | + $proxies = $this->proxyMapper->getProxiesOf($principalArray['uri']); |
|
57 | + foreach ($proxies as $proxy) { |
|
58 | + if ($this->isReadProxyPrincipal($principal) && $proxy->getPermissions() === ProxyMapper::PERMISSION_READ) { |
|
59 | + $members[] = $proxy->getProxyId(); |
|
60 | + } |
|
61 | + |
|
62 | + if ($this->isWriteProxyPrincipal($principal) && $proxy->getPermissions() === (ProxyMapper::PERMISSION_READ | ProxyMapper::PERMISSION_WRITE)) { |
|
63 | + $members[] = $proxy->getProxyId(); |
|
64 | + } |
|
65 | + } |
|
66 | + } |
|
67 | + |
|
68 | + return $members; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Returns the list of groups a principal is a member of |
|
73 | + * |
|
74 | + * @param string $principal |
|
75 | + * @param bool $needGroups |
|
76 | + * @return array |
|
77 | + * @throws Exception |
|
78 | + */ |
|
79 | + public function getGroupMembership($principal, $needGroups = false) { |
|
80 | + [$prefix, $name] = \Sabre\Uri\split($principal); |
|
81 | + |
|
82 | + if ($prefix !== $this->principalPrefix) { |
|
83 | + return []; |
|
84 | + } |
|
85 | + |
|
86 | + $principalArray = $this->getPrincipalByPath($principal); |
|
87 | + if (!$principalArray) { |
|
88 | + throw new Exception('Principal not found'); |
|
89 | + } |
|
90 | + |
|
91 | + $groups = []; |
|
92 | + $proxies = $this->proxyMapper->getProxiesFor($principal); |
|
93 | + foreach ($proxies as $proxy) { |
|
94 | + if ($proxy->getPermissions() === ProxyMapper::PERMISSION_READ) { |
|
95 | + $groups[] = $proxy->getOwnerId() . '/calendar-proxy-read'; |
|
96 | + } |
|
97 | + |
|
98 | + if ($proxy->getPermissions() === (ProxyMapper::PERMISSION_READ | ProxyMapper::PERMISSION_WRITE)) { |
|
99 | + $groups[] = $proxy->getOwnerId() . '/calendar-proxy-write'; |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + return $groups; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Updates the list of group members for a group principal. |
|
108 | + * |
|
109 | + * The principals should be passed as a list of uri's. |
|
110 | + * |
|
111 | + * @param string $principal |
|
112 | + * @param string[] $members |
|
113 | + * @throws Exception |
|
114 | + */ |
|
115 | + public function setGroupMemberSet($principal, array $members) { |
|
116 | + [$principalUri, $target] = \Sabre\Uri\split($principal); |
|
117 | + |
|
118 | + if ($target !== 'calendar-proxy-write' && $target !== 'calendar-proxy-read') { |
|
119 | + throw new Exception('Setting members of the group is not supported yet'); |
|
120 | + } |
|
121 | + |
|
122 | + $masterPrincipalArray = $this->getPrincipalByPath($principalUri); |
|
123 | + if (!$masterPrincipalArray) { |
|
124 | + throw new Exception('Principal not found'); |
|
125 | + } |
|
126 | + |
|
127 | + $permission = ProxyMapper::PERMISSION_READ; |
|
128 | + if ($target === 'calendar-proxy-write') { |
|
129 | + $permission |= ProxyMapper::PERMISSION_WRITE; |
|
130 | + } |
|
131 | + |
|
132 | + [$prefix, $owner] = \Sabre\Uri\split($principalUri); |
|
133 | + $proxies = $this->proxyMapper->getProxiesOf($principalUri); |
|
134 | + |
|
135 | + foreach ($members as $member) { |
|
136 | + [$prefix, $name] = \Sabre\Uri\split($member); |
|
137 | + |
|
138 | + if ($prefix !== $this->principalPrefix) { |
|
139 | + throw new Exception('Invalid member group prefix: ' . $prefix); |
|
140 | + } |
|
141 | + |
|
142 | + $principalArray = $this->getPrincipalByPath($member); |
|
143 | + if (!$principalArray) { |
|
144 | + throw new Exception('Principal not found'); |
|
145 | + } |
|
146 | + |
|
147 | + $found = false; |
|
148 | + foreach ($proxies as $proxy) { |
|
149 | + if ($proxy->getProxyId() === $member) { |
|
150 | + $found = true; |
|
151 | + $proxy->setPermissions($proxy->getPermissions() | $permission); |
|
152 | + $this->proxyMapper->update($proxy); |
|
153 | + |
|
154 | + $proxies = array_filter($proxies, function (Proxy $p) use ($proxy) { |
|
155 | + return $p->getId() !== $proxy->getId(); |
|
156 | + }); |
|
157 | + break; |
|
158 | + } |
|
159 | + } |
|
160 | + |
|
161 | + if ($found === false) { |
|
162 | + $proxy = new Proxy(); |
|
163 | + $proxy->setOwnerId($principalUri); |
|
164 | + $proxy->setProxyId($member); |
|
165 | + $proxy->setPermissions($permission); |
|
166 | + $this->proxyMapper->insert($proxy); |
|
167 | + } |
|
168 | + } |
|
169 | + |
|
170 | + // Delete all remaining proxies |
|
171 | + foreach ($proxies as $proxy) { |
|
172 | + // Write and Read Proxies have individual requests, |
|
173 | + // so only delete proxies of this permission |
|
174 | + if ($proxy->getPermissions() === $permission) { |
|
175 | + $this->proxyMapper->delete($proxy); |
|
176 | + } |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * @param string $principalUri |
|
182 | + * @return bool |
|
183 | + */ |
|
184 | + private function isProxyPrincipal(string $principalUri):bool { |
|
185 | + [$realPrincipalUri, $proxy] = \Sabre\Uri\split($principalUri); |
|
186 | + [$prefix, $userId] = \Sabre\Uri\split($realPrincipalUri); |
|
187 | + |
|
188 | + if (!isset($prefix) || !isset($userId)) { |
|
189 | + return false; |
|
190 | + } |
|
191 | + if ($prefix !== $this->principalPrefix) { |
|
192 | + return false; |
|
193 | + } |
|
194 | + |
|
195 | + return $proxy === 'calendar-proxy-read' |
|
196 | + || $proxy === 'calendar-proxy-write'; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * @param string $principalUri |
|
201 | + * @return bool |
|
202 | + */ |
|
203 | + private function isReadProxyPrincipal(string $principalUri):bool { |
|
204 | + [, $proxy] = \Sabre\Uri\split($principalUri); |
|
205 | + return $proxy === 'calendar-proxy-read'; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * @param string $principalUri |
|
210 | + * @return bool |
|
211 | + */ |
|
212 | + private function isWriteProxyPrincipal(string $principalUri):bool { |
|
213 | + [, $proxy] = \Sabre\Uri\split($principalUri); |
|
214 | + return $proxy === 'calendar-proxy-write'; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * @param string $principalUri |
|
219 | + * @return string |
|
220 | + */ |
|
221 | + private function getPrincipalUriFromProxyPrincipal(string $principalUri):string { |
|
222 | + [$realPrincipalUri, ] = \Sabre\Uri\split($principalUri); |
|
223 | + return $realPrincipalUri; |
|
224 | + } |
|
225 | 225 | } |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | $proxies = $this->proxyMapper->getProxiesFor($principal); |
93 | 93 | foreach ($proxies as $proxy) { |
94 | 94 | if ($proxy->getPermissions() === ProxyMapper::PERMISSION_READ) { |
95 | - $groups[] = $proxy->getOwnerId() . '/calendar-proxy-read'; |
|
95 | + $groups[] = $proxy->getOwnerId().'/calendar-proxy-read'; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | if ($proxy->getPermissions() === (ProxyMapper::PERMISSION_READ | ProxyMapper::PERMISSION_WRITE)) { |
99 | - $groups[] = $proxy->getOwnerId() . '/calendar-proxy-write'; |
|
99 | + $groups[] = $proxy->getOwnerId().'/calendar-proxy-write'; |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | [$prefix, $name] = \Sabre\Uri\split($member); |
137 | 137 | |
138 | 138 | if ($prefix !== $this->principalPrefix) { |
139 | - throw new Exception('Invalid member group prefix: ' . $prefix); |
|
139 | + throw new Exception('Invalid member group prefix: '.$prefix); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | $principalArray = $this->getPrincipalByPath($member); |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | $proxy->setPermissions($proxy->getPermissions() | $permission); |
152 | 152 | $this->proxyMapper->update($proxy); |
153 | 153 | |
154 | - $proxies = array_filter($proxies, function (Proxy $p) use ($proxy) { |
|
154 | + $proxies = array_filter($proxies, function(Proxy $p) use ($proxy) { |
|
155 | 155 | return $p->getId() !== $proxy->getId(); |
156 | 156 | }); |
157 | 157 | break; |
@@ -26,30 +26,30 @@ |
||
26 | 26 | namespace OCA\DAV\CalDAV; |
27 | 27 | |
28 | 28 | class Plugin extends \Sabre\CalDAV\Plugin { |
29 | - public const SYSTEM_CALENDAR_ROOT = 'system-calendars'; |
|
29 | + public const SYSTEM_CALENDAR_ROOT = 'system-calendars'; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Returns the path to a principal's calendar home. |
|
33 | - * |
|
34 | - * The return url must not end with a slash. |
|
35 | - * This function should return null in case a principal did not have |
|
36 | - * a calendar home. |
|
37 | - * |
|
38 | - * @param string $principalUrl |
|
39 | - * @return string|null |
|
40 | - */ |
|
41 | - public function getCalendarHomeForPrincipal($principalUrl) { |
|
42 | - if (strrpos($principalUrl, 'principals/users', -strlen($principalUrl)) !== false) { |
|
43 | - [, $principalId] = \Sabre\Uri\split($principalUrl); |
|
44 | - return self::CALENDAR_ROOT . '/' . $principalId; |
|
45 | - } |
|
46 | - if (strrpos($principalUrl, 'principals/calendar-resources', -strlen($principalUrl)) !== false) { |
|
47 | - [, $principalId] = \Sabre\Uri\split($principalUrl); |
|
48 | - return self::SYSTEM_CALENDAR_ROOT . '/calendar-resources/' . $principalId; |
|
49 | - } |
|
50 | - if (strrpos($principalUrl, 'principals/calendar-rooms', -strlen($principalUrl)) !== false) { |
|
51 | - [, $principalId] = \Sabre\Uri\split($principalUrl); |
|
52 | - return self::SYSTEM_CALENDAR_ROOT . '/calendar-rooms/' . $principalId; |
|
53 | - } |
|
54 | - } |
|
31 | + /** |
|
32 | + * Returns the path to a principal's calendar home. |
|
33 | + * |
|
34 | + * The return url must not end with a slash. |
|
35 | + * This function should return null in case a principal did not have |
|
36 | + * a calendar home. |
|
37 | + * |
|
38 | + * @param string $principalUrl |
|
39 | + * @return string|null |
|
40 | + */ |
|
41 | + public function getCalendarHomeForPrincipal($principalUrl) { |
|
42 | + if (strrpos($principalUrl, 'principals/users', -strlen($principalUrl)) !== false) { |
|
43 | + [, $principalId] = \Sabre\Uri\split($principalUrl); |
|
44 | + return self::CALENDAR_ROOT . '/' . $principalId; |
|
45 | + } |
|
46 | + if (strrpos($principalUrl, 'principals/calendar-resources', -strlen($principalUrl)) !== false) { |
|
47 | + [, $principalId] = \Sabre\Uri\split($principalUrl); |
|
48 | + return self::SYSTEM_CALENDAR_ROOT . '/calendar-resources/' . $principalId; |
|
49 | + } |
|
50 | + if (strrpos($principalUrl, 'principals/calendar-rooms', -strlen($principalUrl)) !== false) { |
|
51 | + [, $principalId] = \Sabre\Uri\split($principalUrl); |
|
52 | + return self::SYSTEM_CALENDAR_ROOT . '/calendar-rooms/' . $principalId; |
|
53 | + } |
|
54 | + } |
|
55 | 55 | } |
@@ -41,15 +41,15 @@ |
||
41 | 41 | public function getCalendarHomeForPrincipal($principalUrl) { |
42 | 42 | if (strrpos($principalUrl, 'principals/users', -strlen($principalUrl)) !== false) { |
43 | 43 | [, $principalId] = \Sabre\Uri\split($principalUrl); |
44 | - return self::CALENDAR_ROOT . '/' . $principalId; |
|
44 | + return self::CALENDAR_ROOT.'/'.$principalId; |
|
45 | 45 | } |
46 | 46 | if (strrpos($principalUrl, 'principals/calendar-resources', -strlen($principalUrl)) !== false) { |
47 | 47 | [, $principalId] = \Sabre\Uri\split($principalUrl); |
48 | - return self::SYSTEM_CALENDAR_ROOT . '/calendar-resources/' . $principalId; |
|
48 | + return self::SYSTEM_CALENDAR_ROOT.'/calendar-resources/'.$principalId; |
|
49 | 49 | } |
50 | 50 | if (strrpos($principalUrl, 'principals/calendar-rooms', -strlen($principalUrl)) !== false) { |
51 | 51 | [, $principalId] = \Sabre\Uri\split($principalUrl); |
52 | - return self::SYSTEM_CALENDAR_ROOT . '/calendar-rooms/' . $principalId; |
|
52 | + return self::SYSTEM_CALENDAR_ROOT.'/calendar-rooms/'.$principalId; |
|
53 | 53 | } |
54 | 54 | } |
55 | 55 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | |
83 | 83 | $server->on('report', [$this, 'report']); |
84 | 84 | |
85 | - $server->xml->elementMap['{' . self::NS_Nextcloud . '}calendar-search'] = |
|
85 | + $server->xml->elementMap['{'.self::NS_Nextcloud.'}calendar-search'] = |
|
86 | 86 | CalendarSearchReport::class; |
87 | 87 | } |
88 | 88 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public function report($reportName, $report, $path) { |
98 | 98 | switch ($reportName) { |
99 | - case '{' . self::NS_Nextcloud . '}calendar-search': |
|
99 | + case '{'.self::NS_Nextcloud.'}calendar-search': |
|
100 | 100 | $this->server->transactionType = 'report-nc-calendar-search'; |
101 | 101 | $this->calendarSearch($report); |
102 | 102 | return false; |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | |
119 | 119 | $reports = []; |
120 | 120 | if ($node instanceof CalendarHome) { |
121 | - $reports[] = '{' . self::NS_Nextcloud . '}calendar-search'; |
|
121 | + $reports[] = '{'.self::NS_Nextcloud.'}calendar-search'; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | return $reports; |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | |
148 | 148 | foreach ($nodePaths as $path) { |
149 | 149 | [$properties] = $this->server->getPropertiesForPath( |
150 | - $this->server->getRequestUri() . '/' . $path, |
|
150 | + $this->server->getRequestUri().'/'.$path, |
|
151 | 151 | $report->properties); |
152 | 152 | $result[] = $properties; |
153 | 153 | } |
@@ -12,134 +12,134 @@ |
||
12 | 12 | use Sabre\DAV\ServerPlugin; |
13 | 13 | |
14 | 14 | class SearchPlugin extends ServerPlugin { |
15 | - public const NS_Nextcloud = 'http://nextcloud.com/ns'; |
|
16 | - |
|
17 | - /** |
|
18 | - * Reference to SabreDAV server object. |
|
19 | - * |
|
20 | - * @var \Sabre\DAV\Server |
|
21 | - */ |
|
22 | - protected $server; |
|
23 | - |
|
24 | - /** |
|
25 | - * This method should return a list of server-features. |
|
26 | - * |
|
27 | - * This is for example 'versioning' and is added to the DAV: header |
|
28 | - * in an OPTIONS response. |
|
29 | - * |
|
30 | - * @return string[] |
|
31 | - */ |
|
32 | - public function getFeatures() { |
|
33 | - // May have to be changed to be detected |
|
34 | - return ['nc-calendar-search']; |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * Returns a plugin name. |
|
39 | - * |
|
40 | - * Using this name other plugins will be able to access other plugins |
|
41 | - * using Sabre\DAV\Server::getPlugin |
|
42 | - * |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public function getPluginName() { |
|
46 | - return 'nc-calendar-search'; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * This initializes the plugin. |
|
51 | - * |
|
52 | - * This function is called by Sabre\DAV\Server, after |
|
53 | - * addPlugin is called. |
|
54 | - * |
|
55 | - * This method should set up the required event subscriptions. |
|
56 | - * |
|
57 | - * @param Server $server |
|
58 | - */ |
|
59 | - public function initialize(Server $server) { |
|
60 | - $this->server = $server; |
|
61 | - |
|
62 | - $server->on('report', [$this, 'report']); |
|
63 | - |
|
64 | - $server->xml->elementMap['{' . self::NS_Nextcloud . '}calendar-search'] = |
|
65 | - CalendarSearchReport::class; |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * This functions handles REPORT requests specific to CalDAV |
|
70 | - * |
|
71 | - * @param string $reportName |
|
72 | - * @param mixed $report |
|
73 | - * @param mixed $path |
|
74 | - * @return bool |
|
75 | - */ |
|
76 | - public function report($reportName, $report, $path) { |
|
77 | - switch ($reportName) { |
|
78 | - case '{' . self::NS_Nextcloud . '}calendar-search': |
|
79 | - $this->server->transactionType = 'report-nc-calendar-search'; |
|
80 | - $this->calendarSearch($report); |
|
81 | - return false; |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Returns a list of reports this plugin supports. |
|
87 | - * |
|
88 | - * This will be used in the {DAV:}supported-report-set property. |
|
89 | - * Note that you still need to subscribe to the 'report' event to actually |
|
90 | - * implement them |
|
91 | - * |
|
92 | - * @param string $uri |
|
93 | - * @return array |
|
94 | - */ |
|
95 | - public function getSupportedReportSet($uri) { |
|
96 | - $node = $this->server->tree->getNodeForPath($uri); |
|
97 | - |
|
98 | - $reports = []; |
|
99 | - if ($node instanceof CalendarHome) { |
|
100 | - $reports[] = '{' . self::NS_Nextcloud . '}calendar-search'; |
|
101 | - } |
|
102 | - |
|
103 | - return $reports; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * This function handles the calendar-query REPORT |
|
108 | - * |
|
109 | - * This report is used by clients to request calendar objects based on |
|
110 | - * complex conditions. |
|
111 | - * |
|
112 | - * @param CalendarSearchReport $report |
|
113 | - * @return void |
|
114 | - */ |
|
115 | - private function calendarSearch($report) { |
|
116 | - $node = $this->server->tree->getNodeForPath($this->server->getRequestUri()); |
|
117 | - $depth = $this->server->getHTTPDepth(2); |
|
118 | - |
|
119 | - // The default result is an empty array |
|
120 | - $result = []; |
|
121 | - |
|
122 | - // If we're dealing with the calendar home, the calendar home itself is |
|
123 | - // responsible for the calendar-query |
|
124 | - if ($node instanceof CalendarHome && $depth === 2) { |
|
125 | - $nodePaths = $node->calendarSearch($report->filters, $report->limit, $report->offset); |
|
126 | - |
|
127 | - foreach ($nodePaths as $path) { |
|
128 | - [$properties] = $this->server->getPropertiesForPath( |
|
129 | - $this->server->getRequestUri() . '/' . $path, |
|
130 | - $report->properties); |
|
131 | - $result[] = $properties; |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - $prefer = $this->server->getHTTPPrefer(); |
|
136 | - |
|
137 | - $this->server->httpResponse->setStatus(Http::STATUS_MULTI_STATUS); |
|
138 | - $this->server->httpResponse->setHeader('Content-Type', |
|
139 | - 'application/xml; charset=utf-8'); |
|
140 | - $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer'); |
|
141 | - $this->server->httpResponse->setBody( |
|
142 | - $this->server->generateMultiStatus($result, |
|
143 | - $prefer['return'] === 'minimal')); |
|
144 | - } |
|
15 | + public const NS_Nextcloud = 'http://nextcloud.com/ns'; |
|
16 | + |
|
17 | + /** |
|
18 | + * Reference to SabreDAV server object. |
|
19 | + * |
|
20 | + * @var \Sabre\DAV\Server |
|
21 | + */ |
|
22 | + protected $server; |
|
23 | + |
|
24 | + /** |
|
25 | + * This method should return a list of server-features. |
|
26 | + * |
|
27 | + * This is for example 'versioning' and is added to the DAV: header |
|
28 | + * in an OPTIONS response. |
|
29 | + * |
|
30 | + * @return string[] |
|
31 | + */ |
|
32 | + public function getFeatures() { |
|
33 | + // May have to be changed to be detected |
|
34 | + return ['nc-calendar-search']; |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * Returns a plugin name. |
|
39 | + * |
|
40 | + * Using this name other plugins will be able to access other plugins |
|
41 | + * using Sabre\DAV\Server::getPlugin |
|
42 | + * |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public function getPluginName() { |
|
46 | + return 'nc-calendar-search'; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * This initializes the plugin. |
|
51 | + * |
|
52 | + * This function is called by Sabre\DAV\Server, after |
|
53 | + * addPlugin is called. |
|
54 | + * |
|
55 | + * This method should set up the required event subscriptions. |
|
56 | + * |
|
57 | + * @param Server $server |
|
58 | + */ |
|
59 | + public function initialize(Server $server) { |
|
60 | + $this->server = $server; |
|
61 | + |
|
62 | + $server->on('report', [$this, 'report']); |
|
63 | + |
|
64 | + $server->xml->elementMap['{' . self::NS_Nextcloud . '}calendar-search'] = |
|
65 | + CalendarSearchReport::class; |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * This functions handles REPORT requests specific to CalDAV |
|
70 | + * |
|
71 | + * @param string $reportName |
|
72 | + * @param mixed $report |
|
73 | + * @param mixed $path |
|
74 | + * @return bool |
|
75 | + */ |
|
76 | + public function report($reportName, $report, $path) { |
|
77 | + switch ($reportName) { |
|
78 | + case '{' . self::NS_Nextcloud . '}calendar-search': |
|
79 | + $this->server->transactionType = 'report-nc-calendar-search'; |
|
80 | + $this->calendarSearch($report); |
|
81 | + return false; |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Returns a list of reports this plugin supports. |
|
87 | + * |
|
88 | + * This will be used in the {DAV:}supported-report-set property. |
|
89 | + * Note that you still need to subscribe to the 'report' event to actually |
|
90 | + * implement them |
|
91 | + * |
|
92 | + * @param string $uri |
|
93 | + * @return array |
|
94 | + */ |
|
95 | + public function getSupportedReportSet($uri) { |
|
96 | + $node = $this->server->tree->getNodeForPath($uri); |
|
97 | + |
|
98 | + $reports = []; |
|
99 | + if ($node instanceof CalendarHome) { |
|
100 | + $reports[] = '{' . self::NS_Nextcloud . '}calendar-search'; |
|
101 | + } |
|
102 | + |
|
103 | + return $reports; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * This function handles the calendar-query REPORT |
|
108 | + * |
|
109 | + * This report is used by clients to request calendar objects based on |
|
110 | + * complex conditions. |
|
111 | + * |
|
112 | + * @param CalendarSearchReport $report |
|
113 | + * @return void |
|
114 | + */ |
|
115 | + private function calendarSearch($report) { |
|
116 | + $node = $this->server->tree->getNodeForPath($this->server->getRequestUri()); |
|
117 | + $depth = $this->server->getHTTPDepth(2); |
|
118 | + |
|
119 | + // The default result is an empty array |
|
120 | + $result = []; |
|
121 | + |
|
122 | + // If we're dealing with the calendar home, the calendar home itself is |
|
123 | + // responsible for the calendar-query |
|
124 | + if ($node instanceof CalendarHome && $depth === 2) { |
|
125 | + $nodePaths = $node->calendarSearch($report->filters, $report->limit, $report->offset); |
|
126 | + |
|
127 | + foreach ($nodePaths as $path) { |
|
128 | + [$properties] = $this->server->getPropertiesForPath( |
|
129 | + $this->server->getRequestUri() . '/' . $path, |
|
130 | + $report->properties); |
|
131 | + $result[] = $properties; |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + $prefer = $this->server->getHTTPPrefer(); |
|
136 | + |
|
137 | + $this->server->httpResponse->setStatus(Http::STATUS_MULTI_STATUS); |
|
138 | + $this->server->httpResponse->setHeader('Content-Type', |
|
139 | + 'application/xml; charset=utf-8'); |
|
140 | + $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer'); |
|
141 | + $this->server->httpResponse->setBody( |
|
142 | + $this->server->generateMultiStatus($result, |
|
143 | + $prefer['return'] === 'minimal')); |
|
144 | + } |
|
145 | 145 | } |
@@ -65,7 +65,7 @@ |
||
65 | 65 | try { |
66 | 66 | $this->activityManager->publish($activity); |
67 | 67 | } catch (BadMethodCallException $e) { |
68 | - $this->logger->warning('Could not publish activity: ' . $e->getMessage(), [ |
|
68 | + $this->logger->warning('Could not publish activity: '.$e->getMessage(), [ |
|
69 | 69 | 'exception' => $e |
70 | 70 | ]); |
71 | 71 | } |
@@ -21,32 +21,32 @@ |
||
21 | 21 | * @template-implements IEventListener<\OC\Authentication\Events\AppPasswordCreatedEvent> |
22 | 22 | */ |
23 | 23 | class AppPasswordCreatedActivityListener implements IEventListener { |
24 | - public function __construct( |
|
25 | - private IActivityManager $activityManager, |
|
26 | - private IUserSession $userSession, |
|
27 | - private LoggerInterface $logger, |
|
28 | - ) { |
|
29 | - } |
|
24 | + public function __construct( |
|
25 | + private IActivityManager $activityManager, |
|
26 | + private IUserSession $userSession, |
|
27 | + private LoggerInterface $logger, |
|
28 | + ) { |
|
29 | + } |
|
30 | 30 | |
31 | - public function handle(Event $event): void { |
|
32 | - if (!($event instanceof AppPasswordCreatedEvent)) { |
|
33 | - return; |
|
34 | - } |
|
31 | + public function handle(Event $event): void { |
|
32 | + if (!($event instanceof AppPasswordCreatedEvent)) { |
|
33 | + return; |
|
34 | + } |
|
35 | 35 | |
36 | - $activity = $this->activityManager->generateEvent(); |
|
37 | - $activity->setApp('settings') |
|
38 | - ->setType('security') |
|
39 | - ->setAffectedUser($event->getToken()->getUID()) |
|
40 | - ->setAuthor($this->userSession->getUser() ? $this->userSession->getUser()->getUID() : '') |
|
41 | - ->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $event->getToken()->getName()]) |
|
42 | - ->setObject('app_token', $event->getToken()->getId()); |
|
36 | + $activity = $this->activityManager->generateEvent(); |
|
37 | + $activity->setApp('settings') |
|
38 | + ->setType('security') |
|
39 | + ->setAffectedUser($event->getToken()->getUID()) |
|
40 | + ->setAuthor($this->userSession->getUser() ? $this->userSession->getUser()->getUID() : '') |
|
41 | + ->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $event->getToken()->getName()]) |
|
42 | + ->setObject('app_token', $event->getToken()->getId()); |
|
43 | 43 | |
44 | - try { |
|
45 | - $this->activityManager->publish($activity); |
|
46 | - } catch (BadMethodCallException $e) { |
|
47 | - $this->logger->warning('Could not publish activity: ' . $e->getMessage(), [ |
|
48 | - 'exception' => $e |
|
49 | - ]); |
|
50 | - } |
|
51 | - } |
|
44 | + try { |
|
45 | + $this->activityManager->publish($activity); |
|
46 | + } catch (BadMethodCallException $e) { |
|
47 | + $this->logger->warning('Could not publish activity: ' . $e->getMessage(), [ |
|
48 | + 'exception' => $e |
|
49 | + ]); |
|
50 | + } |
|
51 | + } |
|
52 | 52 | } |