@@ -30,51 +30,51 @@ |
||
30 | 30 | |
31 | 31 | class Plugin extends \Sabre\CardDAV\Plugin { |
32 | 32 | |
33 | - function initialize(Server $server) { |
|
34 | - $server->on('propFind', [$this, 'propFind']); |
|
35 | - parent::initialize($server); |
|
36 | - } |
|
33 | + function initialize(Server $server) { |
|
34 | + $server->on('propFind', [$this, 'propFind']); |
|
35 | + parent::initialize($server); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Returns the addressbook home for a given principal |
|
40 | - * |
|
41 | - * @param string $principal |
|
42 | - * @return string |
|
43 | - */ |
|
44 | - protected function getAddressbookHomeForPrincipal($principal) { |
|
38 | + /** |
|
39 | + * Returns the addressbook home for a given principal |
|
40 | + * |
|
41 | + * @param string $principal |
|
42 | + * @return string |
|
43 | + */ |
|
44 | + protected function getAddressbookHomeForPrincipal($principal) { |
|
45 | 45 | |
46 | - if (strrpos($principal, 'principals/users', -strlen($principal)) !== false) { |
|
47 | - list(, $principalId) = URLUtil::splitPath($principal); |
|
48 | - return self::ADDRESSBOOK_ROOT . '/users/' . $principalId; |
|
49 | - } |
|
50 | - if (strrpos($principal, 'principals/groups', -strlen($principal)) !== false) { |
|
51 | - list(, $principalId) = URLUtil::splitPath($principal); |
|
52 | - return self::ADDRESSBOOK_ROOT . '/groups/' . $principalId; |
|
53 | - } |
|
54 | - if (strrpos($principal, 'principals/system', -strlen($principal)) !== false) { |
|
55 | - list(, $principalId) = URLUtil::splitPath($principal); |
|
56 | - return self::ADDRESSBOOK_ROOT . '/system/' . $principalId; |
|
57 | - } |
|
46 | + if (strrpos($principal, 'principals/users', -strlen($principal)) !== false) { |
|
47 | + list(, $principalId) = URLUtil::splitPath($principal); |
|
48 | + return self::ADDRESSBOOK_ROOT . '/users/' . $principalId; |
|
49 | + } |
|
50 | + if (strrpos($principal, 'principals/groups', -strlen($principal)) !== false) { |
|
51 | + list(, $principalId) = URLUtil::splitPath($principal); |
|
52 | + return self::ADDRESSBOOK_ROOT . '/groups/' . $principalId; |
|
53 | + } |
|
54 | + if (strrpos($principal, 'principals/system', -strlen($principal)) !== false) { |
|
55 | + list(, $principalId) = URLUtil::splitPath($principal); |
|
56 | + return self::ADDRESSBOOK_ROOT . '/system/' . $principalId; |
|
57 | + } |
|
58 | 58 | |
59 | - throw new \LogicException('This is not supposed to happen'); |
|
60 | - } |
|
59 | + throw new \LogicException('This is not supposed to happen'); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Adds all CardDAV-specific properties |
|
64 | - * |
|
65 | - * @param PropFind $propFind |
|
66 | - * @param INode $node |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - function propFind(PropFind $propFind, INode $node) { |
|
62 | + /** |
|
63 | + * Adds all CardDAV-specific properties |
|
64 | + * |
|
65 | + * @param PropFind $propFind |
|
66 | + * @param INode $node |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + function propFind(PropFind $propFind, INode $node) { |
|
70 | 70 | |
71 | - $ns = '{http://owncloud.org/ns}'; |
|
71 | + $ns = '{http://owncloud.org/ns}'; |
|
72 | 72 | |
73 | - if ($node instanceof AddressBook) { |
|
73 | + if ($node instanceof AddressBook) { |
|
74 | 74 | |
75 | - $propFind->handle($ns . 'groups', function () use ($node) { |
|
76 | - return new Groups($node->getContactsGroups()); |
|
77 | - }); |
|
78 | - } |
|
79 | - } |
|
75 | + $propFind->handle($ns . 'groups', function () use ($node) { |
|
76 | + return new Groups($node->getContactsGroups()); |
|
77 | + }); |
|
78 | + } |
|
79 | + } |
|
80 | 80 | } |
@@ -45,15 +45,15 @@ discard block |
||
45 | 45 | |
46 | 46 | if (strrpos($principal, 'principals/users', -strlen($principal)) !== false) { |
47 | 47 | list(, $principalId) = URLUtil::splitPath($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 | list(, $principalId) = URLUtil::splitPath($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 | list(, $principalId) = URLUtil::splitPath($principal); |
56 | - return self::ADDRESSBOOK_ROOT . '/system/' . $principalId; |
|
56 | + return self::ADDRESSBOOK_ROOT.'/system/'.$principalId; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | throw new \LogicException('This is not supposed to happen'); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | |
73 | 73 | if ($node instanceof AddressBook) { |
74 | 74 | |
75 | - $propFind->handle($ns . 'groups', function () use ($node) { |
|
75 | + $propFind->handle($ns.'groups', function() use ($node) { |
|
76 | 76 | return new Groups($node->getContactsGroups()); |
77 | 77 | }); |
78 | 78 | } |
@@ -31,171 +31,171 @@ |
||
31 | 31 | |
32 | 32 | class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareable { |
33 | 33 | |
34 | - /** |
|
35 | - * AddressBook constructor. |
|
36 | - * |
|
37 | - * @param BackendInterface $carddavBackend |
|
38 | - * @param array $addressBookInfo |
|
39 | - * @param IL10N $l10n |
|
40 | - */ |
|
41 | - public function __construct(BackendInterface $carddavBackend, array $addressBookInfo, IL10N $l10n) { |
|
42 | - parent::__construct($carddavBackend, $addressBookInfo); |
|
43 | - |
|
44 | - if ($this->getName() === CardDavBackend::PERSONAL_ADDRESSBOOK_URI && |
|
45 | - $this->addressBookInfo['{DAV:}displayname'] === CardDavBackend::PERSONAL_ADDRESSBOOK_NAME) { |
|
46 | - $this->addressBookInfo['{DAV:}displayname'] = $l10n->t('Contacts'); |
|
47 | - } |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Updates the list of shares. |
|
52 | - * |
|
53 | - * The first array is a list of people that are to be added to the |
|
54 | - * addressbook. |
|
55 | - * |
|
56 | - * Every element in the add array has the following properties: |
|
57 | - * * href - A url. Usually a mailto: address |
|
58 | - * * commonName - Usually a first and last name, or false |
|
59 | - * * summary - A description of the share, can also be false |
|
60 | - * * readOnly - A boolean value |
|
61 | - * |
|
62 | - * Every element in the remove array is just the address string. |
|
63 | - * |
|
64 | - * @param array $add |
|
65 | - * @param array $remove |
|
66 | - * @return void |
|
67 | - */ |
|
68 | - function updateShares(array $add, array $remove) { |
|
69 | - /** @var CardDavBackend $carddavBackend */ |
|
70 | - $carddavBackend = $this->carddavBackend; |
|
71 | - $carddavBackend->updateShares($this, $add, $remove); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Returns the list of people whom this addressbook is shared with. |
|
76 | - * |
|
77 | - * Every element in this array should have the following properties: |
|
78 | - * * href - Often a mailto: address |
|
79 | - * * commonName - Optional, for example a first + last name |
|
80 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
81 | - * * readOnly - boolean |
|
82 | - * * summary - Optional, a description for the share |
|
83 | - * |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - function getShares() { |
|
87 | - /** @var CardDavBackend $carddavBackend */ |
|
88 | - $carddavBackend = $this->carddavBackend; |
|
89 | - return $carddavBackend->getShares($this->getResourceId()); |
|
90 | - } |
|
91 | - |
|
92 | - function getACL() { |
|
93 | - $acl = [ |
|
94 | - [ |
|
95 | - 'privilege' => '{DAV:}read', |
|
96 | - 'principal' => $this->getOwner(), |
|
97 | - 'protected' => true, |
|
98 | - ]]; |
|
99 | - $acl[] = [ |
|
100 | - 'privilege' => '{DAV:}write', |
|
101 | - 'principal' => $this->getOwner(), |
|
102 | - 'protected' => true, |
|
103 | - ]; |
|
104 | - if ($this->getOwner() !== parent::getOwner()) { |
|
105 | - $acl[] = [ |
|
106 | - 'privilege' => '{DAV:}read', |
|
107 | - 'principal' => parent::getOwner(), |
|
108 | - 'protected' => true, |
|
109 | - ]; |
|
110 | - if ($this->canWrite()) { |
|
111 | - $acl[] = [ |
|
112 | - 'privilege' => '{DAV:}write', |
|
113 | - 'principal' => parent::getOwner(), |
|
114 | - 'protected' => true, |
|
115 | - ]; |
|
116 | - } |
|
117 | - } |
|
118 | - if ($this->getOwner() === 'principals/system/system') { |
|
119 | - $acl[] = [ |
|
120 | - 'privilege' => '{DAV:}read', |
|
121 | - 'principal' => '{DAV:}authenticated', |
|
122 | - 'protected' => true, |
|
123 | - ]; |
|
124 | - } |
|
125 | - |
|
126 | - /** @var CardDavBackend $carddavBackend */ |
|
127 | - $carddavBackend = $this->carddavBackend; |
|
128 | - return $carddavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
129 | - } |
|
130 | - |
|
131 | - function getChildACL() { |
|
132 | - return $this->getACL(); |
|
133 | - } |
|
134 | - |
|
135 | - function getChild($name) { |
|
136 | - |
|
137 | - $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name); |
|
138 | - if (!$obj) { |
|
139 | - throw new NotFound('Card not found'); |
|
140 | - } |
|
141 | - $obj['acl'] = $this->getChildACL(); |
|
142 | - return new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
143 | - |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @return int |
|
148 | - */ |
|
149 | - public function getResourceId() { |
|
150 | - return $this->addressBookInfo['id']; |
|
151 | - } |
|
152 | - |
|
153 | - function getOwner() { |
|
154 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
155 | - return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal']; |
|
156 | - } |
|
157 | - return parent::getOwner(); |
|
158 | - } |
|
159 | - |
|
160 | - function delete() { |
|
161 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
162 | - $principal = 'principal:' . parent::getOwner(); |
|
163 | - $shares = $this->getShares(); |
|
164 | - $shares = array_filter($shares, function($share) use ($principal){ |
|
165 | - return $share['href'] === $principal; |
|
166 | - }); |
|
167 | - if (empty($shares)) { |
|
168 | - throw new Forbidden(); |
|
169 | - } |
|
170 | - |
|
171 | - /** @var CardDavBackend $cardDavBackend */ |
|
172 | - $cardDavBackend = $this->carddavBackend; |
|
173 | - $cardDavBackend->updateShares($this, [], [ |
|
174 | - 'href' => $principal |
|
175 | - ]); |
|
176 | - return; |
|
177 | - } |
|
178 | - parent::delete(); |
|
179 | - } |
|
180 | - |
|
181 | - function propPatch(PropPatch $propPatch) { |
|
182 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
183 | - throw new Forbidden(); |
|
184 | - } |
|
185 | - parent::propPatch($propPatch); |
|
186 | - } |
|
187 | - |
|
188 | - public function getContactsGroups() { |
|
189 | - /** @var CardDavBackend $cardDavBackend */ |
|
190 | - $cardDavBackend = $this->carddavBackend; |
|
191 | - |
|
192 | - return $cardDavBackend->collectCardProperties($this->getResourceId(), 'CATEGORIES'); |
|
193 | - } |
|
194 | - |
|
195 | - private function canWrite() { |
|
196 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}read-only'])) { |
|
197 | - return !$this->addressBookInfo['{http://owncloud.org/ns}read-only']; |
|
198 | - } |
|
199 | - return true; |
|
200 | - } |
|
34 | + /** |
|
35 | + * AddressBook constructor. |
|
36 | + * |
|
37 | + * @param BackendInterface $carddavBackend |
|
38 | + * @param array $addressBookInfo |
|
39 | + * @param IL10N $l10n |
|
40 | + */ |
|
41 | + public function __construct(BackendInterface $carddavBackend, array $addressBookInfo, IL10N $l10n) { |
|
42 | + parent::__construct($carddavBackend, $addressBookInfo); |
|
43 | + |
|
44 | + if ($this->getName() === CardDavBackend::PERSONAL_ADDRESSBOOK_URI && |
|
45 | + $this->addressBookInfo['{DAV:}displayname'] === CardDavBackend::PERSONAL_ADDRESSBOOK_NAME) { |
|
46 | + $this->addressBookInfo['{DAV:}displayname'] = $l10n->t('Contacts'); |
|
47 | + } |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Updates the list of shares. |
|
52 | + * |
|
53 | + * The first array is a list of people that are to be added to the |
|
54 | + * addressbook. |
|
55 | + * |
|
56 | + * Every element in the add array has the following properties: |
|
57 | + * * href - A url. Usually a mailto: address |
|
58 | + * * commonName - Usually a first and last name, or false |
|
59 | + * * summary - A description of the share, can also be false |
|
60 | + * * readOnly - A boolean value |
|
61 | + * |
|
62 | + * Every element in the remove array is just the address string. |
|
63 | + * |
|
64 | + * @param array $add |
|
65 | + * @param array $remove |
|
66 | + * @return void |
|
67 | + */ |
|
68 | + function updateShares(array $add, array $remove) { |
|
69 | + /** @var CardDavBackend $carddavBackend */ |
|
70 | + $carddavBackend = $this->carddavBackend; |
|
71 | + $carddavBackend->updateShares($this, $add, $remove); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Returns the list of people whom this addressbook is shared with. |
|
76 | + * |
|
77 | + * Every element in this array should have the following properties: |
|
78 | + * * href - Often a mailto: address |
|
79 | + * * commonName - Optional, for example a first + last name |
|
80 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
81 | + * * readOnly - boolean |
|
82 | + * * summary - Optional, a description for the share |
|
83 | + * |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + function getShares() { |
|
87 | + /** @var CardDavBackend $carddavBackend */ |
|
88 | + $carddavBackend = $this->carddavBackend; |
|
89 | + return $carddavBackend->getShares($this->getResourceId()); |
|
90 | + } |
|
91 | + |
|
92 | + function getACL() { |
|
93 | + $acl = [ |
|
94 | + [ |
|
95 | + 'privilege' => '{DAV:}read', |
|
96 | + 'principal' => $this->getOwner(), |
|
97 | + 'protected' => true, |
|
98 | + ]]; |
|
99 | + $acl[] = [ |
|
100 | + 'privilege' => '{DAV:}write', |
|
101 | + 'principal' => $this->getOwner(), |
|
102 | + 'protected' => true, |
|
103 | + ]; |
|
104 | + if ($this->getOwner() !== parent::getOwner()) { |
|
105 | + $acl[] = [ |
|
106 | + 'privilege' => '{DAV:}read', |
|
107 | + 'principal' => parent::getOwner(), |
|
108 | + 'protected' => true, |
|
109 | + ]; |
|
110 | + if ($this->canWrite()) { |
|
111 | + $acl[] = [ |
|
112 | + 'privilege' => '{DAV:}write', |
|
113 | + 'principal' => parent::getOwner(), |
|
114 | + 'protected' => true, |
|
115 | + ]; |
|
116 | + } |
|
117 | + } |
|
118 | + if ($this->getOwner() === 'principals/system/system') { |
|
119 | + $acl[] = [ |
|
120 | + 'privilege' => '{DAV:}read', |
|
121 | + 'principal' => '{DAV:}authenticated', |
|
122 | + 'protected' => true, |
|
123 | + ]; |
|
124 | + } |
|
125 | + |
|
126 | + /** @var CardDavBackend $carddavBackend */ |
|
127 | + $carddavBackend = $this->carddavBackend; |
|
128 | + return $carddavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
129 | + } |
|
130 | + |
|
131 | + function getChildACL() { |
|
132 | + return $this->getACL(); |
|
133 | + } |
|
134 | + |
|
135 | + function getChild($name) { |
|
136 | + |
|
137 | + $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name); |
|
138 | + if (!$obj) { |
|
139 | + throw new NotFound('Card not found'); |
|
140 | + } |
|
141 | + $obj['acl'] = $this->getChildACL(); |
|
142 | + return new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
143 | + |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @return int |
|
148 | + */ |
|
149 | + public function getResourceId() { |
|
150 | + return $this->addressBookInfo['id']; |
|
151 | + } |
|
152 | + |
|
153 | + function getOwner() { |
|
154 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
155 | + return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal']; |
|
156 | + } |
|
157 | + return parent::getOwner(); |
|
158 | + } |
|
159 | + |
|
160 | + function delete() { |
|
161 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
162 | + $principal = 'principal:' . parent::getOwner(); |
|
163 | + $shares = $this->getShares(); |
|
164 | + $shares = array_filter($shares, function($share) use ($principal){ |
|
165 | + return $share['href'] === $principal; |
|
166 | + }); |
|
167 | + if (empty($shares)) { |
|
168 | + throw new Forbidden(); |
|
169 | + } |
|
170 | + |
|
171 | + /** @var CardDavBackend $cardDavBackend */ |
|
172 | + $cardDavBackend = $this->carddavBackend; |
|
173 | + $cardDavBackend->updateShares($this, [], [ |
|
174 | + 'href' => $principal |
|
175 | + ]); |
|
176 | + return; |
|
177 | + } |
|
178 | + parent::delete(); |
|
179 | + } |
|
180 | + |
|
181 | + function propPatch(PropPatch $propPatch) { |
|
182 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
183 | + throw new Forbidden(); |
|
184 | + } |
|
185 | + parent::propPatch($propPatch); |
|
186 | + } |
|
187 | + |
|
188 | + public function getContactsGroups() { |
|
189 | + /** @var CardDavBackend $cardDavBackend */ |
|
190 | + $cardDavBackend = $this->carddavBackend; |
|
191 | + |
|
192 | + return $cardDavBackend->collectCardProperties($this->getResourceId(), 'CATEGORIES'); |
|
193 | + } |
|
194 | + |
|
195 | + private function canWrite() { |
|
196 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}read-only'])) { |
|
197 | + return !$this->addressBookInfo['{http://owncloud.org/ns}read-only']; |
|
198 | + } |
|
199 | + return true; |
|
200 | + } |
|
201 | 201 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | } |
91 | 91 | |
92 | 92 | function getACL() { |
93 | - $acl = [ |
|
93 | + $acl = [ |
|
94 | 94 | [ |
95 | 95 | 'privilege' => '{DAV:}read', |
96 | 96 | 'principal' => $this->getOwner(), |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | 'protected' => true, |
103 | 103 | ]; |
104 | 104 | if ($this->getOwner() !== parent::getOwner()) { |
105 | - $acl[] = [ |
|
105 | + $acl[] = [ |
|
106 | 106 | 'privilege' => '{DAV:}read', |
107 | 107 | 'principal' => parent::getOwner(), |
108 | 108 | 'protected' => true, |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | |
160 | 160 | function delete() { |
161 | 161 | if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
162 | - $principal = 'principal:' . parent::getOwner(); |
|
162 | + $principal = 'principal:'.parent::getOwner(); |
|
163 | 163 | $shares = $this->getShares(); |
164 | 164 | $shares = array_filter($shares, function($share) use ($principal){ |
165 | 165 | return $share['href'] === $principal; |
@@ -25,52 +25,52 @@ |
||
25 | 25 | |
26 | 26 | class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome { |
27 | 27 | |
28 | - /** @var IL10N */ |
|
29 | - protected $l10n; |
|
28 | + /** @var IL10N */ |
|
29 | + protected $l10n; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Returns a list of addressbooks |
|
33 | - * |
|
34 | - * @return array |
|
35 | - */ |
|
36 | - function getChildren() { |
|
37 | - if ($this->l10n === null) { |
|
38 | - $this->l10n = \OC::$server->getL10N('dav'); |
|
39 | - } |
|
31 | + /** |
|
32 | + * Returns a list of addressbooks |
|
33 | + * |
|
34 | + * @return array |
|
35 | + */ |
|
36 | + function getChildren() { |
|
37 | + if ($this->l10n === null) { |
|
38 | + $this->l10n = \OC::$server->getL10N('dav'); |
|
39 | + } |
|
40 | 40 | |
41 | - $addressBooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri); |
|
42 | - $objects = []; |
|
43 | - foreach($addressBooks as $addressBook) { |
|
44 | - $objects[] = new AddressBook($this->carddavBackend, $addressBook, $this->l10n); |
|
45 | - } |
|
46 | - return $objects; |
|
41 | + $addressBooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri); |
|
42 | + $objects = []; |
|
43 | + foreach($addressBooks as $addressBook) { |
|
44 | + $objects[] = new AddressBook($this->carddavBackend, $addressBook, $this->l10n); |
|
45 | + } |
|
46 | + return $objects; |
|
47 | 47 | |
48 | - } |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Returns a list of ACE's for this node. |
|
52 | - * |
|
53 | - * Each ACE has the following properties: |
|
54 | - * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
55 | - * currently the only supported privileges |
|
56 | - * * 'principal', a url to the principal who owns the node |
|
57 | - * * 'protected' (optional), indicating that this ACE is not allowed to |
|
58 | - * be updated. |
|
59 | - * |
|
60 | - * @return array |
|
61 | - */ |
|
62 | - function getACL() { |
|
50 | + /** |
|
51 | + * Returns a list of ACE's for this node. |
|
52 | + * |
|
53 | + * Each ACE has the following properties: |
|
54 | + * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
55 | + * currently the only supported privileges |
|
56 | + * * 'principal', a url to the principal who owns the node |
|
57 | + * * 'protected' (optional), indicating that this ACE is not allowed to |
|
58 | + * be updated. |
|
59 | + * |
|
60 | + * @return array |
|
61 | + */ |
|
62 | + function getACL() { |
|
63 | 63 | |
64 | - $acl = parent::getACL(); |
|
65 | - if ($this->principalUri === 'principals/system/system') { |
|
66 | - $acl[] = [ |
|
67 | - 'privilege' => '{DAV:}read', |
|
68 | - 'principal' => '{DAV:}authenticated', |
|
69 | - 'protected' => true, |
|
70 | - ]; |
|
71 | - } |
|
64 | + $acl = parent::getACL(); |
|
65 | + if ($this->principalUri === 'principals/system/system') { |
|
66 | + $acl[] = [ |
|
67 | + 'privilege' => '{DAV:}read', |
|
68 | + 'principal' => '{DAV:}authenticated', |
|
69 | + 'protected' => true, |
|
70 | + ]; |
|
71 | + } |
|
72 | 72 | |
73 | - return $acl; |
|
74 | - } |
|
73 | + return $acl; |
|
74 | + } |
|
75 | 75 | |
76 | 76 | } |
@@ -40,7 +40,7 @@ |
||
40 | 40 | |
41 | 41 | $addressBooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri); |
42 | 42 | $objects = []; |
43 | - foreach($addressBooks as $addressBook) { |
|
43 | + foreach ($addressBooks as $addressBook) { |
|
44 | 44 | $objects[] = new AddressBook($this->carddavBackend, $addressBook, $this->l10n); |
45 | 45 | } |
46 | 46 | return $objects; |
@@ -34,136 +34,136 @@ |
||
34 | 34 | |
35 | 35 | class ImageExportPlugin extends ServerPlugin { |
36 | 36 | |
37 | - /** @var Server */ |
|
38 | - protected $server; |
|
39 | - /** @var ILogger */ |
|
40 | - private $logger; |
|
41 | - |
|
42 | - public function __construct(ILogger $logger) { |
|
43 | - $this->logger = $logger; |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Initializes the plugin and registers event handlers |
|
48 | - * |
|
49 | - * @param Server $server |
|
50 | - * @return void |
|
51 | - */ |
|
52 | - function initialize(Server $server) { |
|
53 | - |
|
54 | - $this->server = $server; |
|
55 | - $this->server->on('method:GET', [$this, 'httpGet'], 90); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Intercepts GET requests on addressbook urls ending with ?photo. |
|
60 | - * |
|
61 | - * @param RequestInterface $request |
|
62 | - * @param ResponseInterface $response |
|
63 | - * @return bool|void |
|
64 | - */ |
|
65 | - function httpGet(RequestInterface $request, ResponseInterface $response) { |
|
66 | - |
|
67 | - $queryParams = $request->getQueryParameters(); |
|
68 | - // TODO: in addition to photo we should also add logo some point in time |
|
69 | - if (!array_key_exists('photo', $queryParams)) { |
|
70 | - return true; |
|
71 | - } |
|
72 | - |
|
73 | - $path = $request->getPath(); |
|
74 | - $node = $this->server->tree->getNodeForPath($path); |
|
75 | - |
|
76 | - if (!($node instanceof Card)) { |
|
77 | - return true; |
|
78 | - } |
|
79 | - |
|
80 | - $this->server->transactionType = 'carddav-image-export'; |
|
81 | - |
|
82 | - // Checking ACL, if available. |
|
83 | - if ($aclPlugin = $this->server->getPlugin('acl')) { |
|
84 | - /** @var \Sabre\DAVACL\Plugin $aclPlugin */ |
|
85 | - $aclPlugin->checkPrivileges($path, '{DAV:}read'); |
|
86 | - } |
|
87 | - |
|
88 | - if ($result = $this->getPhoto($node)) { |
|
89 | - $response->setHeader('Content-Type', $result['Content-Type']); |
|
90 | - $response->setHeader('Content-Disposition', 'attachment'); |
|
91 | - $response->setStatus(200); |
|
92 | - |
|
93 | - $response->setBody($result['body']); |
|
94 | - |
|
95 | - // Returning false to break the event chain |
|
96 | - return false; |
|
97 | - } |
|
98 | - return true; |
|
99 | - } |
|
100 | - |
|
101 | - function getPhoto(Card $node) { |
|
102 | - // TODO: this is kind of expensive - load carddav data from database and parse it |
|
103 | - // we might want to build up a cache one day |
|
104 | - try { |
|
105 | - $vObject = $this->readCard($node->get()); |
|
106 | - if (!$vObject->PHOTO) { |
|
107 | - return false; |
|
108 | - } |
|
109 | - |
|
110 | - $photo = $vObject->PHOTO; |
|
111 | - $type = $this->getType($photo); |
|
112 | - |
|
113 | - $val = $photo->getValue(); |
|
114 | - if ($photo->getValueType() === 'URI') { |
|
115 | - $parsed = \Sabre\URI\parse($val); |
|
116 | - //only allow data:// |
|
117 | - if ($parsed['scheme'] !== 'data') { |
|
118 | - return false; |
|
119 | - } |
|
120 | - if (substr_count($parsed['path'], ';') === 1) { |
|
121 | - list($type,) = explode(';', $parsed['path']); |
|
122 | - } |
|
123 | - $val = file_get_contents($val); |
|
124 | - } |
|
125 | - |
|
126 | - $allowedContentTypes = [ |
|
127 | - 'image/png', |
|
128 | - 'image/jpeg', |
|
129 | - 'image/gif', |
|
130 | - ]; |
|
131 | - |
|
132 | - if(!in_array($type, $allowedContentTypes, true)) { |
|
133 | - $type = 'application/octet-stream'; |
|
134 | - } |
|
135 | - |
|
136 | - return [ |
|
137 | - 'Content-Type' => $type, |
|
138 | - 'body' => $val |
|
139 | - ]; |
|
140 | - } catch(\Exception $ex) { |
|
141 | - $this->logger->logException($ex); |
|
142 | - } |
|
143 | - return false; |
|
144 | - } |
|
145 | - |
|
146 | - private function readCard($cardData) { |
|
147 | - return Reader::read($cardData); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @param Binary $photo |
|
152 | - * @return Parameter |
|
153 | - */ |
|
154 | - private function getType($photo) { |
|
155 | - $params = $photo->parameters(); |
|
156 | - if (isset($params['TYPE']) || isset($params['MEDIATYPE'])) { |
|
157 | - /** @var Parameter $typeParam */ |
|
158 | - $typeParam = isset($params['TYPE']) ? $params['TYPE'] : $params['MEDIATYPE']; |
|
159 | - $type = $typeParam->getValue(); |
|
160 | - |
|
161 | - if (strpos($type, 'image/') === 0) { |
|
162 | - return $type; |
|
163 | - } else { |
|
164 | - return 'image/' . strtolower($type); |
|
165 | - } |
|
166 | - } |
|
167 | - return ''; |
|
168 | - } |
|
37 | + /** @var Server */ |
|
38 | + protected $server; |
|
39 | + /** @var ILogger */ |
|
40 | + private $logger; |
|
41 | + |
|
42 | + public function __construct(ILogger $logger) { |
|
43 | + $this->logger = $logger; |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Initializes the plugin and registers event handlers |
|
48 | + * |
|
49 | + * @param Server $server |
|
50 | + * @return void |
|
51 | + */ |
|
52 | + function initialize(Server $server) { |
|
53 | + |
|
54 | + $this->server = $server; |
|
55 | + $this->server->on('method:GET', [$this, 'httpGet'], 90); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Intercepts GET requests on addressbook urls ending with ?photo. |
|
60 | + * |
|
61 | + * @param RequestInterface $request |
|
62 | + * @param ResponseInterface $response |
|
63 | + * @return bool|void |
|
64 | + */ |
|
65 | + function httpGet(RequestInterface $request, ResponseInterface $response) { |
|
66 | + |
|
67 | + $queryParams = $request->getQueryParameters(); |
|
68 | + // TODO: in addition to photo we should also add logo some point in time |
|
69 | + if (!array_key_exists('photo', $queryParams)) { |
|
70 | + return true; |
|
71 | + } |
|
72 | + |
|
73 | + $path = $request->getPath(); |
|
74 | + $node = $this->server->tree->getNodeForPath($path); |
|
75 | + |
|
76 | + if (!($node instanceof Card)) { |
|
77 | + return true; |
|
78 | + } |
|
79 | + |
|
80 | + $this->server->transactionType = 'carddav-image-export'; |
|
81 | + |
|
82 | + // Checking ACL, if available. |
|
83 | + if ($aclPlugin = $this->server->getPlugin('acl')) { |
|
84 | + /** @var \Sabre\DAVACL\Plugin $aclPlugin */ |
|
85 | + $aclPlugin->checkPrivileges($path, '{DAV:}read'); |
|
86 | + } |
|
87 | + |
|
88 | + if ($result = $this->getPhoto($node)) { |
|
89 | + $response->setHeader('Content-Type', $result['Content-Type']); |
|
90 | + $response->setHeader('Content-Disposition', 'attachment'); |
|
91 | + $response->setStatus(200); |
|
92 | + |
|
93 | + $response->setBody($result['body']); |
|
94 | + |
|
95 | + // Returning false to break the event chain |
|
96 | + return false; |
|
97 | + } |
|
98 | + return true; |
|
99 | + } |
|
100 | + |
|
101 | + function getPhoto(Card $node) { |
|
102 | + // TODO: this is kind of expensive - load carddav data from database and parse it |
|
103 | + // we might want to build up a cache one day |
|
104 | + try { |
|
105 | + $vObject = $this->readCard($node->get()); |
|
106 | + if (!$vObject->PHOTO) { |
|
107 | + return false; |
|
108 | + } |
|
109 | + |
|
110 | + $photo = $vObject->PHOTO; |
|
111 | + $type = $this->getType($photo); |
|
112 | + |
|
113 | + $val = $photo->getValue(); |
|
114 | + if ($photo->getValueType() === 'URI') { |
|
115 | + $parsed = \Sabre\URI\parse($val); |
|
116 | + //only allow data:// |
|
117 | + if ($parsed['scheme'] !== 'data') { |
|
118 | + return false; |
|
119 | + } |
|
120 | + if (substr_count($parsed['path'], ';') === 1) { |
|
121 | + list($type,) = explode(';', $parsed['path']); |
|
122 | + } |
|
123 | + $val = file_get_contents($val); |
|
124 | + } |
|
125 | + |
|
126 | + $allowedContentTypes = [ |
|
127 | + 'image/png', |
|
128 | + 'image/jpeg', |
|
129 | + 'image/gif', |
|
130 | + ]; |
|
131 | + |
|
132 | + if(!in_array($type, $allowedContentTypes, true)) { |
|
133 | + $type = 'application/octet-stream'; |
|
134 | + } |
|
135 | + |
|
136 | + return [ |
|
137 | + 'Content-Type' => $type, |
|
138 | + 'body' => $val |
|
139 | + ]; |
|
140 | + } catch(\Exception $ex) { |
|
141 | + $this->logger->logException($ex); |
|
142 | + } |
|
143 | + return false; |
|
144 | + } |
|
145 | + |
|
146 | + private function readCard($cardData) { |
|
147 | + return Reader::read($cardData); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @param Binary $photo |
|
152 | + * @return Parameter |
|
153 | + */ |
|
154 | + private function getType($photo) { |
|
155 | + $params = $photo->parameters(); |
|
156 | + if (isset($params['TYPE']) || isset($params['MEDIATYPE'])) { |
|
157 | + /** @var Parameter $typeParam */ |
|
158 | + $typeParam = isset($params['TYPE']) ? $params['TYPE'] : $params['MEDIATYPE']; |
|
159 | + $type = $typeParam->getValue(); |
|
160 | + |
|
161 | + if (strpos($type, 'image/') === 0) { |
|
162 | + return $type; |
|
163 | + } else { |
|
164 | + return 'image/' . strtolower($type); |
|
165 | + } |
|
166 | + } |
|
167 | + return ''; |
|
168 | + } |
|
169 | 169 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | 'image/gif', |
130 | 130 | ]; |
131 | 131 | |
132 | - if(!in_array($type, $allowedContentTypes, true)) { |
|
132 | + if (!in_array($type, $allowedContentTypes, true)) { |
|
133 | 133 | $type = 'application/octet-stream'; |
134 | 134 | } |
135 | 135 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | 'Content-Type' => $type, |
138 | 138 | 'body' => $val |
139 | 139 | ]; |
140 | - } catch(\Exception $ex) { |
|
140 | + } catch (\Exception $ex) { |
|
141 | 141 | $this->logger->logException($ex); |
142 | 142 | } |
143 | 143 | return false; |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | if (strpos($type, 'image/') === 0) { |
162 | 162 | return $type; |
163 | 163 | } else { |
164 | - return 'image/' . strtolower($type); |
|
164 | + return 'image/'.strtolower($type); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | return ''; |
@@ -28,15 +28,15 @@ |
||
28 | 28 | |
29 | 29 | class SyncJob extends TimedJob { |
30 | 30 | |
31 | - public function __construct() { |
|
32 | - // Run once a day |
|
33 | - $this->setInterval(24 * 60 * 60); |
|
34 | - } |
|
31 | + public function __construct() { |
|
32 | + // Run once a day |
|
33 | + $this->setInterval(24 * 60 * 60); |
|
34 | + } |
|
35 | 35 | |
36 | - protected function run($argument) { |
|
37 | - $app = new Application(); |
|
38 | - /** @var SyncService $ss */ |
|
39 | - $ss = $app->getSyncService(); |
|
40 | - $ss->syncInstance(); |
|
41 | - } |
|
36 | + protected function run($argument) { |
|
37 | + $app = new Application(); |
|
38 | + /** @var SyncService $ss */ |
|
39 | + $ss = $app->getSyncService(); |
|
40 | + $ss->syncInstance(); |
|
41 | + } |
|
42 | 42 | } |
@@ -39,136 +39,136 @@ |
||
39 | 39 | */ |
40 | 40 | class SystemTagNode implements \Sabre\DAV\INode { |
41 | 41 | |
42 | - /** |
|
43 | - * @var ISystemTag |
|
44 | - */ |
|
45 | - protected $tag; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var ISystemTagManager |
|
49 | - */ |
|
50 | - protected $tagManager; |
|
51 | - |
|
52 | - /** |
|
53 | - * User |
|
54 | - * |
|
55 | - * @var IUser |
|
56 | - */ |
|
57 | - protected $user; |
|
58 | - |
|
59 | - /** |
|
60 | - * Whether to allow permissions for admins |
|
61 | - * |
|
62 | - * @var bool |
|
63 | - */ |
|
64 | - protected $isAdmin; |
|
65 | - |
|
66 | - /** |
|
67 | - * Sets up the node, expects a full path name |
|
68 | - * |
|
69 | - * @param ISystemTag $tag system tag |
|
70 | - * @param IUser $user user |
|
71 | - * @param bool $isAdmin whether to allow operations for admins |
|
72 | - * @param ISystemTagManager $tagManager tag manager |
|
73 | - */ |
|
74 | - public function __construct(ISystemTag $tag, IUser $user, $isAdmin, ISystemTagManager $tagManager) { |
|
75 | - $this->tag = $tag; |
|
76 | - $this->user = $user; |
|
77 | - $this->isAdmin = $isAdmin; |
|
78 | - $this->tagManager = $tagManager; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Returns the id of the tag |
|
83 | - * |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - public function getName() { |
|
87 | - return $this->tag->getId(); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Returns the system tag represented by this node |
|
92 | - * |
|
93 | - * @return ISystemTag system tag |
|
94 | - */ |
|
95 | - public function getSystemTag() { |
|
96 | - return $this->tag; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Renames the node |
|
101 | - * |
|
102 | - * @param string $name The new name |
|
103 | - * |
|
104 | - * @throws MethodNotAllowed not allowed to rename node |
|
105 | - */ |
|
106 | - public function setName($name) { |
|
107 | - throw new MethodNotAllowed(); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Update tag |
|
112 | - * |
|
113 | - * @param string $name new tag name |
|
114 | - * @param bool $userVisible user visible |
|
115 | - * @param bool $userAssignable user assignable |
|
116 | - * @throws NotFound whenever the given tag id does not exist |
|
117 | - * @throws Forbidden whenever there is no permission to update said tag |
|
118 | - * @throws Conflict whenever a tag already exists with the given attributes |
|
119 | - */ |
|
120 | - public function update($name, $userVisible, $userAssignable) { |
|
121 | - try { |
|
122 | - if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) { |
|
123 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist'); |
|
124 | - } |
|
125 | - if (!$this->tagManager->canUserAssignTag($this->tag, $this->user)) { |
|
126 | - throw new Forbidden('No permission to update tag ' . $this->tag->getId()); |
|
127 | - } |
|
128 | - |
|
129 | - // only admin is able to change permissions, regular users can only rename |
|
130 | - if (!$this->isAdmin) { |
|
131 | - // only renaming is allowed for regular users |
|
132 | - if ($userVisible !== $this->tag->isUserVisible() |
|
133 | - || $userAssignable !== $this->tag->isUserAssignable() |
|
134 | - ) { |
|
135 | - throw new Forbidden('No permission to update permissions for tag ' . $this->tag->getId()); |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - $this->tagManager->updateTag($this->tag->getId(), $name, $userVisible, $userAssignable); |
|
140 | - } catch (TagNotFoundException $e) { |
|
141 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist'); |
|
142 | - } catch (TagAlreadyExistsException $e) { |
|
143 | - throw new Conflict( |
|
144 | - 'Tag with the properties "' . $name . '", ' . |
|
145 | - $userVisible . ', ' . $userAssignable . ' already exists' |
|
146 | - ); |
|
147 | - } |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Returns null, not supported |
|
152 | - * |
|
153 | - */ |
|
154 | - public function getLastModified() { |
|
155 | - return null; |
|
156 | - } |
|
157 | - |
|
158 | - public function delete() { |
|
159 | - try { |
|
160 | - if (!$this->isAdmin) { |
|
161 | - throw new Forbidden('No permission to delete tag ' . $this->tag->getId()); |
|
162 | - } |
|
163 | - |
|
164 | - if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) { |
|
165 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found'); |
|
166 | - } |
|
167 | - |
|
168 | - $this->tagManager->deleteTags($this->tag->getId()); |
|
169 | - } catch (TagNotFoundException $e) { |
|
170 | - // can happen if concurrent deletion occurred |
|
171 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found', 0, $e); |
|
172 | - } |
|
173 | - } |
|
42 | + /** |
|
43 | + * @var ISystemTag |
|
44 | + */ |
|
45 | + protected $tag; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var ISystemTagManager |
|
49 | + */ |
|
50 | + protected $tagManager; |
|
51 | + |
|
52 | + /** |
|
53 | + * User |
|
54 | + * |
|
55 | + * @var IUser |
|
56 | + */ |
|
57 | + protected $user; |
|
58 | + |
|
59 | + /** |
|
60 | + * Whether to allow permissions for admins |
|
61 | + * |
|
62 | + * @var bool |
|
63 | + */ |
|
64 | + protected $isAdmin; |
|
65 | + |
|
66 | + /** |
|
67 | + * Sets up the node, expects a full path name |
|
68 | + * |
|
69 | + * @param ISystemTag $tag system tag |
|
70 | + * @param IUser $user user |
|
71 | + * @param bool $isAdmin whether to allow operations for admins |
|
72 | + * @param ISystemTagManager $tagManager tag manager |
|
73 | + */ |
|
74 | + public function __construct(ISystemTag $tag, IUser $user, $isAdmin, ISystemTagManager $tagManager) { |
|
75 | + $this->tag = $tag; |
|
76 | + $this->user = $user; |
|
77 | + $this->isAdmin = $isAdmin; |
|
78 | + $this->tagManager = $tagManager; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Returns the id of the tag |
|
83 | + * |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + public function getName() { |
|
87 | + return $this->tag->getId(); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Returns the system tag represented by this node |
|
92 | + * |
|
93 | + * @return ISystemTag system tag |
|
94 | + */ |
|
95 | + public function getSystemTag() { |
|
96 | + return $this->tag; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Renames the node |
|
101 | + * |
|
102 | + * @param string $name The new name |
|
103 | + * |
|
104 | + * @throws MethodNotAllowed not allowed to rename node |
|
105 | + */ |
|
106 | + public function setName($name) { |
|
107 | + throw new MethodNotAllowed(); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Update tag |
|
112 | + * |
|
113 | + * @param string $name new tag name |
|
114 | + * @param bool $userVisible user visible |
|
115 | + * @param bool $userAssignable user assignable |
|
116 | + * @throws NotFound whenever the given tag id does not exist |
|
117 | + * @throws Forbidden whenever there is no permission to update said tag |
|
118 | + * @throws Conflict whenever a tag already exists with the given attributes |
|
119 | + */ |
|
120 | + public function update($name, $userVisible, $userAssignable) { |
|
121 | + try { |
|
122 | + if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) { |
|
123 | + throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist'); |
|
124 | + } |
|
125 | + if (!$this->tagManager->canUserAssignTag($this->tag, $this->user)) { |
|
126 | + throw new Forbidden('No permission to update tag ' . $this->tag->getId()); |
|
127 | + } |
|
128 | + |
|
129 | + // only admin is able to change permissions, regular users can only rename |
|
130 | + if (!$this->isAdmin) { |
|
131 | + // only renaming is allowed for regular users |
|
132 | + if ($userVisible !== $this->tag->isUserVisible() |
|
133 | + || $userAssignable !== $this->tag->isUserAssignable() |
|
134 | + ) { |
|
135 | + throw new Forbidden('No permission to update permissions for tag ' . $this->tag->getId()); |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + $this->tagManager->updateTag($this->tag->getId(), $name, $userVisible, $userAssignable); |
|
140 | + } catch (TagNotFoundException $e) { |
|
141 | + throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist'); |
|
142 | + } catch (TagAlreadyExistsException $e) { |
|
143 | + throw new Conflict( |
|
144 | + 'Tag with the properties "' . $name . '", ' . |
|
145 | + $userVisible . ', ' . $userAssignable . ' already exists' |
|
146 | + ); |
|
147 | + } |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Returns null, not supported |
|
152 | + * |
|
153 | + */ |
|
154 | + public function getLastModified() { |
|
155 | + return null; |
|
156 | + } |
|
157 | + |
|
158 | + public function delete() { |
|
159 | + try { |
|
160 | + if (!$this->isAdmin) { |
|
161 | + throw new Forbidden('No permission to delete tag ' . $this->tag->getId()); |
|
162 | + } |
|
163 | + |
|
164 | + if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) { |
|
165 | + throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found'); |
|
166 | + } |
|
167 | + |
|
168 | + $this->tagManager->deleteTags($this->tag->getId()); |
|
169 | + } catch (TagNotFoundException $e) { |
|
170 | + // can happen if concurrent deletion occurred |
|
171 | + throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found', 0, $e); |
|
172 | + } |
|
173 | + } |
|
174 | 174 | } |
@@ -120,10 +120,10 @@ discard block |
||
120 | 120 | public function update($name, $userVisible, $userAssignable) { |
121 | 121 | try { |
122 | 122 | if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) { |
123 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist'); |
|
123 | + throw new NotFound('Tag with id '.$this->tag->getId().' does not exist'); |
|
124 | 124 | } |
125 | 125 | if (!$this->tagManager->canUserAssignTag($this->tag, $this->user)) { |
126 | - throw new Forbidden('No permission to update tag ' . $this->tag->getId()); |
|
126 | + throw new Forbidden('No permission to update tag '.$this->tag->getId()); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | // only admin is able to change permissions, regular users can only rename |
@@ -132,17 +132,17 @@ discard block |
||
132 | 132 | if ($userVisible !== $this->tag->isUserVisible() |
133 | 133 | || $userAssignable !== $this->tag->isUserAssignable() |
134 | 134 | ) { |
135 | - throw new Forbidden('No permission to update permissions for tag ' . $this->tag->getId()); |
|
135 | + throw new Forbidden('No permission to update permissions for tag '.$this->tag->getId()); |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
139 | 139 | $this->tagManager->updateTag($this->tag->getId(), $name, $userVisible, $userAssignable); |
140 | 140 | } catch (TagNotFoundException $e) { |
141 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist'); |
|
141 | + throw new NotFound('Tag with id '.$this->tag->getId().' does not exist'); |
|
142 | 142 | } catch (TagAlreadyExistsException $e) { |
143 | 143 | throw new Conflict( |
144 | - 'Tag with the properties "' . $name . '", ' . |
|
145 | - $userVisible . ', ' . $userAssignable . ' already exists' |
|
144 | + 'Tag with the properties "'.$name.'", '. |
|
145 | + $userVisible.', '.$userAssignable.' already exists' |
|
146 | 146 | ); |
147 | 147 | } |
148 | 148 | } |
@@ -158,17 +158,17 @@ discard block |
||
158 | 158 | public function delete() { |
159 | 159 | try { |
160 | 160 | if (!$this->isAdmin) { |
161 | - throw new Forbidden('No permission to delete tag ' . $this->tag->getId()); |
|
161 | + throw new Forbidden('No permission to delete tag '.$this->tag->getId()); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) { |
165 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found'); |
|
165 | + throw new NotFound('Tag with id '.$this->tag->getId().' not found'); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | $this->tagManager->deleteTags($this->tag->getId()); |
169 | 169 | } catch (TagNotFoundException $e) { |
170 | 170 | // can happen if concurrent deletion occurred |
171 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found', 0, $e); |
|
171 | + throw new NotFound('Tag with id '.$this->tag->getId().' not found', 0, $e); |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 | } |
@@ -37,134 +37,134 @@ |
||
37 | 37 | * Mapping node for system tag to object id |
38 | 38 | */ |
39 | 39 | class SystemTagMappingNode implements \Sabre\DAV\INode { |
40 | - /** |
|
41 | - * @var ISystemTag |
|
42 | - */ |
|
43 | - protected $tag; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - private $objectId; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - private $objectType; |
|
54 | - |
|
55 | - /** |
|
56 | - * User |
|
57 | - * |
|
58 | - * @var IUser |
|
59 | - */ |
|
60 | - protected $user; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var ISystemTagManager |
|
64 | - */ |
|
65 | - protected $tagManager; |
|
66 | - |
|
67 | - /** |
|
68 | - * @var ISystemTagObjectMapper |
|
69 | - */ |
|
70 | - private $tagMapper; |
|
71 | - |
|
72 | - /** |
|
73 | - * Sets up the node, expects a full path name |
|
74 | - * |
|
75 | - * @param ISystemTag $tag system tag |
|
76 | - * @param string $objectId |
|
77 | - * @param string $objectType |
|
78 | - * @param IUser $user user |
|
79 | - * @param ISystemTagManager $tagManager |
|
80 | - * @param ISystemTagObjectMapper $tagMapper |
|
81 | - */ |
|
82 | - public function __construct( |
|
83 | - ISystemTag $tag, |
|
84 | - $objectId, |
|
85 | - $objectType, |
|
86 | - IUser $user, |
|
87 | - ISystemTagManager $tagManager, |
|
88 | - ISystemTagObjectMapper $tagMapper |
|
89 | - ) { |
|
90 | - $this->tag = $tag; |
|
91 | - $this->objectId = $objectId; |
|
92 | - $this->objectType = $objectType; |
|
93 | - $this->user = $user; |
|
94 | - $this->tagManager = $tagManager; |
|
95 | - $this->tagMapper = $tagMapper; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Returns the object id of the relationship |
|
100 | - * |
|
101 | - * @return string object id |
|
102 | - */ |
|
103 | - public function getObjectId() { |
|
104 | - return $this->objectId; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Returns the object type of the relationship |
|
109 | - * |
|
110 | - * @return string object type |
|
111 | - */ |
|
112 | - public function getObjectType() { |
|
113 | - return $this->objectType; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Returns the system tag represented by this node |
|
118 | - * |
|
119 | - * @return ISystemTag system tag |
|
120 | - */ |
|
121 | - public function getSystemTag() { |
|
122 | - return $this->tag; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Returns the id of the tag |
|
127 | - * |
|
128 | - * @return string |
|
129 | - */ |
|
130 | - public function getName() { |
|
131 | - return $this->tag->getId(); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Renames the node |
|
136 | - * |
|
137 | - * @param string $name The new name |
|
138 | - * |
|
139 | - * @throws MethodNotAllowed not allowed to rename node |
|
140 | - */ |
|
141 | - public function setName($name) { |
|
142 | - throw new MethodNotAllowed(); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Returns null, not supported |
|
147 | - * |
|
148 | - */ |
|
149 | - public function getLastModified() { |
|
150 | - return null; |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Delete tag to object association |
|
155 | - */ |
|
156 | - public function delete() { |
|
157 | - try { |
|
158 | - if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) { |
|
159 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found'); |
|
160 | - } |
|
161 | - if (!$this->tagManager->canUserAssignTag($this->tag, $this->user)) { |
|
162 | - throw new Forbidden('No permission to unassign tag ' . $this->tag->getId()); |
|
163 | - } |
|
164 | - $this->tagMapper->unassignTags($this->objectId, $this->objectType, $this->tag->getId()); |
|
165 | - } catch (TagNotFoundException $e) { |
|
166 | - // can happen if concurrent deletion occurred |
|
167 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found', 0, $e); |
|
168 | - } |
|
169 | - } |
|
40 | + /** |
|
41 | + * @var ISystemTag |
|
42 | + */ |
|
43 | + protected $tag; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + private $objectId; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + private $objectType; |
|
54 | + |
|
55 | + /** |
|
56 | + * User |
|
57 | + * |
|
58 | + * @var IUser |
|
59 | + */ |
|
60 | + protected $user; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var ISystemTagManager |
|
64 | + */ |
|
65 | + protected $tagManager; |
|
66 | + |
|
67 | + /** |
|
68 | + * @var ISystemTagObjectMapper |
|
69 | + */ |
|
70 | + private $tagMapper; |
|
71 | + |
|
72 | + /** |
|
73 | + * Sets up the node, expects a full path name |
|
74 | + * |
|
75 | + * @param ISystemTag $tag system tag |
|
76 | + * @param string $objectId |
|
77 | + * @param string $objectType |
|
78 | + * @param IUser $user user |
|
79 | + * @param ISystemTagManager $tagManager |
|
80 | + * @param ISystemTagObjectMapper $tagMapper |
|
81 | + */ |
|
82 | + public function __construct( |
|
83 | + ISystemTag $tag, |
|
84 | + $objectId, |
|
85 | + $objectType, |
|
86 | + IUser $user, |
|
87 | + ISystemTagManager $tagManager, |
|
88 | + ISystemTagObjectMapper $tagMapper |
|
89 | + ) { |
|
90 | + $this->tag = $tag; |
|
91 | + $this->objectId = $objectId; |
|
92 | + $this->objectType = $objectType; |
|
93 | + $this->user = $user; |
|
94 | + $this->tagManager = $tagManager; |
|
95 | + $this->tagMapper = $tagMapper; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Returns the object id of the relationship |
|
100 | + * |
|
101 | + * @return string object id |
|
102 | + */ |
|
103 | + public function getObjectId() { |
|
104 | + return $this->objectId; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Returns the object type of the relationship |
|
109 | + * |
|
110 | + * @return string object type |
|
111 | + */ |
|
112 | + public function getObjectType() { |
|
113 | + return $this->objectType; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Returns the system tag represented by this node |
|
118 | + * |
|
119 | + * @return ISystemTag system tag |
|
120 | + */ |
|
121 | + public function getSystemTag() { |
|
122 | + return $this->tag; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Returns the id of the tag |
|
127 | + * |
|
128 | + * @return string |
|
129 | + */ |
|
130 | + public function getName() { |
|
131 | + return $this->tag->getId(); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Renames the node |
|
136 | + * |
|
137 | + * @param string $name The new name |
|
138 | + * |
|
139 | + * @throws MethodNotAllowed not allowed to rename node |
|
140 | + */ |
|
141 | + public function setName($name) { |
|
142 | + throw new MethodNotAllowed(); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Returns null, not supported |
|
147 | + * |
|
148 | + */ |
|
149 | + public function getLastModified() { |
|
150 | + return null; |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Delete tag to object association |
|
155 | + */ |
|
156 | + public function delete() { |
|
157 | + try { |
|
158 | + if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) { |
|
159 | + throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found'); |
|
160 | + } |
|
161 | + if (!$this->tagManager->canUserAssignTag($this->tag, $this->user)) { |
|
162 | + throw new Forbidden('No permission to unassign tag ' . $this->tag->getId()); |
|
163 | + } |
|
164 | + $this->tagMapper->unassignTags($this->objectId, $this->objectType, $this->tag->getId()); |
|
165 | + } catch (TagNotFoundException $e) { |
|
166 | + // can happen if concurrent deletion occurred |
|
167 | + throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found', 0, $e); |
|
168 | + } |
|
169 | + } |
|
170 | 170 | } |
@@ -156,15 +156,15 @@ |
||
156 | 156 | public function delete() { |
157 | 157 | try { |
158 | 158 | if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) { |
159 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found'); |
|
159 | + throw new NotFound('Tag with id '.$this->tag->getId().' not found'); |
|
160 | 160 | } |
161 | 161 | if (!$this->tagManager->canUserAssignTag($this->tag, $this->user)) { |
162 | - throw new Forbidden('No permission to unassign tag ' . $this->tag->getId()); |
|
162 | + throw new Forbidden('No permission to unassign tag '.$this->tag->getId()); |
|
163 | 163 | } |
164 | 164 | $this->tagMapper->unassignTags($this->objectId, $this->objectType, $this->tag->getId()); |
165 | 165 | } catch (TagNotFoundException $e) { |
166 | 166 | // can happen if concurrent deletion occurred |
167 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found', 0, $e); |
|
167 | + throw new NotFound('Tag with id '.$this->tag->getId().' not found', 0, $e); |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | } |
@@ -36,59 +36,59 @@ |
||
36 | 36 | |
37 | 37 | class SystemTagsRelationsCollection extends SimpleCollection { |
38 | 38 | |
39 | - /** |
|
40 | - * SystemTagsRelationsCollection constructor. |
|
41 | - * |
|
42 | - * @param ISystemTagManager $tagManager |
|
43 | - * @param ISystemTagObjectMapper $tagMapper |
|
44 | - * @param IUserSession $userSession |
|
45 | - * @param IGroupManager $groupManager |
|
46 | - * @param EventDispatcherInterface $dispatcher |
|
47 | - */ |
|
48 | - public function __construct( |
|
49 | - ISystemTagManager $tagManager, |
|
50 | - ISystemTagObjectMapper $tagMapper, |
|
51 | - IUserSession $userSession, |
|
52 | - IGroupManager $groupManager, |
|
53 | - EventDispatcherInterface $dispatcher |
|
54 | - ) { |
|
55 | - $children = [ |
|
56 | - new SystemTagsObjectTypeCollection( |
|
57 | - 'files', |
|
58 | - $tagManager, |
|
59 | - $tagMapper, |
|
60 | - $userSession, |
|
61 | - $groupManager, |
|
62 | - function($name) { |
|
63 | - $nodes = \OC::$server->getUserFolder()->getById(intval($name)); |
|
64 | - return !empty($nodes); |
|
65 | - } |
|
66 | - ), |
|
67 | - ]; |
|
39 | + /** |
|
40 | + * SystemTagsRelationsCollection constructor. |
|
41 | + * |
|
42 | + * @param ISystemTagManager $tagManager |
|
43 | + * @param ISystemTagObjectMapper $tagMapper |
|
44 | + * @param IUserSession $userSession |
|
45 | + * @param IGroupManager $groupManager |
|
46 | + * @param EventDispatcherInterface $dispatcher |
|
47 | + */ |
|
48 | + public function __construct( |
|
49 | + ISystemTagManager $tagManager, |
|
50 | + ISystemTagObjectMapper $tagMapper, |
|
51 | + IUserSession $userSession, |
|
52 | + IGroupManager $groupManager, |
|
53 | + EventDispatcherInterface $dispatcher |
|
54 | + ) { |
|
55 | + $children = [ |
|
56 | + new SystemTagsObjectTypeCollection( |
|
57 | + 'files', |
|
58 | + $tagManager, |
|
59 | + $tagMapper, |
|
60 | + $userSession, |
|
61 | + $groupManager, |
|
62 | + function($name) { |
|
63 | + $nodes = \OC::$server->getUserFolder()->getById(intval($name)); |
|
64 | + return !empty($nodes); |
|
65 | + } |
|
66 | + ), |
|
67 | + ]; |
|
68 | 68 | |
69 | - $event = new SystemTagsEntityEvent(SystemTagsEntityEvent::EVENT_ENTITY); |
|
70 | - $dispatcher->dispatch(SystemTagsEntityEvent::EVENT_ENTITY, $event); |
|
69 | + $event = new SystemTagsEntityEvent(SystemTagsEntityEvent::EVENT_ENTITY); |
|
70 | + $dispatcher->dispatch(SystemTagsEntityEvent::EVENT_ENTITY, $event); |
|
71 | 71 | |
72 | - foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) { |
|
73 | - $children[] = new SystemTagsObjectTypeCollection( |
|
74 | - $entity, |
|
75 | - $tagManager, |
|
76 | - $tagMapper, |
|
77 | - $userSession, |
|
78 | - $groupManager, |
|
79 | - $entityExistsFunction |
|
80 | - ); |
|
81 | - } |
|
72 | + foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) { |
|
73 | + $children[] = new SystemTagsObjectTypeCollection( |
|
74 | + $entity, |
|
75 | + $tagManager, |
|
76 | + $tagMapper, |
|
77 | + $userSession, |
|
78 | + $groupManager, |
|
79 | + $entityExistsFunction |
|
80 | + ); |
|
81 | + } |
|
82 | 82 | |
83 | - parent::__construct('root', $children); |
|
84 | - } |
|
83 | + parent::__construct('root', $children); |
|
84 | + } |
|
85 | 85 | |
86 | - function getName() { |
|
87 | - return 'systemtags-relations'; |
|
88 | - } |
|
86 | + function getName() { |
|
87 | + return 'systemtags-relations'; |
|
88 | + } |
|
89 | 89 | |
90 | - function setName($name) { |
|
91 | - throw new Forbidden('Permission denied to rename this collection'); |
|
92 | - } |
|
90 | + function setName($name) { |
|
91 | + throw new Forbidden('Permission denied to rename this collection'); |
|
92 | + } |
|
93 | 93 | |
94 | 94 | } |
@@ -35,17 +35,17 @@ discard block |
||
35 | 35 | use Sabre\CardDAV\Plugin; |
36 | 36 | |
37 | 37 | $authBackend = new Auth( |
38 | - \OC::$server->getSession(), |
|
39 | - \OC::$server->getUserSession(), |
|
40 | - \OC::$server->getRequest(), |
|
41 | - \OC::$server->getTwoFactorAuthManager(), |
|
42 | - \OC::$server->getBruteForceThrottler(), |
|
43 | - 'principals/' |
|
38 | + \OC::$server->getSession(), |
|
39 | + \OC::$server->getUserSession(), |
|
40 | + \OC::$server->getRequest(), |
|
41 | + \OC::$server->getTwoFactorAuthManager(), |
|
42 | + \OC::$server->getBruteForceThrottler(), |
|
43 | + 'principals/' |
|
44 | 44 | ); |
45 | 45 | $principalBackend = new Principal( |
46 | - \OC::$server->getUserManager(), |
|
47 | - \OC::$server->getGroupManager(), |
|
48 | - 'principals/' |
|
46 | + \OC::$server->getUserManager(), |
|
47 | + \OC::$server->getGroupManager(), |
|
48 | + 'principals/' |
|
49 | 49 | ); |
50 | 50 | $db = \OC::$server->getDatabaseConnection(); |
51 | 51 | $cardDavBackend = new CardDavBackend($db, $principalBackend, \OC::$server->getUserManager()); |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | $addressBookRoot->disableListing = !$debugging; // Disable listing |
61 | 61 | |
62 | 62 | $nodes = array( |
63 | - $principalCollection, |
|
64 | - $addressBookRoot, |
|
63 | + $principalCollection, |
|
64 | + $addressBookRoot, |
|
65 | 65 | ); |
66 | 66 | |
67 | 67 | // Fire up server |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | |
77 | 77 | $server->addPlugin(new LegacyDAVACL()); |
78 | 78 | if ($debugging) { |
79 | - $server->addPlugin(new Sabre\DAV\Browser\Plugin()); |
|
79 | + $server->addPlugin(new Sabre\DAV\Browser\Plugin()); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | $server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |