@@ -194,6 +194,9 @@ |
||
| 194 | 194 | parent::propPatch($propPatch); |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | + /** |
|
| 198 | + * @return string |
|
| 199 | + */ |
|
| 197 | 200 | public function getContactsGroups() { |
| 198 | 201 | return $this->carddavBackend->collectCardProperties($this->getResourceId(), 'CATEGORIES'); |
| 199 | 202 | } |
@@ -37,179 +37,179 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareable { |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * AddressBook constructor. |
|
| 42 | - * |
|
| 43 | - * @param BackendInterface $carddavBackend |
|
| 44 | - * @param array $addressBookInfo |
|
| 45 | - * @param IL10N $l10n |
|
| 46 | - */ |
|
| 47 | - public function __construct(BackendInterface $carddavBackend, array $addressBookInfo, IL10N $l10n) { |
|
| 48 | - parent::__construct($carddavBackend, $addressBookInfo); |
|
| 49 | - |
|
| 50 | - if ($this->addressBookInfo['{DAV:}displayname'] === CardDavBackend::PERSONAL_ADDRESSBOOK_NAME && |
|
| 51 | - $this->getName() === CardDavBackend::PERSONAL_ADDRESSBOOK_URI) { |
|
| 52 | - $this->addressBookInfo['{DAV:}displayname'] = $l10n->t('Contacts'); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Updates the list of shares. |
|
| 58 | - * |
|
| 59 | - * The first array is a list of people that are to be added to the |
|
| 60 | - * addressbook. |
|
| 61 | - * |
|
| 62 | - * Every element in the add array has the following properties: |
|
| 63 | - * * href - A url. Usually a mailto: address |
|
| 64 | - * * commonName - Usually a first and last name, or false |
|
| 65 | - * * summary - A description of the share, can also be false |
|
| 66 | - * * readOnly - A boolean value |
|
| 67 | - * |
|
| 68 | - * Every element in the remove array is just the address string. |
|
| 69 | - * |
|
| 70 | - * @param array $add |
|
| 71 | - * @param array $remove |
|
| 72 | - * @return void |
|
| 73 | - * @throws Forbidden |
|
| 74 | - */ |
|
| 75 | - public function updateShares(array $add, array $remove) { |
|
| 76 | - if ($this->isShared()) { |
|
| 77 | - throw new Forbidden(); |
|
| 78 | - } |
|
| 79 | - $this->carddavBackend->updateShares($this, $add, $remove); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Returns the list of people whom this addressbook is shared with. |
|
| 84 | - * |
|
| 85 | - * Every element in this array should have the following properties: |
|
| 86 | - * * href - Often a mailto: address |
|
| 87 | - * * commonName - Optional, for example a first + last name |
|
| 88 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 89 | - * * readOnly - boolean |
|
| 90 | - * * summary - Optional, a description for the share |
|
| 91 | - * |
|
| 92 | - * @return array |
|
| 93 | - */ |
|
| 94 | - public function getShares() { |
|
| 95 | - if ($this->isShared()) { |
|
| 96 | - return []; |
|
| 97 | - } |
|
| 98 | - return $this->carddavBackend->getShares($this->getResourceId()); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - public function getACL() { |
|
| 102 | - $acl = [ |
|
| 103 | - [ |
|
| 104 | - 'privilege' => '{DAV:}read', |
|
| 105 | - 'principal' => $this->getOwner(), |
|
| 106 | - 'protected' => true, |
|
| 107 | - ]]; |
|
| 108 | - $acl[] = [ |
|
| 109 | - 'privilege' => '{DAV:}write', |
|
| 110 | - 'principal' => $this->getOwner(), |
|
| 111 | - 'protected' => true, |
|
| 112 | - ]; |
|
| 113 | - if ($this->getOwner() !== parent::getOwner()) { |
|
| 114 | - $acl[] = [ |
|
| 115 | - 'privilege' => '{DAV:}read', |
|
| 116 | - 'principal' => parent::getOwner(), |
|
| 117 | - 'protected' => true, |
|
| 118 | - ]; |
|
| 119 | - if ($this->canWrite()) { |
|
| 120 | - $acl[] = [ |
|
| 121 | - 'privilege' => '{DAV:}write', |
|
| 122 | - 'principal' => parent::getOwner(), |
|
| 123 | - 'protected' => true, |
|
| 124 | - ]; |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - if ($this->getOwner() === 'principals/system/system') { |
|
| 128 | - $acl[] = [ |
|
| 129 | - 'privilege' => '{DAV:}read', |
|
| 130 | - 'principal' => '{DAV:}authenticated', |
|
| 131 | - 'protected' => true, |
|
| 132 | - ]; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - if ($this->isShared()) { |
|
| 136 | - return $acl; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - return $this->carddavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - public function getChildACL() { |
|
| 143 | - return $this->getACL(); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - public function getChild($name) { |
|
| 147 | - |
|
| 148 | - $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name); |
|
| 149 | - if (!$obj) { |
|
| 150 | - throw new NotFound('Card not found'); |
|
| 151 | - } |
|
| 152 | - $obj['acl'] = $this->getChildACL(); |
|
| 153 | - return new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
| 154 | - |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @return int |
|
| 159 | - */ |
|
| 160 | - public function getResourceId() { |
|
| 161 | - return $this->addressBookInfo['id']; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - public function getOwner() { |
|
| 165 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 166 | - return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal']; |
|
| 167 | - } |
|
| 168 | - return parent::getOwner(); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - public function delete() { |
|
| 172 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 173 | - $principal = 'principal:' . parent::getOwner(); |
|
| 174 | - $shares = $this->carddavBackend->getShares($this->getResourceId()); |
|
| 175 | - $shares = array_filter($shares, function($share) use ($principal){ |
|
| 176 | - return $share['href'] === $principal; |
|
| 177 | - }); |
|
| 178 | - if (empty($shares)) { |
|
| 179 | - throw new Forbidden(); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - $this->carddavBackend->updateShares($this, [], [ |
|
| 183 | - 'href' => $principal |
|
| 184 | - ]); |
|
| 185 | - return; |
|
| 186 | - } |
|
| 187 | - parent::delete(); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - public function propPatch(PropPatch $propPatch) { |
|
| 191 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 192 | - throw new Forbidden(); |
|
| 193 | - } |
|
| 194 | - parent::propPatch($propPatch); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - public function getContactsGroups() { |
|
| 198 | - return $this->carddavBackend->collectCardProperties($this->getResourceId(), 'CATEGORIES'); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - private function isShared() { |
|
| 202 | - if (!isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 203 | - return false; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal'] !== $this->addressBookInfo['principaluri']; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - private function canWrite() { |
|
| 210 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}read-only'])) { |
|
| 211 | - return !$this->addressBookInfo['{http://owncloud.org/ns}read-only']; |
|
| 212 | - } |
|
| 213 | - return true; |
|
| 214 | - } |
|
| 40 | + /** |
|
| 41 | + * AddressBook constructor. |
|
| 42 | + * |
|
| 43 | + * @param BackendInterface $carddavBackend |
|
| 44 | + * @param array $addressBookInfo |
|
| 45 | + * @param IL10N $l10n |
|
| 46 | + */ |
|
| 47 | + public function __construct(BackendInterface $carddavBackend, array $addressBookInfo, IL10N $l10n) { |
|
| 48 | + parent::__construct($carddavBackend, $addressBookInfo); |
|
| 49 | + |
|
| 50 | + if ($this->addressBookInfo['{DAV:}displayname'] === CardDavBackend::PERSONAL_ADDRESSBOOK_NAME && |
|
| 51 | + $this->getName() === CardDavBackend::PERSONAL_ADDRESSBOOK_URI) { |
|
| 52 | + $this->addressBookInfo['{DAV:}displayname'] = $l10n->t('Contacts'); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Updates the list of shares. |
|
| 58 | + * |
|
| 59 | + * The first array is a list of people that are to be added to the |
|
| 60 | + * addressbook. |
|
| 61 | + * |
|
| 62 | + * Every element in the add array has the following properties: |
|
| 63 | + * * href - A url. Usually a mailto: address |
|
| 64 | + * * commonName - Usually a first and last name, or false |
|
| 65 | + * * summary - A description of the share, can also be false |
|
| 66 | + * * readOnly - A boolean value |
|
| 67 | + * |
|
| 68 | + * Every element in the remove array is just the address string. |
|
| 69 | + * |
|
| 70 | + * @param array $add |
|
| 71 | + * @param array $remove |
|
| 72 | + * @return void |
|
| 73 | + * @throws Forbidden |
|
| 74 | + */ |
|
| 75 | + public function updateShares(array $add, array $remove) { |
|
| 76 | + if ($this->isShared()) { |
|
| 77 | + throw new Forbidden(); |
|
| 78 | + } |
|
| 79 | + $this->carddavBackend->updateShares($this, $add, $remove); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Returns the list of people whom this addressbook is shared with. |
|
| 84 | + * |
|
| 85 | + * Every element in this array should have the following properties: |
|
| 86 | + * * href - Often a mailto: address |
|
| 87 | + * * commonName - Optional, for example a first + last name |
|
| 88 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 89 | + * * readOnly - boolean |
|
| 90 | + * * summary - Optional, a description for the share |
|
| 91 | + * |
|
| 92 | + * @return array |
|
| 93 | + */ |
|
| 94 | + public function getShares() { |
|
| 95 | + if ($this->isShared()) { |
|
| 96 | + return []; |
|
| 97 | + } |
|
| 98 | + return $this->carddavBackend->getShares($this->getResourceId()); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + public function getACL() { |
|
| 102 | + $acl = [ |
|
| 103 | + [ |
|
| 104 | + 'privilege' => '{DAV:}read', |
|
| 105 | + 'principal' => $this->getOwner(), |
|
| 106 | + 'protected' => true, |
|
| 107 | + ]]; |
|
| 108 | + $acl[] = [ |
|
| 109 | + 'privilege' => '{DAV:}write', |
|
| 110 | + 'principal' => $this->getOwner(), |
|
| 111 | + 'protected' => true, |
|
| 112 | + ]; |
|
| 113 | + if ($this->getOwner() !== parent::getOwner()) { |
|
| 114 | + $acl[] = [ |
|
| 115 | + 'privilege' => '{DAV:}read', |
|
| 116 | + 'principal' => parent::getOwner(), |
|
| 117 | + 'protected' => true, |
|
| 118 | + ]; |
|
| 119 | + if ($this->canWrite()) { |
|
| 120 | + $acl[] = [ |
|
| 121 | + 'privilege' => '{DAV:}write', |
|
| 122 | + 'principal' => parent::getOwner(), |
|
| 123 | + 'protected' => true, |
|
| 124 | + ]; |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + if ($this->getOwner() === 'principals/system/system') { |
|
| 128 | + $acl[] = [ |
|
| 129 | + 'privilege' => '{DAV:}read', |
|
| 130 | + 'principal' => '{DAV:}authenticated', |
|
| 131 | + 'protected' => true, |
|
| 132 | + ]; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + if ($this->isShared()) { |
|
| 136 | + return $acl; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + return $this->carddavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + public function getChildACL() { |
|
| 143 | + return $this->getACL(); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + public function getChild($name) { |
|
| 147 | + |
|
| 148 | + $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name); |
|
| 149 | + if (!$obj) { |
|
| 150 | + throw new NotFound('Card not found'); |
|
| 151 | + } |
|
| 152 | + $obj['acl'] = $this->getChildACL(); |
|
| 153 | + return new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
| 154 | + |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @return int |
|
| 159 | + */ |
|
| 160 | + public function getResourceId() { |
|
| 161 | + return $this->addressBookInfo['id']; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + public function getOwner() { |
|
| 165 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 166 | + return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal']; |
|
| 167 | + } |
|
| 168 | + return parent::getOwner(); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + public function delete() { |
|
| 172 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 173 | + $principal = 'principal:' . parent::getOwner(); |
|
| 174 | + $shares = $this->carddavBackend->getShares($this->getResourceId()); |
|
| 175 | + $shares = array_filter($shares, function($share) use ($principal){ |
|
| 176 | + return $share['href'] === $principal; |
|
| 177 | + }); |
|
| 178 | + if (empty($shares)) { |
|
| 179 | + throw new Forbidden(); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + $this->carddavBackend->updateShares($this, [], [ |
|
| 183 | + 'href' => $principal |
|
| 184 | + ]); |
|
| 185 | + return; |
|
| 186 | + } |
|
| 187 | + parent::delete(); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + public function propPatch(PropPatch $propPatch) { |
|
| 191 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 192 | + throw new Forbidden(); |
|
| 193 | + } |
|
| 194 | + parent::propPatch($propPatch); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + public function getContactsGroups() { |
|
| 198 | + return $this->carddavBackend->collectCardProperties($this->getResourceId(), 'CATEGORIES'); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + private function isShared() { |
|
| 202 | + if (!isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 203 | + return false; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal'] !== $this->addressBookInfo['principaluri']; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + private function canWrite() { |
|
| 210 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}read-only'])) { |
|
| 211 | + return !$this->addressBookInfo['{http://owncloud.org/ns}read-only']; |
|
| 212 | + } |
|
| 213 | + return true; |
|
| 214 | + } |
|
| 215 | 215 | } |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | public function getACL() { |
| 102 | - $acl = [ |
|
| 102 | + $acl = [ |
|
| 103 | 103 | [ |
| 104 | 104 | 'privilege' => '{DAV:}read', |
| 105 | 105 | 'principal' => $this->getOwner(), |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | 'protected' => true, |
| 112 | 112 | ]; |
| 113 | 113 | if ($this->getOwner() !== parent::getOwner()) { |
| 114 | - $acl[] = [ |
|
| 114 | + $acl[] = [ |
|
| 115 | 115 | 'privilege' => '{DAV:}read', |
| 116 | 116 | 'principal' => parent::getOwner(), |
| 117 | 117 | 'protected' => true, |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | |
| 171 | 171 | public function delete() { |
| 172 | 172 | if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
| 173 | - $principal = 'principal:' . parent::getOwner(); |
|
| 173 | + $principal = 'principal:'.parent::getOwner(); |
|
| 174 | 174 | $shares = $this->carddavBackend->getShares($this->getResourceId()); |
| 175 | 175 | $shares = array_filter($shares, function($share) use ($principal){ |
| 176 | 176 | return $share['href'] === $principal; |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | public function getACL() { |
| 113 | - $acl = [ |
|
| 113 | + $acl = [ |
|
| 114 | 114 | [ |
| 115 | 115 | 'privilege' => '{DAV:}read', |
| 116 | 116 | 'principal' => $this->getOwner(), |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | ]; |
| 125 | 125 | } |
| 126 | 126 | if ($this->getOwner() !== parent::getOwner()) { |
| 127 | - $acl[] = [ |
|
| 127 | + $acl[] = [ |
|
| 128 | 128 | 'privilege' => '{DAV:}read', |
| 129 | 129 | 'principal' => parent::getOwner(), |
| 130 | 130 | 'protected' => true, |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | public function delete() { |
| 167 | 167 | if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) && |
| 168 | 168 | $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) { |
| 169 | - $principal = 'principal:' . parent::getOwner(); |
|
| 169 | + $principal = 'principal:'.parent::getOwner(); |
|
| 170 | 170 | $shares = $this->caldavBackend->getShares($this->getResourceId()); |
| 171 | 171 | $shares = array_filter($shares, function($share) use ($principal){ |
| 172 | 172 | return $share['href'] === $principal; |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | |
| 257 | 257 | $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters); |
| 258 | 258 | if ($this->isShared()) { |
| 259 | - return array_filter($uris, function ($uri) { |
|
| 259 | + return array_filter($uris, function($uri) { |
|
| 260 | 260 | return $this->childExists($uri); |
| 261 | 261 | }); |
| 262 | 262 | } |
@@ -38,269 +38,269 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | class Calendar extends \Sabre\CalDAV\Calendar implements IShareable { |
| 40 | 40 | |
| 41 | - public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n) { |
|
| 42 | - parent::__construct($caldavBackend, $calendarInfo); |
|
| 43 | - |
|
| 44 | - if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
| 45 | - $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays'); |
|
| 46 | - } |
|
| 47 | - if ($this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME && |
|
| 48 | - $this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI) { |
|
| 49 | - $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal'); |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Updates the list of shares. |
|
| 55 | - * |
|
| 56 | - * The first array is a list of people that are to be added to the |
|
| 57 | - * resource. |
|
| 58 | - * |
|
| 59 | - * Every element in the add array has the following properties: |
|
| 60 | - * * href - A url. Usually a mailto: address |
|
| 61 | - * * commonName - Usually a first and last name, or false |
|
| 62 | - * * summary - A description of the share, can also be false |
|
| 63 | - * * readOnly - A boolean value |
|
| 64 | - * |
|
| 65 | - * Every element in the remove array is just the address string. |
|
| 66 | - * |
|
| 67 | - * @param array $add |
|
| 68 | - * @param array $remove |
|
| 69 | - * @return void |
|
| 70 | - * @throws Forbidden |
|
| 71 | - */ |
|
| 72 | - public function updateShares(array $add, array $remove) { |
|
| 73 | - if ($this->isShared()) { |
|
| 74 | - throw new Forbidden(); |
|
| 75 | - } |
|
| 76 | - $this->caldavBackend->updateShares($this, $add, $remove); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Returns the list of people whom this resource is shared with. |
|
| 81 | - * |
|
| 82 | - * Every element in this array should have the following properties: |
|
| 83 | - * * href - Often a mailto: address |
|
| 84 | - * * commonName - Optional, for example a first + last name |
|
| 85 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 86 | - * * readOnly - boolean |
|
| 87 | - * * summary - Optional, a description for the share |
|
| 88 | - * |
|
| 89 | - * @return array |
|
| 90 | - */ |
|
| 91 | - public function getShares() { |
|
| 92 | - if ($this->isShared()) { |
|
| 93 | - return []; |
|
| 94 | - } |
|
| 95 | - return $this->caldavBackend->getShares($this->getResourceId()); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @return int |
|
| 100 | - */ |
|
| 101 | - public function getResourceId() { |
|
| 102 | - return $this->calendarInfo['id']; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @return string |
|
| 107 | - */ |
|
| 108 | - public function getPrincipalURI() { |
|
| 109 | - return $this->calendarInfo['principaluri']; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - public function getACL() { |
|
| 113 | - $acl = [ |
|
| 114 | - [ |
|
| 115 | - 'privilege' => '{DAV:}read', |
|
| 116 | - 'principal' => $this->getOwner(), |
|
| 117 | - 'protected' => true, |
|
| 118 | - ]]; |
|
| 119 | - if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
| 120 | - $acl[] = [ |
|
| 121 | - 'privilege' => '{DAV:}write', |
|
| 122 | - 'principal' => $this->getOwner(), |
|
| 123 | - 'protected' => true, |
|
| 124 | - ]; |
|
| 125 | - } |
|
| 126 | - if ($this->getOwner() !== parent::getOwner()) { |
|
| 127 | - $acl[] = [ |
|
| 128 | - 'privilege' => '{DAV:}read', |
|
| 129 | - 'principal' => parent::getOwner(), |
|
| 130 | - 'protected' => true, |
|
| 131 | - ]; |
|
| 132 | - if ($this->canWrite()) { |
|
| 133 | - $acl[] = [ |
|
| 134 | - 'privilege' => '{DAV:}write', |
|
| 135 | - 'principal' => parent::getOwner(), |
|
| 136 | - 'protected' => true, |
|
| 137 | - ]; |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - if ($this->isPublic()) { |
|
| 141 | - $acl[] = [ |
|
| 142 | - 'privilege' => '{DAV:}read', |
|
| 143 | - 'principal' => 'principals/system/public', |
|
| 144 | - 'protected' => true, |
|
| 145 | - ]; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - if ($this->isShared()) { |
|
| 149 | - return $acl; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - public function getChildACL() { |
|
| 156 | - return $this->getACL(); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - public function getOwner() { |
|
| 160 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 161 | - return $this->calendarInfo['{http://owncloud.org/ns}owner-principal']; |
|
| 162 | - } |
|
| 163 | - return parent::getOwner(); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - public function delete() { |
|
| 167 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) && |
|
| 168 | - $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) { |
|
| 169 | - $principal = 'principal:' . parent::getOwner(); |
|
| 170 | - $shares = $this->caldavBackend->getShares($this->getResourceId()); |
|
| 171 | - $shares = array_filter($shares, function($share) use ($principal){ |
|
| 172 | - return $share['href'] === $principal; |
|
| 173 | - }); |
|
| 174 | - if (empty($shares)) { |
|
| 175 | - throw new Forbidden(); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - $this->caldavBackend->updateShares($this, [], [ |
|
| 179 | - 'href' => $principal |
|
| 180 | - ]); |
|
| 181 | - return; |
|
| 182 | - } |
|
| 183 | - parent::delete(); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - public function propPatch(PropPatch $propPatch) { |
|
| 187 | - // parent::propPatch will only update calendars table |
|
| 188 | - // if calendar is shared, changes have to be made to the properties table |
|
| 189 | - if (!$this->isShared()) { |
|
| 190 | - parent::propPatch($propPatch); |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - public function getChild($name) { |
|
| 195 | - |
|
| 196 | - $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
| 197 | - |
|
| 198 | - if (!$obj) { |
|
| 199 | - throw new NotFound('Calendar object not found'); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 203 | - throw new NotFound('Calendar object not found'); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - $obj['acl'] = $this->getChildACL(); |
|
| 207 | - |
|
| 208 | - return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
| 209 | - |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - public function getChildren() { |
|
| 213 | - |
|
| 214 | - $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']); |
|
| 215 | - $children = []; |
|
| 216 | - foreach ($objs as $obj) { |
|
| 217 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 218 | - continue; |
|
| 219 | - } |
|
| 220 | - $obj['acl'] = $this->getChildACL(); |
|
| 221 | - $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
| 222 | - } |
|
| 223 | - return $children; |
|
| 224 | - |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - public function getMultipleChildren(array $paths) { |
|
| 228 | - |
|
| 229 | - $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths); |
|
| 230 | - $children = []; |
|
| 231 | - foreach ($objs as $obj) { |
|
| 232 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 233 | - continue; |
|
| 234 | - } |
|
| 235 | - $obj['acl'] = $this->getChildACL(); |
|
| 236 | - $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
| 237 | - } |
|
| 238 | - return $children; |
|
| 239 | - |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - public function childExists($name) { |
|
| 243 | - $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
| 244 | - if (!$obj) { |
|
| 245 | - return false; |
|
| 246 | - } |
|
| 247 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 248 | - return false; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - return true; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - public function calendarQuery(array $filters) { |
|
| 255 | - |
|
| 256 | - $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters); |
|
| 257 | - if ($this->isShared()) { |
|
| 258 | - return array_filter($uris, function ($uri) { |
|
| 259 | - return $this->childExists($uri); |
|
| 260 | - }); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - return $uris; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * @param boolean $value |
|
| 268 | - * @return string|null |
|
| 269 | - */ |
|
| 270 | - public function setPublishStatus($value) { |
|
| 271 | - $publicUri = $this->caldavBackend->setPublishStatus($value, $this); |
|
| 272 | - $this->calendarInfo['publicuri'] = $publicUri; |
|
| 273 | - return $publicUri; |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * @return mixed $value |
|
| 278 | - */ |
|
| 279 | - public function getPublishStatus() { |
|
| 280 | - return $this->caldavBackend->getPublishStatus($this); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - private function canWrite() { |
|
| 284 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { |
|
| 285 | - return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; |
|
| 286 | - } |
|
| 287 | - return true; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - private function isPublic() { |
|
| 291 | - return isset($this->calendarInfo['{http://owncloud.org/ns}public']); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - protected function isShared() { |
|
| 295 | - if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 296 | - return false; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - public function isSubscription() { |
|
| 303 | - return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']); |
|
| 304 | - } |
|
| 41 | + public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n) { |
|
| 42 | + parent::__construct($caldavBackend, $calendarInfo); |
|
| 43 | + |
|
| 44 | + if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
| 45 | + $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays'); |
|
| 46 | + } |
|
| 47 | + if ($this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME && |
|
| 48 | + $this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI) { |
|
| 49 | + $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal'); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Updates the list of shares. |
|
| 55 | + * |
|
| 56 | + * The first array is a list of people that are to be added to the |
|
| 57 | + * resource. |
|
| 58 | + * |
|
| 59 | + * Every element in the add array has the following properties: |
|
| 60 | + * * href - A url. Usually a mailto: address |
|
| 61 | + * * commonName - Usually a first and last name, or false |
|
| 62 | + * * summary - A description of the share, can also be false |
|
| 63 | + * * readOnly - A boolean value |
|
| 64 | + * |
|
| 65 | + * Every element in the remove array is just the address string. |
|
| 66 | + * |
|
| 67 | + * @param array $add |
|
| 68 | + * @param array $remove |
|
| 69 | + * @return void |
|
| 70 | + * @throws Forbidden |
|
| 71 | + */ |
|
| 72 | + public function updateShares(array $add, array $remove) { |
|
| 73 | + if ($this->isShared()) { |
|
| 74 | + throw new Forbidden(); |
|
| 75 | + } |
|
| 76 | + $this->caldavBackend->updateShares($this, $add, $remove); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Returns the list of people whom this resource is shared with. |
|
| 81 | + * |
|
| 82 | + * Every element in this array should have the following properties: |
|
| 83 | + * * href - Often a mailto: address |
|
| 84 | + * * commonName - Optional, for example a first + last name |
|
| 85 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 86 | + * * readOnly - boolean |
|
| 87 | + * * summary - Optional, a description for the share |
|
| 88 | + * |
|
| 89 | + * @return array |
|
| 90 | + */ |
|
| 91 | + public function getShares() { |
|
| 92 | + if ($this->isShared()) { |
|
| 93 | + return []; |
|
| 94 | + } |
|
| 95 | + return $this->caldavBackend->getShares($this->getResourceId()); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @return int |
|
| 100 | + */ |
|
| 101 | + public function getResourceId() { |
|
| 102 | + return $this->calendarInfo['id']; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @return string |
|
| 107 | + */ |
|
| 108 | + public function getPrincipalURI() { |
|
| 109 | + return $this->calendarInfo['principaluri']; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + public function getACL() { |
|
| 113 | + $acl = [ |
|
| 114 | + [ |
|
| 115 | + 'privilege' => '{DAV:}read', |
|
| 116 | + 'principal' => $this->getOwner(), |
|
| 117 | + 'protected' => true, |
|
| 118 | + ]]; |
|
| 119 | + if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
| 120 | + $acl[] = [ |
|
| 121 | + 'privilege' => '{DAV:}write', |
|
| 122 | + 'principal' => $this->getOwner(), |
|
| 123 | + 'protected' => true, |
|
| 124 | + ]; |
|
| 125 | + } |
|
| 126 | + if ($this->getOwner() !== parent::getOwner()) { |
|
| 127 | + $acl[] = [ |
|
| 128 | + 'privilege' => '{DAV:}read', |
|
| 129 | + 'principal' => parent::getOwner(), |
|
| 130 | + 'protected' => true, |
|
| 131 | + ]; |
|
| 132 | + if ($this->canWrite()) { |
|
| 133 | + $acl[] = [ |
|
| 134 | + 'privilege' => '{DAV:}write', |
|
| 135 | + 'principal' => parent::getOwner(), |
|
| 136 | + 'protected' => true, |
|
| 137 | + ]; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + if ($this->isPublic()) { |
|
| 141 | + $acl[] = [ |
|
| 142 | + 'privilege' => '{DAV:}read', |
|
| 143 | + 'principal' => 'principals/system/public', |
|
| 144 | + 'protected' => true, |
|
| 145 | + ]; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + if ($this->isShared()) { |
|
| 149 | + return $acl; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + public function getChildACL() { |
|
| 156 | + return $this->getACL(); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + public function getOwner() { |
|
| 160 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 161 | + return $this->calendarInfo['{http://owncloud.org/ns}owner-principal']; |
|
| 162 | + } |
|
| 163 | + return parent::getOwner(); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + public function delete() { |
|
| 167 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) && |
|
| 168 | + $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) { |
|
| 169 | + $principal = 'principal:' . parent::getOwner(); |
|
| 170 | + $shares = $this->caldavBackend->getShares($this->getResourceId()); |
|
| 171 | + $shares = array_filter($shares, function($share) use ($principal){ |
|
| 172 | + return $share['href'] === $principal; |
|
| 173 | + }); |
|
| 174 | + if (empty($shares)) { |
|
| 175 | + throw new Forbidden(); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + $this->caldavBackend->updateShares($this, [], [ |
|
| 179 | + 'href' => $principal |
|
| 180 | + ]); |
|
| 181 | + return; |
|
| 182 | + } |
|
| 183 | + parent::delete(); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + public function propPatch(PropPatch $propPatch) { |
|
| 187 | + // parent::propPatch will only update calendars table |
|
| 188 | + // if calendar is shared, changes have to be made to the properties table |
|
| 189 | + if (!$this->isShared()) { |
|
| 190 | + parent::propPatch($propPatch); |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + public function getChild($name) { |
|
| 195 | + |
|
| 196 | + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
| 197 | + |
|
| 198 | + if (!$obj) { |
|
| 199 | + throw new NotFound('Calendar object not found'); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 203 | + throw new NotFound('Calendar object not found'); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + $obj['acl'] = $this->getChildACL(); |
|
| 207 | + |
|
| 208 | + return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
| 209 | + |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + public function getChildren() { |
|
| 213 | + |
|
| 214 | + $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']); |
|
| 215 | + $children = []; |
|
| 216 | + foreach ($objs as $obj) { |
|
| 217 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 218 | + continue; |
|
| 219 | + } |
|
| 220 | + $obj['acl'] = $this->getChildACL(); |
|
| 221 | + $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
| 222 | + } |
|
| 223 | + return $children; |
|
| 224 | + |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + public function getMultipleChildren(array $paths) { |
|
| 228 | + |
|
| 229 | + $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths); |
|
| 230 | + $children = []; |
|
| 231 | + foreach ($objs as $obj) { |
|
| 232 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 233 | + continue; |
|
| 234 | + } |
|
| 235 | + $obj['acl'] = $this->getChildACL(); |
|
| 236 | + $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
| 237 | + } |
|
| 238 | + return $children; |
|
| 239 | + |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + public function childExists($name) { |
|
| 243 | + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
| 244 | + if (!$obj) { |
|
| 245 | + return false; |
|
| 246 | + } |
|
| 247 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 248 | + return false; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + return true; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + public function calendarQuery(array $filters) { |
|
| 255 | + |
|
| 256 | + $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters); |
|
| 257 | + if ($this->isShared()) { |
|
| 258 | + return array_filter($uris, function ($uri) { |
|
| 259 | + return $this->childExists($uri); |
|
| 260 | + }); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + return $uris; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * @param boolean $value |
|
| 268 | + * @return string|null |
|
| 269 | + */ |
|
| 270 | + public function setPublishStatus($value) { |
|
| 271 | + $publicUri = $this->caldavBackend->setPublishStatus($value, $this); |
|
| 272 | + $this->calendarInfo['publicuri'] = $publicUri; |
|
| 273 | + return $publicUri; |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * @return mixed $value |
|
| 278 | + */ |
|
| 279 | + public function getPublishStatus() { |
|
| 280 | + return $this->caldavBackend->getPublishStatus($this); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + private function canWrite() { |
|
| 284 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { |
|
| 285 | + return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; |
|
| 286 | + } |
|
| 287 | + return true; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + private function isPublic() { |
|
| 291 | + return isset($this->calendarInfo['{http://owncloud.org/ns}public']); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + protected function isShared() { |
|
| 295 | + if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 296 | + return false; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + public function isSubscription() { |
|
| 303 | + return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']); |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | 306 | } |