@@ -43,165 +43,165 @@ |
||
| 43 | 43 | * User global storages controller |
| 44 | 44 | */ |
| 45 | 45 | class UserGlobalStoragesController extends StoragesController { |
| 46 | - /** |
|
| 47 | - * @var IUserSession |
|
| 48 | - */ |
|
| 49 | - private $userSession; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Creates a new user global storages controller. |
|
| 53 | - * |
|
| 54 | - * @param string $AppName application name |
|
| 55 | - * @param IRequest $request request object |
|
| 56 | - * @param IL10N $l10n l10n service |
|
| 57 | - * @param UserGlobalStoragesService $userGlobalStoragesService storage service |
|
| 58 | - * @param IUserSession $userSession |
|
| 59 | - */ |
|
| 60 | - public function __construct( |
|
| 61 | - $AppName, |
|
| 62 | - IRequest $request, |
|
| 63 | - IL10N $l10n, |
|
| 64 | - UserGlobalStoragesService $userGlobalStoragesService, |
|
| 65 | - IUserSession $userSession, |
|
| 66 | - ILogger $logger |
|
| 67 | - ) { |
|
| 68 | - parent::__construct( |
|
| 69 | - $AppName, |
|
| 70 | - $request, |
|
| 71 | - $l10n, |
|
| 72 | - $userGlobalStoragesService, |
|
| 73 | - $logger |
|
| 74 | - ); |
|
| 75 | - $this->userSession = $userSession; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Get all storage entries |
|
| 80 | - * |
|
| 81 | - * @return DataResponse |
|
| 82 | - * |
|
| 83 | - * @NoAdminRequired |
|
| 84 | - */ |
|
| 85 | - public function index() { |
|
| 86 | - $storages = $this->service->getUniqueStorages(); |
|
| 87 | - |
|
| 88 | - // remove configuration data, this must be kept private |
|
| 89 | - foreach ($storages as $storage) { |
|
| 90 | - $this->sanitizeStorage($storage); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - return new DataResponse( |
|
| 94 | - $storages, |
|
| 95 | - Http::STATUS_OK |
|
| 96 | - ); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - protected function manipulateStorageConfig(StorageConfig $storage) { |
|
| 100 | - /** @var AuthMechanism */ |
|
| 101 | - $authMechanism = $storage->getAuthMechanism(); |
|
| 102 | - $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
| 103 | - /** @var Backend */ |
|
| 104 | - $backend = $storage->getBackend(); |
|
| 105 | - $backend->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Get an external storage entry. |
|
| 110 | - * |
|
| 111 | - * @param int $id storage id |
|
| 112 | - * @param bool $testOnly whether to storage should only test the connection or do more things |
|
| 113 | - * @return DataResponse |
|
| 114 | - * |
|
| 115 | - * @NoAdminRequired |
|
| 116 | - */ |
|
| 117 | - public function show($id, $testOnly = true) { |
|
| 118 | - try { |
|
| 119 | - $storage = $this->service->getStorage($id); |
|
| 120 | - |
|
| 121 | - $this->updateStorageStatus($storage, $testOnly); |
|
| 122 | - } catch (NotFoundException $e) { |
|
| 123 | - return new DataResponse( |
|
| 124 | - [ |
|
| 125 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
| 126 | - ], |
|
| 127 | - Http::STATUS_NOT_FOUND |
|
| 128 | - ); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - $this->sanitizeStorage($storage); |
|
| 132 | - |
|
| 133 | - return new DataResponse( |
|
| 134 | - $storage, |
|
| 135 | - Http::STATUS_OK |
|
| 136 | - ); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Update an external storage entry. |
|
| 141 | - * Only allows setting user provided backend fields |
|
| 142 | - * |
|
| 143 | - * @param int $id storage id |
|
| 144 | - * @param array $backendOptions backend-specific options |
|
| 145 | - * @param bool $testOnly whether to storage should only test the connection or do more things |
|
| 146 | - * |
|
| 147 | - * @return DataResponse |
|
| 148 | - * |
|
| 149 | - * @NoAdminRequired |
|
| 150 | - */ |
|
| 151 | - public function update( |
|
| 152 | - $id, |
|
| 153 | - $backendOptions, |
|
| 154 | - $testOnly = true |
|
| 155 | - ) { |
|
| 156 | - try { |
|
| 157 | - $storage = $this->service->getStorage($id); |
|
| 158 | - $authMechanism = $storage->getAuthMechanism(); |
|
| 159 | - if ($authMechanism instanceof IUserProvided) { |
|
| 160 | - $authMechanism->saveBackendOptions($this->userSession->getUser(), $id, $backendOptions); |
|
| 161 | - $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
| 162 | - } else { |
|
| 163 | - return new DataResponse( |
|
| 164 | - [ |
|
| 165 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" is not user editable', array($id)) |
|
| 166 | - ], |
|
| 167 | - Http::STATUS_FORBIDDEN |
|
| 168 | - ); |
|
| 169 | - } |
|
| 170 | - } catch (NotFoundException $e) { |
|
| 171 | - return new DataResponse( |
|
| 172 | - [ |
|
| 173 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
| 174 | - ], |
|
| 175 | - Http::STATUS_NOT_FOUND |
|
| 176 | - ); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - $this->updateStorageStatus($storage, $testOnly); |
|
| 180 | - $this->sanitizeStorage($storage); |
|
| 181 | - |
|
| 182 | - return new DataResponse( |
|
| 183 | - $storage, |
|
| 184 | - Http::STATUS_OK |
|
| 185 | - ); |
|
| 186 | - |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Remove sensitive data from a StorageConfig before returning it to the user |
|
| 191 | - * |
|
| 192 | - * @param StorageConfig $storage |
|
| 193 | - */ |
|
| 194 | - protected function sanitizeStorage(StorageConfig $storage) { |
|
| 195 | - $storage->setBackendOptions([]); |
|
| 196 | - $storage->setMountOptions([]); |
|
| 197 | - |
|
| 198 | - if ($storage->getAuthMechanism() instanceof IUserProvided) { |
|
| 199 | - try { |
|
| 200 | - $storage->getAuthMechanism()->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
| 201 | - } catch (InsufficientDataForMeaningfulAnswerException $e) { |
|
| 202 | - // not configured yet |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 46 | + /** |
|
| 47 | + * @var IUserSession |
|
| 48 | + */ |
|
| 49 | + private $userSession; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Creates a new user global storages controller. |
|
| 53 | + * |
|
| 54 | + * @param string $AppName application name |
|
| 55 | + * @param IRequest $request request object |
|
| 56 | + * @param IL10N $l10n l10n service |
|
| 57 | + * @param UserGlobalStoragesService $userGlobalStoragesService storage service |
|
| 58 | + * @param IUserSession $userSession |
|
| 59 | + */ |
|
| 60 | + public function __construct( |
|
| 61 | + $AppName, |
|
| 62 | + IRequest $request, |
|
| 63 | + IL10N $l10n, |
|
| 64 | + UserGlobalStoragesService $userGlobalStoragesService, |
|
| 65 | + IUserSession $userSession, |
|
| 66 | + ILogger $logger |
|
| 67 | + ) { |
|
| 68 | + parent::__construct( |
|
| 69 | + $AppName, |
|
| 70 | + $request, |
|
| 71 | + $l10n, |
|
| 72 | + $userGlobalStoragesService, |
|
| 73 | + $logger |
|
| 74 | + ); |
|
| 75 | + $this->userSession = $userSession; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Get all storage entries |
|
| 80 | + * |
|
| 81 | + * @return DataResponse |
|
| 82 | + * |
|
| 83 | + * @NoAdminRequired |
|
| 84 | + */ |
|
| 85 | + public function index() { |
|
| 86 | + $storages = $this->service->getUniqueStorages(); |
|
| 87 | + |
|
| 88 | + // remove configuration data, this must be kept private |
|
| 89 | + foreach ($storages as $storage) { |
|
| 90 | + $this->sanitizeStorage($storage); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + return new DataResponse( |
|
| 94 | + $storages, |
|
| 95 | + Http::STATUS_OK |
|
| 96 | + ); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + protected function manipulateStorageConfig(StorageConfig $storage) { |
|
| 100 | + /** @var AuthMechanism */ |
|
| 101 | + $authMechanism = $storage->getAuthMechanism(); |
|
| 102 | + $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
| 103 | + /** @var Backend */ |
|
| 104 | + $backend = $storage->getBackend(); |
|
| 105 | + $backend->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Get an external storage entry. |
|
| 110 | + * |
|
| 111 | + * @param int $id storage id |
|
| 112 | + * @param bool $testOnly whether to storage should only test the connection or do more things |
|
| 113 | + * @return DataResponse |
|
| 114 | + * |
|
| 115 | + * @NoAdminRequired |
|
| 116 | + */ |
|
| 117 | + public function show($id, $testOnly = true) { |
|
| 118 | + try { |
|
| 119 | + $storage = $this->service->getStorage($id); |
|
| 120 | + |
|
| 121 | + $this->updateStorageStatus($storage, $testOnly); |
|
| 122 | + } catch (NotFoundException $e) { |
|
| 123 | + return new DataResponse( |
|
| 124 | + [ |
|
| 125 | + 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
| 126 | + ], |
|
| 127 | + Http::STATUS_NOT_FOUND |
|
| 128 | + ); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + $this->sanitizeStorage($storage); |
|
| 132 | + |
|
| 133 | + return new DataResponse( |
|
| 134 | + $storage, |
|
| 135 | + Http::STATUS_OK |
|
| 136 | + ); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Update an external storage entry. |
|
| 141 | + * Only allows setting user provided backend fields |
|
| 142 | + * |
|
| 143 | + * @param int $id storage id |
|
| 144 | + * @param array $backendOptions backend-specific options |
|
| 145 | + * @param bool $testOnly whether to storage should only test the connection or do more things |
|
| 146 | + * |
|
| 147 | + * @return DataResponse |
|
| 148 | + * |
|
| 149 | + * @NoAdminRequired |
|
| 150 | + */ |
|
| 151 | + public function update( |
|
| 152 | + $id, |
|
| 153 | + $backendOptions, |
|
| 154 | + $testOnly = true |
|
| 155 | + ) { |
|
| 156 | + try { |
|
| 157 | + $storage = $this->service->getStorage($id); |
|
| 158 | + $authMechanism = $storage->getAuthMechanism(); |
|
| 159 | + if ($authMechanism instanceof IUserProvided) { |
|
| 160 | + $authMechanism->saveBackendOptions($this->userSession->getUser(), $id, $backendOptions); |
|
| 161 | + $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
| 162 | + } else { |
|
| 163 | + return new DataResponse( |
|
| 164 | + [ |
|
| 165 | + 'message' => (string)$this->l10n->t('Storage with ID "%d" is not user editable', array($id)) |
|
| 166 | + ], |
|
| 167 | + Http::STATUS_FORBIDDEN |
|
| 168 | + ); |
|
| 169 | + } |
|
| 170 | + } catch (NotFoundException $e) { |
|
| 171 | + return new DataResponse( |
|
| 172 | + [ |
|
| 173 | + 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
| 174 | + ], |
|
| 175 | + Http::STATUS_NOT_FOUND |
|
| 176 | + ); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + $this->updateStorageStatus($storage, $testOnly); |
|
| 180 | + $this->sanitizeStorage($storage); |
|
| 181 | + |
|
| 182 | + return new DataResponse( |
|
| 183 | + $storage, |
|
| 184 | + Http::STATUS_OK |
|
| 185 | + ); |
|
| 186 | + |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Remove sensitive data from a StorageConfig before returning it to the user |
|
| 191 | + * |
|
| 192 | + * @param StorageConfig $storage |
|
| 193 | + */ |
|
| 194 | + protected function sanitizeStorage(StorageConfig $storage) { |
|
| 195 | + $storage->setBackendOptions([]); |
|
| 196 | + $storage->setMountOptions([]); |
|
| 197 | + |
|
| 198 | + if ($storage->getAuthMechanism() instanceof IUserProvided) { |
|
| 199 | + try { |
|
| 200 | + $storage->getAuthMechanism()->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
| 201 | + } catch (InsufficientDataForMeaningfulAnswerException $e) { |
|
| 202 | + // not configured yet |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | 207 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | } catch (NotFoundException $e) { |
| 123 | 123 | return new DataResponse( |
| 124 | 124 | [ |
| 125 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
| 125 | + 'message' => (string) $this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
| 126 | 126 | ], |
| 127 | 127 | Http::STATUS_NOT_FOUND |
| 128 | 128 | ); |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | } else { |
| 163 | 163 | return new DataResponse( |
| 164 | 164 | [ |
| 165 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" is not user editable', array($id)) |
|
| 165 | + 'message' => (string) $this->l10n->t('Storage with ID "%d" is not user editable', array($id)) |
|
| 166 | 166 | ], |
| 167 | 167 | Http::STATUS_FORBIDDEN |
| 168 | 168 | ); |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | } catch (NotFoundException $e) { |
| 171 | 171 | return new DataResponse( |
| 172 | 172 | [ |
| 173 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
| 173 | + 'message' => (string) $this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
| 174 | 174 | ], |
| 175 | 175 | Http::STATUS_NOT_FOUND |
| 176 | 176 | ); |
@@ -276,10 +276,10 @@ discard block |
||
| 276 | 276 | * publish activity if a file/folder was shared by mail |
| 277 | 277 | * |
| 278 | 278 | * @param $subject |
| 279 | - * @param $parameters |
|
| 280 | - * @param $affectedUser |
|
| 279 | + * @param string[] $parameters |
|
| 280 | + * @param string $affectedUser |
|
| 281 | 281 | * @param $fileId |
| 282 | - * @param $filePath |
|
| 282 | + * @param string $filePath |
|
| 283 | 283 | */ |
| 284 | 284 | protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) { |
| 285 | 285 | $event = $this->activityManager->generateEvent(); |
@@ -557,6 +557,7 @@ discard block |
||
| 557 | 557 | * @param string $uidOwner |
| 558 | 558 | * @param int $permissions |
| 559 | 559 | * @param string $token |
| 560 | + * @param string $password |
|
| 560 | 561 | * @return int |
| 561 | 562 | */ |
| 562 | 563 | protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password) { |
@@ -950,7 +951,7 @@ discard block |
||
| 950 | 951 | /** |
| 951 | 952 | * get database row of a give share |
| 952 | 953 | * |
| 953 | - * @param $id |
|
| 954 | + * @param integer $id |
|
| 954 | 955 | * @return array |
| 955 | 956 | * @throws ShareNotFound |
| 956 | 957 | */ |
@@ -210,10 +210,10 @@ discard block |
||
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | $passwordPolicy = $this->getPasswordPolicy(); |
| 213 | - $passwordCharset = ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS; |
|
| 213 | + $passwordCharset = ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS; |
|
| 214 | 214 | $passwordLength = 8; |
| 215 | 215 | if (!empty($passwordPolicy)) { |
| 216 | - $passwordLength = (int)$passwordPolicy['minLength'] > 0 ? (int)$passwordPolicy['minLength'] : $passwordLength; |
|
| 216 | + $passwordLength = (int) $passwordPolicy['minLength'] > 0 ? (int) $passwordPolicy['minLength'] : $passwordLength; |
|
| 217 | 217 | $passwordCharset .= $passwordPolicy['enforceSpecialCharacters'] ? ISecureRandom::CHAR_SYMBOLS : ''; |
| 218 | 218 | } |
| 219 | 219 | |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | $text = $this->l->t('%s shared »%s« with you.', [$initiatorDisplayName, $filename]); |
| 405 | 405 | |
| 406 | 406 | $emailTemplate->addBodyText( |
| 407 | - htmlspecialchars($text . ' ' . $this->l->t('Click the button below to open it.')), |
|
| 407 | + htmlspecialchars($text.' '.$this->l->t('Click the button below to open it.')), |
|
| 408 | 408 | $text |
| 409 | 409 | ); |
| 410 | 410 | $emailTemplate->addBodyButton( |
@@ -428,9 +428,9 @@ discard block |
||
| 428 | 428 | // The "Reply-To" is set to the sharer if an mail address is configured |
| 429 | 429 | // also the default footer contains a "Do not reply" which needs to be adjusted. |
| 430 | 430 | $initiatorEmail = $initiatorUser->getEMailAddress(); |
| 431 | - if($initiatorEmail !== null) { |
|
| 431 | + if ($initiatorEmail !== null) { |
|
| 432 | 432 | $message->setReplyTo([$initiatorEmail => $initiatorDisplayName]); |
| 433 | - $emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : '')); |
|
| 433 | + $emailTemplate->addFooter($instanceName.($this->defaults->getSlogan() !== '' ? ' - '.$this->defaults->getSlogan() : '')); |
|
| 434 | 434 | } else { |
| 435 | 435 | $emailTemplate->addFooter(); |
| 436 | 436 | } |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
| 492 | 492 | if ($initiatorEmailAddress !== null) { |
| 493 | 493 | $message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]); |
| 494 | - $emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan()); |
|
| 494 | + $emailTemplate->addFooter($instanceName.' - '.$this->defaults->getSlogan()); |
|
| 495 | 495 | } else { |
| 496 | 496 | $emailTemplate->addFooter(); |
| 497 | 497 | } |
@@ -586,7 +586,7 @@ discard block |
||
| 586 | 586 | ->orderBy('id'); |
| 587 | 587 | |
| 588 | 588 | $cursor = $qb->execute(); |
| 589 | - while($data = $cursor->fetch()) { |
|
| 589 | + while ($data = $cursor->fetch()) { |
|
| 590 | 590 | $children[] = $this->createShareObject($data); |
| 591 | 591 | } |
| 592 | 592 | $cursor->closeCursor(); |
@@ -630,7 +630,7 @@ discard block |
||
| 630 | 630 | $qb->execute(); |
| 631 | 631 | $id = $qb->getLastInsertId(); |
| 632 | 632 | |
| 633 | - return (int)$id; |
|
| 633 | + return (int) $id; |
|
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | /** |
@@ -647,7 +647,7 @@ discard block |
||
| 647 | 647 | // a real password was given |
| 648 | 648 | $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; |
| 649 | 649 | |
| 650 | - if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
| 650 | + if ($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
| 651 | 651 | $this->sendPassword($share, $plainTextPassword); |
| 652 | 652 | } |
| 653 | 653 | /* |
@@ -740,7 +740,7 @@ discard block |
||
| 740 | 740 | |
| 741 | 741 | $cursor = $qb->execute(); |
| 742 | 742 | $shares = []; |
| 743 | - while($data = $cursor->fetch()) { |
|
| 743 | + while ($data = $cursor->fetch()) { |
|
| 744 | 744 | $shares[] = $this->createShareObject($data); |
| 745 | 745 | } |
| 746 | 746 | $cursor->closeCursor(); |
@@ -792,7 +792,7 @@ discard block |
||
| 792 | 792 | ->execute(); |
| 793 | 793 | |
| 794 | 794 | $shares = []; |
| 795 | - while($data = $cursor->fetch()) { |
|
| 795 | + while ($data = $cursor->fetch()) { |
|
| 796 | 796 | $shares[] = $this->createShareObject($data); |
| 797 | 797 | } |
| 798 | 798 | $cursor->closeCursor(); |
@@ -831,7 +831,7 @@ discard block |
||
| 831 | 831 | |
| 832 | 832 | $cursor = $qb->execute(); |
| 833 | 833 | |
| 834 | - while($data = $cursor->fetch()) { |
|
| 834 | + while ($data = $cursor->fetch()) { |
|
| 835 | 835 | $shares[] = $this->createShareObject($data); |
| 836 | 836 | } |
| 837 | 837 | $cursor->closeCursor(); |
@@ -894,15 +894,15 @@ discard block |
||
| 894 | 894 | protected function createShareObject($data) { |
| 895 | 895 | |
| 896 | 896 | $share = new Share($this->rootFolder, $this->userManager); |
| 897 | - $share->setId((int)$data['id']) |
|
| 898 | - ->setShareType((int)$data['share_type']) |
|
| 899 | - ->setPermissions((int)$data['permissions']) |
|
| 897 | + $share->setId((int) $data['id']) |
|
| 898 | + ->setShareType((int) $data['share_type']) |
|
| 899 | + ->setPermissions((int) $data['permissions']) |
|
| 900 | 900 | ->setTarget($data['file_target']) |
| 901 | - ->setMailSend((bool)$data['mail_send']) |
|
| 901 | + ->setMailSend((bool) $data['mail_send']) |
|
| 902 | 902 | ->setToken($data['token']); |
| 903 | 903 | |
| 904 | 904 | $shareTime = new \DateTime(); |
| 905 | - $shareTime->setTimestamp((int)$data['stime']); |
|
| 905 | + $shareTime->setTimestamp((int) $data['stime']); |
|
| 906 | 906 | $share->setShareTime($shareTime); |
| 907 | 907 | $share->setSharedWith($data['share_with']); |
| 908 | 908 | $share->setPassword($data['password']); |
@@ -913,7 +913,7 @@ discard block |
||
| 913 | 913 | } else { |
| 914 | 914 | //OLD SHARE |
| 915 | 915 | $share->setSharedBy($data['uid_owner']); |
| 916 | - $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
| 916 | + $path = $this->getNode($share->getSharedBy(), (int) $data['file_source']); |
|
| 917 | 917 | |
| 918 | 918 | $owner = $path->getOwner(); |
| 919 | 919 | $share->setShareOwner($owner->getUID()); |
@@ -926,7 +926,7 @@ discard block |
||
| 926 | 926 | } |
| 927 | 927 | } |
| 928 | 928 | |
| 929 | - $share->setNodeId((int)$data['file_source']); |
|
| 929 | + $share->setNodeId((int) $data['file_source']); |
|
| 930 | 930 | $share->setNodeType($data['item_type']); |
| 931 | 931 | |
| 932 | 932 | $share->setProviderId($this->identifier()); |
@@ -1043,7 +1043,7 @@ discard block |
||
| 1043 | 1043 | ); |
| 1044 | 1044 | } |
| 1045 | 1045 | |
| 1046 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
| 1046 | + $qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
| 1047 | 1047 | $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
| 1048 | 1048 | |
| 1049 | 1049 | $qb->orderBy('id'); |
@@ -53,1036 +53,1036 @@ |
||
| 53 | 53 | */ |
| 54 | 54 | class ShareByMailProvider implements IShareProvider { |
| 55 | 55 | |
| 56 | - /** @var IDBConnection */ |
|
| 57 | - private $dbConnection; |
|
| 58 | - |
|
| 59 | - /** @var ILogger */ |
|
| 60 | - private $logger; |
|
| 61 | - |
|
| 62 | - /** @var ISecureRandom */ |
|
| 63 | - private $secureRandom; |
|
| 64 | - |
|
| 65 | - /** @var IUserManager */ |
|
| 66 | - private $userManager; |
|
| 67 | - |
|
| 68 | - /** @var IRootFolder */ |
|
| 69 | - private $rootFolder; |
|
| 70 | - |
|
| 71 | - /** @var IL10N */ |
|
| 72 | - private $l; |
|
| 73 | - |
|
| 74 | - /** @var IMailer */ |
|
| 75 | - private $mailer; |
|
| 76 | - |
|
| 77 | - /** @var IURLGenerator */ |
|
| 78 | - private $urlGenerator; |
|
| 79 | - |
|
| 80 | - /** @var IManager */ |
|
| 81 | - private $activityManager; |
|
| 82 | - |
|
| 83 | - /** @var SettingsManager */ |
|
| 84 | - private $settingsManager; |
|
| 85 | - |
|
| 86 | - /** @var Defaults */ |
|
| 87 | - private $defaults; |
|
| 88 | - |
|
| 89 | - /** @var IHasher */ |
|
| 90 | - private $hasher; |
|
| 91 | - |
|
| 92 | - /** @var CapabilitiesManager */ |
|
| 93 | - private $capabilitiesManager; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Return the identifier of this provider. |
|
| 97 | - * |
|
| 98 | - * @return string Containing only [a-zA-Z0-9] |
|
| 99 | - */ |
|
| 100 | - public function identifier() { |
|
| 101 | - return 'ocMailShare'; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * DefaultShareProvider constructor. |
|
| 106 | - * |
|
| 107 | - * @param IDBConnection $connection |
|
| 108 | - * @param ISecureRandom $secureRandom |
|
| 109 | - * @param IUserManager $userManager |
|
| 110 | - * @param IRootFolder $rootFolder |
|
| 111 | - * @param IL10N $l |
|
| 112 | - * @param ILogger $logger |
|
| 113 | - * @param IMailer $mailer |
|
| 114 | - * @param IURLGenerator $urlGenerator |
|
| 115 | - * @param IManager $activityManager |
|
| 116 | - * @param SettingsManager $settingsManager |
|
| 117 | - * @param Defaults $defaults |
|
| 118 | - * @param IHasher $hasher |
|
| 119 | - * @param CapabilitiesManager $capabilitiesManager |
|
| 120 | - */ |
|
| 121 | - public function __construct( |
|
| 122 | - IDBConnection $connection, |
|
| 123 | - ISecureRandom $secureRandom, |
|
| 124 | - IUserManager $userManager, |
|
| 125 | - IRootFolder $rootFolder, |
|
| 126 | - IL10N $l, |
|
| 127 | - ILogger $logger, |
|
| 128 | - IMailer $mailer, |
|
| 129 | - IURLGenerator $urlGenerator, |
|
| 130 | - IManager $activityManager, |
|
| 131 | - SettingsManager $settingsManager, |
|
| 132 | - Defaults $defaults, |
|
| 133 | - IHasher $hasher, |
|
| 134 | - CapabilitiesManager $capabilitiesManager |
|
| 135 | - ) { |
|
| 136 | - $this->dbConnection = $connection; |
|
| 137 | - $this->secureRandom = $secureRandom; |
|
| 138 | - $this->userManager = $userManager; |
|
| 139 | - $this->rootFolder = $rootFolder; |
|
| 140 | - $this->l = $l; |
|
| 141 | - $this->logger = $logger; |
|
| 142 | - $this->mailer = $mailer; |
|
| 143 | - $this->urlGenerator = $urlGenerator; |
|
| 144 | - $this->activityManager = $activityManager; |
|
| 145 | - $this->settingsManager = $settingsManager; |
|
| 146 | - $this->defaults = $defaults; |
|
| 147 | - $this->hasher = $hasher; |
|
| 148 | - $this->capabilitiesManager = $capabilitiesManager; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Share a path |
|
| 153 | - * |
|
| 154 | - * @param IShare $share |
|
| 155 | - * @return IShare The share object |
|
| 156 | - * @throws ShareNotFound |
|
| 157 | - * @throws \Exception |
|
| 158 | - */ |
|
| 159 | - public function create(IShare $share) { |
|
| 160 | - |
|
| 161 | - $shareWith = $share->getSharedWith(); |
|
| 162 | - /* |
|
| 56 | + /** @var IDBConnection */ |
|
| 57 | + private $dbConnection; |
|
| 58 | + |
|
| 59 | + /** @var ILogger */ |
|
| 60 | + private $logger; |
|
| 61 | + |
|
| 62 | + /** @var ISecureRandom */ |
|
| 63 | + private $secureRandom; |
|
| 64 | + |
|
| 65 | + /** @var IUserManager */ |
|
| 66 | + private $userManager; |
|
| 67 | + |
|
| 68 | + /** @var IRootFolder */ |
|
| 69 | + private $rootFolder; |
|
| 70 | + |
|
| 71 | + /** @var IL10N */ |
|
| 72 | + private $l; |
|
| 73 | + |
|
| 74 | + /** @var IMailer */ |
|
| 75 | + private $mailer; |
|
| 76 | + |
|
| 77 | + /** @var IURLGenerator */ |
|
| 78 | + private $urlGenerator; |
|
| 79 | + |
|
| 80 | + /** @var IManager */ |
|
| 81 | + private $activityManager; |
|
| 82 | + |
|
| 83 | + /** @var SettingsManager */ |
|
| 84 | + private $settingsManager; |
|
| 85 | + |
|
| 86 | + /** @var Defaults */ |
|
| 87 | + private $defaults; |
|
| 88 | + |
|
| 89 | + /** @var IHasher */ |
|
| 90 | + private $hasher; |
|
| 91 | + |
|
| 92 | + /** @var CapabilitiesManager */ |
|
| 93 | + private $capabilitiesManager; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Return the identifier of this provider. |
|
| 97 | + * |
|
| 98 | + * @return string Containing only [a-zA-Z0-9] |
|
| 99 | + */ |
|
| 100 | + public function identifier() { |
|
| 101 | + return 'ocMailShare'; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * DefaultShareProvider constructor. |
|
| 106 | + * |
|
| 107 | + * @param IDBConnection $connection |
|
| 108 | + * @param ISecureRandom $secureRandom |
|
| 109 | + * @param IUserManager $userManager |
|
| 110 | + * @param IRootFolder $rootFolder |
|
| 111 | + * @param IL10N $l |
|
| 112 | + * @param ILogger $logger |
|
| 113 | + * @param IMailer $mailer |
|
| 114 | + * @param IURLGenerator $urlGenerator |
|
| 115 | + * @param IManager $activityManager |
|
| 116 | + * @param SettingsManager $settingsManager |
|
| 117 | + * @param Defaults $defaults |
|
| 118 | + * @param IHasher $hasher |
|
| 119 | + * @param CapabilitiesManager $capabilitiesManager |
|
| 120 | + */ |
|
| 121 | + public function __construct( |
|
| 122 | + IDBConnection $connection, |
|
| 123 | + ISecureRandom $secureRandom, |
|
| 124 | + IUserManager $userManager, |
|
| 125 | + IRootFolder $rootFolder, |
|
| 126 | + IL10N $l, |
|
| 127 | + ILogger $logger, |
|
| 128 | + IMailer $mailer, |
|
| 129 | + IURLGenerator $urlGenerator, |
|
| 130 | + IManager $activityManager, |
|
| 131 | + SettingsManager $settingsManager, |
|
| 132 | + Defaults $defaults, |
|
| 133 | + IHasher $hasher, |
|
| 134 | + CapabilitiesManager $capabilitiesManager |
|
| 135 | + ) { |
|
| 136 | + $this->dbConnection = $connection; |
|
| 137 | + $this->secureRandom = $secureRandom; |
|
| 138 | + $this->userManager = $userManager; |
|
| 139 | + $this->rootFolder = $rootFolder; |
|
| 140 | + $this->l = $l; |
|
| 141 | + $this->logger = $logger; |
|
| 142 | + $this->mailer = $mailer; |
|
| 143 | + $this->urlGenerator = $urlGenerator; |
|
| 144 | + $this->activityManager = $activityManager; |
|
| 145 | + $this->settingsManager = $settingsManager; |
|
| 146 | + $this->defaults = $defaults; |
|
| 147 | + $this->hasher = $hasher; |
|
| 148 | + $this->capabilitiesManager = $capabilitiesManager; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Share a path |
|
| 153 | + * |
|
| 154 | + * @param IShare $share |
|
| 155 | + * @return IShare The share object |
|
| 156 | + * @throws ShareNotFound |
|
| 157 | + * @throws \Exception |
|
| 158 | + */ |
|
| 159 | + public function create(IShare $share) { |
|
| 160 | + |
|
| 161 | + $shareWith = $share->getSharedWith(); |
|
| 162 | + /* |
|
| 163 | 163 | * Check if file is not already shared with the remote user |
| 164 | 164 | */ |
| 165 | - $alreadyShared = $this->getSharedWith($shareWith, \OCP\Share::SHARE_TYPE_EMAIL, $share->getNode(), 1, 0); |
|
| 166 | - if (!empty($alreadyShared)) { |
|
| 167 | - $message = 'Sharing %s failed, this item is already shared with %s'; |
|
| 168 | - $message_t = $this->l->t('Sharing %s failed, this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
| 169 | - $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
| 170 | - throw new \Exception($message_t); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - // if the admin enforces a password for all mail shares we create a |
|
| 174 | - // random password and send it to the recipient |
|
| 175 | - $password = ''; |
|
| 176 | - $passwordEnforced = $this->settingsManager->enforcePasswordProtection(); |
|
| 177 | - if ($passwordEnforced) { |
|
| 178 | - $password = $this->autoGeneratePassword($share); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $shareId = $this->createMailShare($share); |
|
| 182 | - $send = $this->sendPassword($share, $password); |
|
| 183 | - if ($passwordEnforced && $send === false) { |
|
| 184 | - $this->sendPasswordToOwner($share, $password); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - $this->createShareActivity($share); |
|
| 188 | - $data = $this->getRawShare($shareId); |
|
| 189 | - |
|
| 190 | - return $this->createShareObject($data); |
|
| 191 | - |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * auto generate password in case of password enforcement on mail shares |
|
| 196 | - * |
|
| 197 | - * @param IShare $share |
|
| 198 | - * @return string |
|
| 199 | - * @throws \Exception |
|
| 200 | - */ |
|
| 201 | - protected function autoGeneratePassword($share) { |
|
| 202 | - $initiatorUser = $this->userManager->get($share->getSharedBy()); |
|
| 203 | - $initiatorEMailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
|
| 204 | - $allowPasswordByMail = $this->settingsManager->sendPasswordByMail(); |
|
| 205 | - |
|
| 206 | - if ($initiatorEMailAddress === null && !$allowPasswordByMail) { |
|
| 207 | - throw new \Exception( |
|
| 208 | - $this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.") |
|
| 209 | - ); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - $passwordPolicy = $this->getPasswordPolicy(); |
|
| 213 | - $passwordCharset = ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS; |
|
| 214 | - $passwordLength = 8; |
|
| 215 | - if (!empty($passwordPolicy)) { |
|
| 216 | - $passwordLength = (int)$passwordPolicy['minLength'] > 0 ? (int)$passwordPolicy['minLength'] : $passwordLength; |
|
| 217 | - $passwordCharset .= $passwordPolicy['enforceSpecialCharacters'] ? ISecureRandom::CHAR_SYMBOLS : ''; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - $password = $this->secureRandom->generate($passwordLength, $passwordCharset); |
|
| 221 | - |
|
| 222 | - $share->setPassword($this->hasher->hash($password)); |
|
| 223 | - |
|
| 224 | - return $password; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * get password policy |
|
| 229 | - * |
|
| 230 | - * @return array |
|
| 231 | - */ |
|
| 232 | - protected function getPasswordPolicy() { |
|
| 233 | - $capabilities = $this->capabilitiesManager->getCapabilities(); |
|
| 234 | - if (isset($capabilities['password_policy'])) { |
|
| 235 | - return $capabilities['password_policy']; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - return []; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * create activity if a file/folder was shared by mail |
|
| 243 | - * |
|
| 244 | - * @param IShare $share |
|
| 245 | - */ |
|
| 246 | - protected function createShareActivity(IShare $share) { |
|
| 247 | - |
|
| 248 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
| 249 | - |
|
| 250 | - $this->publishActivity( |
|
| 251 | - Activity::SUBJECT_SHARED_EMAIL_SELF, |
|
| 252 | - [$userFolder->getRelativePath($share->getNode()->getPath()), $share->getSharedWith()], |
|
| 253 | - $share->getSharedBy(), |
|
| 254 | - $share->getNode()->getId(), |
|
| 255 | - $userFolder->getRelativePath($share->getNode()->getPath()) |
|
| 256 | - ); |
|
| 257 | - |
|
| 258 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 259 | - $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
| 260 | - $fileId = $share->getNode()->getId(); |
|
| 261 | - $nodes = $ownerFolder->getById($fileId); |
|
| 262 | - $ownerPath = $nodes[0]->getPath(); |
|
| 263 | - $this->publishActivity( |
|
| 264 | - Activity::SUBJECT_SHARED_EMAIL_BY, |
|
| 265 | - [$ownerFolder->getRelativePath($ownerPath), $share->getSharedWith(), $share->getSharedBy()], |
|
| 266 | - $share->getShareOwner(), |
|
| 267 | - $fileId, |
|
| 268 | - $ownerFolder->getRelativePath($ownerPath) |
|
| 269 | - ); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * create activity if a file/folder was shared by mail |
|
| 276 | - * |
|
| 277 | - * @param IShare $share |
|
| 278 | - * @param string $sharedWith |
|
| 279 | - * @param bool $sendToSelf |
|
| 280 | - */ |
|
| 281 | - protected function createPasswordSendActivity(IShare $share, $sharedWith, $sendToSelf) { |
|
| 282 | - |
|
| 283 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
| 284 | - |
|
| 285 | - if ($sendToSelf) { |
|
| 286 | - $this->publishActivity( |
|
| 287 | - Activity::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF, |
|
| 288 | - [$userFolder->getRelativePath($share->getNode()->getPath())], |
|
| 289 | - $share->getSharedBy(), |
|
| 290 | - $share->getNode()->getId(), |
|
| 291 | - $userFolder->getRelativePath($share->getNode()->getPath()) |
|
| 292 | - ); |
|
| 293 | - } else { |
|
| 294 | - $this->publishActivity( |
|
| 295 | - Activity::SUBJECT_SHARED_EMAIL_PASSWORD_SEND, |
|
| 296 | - [$userFolder->getRelativePath($share->getNode()->getPath()), $sharedWith], |
|
| 297 | - $share->getSharedBy(), |
|
| 298 | - $share->getNode()->getId(), |
|
| 299 | - $userFolder->getRelativePath($share->getNode()->getPath()) |
|
| 300 | - ); |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * publish activity if a file/folder was shared by mail |
|
| 307 | - * |
|
| 308 | - * @param $subject |
|
| 309 | - * @param $parameters |
|
| 310 | - * @param $affectedUser |
|
| 311 | - * @param $fileId |
|
| 312 | - * @param $filePath |
|
| 313 | - */ |
|
| 314 | - protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) { |
|
| 315 | - $event = $this->activityManager->generateEvent(); |
|
| 316 | - $event->setApp('sharebymail') |
|
| 317 | - ->setType('shared') |
|
| 318 | - ->setSubject($subject, $parameters) |
|
| 319 | - ->setAffectedUser($affectedUser) |
|
| 320 | - ->setObject('files', $fileId, $filePath); |
|
| 321 | - $this->activityManager->publish($event); |
|
| 322 | - |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * @param IShare $share |
|
| 327 | - * @return int |
|
| 328 | - * @throws \Exception |
|
| 329 | - */ |
|
| 330 | - protected function createMailShare(IShare $share) { |
|
| 331 | - $share->setToken($this->generateToken()); |
|
| 332 | - $shareId = $this->addShareToDB( |
|
| 333 | - $share->getNodeId(), |
|
| 334 | - $share->getNodeType(), |
|
| 335 | - $share->getSharedWith(), |
|
| 336 | - $share->getSharedBy(), |
|
| 337 | - $share->getShareOwner(), |
|
| 338 | - $share->getPermissions(), |
|
| 339 | - $share->getToken(), |
|
| 340 | - $share->getPassword() |
|
| 341 | - ); |
|
| 342 | - |
|
| 343 | - try { |
|
| 344 | - $link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', |
|
| 345 | - ['token' => $share->getToken()]); |
|
| 346 | - $this->sendMailNotification( |
|
| 347 | - $share->getNode()->getName(), |
|
| 348 | - $link, |
|
| 349 | - $share->getSharedBy(), |
|
| 350 | - $share->getSharedWith(), |
|
| 351 | - $share->getExpirationDate() |
|
| 352 | - ); |
|
| 353 | - } catch (HintException $hintException) { |
|
| 354 | - $this->logger->logException($hintException, [ |
|
| 355 | - 'message' => 'Failed to send share by mail.', |
|
| 356 | - 'level' => ILogger::ERROR, |
|
| 357 | - 'app' => 'sharebymail', |
|
| 358 | - ]); |
|
| 359 | - $this->removeShareFromTable($shareId); |
|
| 360 | - throw $hintException; |
|
| 361 | - } catch (\Exception $e) { |
|
| 362 | - $this->logger->logException($e, [ |
|
| 363 | - 'message' => 'Failed to send share by mail.', |
|
| 364 | - 'level' => ILogger::ERROR, |
|
| 365 | - 'app' => 'sharebymail', |
|
| 366 | - ]); |
|
| 367 | - $this->removeShareFromTable($shareId); |
|
| 368 | - throw new HintException('Failed to send share by mail', |
|
| 369 | - $this->l->t('Failed to send share by email')); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - return $shareId; |
|
| 373 | - |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * @param string $filename |
|
| 378 | - * @param string $link |
|
| 379 | - * @param string $initiator |
|
| 380 | - * @param string $shareWith |
|
| 381 | - * @param \DateTime|null $expiration |
|
| 382 | - * @throws \Exception If mail couldn't be sent |
|
| 383 | - */ |
|
| 384 | - protected function sendMailNotification($filename, |
|
| 385 | - $link, |
|
| 386 | - $initiator, |
|
| 387 | - $shareWith, |
|
| 388 | - \DateTime $expiration = null) { |
|
| 389 | - $initiatorUser = $this->userManager->get($initiator); |
|
| 390 | - $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
| 391 | - $message = $this->mailer->createMessage(); |
|
| 392 | - |
|
| 393 | - $emailTemplate = $this->mailer->createEMailTemplate('sharebymail.RecipientNotification', [ |
|
| 394 | - 'filename' => $filename, |
|
| 395 | - 'link' => $link, |
|
| 396 | - 'initiator' => $initiatorDisplayName, |
|
| 397 | - 'expiration' => $expiration, |
|
| 398 | - 'shareWith' => $shareWith, |
|
| 399 | - ]); |
|
| 400 | - |
|
| 401 | - $emailTemplate->setSubject($this->l->t('%s shared »%s« with you', array($initiatorDisplayName, $filename))); |
|
| 402 | - $emailTemplate->addHeader(); |
|
| 403 | - $emailTemplate->addHeading($this->l->t('%s shared »%s« with you', [$initiatorDisplayName, $filename]), false); |
|
| 404 | - $text = $this->l->t('%s shared »%s« with you.', [$initiatorDisplayName, $filename]); |
|
| 405 | - |
|
| 406 | - $emailTemplate->addBodyText( |
|
| 407 | - htmlspecialchars($text . ' ' . $this->l->t('Click the button below to open it.')), |
|
| 408 | - $text |
|
| 409 | - ); |
|
| 410 | - $emailTemplate->addBodyButton( |
|
| 411 | - $this->l->t('Open »%s«', [$filename]), |
|
| 412 | - $link |
|
| 413 | - ); |
|
| 414 | - |
|
| 415 | - $message->setTo([$shareWith]); |
|
| 416 | - |
|
| 417 | - // The "From" contains the sharers name |
|
| 418 | - $instanceName = $this->defaults->getName(); |
|
| 419 | - $senderName = $this->l->t( |
|
| 420 | - '%s via %s', |
|
| 421 | - [ |
|
| 422 | - $initiatorDisplayName, |
|
| 423 | - $instanceName |
|
| 424 | - ] |
|
| 425 | - ); |
|
| 426 | - $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
| 427 | - |
|
| 428 | - // The "Reply-To" is set to the sharer if an mail address is configured |
|
| 429 | - // also the default footer contains a "Do not reply" which needs to be adjusted. |
|
| 430 | - $initiatorEmail = $initiatorUser->getEMailAddress(); |
|
| 431 | - if($initiatorEmail !== null) { |
|
| 432 | - $message->setReplyTo([$initiatorEmail => $initiatorDisplayName]); |
|
| 433 | - $emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : '')); |
|
| 434 | - } else { |
|
| 435 | - $emailTemplate->addFooter(); |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - $message->useTemplate($emailTemplate); |
|
| 439 | - $this->mailer->send($message); |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * send password to recipient of a mail share |
|
| 444 | - * |
|
| 445 | - * @param IShare $share |
|
| 446 | - * @param string $password |
|
| 447 | - * @return bool |
|
| 448 | - */ |
|
| 449 | - protected function sendPassword(IShare $share, $password) { |
|
| 450 | - |
|
| 451 | - $filename = $share->getNode()->getName(); |
|
| 452 | - $initiator = $share->getSharedBy(); |
|
| 453 | - $shareWith = $share->getSharedWith(); |
|
| 454 | - |
|
| 455 | - if ($password === '' || $this->settingsManager->sendPasswordByMail() === false) { |
|
| 456 | - return false; |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - $initiatorUser = $this->userManager->get($initiator); |
|
| 460 | - $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
| 461 | - $initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
|
| 462 | - |
|
| 463 | - $plainBodyPart = $this->l->t("%s shared »%s« with you.\nYou should have already received a separate mail with a link to access it.\n", [$initiatorDisplayName, $filename]); |
|
| 464 | - $htmlBodyPart = $this->l->t('%s shared »%s« with you. You should have already received a separate mail with a link to access it.', [$initiatorDisplayName, $filename]); |
|
| 465 | - |
|
| 466 | - $message = $this->mailer->createMessage(); |
|
| 467 | - |
|
| 468 | - $emailTemplate = $this->mailer->createEMailTemplate('sharebymail.RecipientPasswordNotification', [ |
|
| 469 | - 'filename' => $filename, |
|
| 470 | - 'password' => $password, |
|
| 471 | - 'initiator' => $initiatorDisplayName, |
|
| 472 | - 'initiatorEmail' => $initiatorEmailAddress, |
|
| 473 | - 'shareWith' => $shareWith, |
|
| 474 | - ]); |
|
| 475 | - |
|
| 476 | - $emailTemplate->setSubject($this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName])); |
|
| 477 | - $emailTemplate->addHeader(); |
|
| 478 | - $emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename]), false); |
|
| 479 | - $emailTemplate->addBodyText(htmlspecialchars($htmlBodyPart), $plainBodyPart); |
|
| 480 | - $emailTemplate->addBodyText($this->l->t('It is protected with the following password: %s', [$password])); |
|
| 481 | - |
|
| 482 | - // The "From" contains the sharers name |
|
| 483 | - $instanceName = $this->defaults->getName(); |
|
| 484 | - $senderName = $this->l->t( |
|
| 485 | - '%s via %s', |
|
| 486 | - [ |
|
| 487 | - $initiatorDisplayName, |
|
| 488 | - $instanceName |
|
| 489 | - ] |
|
| 490 | - ); |
|
| 491 | - $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
| 492 | - if ($initiatorEmailAddress !== null) { |
|
| 493 | - $message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]); |
|
| 494 | - $emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan()); |
|
| 495 | - } else { |
|
| 496 | - $emailTemplate->addFooter(); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - $message->setTo([$shareWith]); |
|
| 500 | - $message->useTemplate($emailTemplate); |
|
| 501 | - $this->mailer->send($message); |
|
| 502 | - |
|
| 503 | - $this->createPasswordSendActivity($share, $shareWith, false); |
|
| 504 | - |
|
| 505 | - return true; |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * send auto generated password to the owner. This happens if the admin enforces |
|
| 510 | - * a password for mail shares and forbid to send the password by mail to the recipient |
|
| 511 | - * |
|
| 512 | - * @param IShare $share |
|
| 513 | - * @param string $password |
|
| 514 | - * @return bool |
|
| 515 | - * @throws \Exception |
|
| 516 | - */ |
|
| 517 | - protected function sendPasswordToOwner(IShare $share, $password) { |
|
| 518 | - |
|
| 519 | - $filename = $share->getNode()->getName(); |
|
| 520 | - $initiator = $this->userManager->get($share->getSharedBy()); |
|
| 521 | - $initiatorEMailAddress = ($initiator instanceof IUser) ? $initiator->getEMailAddress() : null; |
|
| 522 | - $initiatorDisplayName = ($initiator instanceof IUser) ? $initiator->getDisplayName() : $share->getSharedBy(); |
|
| 523 | - $shareWith = $share->getSharedWith(); |
|
| 524 | - |
|
| 525 | - if ($initiatorEMailAddress === null) { |
|
| 526 | - throw new \Exception( |
|
| 527 | - $this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.") |
|
| 528 | - ); |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - $bodyPart = $this->l->t("You just shared »%s« with %s. The share was already send to the recipient. Due to the security policies defined by the administrator of %s each share needs to be protected by password and it is not allowed to send the password directly to the recipient. Therefore you need to forward the password manually to the recipient.", [$filename, $shareWith, $this->defaults->getName()]); |
|
| 532 | - |
|
| 533 | - $message = $this->mailer->createMessage(); |
|
| 534 | - $emailTemplate = $this->mailer->createEMailTemplate('sharebymail.OwnerPasswordNotification', [ |
|
| 535 | - 'filename' => $filename, |
|
| 536 | - 'password' => $password, |
|
| 537 | - 'initiator' => $initiatorDisplayName, |
|
| 538 | - 'initiatorEmail' => $initiatorEMailAddress, |
|
| 539 | - 'shareWith' => $shareWith, |
|
| 540 | - ]); |
|
| 541 | - |
|
| 542 | - $emailTemplate->setSubject($this->l->t('Password to access »%s« shared with %s', [$filename, $shareWith])); |
|
| 543 | - $emailTemplate->addHeader(); |
|
| 544 | - $emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename]), false); |
|
| 545 | - $emailTemplate->addBodyText($bodyPart); |
|
| 546 | - $emailTemplate->addBodyText($this->l->t('This is the password: %s', [$password])); |
|
| 547 | - $emailTemplate->addBodyText($this->l->t('You can choose a different password at any time in the share dialog.')); |
|
| 548 | - $emailTemplate->addFooter(); |
|
| 549 | - |
|
| 550 | - if ($initiatorEMailAddress) { |
|
| 551 | - $message->setFrom([$initiatorEMailAddress => $initiatorDisplayName]); |
|
| 552 | - } |
|
| 553 | - $message->setTo([$initiatorEMailAddress => $initiatorDisplayName]); |
|
| 554 | - $message->useTemplate($emailTemplate); |
|
| 555 | - $this->mailer->send($message); |
|
| 556 | - |
|
| 557 | - $this->createPasswordSendActivity($share, $shareWith, true); |
|
| 558 | - |
|
| 559 | - return true; |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - /** |
|
| 563 | - * generate share token |
|
| 564 | - * |
|
| 565 | - * @return string |
|
| 566 | - */ |
|
| 567 | - protected function generateToken($size = 15) { |
|
| 568 | - $token = $this->secureRandom->generate($size, ISecureRandom::CHAR_HUMAN_READABLE); |
|
| 569 | - return $token; |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * Get all children of this share |
|
| 574 | - * |
|
| 575 | - * @param IShare $parent |
|
| 576 | - * @return IShare[] |
|
| 577 | - */ |
|
| 578 | - public function getChildren(IShare $parent) { |
|
| 579 | - $children = []; |
|
| 580 | - |
|
| 581 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 582 | - $qb->select('*') |
|
| 583 | - ->from('share') |
|
| 584 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
| 585 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 586 | - ->orderBy('id'); |
|
| 587 | - |
|
| 588 | - $cursor = $qb->execute(); |
|
| 589 | - while($data = $cursor->fetch()) { |
|
| 590 | - $children[] = $this->createShareObject($data); |
|
| 591 | - } |
|
| 592 | - $cursor->closeCursor(); |
|
| 593 | - |
|
| 594 | - return $children; |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * add share to the database and return the ID |
|
| 599 | - * |
|
| 600 | - * @param int $itemSource |
|
| 601 | - * @param string $itemType |
|
| 602 | - * @param string $shareWith |
|
| 603 | - * @param string $sharedBy |
|
| 604 | - * @param string $uidOwner |
|
| 605 | - * @param int $permissions |
|
| 606 | - * @param string $token |
|
| 607 | - * @return int |
|
| 608 | - */ |
|
| 609 | - protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password) { |
|
| 610 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 611 | - $qb->insert('share') |
|
| 612 | - ->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
| 613 | - ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
| 614 | - ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
| 615 | - ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
| 616 | - ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
| 617 | - ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
| 618 | - ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
| 619 | - ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
| 620 | - ->setValue('token', $qb->createNamedParameter($token)) |
|
| 621 | - ->setValue('password', $qb->createNamedParameter($password)) |
|
| 622 | - ->setValue('stime', $qb->createNamedParameter(time())); |
|
| 623 | - |
|
| 624 | - /* |
|
| 165 | + $alreadyShared = $this->getSharedWith($shareWith, \OCP\Share::SHARE_TYPE_EMAIL, $share->getNode(), 1, 0); |
|
| 166 | + if (!empty($alreadyShared)) { |
|
| 167 | + $message = 'Sharing %s failed, this item is already shared with %s'; |
|
| 168 | + $message_t = $this->l->t('Sharing %s failed, this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
| 169 | + $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
| 170 | + throw new \Exception($message_t); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + // if the admin enforces a password for all mail shares we create a |
|
| 174 | + // random password and send it to the recipient |
|
| 175 | + $password = ''; |
|
| 176 | + $passwordEnforced = $this->settingsManager->enforcePasswordProtection(); |
|
| 177 | + if ($passwordEnforced) { |
|
| 178 | + $password = $this->autoGeneratePassword($share); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $shareId = $this->createMailShare($share); |
|
| 182 | + $send = $this->sendPassword($share, $password); |
|
| 183 | + if ($passwordEnforced && $send === false) { |
|
| 184 | + $this->sendPasswordToOwner($share, $password); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + $this->createShareActivity($share); |
|
| 188 | + $data = $this->getRawShare($shareId); |
|
| 189 | + |
|
| 190 | + return $this->createShareObject($data); |
|
| 191 | + |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * auto generate password in case of password enforcement on mail shares |
|
| 196 | + * |
|
| 197 | + * @param IShare $share |
|
| 198 | + * @return string |
|
| 199 | + * @throws \Exception |
|
| 200 | + */ |
|
| 201 | + protected function autoGeneratePassword($share) { |
|
| 202 | + $initiatorUser = $this->userManager->get($share->getSharedBy()); |
|
| 203 | + $initiatorEMailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
|
| 204 | + $allowPasswordByMail = $this->settingsManager->sendPasswordByMail(); |
|
| 205 | + |
|
| 206 | + if ($initiatorEMailAddress === null && !$allowPasswordByMail) { |
|
| 207 | + throw new \Exception( |
|
| 208 | + $this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.") |
|
| 209 | + ); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + $passwordPolicy = $this->getPasswordPolicy(); |
|
| 213 | + $passwordCharset = ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS; |
|
| 214 | + $passwordLength = 8; |
|
| 215 | + if (!empty($passwordPolicy)) { |
|
| 216 | + $passwordLength = (int)$passwordPolicy['minLength'] > 0 ? (int)$passwordPolicy['minLength'] : $passwordLength; |
|
| 217 | + $passwordCharset .= $passwordPolicy['enforceSpecialCharacters'] ? ISecureRandom::CHAR_SYMBOLS : ''; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + $password = $this->secureRandom->generate($passwordLength, $passwordCharset); |
|
| 221 | + |
|
| 222 | + $share->setPassword($this->hasher->hash($password)); |
|
| 223 | + |
|
| 224 | + return $password; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * get password policy |
|
| 229 | + * |
|
| 230 | + * @return array |
|
| 231 | + */ |
|
| 232 | + protected function getPasswordPolicy() { |
|
| 233 | + $capabilities = $this->capabilitiesManager->getCapabilities(); |
|
| 234 | + if (isset($capabilities['password_policy'])) { |
|
| 235 | + return $capabilities['password_policy']; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + return []; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * create activity if a file/folder was shared by mail |
|
| 243 | + * |
|
| 244 | + * @param IShare $share |
|
| 245 | + */ |
|
| 246 | + protected function createShareActivity(IShare $share) { |
|
| 247 | + |
|
| 248 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
| 249 | + |
|
| 250 | + $this->publishActivity( |
|
| 251 | + Activity::SUBJECT_SHARED_EMAIL_SELF, |
|
| 252 | + [$userFolder->getRelativePath($share->getNode()->getPath()), $share->getSharedWith()], |
|
| 253 | + $share->getSharedBy(), |
|
| 254 | + $share->getNode()->getId(), |
|
| 255 | + $userFolder->getRelativePath($share->getNode()->getPath()) |
|
| 256 | + ); |
|
| 257 | + |
|
| 258 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 259 | + $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
| 260 | + $fileId = $share->getNode()->getId(); |
|
| 261 | + $nodes = $ownerFolder->getById($fileId); |
|
| 262 | + $ownerPath = $nodes[0]->getPath(); |
|
| 263 | + $this->publishActivity( |
|
| 264 | + Activity::SUBJECT_SHARED_EMAIL_BY, |
|
| 265 | + [$ownerFolder->getRelativePath($ownerPath), $share->getSharedWith(), $share->getSharedBy()], |
|
| 266 | + $share->getShareOwner(), |
|
| 267 | + $fileId, |
|
| 268 | + $ownerFolder->getRelativePath($ownerPath) |
|
| 269 | + ); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * create activity if a file/folder was shared by mail |
|
| 276 | + * |
|
| 277 | + * @param IShare $share |
|
| 278 | + * @param string $sharedWith |
|
| 279 | + * @param bool $sendToSelf |
|
| 280 | + */ |
|
| 281 | + protected function createPasswordSendActivity(IShare $share, $sharedWith, $sendToSelf) { |
|
| 282 | + |
|
| 283 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
| 284 | + |
|
| 285 | + if ($sendToSelf) { |
|
| 286 | + $this->publishActivity( |
|
| 287 | + Activity::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF, |
|
| 288 | + [$userFolder->getRelativePath($share->getNode()->getPath())], |
|
| 289 | + $share->getSharedBy(), |
|
| 290 | + $share->getNode()->getId(), |
|
| 291 | + $userFolder->getRelativePath($share->getNode()->getPath()) |
|
| 292 | + ); |
|
| 293 | + } else { |
|
| 294 | + $this->publishActivity( |
|
| 295 | + Activity::SUBJECT_SHARED_EMAIL_PASSWORD_SEND, |
|
| 296 | + [$userFolder->getRelativePath($share->getNode()->getPath()), $sharedWith], |
|
| 297 | + $share->getSharedBy(), |
|
| 298 | + $share->getNode()->getId(), |
|
| 299 | + $userFolder->getRelativePath($share->getNode()->getPath()) |
|
| 300 | + ); |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * publish activity if a file/folder was shared by mail |
|
| 307 | + * |
|
| 308 | + * @param $subject |
|
| 309 | + * @param $parameters |
|
| 310 | + * @param $affectedUser |
|
| 311 | + * @param $fileId |
|
| 312 | + * @param $filePath |
|
| 313 | + */ |
|
| 314 | + protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) { |
|
| 315 | + $event = $this->activityManager->generateEvent(); |
|
| 316 | + $event->setApp('sharebymail') |
|
| 317 | + ->setType('shared') |
|
| 318 | + ->setSubject($subject, $parameters) |
|
| 319 | + ->setAffectedUser($affectedUser) |
|
| 320 | + ->setObject('files', $fileId, $filePath); |
|
| 321 | + $this->activityManager->publish($event); |
|
| 322 | + |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * @param IShare $share |
|
| 327 | + * @return int |
|
| 328 | + * @throws \Exception |
|
| 329 | + */ |
|
| 330 | + protected function createMailShare(IShare $share) { |
|
| 331 | + $share->setToken($this->generateToken()); |
|
| 332 | + $shareId = $this->addShareToDB( |
|
| 333 | + $share->getNodeId(), |
|
| 334 | + $share->getNodeType(), |
|
| 335 | + $share->getSharedWith(), |
|
| 336 | + $share->getSharedBy(), |
|
| 337 | + $share->getShareOwner(), |
|
| 338 | + $share->getPermissions(), |
|
| 339 | + $share->getToken(), |
|
| 340 | + $share->getPassword() |
|
| 341 | + ); |
|
| 342 | + |
|
| 343 | + try { |
|
| 344 | + $link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', |
|
| 345 | + ['token' => $share->getToken()]); |
|
| 346 | + $this->sendMailNotification( |
|
| 347 | + $share->getNode()->getName(), |
|
| 348 | + $link, |
|
| 349 | + $share->getSharedBy(), |
|
| 350 | + $share->getSharedWith(), |
|
| 351 | + $share->getExpirationDate() |
|
| 352 | + ); |
|
| 353 | + } catch (HintException $hintException) { |
|
| 354 | + $this->logger->logException($hintException, [ |
|
| 355 | + 'message' => 'Failed to send share by mail.', |
|
| 356 | + 'level' => ILogger::ERROR, |
|
| 357 | + 'app' => 'sharebymail', |
|
| 358 | + ]); |
|
| 359 | + $this->removeShareFromTable($shareId); |
|
| 360 | + throw $hintException; |
|
| 361 | + } catch (\Exception $e) { |
|
| 362 | + $this->logger->logException($e, [ |
|
| 363 | + 'message' => 'Failed to send share by mail.', |
|
| 364 | + 'level' => ILogger::ERROR, |
|
| 365 | + 'app' => 'sharebymail', |
|
| 366 | + ]); |
|
| 367 | + $this->removeShareFromTable($shareId); |
|
| 368 | + throw new HintException('Failed to send share by mail', |
|
| 369 | + $this->l->t('Failed to send share by email')); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + return $shareId; |
|
| 373 | + |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * @param string $filename |
|
| 378 | + * @param string $link |
|
| 379 | + * @param string $initiator |
|
| 380 | + * @param string $shareWith |
|
| 381 | + * @param \DateTime|null $expiration |
|
| 382 | + * @throws \Exception If mail couldn't be sent |
|
| 383 | + */ |
|
| 384 | + protected function sendMailNotification($filename, |
|
| 385 | + $link, |
|
| 386 | + $initiator, |
|
| 387 | + $shareWith, |
|
| 388 | + \DateTime $expiration = null) { |
|
| 389 | + $initiatorUser = $this->userManager->get($initiator); |
|
| 390 | + $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
| 391 | + $message = $this->mailer->createMessage(); |
|
| 392 | + |
|
| 393 | + $emailTemplate = $this->mailer->createEMailTemplate('sharebymail.RecipientNotification', [ |
|
| 394 | + 'filename' => $filename, |
|
| 395 | + 'link' => $link, |
|
| 396 | + 'initiator' => $initiatorDisplayName, |
|
| 397 | + 'expiration' => $expiration, |
|
| 398 | + 'shareWith' => $shareWith, |
|
| 399 | + ]); |
|
| 400 | + |
|
| 401 | + $emailTemplate->setSubject($this->l->t('%s shared »%s« with you', array($initiatorDisplayName, $filename))); |
|
| 402 | + $emailTemplate->addHeader(); |
|
| 403 | + $emailTemplate->addHeading($this->l->t('%s shared »%s« with you', [$initiatorDisplayName, $filename]), false); |
|
| 404 | + $text = $this->l->t('%s shared »%s« with you.', [$initiatorDisplayName, $filename]); |
|
| 405 | + |
|
| 406 | + $emailTemplate->addBodyText( |
|
| 407 | + htmlspecialchars($text . ' ' . $this->l->t('Click the button below to open it.')), |
|
| 408 | + $text |
|
| 409 | + ); |
|
| 410 | + $emailTemplate->addBodyButton( |
|
| 411 | + $this->l->t('Open »%s«', [$filename]), |
|
| 412 | + $link |
|
| 413 | + ); |
|
| 414 | + |
|
| 415 | + $message->setTo([$shareWith]); |
|
| 416 | + |
|
| 417 | + // The "From" contains the sharers name |
|
| 418 | + $instanceName = $this->defaults->getName(); |
|
| 419 | + $senderName = $this->l->t( |
|
| 420 | + '%s via %s', |
|
| 421 | + [ |
|
| 422 | + $initiatorDisplayName, |
|
| 423 | + $instanceName |
|
| 424 | + ] |
|
| 425 | + ); |
|
| 426 | + $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
| 427 | + |
|
| 428 | + // The "Reply-To" is set to the sharer if an mail address is configured |
|
| 429 | + // also the default footer contains a "Do not reply" which needs to be adjusted. |
|
| 430 | + $initiatorEmail = $initiatorUser->getEMailAddress(); |
|
| 431 | + if($initiatorEmail !== null) { |
|
| 432 | + $message->setReplyTo([$initiatorEmail => $initiatorDisplayName]); |
|
| 433 | + $emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : '')); |
|
| 434 | + } else { |
|
| 435 | + $emailTemplate->addFooter(); |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + $message->useTemplate($emailTemplate); |
|
| 439 | + $this->mailer->send($message); |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * send password to recipient of a mail share |
|
| 444 | + * |
|
| 445 | + * @param IShare $share |
|
| 446 | + * @param string $password |
|
| 447 | + * @return bool |
|
| 448 | + */ |
|
| 449 | + protected function sendPassword(IShare $share, $password) { |
|
| 450 | + |
|
| 451 | + $filename = $share->getNode()->getName(); |
|
| 452 | + $initiator = $share->getSharedBy(); |
|
| 453 | + $shareWith = $share->getSharedWith(); |
|
| 454 | + |
|
| 455 | + if ($password === '' || $this->settingsManager->sendPasswordByMail() === false) { |
|
| 456 | + return false; |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + $initiatorUser = $this->userManager->get($initiator); |
|
| 460 | + $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
| 461 | + $initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
|
| 462 | + |
|
| 463 | + $plainBodyPart = $this->l->t("%s shared »%s« with you.\nYou should have already received a separate mail with a link to access it.\n", [$initiatorDisplayName, $filename]); |
|
| 464 | + $htmlBodyPart = $this->l->t('%s shared »%s« with you. You should have already received a separate mail with a link to access it.', [$initiatorDisplayName, $filename]); |
|
| 465 | + |
|
| 466 | + $message = $this->mailer->createMessage(); |
|
| 467 | + |
|
| 468 | + $emailTemplate = $this->mailer->createEMailTemplate('sharebymail.RecipientPasswordNotification', [ |
|
| 469 | + 'filename' => $filename, |
|
| 470 | + 'password' => $password, |
|
| 471 | + 'initiator' => $initiatorDisplayName, |
|
| 472 | + 'initiatorEmail' => $initiatorEmailAddress, |
|
| 473 | + 'shareWith' => $shareWith, |
|
| 474 | + ]); |
|
| 475 | + |
|
| 476 | + $emailTemplate->setSubject($this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName])); |
|
| 477 | + $emailTemplate->addHeader(); |
|
| 478 | + $emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename]), false); |
|
| 479 | + $emailTemplate->addBodyText(htmlspecialchars($htmlBodyPart), $plainBodyPart); |
|
| 480 | + $emailTemplate->addBodyText($this->l->t('It is protected with the following password: %s', [$password])); |
|
| 481 | + |
|
| 482 | + // The "From" contains the sharers name |
|
| 483 | + $instanceName = $this->defaults->getName(); |
|
| 484 | + $senderName = $this->l->t( |
|
| 485 | + '%s via %s', |
|
| 486 | + [ |
|
| 487 | + $initiatorDisplayName, |
|
| 488 | + $instanceName |
|
| 489 | + ] |
|
| 490 | + ); |
|
| 491 | + $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
| 492 | + if ($initiatorEmailAddress !== null) { |
|
| 493 | + $message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]); |
|
| 494 | + $emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan()); |
|
| 495 | + } else { |
|
| 496 | + $emailTemplate->addFooter(); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + $message->setTo([$shareWith]); |
|
| 500 | + $message->useTemplate($emailTemplate); |
|
| 501 | + $this->mailer->send($message); |
|
| 502 | + |
|
| 503 | + $this->createPasswordSendActivity($share, $shareWith, false); |
|
| 504 | + |
|
| 505 | + return true; |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * send auto generated password to the owner. This happens if the admin enforces |
|
| 510 | + * a password for mail shares and forbid to send the password by mail to the recipient |
|
| 511 | + * |
|
| 512 | + * @param IShare $share |
|
| 513 | + * @param string $password |
|
| 514 | + * @return bool |
|
| 515 | + * @throws \Exception |
|
| 516 | + */ |
|
| 517 | + protected function sendPasswordToOwner(IShare $share, $password) { |
|
| 518 | + |
|
| 519 | + $filename = $share->getNode()->getName(); |
|
| 520 | + $initiator = $this->userManager->get($share->getSharedBy()); |
|
| 521 | + $initiatorEMailAddress = ($initiator instanceof IUser) ? $initiator->getEMailAddress() : null; |
|
| 522 | + $initiatorDisplayName = ($initiator instanceof IUser) ? $initiator->getDisplayName() : $share->getSharedBy(); |
|
| 523 | + $shareWith = $share->getSharedWith(); |
|
| 524 | + |
|
| 525 | + if ($initiatorEMailAddress === null) { |
|
| 526 | + throw new \Exception( |
|
| 527 | + $this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.") |
|
| 528 | + ); |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + $bodyPart = $this->l->t("You just shared »%s« with %s. The share was already send to the recipient. Due to the security policies defined by the administrator of %s each share needs to be protected by password and it is not allowed to send the password directly to the recipient. Therefore you need to forward the password manually to the recipient.", [$filename, $shareWith, $this->defaults->getName()]); |
|
| 532 | + |
|
| 533 | + $message = $this->mailer->createMessage(); |
|
| 534 | + $emailTemplate = $this->mailer->createEMailTemplate('sharebymail.OwnerPasswordNotification', [ |
|
| 535 | + 'filename' => $filename, |
|
| 536 | + 'password' => $password, |
|
| 537 | + 'initiator' => $initiatorDisplayName, |
|
| 538 | + 'initiatorEmail' => $initiatorEMailAddress, |
|
| 539 | + 'shareWith' => $shareWith, |
|
| 540 | + ]); |
|
| 541 | + |
|
| 542 | + $emailTemplate->setSubject($this->l->t('Password to access »%s« shared with %s', [$filename, $shareWith])); |
|
| 543 | + $emailTemplate->addHeader(); |
|
| 544 | + $emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename]), false); |
|
| 545 | + $emailTemplate->addBodyText($bodyPart); |
|
| 546 | + $emailTemplate->addBodyText($this->l->t('This is the password: %s', [$password])); |
|
| 547 | + $emailTemplate->addBodyText($this->l->t('You can choose a different password at any time in the share dialog.')); |
|
| 548 | + $emailTemplate->addFooter(); |
|
| 549 | + |
|
| 550 | + if ($initiatorEMailAddress) { |
|
| 551 | + $message->setFrom([$initiatorEMailAddress => $initiatorDisplayName]); |
|
| 552 | + } |
|
| 553 | + $message->setTo([$initiatorEMailAddress => $initiatorDisplayName]); |
|
| 554 | + $message->useTemplate($emailTemplate); |
|
| 555 | + $this->mailer->send($message); |
|
| 556 | + |
|
| 557 | + $this->createPasswordSendActivity($share, $shareWith, true); |
|
| 558 | + |
|
| 559 | + return true; |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * generate share token |
|
| 564 | + * |
|
| 565 | + * @return string |
|
| 566 | + */ |
|
| 567 | + protected function generateToken($size = 15) { |
|
| 568 | + $token = $this->secureRandom->generate($size, ISecureRandom::CHAR_HUMAN_READABLE); |
|
| 569 | + return $token; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * Get all children of this share |
|
| 574 | + * |
|
| 575 | + * @param IShare $parent |
|
| 576 | + * @return IShare[] |
|
| 577 | + */ |
|
| 578 | + public function getChildren(IShare $parent) { |
|
| 579 | + $children = []; |
|
| 580 | + |
|
| 581 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 582 | + $qb->select('*') |
|
| 583 | + ->from('share') |
|
| 584 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
| 585 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 586 | + ->orderBy('id'); |
|
| 587 | + |
|
| 588 | + $cursor = $qb->execute(); |
|
| 589 | + while($data = $cursor->fetch()) { |
|
| 590 | + $children[] = $this->createShareObject($data); |
|
| 591 | + } |
|
| 592 | + $cursor->closeCursor(); |
|
| 593 | + |
|
| 594 | + return $children; |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * add share to the database and return the ID |
|
| 599 | + * |
|
| 600 | + * @param int $itemSource |
|
| 601 | + * @param string $itemType |
|
| 602 | + * @param string $shareWith |
|
| 603 | + * @param string $sharedBy |
|
| 604 | + * @param string $uidOwner |
|
| 605 | + * @param int $permissions |
|
| 606 | + * @param string $token |
|
| 607 | + * @return int |
|
| 608 | + */ |
|
| 609 | + protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password) { |
|
| 610 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 611 | + $qb->insert('share') |
|
| 612 | + ->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
| 613 | + ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
| 614 | + ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
| 615 | + ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
| 616 | + ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
| 617 | + ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
| 618 | + ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
| 619 | + ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
| 620 | + ->setValue('token', $qb->createNamedParameter($token)) |
|
| 621 | + ->setValue('password', $qb->createNamedParameter($password)) |
|
| 622 | + ->setValue('stime', $qb->createNamedParameter(time())); |
|
| 623 | + |
|
| 624 | + /* |
|
| 625 | 625 | * Added to fix https://github.com/owncloud/core/issues/22215 |
| 626 | 626 | * Can be removed once we get rid of ajax/share.php |
| 627 | 627 | */ |
| 628 | - $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
| 628 | + $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
| 629 | 629 | |
| 630 | - $qb->execute(); |
|
| 631 | - $id = $qb->getLastInsertId(); |
|
| 630 | + $qb->execute(); |
|
| 631 | + $id = $qb->getLastInsertId(); |
|
| 632 | 632 | |
| 633 | - return (int)$id; |
|
| 634 | - } |
|
| 633 | + return (int)$id; |
|
| 634 | + } |
|
| 635 | 635 | |
| 636 | - /** |
|
| 637 | - * Update a share |
|
| 638 | - * |
|
| 639 | - * @param IShare $share |
|
| 640 | - * @param string|null $plainTextPassword |
|
| 641 | - * @return IShare The share object |
|
| 642 | - */ |
|
| 643 | - public function update(IShare $share, $plainTextPassword = null) { |
|
| 636 | + /** |
|
| 637 | + * Update a share |
|
| 638 | + * |
|
| 639 | + * @param IShare $share |
|
| 640 | + * @param string|null $plainTextPassword |
|
| 641 | + * @return IShare The share object |
|
| 642 | + */ |
|
| 643 | + public function update(IShare $share, $plainTextPassword = null) { |
|
| 644 | 644 | |
| 645 | - $originalShare = $this->getShareById($share->getId()); |
|
| 645 | + $originalShare = $this->getShareById($share->getId()); |
|
| 646 | 646 | |
| 647 | - // a real password was given |
|
| 648 | - $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; |
|
| 647 | + // a real password was given |
|
| 648 | + $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; |
|
| 649 | 649 | |
| 650 | - if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
| 651 | - $this->sendPassword($share, $plainTextPassword); |
|
| 652 | - } |
|
| 653 | - /* |
|
| 650 | + if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
| 651 | + $this->sendPassword($share, $plainTextPassword); |
|
| 652 | + } |
|
| 653 | + /* |
|
| 654 | 654 | * We allow updating the permissions and password of mail shares |
| 655 | 655 | */ |
| 656 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 657 | - $qb->update('share') |
|
| 658 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
| 659 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
| 660 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
| 661 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
| 662 | - ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
| 663 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
| 664 | - ->execute(); |
|
| 665 | - |
|
| 666 | - return $share; |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - /** |
|
| 670 | - * @inheritdoc |
|
| 671 | - */ |
|
| 672 | - public function move(IShare $share, $recipient) { |
|
| 673 | - /** |
|
| 674 | - * nothing to do here, mail shares are only outgoing shares |
|
| 675 | - */ |
|
| 676 | - return $share; |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * Delete a share (owner unShares the file) |
|
| 681 | - * |
|
| 682 | - * @param IShare $share |
|
| 683 | - */ |
|
| 684 | - public function delete(IShare $share) { |
|
| 685 | - $this->removeShareFromTable($share->getId()); |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * @inheritdoc |
|
| 690 | - */ |
|
| 691 | - public function deleteFromSelf(IShare $share, $recipient) { |
|
| 692 | - // nothing to do here, mail shares are only outgoing shares |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * @inheritdoc |
|
| 697 | - */ |
|
| 698 | - public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
| 699 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 700 | - $qb->select('*') |
|
| 701 | - ->from('share'); |
|
| 702 | - |
|
| 703 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
| 704 | - |
|
| 705 | - /** |
|
| 706 | - * Reshares for this user are shares where they are the owner. |
|
| 707 | - */ |
|
| 708 | - if ($reshares === false) { |
|
| 709 | - //Special case for old shares created via the web UI |
|
| 710 | - $or1 = $qb->expr()->andX( |
|
| 711 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 712 | - $qb->expr()->isNull('uid_initiator') |
|
| 713 | - ); |
|
| 714 | - |
|
| 715 | - $qb->andWhere( |
|
| 716 | - $qb->expr()->orX( |
|
| 717 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
| 718 | - $or1 |
|
| 719 | - ) |
|
| 720 | - ); |
|
| 721 | - } else { |
|
| 722 | - $qb->andWhere( |
|
| 723 | - $qb->expr()->orX( |
|
| 724 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 725 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 726 | - ) |
|
| 727 | - ); |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - if ($node !== null) { |
|
| 731 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - if ($limit !== -1) { |
|
| 735 | - $qb->setMaxResults($limit); |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - $qb->setFirstResult($offset); |
|
| 739 | - $qb->orderBy('id'); |
|
| 740 | - |
|
| 741 | - $cursor = $qb->execute(); |
|
| 742 | - $shares = []; |
|
| 743 | - while($data = $cursor->fetch()) { |
|
| 744 | - $shares[] = $this->createShareObject($data); |
|
| 745 | - } |
|
| 746 | - $cursor->closeCursor(); |
|
| 747 | - |
|
| 748 | - return $shares; |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - /** |
|
| 752 | - * @inheritdoc |
|
| 753 | - */ |
|
| 754 | - public function getShareById($id, $recipientId = null) { |
|
| 755 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 756 | - |
|
| 757 | - $qb->select('*') |
|
| 758 | - ->from('share') |
|
| 759 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 760 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
| 761 | - |
|
| 762 | - $cursor = $qb->execute(); |
|
| 763 | - $data = $cursor->fetch(); |
|
| 764 | - $cursor->closeCursor(); |
|
| 765 | - |
|
| 766 | - if ($data === false) { |
|
| 767 | - throw new ShareNotFound(); |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - try { |
|
| 771 | - $share = $this->createShareObject($data); |
|
| 772 | - } catch (InvalidShare $e) { |
|
| 773 | - throw new ShareNotFound(); |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - return $share; |
|
| 777 | - } |
|
| 778 | - |
|
| 779 | - /** |
|
| 780 | - * Get shares for a given path |
|
| 781 | - * |
|
| 782 | - * @param \OCP\Files\Node $path |
|
| 783 | - * @return IShare[] |
|
| 784 | - */ |
|
| 785 | - public function getSharesByPath(Node $path) { |
|
| 786 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 787 | - |
|
| 788 | - $cursor = $qb->select('*') |
|
| 789 | - ->from('share') |
|
| 790 | - ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
| 791 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 792 | - ->execute(); |
|
| 793 | - |
|
| 794 | - $shares = []; |
|
| 795 | - while($data = $cursor->fetch()) { |
|
| 796 | - $shares[] = $this->createShareObject($data); |
|
| 797 | - } |
|
| 798 | - $cursor->closeCursor(); |
|
| 799 | - |
|
| 800 | - return $shares; |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - /** |
|
| 804 | - * @inheritdoc |
|
| 805 | - */ |
|
| 806 | - public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
| 807 | - /** @var IShare[] $shares */ |
|
| 808 | - $shares = []; |
|
| 809 | - |
|
| 810 | - //Get shares directly with this user |
|
| 811 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 812 | - $qb->select('*') |
|
| 813 | - ->from('share'); |
|
| 814 | - |
|
| 815 | - // Order by id |
|
| 816 | - $qb->orderBy('id'); |
|
| 817 | - |
|
| 818 | - // Set limit and offset |
|
| 819 | - if ($limit !== -1) { |
|
| 820 | - $qb->setMaxResults($limit); |
|
| 821 | - } |
|
| 822 | - $qb->setFirstResult($offset); |
|
| 823 | - |
|
| 824 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
| 825 | - $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
| 826 | - |
|
| 827 | - // Filter by node if provided |
|
| 828 | - if ($node !== null) { |
|
| 829 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - $cursor = $qb->execute(); |
|
| 833 | - |
|
| 834 | - while($data = $cursor->fetch()) { |
|
| 835 | - $shares[] = $this->createShareObject($data); |
|
| 836 | - } |
|
| 837 | - $cursor->closeCursor(); |
|
| 838 | - |
|
| 839 | - |
|
| 840 | - return $shares; |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - /** |
|
| 844 | - * Get a share by token |
|
| 845 | - * |
|
| 846 | - * @param string $token |
|
| 847 | - * @return IShare |
|
| 848 | - * @throws ShareNotFound |
|
| 849 | - */ |
|
| 850 | - public function getShareByToken($token) { |
|
| 851 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 852 | - |
|
| 853 | - $cursor = $qb->select('*') |
|
| 854 | - ->from('share') |
|
| 855 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 856 | - ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 857 | - ->execute(); |
|
| 858 | - |
|
| 859 | - $data = $cursor->fetch(); |
|
| 860 | - |
|
| 861 | - if ($data === false) { |
|
| 862 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - try { |
|
| 866 | - $share = $this->createShareObject($data); |
|
| 867 | - } catch (InvalidShare $e) { |
|
| 868 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 869 | - } |
|
| 870 | - |
|
| 871 | - return $share; |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - /** |
|
| 875 | - * remove share from table |
|
| 876 | - * |
|
| 877 | - * @param string $shareId |
|
| 878 | - */ |
|
| 879 | - protected function removeShareFromTable($shareId) { |
|
| 880 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 881 | - $qb->delete('share') |
|
| 882 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
| 883 | - $qb->execute(); |
|
| 884 | - } |
|
| 885 | - |
|
| 886 | - /** |
|
| 887 | - * Create a share object from an database row |
|
| 888 | - * |
|
| 889 | - * @param array $data |
|
| 890 | - * @return IShare |
|
| 891 | - * @throws InvalidShare |
|
| 892 | - * @throws ShareNotFound |
|
| 893 | - */ |
|
| 894 | - protected function createShareObject($data) { |
|
| 895 | - |
|
| 896 | - $share = new Share($this->rootFolder, $this->userManager); |
|
| 897 | - $share->setId((int)$data['id']) |
|
| 898 | - ->setShareType((int)$data['share_type']) |
|
| 899 | - ->setPermissions((int)$data['permissions']) |
|
| 900 | - ->setTarget($data['file_target']) |
|
| 901 | - ->setMailSend((bool)$data['mail_send']) |
|
| 902 | - ->setToken($data['token']); |
|
| 903 | - |
|
| 904 | - $shareTime = new \DateTime(); |
|
| 905 | - $shareTime->setTimestamp((int)$data['stime']); |
|
| 906 | - $share->setShareTime($shareTime); |
|
| 907 | - $share->setSharedWith($data['share_with']); |
|
| 908 | - $share->setPassword($data['password']); |
|
| 909 | - |
|
| 910 | - if ($data['uid_initiator'] !== null) { |
|
| 911 | - $share->setShareOwner($data['uid_owner']); |
|
| 912 | - $share->setSharedBy($data['uid_initiator']); |
|
| 913 | - } else { |
|
| 914 | - //OLD SHARE |
|
| 915 | - $share->setSharedBy($data['uid_owner']); |
|
| 916 | - $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
| 917 | - |
|
| 918 | - $owner = $path->getOwner(); |
|
| 919 | - $share->setShareOwner($owner->getUID()); |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - if ($data['expiration'] !== null) { |
|
| 923 | - $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
| 924 | - if ($expiration !== false) { |
|
| 925 | - $share->setExpirationDate($expiration); |
|
| 926 | - } |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - $share->setNodeId((int)$data['file_source']); |
|
| 930 | - $share->setNodeType($data['item_type']); |
|
| 931 | - |
|
| 932 | - $share->setProviderId($this->identifier()); |
|
| 933 | - |
|
| 934 | - return $share; |
|
| 935 | - } |
|
| 936 | - |
|
| 937 | - /** |
|
| 938 | - * Get the node with file $id for $user |
|
| 939 | - * |
|
| 940 | - * @param string $userId |
|
| 941 | - * @param int $id |
|
| 942 | - * @return \OCP\Files\File|\OCP\Files\Folder |
|
| 943 | - * @throws InvalidShare |
|
| 944 | - */ |
|
| 945 | - private function getNode($userId, $id) { |
|
| 946 | - try { |
|
| 947 | - $userFolder = $this->rootFolder->getUserFolder($userId); |
|
| 948 | - } catch (NoUserException $e) { |
|
| 949 | - throw new InvalidShare(); |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - $nodes = $userFolder->getById($id); |
|
| 953 | - |
|
| 954 | - if (empty($nodes)) { |
|
| 955 | - throw new InvalidShare(); |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - return $nodes[0]; |
|
| 959 | - } |
|
| 960 | - |
|
| 961 | - /** |
|
| 962 | - * A user is deleted from the system |
|
| 963 | - * So clean up the relevant shares. |
|
| 964 | - * |
|
| 965 | - * @param string $uid |
|
| 966 | - * @param int $shareType |
|
| 967 | - */ |
|
| 968 | - public function userDeleted($uid, $shareType) { |
|
| 969 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 970 | - |
|
| 971 | - $qb->delete('share') |
|
| 972 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 973 | - ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
| 974 | - ->execute(); |
|
| 975 | - } |
|
| 976 | - |
|
| 977 | - /** |
|
| 978 | - * This provider does not support group shares |
|
| 979 | - * |
|
| 980 | - * @param string $gid |
|
| 981 | - */ |
|
| 982 | - public function groupDeleted($gid) { |
|
| 983 | - } |
|
| 984 | - |
|
| 985 | - /** |
|
| 986 | - * This provider does not support group shares |
|
| 987 | - * |
|
| 988 | - * @param string $uid |
|
| 989 | - * @param string $gid |
|
| 990 | - */ |
|
| 991 | - public function userDeletedFromGroup($uid, $gid) { |
|
| 992 | - } |
|
| 993 | - |
|
| 994 | - /** |
|
| 995 | - * get database row of a give share |
|
| 996 | - * |
|
| 997 | - * @param $id |
|
| 998 | - * @return array |
|
| 999 | - * @throws ShareNotFound |
|
| 1000 | - */ |
|
| 1001 | - protected function getRawShare($id) { |
|
| 1002 | - |
|
| 1003 | - // Now fetch the inserted share and create a complete share object |
|
| 1004 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 1005 | - $qb->select('*') |
|
| 1006 | - ->from('share') |
|
| 1007 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
| 1008 | - |
|
| 1009 | - $cursor = $qb->execute(); |
|
| 1010 | - $data = $cursor->fetch(); |
|
| 1011 | - $cursor->closeCursor(); |
|
| 1012 | - |
|
| 1013 | - if ($data === false) { |
|
| 1014 | - throw new ShareNotFound; |
|
| 1015 | - } |
|
| 1016 | - |
|
| 1017 | - return $data; |
|
| 1018 | - } |
|
| 1019 | - |
|
| 1020 | - public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
| 1021 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 1022 | - $qb->select('*') |
|
| 1023 | - ->from('share', 's') |
|
| 1024 | - ->andWhere($qb->expr()->orX( |
|
| 1025 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 1026 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 1027 | - )) |
|
| 1028 | - ->andWhere( |
|
| 1029 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
| 1030 | - ); |
|
| 1031 | - |
|
| 1032 | - /** |
|
| 1033 | - * Reshares for this user are shares where they are the owner. |
|
| 1034 | - */ |
|
| 1035 | - if ($reshares === false) { |
|
| 1036 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
| 1037 | - } else { |
|
| 1038 | - $qb->andWhere( |
|
| 1039 | - $qb->expr()->orX( |
|
| 1040 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 1041 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 1042 | - ) |
|
| 1043 | - ); |
|
| 1044 | - } |
|
| 1045 | - |
|
| 1046 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
| 1047 | - $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
| 1048 | - |
|
| 1049 | - $qb->orderBy('id'); |
|
| 1050 | - |
|
| 1051 | - $cursor = $qb->execute(); |
|
| 1052 | - $shares = []; |
|
| 1053 | - while ($data = $cursor->fetch()) { |
|
| 1054 | - $shares[$data['fileid']][] = $this->createShareObject($data); |
|
| 1055 | - } |
|
| 1056 | - $cursor->closeCursor(); |
|
| 1057 | - |
|
| 1058 | - return $shares; |
|
| 1059 | - } |
|
| 1060 | - |
|
| 1061 | - /** |
|
| 1062 | - * @inheritdoc |
|
| 1063 | - */ |
|
| 1064 | - public function getAccessList($nodes, $currentAccess) { |
|
| 1065 | - $ids = []; |
|
| 1066 | - foreach ($nodes as $node) { |
|
| 1067 | - $ids[] = $node->getId(); |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 1071 | - $qb->select('share_with') |
|
| 1072 | - ->from('share') |
|
| 1073 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 1074 | - ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 1075 | - ->andWhere($qb->expr()->orX( |
|
| 1076 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 1077 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 1078 | - )) |
|
| 1079 | - ->setMaxResults(1); |
|
| 1080 | - $cursor = $qb->execute(); |
|
| 1081 | - |
|
| 1082 | - $mail = $cursor->fetch() !== false; |
|
| 1083 | - $cursor->closeCursor(); |
|
| 1084 | - |
|
| 1085 | - return ['public' => $mail]; |
|
| 1086 | - } |
|
| 656 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 657 | + $qb->update('share') |
|
| 658 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
| 659 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
| 660 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
| 661 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
| 662 | + ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
| 663 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
| 664 | + ->execute(); |
|
| 665 | + |
|
| 666 | + return $share; |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + /** |
|
| 670 | + * @inheritdoc |
|
| 671 | + */ |
|
| 672 | + public function move(IShare $share, $recipient) { |
|
| 673 | + /** |
|
| 674 | + * nothing to do here, mail shares are only outgoing shares |
|
| 675 | + */ |
|
| 676 | + return $share; |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * Delete a share (owner unShares the file) |
|
| 681 | + * |
|
| 682 | + * @param IShare $share |
|
| 683 | + */ |
|
| 684 | + public function delete(IShare $share) { |
|
| 685 | + $this->removeShareFromTable($share->getId()); |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * @inheritdoc |
|
| 690 | + */ |
|
| 691 | + public function deleteFromSelf(IShare $share, $recipient) { |
|
| 692 | + // nothing to do here, mail shares are only outgoing shares |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * @inheritdoc |
|
| 697 | + */ |
|
| 698 | + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
| 699 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 700 | + $qb->select('*') |
|
| 701 | + ->from('share'); |
|
| 702 | + |
|
| 703 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
| 704 | + |
|
| 705 | + /** |
|
| 706 | + * Reshares for this user are shares where they are the owner. |
|
| 707 | + */ |
|
| 708 | + if ($reshares === false) { |
|
| 709 | + //Special case for old shares created via the web UI |
|
| 710 | + $or1 = $qb->expr()->andX( |
|
| 711 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 712 | + $qb->expr()->isNull('uid_initiator') |
|
| 713 | + ); |
|
| 714 | + |
|
| 715 | + $qb->andWhere( |
|
| 716 | + $qb->expr()->orX( |
|
| 717 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
| 718 | + $or1 |
|
| 719 | + ) |
|
| 720 | + ); |
|
| 721 | + } else { |
|
| 722 | + $qb->andWhere( |
|
| 723 | + $qb->expr()->orX( |
|
| 724 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 725 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 726 | + ) |
|
| 727 | + ); |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + if ($node !== null) { |
|
| 731 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + if ($limit !== -1) { |
|
| 735 | + $qb->setMaxResults($limit); |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + $qb->setFirstResult($offset); |
|
| 739 | + $qb->orderBy('id'); |
|
| 740 | + |
|
| 741 | + $cursor = $qb->execute(); |
|
| 742 | + $shares = []; |
|
| 743 | + while($data = $cursor->fetch()) { |
|
| 744 | + $shares[] = $this->createShareObject($data); |
|
| 745 | + } |
|
| 746 | + $cursor->closeCursor(); |
|
| 747 | + |
|
| 748 | + return $shares; |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + /** |
|
| 752 | + * @inheritdoc |
|
| 753 | + */ |
|
| 754 | + public function getShareById($id, $recipientId = null) { |
|
| 755 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 756 | + |
|
| 757 | + $qb->select('*') |
|
| 758 | + ->from('share') |
|
| 759 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 760 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
| 761 | + |
|
| 762 | + $cursor = $qb->execute(); |
|
| 763 | + $data = $cursor->fetch(); |
|
| 764 | + $cursor->closeCursor(); |
|
| 765 | + |
|
| 766 | + if ($data === false) { |
|
| 767 | + throw new ShareNotFound(); |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + try { |
|
| 771 | + $share = $this->createShareObject($data); |
|
| 772 | + } catch (InvalidShare $e) { |
|
| 773 | + throw new ShareNotFound(); |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + return $share; |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + /** |
|
| 780 | + * Get shares for a given path |
|
| 781 | + * |
|
| 782 | + * @param \OCP\Files\Node $path |
|
| 783 | + * @return IShare[] |
|
| 784 | + */ |
|
| 785 | + public function getSharesByPath(Node $path) { |
|
| 786 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 787 | + |
|
| 788 | + $cursor = $qb->select('*') |
|
| 789 | + ->from('share') |
|
| 790 | + ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
| 791 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 792 | + ->execute(); |
|
| 793 | + |
|
| 794 | + $shares = []; |
|
| 795 | + while($data = $cursor->fetch()) { |
|
| 796 | + $shares[] = $this->createShareObject($data); |
|
| 797 | + } |
|
| 798 | + $cursor->closeCursor(); |
|
| 799 | + |
|
| 800 | + return $shares; |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + /** |
|
| 804 | + * @inheritdoc |
|
| 805 | + */ |
|
| 806 | + public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
| 807 | + /** @var IShare[] $shares */ |
|
| 808 | + $shares = []; |
|
| 809 | + |
|
| 810 | + //Get shares directly with this user |
|
| 811 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 812 | + $qb->select('*') |
|
| 813 | + ->from('share'); |
|
| 814 | + |
|
| 815 | + // Order by id |
|
| 816 | + $qb->orderBy('id'); |
|
| 817 | + |
|
| 818 | + // Set limit and offset |
|
| 819 | + if ($limit !== -1) { |
|
| 820 | + $qb->setMaxResults($limit); |
|
| 821 | + } |
|
| 822 | + $qb->setFirstResult($offset); |
|
| 823 | + |
|
| 824 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
| 825 | + $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
| 826 | + |
|
| 827 | + // Filter by node if provided |
|
| 828 | + if ($node !== null) { |
|
| 829 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + $cursor = $qb->execute(); |
|
| 833 | + |
|
| 834 | + while($data = $cursor->fetch()) { |
|
| 835 | + $shares[] = $this->createShareObject($data); |
|
| 836 | + } |
|
| 837 | + $cursor->closeCursor(); |
|
| 838 | + |
|
| 839 | + |
|
| 840 | + return $shares; |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + /** |
|
| 844 | + * Get a share by token |
|
| 845 | + * |
|
| 846 | + * @param string $token |
|
| 847 | + * @return IShare |
|
| 848 | + * @throws ShareNotFound |
|
| 849 | + */ |
|
| 850 | + public function getShareByToken($token) { |
|
| 851 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 852 | + |
|
| 853 | + $cursor = $qb->select('*') |
|
| 854 | + ->from('share') |
|
| 855 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 856 | + ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 857 | + ->execute(); |
|
| 858 | + |
|
| 859 | + $data = $cursor->fetch(); |
|
| 860 | + |
|
| 861 | + if ($data === false) { |
|
| 862 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + try { |
|
| 866 | + $share = $this->createShareObject($data); |
|
| 867 | + } catch (InvalidShare $e) { |
|
| 868 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 869 | + } |
|
| 870 | + |
|
| 871 | + return $share; |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + /** |
|
| 875 | + * remove share from table |
|
| 876 | + * |
|
| 877 | + * @param string $shareId |
|
| 878 | + */ |
|
| 879 | + protected function removeShareFromTable($shareId) { |
|
| 880 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 881 | + $qb->delete('share') |
|
| 882 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
| 883 | + $qb->execute(); |
|
| 884 | + } |
|
| 885 | + |
|
| 886 | + /** |
|
| 887 | + * Create a share object from an database row |
|
| 888 | + * |
|
| 889 | + * @param array $data |
|
| 890 | + * @return IShare |
|
| 891 | + * @throws InvalidShare |
|
| 892 | + * @throws ShareNotFound |
|
| 893 | + */ |
|
| 894 | + protected function createShareObject($data) { |
|
| 895 | + |
|
| 896 | + $share = new Share($this->rootFolder, $this->userManager); |
|
| 897 | + $share->setId((int)$data['id']) |
|
| 898 | + ->setShareType((int)$data['share_type']) |
|
| 899 | + ->setPermissions((int)$data['permissions']) |
|
| 900 | + ->setTarget($data['file_target']) |
|
| 901 | + ->setMailSend((bool)$data['mail_send']) |
|
| 902 | + ->setToken($data['token']); |
|
| 903 | + |
|
| 904 | + $shareTime = new \DateTime(); |
|
| 905 | + $shareTime->setTimestamp((int)$data['stime']); |
|
| 906 | + $share->setShareTime($shareTime); |
|
| 907 | + $share->setSharedWith($data['share_with']); |
|
| 908 | + $share->setPassword($data['password']); |
|
| 909 | + |
|
| 910 | + if ($data['uid_initiator'] !== null) { |
|
| 911 | + $share->setShareOwner($data['uid_owner']); |
|
| 912 | + $share->setSharedBy($data['uid_initiator']); |
|
| 913 | + } else { |
|
| 914 | + //OLD SHARE |
|
| 915 | + $share->setSharedBy($data['uid_owner']); |
|
| 916 | + $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
| 917 | + |
|
| 918 | + $owner = $path->getOwner(); |
|
| 919 | + $share->setShareOwner($owner->getUID()); |
|
| 920 | + } |
|
| 921 | + |
|
| 922 | + if ($data['expiration'] !== null) { |
|
| 923 | + $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
| 924 | + if ($expiration !== false) { |
|
| 925 | + $share->setExpirationDate($expiration); |
|
| 926 | + } |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + $share->setNodeId((int)$data['file_source']); |
|
| 930 | + $share->setNodeType($data['item_type']); |
|
| 931 | + |
|
| 932 | + $share->setProviderId($this->identifier()); |
|
| 933 | + |
|
| 934 | + return $share; |
|
| 935 | + } |
|
| 936 | + |
|
| 937 | + /** |
|
| 938 | + * Get the node with file $id for $user |
|
| 939 | + * |
|
| 940 | + * @param string $userId |
|
| 941 | + * @param int $id |
|
| 942 | + * @return \OCP\Files\File|\OCP\Files\Folder |
|
| 943 | + * @throws InvalidShare |
|
| 944 | + */ |
|
| 945 | + private function getNode($userId, $id) { |
|
| 946 | + try { |
|
| 947 | + $userFolder = $this->rootFolder->getUserFolder($userId); |
|
| 948 | + } catch (NoUserException $e) { |
|
| 949 | + throw new InvalidShare(); |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + $nodes = $userFolder->getById($id); |
|
| 953 | + |
|
| 954 | + if (empty($nodes)) { |
|
| 955 | + throw new InvalidShare(); |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | + return $nodes[0]; |
|
| 959 | + } |
|
| 960 | + |
|
| 961 | + /** |
|
| 962 | + * A user is deleted from the system |
|
| 963 | + * So clean up the relevant shares. |
|
| 964 | + * |
|
| 965 | + * @param string $uid |
|
| 966 | + * @param int $shareType |
|
| 967 | + */ |
|
| 968 | + public function userDeleted($uid, $shareType) { |
|
| 969 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 970 | + |
|
| 971 | + $qb->delete('share') |
|
| 972 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 973 | + ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
| 974 | + ->execute(); |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + /** |
|
| 978 | + * This provider does not support group shares |
|
| 979 | + * |
|
| 980 | + * @param string $gid |
|
| 981 | + */ |
|
| 982 | + public function groupDeleted($gid) { |
|
| 983 | + } |
|
| 984 | + |
|
| 985 | + /** |
|
| 986 | + * This provider does not support group shares |
|
| 987 | + * |
|
| 988 | + * @param string $uid |
|
| 989 | + * @param string $gid |
|
| 990 | + */ |
|
| 991 | + public function userDeletedFromGroup($uid, $gid) { |
|
| 992 | + } |
|
| 993 | + |
|
| 994 | + /** |
|
| 995 | + * get database row of a give share |
|
| 996 | + * |
|
| 997 | + * @param $id |
|
| 998 | + * @return array |
|
| 999 | + * @throws ShareNotFound |
|
| 1000 | + */ |
|
| 1001 | + protected function getRawShare($id) { |
|
| 1002 | + |
|
| 1003 | + // Now fetch the inserted share and create a complete share object |
|
| 1004 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 1005 | + $qb->select('*') |
|
| 1006 | + ->from('share') |
|
| 1007 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
| 1008 | + |
|
| 1009 | + $cursor = $qb->execute(); |
|
| 1010 | + $data = $cursor->fetch(); |
|
| 1011 | + $cursor->closeCursor(); |
|
| 1012 | + |
|
| 1013 | + if ($data === false) { |
|
| 1014 | + throw new ShareNotFound; |
|
| 1015 | + } |
|
| 1016 | + |
|
| 1017 | + return $data; |
|
| 1018 | + } |
|
| 1019 | + |
|
| 1020 | + public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
| 1021 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 1022 | + $qb->select('*') |
|
| 1023 | + ->from('share', 's') |
|
| 1024 | + ->andWhere($qb->expr()->orX( |
|
| 1025 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 1026 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 1027 | + )) |
|
| 1028 | + ->andWhere( |
|
| 1029 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
| 1030 | + ); |
|
| 1031 | + |
|
| 1032 | + /** |
|
| 1033 | + * Reshares for this user are shares where they are the owner. |
|
| 1034 | + */ |
|
| 1035 | + if ($reshares === false) { |
|
| 1036 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
| 1037 | + } else { |
|
| 1038 | + $qb->andWhere( |
|
| 1039 | + $qb->expr()->orX( |
|
| 1040 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 1041 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 1042 | + ) |
|
| 1043 | + ); |
|
| 1044 | + } |
|
| 1045 | + |
|
| 1046 | + $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
| 1047 | + $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
| 1048 | + |
|
| 1049 | + $qb->orderBy('id'); |
|
| 1050 | + |
|
| 1051 | + $cursor = $qb->execute(); |
|
| 1052 | + $shares = []; |
|
| 1053 | + while ($data = $cursor->fetch()) { |
|
| 1054 | + $shares[$data['fileid']][] = $this->createShareObject($data); |
|
| 1055 | + } |
|
| 1056 | + $cursor->closeCursor(); |
|
| 1057 | + |
|
| 1058 | + return $shares; |
|
| 1059 | + } |
|
| 1060 | + |
|
| 1061 | + /** |
|
| 1062 | + * @inheritdoc |
|
| 1063 | + */ |
|
| 1064 | + public function getAccessList($nodes, $currentAccess) { |
|
| 1065 | + $ids = []; |
|
| 1066 | + foreach ($nodes as $node) { |
|
| 1067 | + $ids[] = $node->getId(); |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 1071 | + $qb->select('share_with') |
|
| 1072 | + ->from('share') |
|
| 1073 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 1074 | + ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 1075 | + ->andWhere($qb->expr()->orX( |
|
| 1076 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 1077 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 1078 | + )) |
|
| 1079 | + ->setMaxResults(1); |
|
| 1080 | + $cursor = $qb->execute(); |
|
| 1081 | + |
|
| 1082 | + $mail = $cursor->fetch() !== false; |
|
| 1083 | + $cursor->closeCursor(); |
|
| 1084 | + |
|
| 1085 | + return ['public' => $mail]; |
|
| 1086 | + } |
|
| 1087 | 1087 | |
| 1088 | 1088 | } |
@@ -27,73 +27,73 @@ |
||
| 27 | 27 | |
| 28 | 28 | class Hooks { |
| 29 | 29 | |
| 30 | - /** @var AccountManager */ |
|
| 31 | - private $accountManager = null; |
|
| 32 | - |
|
| 33 | - /** @var ILogger */ |
|
| 34 | - private $logger; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Hooks constructor. |
|
| 38 | - * |
|
| 39 | - * @param ILogger $logger |
|
| 40 | - */ |
|
| 41 | - public function __construct(ILogger $logger) { |
|
| 42 | - $this->logger = $logger; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * update accounts table if email address or display name was changed from outside |
|
| 47 | - * |
|
| 48 | - * @param array $params |
|
| 49 | - */ |
|
| 50 | - public function changeUserHook($params) { |
|
| 51 | - |
|
| 52 | - $accountManager = $this->getAccountManager(); |
|
| 53 | - |
|
| 54 | - /** @var IUser $user */ |
|
| 55 | - $user = isset($params['user']) ? $params['user'] : null; |
|
| 56 | - $feature = isset($params['feature']) ? $params['feature'] : null; |
|
| 57 | - $newValue = isset($params['value']) ? $params['value'] : null; |
|
| 58 | - |
|
| 59 | - if (is_null($user) || is_null($feature) || is_null($newValue)) { |
|
| 60 | - $this->logger->warning('Missing expected parameters in change user hook'); |
|
| 61 | - return; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - $accountData = $accountManager->getUser($user); |
|
| 65 | - |
|
| 66 | - switch ($feature) { |
|
| 67 | - case 'eMailAddress': |
|
| 68 | - if ($accountData[AccountManager::PROPERTY_EMAIL]['value'] !== $newValue) { |
|
| 69 | - $accountData[AccountManager::PROPERTY_EMAIL]['value'] = $newValue; |
|
| 70 | - $accountManager->updateUser($user, $accountData); |
|
| 71 | - } |
|
| 72 | - break; |
|
| 73 | - case 'displayName': |
|
| 74 | - if ($accountData[AccountManager::PROPERTY_DISPLAYNAME]['value'] !== $newValue) { |
|
| 75 | - $accountData[AccountManager::PROPERTY_DISPLAYNAME]['value'] = $newValue; |
|
| 76 | - $accountManager->updateUser($user, $accountData); |
|
| 77 | - } |
|
| 78 | - break; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * return instance of accountManager |
|
| 85 | - * |
|
| 86 | - * @return AccountManager |
|
| 87 | - */ |
|
| 88 | - protected function getAccountManager() { |
|
| 89 | - if (is_null($this->accountManager)) { |
|
| 90 | - $this->accountManager = new AccountManager( |
|
| 91 | - \OC::$server->getDatabaseConnection(), |
|
| 92 | - \OC::$server->getEventDispatcher(), |
|
| 93 | - \OC::$server->getJobList() |
|
| 94 | - ); |
|
| 95 | - } |
|
| 96 | - return $this->accountManager; |
|
| 97 | - } |
|
| 30 | + /** @var AccountManager */ |
|
| 31 | + private $accountManager = null; |
|
| 32 | + |
|
| 33 | + /** @var ILogger */ |
|
| 34 | + private $logger; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Hooks constructor. |
|
| 38 | + * |
|
| 39 | + * @param ILogger $logger |
|
| 40 | + */ |
|
| 41 | + public function __construct(ILogger $logger) { |
|
| 42 | + $this->logger = $logger; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * update accounts table if email address or display name was changed from outside |
|
| 47 | + * |
|
| 48 | + * @param array $params |
|
| 49 | + */ |
|
| 50 | + public function changeUserHook($params) { |
|
| 51 | + |
|
| 52 | + $accountManager = $this->getAccountManager(); |
|
| 53 | + |
|
| 54 | + /** @var IUser $user */ |
|
| 55 | + $user = isset($params['user']) ? $params['user'] : null; |
|
| 56 | + $feature = isset($params['feature']) ? $params['feature'] : null; |
|
| 57 | + $newValue = isset($params['value']) ? $params['value'] : null; |
|
| 58 | + |
|
| 59 | + if (is_null($user) || is_null($feature) || is_null($newValue)) { |
|
| 60 | + $this->logger->warning('Missing expected parameters in change user hook'); |
|
| 61 | + return; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + $accountData = $accountManager->getUser($user); |
|
| 65 | + |
|
| 66 | + switch ($feature) { |
|
| 67 | + case 'eMailAddress': |
|
| 68 | + if ($accountData[AccountManager::PROPERTY_EMAIL]['value'] !== $newValue) { |
|
| 69 | + $accountData[AccountManager::PROPERTY_EMAIL]['value'] = $newValue; |
|
| 70 | + $accountManager->updateUser($user, $accountData); |
|
| 71 | + } |
|
| 72 | + break; |
|
| 73 | + case 'displayName': |
|
| 74 | + if ($accountData[AccountManager::PROPERTY_DISPLAYNAME]['value'] !== $newValue) { |
|
| 75 | + $accountData[AccountManager::PROPERTY_DISPLAYNAME]['value'] = $newValue; |
|
| 76 | + $accountManager->updateUser($user, $accountData); |
|
| 77 | + } |
|
| 78 | + break; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * return instance of accountManager |
|
| 85 | + * |
|
| 86 | + * @return AccountManager |
|
| 87 | + */ |
|
| 88 | + protected function getAccountManager() { |
|
| 89 | + if (is_null($this->accountManager)) { |
|
| 90 | + $this->accountManager = new AccountManager( |
|
| 91 | + \OC::$server->getDatabaseConnection(), |
|
| 92 | + \OC::$server->getEventDispatcher(), |
|
| 93 | + \OC::$server->getJobList() |
|
| 94 | + ); |
|
| 95 | + } |
|
| 96 | + return $this->accountManager; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | 99 | } |
@@ -97,7 +97,19 @@ |
||
| 97 | 97 | <p><label for="ldap_group_display_name"><?php p($l->t('Group Display Name Field'));?></label><input type="text" id="ldap_group_display_name" name="ldap_group_display_name" data-default="<?php p($_['ldap_group_display_name_default']); ?>" title="<?php p($l->t('The LDAP attribute to use to generate the groups\'s display name.'));?>" /></p> |
| 98 | 98 | <p><label for="ldap_base_groups"><?php p($l->t('Base Group Tree'));?></label><textarea id="ldap_base_groups" name="ldap_base_groups" placeholder="<?php p($l->t('One Group Base DN per line'));?>" data-default="<?php p($_['ldap_base_groups_default']); ?>" title="<?php p($l->t('Base Group Tree'));?>"></textarea></p> |
| 99 | 99 | <p><label for="ldap_attributes_for_group_search"><?php p($l->t('Group Search Attributes'));?></label><textarea id="ldap_attributes_for_group_search" name="ldap_attributes_for_group_search" placeholder="<?php p($l->t('Optional; one attribute per line'));?>" data-default="<?php p($_['ldap_attributes_for_group_search_default']); ?>" title="<?php p($l->t('Group Search Attributes'));?>"></textarea></p> |
| 100 | - <p><label for="ldap_group_member_assoc_attribute"><?php p($l->t('Group-Member association'));?></label><select id="ldap_group_member_assoc_attribute" name="ldap_group_member_assoc_attribute" data-default="<?php p($_['ldap_group_member_assoc_attribute_default']); ?>" ><option value="uniqueMember"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'uniqueMember')) p(' selected'); ?>>uniqueMember</option><option value="memberUid"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'memberUid')) p(' selected'); ?>>memberUid</option><option value="member"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'member')) p(' selected'); ?>>member (AD)</option><option value="gidNumber"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'gidNumber')) p(' selected'); ?>>gidNumber</option></select></p> <p><label for="ldap_dynamic_group_member_url"><?php p($l->t('Dynamic Group Member URL'));?></label><input type="text" id="ldap_dynamic_group_member_url" name="ldap_dynamic_group_member_url" title="<?php p($l->t('The LDAP attribute that on group objects contains an LDAP search URL that determines what objects belong to the group. (An empty setting disables dynamic group membership functionality.)'));?>" data-default="<?php p($_['ldap_dynamic_group_member_url_default']); ?>" /></p> |
|
| 100 | + <p><label for="ldap_group_member_assoc_attribute"><?php p($l->t('Group-Member association'));?></label><select id="ldap_group_member_assoc_attribute" name="ldap_group_member_assoc_attribute" data-default="<?php p($_['ldap_group_member_assoc_attribute_default']); ?>" ><option value="uniqueMember"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'uniqueMember')) { |
|
| 101 | + p(' selected'); |
|
| 102 | +} |
|
| 103 | +?>>uniqueMember</option><option value="memberUid"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'memberUid')) { |
|
| 104 | + p(' selected'); |
|
| 105 | +} |
|
| 106 | +?>>memberUid</option><option value="member"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'member')) { |
|
| 107 | + p(' selected'); |
|
| 108 | +} |
|
| 109 | +?>>member (AD)</option><option value="gidNumber"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'gidNumber')) { |
|
| 110 | + p(' selected'); |
|
| 111 | +} |
|
| 112 | +?>>gidNumber</option></select></p> <p><label for="ldap_dynamic_group_member_url"><?php p($l->t('Dynamic Group Member URL'));?></label><input type="text" id="ldap_dynamic_group_member_url" name="ldap_dynamic_group_member_url" title="<?php p($l->t('The LDAP attribute that on group objects contains an LDAP search URL that determines what objects belong to the group. (An empty setting disables dynamic group membership functionality.)'));?>" data-default="<?php p($_['ldap_dynamic_group_member_url_default']); ?>" /></p> |
|
| 101 | 113 | <p><label for="ldap_nested_groups"><?php p($l->t('Nested Groups'));?></label><input type="checkbox" id="ldap_nested_groups" name="ldap_nested_groups" value="1" data-default="<?php p($_['ldap_nested_groups_default']); ?>" title="<?php p($l->t('When switched on, groups that contain groups are supported. (Only works if the group member attribute contains DNs.)'));?>" /></p> |
| 102 | 114 | <p><label for="ldap_paging_size"><?php p($l->t('Paging chunksize'));?></label><input type="number" id="ldap_paging_size" name="ldap_paging_size" title="<?php p($l->t('Chunksize used for paged LDAP searches that may return bulky results like user or group enumeration. (Setting it 0 disables paged LDAP searches in those situations.)'));?>" data-default="<?php p($_['ldap_paging_size_default']); ?>" /></p> |
| 103 | 115 | <p><label for="ldap_turn_on_pwd_change"><?php p($l->t('Enable LDAP password changes per user'));?></label><span class="inlinetable"><span class="tablerow left"><input type="checkbox" id="ldap_turn_on_pwd_change" name="ldap_turn_on_pwd_change" value="1" data-default="<?php p($_['ldap_turn_on_pwd_change_default']); ?>" title="<?php p($l->t('Allow LDAP users to change their password and allow Super Administrators and Group Administrators to change the password of their LDAP users. Only works when access control policies are configured accordingly on the LDAP server. As passwords are sent in plaintext to the LDAP server, transport encryption must be used and password hashing should be configured on the LDAP server.'));?>" /><span class="tablecell"><?php p($l->t('(New password is sent as plain text to LDAP)'));?></span></span> |
@@ -5,46 +5,46 @@ discard block |
||
| 5 | 5 | vendor_style('user_ldap', 'ui-multiselect/jquery.multiselect'); |
| 6 | 6 | |
| 7 | 7 | script('user_ldap', [ |
| 8 | - 'wizard/controller', |
|
| 9 | - 'wizard/configModel', |
|
| 10 | - 'wizard/view', |
|
| 11 | - 'wizard/wizardObject', |
|
| 12 | - 'wizard/wizardTabGeneric', |
|
| 13 | - 'wizard/wizardTabElementary', |
|
| 14 | - 'wizard/wizardTabAbstractFilter', |
|
| 15 | - 'wizard/wizardTabUserFilter', |
|
| 16 | - 'wizard/wizardTabLoginFilter', |
|
| 17 | - 'wizard/wizardTabGroupFilter', |
|
| 18 | - 'wizard/wizardTabAdvanced', |
|
| 19 | - 'wizard/wizardTabExpert', |
|
| 20 | - 'wizard/wizardDetectorQueue', |
|
| 21 | - 'wizard/wizardDetectorGeneric', |
|
| 22 | - 'wizard/wizardDetectorPort', |
|
| 23 | - 'wizard/wizardDetectorBaseDN', |
|
| 24 | - 'wizard/wizardDetectorFeatureAbstract', |
|
| 25 | - 'wizard/wizardDetectorUserObjectClasses', |
|
| 26 | - 'wizard/wizardDetectorGroupObjectClasses', |
|
| 27 | - 'wizard/wizardDetectorGroupsForUsers', |
|
| 28 | - 'wizard/wizardDetectorGroupsForGroups', |
|
| 29 | - 'wizard/wizardDetectorSimpleRequestAbstract', |
|
| 30 | - 'wizard/wizardDetectorFilterUser', |
|
| 31 | - 'wizard/wizardDetectorFilterLogin', |
|
| 32 | - 'wizard/wizardDetectorFilterGroup', |
|
| 33 | - 'wizard/wizardDetectorUserCount', |
|
| 34 | - 'wizard/wizardDetectorGroupCount', |
|
| 35 | - 'wizard/wizardDetectorEmailAttribute', |
|
| 36 | - 'wizard/wizardDetectorUserDisplayNameAttribute', |
|
| 37 | - 'wizard/wizardDetectorUserGroupAssociation', |
|
| 38 | - 'wizard/wizardDetectorAvailableAttributes', |
|
| 39 | - 'wizard/wizardDetectorTestAbstract', |
|
| 40 | - 'wizard/wizardDetectorTestLoginName', |
|
| 41 | - 'wizard/wizardDetectorTestBaseDN', |
|
| 42 | - 'wizard/wizardDetectorTestConfiguration', |
|
| 43 | - 'wizard/wizardDetectorClearUserMappings', |
|
| 44 | - 'wizard/wizardDetectorClearGroupMappings', |
|
| 45 | - 'wizard/wizardFilterOnType', |
|
| 46 | - 'wizard/wizardFilterOnTypeFactory', |
|
| 47 | - 'wizard/wizard' |
|
| 8 | + 'wizard/controller', |
|
| 9 | + 'wizard/configModel', |
|
| 10 | + 'wizard/view', |
|
| 11 | + 'wizard/wizardObject', |
|
| 12 | + 'wizard/wizardTabGeneric', |
|
| 13 | + 'wizard/wizardTabElementary', |
|
| 14 | + 'wizard/wizardTabAbstractFilter', |
|
| 15 | + 'wizard/wizardTabUserFilter', |
|
| 16 | + 'wizard/wizardTabLoginFilter', |
|
| 17 | + 'wizard/wizardTabGroupFilter', |
|
| 18 | + 'wizard/wizardTabAdvanced', |
|
| 19 | + 'wizard/wizardTabExpert', |
|
| 20 | + 'wizard/wizardDetectorQueue', |
|
| 21 | + 'wizard/wizardDetectorGeneric', |
|
| 22 | + 'wizard/wizardDetectorPort', |
|
| 23 | + 'wizard/wizardDetectorBaseDN', |
|
| 24 | + 'wizard/wizardDetectorFeatureAbstract', |
|
| 25 | + 'wizard/wizardDetectorUserObjectClasses', |
|
| 26 | + 'wizard/wizardDetectorGroupObjectClasses', |
|
| 27 | + 'wizard/wizardDetectorGroupsForUsers', |
|
| 28 | + 'wizard/wizardDetectorGroupsForGroups', |
|
| 29 | + 'wizard/wizardDetectorSimpleRequestAbstract', |
|
| 30 | + 'wizard/wizardDetectorFilterUser', |
|
| 31 | + 'wizard/wizardDetectorFilterLogin', |
|
| 32 | + 'wizard/wizardDetectorFilterGroup', |
|
| 33 | + 'wizard/wizardDetectorUserCount', |
|
| 34 | + 'wizard/wizardDetectorGroupCount', |
|
| 35 | + 'wizard/wizardDetectorEmailAttribute', |
|
| 36 | + 'wizard/wizardDetectorUserDisplayNameAttribute', |
|
| 37 | + 'wizard/wizardDetectorUserGroupAssociation', |
|
| 38 | + 'wizard/wizardDetectorAvailableAttributes', |
|
| 39 | + 'wizard/wizardDetectorTestAbstract', |
|
| 40 | + 'wizard/wizardDetectorTestLoginName', |
|
| 41 | + 'wizard/wizardDetectorTestBaseDN', |
|
| 42 | + 'wizard/wizardDetectorTestConfiguration', |
|
| 43 | + 'wizard/wizardDetectorClearUserMappings', |
|
| 44 | + 'wizard/wizardDetectorClearGroupMappings', |
|
| 45 | + 'wizard/wizardFilterOnType', |
|
| 46 | + 'wizard/wizardFilterOnTypeFactory', |
|
| 47 | + 'wizard/wizard' |
|
| 48 | 48 | ]); |
| 49 | 49 | |
| 50 | 50 | style('user_ldap', 'settings'); |
@@ -67,10 +67,10 @@ discard block |
||
| 67 | 67 | <li class="ldapSettingsTabs"><a href="#ldapSettings-1"><?php p($l->t('Advanced'));?></a></li> |
| 68 | 68 | </ul> |
| 69 | 69 | <?php |
| 70 | - if(!function_exists('ldap_connect')) { |
|
| 71 | - print_unescaped('<p class="ldapwarning">'.$l->t('<b>Warning:</b> The PHP LDAP module is not installed, the backend will not work. Please ask your system administrator to install it.').'</p>'); |
|
| 72 | - } |
|
| 73 | - ?> |
|
| 70 | + if(!function_exists('ldap_connect')) { |
|
| 71 | + print_unescaped('<p class="ldapwarning">'.$l->t('<b>Warning:</b> The PHP LDAP module is not installed, the backend will not work. Please ask your system administrator to install it.').'</p>'); |
|
| 72 | + } |
|
| 73 | + ?> |
|
| 74 | 74 | <?php require_once __DIR__ . '/part.wizard-server.php'; ?> |
| 75 | 75 | <?php require_once __DIR__ . '/part.wizard-userfilter.php'; ?> |
| 76 | 76 | <?php require_once __DIR__ . '/part.wizard-loginfilter.php'; ?> |
@@ -59,70 +59,70 @@ |
||
| 59 | 59 | |
| 60 | 60 | <div id="ldapSettings"> |
| 61 | 61 | <ul> |
| 62 | - <li id="#ldapWizard1"><a href="#ldapWizard1"><?php p($l->t('Server'));?></a></li> |
|
| 63 | - <li id="#ldapWizard2"><a href="#ldapWizard2"><?php p($l->t('Users'));?></a></li> |
|
| 64 | - <li id="#ldapWizard3"><a href="#ldapWizard3"><?php p($l->t('Login Attributes'));?></a></li> |
|
| 65 | - <li id="#ldapWizard4"><a href="#ldapWizard4"><?php p($l->t('Groups'));?></a></li> |
|
| 66 | - <li class="ldapSettingsTabs"><a href="#ldapSettings-2"><?php p($l->t('Expert'));?></a></li> |
|
| 67 | - <li class="ldapSettingsTabs"><a href="#ldapSettings-1"><?php p($l->t('Advanced'));?></a></li> |
|
| 62 | + <li id="#ldapWizard1"><a href="#ldapWizard1"><?php p($l->t('Server')); ?></a></li> |
|
| 63 | + <li id="#ldapWizard2"><a href="#ldapWizard2"><?php p($l->t('Users')); ?></a></li> |
|
| 64 | + <li id="#ldapWizard3"><a href="#ldapWizard3"><?php p($l->t('Login Attributes')); ?></a></li> |
|
| 65 | + <li id="#ldapWizard4"><a href="#ldapWizard4"><?php p($l->t('Groups')); ?></a></li> |
|
| 66 | + <li class="ldapSettingsTabs"><a href="#ldapSettings-2"><?php p($l->t('Expert')); ?></a></li> |
|
| 67 | + <li class="ldapSettingsTabs"><a href="#ldapSettings-1"><?php p($l->t('Advanced')); ?></a></li> |
|
| 68 | 68 | </ul> |
| 69 | 69 | <?php |
| 70 | - if(!function_exists('ldap_connect')) { |
|
| 70 | + if (!function_exists('ldap_connect')) { |
|
| 71 | 71 | print_unescaped('<p class="ldapwarning">'.$l->t('<b>Warning:</b> The PHP LDAP module is not installed, the backend will not work. Please ask your system administrator to install it.').'</p>'); |
| 72 | 72 | } |
| 73 | 73 | ?> |
| 74 | - <?php require_once __DIR__ . '/part.wizard-server.php'; ?> |
|
| 75 | - <?php require_once __DIR__ . '/part.wizard-userfilter.php'; ?> |
|
| 76 | - <?php require_once __DIR__ . '/part.wizard-loginfilter.php'; ?> |
|
| 77 | - <?php require_once __DIR__ . '/part.wizard-groupfilter.php'; ?> |
|
| 74 | + <?php require_once __DIR__.'/part.wizard-server.php'; ?> |
|
| 75 | + <?php require_once __DIR__.'/part.wizard-userfilter.php'; ?> |
|
| 76 | + <?php require_once __DIR__.'/part.wizard-loginfilter.php'; ?> |
|
| 77 | + <?php require_once __DIR__.'/part.wizard-groupfilter.php'; ?> |
|
| 78 | 78 | <fieldset id="ldapSettings-1"> |
| 79 | 79 | <div id="ldapAdvancedAccordion"> |
| 80 | - <h3><?php p($l->t('Connection Settings'));?></h3> |
|
| 80 | + <h3><?php p($l->t('Connection Settings')); ?></h3> |
|
| 81 | 81 | <div> |
| 82 | - <p><label for="ldap_configuration_active"><?php p($l->t('Configuration Active'));?></label><input type="checkbox" id="ldap_configuration_active" name="ldap_configuration_active" value="1" data-default="<?php p($_['ldap_configuration_active_default']); ?>" title="<?php p($l->t('When unchecked, this configuration will be skipped.'));?>" /></p> |
|
| 83 | - <p><label for="ldap_backup_host"><?php p($l->t('Backup (Replica) Host'));?></label><input type="text" id="ldap_backup_host" name="ldap_backup_host" data-default="<?php p($_['ldap_backup_host_default']); ?>" title="<?php p($l->t('Give an optional backup host. It must be a replica of the main LDAP/AD server.'));?>"></p> |
|
| 84 | - <p><label for="ldap_backup_port"><?php p($l->t('Backup (Replica) Port'));?></label><input type="number" id="ldap_backup_port" name="ldap_backup_port" data-default="<?php p($_['ldap_backup_port_default']); ?>" /></p> |
|
| 85 | - <p><label for="ldap_override_main_server"><?php p($l->t('Disable Main Server'));?></label><input type="checkbox" id="ldap_override_main_server" name="ldap_override_main_server" value="1" data-default="<?php p($_['ldap_override_main_server_default']); ?>" title="<?php p($l->t('Only connect to the replica server.'));?>" /></p> |
|
| 86 | - <p><label for="ldap_turn_off_cert_check"><?php p($l->t('Turn off SSL certificate validation.'));?></label><input type="checkbox" id="ldap_turn_off_cert_check" name="ldap_turn_off_cert_check" title="<?php p($l->t('Not recommended, use it for testing only! If connection only works with this option, import the LDAP server\'s SSL certificate in your %s server.', [$theme->getName()] ));?>" data-default="<?php p($_['ldap_turn_off_cert_check_default']); ?>" value="1"><br/></p> |
|
| 87 | - <p><label for="ldap_cache_ttl"><?php p($l->t('Cache Time-To-Live'));?></label><input type="number" id="ldap_cache_ttl" name="ldap_cache_ttl" title="<?php p($l->t('in seconds. A change empties the cache.'));?>" data-default="<?php p($_['ldap_cache_ttl_default']); ?>" /></p> |
|
| 82 | + <p><label for="ldap_configuration_active"><?php p($l->t('Configuration Active')); ?></label><input type="checkbox" id="ldap_configuration_active" name="ldap_configuration_active" value="1" data-default="<?php p($_['ldap_configuration_active_default']); ?>" title="<?php p($l->t('When unchecked, this configuration will be skipped.')); ?>" /></p> |
|
| 83 | + <p><label for="ldap_backup_host"><?php p($l->t('Backup (Replica) Host')); ?></label><input type="text" id="ldap_backup_host" name="ldap_backup_host" data-default="<?php p($_['ldap_backup_host_default']); ?>" title="<?php p($l->t('Give an optional backup host. It must be a replica of the main LDAP/AD server.')); ?>"></p> |
|
| 84 | + <p><label for="ldap_backup_port"><?php p($l->t('Backup (Replica) Port')); ?></label><input type="number" id="ldap_backup_port" name="ldap_backup_port" data-default="<?php p($_['ldap_backup_port_default']); ?>" /></p> |
|
| 85 | + <p><label for="ldap_override_main_server"><?php p($l->t('Disable Main Server')); ?></label><input type="checkbox" id="ldap_override_main_server" name="ldap_override_main_server" value="1" data-default="<?php p($_['ldap_override_main_server_default']); ?>" title="<?php p($l->t('Only connect to the replica server.')); ?>" /></p> |
|
| 86 | + <p><label for="ldap_turn_off_cert_check"><?php p($l->t('Turn off SSL certificate validation.')); ?></label><input type="checkbox" id="ldap_turn_off_cert_check" name="ldap_turn_off_cert_check" title="<?php p($l->t('Not recommended, use it for testing only! If connection only works with this option, import the LDAP server\'s SSL certificate in your %s server.', [$theme->getName()])); ?>" data-default="<?php p($_['ldap_turn_off_cert_check_default']); ?>" value="1"><br/></p> |
|
| 87 | + <p><label for="ldap_cache_ttl"><?php p($l->t('Cache Time-To-Live')); ?></label><input type="number" id="ldap_cache_ttl" name="ldap_cache_ttl" title="<?php p($l->t('in seconds. A change empties the cache.')); ?>" data-default="<?php p($_['ldap_cache_ttl_default']); ?>" /></p> |
|
| 88 | 88 | </div> |
| 89 | - <h3><?php p($l->t('Directory Settings'));?></h3> |
|
| 89 | + <h3><?php p($l->t('Directory Settings')); ?></h3> |
|
| 90 | 90 | <div> |
| 91 | - <p><label for="ldap_display_name"><?php p($l->t('User Display Name Field'));?></label><input type="text" id="ldap_display_name" name="ldap_display_name" data-default="<?php p($_['ldap_display_name_default']); ?>" title="<?php p($l->t('The LDAP attribute to use to generate the user\'s display name.'));?>" /></p> |
|
| 92 | - <p><label for="ldap_user_display_name_2"><?php p($l->t('2nd User Display Name Field'));?></label><input type="text" id="ldap_user_display_name_2" name="ldap_user_display_name_2" data-default="<?php p($_['ldap_user_display_name_2_default']); ?>" title="<?php p($l->t('Optional. An LDAP attribute to be added to the display name in brackets. Results in e.g. »John Doe ([email protected])«.'));?>" /></p> |
|
| 93 | - <p><label for="ldap_base_users"><?php p($l->t('Base User Tree'));?></label><textarea id="ldap_base_users" name="ldap_base_users" placeholder="<?php p($l->t('One User Base DN per line'));?>" data-default="<?php p($_['ldap_base_users_default']); ?>" title="<?php p($l->t('Base User Tree'));?>"></textarea></p> |
|
| 94 | - <p><label for="ldap_attributes_for_user_search"><?php p($l->t('User Search Attributes'));?></label><textarea id="ldap_attributes_for_user_search" name="ldap_attributes_for_user_search" placeholder="<?php p($l->t('Optional; one attribute per line'));?>" data-default="<?php p($_['ldap_attributes_for_user_search_default']); ?>" title="<?php p($l->t('User Search Attributes'));?>"></textarea></p> |
|
| 95 | - <p><label for="ldap_group_display_name"><?php p($l->t('Group Display Name Field'));?></label><input type="text" id="ldap_group_display_name" name="ldap_group_display_name" data-default="<?php p($_['ldap_group_display_name_default']); ?>" title="<?php p($l->t('The LDAP attribute to use to generate the groups\'s display name.'));?>" /></p> |
|
| 96 | - <p><label for="ldap_base_groups"><?php p($l->t('Base Group Tree'));?></label><textarea id="ldap_base_groups" name="ldap_base_groups" placeholder="<?php p($l->t('One Group Base DN per line'));?>" data-default="<?php p($_['ldap_base_groups_default']); ?>" title="<?php p($l->t('Base Group Tree'));?>"></textarea></p> |
|
| 97 | - <p><label for="ldap_attributes_for_group_search"><?php p($l->t('Group Search Attributes'));?></label><textarea id="ldap_attributes_for_group_search" name="ldap_attributes_for_group_search" placeholder="<?php p($l->t('Optional; one attribute per line'));?>" data-default="<?php p($_['ldap_attributes_for_group_search_default']); ?>" title="<?php p($l->t('Group Search Attributes'));?>"></textarea></p> |
|
| 98 | - <p><label for="ldap_group_member_assoc_attribute"><?php p($l->t('Group-Member association'));?></label><select id="ldap_group_member_assoc_attribute" name="ldap_group_member_assoc_attribute" data-default="<?php p($_['ldap_group_member_assoc_attribute_default']); ?>" ><option value="uniqueMember"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'uniqueMember')) p(' selected'); ?>>uniqueMember</option><option value="memberUid"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'memberUid')) p(' selected'); ?>>memberUid</option><option value="member"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'member')) p(' selected'); ?>>member (AD)</option><option value="gidNumber"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'gidNumber')) p(' selected'); ?>>gidNumber</option></select></p> <p><label for="ldap_dynamic_group_member_url"><?php p($l->t('Dynamic Group Member URL'));?></label><input type="text" id="ldap_dynamic_group_member_url" name="ldap_dynamic_group_member_url" title="<?php p($l->t('The LDAP attribute that on group objects contains an LDAP search URL that determines what objects belong to the group. (An empty setting disables dynamic group membership functionality.)'));?>" data-default="<?php p($_['ldap_dynamic_group_member_url_default']); ?>" /></p> |
|
| 99 | - <p><label for="ldap_nested_groups"><?php p($l->t('Nested Groups'));?></label><input type="checkbox" id="ldap_nested_groups" name="ldap_nested_groups" value="1" data-default="<?php p($_['ldap_nested_groups_default']); ?>" title="<?php p($l->t('When switched on, groups that contain groups are supported. (Only works if the group member attribute contains DNs.)'));?>" /></p> |
|
| 100 | - <p><label for="ldap_paging_size"><?php p($l->t('Paging chunksize'));?></label><input type="number" id="ldap_paging_size" name="ldap_paging_size" title="<?php p($l->t('Chunksize used for paged LDAP searches that may return bulky results like user or group enumeration. (Setting it 0 disables paged LDAP searches in those situations.)'));?>" data-default="<?php p($_['ldap_paging_size_default']); ?>" /></p> |
|
| 101 | - <p><label for="ldap_turn_on_pwd_change"><?php p($l->t('Enable LDAP password changes per user'));?></label><span class="inlinetable"><span class="tablerow left"><input type="checkbox" id="ldap_turn_on_pwd_change" name="ldap_turn_on_pwd_change" value="1" data-default="<?php p($_['ldap_turn_on_pwd_change_default']); ?>" title="<?php p($l->t('Allow LDAP users to change their password and allow Super Administrators and Group Administrators to change the password of their LDAP users. Only works when access control policies are configured accordingly on the LDAP server. As passwords are sent in plaintext to the LDAP server, transport encryption must be used and password hashing should be configured on the LDAP server.'));?>" /><span class="tablecell"><?php p($l->t('(New password is sent as plain text to LDAP)'));?></span></span> |
|
| 91 | + <p><label for="ldap_display_name"><?php p($l->t('User Display Name Field')); ?></label><input type="text" id="ldap_display_name" name="ldap_display_name" data-default="<?php p($_['ldap_display_name_default']); ?>" title="<?php p($l->t('The LDAP attribute to use to generate the user\'s display name.')); ?>" /></p> |
|
| 92 | + <p><label for="ldap_user_display_name_2"><?php p($l->t('2nd User Display Name Field')); ?></label><input type="text" id="ldap_user_display_name_2" name="ldap_user_display_name_2" data-default="<?php p($_['ldap_user_display_name_2_default']); ?>" title="<?php p($l->t('Optional. An LDAP attribute to be added to the display name in brackets. Results in e.g. »John Doe ([email protected])«.')); ?>" /></p> |
|
| 93 | + <p><label for="ldap_base_users"><?php p($l->t('Base User Tree')); ?></label><textarea id="ldap_base_users" name="ldap_base_users" placeholder="<?php p($l->t('One User Base DN per line')); ?>" data-default="<?php p($_['ldap_base_users_default']); ?>" title="<?php p($l->t('Base User Tree')); ?>"></textarea></p> |
|
| 94 | + <p><label for="ldap_attributes_for_user_search"><?php p($l->t('User Search Attributes')); ?></label><textarea id="ldap_attributes_for_user_search" name="ldap_attributes_for_user_search" placeholder="<?php p($l->t('Optional; one attribute per line')); ?>" data-default="<?php p($_['ldap_attributes_for_user_search_default']); ?>" title="<?php p($l->t('User Search Attributes')); ?>"></textarea></p> |
|
| 95 | + <p><label for="ldap_group_display_name"><?php p($l->t('Group Display Name Field')); ?></label><input type="text" id="ldap_group_display_name" name="ldap_group_display_name" data-default="<?php p($_['ldap_group_display_name_default']); ?>" title="<?php p($l->t('The LDAP attribute to use to generate the groups\'s display name.')); ?>" /></p> |
|
| 96 | + <p><label for="ldap_base_groups"><?php p($l->t('Base Group Tree')); ?></label><textarea id="ldap_base_groups" name="ldap_base_groups" placeholder="<?php p($l->t('One Group Base DN per line')); ?>" data-default="<?php p($_['ldap_base_groups_default']); ?>" title="<?php p($l->t('Base Group Tree')); ?>"></textarea></p> |
|
| 97 | + <p><label for="ldap_attributes_for_group_search"><?php p($l->t('Group Search Attributes')); ?></label><textarea id="ldap_attributes_for_group_search" name="ldap_attributes_for_group_search" placeholder="<?php p($l->t('Optional; one attribute per line')); ?>" data-default="<?php p($_['ldap_attributes_for_group_search_default']); ?>" title="<?php p($l->t('Group Search Attributes')); ?>"></textarea></p> |
|
| 98 | + <p><label for="ldap_group_member_assoc_attribute"><?php p($l->t('Group-Member association')); ?></label><select id="ldap_group_member_assoc_attribute" name="ldap_group_member_assoc_attribute" data-default="<?php p($_['ldap_group_member_assoc_attribute_default']); ?>" ><option value="uniqueMember"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'uniqueMember')) p(' selected'); ?>>uniqueMember</option><option value="memberUid"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'memberUid')) p(' selected'); ?>>memberUid</option><option value="member"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'member')) p(' selected'); ?>>member (AD)</option><option value="gidNumber"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'gidNumber')) p(' selected'); ?>>gidNumber</option></select></p> <p><label for="ldap_dynamic_group_member_url"><?php p($l->t('Dynamic Group Member URL')); ?></label><input type="text" id="ldap_dynamic_group_member_url" name="ldap_dynamic_group_member_url" title="<?php p($l->t('The LDAP attribute that on group objects contains an LDAP search URL that determines what objects belong to the group. (An empty setting disables dynamic group membership functionality.)')); ?>" data-default="<?php p($_['ldap_dynamic_group_member_url_default']); ?>" /></p> |
|
| 99 | + <p><label for="ldap_nested_groups"><?php p($l->t('Nested Groups')); ?></label><input type="checkbox" id="ldap_nested_groups" name="ldap_nested_groups" value="1" data-default="<?php p($_['ldap_nested_groups_default']); ?>" title="<?php p($l->t('When switched on, groups that contain groups are supported. (Only works if the group member attribute contains DNs.)')); ?>" /></p> |
|
| 100 | + <p><label for="ldap_paging_size"><?php p($l->t('Paging chunksize')); ?></label><input type="number" id="ldap_paging_size" name="ldap_paging_size" title="<?php p($l->t('Chunksize used for paged LDAP searches that may return bulky results like user or group enumeration. (Setting it 0 disables paged LDAP searches in those situations.)')); ?>" data-default="<?php p($_['ldap_paging_size_default']); ?>" /></p> |
|
| 101 | + <p><label for="ldap_turn_on_pwd_change"><?php p($l->t('Enable LDAP password changes per user')); ?></label><span class="inlinetable"><span class="tablerow left"><input type="checkbox" id="ldap_turn_on_pwd_change" name="ldap_turn_on_pwd_change" value="1" data-default="<?php p($_['ldap_turn_on_pwd_change_default']); ?>" title="<?php p($l->t('Allow LDAP users to change their password and allow Super Administrators and Group Administrators to change the password of their LDAP users. Only works when access control policies are configured accordingly on the LDAP server. As passwords are sent in plaintext to the LDAP server, transport encryption must be used and password hashing should be configured on the LDAP server.')); ?>" /><span class="tablecell"><?php p($l->t('(New password is sent as plain text to LDAP)')); ?></span></span> |
|
| 102 | 102 | </span><br/></p> |
| 103 | - <p><label for="ldap_default_ppolicy_dn"><?php p($l->t('Default password policy DN'));?></label><input type="text" id="ldap_default_ppolicy_dn" name="ldap_default_ppolicy_dn" title="<?php p($l->t('The DN of a default password policy that will be used for password expiry handling. Works only when LDAP password changes per user are enabled and is only supported by OpenLDAP. Leave empty to disable password expiry handling.'));?>" data-default="<?php p($_['ldap_default_ppolicy_dn_default']); ?>" /></p> |
|
| 103 | + <p><label for="ldap_default_ppolicy_dn"><?php p($l->t('Default password policy DN')); ?></label><input type="text" id="ldap_default_ppolicy_dn" name="ldap_default_ppolicy_dn" title="<?php p($l->t('The DN of a default password policy that will be used for password expiry handling. Works only when LDAP password changes per user are enabled and is only supported by OpenLDAP. Leave empty to disable password expiry handling.')); ?>" data-default="<?php p($_['ldap_default_ppolicy_dn_default']); ?>" /></p> |
|
| 104 | 104 | </div> |
| 105 | - <h3><?php p($l->t('Special Attributes'));?></h3> |
|
| 105 | + <h3><?php p($l->t('Special Attributes')); ?></h3> |
|
| 106 | 106 | <div> |
| 107 | - <p><label for="ldap_quota_attr"><?php p($l->t('Quota Field'));?></label><input type="text" id="ldap_quota_attr" name="ldap_quota_attr" data-default="<?php p($_['ldap_quota_attr_default']); ?>" title="<?php p($l->t('Leave empty for user\'s default quota. Otherwise, specify an LDAP/AD attribute.'));?>" /></p> |
|
| 108 | - <p><label for="ldap_quota_def"><?php p($l->t('Quota Default'));?></label><input type="text" id="ldap_quota_def" name="ldap_quota_def" data-default="<?php p($_['ldap_quota_def_default']); ?>" title="<?php p($l->t('Override default quota for LDAP users who do not have a quota set in the Quota Field.'));?>" /></p> |
|
| 109 | - <p><label for="ldap_email_attr"><?php p($l->t('Email Field'));?></label><input type="text" id="ldap_email_attr" name="ldap_email_attr" data-default="<?php p($_['ldap_email_attr_default']); ?>" title="<?php p($l->t('Set the user\'s email from their LDAP attribute. Leave it empty for default behaviour.'));?>" /></p> |
|
| 110 | - <p><label for="home_folder_naming_rule"><?php p($l->t('User Home Folder Naming Rule'));?></label><input type="text" id="home_folder_naming_rule" name="home_folder_naming_rule" title="<?php p($l->t('Leave empty for user name (default). Otherwise, specify an LDAP/AD attribute.'));?>" data-default="<?php p($_['home_folder_naming_rule_default']); ?>" /></p> |
|
| 107 | + <p><label for="ldap_quota_attr"><?php p($l->t('Quota Field')); ?></label><input type="text" id="ldap_quota_attr" name="ldap_quota_attr" data-default="<?php p($_['ldap_quota_attr_default']); ?>" title="<?php p($l->t('Leave empty for user\'s default quota. Otherwise, specify an LDAP/AD attribute.')); ?>" /></p> |
|
| 108 | + <p><label for="ldap_quota_def"><?php p($l->t('Quota Default')); ?></label><input type="text" id="ldap_quota_def" name="ldap_quota_def" data-default="<?php p($_['ldap_quota_def_default']); ?>" title="<?php p($l->t('Override default quota for LDAP users who do not have a quota set in the Quota Field.')); ?>" /></p> |
|
| 109 | + <p><label for="ldap_email_attr"><?php p($l->t('Email Field')); ?></label><input type="text" id="ldap_email_attr" name="ldap_email_attr" data-default="<?php p($_['ldap_email_attr_default']); ?>" title="<?php p($l->t('Set the user\'s email from their LDAP attribute. Leave it empty for default behaviour.')); ?>" /></p> |
|
| 110 | + <p><label for="home_folder_naming_rule"><?php p($l->t('User Home Folder Naming Rule')); ?></label><input type="text" id="home_folder_naming_rule" name="home_folder_naming_rule" title="<?php p($l->t('Leave empty for user name (default). Otherwise, specify an LDAP/AD attribute.')); ?>" data-default="<?php p($_['home_folder_naming_rule_default']); ?>" /></p> |
|
| 111 | 111 | </div> |
| 112 | 112 | </div> |
| 113 | 113 | <?php print_unescaped($_['settingControls']); ?> |
| 114 | 114 | </fieldset> |
| 115 | 115 | <fieldset id="ldapSettings-2"> |
| 116 | - <p><strong><?php p($l->t('Internal Username'));?></strong></p> |
|
| 117 | - <p class="ldapIndent"><?php p($l->t('By default the internal username will be created from the UUID attribute. It makes sure that the username is unique and characters do not need to be converted. The internal username has the restriction that only these characters are allowed: [ a-zA-Z0-9_.@- ]. Other characters are replaced with their ASCII correspondence or simply omitted. On collisions a number will be added/increased. The internal username is used to identify a user internally. It is also the default name for the user home folder. It is also a part of remote URLs, for instance for all *DAV services. With this setting, the default behavior can be overridden. Leave it empty for default behavior. Changes will have effect only on newly mapped (added) LDAP users.'));?></p> |
|
| 118 | - <p class="ldapIndent"><label for="ldap_expert_username_attr"><?php p($l->t('Internal Username Attribute:'));?></label><input type="text" id="ldap_expert_username_attr" name="ldap_expert_username_attr" data-default="<?php p($_['ldap_expert_username_attr_default']); ?>" /></p> |
|
| 119 | - <p><strong><?php p($l->t('Override UUID detection'));?></strong></p> |
|
| 120 | - <p class="ldapIndent"><?php p($l->t('By default, the UUID attribute is automatically detected. The UUID attribute is used to doubtlessly identify LDAP users and groups. Also, the internal username will be created based on the UUID, if not specified otherwise above. You can override the setting and pass an attribute of your choice. You must make sure that the attribute of your choice can be fetched for both users and groups and it is unique. Leave it empty for default behavior. Changes will have effect only on newly mapped (added) LDAP users and groups.'));?></p> |
|
| 121 | - <p class="ldapIndent"><label for="ldap_expert_uuid_user_attr"><?php p($l->t('UUID Attribute for Users:'));?></label><input type="text" id="ldap_expert_uuid_user_attr" name="ldap_expert_uuid_user_attr" data-default="<?php p($_['ldap_expert_uuid_user_attr_default']); ?>" /></p> |
|
| 122 | - <p class="ldapIndent"><label for="ldap_expert_uuid_group_attr"><?php p($l->t('UUID Attribute for Groups:'));?></label><input type="text" id="ldap_expert_uuid_group_attr" name="ldap_expert_uuid_group_attr" data-default="<?php p($_['ldap_expert_uuid_group_attr_default']); ?>" /></p> |
|
| 123 | - <p><strong><?php p($l->t('Username-LDAP User Mapping'));?></strong></p> |
|
| 124 | - <p class="ldapIndent"><?php p($l->t('Usernames are used to store and assign metadata. In order to precisely identify and recognize users, each LDAP user will have an internal username. This requires a mapping from username to LDAP user. The created username is mapped to the UUID of the LDAP user. Additionally the DN is cached as well to reduce LDAP interaction, but it is not used for identification. If the DN changes, the changes will be found. The internal username is used all over. Clearing the mappings will have leftovers everywhere. Clearing the mappings is not configuration sensitive, it affects all LDAP configurations! Never clear the mappings in a production environment, only in a testing or experimental stage.'));?></p> |
|
| 125 | - <p class="ldapIndent"><button type="button" id="ldap_action_clear_user_mappings" name="ldap_action_clear_user_mappings"><?php p($l->t('Clear Username-LDAP User Mapping'));?></button><br/><button type="button" id="ldap_action_clear_group_mappings" name="ldap_action_clear_group_mappings"><?php p($l->t('Clear Groupname-LDAP Group Mapping'));?></button></p> |
|
| 116 | + <p><strong><?php p($l->t('Internal Username')); ?></strong></p> |
|
| 117 | + <p class="ldapIndent"><?php p($l->t('By default the internal username will be created from the UUID attribute. It makes sure that the username is unique and characters do not need to be converted. The internal username has the restriction that only these characters are allowed: [ a-zA-Z0-9_.@- ]. Other characters are replaced with their ASCII correspondence or simply omitted. On collisions a number will be added/increased. The internal username is used to identify a user internally. It is also the default name for the user home folder. It is also a part of remote URLs, for instance for all *DAV services. With this setting, the default behavior can be overridden. Leave it empty for default behavior. Changes will have effect only on newly mapped (added) LDAP users.')); ?></p> |
|
| 118 | + <p class="ldapIndent"><label for="ldap_expert_username_attr"><?php p($l->t('Internal Username Attribute:')); ?></label><input type="text" id="ldap_expert_username_attr" name="ldap_expert_username_attr" data-default="<?php p($_['ldap_expert_username_attr_default']); ?>" /></p> |
|
| 119 | + <p><strong><?php p($l->t('Override UUID detection')); ?></strong></p> |
|
| 120 | + <p class="ldapIndent"><?php p($l->t('By default, the UUID attribute is automatically detected. The UUID attribute is used to doubtlessly identify LDAP users and groups. Also, the internal username will be created based on the UUID, if not specified otherwise above. You can override the setting and pass an attribute of your choice. You must make sure that the attribute of your choice can be fetched for both users and groups and it is unique. Leave it empty for default behavior. Changes will have effect only on newly mapped (added) LDAP users and groups.')); ?></p> |
|
| 121 | + <p class="ldapIndent"><label for="ldap_expert_uuid_user_attr"><?php p($l->t('UUID Attribute for Users:')); ?></label><input type="text" id="ldap_expert_uuid_user_attr" name="ldap_expert_uuid_user_attr" data-default="<?php p($_['ldap_expert_uuid_user_attr_default']); ?>" /></p> |
|
| 122 | + <p class="ldapIndent"><label for="ldap_expert_uuid_group_attr"><?php p($l->t('UUID Attribute for Groups:')); ?></label><input type="text" id="ldap_expert_uuid_group_attr" name="ldap_expert_uuid_group_attr" data-default="<?php p($_['ldap_expert_uuid_group_attr_default']); ?>" /></p> |
|
| 123 | + <p><strong><?php p($l->t('Username-LDAP User Mapping')); ?></strong></p> |
|
| 124 | + <p class="ldapIndent"><?php p($l->t('Usernames are used to store and assign metadata. In order to precisely identify and recognize users, each LDAP user will have an internal username. This requires a mapping from username to LDAP user. The created username is mapped to the UUID of the LDAP user. Additionally the DN is cached as well to reduce LDAP interaction, but it is not used for identification. If the DN changes, the changes will be found. The internal username is used all over. Clearing the mappings will have leftovers everywhere. Clearing the mappings is not configuration sensitive, it affects all LDAP configurations! Never clear the mappings in a production environment, only in a testing or experimental stage.')); ?></p> |
|
| 125 | + <p class="ldapIndent"><button type="button" id="ldap_action_clear_user_mappings" name="ldap_action_clear_user_mappings"><?php p($l->t('Clear Username-LDAP User Mapping')); ?></button><br/><button type="button" id="ldap_action_clear_group_mappings" name="ldap_action_clear_group_mappings"><?php p($l->t('Clear Groupname-LDAP Group Mapping')); ?></button></p> |
|
| 126 | 126 | <?php print_unescaped($_['settingControls']); ?> |
| 127 | 127 | </fieldset> |
| 128 | 128 | </div> |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | $offset = $arguments['offset']; |
| 70 | 70 | $stopAt = $arguments['stopAt']; |
| 71 | 71 | |
| 72 | - $this->logger->info('Building calendar index (' . $offset .'/' . $stopAt . ')'); |
|
| 72 | + $this->logger->info('Building calendar index ('.$offset.'/'.$stopAt.')'); |
|
| 73 | 73 | |
| 74 | 74 | $offset = $this->buildIndex($offset, $stopAt); |
| 75 | 75 | |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | 'offset' => $offset, |
| 81 | 81 | 'stopAt' => $stopAt |
| 82 | 82 | ]); |
| 83 | - $this->logger->info('New building calendar index job scheduled with offset ' . $offset); |
|
| 83 | + $this->logger->info('New building calendar index job scheduled with offset '.$offset); |
|
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | ->orderBy('id', 'ASC'); |
| 101 | 101 | |
| 102 | 102 | $stmt = $query->execute(); |
| 103 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 103 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 104 | 104 | $offset = $row['id']; |
| 105 | 105 | |
| 106 | 106 | $calendarData = $row['calendardata']; |
@@ -31,90 +31,90 @@ |
||
| 31 | 31 | |
| 32 | 32 | class BuildCalendarSearchIndexBackgroundJob extends QueuedJob { |
| 33 | 33 | |
| 34 | - /** @var IDBConnection */ |
|
| 35 | - private $db; |
|
| 36 | - |
|
| 37 | - /** @var CalDavBackend */ |
|
| 38 | - private $calDavBackend; |
|
| 39 | - |
|
| 40 | - /** @var ILogger */ |
|
| 41 | - private $logger; |
|
| 42 | - |
|
| 43 | - /** @var IJobList */ |
|
| 44 | - private $jobList; |
|
| 45 | - |
|
| 46 | - /** @var ITimeFactory */ |
|
| 47 | - private $timeFactory; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @param IDBConnection $db |
|
| 51 | - * @param CalDavBackend $calDavBackend |
|
| 52 | - * @param ILogger $logger |
|
| 53 | - * @param IJobList $jobList |
|
| 54 | - * @param ITimeFactory $timeFactory |
|
| 55 | - */ |
|
| 56 | - public function __construct(IDBConnection $db, |
|
| 57 | - CalDavBackend $calDavBackend, |
|
| 58 | - ILogger $logger, |
|
| 59 | - IJobList $jobList, |
|
| 60 | - ITimeFactory $timeFactory) { |
|
| 61 | - $this->db = $db; |
|
| 62 | - $this->calDavBackend = $calDavBackend; |
|
| 63 | - $this->logger = $logger; |
|
| 64 | - $this->jobList = $jobList; |
|
| 65 | - $this->timeFactory = $timeFactory; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public function run($arguments) { |
|
| 69 | - $offset = $arguments['offset']; |
|
| 70 | - $stopAt = $arguments['stopAt']; |
|
| 71 | - |
|
| 72 | - $this->logger->info('Building calendar index (' . $offset .'/' . $stopAt . ')'); |
|
| 73 | - |
|
| 74 | - $offset = $this->buildIndex($offset, $stopAt); |
|
| 75 | - |
|
| 76 | - if ($offset >= $stopAt) { |
|
| 77 | - $this->logger->info('Building calendar index done'); |
|
| 78 | - } else { |
|
| 79 | - $this->jobList->add(self::class, [ |
|
| 80 | - 'offset' => $offset, |
|
| 81 | - 'stopAt' => $stopAt |
|
| 82 | - ]); |
|
| 83 | - $this->logger->info('New building calendar index job scheduled with offset ' . $offset); |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @param int $offset |
|
| 89 | - * @param int $stopAt |
|
| 90 | - * @return int |
|
| 91 | - */ |
|
| 92 | - private function buildIndex($offset, $stopAt) { |
|
| 93 | - $startTime = $this->timeFactory->getTime(); |
|
| 94 | - |
|
| 95 | - $query = $this->db->getQueryBuilder(); |
|
| 96 | - $query->select(['id', 'calendarid', 'uri', 'calendardata']) |
|
| 97 | - ->from('calendarobjects') |
|
| 98 | - ->where($query->expr()->lte('id', $query->createNamedParameter($stopAt))) |
|
| 99 | - ->andWhere($query->expr()->gt('id', $query->createNamedParameter($offset))) |
|
| 100 | - ->orderBy('id', 'ASC'); |
|
| 101 | - |
|
| 102 | - $stmt = $query->execute(); |
|
| 103 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 104 | - $offset = $row['id']; |
|
| 105 | - |
|
| 106 | - $calendarData = $row['calendardata']; |
|
| 107 | - if (is_resource($calendarData)) { |
|
| 108 | - $calendarData = stream_get_contents($calendarData); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $this->calDavBackend->updateProperties($row['calendarid'], $row['uri'], $calendarData); |
|
| 112 | - |
|
| 113 | - if (($this->timeFactory->getTime() - $startTime) > 15) { |
|
| 114 | - return $offset; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - return $stopAt; |
|
| 119 | - } |
|
| 34 | + /** @var IDBConnection */ |
|
| 35 | + private $db; |
|
| 36 | + |
|
| 37 | + /** @var CalDavBackend */ |
|
| 38 | + private $calDavBackend; |
|
| 39 | + |
|
| 40 | + /** @var ILogger */ |
|
| 41 | + private $logger; |
|
| 42 | + |
|
| 43 | + /** @var IJobList */ |
|
| 44 | + private $jobList; |
|
| 45 | + |
|
| 46 | + /** @var ITimeFactory */ |
|
| 47 | + private $timeFactory; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @param IDBConnection $db |
|
| 51 | + * @param CalDavBackend $calDavBackend |
|
| 52 | + * @param ILogger $logger |
|
| 53 | + * @param IJobList $jobList |
|
| 54 | + * @param ITimeFactory $timeFactory |
|
| 55 | + */ |
|
| 56 | + public function __construct(IDBConnection $db, |
|
| 57 | + CalDavBackend $calDavBackend, |
|
| 58 | + ILogger $logger, |
|
| 59 | + IJobList $jobList, |
|
| 60 | + ITimeFactory $timeFactory) { |
|
| 61 | + $this->db = $db; |
|
| 62 | + $this->calDavBackend = $calDavBackend; |
|
| 63 | + $this->logger = $logger; |
|
| 64 | + $this->jobList = $jobList; |
|
| 65 | + $this->timeFactory = $timeFactory; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public function run($arguments) { |
|
| 69 | + $offset = $arguments['offset']; |
|
| 70 | + $stopAt = $arguments['stopAt']; |
|
| 71 | + |
|
| 72 | + $this->logger->info('Building calendar index (' . $offset .'/' . $stopAt . ')'); |
|
| 73 | + |
|
| 74 | + $offset = $this->buildIndex($offset, $stopAt); |
|
| 75 | + |
|
| 76 | + if ($offset >= $stopAt) { |
|
| 77 | + $this->logger->info('Building calendar index done'); |
|
| 78 | + } else { |
|
| 79 | + $this->jobList->add(self::class, [ |
|
| 80 | + 'offset' => $offset, |
|
| 81 | + 'stopAt' => $stopAt |
|
| 82 | + ]); |
|
| 83 | + $this->logger->info('New building calendar index job scheduled with offset ' . $offset); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @param int $offset |
|
| 89 | + * @param int $stopAt |
|
| 90 | + * @return int |
|
| 91 | + */ |
|
| 92 | + private function buildIndex($offset, $stopAt) { |
|
| 93 | + $startTime = $this->timeFactory->getTime(); |
|
| 94 | + |
|
| 95 | + $query = $this->db->getQueryBuilder(); |
|
| 96 | + $query->select(['id', 'calendarid', 'uri', 'calendardata']) |
|
| 97 | + ->from('calendarobjects') |
|
| 98 | + ->where($query->expr()->lte('id', $query->createNamedParameter($stopAt))) |
|
| 99 | + ->andWhere($query->expr()->gt('id', $query->createNamedParameter($offset))) |
|
| 100 | + ->orderBy('id', 'ASC'); |
|
| 101 | + |
|
| 102 | + $stmt = $query->execute(); |
|
| 103 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 104 | + $offset = $row['id']; |
|
| 105 | + |
|
| 106 | + $calendarData = $row['calendardata']; |
|
| 107 | + if (is_resource($calendarData)) { |
|
| 108 | + $calendarData = stream_get_contents($calendarData); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $this->calDavBackend->updateProperties($row['calendarid'], $row['uri'], $calendarData); |
|
| 112 | + |
|
| 113 | + if (($this->timeFactory->getTime() - $startTime) > 15) { |
|
| 114 | + return $offset; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + return $stopAt; |
|
| 119 | + } |
|
| 120 | 120 | } |
@@ -30,57 +30,57 @@ |
||
| 30 | 30 | |
| 31 | 31 | class BuildCalendarSearchIndex implements IRepairStep { |
| 32 | 32 | |
| 33 | - /** @var IDBConnection */ |
|
| 34 | - private $db; |
|
| 33 | + /** @var IDBConnection */ |
|
| 34 | + private $db; |
|
| 35 | 35 | |
| 36 | - /** @var IJobList */ |
|
| 37 | - private $jobList; |
|
| 36 | + /** @var IJobList */ |
|
| 37 | + private $jobList; |
|
| 38 | 38 | |
| 39 | - /** @var IConfig */ |
|
| 40 | - private $config; |
|
| 39 | + /** @var IConfig */ |
|
| 40 | + private $config; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @param IDBConnection $db |
|
| 44 | - * @param IJobList $jobList |
|
| 45 | - * @param IConfig $config |
|
| 46 | - */ |
|
| 47 | - public function __construct(IDBConnection $db, |
|
| 48 | - IJobList $jobList, |
|
| 49 | - IConfig $config) { |
|
| 50 | - $this->db = $db; |
|
| 51 | - $this->jobList = $jobList; |
|
| 52 | - $this->config = $config; |
|
| 53 | - } |
|
| 42 | + /** |
|
| 43 | + * @param IDBConnection $db |
|
| 44 | + * @param IJobList $jobList |
|
| 45 | + * @param IConfig $config |
|
| 46 | + */ |
|
| 47 | + public function __construct(IDBConnection $db, |
|
| 48 | + IJobList $jobList, |
|
| 49 | + IConfig $config) { |
|
| 50 | + $this->db = $db; |
|
| 51 | + $this->jobList = $jobList; |
|
| 52 | + $this->config = $config; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @return string |
|
| 57 | - */ |
|
| 58 | - public function getName() { |
|
| 59 | - return 'Registering building of calendar search index as background job'; |
|
| 60 | - } |
|
| 55 | + /** |
|
| 56 | + * @return string |
|
| 57 | + */ |
|
| 58 | + public function getName() { |
|
| 59 | + return 'Registering building of calendar search index as background job'; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @param IOutput $output |
|
| 64 | - */ |
|
| 65 | - public function run(IOutput $output) { |
|
| 66 | - // only run once |
|
| 67 | - if ($this->config->getAppValue('dav', 'buildCalendarSearchIndex') === 'yes') { |
|
| 68 | - $output->info('Repair step already executed'); |
|
| 69 | - return; |
|
| 70 | - } |
|
| 62 | + /** |
|
| 63 | + * @param IOutput $output |
|
| 64 | + */ |
|
| 65 | + public function run(IOutput $output) { |
|
| 66 | + // only run once |
|
| 67 | + if ($this->config->getAppValue('dav', 'buildCalendarSearchIndex') === 'yes') { |
|
| 68 | + $output->info('Repair step already executed'); |
|
| 69 | + return; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - $query = $this->db->getQueryBuilder(); |
|
| 73 | - $query->select($query->createFunction('MAX(id)')) |
|
| 74 | - ->from('calendarobjects'); |
|
| 75 | - $maxId = (int)$query->execute()->fetchColumn(); |
|
| 72 | + $query = $this->db->getQueryBuilder(); |
|
| 73 | + $query->select($query->createFunction('MAX(id)')) |
|
| 74 | + ->from('calendarobjects'); |
|
| 75 | + $maxId = (int)$query->execute()->fetchColumn(); |
|
| 76 | 76 | |
| 77 | - $output->info('Add background job'); |
|
| 78 | - $this->jobList->add(BuildCalendarSearchIndexBackgroundJob::class, [ |
|
| 79 | - 'offset' => 0, |
|
| 80 | - 'stopAt' => $maxId |
|
| 81 | - ]); |
|
| 77 | + $output->info('Add background job'); |
|
| 78 | + $this->jobList->add(BuildCalendarSearchIndexBackgroundJob::class, [ |
|
| 79 | + 'offset' => 0, |
|
| 80 | + 'stopAt' => $maxId |
|
| 81 | + ]); |
|
| 82 | 82 | |
| 83 | - // if all were done, no need to redo the repair during next upgrade |
|
| 84 | - $this->config->setAppValue('dav', 'buildCalendarSearchIndex', 'yes'); |
|
| 85 | - } |
|
| 83 | + // if all were done, no need to redo the repair during next upgrade |
|
| 84 | + $this->config->setAppValue('dav', 'buildCalendarSearchIndex', 'yes'); |
|
| 85 | + } |
|
| 86 | 86 | } |
| 87 | 87 | \ No newline at end of file |
@@ -72,7 +72,7 @@ |
||
| 72 | 72 | $query = $this->db->getQueryBuilder(); |
| 73 | 73 | $query->select($query->createFunction('MAX(id)')) |
| 74 | 74 | ->from('calendarobjects'); |
| 75 | - $maxId = (int)$query->execute()->fetchColumn(); |
|
| 75 | + $maxId = (int) $query->execute()->fetchColumn(); |
|
| 76 | 76 | |
| 77 | 77 | $output->info('Add background job'); |
| 78 | 78 | $this->jobList->add(BuildCalendarSearchIndexBackgroundJob::class, [ |
@@ -11,9 +11,9 @@ |
||
| 11 | 11 | <p class="settings-hint"><?php p($l->t('Allows users to share a personalized link to a file or folder by putting in an email address.')); ?></p> |
| 12 | 12 | |
| 13 | 13 | <p> |
| 14 | - <input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if($_['sendPasswordMail']) p('checked'); ?> /> |
|
| 14 | + <input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if ($_['sendPasswordMail']) p('checked'); ?> /> |
|
| 15 | 15 | <label for="sendPasswordMail"><?php p($l->t('Send password by mail')); ?></label><br/> |
| 16 | - <input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if($_['enforcePasswordProtection']) p('checked'); ?> /> |
|
| 16 | + <input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if ($_['enforcePasswordProtection']) p('checked'); ?> /> |
|
| 17 | 17 | <label for="enforcePasswordProtection"><?php p($l->t('Enforce password protection')); ?></label> |
| 18 | 18 | </p> |
| 19 | 19 | |
@@ -11,9 +11,15 @@ |
||
| 11 | 11 | <p class="settings-hint"><?php p($l->t('Allows users to share a personalized link to a file or folder by putting in an email address.')); ?></p> |
| 12 | 12 | |
| 13 | 13 | <p> |
| 14 | - <input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if($_['sendPasswordMail']) p('checked'); ?> /> |
|
| 14 | + <input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if($_['sendPasswordMail']) { |
|
| 15 | + p('checked'); |
|
| 16 | +} |
|
| 17 | +?> /> |
|
| 15 | 18 | <label for="sendPasswordMail"><?php p($l->t('Send password by mail')); ?></label><br/> |
| 16 | - <input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if($_['enforcePasswordProtection']) p('checked'); ?> /> |
|
| 19 | + <input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if($_['enforcePasswordProtection']) { |
|
| 20 | + p('checked'); |
|
| 21 | +} |
|
| 22 | +?> /> |
|
| 17 | 23 | <label for="enforcePasswordProtection"><?php p($l->t('Enforce password protection')); ?></label> |
| 18 | 24 | </p> |
| 19 | 25 | |
@@ -220,9 +220,9 @@ discard block |
||
| 220 | 220 | )) { |
| 221 | 221 | // note: pre-fetching only supported for depth <= 1 |
| 222 | 222 | $folderContent = $node->getChildren(); |
| 223 | - $fileIds[] = (int)$node->getId(); |
|
| 223 | + $fileIds[] = (int) $node->getId(); |
|
| 224 | 224 | foreach ($folderContent as $info) { |
| 225 | - $fileIds[] = (int)$info->getId(); |
|
| 225 | + $fileIds[] = (int) $info->getId(); |
|
| 226 | 226 | } |
| 227 | 227 | $tags = $this->getTagger()->getTagsForObjects($fileIds); |
| 228 | 228 | if ($tags === false) { |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | }); |
| 279 | 279 | |
| 280 | 280 | $propPatch->handle(self::FAVORITE_PROPERTYNAME, function($favState) use ($node) { |
| 281 | - if ((int)$favState === 1 || $favState === 'true') { |
|
| 281 | + if ((int) $favState === 1 || $favState === 'true') { |
|
| 282 | 282 | $this->getTagger()->tagAs($node->getId(), self::TAG_FAVORITE); |
| 283 | 283 | } else { |
| 284 | 284 | $this->getTagger()->unTag($node->getId(), self::TAG_FAVORITE); |
@@ -51,246 +51,246 @@ |
||
| 51 | 51 | class TagsPlugin extends \Sabre\DAV\ServerPlugin |
| 52 | 52 | { |
| 53 | 53 | |
| 54 | - // namespace |
|
| 55 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 56 | - const TAGS_PROPERTYNAME = '{http://owncloud.org/ns}tags'; |
|
| 57 | - const FAVORITE_PROPERTYNAME = '{http://owncloud.org/ns}favorite'; |
|
| 58 | - const TAG_FAVORITE = '_$!<Favorite>!$_'; |
|
| 54 | + // namespace |
|
| 55 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 56 | + const TAGS_PROPERTYNAME = '{http://owncloud.org/ns}tags'; |
|
| 57 | + const FAVORITE_PROPERTYNAME = '{http://owncloud.org/ns}favorite'; |
|
| 58 | + const TAG_FAVORITE = '_$!<Favorite>!$_'; |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Reference to main server object |
|
| 62 | - * |
|
| 63 | - * @var \Sabre\DAV\Server |
|
| 64 | - */ |
|
| 65 | - private $server; |
|
| 60 | + /** |
|
| 61 | + * Reference to main server object |
|
| 62 | + * |
|
| 63 | + * @var \Sabre\DAV\Server |
|
| 64 | + */ |
|
| 65 | + private $server; |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @var \OCP\ITagManager |
|
| 69 | - */ |
|
| 70 | - private $tagManager; |
|
| 67 | + /** |
|
| 68 | + * @var \OCP\ITagManager |
|
| 69 | + */ |
|
| 70 | + private $tagManager; |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @var \OCP\ITags |
|
| 74 | - */ |
|
| 75 | - private $tagger; |
|
| 72 | + /** |
|
| 73 | + * @var \OCP\ITags |
|
| 74 | + */ |
|
| 75 | + private $tagger; |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Array of file id to tags array |
|
| 79 | - * The null value means the cache wasn't initialized. |
|
| 80 | - * |
|
| 81 | - * @var array |
|
| 82 | - */ |
|
| 83 | - private $cachedTags; |
|
| 77 | + /** |
|
| 78 | + * Array of file id to tags array |
|
| 79 | + * The null value means the cache wasn't initialized. |
|
| 80 | + * |
|
| 81 | + * @var array |
|
| 82 | + */ |
|
| 83 | + private $cachedTags; |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * @var \Sabre\DAV\Tree |
|
| 87 | - */ |
|
| 88 | - private $tree; |
|
| 85 | + /** |
|
| 86 | + * @var \Sabre\DAV\Tree |
|
| 87 | + */ |
|
| 88 | + private $tree; |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * @param \Sabre\DAV\Tree $tree tree |
|
| 92 | - * @param \OCP\ITagManager $tagManager tag manager |
|
| 93 | - */ |
|
| 94 | - public function __construct(\Sabre\DAV\Tree $tree, \OCP\ITagManager $tagManager) { |
|
| 95 | - $this->tree = $tree; |
|
| 96 | - $this->tagManager = $tagManager; |
|
| 97 | - $this->tagger = null; |
|
| 98 | - $this->cachedTags = array(); |
|
| 99 | - } |
|
| 90 | + /** |
|
| 91 | + * @param \Sabre\DAV\Tree $tree tree |
|
| 92 | + * @param \OCP\ITagManager $tagManager tag manager |
|
| 93 | + */ |
|
| 94 | + public function __construct(\Sabre\DAV\Tree $tree, \OCP\ITagManager $tagManager) { |
|
| 95 | + $this->tree = $tree; |
|
| 96 | + $this->tagManager = $tagManager; |
|
| 97 | + $this->tagger = null; |
|
| 98 | + $this->cachedTags = array(); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * This initializes the plugin. |
|
| 103 | - * |
|
| 104 | - * This function is called by \Sabre\DAV\Server, after |
|
| 105 | - * addPlugin is called. |
|
| 106 | - * |
|
| 107 | - * This method should set up the required event subscriptions. |
|
| 108 | - * |
|
| 109 | - * @param \Sabre\DAV\Server $server |
|
| 110 | - * @return void |
|
| 111 | - */ |
|
| 112 | - public function initialize(\Sabre\DAV\Server $server) { |
|
| 101 | + /** |
|
| 102 | + * This initializes the plugin. |
|
| 103 | + * |
|
| 104 | + * This function is called by \Sabre\DAV\Server, after |
|
| 105 | + * addPlugin is called. |
|
| 106 | + * |
|
| 107 | + * This method should set up the required event subscriptions. |
|
| 108 | + * |
|
| 109 | + * @param \Sabre\DAV\Server $server |
|
| 110 | + * @return void |
|
| 111 | + */ |
|
| 112 | + public function initialize(\Sabre\DAV\Server $server) { |
|
| 113 | 113 | |
| 114 | - $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
| 115 | - $server->xml->elementMap[self::TAGS_PROPERTYNAME] = TagList::class; |
|
| 114 | + $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
| 115 | + $server->xml->elementMap[self::TAGS_PROPERTYNAME] = TagList::class; |
|
| 116 | 116 | |
| 117 | - $this->server = $server; |
|
| 118 | - $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
| 119 | - $this->server->on('propPatch', array($this, 'handleUpdateProperties')); |
|
| 120 | - } |
|
| 117 | + $this->server = $server; |
|
| 118 | + $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
| 119 | + $this->server->on('propPatch', array($this, 'handleUpdateProperties')); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Returns the tagger |
|
| 124 | - * |
|
| 125 | - * @return \OCP\ITags tagger |
|
| 126 | - */ |
|
| 127 | - private function getTagger() { |
|
| 128 | - if (!$this->tagger) { |
|
| 129 | - $this->tagger = $this->tagManager->load('files'); |
|
| 130 | - } |
|
| 131 | - return $this->tagger; |
|
| 132 | - } |
|
| 122 | + /** |
|
| 123 | + * Returns the tagger |
|
| 124 | + * |
|
| 125 | + * @return \OCP\ITags tagger |
|
| 126 | + */ |
|
| 127 | + private function getTagger() { |
|
| 128 | + if (!$this->tagger) { |
|
| 129 | + $this->tagger = $this->tagManager->load('files'); |
|
| 130 | + } |
|
| 131 | + return $this->tagger; |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - /** |
|
| 135 | - * Returns tags and favorites. |
|
| 136 | - * |
|
| 137 | - * @param integer $fileId file id |
|
| 138 | - * @return array list($tags, $favorite) with $tags as tag array |
|
| 139 | - * and $favorite is a boolean whether the file was favorited |
|
| 140 | - */ |
|
| 141 | - private function getTagsAndFav($fileId) { |
|
| 142 | - $isFav = false; |
|
| 143 | - $tags = $this->getTags($fileId); |
|
| 144 | - if ($tags) { |
|
| 145 | - $favPos = array_search(self::TAG_FAVORITE, $tags); |
|
| 146 | - if ($favPos !== false) { |
|
| 147 | - $isFav = true; |
|
| 148 | - unset($tags[$favPos]); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - return array($tags, $isFav); |
|
| 152 | - } |
|
| 134 | + /** |
|
| 135 | + * Returns tags and favorites. |
|
| 136 | + * |
|
| 137 | + * @param integer $fileId file id |
|
| 138 | + * @return array list($tags, $favorite) with $tags as tag array |
|
| 139 | + * and $favorite is a boolean whether the file was favorited |
|
| 140 | + */ |
|
| 141 | + private function getTagsAndFav($fileId) { |
|
| 142 | + $isFav = false; |
|
| 143 | + $tags = $this->getTags($fileId); |
|
| 144 | + if ($tags) { |
|
| 145 | + $favPos = array_search(self::TAG_FAVORITE, $tags); |
|
| 146 | + if ($favPos !== false) { |
|
| 147 | + $isFav = true; |
|
| 148 | + unset($tags[$favPos]); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + return array($tags, $isFav); |
|
| 152 | + } |
|
| 153 | 153 | |
| 154 | - /** |
|
| 155 | - * Returns tags for the given file id |
|
| 156 | - * |
|
| 157 | - * @param integer $fileId file id |
|
| 158 | - * @return array list of tags for that file |
|
| 159 | - */ |
|
| 160 | - private function getTags($fileId) { |
|
| 161 | - if (isset($this->cachedTags[$fileId])) { |
|
| 162 | - return $this->cachedTags[$fileId]; |
|
| 163 | - } else { |
|
| 164 | - $tags = $this->getTagger()->getTagsForObjects(array($fileId)); |
|
| 165 | - if ($tags !== false) { |
|
| 166 | - if (empty($tags)) { |
|
| 167 | - return array(); |
|
| 168 | - } |
|
| 169 | - return current($tags); |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - return null; |
|
| 173 | - } |
|
| 154 | + /** |
|
| 155 | + * Returns tags for the given file id |
|
| 156 | + * |
|
| 157 | + * @param integer $fileId file id |
|
| 158 | + * @return array list of tags for that file |
|
| 159 | + */ |
|
| 160 | + private function getTags($fileId) { |
|
| 161 | + if (isset($this->cachedTags[$fileId])) { |
|
| 162 | + return $this->cachedTags[$fileId]; |
|
| 163 | + } else { |
|
| 164 | + $tags = $this->getTagger()->getTagsForObjects(array($fileId)); |
|
| 165 | + if ($tags !== false) { |
|
| 166 | + if (empty($tags)) { |
|
| 167 | + return array(); |
|
| 168 | + } |
|
| 169 | + return current($tags); |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + return null; |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - /** |
|
| 176 | - * Updates the tags of the given file id |
|
| 177 | - * |
|
| 178 | - * @param int $fileId |
|
| 179 | - * @param array $tags array of tag strings |
|
| 180 | - */ |
|
| 181 | - private function updateTags($fileId, $tags) { |
|
| 182 | - $tagger = $this->getTagger(); |
|
| 183 | - $currentTags = $this->getTags($fileId); |
|
| 175 | + /** |
|
| 176 | + * Updates the tags of the given file id |
|
| 177 | + * |
|
| 178 | + * @param int $fileId |
|
| 179 | + * @param array $tags array of tag strings |
|
| 180 | + */ |
|
| 181 | + private function updateTags($fileId, $tags) { |
|
| 182 | + $tagger = $this->getTagger(); |
|
| 183 | + $currentTags = $this->getTags($fileId); |
|
| 184 | 184 | |
| 185 | - $newTags = array_diff($tags, $currentTags); |
|
| 186 | - foreach ($newTags as $tag) { |
|
| 187 | - if ($tag === self::TAG_FAVORITE) { |
|
| 188 | - continue; |
|
| 189 | - } |
|
| 190 | - $tagger->tagAs($fileId, $tag); |
|
| 191 | - } |
|
| 192 | - $deletedTags = array_diff($currentTags, $tags); |
|
| 193 | - foreach ($deletedTags as $tag) { |
|
| 194 | - if ($tag === self::TAG_FAVORITE) { |
|
| 195 | - continue; |
|
| 196 | - } |
|
| 197 | - $tagger->unTag($fileId, $tag); |
|
| 198 | - } |
|
| 199 | - } |
|
| 185 | + $newTags = array_diff($tags, $currentTags); |
|
| 186 | + foreach ($newTags as $tag) { |
|
| 187 | + if ($tag === self::TAG_FAVORITE) { |
|
| 188 | + continue; |
|
| 189 | + } |
|
| 190 | + $tagger->tagAs($fileId, $tag); |
|
| 191 | + } |
|
| 192 | + $deletedTags = array_diff($currentTags, $tags); |
|
| 193 | + foreach ($deletedTags as $tag) { |
|
| 194 | + if ($tag === self::TAG_FAVORITE) { |
|
| 195 | + continue; |
|
| 196 | + } |
|
| 197 | + $tagger->unTag($fileId, $tag); |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * Adds tags and favorites properties to the response, |
|
| 203 | - * if requested. |
|
| 204 | - * |
|
| 205 | - * @param PropFind $propFind |
|
| 206 | - * @param \Sabre\DAV\INode $node |
|
| 207 | - * @return void |
|
| 208 | - */ |
|
| 209 | - public function handleGetProperties( |
|
| 210 | - PropFind $propFind, |
|
| 211 | - \Sabre\DAV\INode $node |
|
| 212 | - ) { |
|
| 213 | - if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
| 214 | - return; |
|
| 215 | - } |
|
| 201 | + /** |
|
| 202 | + * Adds tags and favorites properties to the response, |
|
| 203 | + * if requested. |
|
| 204 | + * |
|
| 205 | + * @param PropFind $propFind |
|
| 206 | + * @param \Sabre\DAV\INode $node |
|
| 207 | + * @return void |
|
| 208 | + */ |
|
| 209 | + public function handleGetProperties( |
|
| 210 | + PropFind $propFind, |
|
| 211 | + \Sabre\DAV\INode $node |
|
| 212 | + ) { |
|
| 213 | + if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
| 214 | + return; |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | - // need prefetch ? |
|
| 218 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Directory |
|
| 219 | - && $propFind->getDepth() !== 0 |
|
| 220 | - && (!is_null($propFind->getStatus(self::TAGS_PROPERTYNAME)) |
|
| 221 | - || !is_null($propFind->getStatus(self::FAVORITE_PROPERTYNAME)) |
|
| 222 | - )) { |
|
| 223 | - // note: pre-fetching only supported for depth <= 1 |
|
| 224 | - $folderContent = $node->getChildren(); |
|
| 225 | - $fileIds[] = (int)$node->getId(); |
|
| 226 | - foreach ($folderContent as $info) { |
|
| 227 | - $fileIds[] = (int)$info->getId(); |
|
| 228 | - } |
|
| 229 | - $tags = $this->getTagger()->getTagsForObjects($fileIds); |
|
| 230 | - if ($tags === false) { |
|
| 231 | - // the tags API returns false on error... |
|
| 232 | - $tags = array(); |
|
| 233 | - } |
|
| 217 | + // need prefetch ? |
|
| 218 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Directory |
|
| 219 | + && $propFind->getDepth() !== 0 |
|
| 220 | + && (!is_null($propFind->getStatus(self::TAGS_PROPERTYNAME)) |
|
| 221 | + || !is_null($propFind->getStatus(self::FAVORITE_PROPERTYNAME)) |
|
| 222 | + )) { |
|
| 223 | + // note: pre-fetching only supported for depth <= 1 |
|
| 224 | + $folderContent = $node->getChildren(); |
|
| 225 | + $fileIds[] = (int)$node->getId(); |
|
| 226 | + foreach ($folderContent as $info) { |
|
| 227 | + $fileIds[] = (int)$info->getId(); |
|
| 228 | + } |
|
| 229 | + $tags = $this->getTagger()->getTagsForObjects($fileIds); |
|
| 230 | + if ($tags === false) { |
|
| 231 | + // the tags API returns false on error... |
|
| 232 | + $tags = array(); |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - $this->cachedTags = $this->cachedTags + $tags; |
|
| 236 | - $emptyFileIds = array_diff($fileIds, array_keys($tags)); |
|
| 237 | - // also cache the ones that were not found |
|
| 238 | - foreach ($emptyFileIds as $fileId) { |
|
| 239 | - $this->cachedTags[$fileId] = []; |
|
| 240 | - } |
|
| 241 | - } |
|
| 235 | + $this->cachedTags = $this->cachedTags + $tags; |
|
| 236 | + $emptyFileIds = array_diff($fileIds, array_keys($tags)); |
|
| 237 | + // also cache the ones that were not found |
|
| 238 | + foreach ($emptyFileIds as $fileId) { |
|
| 239 | + $this->cachedTags[$fileId] = []; |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - $isFav = null; |
|
| 243 | + $isFav = null; |
|
| 244 | 244 | |
| 245 | - $propFind->handle(self::TAGS_PROPERTYNAME, function() use (&$isFav, $node) { |
|
| 246 | - list($tags, $isFav) = $this->getTagsAndFav($node->getId()); |
|
| 247 | - return new TagList($tags); |
|
| 248 | - }); |
|
| 245 | + $propFind->handle(self::TAGS_PROPERTYNAME, function() use (&$isFav, $node) { |
|
| 246 | + list($tags, $isFav) = $this->getTagsAndFav($node->getId()); |
|
| 247 | + return new TagList($tags); |
|
| 248 | + }); |
|
| 249 | 249 | |
| 250 | - $propFind->handle(self::FAVORITE_PROPERTYNAME, function() use ($isFav, $node) { |
|
| 251 | - if (is_null($isFav)) { |
|
| 252 | - list(, $isFav) = $this->getTagsAndFav($node->getId()); |
|
| 253 | - } |
|
| 254 | - if ($isFav) { |
|
| 255 | - return 1; |
|
| 256 | - } else { |
|
| 257 | - return 0; |
|
| 258 | - } |
|
| 259 | - }); |
|
| 260 | - } |
|
| 250 | + $propFind->handle(self::FAVORITE_PROPERTYNAME, function() use ($isFav, $node) { |
|
| 251 | + if (is_null($isFav)) { |
|
| 252 | + list(, $isFav) = $this->getTagsAndFav($node->getId()); |
|
| 253 | + } |
|
| 254 | + if ($isFav) { |
|
| 255 | + return 1; |
|
| 256 | + } else { |
|
| 257 | + return 0; |
|
| 258 | + } |
|
| 259 | + }); |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - /** |
|
| 263 | - * Updates tags and favorites properties, if applicable. |
|
| 264 | - * |
|
| 265 | - * @param string $path |
|
| 266 | - * @param PropPatch $propPatch |
|
| 267 | - * |
|
| 268 | - * @return void |
|
| 269 | - */ |
|
| 270 | - public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
| 271 | - $node = $this->tree->getNodeForPath($path); |
|
| 272 | - if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
| 273 | - return; |
|
| 274 | - } |
|
| 262 | + /** |
|
| 263 | + * Updates tags and favorites properties, if applicable. |
|
| 264 | + * |
|
| 265 | + * @param string $path |
|
| 266 | + * @param PropPatch $propPatch |
|
| 267 | + * |
|
| 268 | + * @return void |
|
| 269 | + */ |
|
| 270 | + public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
| 271 | + $node = $this->tree->getNodeForPath($path); |
|
| 272 | + if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
| 273 | + return; |
|
| 274 | + } |
|
| 275 | 275 | |
| 276 | - $propPatch->handle(self::TAGS_PROPERTYNAME, function($tagList) use ($node) { |
|
| 277 | - $this->updateTags($node->getId(), $tagList->getTags()); |
|
| 278 | - return true; |
|
| 279 | - }); |
|
| 276 | + $propPatch->handle(self::TAGS_PROPERTYNAME, function($tagList) use ($node) { |
|
| 277 | + $this->updateTags($node->getId(), $tagList->getTags()); |
|
| 278 | + return true; |
|
| 279 | + }); |
|
| 280 | 280 | |
| 281 | - $propPatch->handle(self::FAVORITE_PROPERTYNAME, function($favState) use ($node) { |
|
| 282 | - if ((int)$favState === 1 || $favState === 'true') { |
|
| 283 | - $this->getTagger()->tagAs($node->getId(), self::TAG_FAVORITE); |
|
| 284 | - } else { |
|
| 285 | - $this->getTagger()->unTag($node->getId(), self::TAG_FAVORITE); |
|
| 286 | - } |
|
| 281 | + $propPatch->handle(self::FAVORITE_PROPERTYNAME, function($favState) use ($node) { |
|
| 282 | + if ((int)$favState === 1 || $favState === 'true') { |
|
| 283 | + $this->getTagger()->tagAs($node->getId(), self::TAG_FAVORITE); |
|
| 284 | + } else { |
|
| 285 | + $this->getTagger()->unTag($node->getId(), self::TAG_FAVORITE); |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | - if (is_null($favState)) { |
|
| 289 | - // confirm deletion |
|
| 290 | - return 204; |
|
| 291 | - } |
|
| 288 | + if (is_null($favState)) { |
|
| 289 | + // confirm deletion |
|
| 290 | + return 204; |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | - return 200; |
|
| 294 | - }); |
|
| 295 | - } |
|
| 293 | + return 200; |
|
| 294 | + }); |
|
| 295 | + } |
|
| 296 | 296 | } |
@@ -68,8 +68,8 @@ |
||
| 68 | 68 | $this->getBundles(), |
| 69 | 69 | $this->getDefaultInstallationBundle() |
| 70 | 70 | ); |
| 71 | - foreach($bundles as $bundle) { |
|
| 72 | - if($bundle->getIdentifier() === $identifier) { |
|
| 71 | + foreach ($bundles as $bundle) { |
|
| 72 | + if ($bundle->getIdentifier() === $identifier) { |
|
| 73 | 73 | return $bundle; |
| 74 | 74 | } |
| 75 | 75 | } |
@@ -24,58 +24,58 @@ |
||
| 24 | 24 | use OCP\IL10N; |
| 25 | 25 | |
| 26 | 26 | class BundleFetcher { |
| 27 | - /** @var IL10N */ |
|
| 28 | - private $l10n; |
|
| 27 | + /** @var IL10N */ |
|
| 28 | + private $l10n; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @param IL10N $l10n |
|
| 32 | - */ |
|
| 33 | - public function __construct(IL10N $l10n) { |
|
| 34 | - $this->l10n = $l10n; |
|
| 35 | - } |
|
| 30 | + /** |
|
| 31 | + * @param IL10N $l10n |
|
| 32 | + */ |
|
| 33 | + public function __construct(IL10N $l10n) { |
|
| 34 | + $this->l10n = $l10n; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @return Bundle[] |
|
| 39 | - */ |
|
| 40 | - public function getBundles() { |
|
| 41 | - return [ |
|
| 42 | - new EnterpriseBundle($this->l10n), |
|
| 43 | - new GroupwareBundle($this->l10n), |
|
| 44 | - new SocialSharingBundle($this->l10n), |
|
| 45 | - new EducationBundle($this->l10n), |
|
| 46 | - ]; |
|
| 47 | - } |
|
| 37 | + /** |
|
| 38 | + * @return Bundle[] |
|
| 39 | + */ |
|
| 40 | + public function getBundles() { |
|
| 41 | + return [ |
|
| 42 | + new EnterpriseBundle($this->l10n), |
|
| 43 | + new GroupwareBundle($this->l10n), |
|
| 44 | + new SocialSharingBundle($this->l10n), |
|
| 45 | + new EducationBundle($this->l10n), |
|
| 46 | + ]; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Bundles that should be installed by default after installation |
|
| 51 | - * |
|
| 52 | - * @return Bundle[] |
|
| 53 | - */ |
|
| 54 | - public function getDefaultInstallationBundle() { |
|
| 55 | - return [ |
|
| 56 | - new CoreBundle($this->l10n), |
|
| 57 | - ]; |
|
| 58 | - } |
|
| 49 | + /** |
|
| 50 | + * Bundles that should be installed by default after installation |
|
| 51 | + * |
|
| 52 | + * @return Bundle[] |
|
| 53 | + */ |
|
| 54 | + public function getDefaultInstallationBundle() { |
|
| 55 | + return [ |
|
| 56 | + new CoreBundle($this->l10n), |
|
| 57 | + ]; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Get the bundle with the specified identifier |
|
| 62 | - * |
|
| 63 | - * @param string $identifier |
|
| 64 | - * @return Bundle |
|
| 65 | - * @throws \BadMethodCallException If the bundle does not exist |
|
| 66 | - */ |
|
| 67 | - public function getBundleByIdentifier($identifier) { |
|
| 68 | - /** @var Bundle[] $bundles */ |
|
| 69 | - $bundles = array_merge( |
|
| 70 | - $this->getBundles(), |
|
| 71 | - $this->getDefaultInstallationBundle() |
|
| 72 | - ); |
|
| 73 | - foreach($bundles as $bundle) { |
|
| 74 | - if($bundle->getIdentifier() === $identifier) { |
|
| 75 | - return $bundle; |
|
| 76 | - } |
|
| 77 | - } |
|
| 60 | + /** |
|
| 61 | + * Get the bundle with the specified identifier |
|
| 62 | + * |
|
| 63 | + * @param string $identifier |
|
| 64 | + * @return Bundle |
|
| 65 | + * @throws \BadMethodCallException If the bundle does not exist |
|
| 66 | + */ |
|
| 67 | + public function getBundleByIdentifier($identifier) { |
|
| 68 | + /** @var Bundle[] $bundles */ |
|
| 69 | + $bundles = array_merge( |
|
| 70 | + $this->getBundles(), |
|
| 71 | + $this->getDefaultInstallationBundle() |
|
| 72 | + ); |
|
| 73 | + foreach($bundles as $bundle) { |
|
| 74 | + if($bundle->getIdentifier() === $identifier) { |
|
| 75 | + return $bundle; |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - throw new \BadMethodCallException('Bundle with specified identifier does not exist'); |
|
| 80 | - } |
|
| 79 | + throw new \BadMethodCallException('Bundle with specified identifier does not exist'); |
|
| 80 | + } |
|
| 81 | 81 | } |