@@ -34,197 +34,197 @@ |
||
| 34 | 34 | use OCP\Notification\INotifier; |
| 35 | 35 | |
| 36 | 36 | class Notifier implements INotifier { |
| 37 | - /** @var IFactory */ |
|
| 38 | - protected $factory; |
|
| 39 | - /** @var IManager */ |
|
| 40 | - protected $contactsManager; |
|
| 41 | - /** @var IURLGenerator */ |
|
| 42 | - protected $url; |
|
| 43 | - /** @var array */ |
|
| 44 | - protected $federatedContacts; |
|
| 45 | - /** @var ICloudIdManager */ |
|
| 46 | - protected $cloudIdManager; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @param IFactory $factory |
|
| 50 | - * @param IManager $contactsManager |
|
| 51 | - * @param IURLGenerator $url |
|
| 52 | - * @param ICloudIdManager $cloudIdManager |
|
| 53 | - */ |
|
| 54 | - public function __construct(IFactory $factory, IManager $contactsManager, IURLGenerator $url, ICloudIdManager $cloudIdManager) { |
|
| 55 | - $this->factory = $factory; |
|
| 56 | - $this->contactsManager = $contactsManager; |
|
| 57 | - $this->url = $url; |
|
| 58 | - $this->cloudIdManager = $cloudIdManager; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @param INotification $notification |
|
| 63 | - * @param string $languageCode The code of the language that should be used to prepare the notification |
|
| 64 | - * @return INotification |
|
| 65 | - * @throws \InvalidArgumentException |
|
| 66 | - */ |
|
| 67 | - public function prepare(INotification $notification, $languageCode) { |
|
| 68 | - if ($notification->getApp() !== 'files_sharing') { |
|
| 69 | - // Not my app => throw |
|
| 70 | - throw new \InvalidArgumentException(); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - // Read the language from the notification |
|
| 74 | - $l = $this->factory->get('files_sharing', $languageCode); |
|
| 75 | - |
|
| 76 | - switch ($notification->getSubject()) { |
|
| 77 | - // Deal with known subjects |
|
| 78 | - case 'remote_share': |
|
| 79 | - $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 80 | - |
|
| 81 | - $params = $notification->getSubjectParameters(); |
|
| 82 | - if ($params[0] !== $params[1] && $params[1] !== null) { |
|
| 83 | - $notification->setParsedSubject( |
|
| 84 | - $l->t('You received "%3$s" as a remote share from %1$s (on behalf of %2$s)', $params) |
|
| 85 | - ); |
|
| 86 | - $notification->setRichSubject( |
|
| 87 | - $l->t('You received {share} as a remote share from {user} (on behalf of {behalf})'), |
|
| 88 | - [ |
|
| 89 | - 'share' => [ |
|
| 90 | - 'type' => 'pending-federated-share', |
|
| 91 | - 'id' => $notification->getObjectId(), |
|
| 92 | - 'name' => $params[2], |
|
| 93 | - ], |
|
| 94 | - 'user' => $this->createRemoteUser($params[0]), |
|
| 95 | - 'behalf' => $this->createRemoteUser($params[1]), |
|
| 96 | - ] |
|
| 97 | - ); |
|
| 98 | - } else { |
|
| 99 | - $notification->setParsedSubject( |
|
| 100 | - $l->t('You received "%3$s" as a remote share from %1$s', $params) |
|
| 101 | - ); |
|
| 102 | - $notification->setRichSubject( |
|
| 103 | - $l->t('You received {share} as a remote share from {user}'), |
|
| 104 | - [ |
|
| 105 | - 'share' => [ |
|
| 106 | - 'type' => 'pending-federated-share', |
|
| 107 | - 'id' => $notification->getObjectId(), |
|
| 108 | - 'name' => $params[2], |
|
| 109 | - ], |
|
| 110 | - 'user' => $this->createRemoteUser($params[0]), |
|
| 111 | - ] |
|
| 112 | - ); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // Deal with the actions for a known subject |
|
| 116 | - foreach ($notification->getActions() as $action) { |
|
| 117 | - switch ($action->getLabel()) { |
|
| 118 | - case 'accept': |
|
| 119 | - $action->setParsedLabel( |
|
| 120 | - (string) $l->t('Accept') |
|
| 121 | - ) |
|
| 122 | - ->setPrimary(true); |
|
| 123 | - break; |
|
| 124 | - |
|
| 125 | - case 'decline': |
|
| 126 | - $action->setParsedLabel( |
|
| 127 | - (string) $l->t('Decline') |
|
| 128 | - ); |
|
| 129 | - break; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - $notification->addParsedAction($action); |
|
| 133 | - } |
|
| 134 | - return $notification; |
|
| 135 | - |
|
| 136 | - default: |
|
| 137 | - // Unknown subject => Unknown notification => throw |
|
| 138 | - throw new \InvalidArgumentException(); |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @param string $cloudId |
|
| 144 | - * @return array |
|
| 145 | - */ |
|
| 146 | - protected function createRemoteUser($cloudId) { |
|
| 147 | - $displayName = $cloudId; |
|
| 148 | - try { |
|
| 149 | - $resolvedId = $this->cloudIdManager->resolveCloudId($cloudId); |
|
| 150 | - $displayName = $this->getDisplayName($resolvedId); |
|
| 151 | - $user = $resolvedId->getUser(); |
|
| 152 | - $server = $resolvedId->getRemote(); |
|
| 153 | - } catch (HintException $e) { |
|
| 154 | - $user = $cloudId; |
|
| 155 | - $server = ''; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - return [ |
|
| 159 | - 'type' => 'user', |
|
| 160 | - 'id' => $user, |
|
| 161 | - 'name' => $displayName, |
|
| 162 | - 'server' => $server, |
|
| 163 | - ]; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Try to find the user in the contacts |
|
| 168 | - * |
|
| 169 | - * @param ICloudId $cloudId |
|
| 170 | - * @return string |
|
| 171 | - */ |
|
| 172 | - protected function getDisplayName(ICloudId $cloudId) { |
|
| 173 | - $server = $cloudId->getRemote(); |
|
| 174 | - $user = $cloudId->getUser(); |
|
| 175 | - if (strpos($server, 'http://') === 0) { |
|
| 176 | - $server = substr($server, strlen('http://')); |
|
| 177 | - } else if (strpos($server, 'https://') === 0) { |
|
| 178 | - $server = substr($server, strlen('https://')); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - try { |
|
| 182 | - return $this->getDisplayNameFromContact($cloudId->getId()); |
|
| 183 | - } catch (\OutOfBoundsException $e) { |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - try { |
|
| 187 | - $this->getDisplayNameFromContact($user . '@http://' . $server); |
|
| 188 | - } catch (\OutOfBoundsException $e) { |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - try { |
|
| 192 | - $this->getDisplayNameFromContact($user . '@https://' . $server); |
|
| 193 | - } catch (\OutOfBoundsException $e) { |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - return $cloudId->getId(); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Try to find the user in the contacts |
|
| 201 | - * |
|
| 202 | - * @param string $federatedCloudId |
|
| 203 | - * @return string |
|
| 204 | - * @throws \OutOfBoundsException when there is no contact for the id |
|
| 205 | - */ |
|
| 206 | - protected function getDisplayNameFromContact($federatedCloudId) { |
|
| 207 | - if (isset($this->federatedContacts[$federatedCloudId])) { |
|
| 208 | - if ($this->federatedContacts[$federatedCloudId] !== '') { |
|
| 209 | - return $this->federatedContacts[$federatedCloudId]; |
|
| 210 | - } else { |
|
| 211 | - throw new \OutOfBoundsException('No contact found for federated cloud id'); |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - $addressBookEntries = $this->contactsManager->search($federatedCloudId, ['CLOUD']); |
|
| 216 | - foreach ($addressBookEntries as $entry) { |
|
| 217 | - if (isset($entry['CLOUD'])) { |
|
| 218 | - foreach ($entry['CLOUD'] as $cloudID) { |
|
| 219 | - if ($cloudID === $federatedCloudId) { |
|
| 220 | - $this->federatedContacts[$federatedCloudId] = $entry['FN']; |
|
| 221 | - return $entry['FN']; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - $this->federatedContacts[$federatedCloudId] = ''; |
|
| 228 | - throw new \OutOfBoundsException('No contact found for federated cloud id'); |
|
| 229 | - } |
|
| 37 | + /** @var IFactory */ |
|
| 38 | + protected $factory; |
|
| 39 | + /** @var IManager */ |
|
| 40 | + protected $contactsManager; |
|
| 41 | + /** @var IURLGenerator */ |
|
| 42 | + protected $url; |
|
| 43 | + /** @var array */ |
|
| 44 | + protected $federatedContacts; |
|
| 45 | + /** @var ICloudIdManager */ |
|
| 46 | + protected $cloudIdManager; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @param IFactory $factory |
|
| 50 | + * @param IManager $contactsManager |
|
| 51 | + * @param IURLGenerator $url |
|
| 52 | + * @param ICloudIdManager $cloudIdManager |
|
| 53 | + */ |
|
| 54 | + public function __construct(IFactory $factory, IManager $contactsManager, IURLGenerator $url, ICloudIdManager $cloudIdManager) { |
|
| 55 | + $this->factory = $factory; |
|
| 56 | + $this->contactsManager = $contactsManager; |
|
| 57 | + $this->url = $url; |
|
| 58 | + $this->cloudIdManager = $cloudIdManager; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @param INotification $notification |
|
| 63 | + * @param string $languageCode The code of the language that should be used to prepare the notification |
|
| 64 | + * @return INotification |
|
| 65 | + * @throws \InvalidArgumentException |
|
| 66 | + */ |
|
| 67 | + public function prepare(INotification $notification, $languageCode) { |
|
| 68 | + if ($notification->getApp() !== 'files_sharing') { |
|
| 69 | + // Not my app => throw |
|
| 70 | + throw new \InvalidArgumentException(); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + // Read the language from the notification |
|
| 74 | + $l = $this->factory->get('files_sharing', $languageCode); |
|
| 75 | + |
|
| 76 | + switch ($notification->getSubject()) { |
|
| 77 | + // Deal with known subjects |
|
| 78 | + case 'remote_share': |
|
| 79 | + $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 80 | + |
|
| 81 | + $params = $notification->getSubjectParameters(); |
|
| 82 | + if ($params[0] !== $params[1] && $params[1] !== null) { |
|
| 83 | + $notification->setParsedSubject( |
|
| 84 | + $l->t('You received "%3$s" as a remote share from %1$s (on behalf of %2$s)', $params) |
|
| 85 | + ); |
|
| 86 | + $notification->setRichSubject( |
|
| 87 | + $l->t('You received {share} as a remote share from {user} (on behalf of {behalf})'), |
|
| 88 | + [ |
|
| 89 | + 'share' => [ |
|
| 90 | + 'type' => 'pending-federated-share', |
|
| 91 | + 'id' => $notification->getObjectId(), |
|
| 92 | + 'name' => $params[2], |
|
| 93 | + ], |
|
| 94 | + 'user' => $this->createRemoteUser($params[0]), |
|
| 95 | + 'behalf' => $this->createRemoteUser($params[1]), |
|
| 96 | + ] |
|
| 97 | + ); |
|
| 98 | + } else { |
|
| 99 | + $notification->setParsedSubject( |
|
| 100 | + $l->t('You received "%3$s" as a remote share from %1$s', $params) |
|
| 101 | + ); |
|
| 102 | + $notification->setRichSubject( |
|
| 103 | + $l->t('You received {share} as a remote share from {user}'), |
|
| 104 | + [ |
|
| 105 | + 'share' => [ |
|
| 106 | + 'type' => 'pending-federated-share', |
|
| 107 | + 'id' => $notification->getObjectId(), |
|
| 108 | + 'name' => $params[2], |
|
| 109 | + ], |
|
| 110 | + 'user' => $this->createRemoteUser($params[0]), |
|
| 111 | + ] |
|
| 112 | + ); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // Deal with the actions for a known subject |
|
| 116 | + foreach ($notification->getActions() as $action) { |
|
| 117 | + switch ($action->getLabel()) { |
|
| 118 | + case 'accept': |
|
| 119 | + $action->setParsedLabel( |
|
| 120 | + (string) $l->t('Accept') |
|
| 121 | + ) |
|
| 122 | + ->setPrimary(true); |
|
| 123 | + break; |
|
| 124 | + |
|
| 125 | + case 'decline': |
|
| 126 | + $action->setParsedLabel( |
|
| 127 | + (string) $l->t('Decline') |
|
| 128 | + ); |
|
| 129 | + break; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + $notification->addParsedAction($action); |
|
| 133 | + } |
|
| 134 | + return $notification; |
|
| 135 | + |
|
| 136 | + default: |
|
| 137 | + // Unknown subject => Unknown notification => throw |
|
| 138 | + throw new \InvalidArgumentException(); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @param string $cloudId |
|
| 144 | + * @return array |
|
| 145 | + */ |
|
| 146 | + protected function createRemoteUser($cloudId) { |
|
| 147 | + $displayName = $cloudId; |
|
| 148 | + try { |
|
| 149 | + $resolvedId = $this->cloudIdManager->resolveCloudId($cloudId); |
|
| 150 | + $displayName = $this->getDisplayName($resolvedId); |
|
| 151 | + $user = $resolvedId->getUser(); |
|
| 152 | + $server = $resolvedId->getRemote(); |
|
| 153 | + } catch (HintException $e) { |
|
| 154 | + $user = $cloudId; |
|
| 155 | + $server = ''; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + return [ |
|
| 159 | + 'type' => 'user', |
|
| 160 | + 'id' => $user, |
|
| 161 | + 'name' => $displayName, |
|
| 162 | + 'server' => $server, |
|
| 163 | + ]; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Try to find the user in the contacts |
|
| 168 | + * |
|
| 169 | + * @param ICloudId $cloudId |
|
| 170 | + * @return string |
|
| 171 | + */ |
|
| 172 | + protected function getDisplayName(ICloudId $cloudId) { |
|
| 173 | + $server = $cloudId->getRemote(); |
|
| 174 | + $user = $cloudId->getUser(); |
|
| 175 | + if (strpos($server, 'http://') === 0) { |
|
| 176 | + $server = substr($server, strlen('http://')); |
|
| 177 | + } else if (strpos($server, 'https://') === 0) { |
|
| 178 | + $server = substr($server, strlen('https://')); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + try { |
|
| 182 | + return $this->getDisplayNameFromContact($cloudId->getId()); |
|
| 183 | + } catch (\OutOfBoundsException $e) { |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + try { |
|
| 187 | + $this->getDisplayNameFromContact($user . '@http://' . $server); |
|
| 188 | + } catch (\OutOfBoundsException $e) { |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + try { |
|
| 192 | + $this->getDisplayNameFromContact($user . '@https://' . $server); |
|
| 193 | + } catch (\OutOfBoundsException $e) { |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + return $cloudId->getId(); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Try to find the user in the contacts |
|
| 201 | + * |
|
| 202 | + * @param string $federatedCloudId |
|
| 203 | + * @return string |
|
| 204 | + * @throws \OutOfBoundsException when there is no contact for the id |
|
| 205 | + */ |
|
| 206 | + protected function getDisplayNameFromContact($federatedCloudId) { |
|
| 207 | + if (isset($this->federatedContacts[$federatedCloudId])) { |
|
| 208 | + if ($this->federatedContacts[$federatedCloudId] !== '') { |
|
| 209 | + return $this->federatedContacts[$federatedCloudId]; |
|
| 210 | + } else { |
|
| 211 | + throw new \OutOfBoundsException('No contact found for federated cloud id'); |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + $addressBookEntries = $this->contactsManager->search($federatedCloudId, ['CLOUD']); |
|
| 216 | + foreach ($addressBookEntries as $entry) { |
|
| 217 | + if (isset($entry['CLOUD'])) { |
|
| 218 | + foreach ($entry['CLOUD'] as $cloudID) { |
|
| 219 | + if ($cloudID === $federatedCloudId) { |
|
| 220 | + $this->federatedContacts[$federatedCloudId] = $entry['FN']; |
|
| 221 | + return $entry['FN']; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + $this->federatedContacts[$federatedCloudId] = ''; |
|
| 228 | + throw new \OutOfBoundsException('No contact found for federated cloud id'); |
|
| 229 | + } |
|
| 230 | 230 | } |
@@ -33,30 +33,30 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class TokenHandler { |
| 35 | 35 | |
| 36 | - const TOKEN_LENGTH = 15; |
|
| 37 | - |
|
| 38 | - /** @var ISecureRandom */ |
|
| 39 | - private $secureRandom; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * TokenHandler constructor. |
|
| 43 | - * |
|
| 44 | - * @param ISecureRandom $secureRandom |
|
| 45 | - */ |
|
| 46 | - public function __construct(ISecureRandom $secureRandom) { |
|
| 47 | - $this->secureRandom = $secureRandom; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * generate to token used to authenticate federated shares |
|
| 52 | - * |
|
| 53 | - * @return string |
|
| 54 | - */ |
|
| 55 | - public function generateToken() { |
|
| 56 | - $token = $this->secureRandom->generate( |
|
| 57 | - self::TOKEN_LENGTH, |
|
| 58 | - ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
| 59 | - return $token; |
|
| 60 | - } |
|
| 36 | + const TOKEN_LENGTH = 15; |
|
| 37 | + |
|
| 38 | + /** @var ISecureRandom */ |
|
| 39 | + private $secureRandom; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * TokenHandler constructor. |
|
| 43 | + * |
|
| 44 | + * @param ISecureRandom $secureRandom |
|
| 45 | + */ |
|
| 46 | + public function __construct(ISecureRandom $secureRandom) { |
|
| 47 | + $this->secureRandom = $secureRandom; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * generate to token used to authenticate federated shares |
|
| 52 | + * |
|
| 53 | + * @return string |
|
| 54 | + */ |
|
| 55 | + public function generateToken() { |
|
| 56 | + $token = $this->secureRandom->generate( |
|
| 57 | + self::TOKEN_LENGTH, |
|
| 58 | + ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
| 59 | + return $token; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | } |
@@ -28,10 +28,10 @@ |
||
| 28 | 28 | <?php if((int)$trustedServer['status'] === TrustedServers::STATUS_OK) { ?> |
| 29 | 29 | <span class="status success"></span> |
| 30 | 30 | <?php |
| 31 | - } elseif( |
|
| 32 | - (int)$trustedServer['status'] === TrustedServers::STATUS_PENDING || |
|
| 33 | - (int)$trustedServer['status'] === TrustedServers::STATUS_ACCESS_REVOKED |
|
| 34 | - ) { ?> |
|
| 31 | + } elseif( |
|
| 32 | + (int)$trustedServer['status'] === TrustedServers::STATUS_PENDING || |
|
| 33 | + (int)$trustedServer['status'] === TrustedServers::STATUS_ACCESS_REVOKED |
|
| 34 | + ) { ?> |
|
| 35 | 35 | <span class="status indeterminate"></span> |
| 36 | 36 | <?php } else {?> |
| 37 | 37 | <span class="status error"></span> |
@@ -29,41 +29,41 @@ |
||
| 29 | 29 | |
| 30 | 30 | class Admin implements ISettings { |
| 31 | 31 | |
| 32 | - /** @var TrustedServers */ |
|
| 33 | - private $trustedServers; |
|
| 32 | + /** @var TrustedServers */ |
|
| 33 | + private $trustedServers; |
|
| 34 | 34 | |
| 35 | - public function __construct(TrustedServers $trustedServers) { |
|
| 36 | - $this->trustedServers = $trustedServers; |
|
| 37 | - } |
|
| 35 | + public function __construct(TrustedServers $trustedServers) { |
|
| 36 | + $this->trustedServers = $trustedServers; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @return TemplateResponse |
|
| 41 | - */ |
|
| 42 | - public function getForm() { |
|
| 43 | - $parameters = [ |
|
| 44 | - 'trustedServers' => $this->trustedServers->getServers(), |
|
| 45 | - 'autoAddServers' => $this->trustedServers->getAutoAddServers(), |
|
| 46 | - ]; |
|
| 39 | + /** |
|
| 40 | + * @return TemplateResponse |
|
| 41 | + */ |
|
| 42 | + public function getForm() { |
|
| 43 | + $parameters = [ |
|
| 44 | + 'trustedServers' => $this->trustedServers->getServers(), |
|
| 45 | + 'autoAddServers' => $this->trustedServers->getAutoAddServers(), |
|
| 46 | + ]; |
|
| 47 | 47 | |
| 48 | - return new TemplateResponse('federation', 'settings-admin', $parameters, ''); |
|
| 49 | - } |
|
| 48 | + return new TemplateResponse('federation', 'settings-admin', $parameters, ''); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @return string the section ID, e.g. 'sharing' |
|
| 53 | - */ |
|
| 54 | - public function getSection() { |
|
| 55 | - return 'sharing'; |
|
| 56 | - } |
|
| 51 | + /** |
|
| 52 | + * @return string the section ID, e.g. 'sharing' |
|
| 53 | + */ |
|
| 54 | + public function getSection() { |
|
| 55 | + return 'sharing'; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @return int whether the form should be rather on the top or bottom of |
|
| 60 | - * the admin section. The forms are arranged in ascending order of the |
|
| 61 | - * priority values. It is required to return a value between 0 and 100. |
|
| 62 | - * |
|
| 63 | - * E.g.: 70 |
|
| 64 | - */ |
|
| 65 | - public function getPriority() { |
|
| 66 | - return 30; |
|
| 67 | - } |
|
| 58 | + /** |
|
| 59 | + * @return int whether the form should be rather on the top or bottom of |
|
| 60 | + * the admin section. The forms are arranged in ascending order of the |
|
| 61 | + * priority values. It is required to return a value between 0 and 100. |
|
| 62 | + * |
|
| 63 | + * E.g.: 70 |
|
| 64 | + */ |
|
| 65 | + public function getPriority() { |
|
| 66 | + return 30; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | 69 | } |
@@ -27,25 +27,25 @@ |
||
| 27 | 27 | |
| 28 | 28 | class Hooks { |
| 29 | 29 | |
| 30 | - /** @var TrustedServers */ |
|
| 31 | - private $trustedServers; |
|
| 32 | - |
|
| 33 | - public function __construct(TrustedServers $trustedServers) { |
|
| 34 | - $this->trustedServers = $trustedServers; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * add servers to the list of trusted servers once a federated share was established |
|
| 39 | - * |
|
| 40 | - * @param array $params |
|
| 41 | - */ |
|
| 42 | - public function addServerHook($params) { |
|
| 43 | - if ( |
|
| 44 | - $this->trustedServers->getAutoAddServers() === true && |
|
| 45 | - $this->trustedServers->isTrustedServer($params['server']) === false |
|
| 46 | - ) { |
|
| 47 | - $this->trustedServers->addServer($params['server']); |
|
| 48 | - } |
|
| 49 | - } |
|
| 30 | + /** @var TrustedServers */ |
|
| 31 | + private $trustedServers; |
|
| 32 | + |
|
| 33 | + public function __construct(TrustedServers $trustedServers) { |
|
| 34 | + $this->trustedServers = $trustedServers; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * add servers to the list of trusted servers once a federated share was established |
|
| 39 | + * |
|
| 40 | + * @param array $params |
|
| 41 | + */ |
|
| 42 | + public function addServerHook($params) { |
|
| 43 | + if ( |
|
| 44 | + $this->trustedServers->getAutoAddServers() === true && |
|
| 45 | + $this->trustedServers->isTrustedServer($params['server']) === false |
|
| 46 | + ) { |
|
| 47 | + $this->trustedServers->addServer($params['server']); |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | } |
@@ -26,67 +26,67 @@ |
||
| 26 | 26 | |
| 27 | 27 | class PublicAuth implements BackendInterface { |
| 28 | 28 | |
| 29 | - /** @var string[] */ |
|
| 30 | - private $publicURLs; |
|
| 29 | + /** @var string[] */ |
|
| 30 | + private $publicURLs; |
|
| 31 | 31 | |
| 32 | - public function __construct() { |
|
| 33 | - $this->publicURLs = [ |
|
| 34 | - 'public-calendars', |
|
| 35 | - 'principals/system/public' |
|
| 36 | - ]; |
|
| 37 | - } |
|
| 32 | + public function __construct() { |
|
| 33 | + $this->publicURLs = [ |
|
| 34 | + 'public-calendars', |
|
| 35 | + 'principals/system/public' |
|
| 36 | + ]; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * When this method is called, the backend must check if authentication was |
|
| 41 | - * successful. |
|
| 42 | - * |
|
| 43 | - * The returned value must be one of the following |
|
| 44 | - * |
|
| 45 | - * [true, "principals/username"] |
|
| 46 | - * [false, "reason for failure"] |
|
| 47 | - * |
|
| 48 | - * If authentication was successful, it's expected that the authentication |
|
| 49 | - * backend returns a so-called principal url. |
|
| 50 | - * |
|
| 51 | - * Examples of a principal url: |
|
| 52 | - * |
|
| 53 | - * principals/admin |
|
| 54 | - * principals/user1 |
|
| 55 | - * principals/users/joe |
|
| 56 | - * principals/uid/123457 |
|
| 57 | - * |
|
| 58 | - * If you don't use WebDAV ACL (RFC3744) we recommend that you simply |
|
| 59 | - * return a string such as: |
|
| 60 | - * |
|
| 61 | - * principals/users/[username] |
|
| 62 | - * |
|
| 63 | - * @param RequestInterface $request |
|
| 64 | - * @param ResponseInterface $response |
|
| 65 | - * @return array |
|
| 66 | - */ |
|
| 67 | - function check(RequestInterface $request, ResponseInterface $response) { |
|
| 39 | + /** |
|
| 40 | + * When this method is called, the backend must check if authentication was |
|
| 41 | + * successful. |
|
| 42 | + * |
|
| 43 | + * The returned value must be one of the following |
|
| 44 | + * |
|
| 45 | + * [true, "principals/username"] |
|
| 46 | + * [false, "reason for failure"] |
|
| 47 | + * |
|
| 48 | + * If authentication was successful, it's expected that the authentication |
|
| 49 | + * backend returns a so-called principal url. |
|
| 50 | + * |
|
| 51 | + * Examples of a principal url: |
|
| 52 | + * |
|
| 53 | + * principals/admin |
|
| 54 | + * principals/user1 |
|
| 55 | + * principals/users/joe |
|
| 56 | + * principals/uid/123457 |
|
| 57 | + * |
|
| 58 | + * If you don't use WebDAV ACL (RFC3744) we recommend that you simply |
|
| 59 | + * return a string such as: |
|
| 60 | + * |
|
| 61 | + * principals/users/[username] |
|
| 62 | + * |
|
| 63 | + * @param RequestInterface $request |
|
| 64 | + * @param ResponseInterface $response |
|
| 65 | + * @return array |
|
| 66 | + */ |
|
| 67 | + function check(RequestInterface $request, ResponseInterface $response) { |
|
| 68 | 68 | |
| 69 | - if ($this->isRequestPublic($request)) { |
|
| 70 | - return [true, "principals/system/public"]; |
|
| 71 | - } |
|
| 72 | - return [false, "No public access to this resource."]; |
|
| 73 | - } |
|
| 69 | + if ($this->isRequestPublic($request)) { |
|
| 70 | + return [true, "principals/system/public"]; |
|
| 71 | + } |
|
| 72 | + return [false, "No public access to this resource."]; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @inheritdoc |
|
| 77 | - */ |
|
| 78 | - function challenge(RequestInterface $request, ResponseInterface $response) { |
|
| 79 | - } |
|
| 75 | + /** |
|
| 76 | + * @inheritdoc |
|
| 77 | + */ |
|
| 78 | + function challenge(RequestInterface $request, ResponseInterface $response) { |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @param RequestInterface $request |
|
| 83 | - * @return bool |
|
| 84 | - */ |
|
| 85 | - private function isRequestPublic(RequestInterface $request) { |
|
| 86 | - $url = $request->getPath(); |
|
| 87 | - $matchingUrls = array_filter($this->publicURLs, function ($publicUrl) use ($url) { |
|
| 88 | - return strpos($url, $publicUrl, 0) === 0; |
|
| 89 | - }); |
|
| 90 | - return !empty($matchingUrls); |
|
| 91 | - } |
|
| 81 | + /** |
|
| 82 | + * @param RequestInterface $request |
|
| 83 | + * @return bool |
|
| 84 | + */ |
|
| 85 | + private function isRequestPublic(RequestInterface $request) { |
|
| 86 | + $url = $request->getPath(); |
|
| 87 | + $matchingUrls = array_filter($this->publicURLs, function ($publicUrl) use ($url) { |
|
| 88 | + return strpos($url, $publicUrl, 0) === 0; |
|
| 89 | + }); |
|
| 90 | + return !empty($matchingUrls); |
|
| 91 | + } |
|
| 92 | 92 | } |
@@ -41,130 +41,130 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | class Invite implements XmlSerializable { |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * The list of users a calendar has been shared to. |
|
| 46 | - * |
|
| 47 | - * @var array |
|
| 48 | - */ |
|
| 49 | - protected $users; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * The organizer contains information about the person who shared the |
|
| 53 | - * object. |
|
| 54 | - * |
|
| 55 | - * @var array|null |
|
| 56 | - */ |
|
| 57 | - protected $organizer; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Creates the property. |
|
| 61 | - * |
|
| 62 | - * Users is an array. Each element of the array has the following |
|
| 63 | - * properties: |
|
| 64 | - * |
|
| 65 | - * * href - Often a mailto: address |
|
| 66 | - * * commonName - Optional, for example a first and lastname for a user. |
|
| 67 | - * * status - One of the SharingPlugin::STATUS_* constants. |
|
| 68 | - * * readOnly - true or false |
|
| 69 | - * * summary - Optional, description of the share |
|
| 70 | - * |
|
| 71 | - * The organizer key is optional to specify. It's only useful when a |
|
| 72 | - * 'sharee' requests the sharing information. |
|
| 73 | - * |
|
| 74 | - * The organizer may have the following properties: |
|
| 75 | - * * href - Often a mailto: address. |
|
| 76 | - * * commonName - Optional human-readable name. |
|
| 77 | - * * firstName - Optional first name. |
|
| 78 | - * * lastName - Optional last name. |
|
| 79 | - * |
|
| 80 | - * If you wonder why these two structures are so different, I guess a |
|
| 81 | - * valid answer is that the current spec is still a draft. |
|
| 82 | - * |
|
| 83 | - * @param array $users |
|
| 84 | - */ |
|
| 85 | - function __construct(array $users, array $organizer = null) { |
|
| 86 | - |
|
| 87 | - $this->users = $users; |
|
| 88 | - $this->organizer = $organizer; |
|
| 89 | - |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Returns the list of users, as it was passed to the constructor. |
|
| 94 | - * |
|
| 95 | - * @return array |
|
| 96 | - */ |
|
| 97 | - function getValue() { |
|
| 98 | - |
|
| 99 | - return $this->users; |
|
| 100 | - |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * The xmlSerialize metod is called during xml writing. |
|
| 105 | - * |
|
| 106 | - * Use the $writer argument to write its own xml serialization. |
|
| 107 | - * |
|
| 108 | - * An important note: do _not_ create a parent element. Any element |
|
| 109 | - * implementing XmlSerializble should only ever write what's considered |
|
| 110 | - * its 'inner xml'. |
|
| 111 | - * |
|
| 112 | - * The parent of the current element is responsible for writing a |
|
| 113 | - * containing element. |
|
| 114 | - * |
|
| 115 | - * This allows serializers to be re-used for different element names. |
|
| 116 | - * |
|
| 117 | - * If you are opening new elements, you must also close them again. |
|
| 118 | - * |
|
| 119 | - * @param Writer $writer |
|
| 120 | - * @return void |
|
| 121 | - */ |
|
| 122 | - function xmlSerialize(Writer $writer) { |
|
| 123 | - |
|
| 124 | - $cs = '{' . Plugin::NS_OWNCLOUD . '}'; |
|
| 125 | - |
|
| 126 | - if (!is_null($this->organizer)) { |
|
| 127 | - |
|
| 128 | - $writer->startElement($cs . 'organizer'); |
|
| 129 | - $writer->writeElement('{DAV:}href', $this->organizer['href']); |
|
| 130 | - |
|
| 131 | - if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
|
| 132 | - $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
| 133 | - } |
|
| 134 | - if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
|
| 135 | - $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
| 136 | - } |
|
| 137 | - if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
|
| 138 | - $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
| 139 | - } |
|
| 140 | - $writer->endElement(); // organizer |
|
| 141 | - |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - foreach ($this->users as $user) { |
|
| 145 | - |
|
| 146 | - $writer->startElement($cs . 'user'); |
|
| 147 | - $writer->writeElement('{DAV:}href', $user['href']); |
|
| 148 | - if (isset($user['commonName']) && $user['commonName']) { |
|
| 149 | - $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
| 150 | - } |
|
| 151 | - $writer->writeElement($cs . 'invite-accepted'); |
|
| 152 | - |
|
| 153 | - $writer->startElement($cs . 'access'); |
|
| 154 | - if ($user['readOnly']) { |
|
| 155 | - $writer->writeElement($cs . 'read'); |
|
| 156 | - } else { |
|
| 157 | - $writer->writeElement($cs . 'read-write'); |
|
| 158 | - } |
|
| 159 | - $writer->endElement(); // access |
|
| 160 | - |
|
| 161 | - if (isset($user['summary']) && $user['summary']) { |
|
| 162 | - $writer->writeElement($cs . 'summary', $user['summary']); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - $writer->endElement(); //user |
|
| 166 | - |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - } |
|
| 44 | + /** |
|
| 45 | + * The list of users a calendar has been shared to. |
|
| 46 | + * |
|
| 47 | + * @var array |
|
| 48 | + */ |
|
| 49 | + protected $users; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * The organizer contains information about the person who shared the |
|
| 53 | + * object. |
|
| 54 | + * |
|
| 55 | + * @var array|null |
|
| 56 | + */ |
|
| 57 | + protected $organizer; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Creates the property. |
|
| 61 | + * |
|
| 62 | + * Users is an array. Each element of the array has the following |
|
| 63 | + * properties: |
|
| 64 | + * |
|
| 65 | + * * href - Often a mailto: address |
|
| 66 | + * * commonName - Optional, for example a first and lastname for a user. |
|
| 67 | + * * status - One of the SharingPlugin::STATUS_* constants. |
|
| 68 | + * * readOnly - true or false |
|
| 69 | + * * summary - Optional, description of the share |
|
| 70 | + * |
|
| 71 | + * The organizer key is optional to specify. It's only useful when a |
|
| 72 | + * 'sharee' requests the sharing information. |
|
| 73 | + * |
|
| 74 | + * The organizer may have the following properties: |
|
| 75 | + * * href - Often a mailto: address. |
|
| 76 | + * * commonName - Optional human-readable name. |
|
| 77 | + * * firstName - Optional first name. |
|
| 78 | + * * lastName - Optional last name. |
|
| 79 | + * |
|
| 80 | + * If you wonder why these two structures are so different, I guess a |
|
| 81 | + * valid answer is that the current spec is still a draft. |
|
| 82 | + * |
|
| 83 | + * @param array $users |
|
| 84 | + */ |
|
| 85 | + function __construct(array $users, array $organizer = null) { |
|
| 86 | + |
|
| 87 | + $this->users = $users; |
|
| 88 | + $this->organizer = $organizer; |
|
| 89 | + |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Returns the list of users, as it was passed to the constructor. |
|
| 94 | + * |
|
| 95 | + * @return array |
|
| 96 | + */ |
|
| 97 | + function getValue() { |
|
| 98 | + |
|
| 99 | + return $this->users; |
|
| 100 | + |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * The xmlSerialize metod is called during xml writing. |
|
| 105 | + * |
|
| 106 | + * Use the $writer argument to write its own xml serialization. |
|
| 107 | + * |
|
| 108 | + * An important note: do _not_ create a parent element. Any element |
|
| 109 | + * implementing XmlSerializble should only ever write what's considered |
|
| 110 | + * its 'inner xml'. |
|
| 111 | + * |
|
| 112 | + * The parent of the current element is responsible for writing a |
|
| 113 | + * containing element. |
|
| 114 | + * |
|
| 115 | + * This allows serializers to be re-used for different element names. |
|
| 116 | + * |
|
| 117 | + * If you are opening new elements, you must also close them again. |
|
| 118 | + * |
|
| 119 | + * @param Writer $writer |
|
| 120 | + * @return void |
|
| 121 | + */ |
|
| 122 | + function xmlSerialize(Writer $writer) { |
|
| 123 | + |
|
| 124 | + $cs = '{' . Plugin::NS_OWNCLOUD . '}'; |
|
| 125 | + |
|
| 126 | + if (!is_null($this->organizer)) { |
|
| 127 | + |
|
| 128 | + $writer->startElement($cs . 'organizer'); |
|
| 129 | + $writer->writeElement('{DAV:}href', $this->organizer['href']); |
|
| 130 | + |
|
| 131 | + if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
|
| 132 | + $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
| 133 | + } |
|
| 134 | + if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
|
| 135 | + $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
| 136 | + } |
|
| 137 | + if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
|
| 138 | + $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
| 139 | + } |
|
| 140 | + $writer->endElement(); // organizer |
|
| 141 | + |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + foreach ($this->users as $user) { |
|
| 145 | + |
|
| 146 | + $writer->startElement($cs . 'user'); |
|
| 147 | + $writer->writeElement('{DAV:}href', $user['href']); |
|
| 148 | + if (isset($user['commonName']) && $user['commonName']) { |
|
| 149 | + $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
| 150 | + } |
|
| 151 | + $writer->writeElement($cs . 'invite-accepted'); |
|
| 152 | + |
|
| 153 | + $writer->startElement($cs . 'access'); |
|
| 154 | + if ($user['readOnly']) { |
|
| 155 | + $writer->writeElement($cs . 'read'); |
|
| 156 | + } else { |
|
| 157 | + $writer->writeElement($cs . 'read-write'); |
|
| 158 | + } |
|
| 159 | + $writer->endElement(); // access |
|
| 160 | + |
|
| 161 | + if (isset($user['summary']) && $user['summary']) { |
|
| 162 | + $writer->writeElement($cs . 'summary', $user['summary']); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + $writer->endElement(); //user |
|
| 166 | + |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + } |
|
| 170 | 170 | } |
@@ -28,48 +28,48 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | interface IShareable extends INode { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Updates the list of shares. |
|
| 33 | - * |
|
| 34 | - * The first array is a list of people that are to be added to the |
|
| 35 | - * resource. |
|
| 36 | - * |
|
| 37 | - * Every element in the add array has the following properties: |
|
| 38 | - * * href - A url. Usually a mailto: address |
|
| 39 | - * * commonName - Usually a first and last name, or false |
|
| 40 | - * * summary - A description of the share, can also be false |
|
| 41 | - * * readOnly - A boolean value |
|
| 42 | - * |
|
| 43 | - * Every element in the remove array is just the address string. |
|
| 44 | - * |
|
| 45 | - * @param array $add |
|
| 46 | - * @param array $remove |
|
| 47 | - * @return void |
|
| 48 | - */ |
|
| 49 | - function updateShares(array $add, array $remove); |
|
| 31 | + /** |
|
| 32 | + * Updates the list of shares. |
|
| 33 | + * |
|
| 34 | + * The first array is a list of people that are to be added to the |
|
| 35 | + * resource. |
|
| 36 | + * |
|
| 37 | + * Every element in the add array has the following properties: |
|
| 38 | + * * href - A url. Usually a mailto: address |
|
| 39 | + * * commonName - Usually a first and last name, or false |
|
| 40 | + * * summary - A description of the share, can also be false |
|
| 41 | + * * readOnly - A boolean value |
|
| 42 | + * |
|
| 43 | + * Every element in the remove array is just the address string. |
|
| 44 | + * |
|
| 45 | + * @param array $add |
|
| 46 | + * @param array $remove |
|
| 47 | + * @return void |
|
| 48 | + */ |
|
| 49 | + function updateShares(array $add, array $remove); |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Returns the list of people whom this resource is shared with. |
|
| 53 | - * |
|
| 54 | - * Every element in this array should have the following properties: |
|
| 55 | - * * href - Often a mailto: address |
|
| 56 | - * * commonName - Optional, for example a first + last name |
|
| 57 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 58 | - * * readOnly - boolean |
|
| 59 | - * * summary - Optional, a description for the share |
|
| 60 | - * |
|
| 61 | - * @return array |
|
| 62 | - */ |
|
| 63 | - function getShares(); |
|
| 51 | + /** |
|
| 52 | + * Returns the list of people whom this resource is shared with. |
|
| 53 | + * |
|
| 54 | + * Every element in this array should have the following properties: |
|
| 55 | + * * href - Often a mailto: address |
|
| 56 | + * * commonName - Optional, for example a first + last name |
|
| 57 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 58 | + * * readOnly - boolean |
|
| 59 | + * * summary - Optional, a description for the share |
|
| 60 | + * |
|
| 61 | + * @return array |
|
| 62 | + */ |
|
| 63 | + function getShares(); |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @return int |
|
| 67 | - */ |
|
| 68 | - public function getResourceId(); |
|
| 65 | + /** |
|
| 66 | + * @return int |
|
| 67 | + */ |
|
| 68 | + public function getResourceId(); |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @return string |
|
| 72 | - */ |
|
| 73 | - public function getOwner(); |
|
| 70 | + /** |
|
| 71 | + * @return string |
|
| 72 | + */ |
|
| 73 | + public function getOwner(); |
|
| 74 | 74 | |
| 75 | 75 | } |
| 76 | 76 | \ No newline at end of file |
@@ -43,85 +43,85 @@ |
||
| 43 | 43 | */ |
| 44 | 44 | class EntityTypeCollection extends RootCollection { |
| 45 | 45 | |
| 46 | - /** @var ILogger */ |
|
| 47 | - protected $logger; |
|
| 46 | + /** @var ILogger */ |
|
| 47 | + protected $logger; |
|
| 48 | 48 | |
| 49 | - /** @var IUserManager */ |
|
| 50 | - protected $userManager; |
|
| 49 | + /** @var IUserManager */ |
|
| 50 | + protected $userManager; |
|
| 51 | 51 | |
| 52 | - /** @var \Closure */ |
|
| 53 | - protected $childExistsFunction; |
|
| 52 | + /** @var \Closure */ |
|
| 53 | + protected $childExistsFunction; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @param string $name |
|
| 57 | - * @param ICommentsManager $commentsManager |
|
| 58 | - * @param IUserManager $userManager |
|
| 59 | - * @param IUserSession $userSession |
|
| 60 | - * @param ILogger $logger |
|
| 61 | - * @param \Closure $childExistsFunction |
|
| 62 | - */ |
|
| 63 | - public function __construct( |
|
| 64 | - $name, |
|
| 65 | - ICommentsManager $commentsManager, |
|
| 66 | - IUserManager $userManager, |
|
| 67 | - IUserSession $userSession, |
|
| 68 | - ILogger $logger, |
|
| 69 | - \Closure $childExistsFunction |
|
| 70 | - ) { |
|
| 71 | - $name = trim($name); |
|
| 72 | - if(empty($name) || !is_string($name)) { |
|
| 73 | - throw new \InvalidArgumentException('"name" parameter must be non-empty string'); |
|
| 74 | - } |
|
| 75 | - $this->name = $name; |
|
| 76 | - $this->commentsManager = $commentsManager; |
|
| 77 | - $this->logger = $logger; |
|
| 78 | - $this->userManager = $userManager; |
|
| 79 | - $this->userSession = $userSession; |
|
| 80 | - $this->childExistsFunction = $childExistsFunction; |
|
| 81 | - } |
|
| 55 | + /** |
|
| 56 | + * @param string $name |
|
| 57 | + * @param ICommentsManager $commentsManager |
|
| 58 | + * @param IUserManager $userManager |
|
| 59 | + * @param IUserSession $userSession |
|
| 60 | + * @param ILogger $logger |
|
| 61 | + * @param \Closure $childExistsFunction |
|
| 62 | + */ |
|
| 63 | + public function __construct( |
|
| 64 | + $name, |
|
| 65 | + ICommentsManager $commentsManager, |
|
| 66 | + IUserManager $userManager, |
|
| 67 | + IUserSession $userSession, |
|
| 68 | + ILogger $logger, |
|
| 69 | + \Closure $childExistsFunction |
|
| 70 | + ) { |
|
| 71 | + $name = trim($name); |
|
| 72 | + if(empty($name) || !is_string($name)) { |
|
| 73 | + throw new \InvalidArgumentException('"name" parameter must be non-empty string'); |
|
| 74 | + } |
|
| 75 | + $this->name = $name; |
|
| 76 | + $this->commentsManager = $commentsManager; |
|
| 77 | + $this->logger = $logger; |
|
| 78 | + $this->userManager = $userManager; |
|
| 79 | + $this->userSession = $userSession; |
|
| 80 | + $this->childExistsFunction = $childExistsFunction; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Returns a specific child node, referenced by its name |
|
| 85 | - * |
|
| 86 | - * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
| 87 | - * exist. |
|
| 88 | - * |
|
| 89 | - * @param string $name |
|
| 90 | - * @return \Sabre\DAV\INode |
|
| 91 | - * @throws NotFound |
|
| 92 | - */ |
|
| 93 | - function getChild($name) { |
|
| 94 | - if(!$this->childExists($name)) { |
|
| 95 | - throw new NotFound('Entity does not exist or is not available'); |
|
| 96 | - } |
|
| 97 | - return new EntityCollection( |
|
| 98 | - $name, |
|
| 99 | - $this->name, |
|
| 100 | - $this->commentsManager, |
|
| 101 | - $this->userManager, |
|
| 102 | - $this->userSession, |
|
| 103 | - $this->logger |
|
| 104 | - ); |
|
| 105 | - } |
|
| 83 | + /** |
|
| 84 | + * Returns a specific child node, referenced by its name |
|
| 85 | + * |
|
| 86 | + * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
| 87 | + * exist. |
|
| 88 | + * |
|
| 89 | + * @param string $name |
|
| 90 | + * @return \Sabre\DAV\INode |
|
| 91 | + * @throws NotFound |
|
| 92 | + */ |
|
| 93 | + function getChild($name) { |
|
| 94 | + if(!$this->childExists($name)) { |
|
| 95 | + throw new NotFound('Entity does not exist or is not available'); |
|
| 96 | + } |
|
| 97 | + return new EntityCollection( |
|
| 98 | + $name, |
|
| 99 | + $this->name, |
|
| 100 | + $this->commentsManager, |
|
| 101 | + $this->userManager, |
|
| 102 | + $this->userSession, |
|
| 103 | + $this->logger |
|
| 104 | + ); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Returns an array with all the child nodes |
|
| 109 | - * |
|
| 110 | - * @return \Sabre\DAV\INode[] |
|
| 111 | - * @throws MethodNotAllowed |
|
| 112 | - */ |
|
| 113 | - function getChildren() { |
|
| 114 | - throw new MethodNotAllowed('No permission to list folder contents'); |
|
| 115 | - } |
|
| 107 | + /** |
|
| 108 | + * Returns an array with all the child nodes |
|
| 109 | + * |
|
| 110 | + * @return \Sabre\DAV\INode[] |
|
| 111 | + * @throws MethodNotAllowed |
|
| 112 | + */ |
|
| 113 | + function getChildren() { |
|
| 114 | + throw new MethodNotAllowed('No permission to list folder contents'); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Checks if a child-node with the specified name exists |
|
| 119 | - * |
|
| 120 | - * @param string $name |
|
| 121 | - * @return bool |
|
| 122 | - */ |
|
| 123 | - function childExists($name) { |
|
| 124 | - return call_user_func($this->childExistsFunction, $name); |
|
| 125 | - } |
|
| 117 | + /** |
|
| 118 | + * Checks if a child-node with the specified name exists |
|
| 119 | + * |
|
| 120 | + * @param string $name |
|
| 121 | + * @return bool |
|
| 122 | + */ |
|
| 123 | + function childExists($name) { |
|
| 124 | + return call_user_func($this->childExistsFunction, $name); |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | 127 | } |