@@ -49,752 +49,752 @@ |
||
| 49 | 49 | */ |
| 50 | 50 | class ShareByMailProvider implements IShareProvider { |
| 51 | 51 | |
| 52 | - /** @var IDBConnection */ |
|
| 53 | - private $dbConnection; |
|
| 54 | - |
|
| 55 | - /** @var ILogger */ |
|
| 56 | - private $logger; |
|
| 57 | - |
|
| 58 | - /** @var ISecureRandom */ |
|
| 59 | - private $secureRandom; |
|
| 60 | - |
|
| 61 | - /** @var IUserManager */ |
|
| 62 | - private $userManager; |
|
| 63 | - |
|
| 64 | - /** @var IRootFolder */ |
|
| 65 | - private $rootFolder; |
|
| 66 | - |
|
| 67 | - /** @var IL10N */ |
|
| 68 | - private $l; |
|
| 69 | - |
|
| 70 | - /** @var IMailer */ |
|
| 71 | - private $mailer; |
|
| 72 | - |
|
| 73 | - /** @var IURLGenerator */ |
|
| 74 | - private $urlGenerator; |
|
| 75 | - |
|
| 76 | - /** @var IManager */ |
|
| 77 | - private $activityManager; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Return the identifier of this provider. |
|
| 81 | - * |
|
| 82 | - * @return string Containing only [a-zA-Z0-9] |
|
| 83 | - */ |
|
| 84 | - public function identifier() { |
|
| 85 | - return 'ocShareByMail'; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * DefaultShareProvider constructor. |
|
| 90 | - * |
|
| 91 | - * @param IDBConnection $connection |
|
| 92 | - * @param ISecureRandom $secureRandom |
|
| 93 | - * @param IUserManager $userManager |
|
| 94 | - * @param IRootFolder $rootFolder |
|
| 95 | - * @param IL10N $l |
|
| 96 | - * @param ILogger $logger |
|
| 97 | - * @param IMailer $mailer |
|
| 98 | - * @param IURLGenerator $urlGenerator |
|
| 99 | - * @param IManager $activityManager |
|
| 100 | - */ |
|
| 101 | - public function __construct( |
|
| 102 | - IDBConnection $connection, |
|
| 103 | - ISecureRandom $secureRandom, |
|
| 104 | - IUserManager $userManager, |
|
| 105 | - IRootFolder $rootFolder, |
|
| 106 | - IL10N $l, |
|
| 107 | - ILogger $logger, |
|
| 108 | - IMailer $mailer, |
|
| 109 | - IURLGenerator $urlGenerator, |
|
| 110 | - IManager $activityManager |
|
| 111 | - ) { |
|
| 112 | - $this->dbConnection = $connection; |
|
| 113 | - $this->secureRandom = $secureRandom; |
|
| 114 | - $this->userManager = $userManager; |
|
| 115 | - $this->rootFolder = $rootFolder; |
|
| 116 | - $this->l = $l; |
|
| 117 | - $this->logger = $logger; |
|
| 118 | - $this->mailer = $mailer; |
|
| 119 | - $this->urlGenerator = $urlGenerator; |
|
| 120 | - $this->activityManager = $activityManager; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Share a path |
|
| 125 | - * |
|
| 126 | - * @param IShare $share |
|
| 127 | - * @return IShare The share object |
|
| 128 | - * @throws ShareNotFound |
|
| 129 | - * @throws \Exception |
|
| 130 | - */ |
|
| 131 | - public function create(IShare $share) { |
|
| 132 | - |
|
| 133 | - $shareWith = $share->getSharedWith(); |
|
| 134 | - /* |
|
| 52 | + /** @var IDBConnection */ |
|
| 53 | + private $dbConnection; |
|
| 54 | + |
|
| 55 | + /** @var ILogger */ |
|
| 56 | + private $logger; |
|
| 57 | + |
|
| 58 | + /** @var ISecureRandom */ |
|
| 59 | + private $secureRandom; |
|
| 60 | + |
|
| 61 | + /** @var IUserManager */ |
|
| 62 | + private $userManager; |
|
| 63 | + |
|
| 64 | + /** @var IRootFolder */ |
|
| 65 | + private $rootFolder; |
|
| 66 | + |
|
| 67 | + /** @var IL10N */ |
|
| 68 | + private $l; |
|
| 69 | + |
|
| 70 | + /** @var IMailer */ |
|
| 71 | + private $mailer; |
|
| 72 | + |
|
| 73 | + /** @var IURLGenerator */ |
|
| 74 | + private $urlGenerator; |
|
| 75 | + |
|
| 76 | + /** @var IManager */ |
|
| 77 | + private $activityManager; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Return the identifier of this provider. |
|
| 81 | + * |
|
| 82 | + * @return string Containing only [a-zA-Z0-9] |
|
| 83 | + */ |
|
| 84 | + public function identifier() { |
|
| 85 | + return 'ocShareByMail'; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * DefaultShareProvider constructor. |
|
| 90 | + * |
|
| 91 | + * @param IDBConnection $connection |
|
| 92 | + * @param ISecureRandom $secureRandom |
|
| 93 | + * @param IUserManager $userManager |
|
| 94 | + * @param IRootFolder $rootFolder |
|
| 95 | + * @param IL10N $l |
|
| 96 | + * @param ILogger $logger |
|
| 97 | + * @param IMailer $mailer |
|
| 98 | + * @param IURLGenerator $urlGenerator |
|
| 99 | + * @param IManager $activityManager |
|
| 100 | + */ |
|
| 101 | + public function __construct( |
|
| 102 | + IDBConnection $connection, |
|
| 103 | + ISecureRandom $secureRandom, |
|
| 104 | + IUserManager $userManager, |
|
| 105 | + IRootFolder $rootFolder, |
|
| 106 | + IL10N $l, |
|
| 107 | + ILogger $logger, |
|
| 108 | + IMailer $mailer, |
|
| 109 | + IURLGenerator $urlGenerator, |
|
| 110 | + IManager $activityManager |
|
| 111 | + ) { |
|
| 112 | + $this->dbConnection = $connection; |
|
| 113 | + $this->secureRandom = $secureRandom; |
|
| 114 | + $this->userManager = $userManager; |
|
| 115 | + $this->rootFolder = $rootFolder; |
|
| 116 | + $this->l = $l; |
|
| 117 | + $this->logger = $logger; |
|
| 118 | + $this->mailer = $mailer; |
|
| 119 | + $this->urlGenerator = $urlGenerator; |
|
| 120 | + $this->activityManager = $activityManager; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Share a path |
|
| 125 | + * |
|
| 126 | + * @param IShare $share |
|
| 127 | + * @return IShare The share object |
|
| 128 | + * @throws ShareNotFound |
|
| 129 | + * @throws \Exception |
|
| 130 | + */ |
|
| 131 | + public function create(IShare $share) { |
|
| 132 | + |
|
| 133 | + $shareWith = $share->getSharedWith(); |
|
| 134 | + /* |
|
| 135 | 135 | * Check if file is not already shared with the remote user |
| 136 | 136 | */ |
| 137 | - $alreadyShared = $this->getSharedWith($shareWith, \OCP\Share::SHARE_TYPE_EMAIL, $share->getNode(), 1, 0); |
|
| 138 | - if (!empty($alreadyShared)) { |
|
| 139 | - $message = 'Sharing %s failed, this item is already shared with %s'; |
|
| 140 | - $message_t = $this->l->t('Sharing %s failed, this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
| 141 | - $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
| 142 | - throw new \Exception($message_t); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - $shareId = $this->createMailShare($share); |
|
| 146 | - $this->createActivity($share); |
|
| 147 | - $data = $this->getRawShare($shareId); |
|
| 148 | - return $this->createShareObject($data); |
|
| 149 | - |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * create activity if a file/folder was shared by mail |
|
| 154 | - * |
|
| 155 | - * @param IShare $share |
|
| 156 | - */ |
|
| 157 | - protected function createActivity(IShare $share) { |
|
| 158 | - |
|
| 159 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
| 160 | - |
|
| 161 | - $this->publishActivity( |
|
| 162 | - Activity::SUBJECT_SHARED_EMAIL_SELF, |
|
| 163 | - [$userFolder->getRelativePath($share->getNode()->getPath()), $share->getSharedWith()], |
|
| 164 | - $share->getSharedBy(), |
|
| 165 | - $share->getNode()->getId(), |
|
| 166 | - $userFolder->getRelativePath($share->getNode()->getPath()) |
|
| 167 | - ); |
|
| 168 | - |
|
| 169 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 170 | - $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
| 171 | - $fileId = $share->getNode()->getId(); |
|
| 172 | - $nodes = $ownerFolder->getById($fileId); |
|
| 173 | - $ownerPath = $nodes[0]->getPath(); |
|
| 174 | - $this->publishActivity( |
|
| 175 | - Activity::SUBJECT_SHARED_EMAIL_BY, |
|
| 176 | - [$ownerFolder->getRelativePath($ownerPath), $share->getSharedWith(), $share->getSharedBy()], |
|
| 177 | - $share->getShareOwner(), |
|
| 178 | - $fileId, |
|
| 179 | - $ownerFolder->getRelativePath($ownerPath) |
|
| 180 | - ); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * publish activity if a file/folder was shared by mail |
|
| 187 | - * |
|
| 188 | - * @param $subject |
|
| 189 | - * @param $parameters |
|
| 190 | - * @param $affectedUser |
|
| 191 | - * @param $fileId |
|
| 192 | - * @param $filePath |
|
| 193 | - */ |
|
| 194 | - protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) { |
|
| 195 | - $event = $this->activityManager->generateEvent(); |
|
| 196 | - $event->setApp('sharebymail') |
|
| 197 | - ->setType('shared') |
|
| 198 | - ->setSubject($subject, $parameters) |
|
| 199 | - ->setAffectedUser($affectedUser) |
|
| 200 | - ->setObject('files', $fileId, $filePath); |
|
| 201 | - $this->activityManager->publish($event); |
|
| 202 | - |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * @param IShare $share |
|
| 207 | - * @return int |
|
| 208 | - * @throws \Exception |
|
| 209 | - */ |
|
| 210 | - protected function createMailShare(IShare $share) { |
|
| 211 | - $share->setToken($this->generateToken()); |
|
| 212 | - $shareId = $this->addShareToDB( |
|
| 213 | - $share->getNodeId(), |
|
| 214 | - $share->getNodeType(), |
|
| 215 | - $share->getSharedWith(), |
|
| 216 | - $share->getSharedBy(), |
|
| 217 | - $share->getShareOwner(), |
|
| 218 | - $share->getPermissions(), |
|
| 219 | - $share->getToken() |
|
| 220 | - ); |
|
| 221 | - |
|
| 222 | - try { |
|
| 223 | - $link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', |
|
| 224 | - ['token' => $share->getToken()]); |
|
| 225 | - $this->sendMailNotification($share->getNode()->getName(), |
|
| 226 | - $link, |
|
| 227 | - $share->getShareOwner(), |
|
| 228 | - $share->getSharedBy(), $share->getSharedWith()); |
|
| 229 | - } catch (HintException $hintException) { |
|
| 230 | - $this->logger->error('Failed to send share by mail: ' . $hintException->getMessage()); |
|
| 231 | - $this->removeShareFromTable($shareId); |
|
| 232 | - throw $hintException; |
|
| 233 | - } catch (\Exception $e) { |
|
| 234 | - $this->logger->error('Failed to send share by mail: ' . $e->getMessage()); |
|
| 235 | - $this->removeShareFromTable($shareId); |
|
| 236 | - throw new HintException('Failed to send share by mail', |
|
| 237 | - $this->l->t('Failed to send share by E-mail')); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - return $shareId; |
|
| 241 | - |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - protected function sendMailNotification($filename, $link, $owner, $initiator, $shareWith) { |
|
| 245 | - $ownerUser = $this->userManager->get($owner); |
|
| 246 | - $initiatorUser = $this->userManager->get($initiator); |
|
| 247 | - $ownerDisplayName = ($ownerUser instanceof IUser) ? $ownerUser->getDisplayName() : $owner; |
|
| 248 | - $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
| 249 | - if ($owner === $initiator) { |
|
| 250 | - $subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename)); |
|
| 251 | - } else { |
|
| 252 | - $subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName)); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - $message = $this->mailer->createMessage(); |
|
| 256 | - $htmlBody = $this->createMailBody('mail', $filename, $link, $ownerDisplayName, $initiatorDisplayName); |
|
| 257 | - $textBody = $this->createMailBody('altmail', $filename, $link, $ownerDisplayName, $initiatorDisplayName); |
|
| 258 | - $message->setTo([$shareWith]); |
|
| 259 | - $message->setSubject($subject); |
|
| 260 | - $message->setBody($textBody, 'text/plain'); |
|
| 261 | - $message->setHtmlBody($htmlBody); |
|
| 262 | - $this->mailer->send($message); |
|
| 263 | - |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * create mail body |
|
| 268 | - * |
|
| 269 | - * @param $filename |
|
| 270 | - * @param $link |
|
| 271 | - * @param $owner |
|
| 272 | - * @param $initiator |
|
| 273 | - * @return string plain text mail |
|
| 274 | - * @throws HintException |
|
| 275 | - */ |
|
| 276 | - protected function createMailBody($template, $filename, $link, $owner, $initiator) { |
|
| 277 | - |
|
| 278 | - $mailBodyTemplate = new Template('sharebymail', $template, ''); |
|
| 279 | - $mailBodyTemplate->assign ('filename', $filename); |
|
| 280 | - $mailBodyTemplate->assign ('link', $link); |
|
| 281 | - $mailBodyTemplate->assign ('owner', $owner); |
|
| 282 | - $mailBodyTemplate->assign ('initiator', $initiator); |
|
| 283 | - $mailBodyTemplate->assign ('onBehalfOf', $initiator !== $owner); |
|
| 284 | - $mailBody = $mailBodyTemplate->fetchPage(); |
|
| 285 | - |
|
| 286 | - if (is_string($mailBody)) { |
|
| 287 | - return $mailBody; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - throw new HintException('Failed to create the E-mail', |
|
| 291 | - $this->l->t('Failed to create the E-mail')); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * generate share token |
|
| 296 | - * |
|
| 297 | - * @return string |
|
| 298 | - */ |
|
| 299 | - protected function generateToken() { |
|
| 300 | - $token = $this->secureRandom->generate( |
|
| 301 | - 15, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
| 302 | - return $token; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Get all children of this share |
|
| 307 | - * |
|
| 308 | - * @param IShare $parent |
|
| 309 | - * @return IShare[] |
|
| 310 | - */ |
|
| 311 | - public function getChildren(IShare $parent) { |
|
| 312 | - $children = []; |
|
| 313 | - |
|
| 314 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 315 | - $qb->select('*') |
|
| 316 | - ->from('share') |
|
| 317 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
| 318 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 319 | - ->orderBy('id'); |
|
| 320 | - |
|
| 321 | - $cursor = $qb->execute(); |
|
| 322 | - while($data = $cursor->fetch()) { |
|
| 323 | - $children[] = $this->createShareObject($data); |
|
| 324 | - } |
|
| 325 | - $cursor->closeCursor(); |
|
| 326 | - |
|
| 327 | - return $children; |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * add share to the database and return the ID |
|
| 332 | - * |
|
| 333 | - * @param int $itemSource |
|
| 334 | - * @param string $itemType |
|
| 335 | - * @param string $shareWith |
|
| 336 | - * @param string $sharedBy |
|
| 337 | - * @param string $uidOwner |
|
| 338 | - * @param int $permissions |
|
| 339 | - * @param string $token |
|
| 340 | - * @return int |
|
| 341 | - */ |
|
| 342 | - protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) { |
|
| 343 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 344 | - $qb->insert('share') |
|
| 345 | - ->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
| 346 | - ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
| 347 | - ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
| 348 | - ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
| 349 | - ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
| 350 | - ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
| 351 | - ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
| 352 | - ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
| 353 | - ->setValue('token', $qb->createNamedParameter($token)) |
|
| 354 | - ->setValue('stime', $qb->createNamedParameter(time())); |
|
| 355 | - |
|
| 356 | - /* |
|
| 137 | + $alreadyShared = $this->getSharedWith($shareWith, \OCP\Share::SHARE_TYPE_EMAIL, $share->getNode(), 1, 0); |
|
| 138 | + if (!empty($alreadyShared)) { |
|
| 139 | + $message = 'Sharing %s failed, this item is already shared with %s'; |
|
| 140 | + $message_t = $this->l->t('Sharing %s failed, this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
| 141 | + $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
| 142 | + throw new \Exception($message_t); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + $shareId = $this->createMailShare($share); |
|
| 146 | + $this->createActivity($share); |
|
| 147 | + $data = $this->getRawShare($shareId); |
|
| 148 | + return $this->createShareObject($data); |
|
| 149 | + |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * create activity if a file/folder was shared by mail |
|
| 154 | + * |
|
| 155 | + * @param IShare $share |
|
| 156 | + */ |
|
| 157 | + protected function createActivity(IShare $share) { |
|
| 158 | + |
|
| 159 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
| 160 | + |
|
| 161 | + $this->publishActivity( |
|
| 162 | + Activity::SUBJECT_SHARED_EMAIL_SELF, |
|
| 163 | + [$userFolder->getRelativePath($share->getNode()->getPath()), $share->getSharedWith()], |
|
| 164 | + $share->getSharedBy(), |
|
| 165 | + $share->getNode()->getId(), |
|
| 166 | + $userFolder->getRelativePath($share->getNode()->getPath()) |
|
| 167 | + ); |
|
| 168 | + |
|
| 169 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 170 | + $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
| 171 | + $fileId = $share->getNode()->getId(); |
|
| 172 | + $nodes = $ownerFolder->getById($fileId); |
|
| 173 | + $ownerPath = $nodes[0]->getPath(); |
|
| 174 | + $this->publishActivity( |
|
| 175 | + Activity::SUBJECT_SHARED_EMAIL_BY, |
|
| 176 | + [$ownerFolder->getRelativePath($ownerPath), $share->getSharedWith(), $share->getSharedBy()], |
|
| 177 | + $share->getShareOwner(), |
|
| 178 | + $fileId, |
|
| 179 | + $ownerFolder->getRelativePath($ownerPath) |
|
| 180 | + ); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * publish activity if a file/folder was shared by mail |
|
| 187 | + * |
|
| 188 | + * @param $subject |
|
| 189 | + * @param $parameters |
|
| 190 | + * @param $affectedUser |
|
| 191 | + * @param $fileId |
|
| 192 | + * @param $filePath |
|
| 193 | + */ |
|
| 194 | + protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) { |
|
| 195 | + $event = $this->activityManager->generateEvent(); |
|
| 196 | + $event->setApp('sharebymail') |
|
| 197 | + ->setType('shared') |
|
| 198 | + ->setSubject($subject, $parameters) |
|
| 199 | + ->setAffectedUser($affectedUser) |
|
| 200 | + ->setObject('files', $fileId, $filePath); |
|
| 201 | + $this->activityManager->publish($event); |
|
| 202 | + |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * @param IShare $share |
|
| 207 | + * @return int |
|
| 208 | + * @throws \Exception |
|
| 209 | + */ |
|
| 210 | + protected function createMailShare(IShare $share) { |
|
| 211 | + $share->setToken($this->generateToken()); |
|
| 212 | + $shareId = $this->addShareToDB( |
|
| 213 | + $share->getNodeId(), |
|
| 214 | + $share->getNodeType(), |
|
| 215 | + $share->getSharedWith(), |
|
| 216 | + $share->getSharedBy(), |
|
| 217 | + $share->getShareOwner(), |
|
| 218 | + $share->getPermissions(), |
|
| 219 | + $share->getToken() |
|
| 220 | + ); |
|
| 221 | + |
|
| 222 | + try { |
|
| 223 | + $link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', |
|
| 224 | + ['token' => $share->getToken()]); |
|
| 225 | + $this->sendMailNotification($share->getNode()->getName(), |
|
| 226 | + $link, |
|
| 227 | + $share->getShareOwner(), |
|
| 228 | + $share->getSharedBy(), $share->getSharedWith()); |
|
| 229 | + } catch (HintException $hintException) { |
|
| 230 | + $this->logger->error('Failed to send share by mail: ' . $hintException->getMessage()); |
|
| 231 | + $this->removeShareFromTable($shareId); |
|
| 232 | + throw $hintException; |
|
| 233 | + } catch (\Exception $e) { |
|
| 234 | + $this->logger->error('Failed to send share by mail: ' . $e->getMessage()); |
|
| 235 | + $this->removeShareFromTable($shareId); |
|
| 236 | + throw new HintException('Failed to send share by mail', |
|
| 237 | + $this->l->t('Failed to send share by E-mail')); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + return $shareId; |
|
| 241 | + |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + protected function sendMailNotification($filename, $link, $owner, $initiator, $shareWith) { |
|
| 245 | + $ownerUser = $this->userManager->get($owner); |
|
| 246 | + $initiatorUser = $this->userManager->get($initiator); |
|
| 247 | + $ownerDisplayName = ($ownerUser instanceof IUser) ? $ownerUser->getDisplayName() : $owner; |
|
| 248 | + $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
| 249 | + if ($owner === $initiator) { |
|
| 250 | + $subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename)); |
|
| 251 | + } else { |
|
| 252 | + $subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName)); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + $message = $this->mailer->createMessage(); |
|
| 256 | + $htmlBody = $this->createMailBody('mail', $filename, $link, $ownerDisplayName, $initiatorDisplayName); |
|
| 257 | + $textBody = $this->createMailBody('altmail', $filename, $link, $ownerDisplayName, $initiatorDisplayName); |
|
| 258 | + $message->setTo([$shareWith]); |
|
| 259 | + $message->setSubject($subject); |
|
| 260 | + $message->setBody($textBody, 'text/plain'); |
|
| 261 | + $message->setHtmlBody($htmlBody); |
|
| 262 | + $this->mailer->send($message); |
|
| 263 | + |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * create mail body |
|
| 268 | + * |
|
| 269 | + * @param $filename |
|
| 270 | + * @param $link |
|
| 271 | + * @param $owner |
|
| 272 | + * @param $initiator |
|
| 273 | + * @return string plain text mail |
|
| 274 | + * @throws HintException |
|
| 275 | + */ |
|
| 276 | + protected function createMailBody($template, $filename, $link, $owner, $initiator) { |
|
| 277 | + |
|
| 278 | + $mailBodyTemplate = new Template('sharebymail', $template, ''); |
|
| 279 | + $mailBodyTemplate->assign ('filename', $filename); |
|
| 280 | + $mailBodyTemplate->assign ('link', $link); |
|
| 281 | + $mailBodyTemplate->assign ('owner', $owner); |
|
| 282 | + $mailBodyTemplate->assign ('initiator', $initiator); |
|
| 283 | + $mailBodyTemplate->assign ('onBehalfOf', $initiator !== $owner); |
|
| 284 | + $mailBody = $mailBodyTemplate->fetchPage(); |
|
| 285 | + |
|
| 286 | + if (is_string($mailBody)) { |
|
| 287 | + return $mailBody; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + throw new HintException('Failed to create the E-mail', |
|
| 291 | + $this->l->t('Failed to create the E-mail')); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * generate share token |
|
| 296 | + * |
|
| 297 | + * @return string |
|
| 298 | + */ |
|
| 299 | + protected function generateToken() { |
|
| 300 | + $token = $this->secureRandom->generate( |
|
| 301 | + 15, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
| 302 | + return $token; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Get all children of this share |
|
| 307 | + * |
|
| 308 | + * @param IShare $parent |
|
| 309 | + * @return IShare[] |
|
| 310 | + */ |
|
| 311 | + public function getChildren(IShare $parent) { |
|
| 312 | + $children = []; |
|
| 313 | + |
|
| 314 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 315 | + $qb->select('*') |
|
| 316 | + ->from('share') |
|
| 317 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
| 318 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 319 | + ->orderBy('id'); |
|
| 320 | + |
|
| 321 | + $cursor = $qb->execute(); |
|
| 322 | + while($data = $cursor->fetch()) { |
|
| 323 | + $children[] = $this->createShareObject($data); |
|
| 324 | + } |
|
| 325 | + $cursor->closeCursor(); |
|
| 326 | + |
|
| 327 | + return $children; |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * add share to the database and return the ID |
|
| 332 | + * |
|
| 333 | + * @param int $itemSource |
|
| 334 | + * @param string $itemType |
|
| 335 | + * @param string $shareWith |
|
| 336 | + * @param string $sharedBy |
|
| 337 | + * @param string $uidOwner |
|
| 338 | + * @param int $permissions |
|
| 339 | + * @param string $token |
|
| 340 | + * @return int |
|
| 341 | + */ |
|
| 342 | + protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) { |
|
| 343 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 344 | + $qb->insert('share') |
|
| 345 | + ->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
| 346 | + ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
| 347 | + ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
| 348 | + ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
| 349 | + ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
| 350 | + ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
| 351 | + ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
| 352 | + ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
| 353 | + ->setValue('token', $qb->createNamedParameter($token)) |
|
| 354 | + ->setValue('stime', $qb->createNamedParameter(time())); |
|
| 355 | + |
|
| 356 | + /* |
|
| 357 | 357 | * Added to fix https://github.com/owncloud/core/issues/22215 |
| 358 | 358 | * Can be removed once we get rid of ajax/share.php |
| 359 | 359 | */ |
| 360 | - $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
| 361 | - |
|
| 362 | - $qb->execute(); |
|
| 363 | - $id = $qb->getLastInsertId(); |
|
| 364 | - |
|
| 365 | - return (int)$id; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * Update a share |
|
| 370 | - * |
|
| 371 | - * @param IShare $share |
|
| 372 | - * @return IShare The share object |
|
| 373 | - */ |
|
| 374 | - public function update(IShare $share) { |
|
| 375 | - /* |
|
| 360 | + $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
| 361 | + |
|
| 362 | + $qb->execute(); |
|
| 363 | + $id = $qb->getLastInsertId(); |
|
| 364 | + |
|
| 365 | + return (int)$id; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * Update a share |
|
| 370 | + * |
|
| 371 | + * @param IShare $share |
|
| 372 | + * @return IShare The share object |
|
| 373 | + */ |
|
| 374 | + public function update(IShare $share) { |
|
| 375 | + /* |
|
| 376 | 376 | * We allow updating the permissions of mail shares |
| 377 | 377 | */ |
| 378 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 379 | - $qb->update('share') |
|
| 380 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
| 381 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
| 382 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
| 383 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
| 384 | - ->execute(); |
|
| 385 | - |
|
| 386 | - return $share; |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * @inheritdoc |
|
| 391 | - */ |
|
| 392 | - public function move(IShare $share, $recipient) { |
|
| 393 | - /** |
|
| 394 | - * nothing to do here, mail shares are only outgoing shares |
|
| 395 | - */ |
|
| 396 | - return $share; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - /** |
|
| 400 | - * Delete a share (owner unShares the file) |
|
| 401 | - * |
|
| 402 | - * @param IShare $share |
|
| 403 | - */ |
|
| 404 | - public function delete(IShare $share) { |
|
| 405 | - $this->removeShareFromTable($share->getId()); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * @inheritdoc |
|
| 410 | - */ |
|
| 411 | - public function deleteFromSelf(IShare $share, $recipient) { |
|
| 412 | - // nothing to do here, mail shares are only outgoing shares |
|
| 413 | - return; |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * @inheritdoc |
|
| 418 | - */ |
|
| 419 | - public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
| 420 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 421 | - $qb->select('*') |
|
| 422 | - ->from('share'); |
|
| 423 | - |
|
| 424 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * Reshares for this user are shares where they are the owner. |
|
| 428 | - */ |
|
| 429 | - if ($reshares === false) { |
|
| 430 | - //Special case for old shares created via the web UI |
|
| 431 | - $or1 = $qb->expr()->andX( |
|
| 432 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 433 | - $qb->expr()->isNull('uid_initiator') |
|
| 434 | - ); |
|
| 435 | - |
|
| 436 | - $qb->andWhere( |
|
| 437 | - $qb->expr()->orX( |
|
| 438 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
| 439 | - $or1 |
|
| 440 | - ) |
|
| 441 | - ); |
|
| 442 | - } else { |
|
| 443 | - $qb->andWhere( |
|
| 444 | - $qb->expr()->orX( |
|
| 445 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 446 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 447 | - ) |
|
| 448 | - ); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - if ($node !== null) { |
|
| 452 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - if ($limit !== -1) { |
|
| 456 | - $qb->setMaxResults($limit); |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - $qb->setFirstResult($offset); |
|
| 460 | - $qb->orderBy('id'); |
|
| 461 | - |
|
| 462 | - $cursor = $qb->execute(); |
|
| 463 | - $shares = []; |
|
| 464 | - while($data = $cursor->fetch()) { |
|
| 465 | - $shares[] = $this->createShareObject($data); |
|
| 466 | - } |
|
| 467 | - $cursor->closeCursor(); |
|
| 468 | - |
|
| 469 | - return $shares; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * @inheritdoc |
|
| 474 | - */ |
|
| 475 | - public function getShareById($id, $recipientId = null) { |
|
| 476 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 477 | - |
|
| 478 | - $qb->select('*') |
|
| 479 | - ->from('share') |
|
| 480 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 481 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
| 482 | - |
|
| 483 | - $cursor = $qb->execute(); |
|
| 484 | - $data = $cursor->fetch(); |
|
| 485 | - $cursor->closeCursor(); |
|
| 486 | - |
|
| 487 | - if ($data === false) { |
|
| 488 | - throw new ShareNotFound(); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - try { |
|
| 492 | - $share = $this->createShareObject($data); |
|
| 493 | - } catch (InvalidShare $e) { |
|
| 494 | - throw new ShareNotFound(); |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - return $share; |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * Get shares for a given path |
|
| 502 | - * |
|
| 503 | - * @param \OCP\Files\Node $path |
|
| 504 | - * @return IShare[] |
|
| 505 | - */ |
|
| 506 | - public function getSharesByPath(Node $path) { |
|
| 507 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 508 | - |
|
| 509 | - $cursor = $qb->select('*') |
|
| 510 | - ->from('share') |
|
| 511 | - ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
| 512 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 513 | - ->execute(); |
|
| 514 | - |
|
| 515 | - $shares = []; |
|
| 516 | - while($data = $cursor->fetch()) { |
|
| 517 | - $shares[] = $this->createShareObject($data); |
|
| 518 | - } |
|
| 519 | - $cursor->closeCursor(); |
|
| 520 | - |
|
| 521 | - return $shares; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * @inheritdoc |
|
| 526 | - */ |
|
| 527 | - public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
| 528 | - /** @var IShare[] $shares */ |
|
| 529 | - $shares = []; |
|
| 530 | - |
|
| 531 | - //Get shares directly with this user |
|
| 532 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 533 | - $qb->select('*') |
|
| 534 | - ->from('share'); |
|
| 535 | - |
|
| 536 | - // Order by id |
|
| 537 | - $qb->orderBy('id'); |
|
| 538 | - |
|
| 539 | - // Set limit and offset |
|
| 540 | - if ($limit !== -1) { |
|
| 541 | - $qb->setMaxResults($limit); |
|
| 542 | - } |
|
| 543 | - $qb->setFirstResult($offset); |
|
| 544 | - |
|
| 545 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
| 546 | - $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
| 547 | - |
|
| 548 | - // Filter by node if provided |
|
| 549 | - if ($node !== null) { |
|
| 550 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - $cursor = $qb->execute(); |
|
| 554 | - |
|
| 555 | - while($data = $cursor->fetch()) { |
|
| 556 | - $shares[] = $this->createShareObject($data); |
|
| 557 | - } |
|
| 558 | - $cursor->closeCursor(); |
|
| 559 | - |
|
| 560 | - |
|
| 561 | - return $shares; |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - /** |
|
| 565 | - * Get a share by token |
|
| 566 | - * |
|
| 567 | - * @param string $token |
|
| 568 | - * @return IShare |
|
| 569 | - * @throws ShareNotFound |
|
| 570 | - */ |
|
| 571 | - public function getShareByToken($token) { |
|
| 572 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 573 | - |
|
| 574 | - $cursor = $qb->select('*') |
|
| 575 | - ->from('share') |
|
| 576 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 577 | - ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 578 | - ->execute(); |
|
| 579 | - |
|
| 580 | - $data = $cursor->fetch(); |
|
| 581 | - |
|
| 582 | - if ($data === false) { |
|
| 583 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - try { |
|
| 587 | - $share = $this->createShareObject($data); |
|
| 588 | - } catch (InvalidShare $e) { |
|
| 589 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - return $share; |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * remove share from table |
|
| 597 | - * |
|
| 598 | - * @param string $shareId |
|
| 599 | - */ |
|
| 600 | - protected function removeShareFromTable($shareId) { |
|
| 601 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 602 | - $qb->delete('share') |
|
| 603 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
| 604 | - $qb->execute(); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * Create a share object from an database row |
|
| 609 | - * |
|
| 610 | - * @param array $data |
|
| 611 | - * @return IShare |
|
| 612 | - * @throws InvalidShare |
|
| 613 | - * @throws ShareNotFound |
|
| 614 | - */ |
|
| 615 | - protected function createShareObject($data) { |
|
| 616 | - |
|
| 617 | - $share = new Share($this->rootFolder, $this->userManager); |
|
| 618 | - $share->setId((int)$data['id']) |
|
| 619 | - ->setShareType((int)$data['share_type']) |
|
| 620 | - ->setPermissions((int)$data['permissions']) |
|
| 621 | - ->setTarget($data['file_target']) |
|
| 622 | - ->setMailSend((bool)$data['mail_send']) |
|
| 623 | - ->setToken($data['token']); |
|
| 624 | - |
|
| 625 | - $shareTime = new \DateTime(); |
|
| 626 | - $shareTime->setTimestamp((int)$data['stime']); |
|
| 627 | - $share->setShareTime($shareTime); |
|
| 628 | - $share->setSharedWith($data['share_with']); |
|
| 629 | - |
|
| 630 | - if ($data['uid_initiator'] !== null) { |
|
| 631 | - $share->setShareOwner($data['uid_owner']); |
|
| 632 | - $share->setSharedBy($data['uid_initiator']); |
|
| 633 | - } else { |
|
| 634 | - //OLD SHARE |
|
| 635 | - $share->setSharedBy($data['uid_owner']); |
|
| 636 | - $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
| 637 | - |
|
| 638 | - $owner = $path->getOwner(); |
|
| 639 | - $share->setShareOwner($owner->getUID()); |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - $share->setNodeId((int)$data['file_source']); |
|
| 643 | - $share->setNodeType($data['item_type']); |
|
| 644 | - |
|
| 645 | - $share->setProviderId($this->identifier()); |
|
| 646 | - |
|
| 647 | - return $share; |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - /** |
|
| 651 | - * Get the node with file $id for $user |
|
| 652 | - * |
|
| 653 | - * @param string $userId |
|
| 654 | - * @param int $id |
|
| 655 | - * @return \OCP\Files\File|\OCP\Files\Folder |
|
| 656 | - * @throws InvalidShare |
|
| 657 | - */ |
|
| 658 | - private function getNode($userId, $id) { |
|
| 659 | - try { |
|
| 660 | - $userFolder = $this->rootFolder->getUserFolder($userId); |
|
| 661 | - } catch (NotFoundException $e) { |
|
| 662 | - throw new InvalidShare(); |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - $nodes = $userFolder->getById($id); |
|
| 666 | - |
|
| 667 | - if (empty($nodes)) { |
|
| 668 | - throw new InvalidShare(); |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - return $nodes[0]; |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - /** |
|
| 675 | - * A user is deleted from the system |
|
| 676 | - * So clean up the relevant shares. |
|
| 677 | - * |
|
| 678 | - * @param string $uid |
|
| 679 | - * @param int $shareType |
|
| 680 | - */ |
|
| 681 | - public function userDeleted($uid, $shareType) { |
|
| 682 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 683 | - |
|
| 684 | - $qb->delete('share') |
|
| 685 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 686 | - ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
| 687 | - ->execute(); |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - /** |
|
| 691 | - * This provider does not support group shares |
|
| 692 | - * |
|
| 693 | - * @param string $gid |
|
| 694 | - */ |
|
| 695 | - public function groupDeleted($gid) { |
|
| 696 | - return; |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - /** |
|
| 700 | - * This provider does not support group shares |
|
| 701 | - * |
|
| 702 | - * @param string $uid |
|
| 703 | - * @param string $gid |
|
| 704 | - */ |
|
| 705 | - public function userDeletedFromGroup($uid, $gid) { |
|
| 706 | - return; |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - /** |
|
| 710 | - * get database row of a give share |
|
| 711 | - * |
|
| 712 | - * @param $id |
|
| 713 | - * @return array |
|
| 714 | - * @throws ShareNotFound |
|
| 715 | - */ |
|
| 716 | - protected function getRawShare($id) { |
|
| 717 | - |
|
| 718 | - // Now fetch the inserted share and create a complete share object |
|
| 719 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 720 | - $qb->select('*') |
|
| 721 | - ->from('share') |
|
| 722 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
| 723 | - |
|
| 724 | - $cursor = $qb->execute(); |
|
| 725 | - $data = $cursor->fetch(); |
|
| 726 | - $cursor->closeCursor(); |
|
| 727 | - |
|
| 728 | - if ($data === false) { |
|
| 729 | - throw new ShareNotFound; |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - return $data; |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
| 736 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 737 | - $qb->select('*') |
|
| 738 | - ->from('share', 's') |
|
| 739 | - ->andWhere($qb->expr()->orX( |
|
| 740 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 741 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 742 | - )) |
|
| 743 | - ->andWhere( |
|
| 744 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
| 745 | - ); |
|
| 746 | - |
|
| 747 | - /** |
|
| 748 | - * Reshares for this user are shares where they are the owner. |
|
| 749 | - */ |
|
| 750 | - if ($reshares === false) { |
|
| 751 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
| 752 | - } else { |
|
| 753 | - $qb->andWhere( |
|
| 754 | - $qb->expr()->orX( |
|
| 755 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 756 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 757 | - ) |
|
| 758 | - ); |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - $qb->innerJoin('s', 'filecache' ,'f', 's.file_source = f.fileid'); |
|
| 762 | - $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
| 763 | - |
|
| 764 | - $qb->orderBy('id'); |
|
| 765 | - |
|
| 766 | - $cursor = $qb->execute(); |
|
| 767 | - $shares = []; |
|
| 768 | - while ($data = $cursor->fetch()) { |
|
| 769 | - $shares[$data['fileid']][] = $this->createShareObject($data); |
|
| 770 | - } |
|
| 771 | - $cursor->closeCursor(); |
|
| 772 | - |
|
| 773 | - return $shares; |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - public function getAccessList($nodes, $currentAccess) { |
|
| 777 | - $ids = []; |
|
| 778 | - foreach ($nodes as $node) { |
|
| 779 | - $ids[] = $node->getId(); |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 783 | - $qb->select('share_with') |
|
| 784 | - ->from('share') |
|
| 785 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 786 | - ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 787 | - ->andWhere($qb->expr()->orX( |
|
| 788 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 789 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 790 | - )) |
|
| 791 | - ->setMaxResults(1); |
|
| 792 | - $cursor = $qb->execute(); |
|
| 793 | - |
|
| 794 | - $mail = $cursor->fetch() !== false; |
|
| 795 | - $cursor->closeCursor(); |
|
| 796 | - |
|
| 797 | - return ['mail' => $mail]; |
|
| 798 | - } |
|
| 378 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 379 | + $qb->update('share') |
|
| 380 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
| 381 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
| 382 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
| 383 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
| 384 | + ->execute(); |
|
| 385 | + |
|
| 386 | + return $share; |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * @inheritdoc |
|
| 391 | + */ |
|
| 392 | + public function move(IShare $share, $recipient) { |
|
| 393 | + /** |
|
| 394 | + * nothing to do here, mail shares are only outgoing shares |
|
| 395 | + */ |
|
| 396 | + return $share; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + /** |
|
| 400 | + * Delete a share (owner unShares the file) |
|
| 401 | + * |
|
| 402 | + * @param IShare $share |
|
| 403 | + */ |
|
| 404 | + public function delete(IShare $share) { |
|
| 405 | + $this->removeShareFromTable($share->getId()); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * @inheritdoc |
|
| 410 | + */ |
|
| 411 | + public function deleteFromSelf(IShare $share, $recipient) { |
|
| 412 | + // nothing to do here, mail shares are only outgoing shares |
|
| 413 | + return; |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * @inheritdoc |
|
| 418 | + */ |
|
| 419 | + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
| 420 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 421 | + $qb->select('*') |
|
| 422 | + ->from('share'); |
|
| 423 | + |
|
| 424 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * Reshares for this user are shares where they are the owner. |
|
| 428 | + */ |
|
| 429 | + if ($reshares === false) { |
|
| 430 | + //Special case for old shares created via the web UI |
|
| 431 | + $or1 = $qb->expr()->andX( |
|
| 432 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 433 | + $qb->expr()->isNull('uid_initiator') |
|
| 434 | + ); |
|
| 435 | + |
|
| 436 | + $qb->andWhere( |
|
| 437 | + $qb->expr()->orX( |
|
| 438 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
| 439 | + $or1 |
|
| 440 | + ) |
|
| 441 | + ); |
|
| 442 | + } else { |
|
| 443 | + $qb->andWhere( |
|
| 444 | + $qb->expr()->orX( |
|
| 445 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 446 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 447 | + ) |
|
| 448 | + ); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + if ($node !== null) { |
|
| 452 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + if ($limit !== -1) { |
|
| 456 | + $qb->setMaxResults($limit); |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + $qb->setFirstResult($offset); |
|
| 460 | + $qb->orderBy('id'); |
|
| 461 | + |
|
| 462 | + $cursor = $qb->execute(); |
|
| 463 | + $shares = []; |
|
| 464 | + while($data = $cursor->fetch()) { |
|
| 465 | + $shares[] = $this->createShareObject($data); |
|
| 466 | + } |
|
| 467 | + $cursor->closeCursor(); |
|
| 468 | + |
|
| 469 | + return $shares; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * @inheritdoc |
|
| 474 | + */ |
|
| 475 | + public function getShareById($id, $recipientId = null) { |
|
| 476 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 477 | + |
|
| 478 | + $qb->select('*') |
|
| 479 | + ->from('share') |
|
| 480 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 481 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
| 482 | + |
|
| 483 | + $cursor = $qb->execute(); |
|
| 484 | + $data = $cursor->fetch(); |
|
| 485 | + $cursor->closeCursor(); |
|
| 486 | + |
|
| 487 | + if ($data === false) { |
|
| 488 | + throw new ShareNotFound(); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + try { |
|
| 492 | + $share = $this->createShareObject($data); |
|
| 493 | + } catch (InvalidShare $e) { |
|
| 494 | + throw new ShareNotFound(); |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + return $share; |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * Get shares for a given path |
|
| 502 | + * |
|
| 503 | + * @param \OCP\Files\Node $path |
|
| 504 | + * @return IShare[] |
|
| 505 | + */ |
|
| 506 | + public function getSharesByPath(Node $path) { |
|
| 507 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 508 | + |
|
| 509 | + $cursor = $qb->select('*') |
|
| 510 | + ->from('share') |
|
| 511 | + ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
| 512 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 513 | + ->execute(); |
|
| 514 | + |
|
| 515 | + $shares = []; |
|
| 516 | + while($data = $cursor->fetch()) { |
|
| 517 | + $shares[] = $this->createShareObject($data); |
|
| 518 | + } |
|
| 519 | + $cursor->closeCursor(); |
|
| 520 | + |
|
| 521 | + return $shares; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * @inheritdoc |
|
| 526 | + */ |
|
| 527 | + public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
| 528 | + /** @var IShare[] $shares */ |
|
| 529 | + $shares = []; |
|
| 530 | + |
|
| 531 | + //Get shares directly with this user |
|
| 532 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 533 | + $qb->select('*') |
|
| 534 | + ->from('share'); |
|
| 535 | + |
|
| 536 | + // Order by id |
|
| 537 | + $qb->orderBy('id'); |
|
| 538 | + |
|
| 539 | + // Set limit and offset |
|
| 540 | + if ($limit !== -1) { |
|
| 541 | + $qb->setMaxResults($limit); |
|
| 542 | + } |
|
| 543 | + $qb->setFirstResult($offset); |
|
| 544 | + |
|
| 545 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
| 546 | + $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
| 547 | + |
|
| 548 | + // Filter by node if provided |
|
| 549 | + if ($node !== null) { |
|
| 550 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + $cursor = $qb->execute(); |
|
| 554 | + |
|
| 555 | + while($data = $cursor->fetch()) { |
|
| 556 | + $shares[] = $this->createShareObject($data); |
|
| 557 | + } |
|
| 558 | + $cursor->closeCursor(); |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + return $shares; |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + /** |
|
| 565 | + * Get a share by token |
|
| 566 | + * |
|
| 567 | + * @param string $token |
|
| 568 | + * @return IShare |
|
| 569 | + * @throws ShareNotFound |
|
| 570 | + */ |
|
| 571 | + public function getShareByToken($token) { |
|
| 572 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 573 | + |
|
| 574 | + $cursor = $qb->select('*') |
|
| 575 | + ->from('share') |
|
| 576 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 577 | + ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 578 | + ->execute(); |
|
| 579 | + |
|
| 580 | + $data = $cursor->fetch(); |
|
| 581 | + |
|
| 582 | + if ($data === false) { |
|
| 583 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + try { |
|
| 587 | + $share = $this->createShareObject($data); |
|
| 588 | + } catch (InvalidShare $e) { |
|
| 589 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + return $share; |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * remove share from table |
|
| 597 | + * |
|
| 598 | + * @param string $shareId |
|
| 599 | + */ |
|
| 600 | + protected function removeShareFromTable($shareId) { |
|
| 601 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 602 | + $qb->delete('share') |
|
| 603 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
| 604 | + $qb->execute(); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + /** |
|
| 608 | + * Create a share object from an database row |
|
| 609 | + * |
|
| 610 | + * @param array $data |
|
| 611 | + * @return IShare |
|
| 612 | + * @throws InvalidShare |
|
| 613 | + * @throws ShareNotFound |
|
| 614 | + */ |
|
| 615 | + protected function createShareObject($data) { |
|
| 616 | + |
|
| 617 | + $share = new Share($this->rootFolder, $this->userManager); |
|
| 618 | + $share->setId((int)$data['id']) |
|
| 619 | + ->setShareType((int)$data['share_type']) |
|
| 620 | + ->setPermissions((int)$data['permissions']) |
|
| 621 | + ->setTarget($data['file_target']) |
|
| 622 | + ->setMailSend((bool)$data['mail_send']) |
|
| 623 | + ->setToken($data['token']); |
|
| 624 | + |
|
| 625 | + $shareTime = new \DateTime(); |
|
| 626 | + $shareTime->setTimestamp((int)$data['stime']); |
|
| 627 | + $share->setShareTime($shareTime); |
|
| 628 | + $share->setSharedWith($data['share_with']); |
|
| 629 | + |
|
| 630 | + if ($data['uid_initiator'] !== null) { |
|
| 631 | + $share->setShareOwner($data['uid_owner']); |
|
| 632 | + $share->setSharedBy($data['uid_initiator']); |
|
| 633 | + } else { |
|
| 634 | + //OLD SHARE |
|
| 635 | + $share->setSharedBy($data['uid_owner']); |
|
| 636 | + $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
| 637 | + |
|
| 638 | + $owner = $path->getOwner(); |
|
| 639 | + $share->setShareOwner($owner->getUID()); |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + $share->setNodeId((int)$data['file_source']); |
|
| 643 | + $share->setNodeType($data['item_type']); |
|
| 644 | + |
|
| 645 | + $share->setProviderId($this->identifier()); |
|
| 646 | + |
|
| 647 | + return $share; |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + /** |
|
| 651 | + * Get the node with file $id for $user |
|
| 652 | + * |
|
| 653 | + * @param string $userId |
|
| 654 | + * @param int $id |
|
| 655 | + * @return \OCP\Files\File|\OCP\Files\Folder |
|
| 656 | + * @throws InvalidShare |
|
| 657 | + */ |
|
| 658 | + private function getNode($userId, $id) { |
|
| 659 | + try { |
|
| 660 | + $userFolder = $this->rootFolder->getUserFolder($userId); |
|
| 661 | + } catch (NotFoundException $e) { |
|
| 662 | + throw new InvalidShare(); |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + $nodes = $userFolder->getById($id); |
|
| 666 | + |
|
| 667 | + if (empty($nodes)) { |
|
| 668 | + throw new InvalidShare(); |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + return $nodes[0]; |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + /** |
|
| 675 | + * A user is deleted from the system |
|
| 676 | + * So clean up the relevant shares. |
|
| 677 | + * |
|
| 678 | + * @param string $uid |
|
| 679 | + * @param int $shareType |
|
| 680 | + */ |
|
| 681 | + public function userDeleted($uid, $shareType) { |
|
| 682 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 683 | + |
|
| 684 | + $qb->delete('share') |
|
| 685 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 686 | + ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
| 687 | + ->execute(); |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + /** |
|
| 691 | + * This provider does not support group shares |
|
| 692 | + * |
|
| 693 | + * @param string $gid |
|
| 694 | + */ |
|
| 695 | + public function groupDeleted($gid) { |
|
| 696 | + return; |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + /** |
|
| 700 | + * This provider does not support group shares |
|
| 701 | + * |
|
| 702 | + * @param string $uid |
|
| 703 | + * @param string $gid |
|
| 704 | + */ |
|
| 705 | + public function userDeletedFromGroup($uid, $gid) { |
|
| 706 | + return; |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | + * get database row of a give share |
|
| 711 | + * |
|
| 712 | + * @param $id |
|
| 713 | + * @return array |
|
| 714 | + * @throws ShareNotFound |
|
| 715 | + */ |
|
| 716 | + protected function getRawShare($id) { |
|
| 717 | + |
|
| 718 | + // Now fetch the inserted share and create a complete share object |
|
| 719 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 720 | + $qb->select('*') |
|
| 721 | + ->from('share') |
|
| 722 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
| 723 | + |
|
| 724 | + $cursor = $qb->execute(); |
|
| 725 | + $data = $cursor->fetch(); |
|
| 726 | + $cursor->closeCursor(); |
|
| 727 | + |
|
| 728 | + if ($data === false) { |
|
| 729 | + throw new ShareNotFound; |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + return $data; |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
| 736 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 737 | + $qb->select('*') |
|
| 738 | + ->from('share', 's') |
|
| 739 | + ->andWhere($qb->expr()->orX( |
|
| 740 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 741 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 742 | + )) |
|
| 743 | + ->andWhere( |
|
| 744 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
| 745 | + ); |
|
| 746 | + |
|
| 747 | + /** |
|
| 748 | + * Reshares for this user are shares where they are the owner. |
|
| 749 | + */ |
|
| 750 | + if ($reshares === false) { |
|
| 751 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
| 752 | + } else { |
|
| 753 | + $qb->andWhere( |
|
| 754 | + $qb->expr()->orX( |
|
| 755 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 756 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 757 | + ) |
|
| 758 | + ); |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + $qb->innerJoin('s', 'filecache' ,'f', 's.file_source = f.fileid'); |
|
| 762 | + $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
| 763 | + |
|
| 764 | + $qb->orderBy('id'); |
|
| 765 | + |
|
| 766 | + $cursor = $qb->execute(); |
|
| 767 | + $shares = []; |
|
| 768 | + while ($data = $cursor->fetch()) { |
|
| 769 | + $shares[$data['fileid']][] = $this->createShareObject($data); |
|
| 770 | + } |
|
| 771 | + $cursor->closeCursor(); |
|
| 772 | + |
|
| 773 | + return $shares; |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + public function getAccessList($nodes, $currentAccess) { |
|
| 777 | + $ids = []; |
|
| 778 | + foreach ($nodes as $node) { |
|
| 779 | + $ids[] = $node->getId(); |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 783 | + $qb->select('share_with') |
|
| 784 | + ->from('share') |
|
| 785 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 786 | + ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 787 | + ->andWhere($qb->expr()->orX( |
|
| 788 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 789 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 790 | + )) |
|
| 791 | + ->setMaxResults(1); |
|
| 792 | + $cursor = $qb->execute(); |
|
| 793 | + |
|
| 794 | + $mail = $cursor->fetch() !== false; |
|
| 795 | + $cursor->closeCursor(); |
|
| 796 | + |
|
| 797 | + return ['mail' => $mail]; |
|
| 798 | + } |
|
| 799 | 799 | |
| 800 | 800 | } |
@@ -50,947 +50,947 @@ |
||
| 50 | 50 | */ |
| 51 | 51 | class FederatedShareProvider implements IShareProvider { |
| 52 | 52 | |
| 53 | - const SHARE_TYPE_REMOTE = 6; |
|
| 54 | - |
|
| 55 | - /** @var IDBConnection */ |
|
| 56 | - private $dbConnection; |
|
| 57 | - |
|
| 58 | - /** @var AddressHandler */ |
|
| 59 | - private $addressHandler; |
|
| 60 | - |
|
| 61 | - /** @var Notifications */ |
|
| 62 | - private $notifications; |
|
| 63 | - |
|
| 64 | - /** @var TokenHandler */ |
|
| 65 | - private $tokenHandler; |
|
| 66 | - |
|
| 67 | - /** @var IL10N */ |
|
| 68 | - private $l; |
|
| 69 | - |
|
| 70 | - /** @var ILogger */ |
|
| 71 | - private $logger; |
|
| 72 | - |
|
| 73 | - /** @var IRootFolder */ |
|
| 74 | - private $rootFolder; |
|
| 75 | - |
|
| 76 | - /** @var IConfig */ |
|
| 77 | - private $config; |
|
| 78 | - |
|
| 79 | - /** @var string */ |
|
| 80 | - private $externalShareTable = 'share_external'; |
|
| 81 | - |
|
| 82 | - /** @var IUserManager */ |
|
| 83 | - private $userManager; |
|
| 84 | - |
|
| 85 | - /** @var ICloudIdManager */ |
|
| 86 | - private $cloudIdManager; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * DefaultShareProvider constructor. |
|
| 90 | - * |
|
| 91 | - * @param IDBConnection $connection |
|
| 92 | - * @param AddressHandler $addressHandler |
|
| 93 | - * @param Notifications $notifications |
|
| 94 | - * @param TokenHandler $tokenHandler |
|
| 95 | - * @param IL10N $l10n |
|
| 96 | - * @param ILogger $logger |
|
| 97 | - * @param IRootFolder $rootFolder |
|
| 98 | - * @param IConfig $config |
|
| 99 | - * @param IUserManager $userManager |
|
| 100 | - * @param ICloudIdManager $cloudIdManager |
|
| 101 | - */ |
|
| 102 | - public function __construct( |
|
| 103 | - IDBConnection $connection, |
|
| 104 | - AddressHandler $addressHandler, |
|
| 105 | - Notifications $notifications, |
|
| 106 | - TokenHandler $tokenHandler, |
|
| 107 | - IL10N $l10n, |
|
| 108 | - ILogger $logger, |
|
| 109 | - IRootFolder $rootFolder, |
|
| 110 | - IConfig $config, |
|
| 111 | - IUserManager $userManager, |
|
| 112 | - ICloudIdManager $cloudIdManager |
|
| 113 | - ) { |
|
| 114 | - $this->dbConnection = $connection; |
|
| 115 | - $this->addressHandler = $addressHandler; |
|
| 116 | - $this->notifications = $notifications; |
|
| 117 | - $this->tokenHandler = $tokenHandler; |
|
| 118 | - $this->l = $l10n; |
|
| 119 | - $this->logger = $logger; |
|
| 120 | - $this->rootFolder = $rootFolder; |
|
| 121 | - $this->config = $config; |
|
| 122 | - $this->userManager = $userManager; |
|
| 123 | - $this->cloudIdManager = $cloudIdManager; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Return the identifier of this provider. |
|
| 128 | - * |
|
| 129 | - * @return string Containing only [a-zA-Z0-9] |
|
| 130 | - */ |
|
| 131 | - public function identifier() { |
|
| 132 | - return 'ocFederatedSharing'; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Share a path |
|
| 137 | - * |
|
| 138 | - * @param IShare $share |
|
| 139 | - * @return IShare The share object |
|
| 140 | - * @throws ShareNotFound |
|
| 141 | - * @throws \Exception |
|
| 142 | - */ |
|
| 143 | - public function create(IShare $share) { |
|
| 144 | - |
|
| 145 | - $shareWith = $share->getSharedWith(); |
|
| 146 | - $itemSource = $share->getNodeId(); |
|
| 147 | - $itemType = $share->getNodeType(); |
|
| 148 | - $permissions = $share->getPermissions(); |
|
| 149 | - $sharedBy = $share->getSharedBy(); |
|
| 150 | - |
|
| 151 | - /* |
|
| 53 | + const SHARE_TYPE_REMOTE = 6; |
|
| 54 | + |
|
| 55 | + /** @var IDBConnection */ |
|
| 56 | + private $dbConnection; |
|
| 57 | + |
|
| 58 | + /** @var AddressHandler */ |
|
| 59 | + private $addressHandler; |
|
| 60 | + |
|
| 61 | + /** @var Notifications */ |
|
| 62 | + private $notifications; |
|
| 63 | + |
|
| 64 | + /** @var TokenHandler */ |
|
| 65 | + private $tokenHandler; |
|
| 66 | + |
|
| 67 | + /** @var IL10N */ |
|
| 68 | + private $l; |
|
| 69 | + |
|
| 70 | + /** @var ILogger */ |
|
| 71 | + private $logger; |
|
| 72 | + |
|
| 73 | + /** @var IRootFolder */ |
|
| 74 | + private $rootFolder; |
|
| 75 | + |
|
| 76 | + /** @var IConfig */ |
|
| 77 | + private $config; |
|
| 78 | + |
|
| 79 | + /** @var string */ |
|
| 80 | + private $externalShareTable = 'share_external'; |
|
| 81 | + |
|
| 82 | + /** @var IUserManager */ |
|
| 83 | + private $userManager; |
|
| 84 | + |
|
| 85 | + /** @var ICloudIdManager */ |
|
| 86 | + private $cloudIdManager; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * DefaultShareProvider constructor. |
|
| 90 | + * |
|
| 91 | + * @param IDBConnection $connection |
|
| 92 | + * @param AddressHandler $addressHandler |
|
| 93 | + * @param Notifications $notifications |
|
| 94 | + * @param TokenHandler $tokenHandler |
|
| 95 | + * @param IL10N $l10n |
|
| 96 | + * @param ILogger $logger |
|
| 97 | + * @param IRootFolder $rootFolder |
|
| 98 | + * @param IConfig $config |
|
| 99 | + * @param IUserManager $userManager |
|
| 100 | + * @param ICloudIdManager $cloudIdManager |
|
| 101 | + */ |
|
| 102 | + public function __construct( |
|
| 103 | + IDBConnection $connection, |
|
| 104 | + AddressHandler $addressHandler, |
|
| 105 | + Notifications $notifications, |
|
| 106 | + TokenHandler $tokenHandler, |
|
| 107 | + IL10N $l10n, |
|
| 108 | + ILogger $logger, |
|
| 109 | + IRootFolder $rootFolder, |
|
| 110 | + IConfig $config, |
|
| 111 | + IUserManager $userManager, |
|
| 112 | + ICloudIdManager $cloudIdManager |
|
| 113 | + ) { |
|
| 114 | + $this->dbConnection = $connection; |
|
| 115 | + $this->addressHandler = $addressHandler; |
|
| 116 | + $this->notifications = $notifications; |
|
| 117 | + $this->tokenHandler = $tokenHandler; |
|
| 118 | + $this->l = $l10n; |
|
| 119 | + $this->logger = $logger; |
|
| 120 | + $this->rootFolder = $rootFolder; |
|
| 121 | + $this->config = $config; |
|
| 122 | + $this->userManager = $userManager; |
|
| 123 | + $this->cloudIdManager = $cloudIdManager; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Return the identifier of this provider. |
|
| 128 | + * |
|
| 129 | + * @return string Containing only [a-zA-Z0-9] |
|
| 130 | + */ |
|
| 131 | + public function identifier() { |
|
| 132 | + return 'ocFederatedSharing'; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Share a path |
|
| 137 | + * |
|
| 138 | + * @param IShare $share |
|
| 139 | + * @return IShare The share object |
|
| 140 | + * @throws ShareNotFound |
|
| 141 | + * @throws \Exception |
|
| 142 | + */ |
|
| 143 | + public function create(IShare $share) { |
|
| 144 | + |
|
| 145 | + $shareWith = $share->getSharedWith(); |
|
| 146 | + $itemSource = $share->getNodeId(); |
|
| 147 | + $itemType = $share->getNodeType(); |
|
| 148 | + $permissions = $share->getPermissions(); |
|
| 149 | + $sharedBy = $share->getSharedBy(); |
|
| 150 | + |
|
| 151 | + /* |
|
| 152 | 152 | * Check if file is not already shared with the remote user |
| 153 | 153 | */ |
| 154 | - $alreadyShared = $this->getSharedWith($shareWith, self::SHARE_TYPE_REMOTE, $share->getNode(), 1, 0); |
|
| 155 | - if (!empty($alreadyShared)) { |
|
| 156 | - $message = 'Sharing %s failed, because this item is already shared with %s'; |
|
| 157 | - $message_t = $this->l->t('Sharing %s failed, because this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
| 158 | - $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
| 159 | - throw new \Exception($message_t); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - // don't allow federated shares if source and target server are the same |
|
| 164 | - $cloudId = $this->cloudIdManager->resolveCloudId($shareWith); |
|
| 165 | - $currentServer = $this->addressHandler->generateRemoteURL(); |
|
| 166 | - $currentUser = $sharedBy; |
|
| 167 | - if ($this->addressHandler->compareAddresses($cloudId->getUser(), $cloudId->getRemote(), $currentUser, $currentServer)) { |
|
| 168 | - $message = 'Not allowed to create a federated share with the same user.'; |
|
| 169 | - $message_t = $this->l->t('Not allowed to create a federated share with the same user'); |
|
| 170 | - $this->logger->debug($message, ['app' => 'Federated File Sharing']); |
|
| 171 | - throw new \Exception($message_t); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - $share->setSharedWith($cloudId->getId()); |
|
| 176 | - |
|
| 177 | - try { |
|
| 178 | - $remoteShare = $this->getShareFromExternalShareTable($share); |
|
| 179 | - } catch (ShareNotFound $e) { |
|
| 180 | - $remoteShare = null; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - if ($remoteShare) { |
|
| 184 | - try { |
|
| 185 | - $ownerCloudId = $this->cloudIdManager->getCloudId($remoteShare['owner'], $remoteShare['remote']); |
|
| 186 | - $shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time()); |
|
| 187 | - $share->setId($shareId); |
|
| 188 | - list($token, $remoteId) = $this->askOwnerToReShare($shareWith, $share, $shareId); |
|
| 189 | - // remote share was create successfully if we get a valid token as return |
|
| 190 | - $send = is_string($token) && $token !== ''; |
|
| 191 | - } catch (\Exception $e) { |
|
| 192 | - // fall back to old re-share behavior if the remote server |
|
| 193 | - // doesn't support flat re-shares (was introduced with Nextcloud 9.1) |
|
| 194 | - $this->removeShareFromTable($share); |
|
| 195 | - $shareId = $this->createFederatedShare($share); |
|
| 196 | - } |
|
| 197 | - if ($send) { |
|
| 198 | - $this->updateSuccessfulReshare($shareId, $token); |
|
| 199 | - $this->storeRemoteId($shareId, $remoteId); |
|
| 200 | - } else { |
|
| 201 | - $this->removeShareFromTable($share); |
|
| 202 | - $message_t = $this->l->t('File is already shared with %s', [$shareWith]); |
|
| 203 | - throw new \Exception($message_t); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - } else { |
|
| 207 | - $shareId = $this->createFederatedShare($share); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - $data = $this->getRawShare($shareId); |
|
| 211 | - return $this->createShareObject($data); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * create federated share and inform the recipient |
|
| 216 | - * |
|
| 217 | - * @param IShare $share |
|
| 218 | - * @return int |
|
| 219 | - * @throws ShareNotFound |
|
| 220 | - * @throws \Exception |
|
| 221 | - */ |
|
| 222 | - protected function createFederatedShare(IShare $share) { |
|
| 223 | - $token = $this->tokenHandler->generateToken(); |
|
| 224 | - $shareId = $this->addShareToDB( |
|
| 225 | - $share->getNodeId(), |
|
| 226 | - $share->getNodeType(), |
|
| 227 | - $share->getSharedWith(), |
|
| 228 | - $share->getSharedBy(), |
|
| 229 | - $share->getShareOwner(), |
|
| 230 | - $share->getPermissions(), |
|
| 231 | - $token |
|
| 232 | - ); |
|
| 233 | - |
|
| 234 | - $failure = false; |
|
| 235 | - |
|
| 236 | - try { |
|
| 237 | - $sharedByFederatedId = $share->getSharedBy(); |
|
| 238 | - if ($this->userManager->userExists($sharedByFederatedId)) { |
|
| 239 | - $cloudId = $this->cloudIdManager->getCloudId($sharedByFederatedId, $this->addressHandler->generateRemoteURL()); |
|
| 240 | - $sharedByFederatedId = $cloudId->getId(); |
|
| 241 | - } |
|
| 242 | - $ownerCloudId = $this->cloudIdManager->getCloudId($share->getShareOwner(), $this->addressHandler->generateRemoteURL()); |
|
| 243 | - $send = $this->notifications->sendRemoteShare( |
|
| 244 | - $token, |
|
| 245 | - $share->getSharedWith(), |
|
| 246 | - $share->getNode()->getName(), |
|
| 247 | - $shareId, |
|
| 248 | - $share->getShareOwner(), |
|
| 249 | - $ownerCloudId->getId(), |
|
| 250 | - $share->getSharedBy(), |
|
| 251 | - $sharedByFederatedId |
|
| 252 | - ); |
|
| 253 | - |
|
| 254 | - if ($send === false) { |
|
| 255 | - $failure = true; |
|
| 256 | - } |
|
| 257 | - } catch (\Exception $e) { |
|
| 258 | - $this->logger->error('Failed to notify remote server of federated share, removing share (' . $e->getMessage() . ')'); |
|
| 259 | - $failure = true; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - if($failure) { |
|
| 263 | - $this->removeShareFromTableById($shareId); |
|
| 264 | - $message_t = $this->l->t('Sharing %s failed, could not find %s, maybe the server is currently unreachable or uses a self-signed certificate.', |
|
| 265 | - [$share->getNode()->getName(), $share->getSharedWith()]); |
|
| 266 | - throw new \Exception($message_t); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - return $shareId; |
|
| 270 | - |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * @param string $shareWith |
|
| 275 | - * @param IShare $share |
|
| 276 | - * @param string $shareId internal share Id |
|
| 277 | - * @return array |
|
| 278 | - * @throws \Exception |
|
| 279 | - */ |
|
| 280 | - protected function askOwnerToReShare($shareWith, IShare $share, $shareId) { |
|
| 281 | - |
|
| 282 | - $remoteShare = $this->getShareFromExternalShareTable($share); |
|
| 283 | - $token = $remoteShare['share_token']; |
|
| 284 | - $remoteId = $remoteShare['remote_id']; |
|
| 285 | - $remote = $remoteShare['remote']; |
|
| 286 | - |
|
| 287 | - list($token, $remoteId) = $this->notifications->requestReShare( |
|
| 288 | - $token, |
|
| 289 | - $remoteId, |
|
| 290 | - $shareId, |
|
| 291 | - $remote, |
|
| 292 | - $shareWith, |
|
| 293 | - $share->getPermissions() |
|
| 294 | - ); |
|
| 295 | - |
|
| 296 | - return [$token, $remoteId]; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * get federated share from the share_external table but exclude mounted link shares |
|
| 301 | - * |
|
| 302 | - * @param IShare $share |
|
| 303 | - * @return array |
|
| 304 | - * @throws ShareNotFound |
|
| 305 | - */ |
|
| 306 | - protected function getShareFromExternalShareTable(IShare $share) { |
|
| 307 | - $query = $this->dbConnection->getQueryBuilder(); |
|
| 308 | - $query->select('*')->from($this->externalShareTable) |
|
| 309 | - ->where($query->expr()->eq('user', $query->createNamedParameter($share->getShareOwner()))) |
|
| 310 | - ->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($share->getTarget()))); |
|
| 311 | - $result = $query->execute()->fetchAll(); |
|
| 312 | - |
|
| 313 | - if (isset($result[0]) && (int)$result[0]['remote_id'] > 0) { |
|
| 314 | - return $result[0]; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - throw new ShareNotFound('share not found in share_external table'); |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * add share to the database and return the ID |
|
| 322 | - * |
|
| 323 | - * @param int $itemSource |
|
| 324 | - * @param string $itemType |
|
| 325 | - * @param string $shareWith |
|
| 326 | - * @param string $sharedBy |
|
| 327 | - * @param string $uidOwner |
|
| 328 | - * @param int $permissions |
|
| 329 | - * @param string $token |
|
| 330 | - * @return int |
|
| 331 | - */ |
|
| 332 | - private function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) { |
|
| 333 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 334 | - $qb->insert('share') |
|
| 335 | - ->setValue('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)) |
|
| 336 | - ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
| 337 | - ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
| 338 | - ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
| 339 | - ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
| 340 | - ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
| 341 | - ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
| 342 | - ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
| 343 | - ->setValue('token', $qb->createNamedParameter($token)) |
|
| 344 | - ->setValue('stime', $qb->createNamedParameter(time())); |
|
| 345 | - |
|
| 346 | - /* |
|
| 154 | + $alreadyShared = $this->getSharedWith($shareWith, self::SHARE_TYPE_REMOTE, $share->getNode(), 1, 0); |
|
| 155 | + if (!empty($alreadyShared)) { |
|
| 156 | + $message = 'Sharing %s failed, because this item is already shared with %s'; |
|
| 157 | + $message_t = $this->l->t('Sharing %s failed, because this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
| 158 | + $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
| 159 | + throw new \Exception($message_t); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + // don't allow federated shares if source and target server are the same |
|
| 164 | + $cloudId = $this->cloudIdManager->resolveCloudId($shareWith); |
|
| 165 | + $currentServer = $this->addressHandler->generateRemoteURL(); |
|
| 166 | + $currentUser = $sharedBy; |
|
| 167 | + if ($this->addressHandler->compareAddresses($cloudId->getUser(), $cloudId->getRemote(), $currentUser, $currentServer)) { |
|
| 168 | + $message = 'Not allowed to create a federated share with the same user.'; |
|
| 169 | + $message_t = $this->l->t('Not allowed to create a federated share with the same user'); |
|
| 170 | + $this->logger->debug($message, ['app' => 'Federated File Sharing']); |
|
| 171 | + throw new \Exception($message_t); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + $share->setSharedWith($cloudId->getId()); |
|
| 176 | + |
|
| 177 | + try { |
|
| 178 | + $remoteShare = $this->getShareFromExternalShareTable($share); |
|
| 179 | + } catch (ShareNotFound $e) { |
|
| 180 | + $remoteShare = null; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + if ($remoteShare) { |
|
| 184 | + try { |
|
| 185 | + $ownerCloudId = $this->cloudIdManager->getCloudId($remoteShare['owner'], $remoteShare['remote']); |
|
| 186 | + $shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time()); |
|
| 187 | + $share->setId($shareId); |
|
| 188 | + list($token, $remoteId) = $this->askOwnerToReShare($shareWith, $share, $shareId); |
|
| 189 | + // remote share was create successfully if we get a valid token as return |
|
| 190 | + $send = is_string($token) && $token !== ''; |
|
| 191 | + } catch (\Exception $e) { |
|
| 192 | + // fall back to old re-share behavior if the remote server |
|
| 193 | + // doesn't support flat re-shares (was introduced with Nextcloud 9.1) |
|
| 194 | + $this->removeShareFromTable($share); |
|
| 195 | + $shareId = $this->createFederatedShare($share); |
|
| 196 | + } |
|
| 197 | + if ($send) { |
|
| 198 | + $this->updateSuccessfulReshare($shareId, $token); |
|
| 199 | + $this->storeRemoteId($shareId, $remoteId); |
|
| 200 | + } else { |
|
| 201 | + $this->removeShareFromTable($share); |
|
| 202 | + $message_t = $this->l->t('File is already shared with %s', [$shareWith]); |
|
| 203 | + throw new \Exception($message_t); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + } else { |
|
| 207 | + $shareId = $this->createFederatedShare($share); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + $data = $this->getRawShare($shareId); |
|
| 211 | + return $this->createShareObject($data); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * create federated share and inform the recipient |
|
| 216 | + * |
|
| 217 | + * @param IShare $share |
|
| 218 | + * @return int |
|
| 219 | + * @throws ShareNotFound |
|
| 220 | + * @throws \Exception |
|
| 221 | + */ |
|
| 222 | + protected function createFederatedShare(IShare $share) { |
|
| 223 | + $token = $this->tokenHandler->generateToken(); |
|
| 224 | + $shareId = $this->addShareToDB( |
|
| 225 | + $share->getNodeId(), |
|
| 226 | + $share->getNodeType(), |
|
| 227 | + $share->getSharedWith(), |
|
| 228 | + $share->getSharedBy(), |
|
| 229 | + $share->getShareOwner(), |
|
| 230 | + $share->getPermissions(), |
|
| 231 | + $token |
|
| 232 | + ); |
|
| 233 | + |
|
| 234 | + $failure = false; |
|
| 235 | + |
|
| 236 | + try { |
|
| 237 | + $sharedByFederatedId = $share->getSharedBy(); |
|
| 238 | + if ($this->userManager->userExists($sharedByFederatedId)) { |
|
| 239 | + $cloudId = $this->cloudIdManager->getCloudId($sharedByFederatedId, $this->addressHandler->generateRemoteURL()); |
|
| 240 | + $sharedByFederatedId = $cloudId->getId(); |
|
| 241 | + } |
|
| 242 | + $ownerCloudId = $this->cloudIdManager->getCloudId($share->getShareOwner(), $this->addressHandler->generateRemoteURL()); |
|
| 243 | + $send = $this->notifications->sendRemoteShare( |
|
| 244 | + $token, |
|
| 245 | + $share->getSharedWith(), |
|
| 246 | + $share->getNode()->getName(), |
|
| 247 | + $shareId, |
|
| 248 | + $share->getShareOwner(), |
|
| 249 | + $ownerCloudId->getId(), |
|
| 250 | + $share->getSharedBy(), |
|
| 251 | + $sharedByFederatedId |
|
| 252 | + ); |
|
| 253 | + |
|
| 254 | + if ($send === false) { |
|
| 255 | + $failure = true; |
|
| 256 | + } |
|
| 257 | + } catch (\Exception $e) { |
|
| 258 | + $this->logger->error('Failed to notify remote server of federated share, removing share (' . $e->getMessage() . ')'); |
|
| 259 | + $failure = true; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + if($failure) { |
|
| 263 | + $this->removeShareFromTableById($shareId); |
|
| 264 | + $message_t = $this->l->t('Sharing %s failed, could not find %s, maybe the server is currently unreachable or uses a self-signed certificate.', |
|
| 265 | + [$share->getNode()->getName(), $share->getSharedWith()]); |
|
| 266 | + throw new \Exception($message_t); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + return $shareId; |
|
| 270 | + |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * @param string $shareWith |
|
| 275 | + * @param IShare $share |
|
| 276 | + * @param string $shareId internal share Id |
|
| 277 | + * @return array |
|
| 278 | + * @throws \Exception |
|
| 279 | + */ |
|
| 280 | + protected function askOwnerToReShare($shareWith, IShare $share, $shareId) { |
|
| 281 | + |
|
| 282 | + $remoteShare = $this->getShareFromExternalShareTable($share); |
|
| 283 | + $token = $remoteShare['share_token']; |
|
| 284 | + $remoteId = $remoteShare['remote_id']; |
|
| 285 | + $remote = $remoteShare['remote']; |
|
| 286 | + |
|
| 287 | + list($token, $remoteId) = $this->notifications->requestReShare( |
|
| 288 | + $token, |
|
| 289 | + $remoteId, |
|
| 290 | + $shareId, |
|
| 291 | + $remote, |
|
| 292 | + $shareWith, |
|
| 293 | + $share->getPermissions() |
|
| 294 | + ); |
|
| 295 | + |
|
| 296 | + return [$token, $remoteId]; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * get federated share from the share_external table but exclude mounted link shares |
|
| 301 | + * |
|
| 302 | + * @param IShare $share |
|
| 303 | + * @return array |
|
| 304 | + * @throws ShareNotFound |
|
| 305 | + */ |
|
| 306 | + protected function getShareFromExternalShareTable(IShare $share) { |
|
| 307 | + $query = $this->dbConnection->getQueryBuilder(); |
|
| 308 | + $query->select('*')->from($this->externalShareTable) |
|
| 309 | + ->where($query->expr()->eq('user', $query->createNamedParameter($share->getShareOwner()))) |
|
| 310 | + ->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($share->getTarget()))); |
|
| 311 | + $result = $query->execute()->fetchAll(); |
|
| 312 | + |
|
| 313 | + if (isset($result[0]) && (int)$result[0]['remote_id'] > 0) { |
|
| 314 | + return $result[0]; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + throw new ShareNotFound('share not found in share_external table'); |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * add share to the database and return the ID |
|
| 322 | + * |
|
| 323 | + * @param int $itemSource |
|
| 324 | + * @param string $itemType |
|
| 325 | + * @param string $shareWith |
|
| 326 | + * @param string $sharedBy |
|
| 327 | + * @param string $uidOwner |
|
| 328 | + * @param int $permissions |
|
| 329 | + * @param string $token |
|
| 330 | + * @return int |
|
| 331 | + */ |
|
| 332 | + private function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) { |
|
| 333 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 334 | + $qb->insert('share') |
|
| 335 | + ->setValue('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)) |
|
| 336 | + ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
| 337 | + ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
| 338 | + ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
| 339 | + ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
| 340 | + ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
| 341 | + ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
| 342 | + ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
| 343 | + ->setValue('token', $qb->createNamedParameter($token)) |
|
| 344 | + ->setValue('stime', $qb->createNamedParameter(time())); |
|
| 345 | + |
|
| 346 | + /* |
|
| 347 | 347 | * Added to fix https://github.com/owncloud/core/issues/22215 |
| 348 | 348 | * Can be removed once we get rid of ajax/share.php |
| 349 | 349 | */ |
| 350 | - $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
| 351 | - |
|
| 352 | - $qb->execute(); |
|
| 353 | - $id = $qb->getLastInsertId(); |
|
| 354 | - |
|
| 355 | - return (int)$id; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * Update a share |
|
| 360 | - * |
|
| 361 | - * @param IShare $share |
|
| 362 | - * @return IShare The share object |
|
| 363 | - */ |
|
| 364 | - public function update(IShare $share) { |
|
| 365 | - /* |
|
| 350 | + $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
| 351 | + |
|
| 352 | + $qb->execute(); |
|
| 353 | + $id = $qb->getLastInsertId(); |
|
| 354 | + |
|
| 355 | + return (int)$id; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * Update a share |
|
| 360 | + * |
|
| 361 | + * @param IShare $share |
|
| 362 | + * @return IShare The share object |
|
| 363 | + */ |
|
| 364 | + public function update(IShare $share) { |
|
| 365 | + /* |
|
| 366 | 366 | * We allow updating the permissions of federated shares |
| 367 | 367 | */ |
| 368 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 369 | - $qb->update('share') |
|
| 370 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
| 371 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
| 372 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
| 373 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
| 374 | - ->execute(); |
|
| 375 | - |
|
| 376 | - // send the updated permission to the owner/initiator, if they are not the same |
|
| 377 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 378 | - $this->sendPermissionUpdate($share); |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - return $share; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * send the updated permission to the owner/initiator, if they are not the same |
|
| 386 | - * |
|
| 387 | - * @param IShare $share |
|
| 388 | - * @throws ShareNotFound |
|
| 389 | - * @throws \OC\HintException |
|
| 390 | - */ |
|
| 391 | - protected function sendPermissionUpdate(IShare $share) { |
|
| 392 | - $remoteId = $this->getRemoteId($share); |
|
| 393 | - // if the local user is the owner we send the permission change to the initiator |
|
| 394 | - if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 395 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 396 | - } else { // ... if not we send the permission change to the owner |
|
| 397 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
| 398 | - } |
|
| 399 | - $this->notifications->sendPermissionChange($remote, $remoteId, $share->getToken(), $share->getPermissions()); |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * update successful reShare with the correct token |
|
| 405 | - * |
|
| 406 | - * @param int $shareId |
|
| 407 | - * @param string $token |
|
| 408 | - */ |
|
| 409 | - protected function updateSuccessfulReShare($shareId, $token) { |
|
| 410 | - $query = $this->dbConnection->getQueryBuilder(); |
|
| 411 | - $query->update('share') |
|
| 412 | - ->where($query->expr()->eq('id', $query->createNamedParameter($shareId))) |
|
| 413 | - ->set('token', $query->createNamedParameter($token)) |
|
| 414 | - ->execute(); |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * store remote ID in federated reShare table |
|
| 419 | - * |
|
| 420 | - * @param $shareId |
|
| 421 | - * @param $remoteId |
|
| 422 | - */ |
|
| 423 | - public function storeRemoteId($shareId, $remoteId) { |
|
| 424 | - $query = $this->dbConnection->getQueryBuilder(); |
|
| 425 | - $query->insert('federated_reshares') |
|
| 426 | - ->values( |
|
| 427 | - [ |
|
| 428 | - 'share_id' => $query->createNamedParameter($shareId), |
|
| 429 | - 'remote_id' => $query->createNamedParameter($remoteId), |
|
| 430 | - ] |
|
| 431 | - ); |
|
| 432 | - $query->execute(); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * get share ID on remote server for federated re-shares |
|
| 437 | - * |
|
| 438 | - * @param IShare $share |
|
| 439 | - * @return int |
|
| 440 | - * @throws ShareNotFound |
|
| 441 | - */ |
|
| 442 | - public function getRemoteId(IShare $share) { |
|
| 443 | - $query = $this->dbConnection->getQueryBuilder(); |
|
| 444 | - $query->select('remote_id')->from('federated_reshares') |
|
| 445 | - ->where($query->expr()->eq('share_id', $query->createNamedParameter((int)$share->getId()))); |
|
| 446 | - $data = $query->execute()->fetch(); |
|
| 447 | - |
|
| 448 | - if (!is_array($data) || !isset($data['remote_id'])) { |
|
| 449 | - throw new ShareNotFound(); |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - return (int)$data['remote_id']; |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * @inheritdoc |
|
| 457 | - */ |
|
| 458 | - public function move(IShare $share, $recipient) { |
|
| 459 | - /* |
|
| 368 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 369 | + $qb->update('share') |
|
| 370 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
| 371 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
| 372 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
| 373 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
| 374 | + ->execute(); |
|
| 375 | + |
|
| 376 | + // send the updated permission to the owner/initiator, if they are not the same |
|
| 377 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 378 | + $this->sendPermissionUpdate($share); |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + return $share; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * send the updated permission to the owner/initiator, if they are not the same |
|
| 386 | + * |
|
| 387 | + * @param IShare $share |
|
| 388 | + * @throws ShareNotFound |
|
| 389 | + * @throws \OC\HintException |
|
| 390 | + */ |
|
| 391 | + protected function sendPermissionUpdate(IShare $share) { |
|
| 392 | + $remoteId = $this->getRemoteId($share); |
|
| 393 | + // if the local user is the owner we send the permission change to the initiator |
|
| 394 | + if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 395 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 396 | + } else { // ... if not we send the permission change to the owner |
|
| 397 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
| 398 | + } |
|
| 399 | + $this->notifications->sendPermissionChange($remote, $remoteId, $share->getToken(), $share->getPermissions()); |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * update successful reShare with the correct token |
|
| 405 | + * |
|
| 406 | + * @param int $shareId |
|
| 407 | + * @param string $token |
|
| 408 | + */ |
|
| 409 | + protected function updateSuccessfulReShare($shareId, $token) { |
|
| 410 | + $query = $this->dbConnection->getQueryBuilder(); |
|
| 411 | + $query->update('share') |
|
| 412 | + ->where($query->expr()->eq('id', $query->createNamedParameter($shareId))) |
|
| 413 | + ->set('token', $query->createNamedParameter($token)) |
|
| 414 | + ->execute(); |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * store remote ID in federated reShare table |
|
| 419 | + * |
|
| 420 | + * @param $shareId |
|
| 421 | + * @param $remoteId |
|
| 422 | + */ |
|
| 423 | + public function storeRemoteId($shareId, $remoteId) { |
|
| 424 | + $query = $this->dbConnection->getQueryBuilder(); |
|
| 425 | + $query->insert('federated_reshares') |
|
| 426 | + ->values( |
|
| 427 | + [ |
|
| 428 | + 'share_id' => $query->createNamedParameter($shareId), |
|
| 429 | + 'remote_id' => $query->createNamedParameter($remoteId), |
|
| 430 | + ] |
|
| 431 | + ); |
|
| 432 | + $query->execute(); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * get share ID on remote server for federated re-shares |
|
| 437 | + * |
|
| 438 | + * @param IShare $share |
|
| 439 | + * @return int |
|
| 440 | + * @throws ShareNotFound |
|
| 441 | + */ |
|
| 442 | + public function getRemoteId(IShare $share) { |
|
| 443 | + $query = $this->dbConnection->getQueryBuilder(); |
|
| 444 | + $query->select('remote_id')->from('federated_reshares') |
|
| 445 | + ->where($query->expr()->eq('share_id', $query->createNamedParameter((int)$share->getId()))); |
|
| 446 | + $data = $query->execute()->fetch(); |
|
| 447 | + |
|
| 448 | + if (!is_array($data) || !isset($data['remote_id'])) { |
|
| 449 | + throw new ShareNotFound(); |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + return (int)$data['remote_id']; |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * @inheritdoc |
|
| 457 | + */ |
|
| 458 | + public function move(IShare $share, $recipient) { |
|
| 459 | + /* |
|
| 460 | 460 | * This function does nothing yet as it is just for outgoing |
| 461 | 461 | * federated shares. |
| 462 | 462 | */ |
| 463 | - return $share; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * Get all children of this share |
|
| 468 | - * |
|
| 469 | - * @param IShare $parent |
|
| 470 | - * @return IShare[] |
|
| 471 | - */ |
|
| 472 | - public function getChildren(IShare $parent) { |
|
| 473 | - $children = []; |
|
| 474 | - |
|
| 475 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 476 | - $qb->select('*') |
|
| 477 | - ->from('share') |
|
| 478 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
| 479 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
| 480 | - ->orderBy('id'); |
|
| 481 | - |
|
| 482 | - $cursor = $qb->execute(); |
|
| 483 | - while($data = $cursor->fetch()) { |
|
| 484 | - $children[] = $this->createShareObject($data); |
|
| 485 | - } |
|
| 486 | - $cursor->closeCursor(); |
|
| 487 | - |
|
| 488 | - return $children; |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * Delete a share (owner unShares the file) |
|
| 493 | - * |
|
| 494 | - * @param IShare $share |
|
| 495 | - */ |
|
| 496 | - public function delete(IShare $share) { |
|
| 497 | - |
|
| 498 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedWith()); |
|
| 499 | - |
|
| 500 | - $isOwner = false; |
|
| 501 | - |
|
| 502 | - $this->removeShareFromTable($share); |
|
| 503 | - |
|
| 504 | - // if the local user is the owner we can send the unShare request directly... |
|
| 505 | - if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 506 | - $this->notifications->sendRemoteUnShare($remote, $share->getId(), $share->getToken()); |
|
| 507 | - $this->revokeShare($share, true); |
|
| 508 | - $isOwner = true; |
|
| 509 | - } else { // ... if not we need to correct ID for the unShare request |
|
| 510 | - $remoteId = $this->getRemoteId($share); |
|
| 511 | - $this->notifications->sendRemoteUnShare($remote, $remoteId, $share->getToken()); |
|
| 512 | - $this->revokeShare($share, false); |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - // send revoke notification to the other user, if initiator and owner are not the same user |
|
| 516 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 517 | - $remoteId = $this->getRemoteId($share); |
|
| 518 | - if ($isOwner) { |
|
| 519 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 520 | - } else { |
|
| 521 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
| 522 | - } |
|
| 523 | - $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken()); |
|
| 524 | - } |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * in case of a re-share we need to send the other use (initiator or owner) |
|
| 529 | - * a message that the file was unshared |
|
| 530 | - * |
|
| 531 | - * @param IShare $share |
|
| 532 | - * @param bool $isOwner the user can either be the owner or the user who re-sahred it |
|
| 533 | - * @throws ShareNotFound |
|
| 534 | - * @throws \OC\HintException |
|
| 535 | - */ |
|
| 536 | - protected function revokeShare($share, $isOwner) { |
|
| 537 | - // also send a unShare request to the initiator, if this is a different user than the owner |
|
| 538 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 539 | - if ($isOwner) { |
|
| 540 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 541 | - } else { |
|
| 542 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
| 543 | - } |
|
| 544 | - $remoteId = $this->getRemoteId($share); |
|
| 545 | - $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken()); |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * remove share from table |
|
| 551 | - * |
|
| 552 | - * @param IShare $share |
|
| 553 | - */ |
|
| 554 | - public function removeShareFromTable(IShare $share) { |
|
| 555 | - $this->removeShareFromTableById($share->getId()); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * remove share from table |
|
| 560 | - * |
|
| 561 | - * @param string $shareId |
|
| 562 | - */ |
|
| 563 | - private function removeShareFromTableById($shareId) { |
|
| 564 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 565 | - $qb->delete('share') |
|
| 566 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
| 567 | - $qb->execute(); |
|
| 568 | - |
|
| 569 | - $qb->delete('federated_reshares') |
|
| 570 | - ->where($qb->expr()->eq('share_id', $qb->createNamedParameter($shareId))); |
|
| 571 | - $qb->execute(); |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - /** |
|
| 575 | - * @inheritdoc |
|
| 576 | - */ |
|
| 577 | - public function deleteFromSelf(IShare $share, $recipient) { |
|
| 578 | - // nothing to do here. Technically deleteFromSelf in the context of federated |
|
| 579 | - // shares is a umount of a external storage. This is handled here |
|
| 580 | - // apps/files_sharing/lib/external/manager.php |
|
| 581 | - // TODO move this code over to this app |
|
| 582 | - return; |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - |
|
| 586 | - public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
| 587 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 588 | - $qb->select('*') |
|
| 589 | - ->from('share', 's') |
|
| 590 | - ->andWhere($qb->expr()->orX( |
|
| 591 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 592 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 593 | - )) |
|
| 594 | - ->andWhere( |
|
| 595 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE)) |
|
| 596 | - ); |
|
| 597 | - |
|
| 598 | - /** |
|
| 599 | - * Reshares for this user are shares where they are the owner. |
|
| 600 | - */ |
|
| 601 | - if ($reshares === false) { |
|
| 602 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
| 603 | - } else { |
|
| 604 | - $qb->andWhere( |
|
| 605 | - $qb->expr()->orX( |
|
| 606 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 607 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 608 | - ) |
|
| 609 | - ); |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - $qb->innerJoin('s', 'filecache' ,'f', 's.file_source = f.fileid'); |
|
| 613 | - $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
| 614 | - |
|
| 615 | - $qb->orderBy('id'); |
|
| 616 | - |
|
| 617 | - $cursor = $qb->execute(); |
|
| 618 | - $shares = []; |
|
| 619 | - while ($data = $cursor->fetch()) { |
|
| 620 | - $shares[$data['fileid']][] = $this->createShareObject($data); |
|
| 621 | - } |
|
| 622 | - $cursor->closeCursor(); |
|
| 623 | - |
|
| 624 | - return $shares; |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * @inheritdoc |
|
| 629 | - */ |
|
| 630 | - public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
| 631 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 632 | - $qb->select('*') |
|
| 633 | - ->from('share'); |
|
| 634 | - |
|
| 635 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
| 636 | - |
|
| 637 | - /** |
|
| 638 | - * Reshares for this user are shares where they are the owner. |
|
| 639 | - */ |
|
| 640 | - if ($reshares === false) { |
|
| 641 | - //Special case for old shares created via the web UI |
|
| 642 | - $or1 = $qb->expr()->andX( |
|
| 643 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 644 | - $qb->expr()->isNull('uid_initiator') |
|
| 645 | - ); |
|
| 646 | - |
|
| 647 | - $qb->andWhere( |
|
| 648 | - $qb->expr()->orX( |
|
| 649 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
| 650 | - $or1 |
|
| 651 | - ) |
|
| 652 | - ); |
|
| 653 | - } else { |
|
| 654 | - $qb->andWhere( |
|
| 655 | - $qb->expr()->orX( |
|
| 656 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 657 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 658 | - ) |
|
| 659 | - ); |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - if ($node !== null) { |
|
| 663 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - if ($limit !== -1) { |
|
| 667 | - $qb->setMaxResults($limit); |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - $qb->setFirstResult($offset); |
|
| 671 | - $qb->orderBy('id'); |
|
| 672 | - |
|
| 673 | - $cursor = $qb->execute(); |
|
| 674 | - $shares = []; |
|
| 675 | - while($data = $cursor->fetch()) { |
|
| 676 | - $shares[] = $this->createShareObject($data); |
|
| 677 | - } |
|
| 678 | - $cursor->closeCursor(); |
|
| 679 | - |
|
| 680 | - return $shares; |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * @inheritdoc |
|
| 685 | - */ |
|
| 686 | - public function getShareById($id, $recipientId = null) { |
|
| 687 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 688 | - |
|
| 689 | - $qb->select('*') |
|
| 690 | - ->from('share') |
|
| 691 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 692 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
| 693 | - |
|
| 694 | - $cursor = $qb->execute(); |
|
| 695 | - $data = $cursor->fetch(); |
|
| 696 | - $cursor->closeCursor(); |
|
| 697 | - |
|
| 698 | - if ($data === false) { |
|
| 699 | - throw new ShareNotFound(); |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - try { |
|
| 703 | - $share = $this->createShareObject($data); |
|
| 704 | - } catch (InvalidShare $e) { |
|
| 705 | - throw new ShareNotFound(); |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - return $share; |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * Get shares for a given path |
|
| 713 | - * |
|
| 714 | - * @param \OCP\Files\Node $path |
|
| 715 | - * @return IShare[] |
|
| 716 | - */ |
|
| 717 | - public function getSharesByPath(Node $path) { |
|
| 718 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 719 | - |
|
| 720 | - $cursor = $qb->select('*') |
|
| 721 | - ->from('share') |
|
| 722 | - ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
| 723 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
| 724 | - ->execute(); |
|
| 725 | - |
|
| 726 | - $shares = []; |
|
| 727 | - while($data = $cursor->fetch()) { |
|
| 728 | - $shares[] = $this->createShareObject($data); |
|
| 729 | - } |
|
| 730 | - $cursor->closeCursor(); |
|
| 731 | - |
|
| 732 | - return $shares; |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - /** |
|
| 736 | - * @inheritdoc |
|
| 737 | - */ |
|
| 738 | - public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
| 739 | - /** @var IShare[] $shares */ |
|
| 740 | - $shares = []; |
|
| 741 | - |
|
| 742 | - //Get shares directly with this user |
|
| 743 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 744 | - $qb->select('*') |
|
| 745 | - ->from('share'); |
|
| 746 | - |
|
| 747 | - // Order by id |
|
| 748 | - $qb->orderBy('id'); |
|
| 749 | - |
|
| 750 | - // Set limit and offset |
|
| 751 | - if ($limit !== -1) { |
|
| 752 | - $qb->setMaxResults($limit); |
|
| 753 | - } |
|
| 754 | - $qb->setFirstResult($offset); |
|
| 755 | - |
|
| 756 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
| 757 | - $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
| 758 | - |
|
| 759 | - // Filter by node if provided |
|
| 760 | - if ($node !== null) { |
|
| 761 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - $cursor = $qb->execute(); |
|
| 765 | - |
|
| 766 | - while($data = $cursor->fetch()) { |
|
| 767 | - $shares[] = $this->createShareObject($data); |
|
| 768 | - } |
|
| 769 | - $cursor->closeCursor(); |
|
| 770 | - |
|
| 771 | - |
|
| 772 | - return $shares; |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - /** |
|
| 776 | - * Get a share by token |
|
| 777 | - * |
|
| 778 | - * @param string $token |
|
| 779 | - * @return IShare |
|
| 780 | - * @throws ShareNotFound |
|
| 781 | - */ |
|
| 782 | - public function getShareByToken($token) { |
|
| 783 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 784 | - |
|
| 785 | - $cursor = $qb->select('*') |
|
| 786 | - ->from('share') |
|
| 787 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
| 788 | - ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 789 | - ->execute(); |
|
| 790 | - |
|
| 791 | - $data = $cursor->fetch(); |
|
| 792 | - |
|
| 793 | - if ($data === false) { |
|
| 794 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - try { |
|
| 798 | - $share = $this->createShareObject($data); |
|
| 799 | - } catch (InvalidShare $e) { |
|
| 800 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - return $share; |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - /** |
|
| 807 | - * get database row of a give share |
|
| 808 | - * |
|
| 809 | - * @param $id |
|
| 810 | - * @return array |
|
| 811 | - * @throws ShareNotFound |
|
| 812 | - */ |
|
| 813 | - private function getRawShare($id) { |
|
| 814 | - |
|
| 815 | - // Now fetch the inserted share and create a complete share object |
|
| 816 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 817 | - $qb->select('*') |
|
| 818 | - ->from('share') |
|
| 819 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
| 820 | - |
|
| 821 | - $cursor = $qb->execute(); |
|
| 822 | - $data = $cursor->fetch(); |
|
| 823 | - $cursor->closeCursor(); |
|
| 824 | - |
|
| 825 | - if ($data === false) { |
|
| 826 | - throw new ShareNotFound; |
|
| 827 | - } |
|
| 828 | - |
|
| 829 | - return $data; |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - /** |
|
| 833 | - * Create a share object from an database row |
|
| 834 | - * |
|
| 835 | - * @param array $data |
|
| 836 | - * @return IShare |
|
| 837 | - * @throws InvalidShare |
|
| 838 | - * @throws ShareNotFound |
|
| 839 | - */ |
|
| 840 | - private function createShareObject($data) { |
|
| 841 | - |
|
| 842 | - $share = new Share($this->rootFolder, $this->userManager); |
|
| 843 | - $share->setId((int)$data['id']) |
|
| 844 | - ->setShareType((int)$data['share_type']) |
|
| 845 | - ->setPermissions((int)$data['permissions']) |
|
| 846 | - ->setTarget($data['file_target']) |
|
| 847 | - ->setMailSend((bool)$data['mail_send']) |
|
| 848 | - ->setToken($data['token']); |
|
| 849 | - |
|
| 850 | - $shareTime = new \DateTime(); |
|
| 851 | - $shareTime->setTimestamp((int)$data['stime']); |
|
| 852 | - $share->setShareTime($shareTime); |
|
| 853 | - $share->setSharedWith($data['share_with']); |
|
| 854 | - |
|
| 855 | - if ($data['uid_initiator'] !== null) { |
|
| 856 | - $share->setShareOwner($data['uid_owner']); |
|
| 857 | - $share->setSharedBy($data['uid_initiator']); |
|
| 858 | - } else { |
|
| 859 | - //OLD SHARE |
|
| 860 | - $share->setSharedBy($data['uid_owner']); |
|
| 861 | - $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
| 862 | - |
|
| 863 | - $owner = $path->getOwner(); |
|
| 864 | - $share->setShareOwner($owner->getUID()); |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - $share->setNodeId((int)$data['file_source']); |
|
| 868 | - $share->setNodeType($data['item_type']); |
|
| 869 | - |
|
| 870 | - $share->setProviderId($this->identifier()); |
|
| 871 | - |
|
| 872 | - return $share; |
|
| 873 | - } |
|
| 874 | - |
|
| 875 | - /** |
|
| 876 | - * Get the node with file $id for $user |
|
| 877 | - * |
|
| 878 | - * @param string $userId |
|
| 879 | - * @param int $id |
|
| 880 | - * @return \OCP\Files\File|\OCP\Files\Folder |
|
| 881 | - * @throws InvalidShare |
|
| 882 | - */ |
|
| 883 | - private function getNode($userId, $id) { |
|
| 884 | - try { |
|
| 885 | - $userFolder = $this->rootFolder->getUserFolder($userId); |
|
| 886 | - } catch (NotFoundException $e) { |
|
| 887 | - throw new InvalidShare(); |
|
| 888 | - } |
|
| 889 | - |
|
| 890 | - $nodes = $userFolder->getById($id); |
|
| 891 | - |
|
| 892 | - if (empty($nodes)) { |
|
| 893 | - throw new InvalidShare(); |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - return $nodes[0]; |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - /** |
|
| 900 | - * A user is deleted from the system |
|
| 901 | - * So clean up the relevant shares. |
|
| 902 | - * |
|
| 903 | - * @param string $uid |
|
| 904 | - * @param int $shareType |
|
| 905 | - */ |
|
| 906 | - public function userDeleted($uid, $shareType) { |
|
| 907 | - //TODO: probabaly a good idea to send unshare info to remote servers |
|
| 908 | - |
|
| 909 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 910 | - |
|
| 911 | - $qb->delete('share') |
|
| 912 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE))) |
|
| 913 | - ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
| 914 | - ->execute(); |
|
| 915 | - } |
|
| 916 | - |
|
| 917 | - /** |
|
| 918 | - * This provider does not handle groups |
|
| 919 | - * |
|
| 920 | - * @param string $gid |
|
| 921 | - */ |
|
| 922 | - public function groupDeleted($gid) { |
|
| 923 | - // We don't handle groups here |
|
| 924 | - return; |
|
| 925 | - } |
|
| 926 | - |
|
| 927 | - /** |
|
| 928 | - * This provider does not handle groups |
|
| 929 | - * |
|
| 930 | - * @param string $uid |
|
| 931 | - * @param string $gid |
|
| 932 | - */ |
|
| 933 | - public function userDeletedFromGroup($uid, $gid) { |
|
| 934 | - // We don't handle groups here |
|
| 935 | - return; |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - /** |
|
| 939 | - * check if users from other Nextcloud instances are allowed to mount public links share by this instance |
|
| 940 | - * |
|
| 941 | - * @return bool |
|
| 942 | - */ |
|
| 943 | - public function isOutgoingServer2serverShareEnabled() { |
|
| 944 | - $result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes'); |
|
| 945 | - return ($result === 'yes') ? true : false; |
|
| 946 | - } |
|
| 947 | - |
|
| 948 | - /** |
|
| 949 | - * check if users are allowed to mount public links from other ownClouds |
|
| 950 | - * |
|
| 951 | - * @return bool |
|
| 952 | - */ |
|
| 953 | - public function isIncomingServer2serverShareEnabled() { |
|
| 954 | - $result = $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes'); |
|
| 955 | - return ($result === 'yes') ? true : false; |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - /** |
|
| 959 | - * Check if querying sharees on the lookup server is enabled |
|
| 960 | - * |
|
| 961 | - * @return bool |
|
| 962 | - */ |
|
| 963 | - public function isLookupServerQueriesEnabled() { |
|
| 964 | - $result = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no'); |
|
| 965 | - return ($result === 'yes') ? true : false; |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - public function getAccessList($nodes, $currentAccess) { |
|
| 969 | - $ids = []; |
|
| 970 | - foreach ($nodes as $node) { |
|
| 971 | - $ids[] = $node->getId(); |
|
| 972 | - } |
|
| 973 | - |
|
| 974 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 975 | - $qb->select('share_with', 'file_source', 'file_target') |
|
| 976 | - ->from('share') |
|
| 977 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE))) |
|
| 978 | - ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 979 | - ->andWhere($qb->expr()->orX( |
|
| 980 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 981 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 982 | - )); |
|
| 983 | - $cursor = $qb->execute(); |
|
| 984 | - |
|
| 985 | - $remote = []; |
|
| 986 | - while ($row = $cursor->fetch()) { |
|
| 987 | - $remote[$row['share_with']] = [ |
|
| 988 | - 'node_id' => $row['file_source'], |
|
| 989 | - 'node_path' => $row['file_target'], |
|
| 990 | - ]; |
|
| 991 | - } |
|
| 992 | - $cursor->closeCursor(); |
|
| 993 | - |
|
| 994 | - return ['remote' => $remote]; |
|
| 995 | - } |
|
| 463 | + return $share; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * Get all children of this share |
|
| 468 | + * |
|
| 469 | + * @param IShare $parent |
|
| 470 | + * @return IShare[] |
|
| 471 | + */ |
|
| 472 | + public function getChildren(IShare $parent) { |
|
| 473 | + $children = []; |
|
| 474 | + |
|
| 475 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 476 | + $qb->select('*') |
|
| 477 | + ->from('share') |
|
| 478 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
| 479 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
| 480 | + ->orderBy('id'); |
|
| 481 | + |
|
| 482 | + $cursor = $qb->execute(); |
|
| 483 | + while($data = $cursor->fetch()) { |
|
| 484 | + $children[] = $this->createShareObject($data); |
|
| 485 | + } |
|
| 486 | + $cursor->closeCursor(); |
|
| 487 | + |
|
| 488 | + return $children; |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * Delete a share (owner unShares the file) |
|
| 493 | + * |
|
| 494 | + * @param IShare $share |
|
| 495 | + */ |
|
| 496 | + public function delete(IShare $share) { |
|
| 497 | + |
|
| 498 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedWith()); |
|
| 499 | + |
|
| 500 | + $isOwner = false; |
|
| 501 | + |
|
| 502 | + $this->removeShareFromTable($share); |
|
| 503 | + |
|
| 504 | + // if the local user is the owner we can send the unShare request directly... |
|
| 505 | + if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 506 | + $this->notifications->sendRemoteUnShare($remote, $share->getId(), $share->getToken()); |
|
| 507 | + $this->revokeShare($share, true); |
|
| 508 | + $isOwner = true; |
|
| 509 | + } else { // ... if not we need to correct ID for the unShare request |
|
| 510 | + $remoteId = $this->getRemoteId($share); |
|
| 511 | + $this->notifications->sendRemoteUnShare($remote, $remoteId, $share->getToken()); |
|
| 512 | + $this->revokeShare($share, false); |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + // send revoke notification to the other user, if initiator and owner are not the same user |
|
| 516 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 517 | + $remoteId = $this->getRemoteId($share); |
|
| 518 | + if ($isOwner) { |
|
| 519 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 520 | + } else { |
|
| 521 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
| 522 | + } |
|
| 523 | + $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken()); |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * in case of a re-share we need to send the other use (initiator or owner) |
|
| 529 | + * a message that the file was unshared |
|
| 530 | + * |
|
| 531 | + * @param IShare $share |
|
| 532 | + * @param bool $isOwner the user can either be the owner or the user who re-sahred it |
|
| 533 | + * @throws ShareNotFound |
|
| 534 | + * @throws \OC\HintException |
|
| 535 | + */ |
|
| 536 | + protected function revokeShare($share, $isOwner) { |
|
| 537 | + // also send a unShare request to the initiator, if this is a different user than the owner |
|
| 538 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 539 | + if ($isOwner) { |
|
| 540 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 541 | + } else { |
|
| 542 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
| 543 | + } |
|
| 544 | + $remoteId = $this->getRemoteId($share); |
|
| 545 | + $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken()); |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * remove share from table |
|
| 551 | + * |
|
| 552 | + * @param IShare $share |
|
| 553 | + */ |
|
| 554 | + public function removeShareFromTable(IShare $share) { |
|
| 555 | + $this->removeShareFromTableById($share->getId()); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * remove share from table |
|
| 560 | + * |
|
| 561 | + * @param string $shareId |
|
| 562 | + */ |
|
| 563 | + private function removeShareFromTableById($shareId) { |
|
| 564 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 565 | + $qb->delete('share') |
|
| 566 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
| 567 | + $qb->execute(); |
|
| 568 | + |
|
| 569 | + $qb->delete('federated_reshares') |
|
| 570 | + ->where($qb->expr()->eq('share_id', $qb->createNamedParameter($shareId))); |
|
| 571 | + $qb->execute(); |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + /** |
|
| 575 | + * @inheritdoc |
|
| 576 | + */ |
|
| 577 | + public function deleteFromSelf(IShare $share, $recipient) { |
|
| 578 | + // nothing to do here. Technically deleteFromSelf in the context of federated |
|
| 579 | + // shares is a umount of a external storage. This is handled here |
|
| 580 | + // apps/files_sharing/lib/external/manager.php |
|
| 581 | + // TODO move this code over to this app |
|
| 582 | + return; |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + |
|
| 586 | + public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
| 587 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 588 | + $qb->select('*') |
|
| 589 | + ->from('share', 's') |
|
| 590 | + ->andWhere($qb->expr()->orX( |
|
| 591 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 592 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 593 | + )) |
|
| 594 | + ->andWhere( |
|
| 595 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE)) |
|
| 596 | + ); |
|
| 597 | + |
|
| 598 | + /** |
|
| 599 | + * Reshares for this user are shares where they are the owner. |
|
| 600 | + */ |
|
| 601 | + if ($reshares === false) { |
|
| 602 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
| 603 | + } else { |
|
| 604 | + $qb->andWhere( |
|
| 605 | + $qb->expr()->orX( |
|
| 606 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 607 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 608 | + ) |
|
| 609 | + ); |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + $qb->innerJoin('s', 'filecache' ,'f', 's.file_source = f.fileid'); |
|
| 613 | + $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
| 614 | + |
|
| 615 | + $qb->orderBy('id'); |
|
| 616 | + |
|
| 617 | + $cursor = $qb->execute(); |
|
| 618 | + $shares = []; |
|
| 619 | + while ($data = $cursor->fetch()) { |
|
| 620 | + $shares[$data['fileid']][] = $this->createShareObject($data); |
|
| 621 | + } |
|
| 622 | + $cursor->closeCursor(); |
|
| 623 | + |
|
| 624 | + return $shares; |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * @inheritdoc |
|
| 629 | + */ |
|
| 630 | + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
| 631 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 632 | + $qb->select('*') |
|
| 633 | + ->from('share'); |
|
| 634 | + |
|
| 635 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
| 636 | + |
|
| 637 | + /** |
|
| 638 | + * Reshares for this user are shares where they are the owner. |
|
| 639 | + */ |
|
| 640 | + if ($reshares === false) { |
|
| 641 | + //Special case for old shares created via the web UI |
|
| 642 | + $or1 = $qb->expr()->andX( |
|
| 643 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 644 | + $qb->expr()->isNull('uid_initiator') |
|
| 645 | + ); |
|
| 646 | + |
|
| 647 | + $qb->andWhere( |
|
| 648 | + $qb->expr()->orX( |
|
| 649 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
| 650 | + $or1 |
|
| 651 | + ) |
|
| 652 | + ); |
|
| 653 | + } else { |
|
| 654 | + $qb->andWhere( |
|
| 655 | + $qb->expr()->orX( |
|
| 656 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 657 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 658 | + ) |
|
| 659 | + ); |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + if ($node !== null) { |
|
| 663 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + if ($limit !== -1) { |
|
| 667 | + $qb->setMaxResults($limit); |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + $qb->setFirstResult($offset); |
|
| 671 | + $qb->orderBy('id'); |
|
| 672 | + |
|
| 673 | + $cursor = $qb->execute(); |
|
| 674 | + $shares = []; |
|
| 675 | + while($data = $cursor->fetch()) { |
|
| 676 | + $shares[] = $this->createShareObject($data); |
|
| 677 | + } |
|
| 678 | + $cursor->closeCursor(); |
|
| 679 | + |
|
| 680 | + return $shares; |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + /** |
|
| 684 | + * @inheritdoc |
|
| 685 | + */ |
|
| 686 | + public function getShareById($id, $recipientId = null) { |
|
| 687 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 688 | + |
|
| 689 | + $qb->select('*') |
|
| 690 | + ->from('share') |
|
| 691 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 692 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
| 693 | + |
|
| 694 | + $cursor = $qb->execute(); |
|
| 695 | + $data = $cursor->fetch(); |
|
| 696 | + $cursor->closeCursor(); |
|
| 697 | + |
|
| 698 | + if ($data === false) { |
|
| 699 | + throw new ShareNotFound(); |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + try { |
|
| 703 | + $share = $this->createShareObject($data); |
|
| 704 | + } catch (InvalidShare $e) { |
|
| 705 | + throw new ShareNotFound(); |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + return $share; |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * Get shares for a given path |
|
| 713 | + * |
|
| 714 | + * @param \OCP\Files\Node $path |
|
| 715 | + * @return IShare[] |
|
| 716 | + */ |
|
| 717 | + public function getSharesByPath(Node $path) { |
|
| 718 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 719 | + |
|
| 720 | + $cursor = $qb->select('*') |
|
| 721 | + ->from('share') |
|
| 722 | + ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
| 723 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
| 724 | + ->execute(); |
|
| 725 | + |
|
| 726 | + $shares = []; |
|
| 727 | + while($data = $cursor->fetch()) { |
|
| 728 | + $shares[] = $this->createShareObject($data); |
|
| 729 | + } |
|
| 730 | + $cursor->closeCursor(); |
|
| 731 | + |
|
| 732 | + return $shares; |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + /** |
|
| 736 | + * @inheritdoc |
|
| 737 | + */ |
|
| 738 | + public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
| 739 | + /** @var IShare[] $shares */ |
|
| 740 | + $shares = []; |
|
| 741 | + |
|
| 742 | + //Get shares directly with this user |
|
| 743 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 744 | + $qb->select('*') |
|
| 745 | + ->from('share'); |
|
| 746 | + |
|
| 747 | + // Order by id |
|
| 748 | + $qb->orderBy('id'); |
|
| 749 | + |
|
| 750 | + // Set limit and offset |
|
| 751 | + if ($limit !== -1) { |
|
| 752 | + $qb->setMaxResults($limit); |
|
| 753 | + } |
|
| 754 | + $qb->setFirstResult($offset); |
|
| 755 | + |
|
| 756 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
| 757 | + $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
| 758 | + |
|
| 759 | + // Filter by node if provided |
|
| 760 | + if ($node !== null) { |
|
| 761 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + $cursor = $qb->execute(); |
|
| 765 | + |
|
| 766 | + while($data = $cursor->fetch()) { |
|
| 767 | + $shares[] = $this->createShareObject($data); |
|
| 768 | + } |
|
| 769 | + $cursor->closeCursor(); |
|
| 770 | + |
|
| 771 | + |
|
| 772 | + return $shares; |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + /** |
|
| 776 | + * Get a share by token |
|
| 777 | + * |
|
| 778 | + * @param string $token |
|
| 779 | + * @return IShare |
|
| 780 | + * @throws ShareNotFound |
|
| 781 | + */ |
|
| 782 | + public function getShareByToken($token) { |
|
| 783 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 784 | + |
|
| 785 | + $cursor = $qb->select('*') |
|
| 786 | + ->from('share') |
|
| 787 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
| 788 | + ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 789 | + ->execute(); |
|
| 790 | + |
|
| 791 | + $data = $cursor->fetch(); |
|
| 792 | + |
|
| 793 | + if ($data === false) { |
|
| 794 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + try { |
|
| 798 | + $share = $this->createShareObject($data); |
|
| 799 | + } catch (InvalidShare $e) { |
|
| 800 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + return $share; |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + /** |
|
| 807 | + * get database row of a give share |
|
| 808 | + * |
|
| 809 | + * @param $id |
|
| 810 | + * @return array |
|
| 811 | + * @throws ShareNotFound |
|
| 812 | + */ |
|
| 813 | + private function getRawShare($id) { |
|
| 814 | + |
|
| 815 | + // Now fetch the inserted share and create a complete share object |
|
| 816 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 817 | + $qb->select('*') |
|
| 818 | + ->from('share') |
|
| 819 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
| 820 | + |
|
| 821 | + $cursor = $qb->execute(); |
|
| 822 | + $data = $cursor->fetch(); |
|
| 823 | + $cursor->closeCursor(); |
|
| 824 | + |
|
| 825 | + if ($data === false) { |
|
| 826 | + throw new ShareNotFound; |
|
| 827 | + } |
|
| 828 | + |
|
| 829 | + return $data; |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + /** |
|
| 833 | + * Create a share object from an database row |
|
| 834 | + * |
|
| 835 | + * @param array $data |
|
| 836 | + * @return IShare |
|
| 837 | + * @throws InvalidShare |
|
| 838 | + * @throws ShareNotFound |
|
| 839 | + */ |
|
| 840 | + private function createShareObject($data) { |
|
| 841 | + |
|
| 842 | + $share = new Share($this->rootFolder, $this->userManager); |
|
| 843 | + $share->setId((int)$data['id']) |
|
| 844 | + ->setShareType((int)$data['share_type']) |
|
| 845 | + ->setPermissions((int)$data['permissions']) |
|
| 846 | + ->setTarget($data['file_target']) |
|
| 847 | + ->setMailSend((bool)$data['mail_send']) |
|
| 848 | + ->setToken($data['token']); |
|
| 849 | + |
|
| 850 | + $shareTime = new \DateTime(); |
|
| 851 | + $shareTime->setTimestamp((int)$data['stime']); |
|
| 852 | + $share->setShareTime($shareTime); |
|
| 853 | + $share->setSharedWith($data['share_with']); |
|
| 854 | + |
|
| 855 | + if ($data['uid_initiator'] !== null) { |
|
| 856 | + $share->setShareOwner($data['uid_owner']); |
|
| 857 | + $share->setSharedBy($data['uid_initiator']); |
|
| 858 | + } else { |
|
| 859 | + //OLD SHARE |
|
| 860 | + $share->setSharedBy($data['uid_owner']); |
|
| 861 | + $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
| 862 | + |
|
| 863 | + $owner = $path->getOwner(); |
|
| 864 | + $share->setShareOwner($owner->getUID()); |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + $share->setNodeId((int)$data['file_source']); |
|
| 868 | + $share->setNodeType($data['item_type']); |
|
| 869 | + |
|
| 870 | + $share->setProviderId($this->identifier()); |
|
| 871 | + |
|
| 872 | + return $share; |
|
| 873 | + } |
|
| 874 | + |
|
| 875 | + /** |
|
| 876 | + * Get the node with file $id for $user |
|
| 877 | + * |
|
| 878 | + * @param string $userId |
|
| 879 | + * @param int $id |
|
| 880 | + * @return \OCP\Files\File|\OCP\Files\Folder |
|
| 881 | + * @throws InvalidShare |
|
| 882 | + */ |
|
| 883 | + private function getNode($userId, $id) { |
|
| 884 | + try { |
|
| 885 | + $userFolder = $this->rootFolder->getUserFolder($userId); |
|
| 886 | + } catch (NotFoundException $e) { |
|
| 887 | + throw new InvalidShare(); |
|
| 888 | + } |
|
| 889 | + |
|
| 890 | + $nodes = $userFolder->getById($id); |
|
| 891 | + |
|
| 892 | + if (empty($nodes)) { |
|
| 893 | + throw new InvalidShare(); |
|
| 894 | + } |
|
| 895 | + |
|
| 896 | + return $nodes[0]; |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * A user is deleted from the system |
|
| 901 | + * So clean up the relevant shares. |
|
| 902 | + * |
|
| 903 | + * @param string $uid |
|
| 904 | + * @param int $shareType |
|
| 905 | + */ |
|
| 906 | + public function userDeleted($uid, $shareType) { |
|
| 907 | + //TODO: probabaly a good idea to send unshare info to remote servers |
|
| 908 | + |
|
| 909 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 910 | + |
|
| 911 | + $qb->delete('share') |
|
| 912 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE))) |
|
| 913 | + ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
| 914 | + ->execute(); |
|
| 915 | + } |
|
| 916 | + |
|
| 917 | + /** |
|
| 918 | + * This provider does not handle groups |
|
| 919 | + * |
|
| 920 | + * @param string $gid |
|
| 921 | + */ |
|
| 922 | + public function groupDeleted($gid) { |
|
| 923 | + // We don't handle groups here |
|
| 924 | + return; |
|
| 925 | + } |
|
| 926 | + |
|
| 927 | + /** |
|
| 928 | + * This provider does not handle groups |
|
| 929 | + * |
|
| 930 | + * @param string $uid |
|
| 931 | + * @param string $gid |
|
| 932 | + */ |
|
| 933 | + public function userDeletedFromGroup($uid, $gid) { |
|
| 934 | + // We don't handle groups here |
|
| 935 | + return; |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + /** |
|
| 939 | + * check if users from other Nextcloud instances are allowed to mount public links share by this instance |
|
| 940 | + * |
|
| 941 | + * @return bool |
|
| 942 | + */ |
|
| 943 | + public function isOutgoingServer2serverShareEnabled() { |
|
| 944 | + $result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes'); |
|
| 945 | + return ($result === 'yes') ? true : false; |
|
| 946 | + } |
|
| 947 | + |
|
| 948 | + /** |
|
| 949 | + * check if users are allowed to mount public links from other ownClouds |
|
| 950 | + * |
|
| 951 | + * @return bool |
|
| 952 | + */ |
|
| 953 | + public function isIncomingServer2serverShareEnabled() { |
|
| 954 | + $result = $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes'); |
|
| 955 | + return ($result === 'yes') ? true : false; |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | + /** |
|
| 959 | + * Check if querying sharees on the lookup server is enabled |
|
| 960 | + * |
|
| 961 | + * @return bool |
|
| 962 | + */ |
|
| 963 | + public function isLookupServerQueriesEnabled() { |
|
| 964 | + $result = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no'); |
|
| 965 | + return ($result === 'yes') ? true : false; |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + public function getAccessList($nodes, $currentAccess) { |
|
| 969 | + $ids = []; |
|
| 970 | + foreach ($nodes as $node) { |
|
| 971 | + $ids[] = $node->getId(); |
|
| 972 | + } |
|
| 973 | + |
|
| 974 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 975 | + $qb->select('share_with', 'file_source', 'file_target') |
|
| 976 | + ->from('share') |
|
| 977 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE))) |
|
| 978 | + ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 979 | + ->andWhere($qb->expr()->orX( |
|
| 980 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 981 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 982 | + )); |
|
| 983 | + $cursor = $qb->execute(); |
|
| 984 | + |
|
| 985 | + $remote = []; |
|
| 986 | + while ($row = $cursor->fetch()) { |
|
| 987 | + $remote[$row['share_with']] = [ |
|
| 988 | + 'node_id' => $row['file_source'], |
|
| 989 | + 'node_path' => $row['file_target'], |
|
| 990 | + ]; |
|
| 991 | + } |
|
| 992 | + $cursor->closeCursor(); |
|
| 993 | + |
|
| 994 | + return ['remote' => $remote]; |
|
| 995 | + } |
|
| 996 | 996 | } |
@@ -34,178 +34,178 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | interface IShareProvider { |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Return the identifier of this provider. |
|
| 39 | - * |
|
| 40 | - * @return string Containing only [a-zA-Z0-9] |
|
| 41 | - * @since 9.0.0 |
|
| 42 | - */ |
|
| 43 | - public function identifier(); |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Create a share |
|
| 47 | - * |
|
| 48 | - * @param \OCP\Share\IShare $share |
|
| 49 | - * @return \OCP\Share\IShare The share object |
|
| 50 | - * @since 9.0.0 |
|
| 51 | - */ |
|
| 52 | - public function create(\OCP\Share\IShare $share); |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Update a share |
|
| 56 | - * |
|
| 57 | - * @param \OCP\Share\IShare $share |
|
| 58 | - * @return \OCP\Share\IShare The share object |
|
| 59 | - * @since 9.0.0 |
|
| 60 | - */ |
|
| 61 | - public function update(\OCP\Share\IShare $share); |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Delete a share |
|
| 65 | - * |
|
| 66 | - * @param \OCP\Share\IShare $share |
|
| 67 | - * @since 9.0.0 |
|
| 68 | - */ |
|
| 69 | - public function delete(\OCP\Share\IShare $share); |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Unshare a file from self as recipient. |
|
| 73 | - * This may require special handling. If a user unshares a group |
|
| 74 | - * share from their self then the original group share should still exist. |
|
| 75 | - * |
|
| 76 | - * @param \OCP\Share\IShare $share |
|
| 77 | - * @param string $recipient UserId of the recipient |
|
| 78 | - * @since 9.0.0 |
|
| 79 | - */ |
|
| 80 | - public function deleteFromSelf(\OCP\Share\IShare $share, $recipient); |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Move a share as a recipient. |
|
| 84 | - * This is updating the share target. Thus the mount point of the recipient. |
|
| 85 | - * This may require special handling. If a user moves a group share |
|
| 86 | - * the target should only be changed for them. |
|
| 87 | - * |
|
| 88 | - * @param \OCP\Share\IShare $share |
|
| 89 | - * @param string $recipient userId of recipient |
|
| 90 | - * @return \OCP\Share\IShare |
|
| 91 | - * @since 9.0.0 |
|
| 92 | - */ |
|
| 93 | - public function move(\OCP\Share\IShare $share, $recipient); |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Get all shares by the given user in a folder |
|
| 97 | - * |
|
| 98 | - * @param string $userId |
|
| 99 | - * @param Folder $node |
|
| 100 | - * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator |
|
| 101 | - * @return \OCP\Share\IShare[] |
|
| 102 | - * @since 11.0.0 |
|
| 103 | - */ |
|
| 104 | - public function getSharesInFolder($userId, Folder $node, $reshares); |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Get all shares by the given user |
|
| 108 | - * |
|
| 109 | - * @param string $userId |
|
| 110 | - * @param int $shareType |
|
| 111 | - * @param Node|null $node |
|
| 112 | - * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator |
|
| 113 | - * @param int $limit The maximum number of shares to be returned, -1 for all shares |
|
| 114 | - * @param int $offset |
|
| 115 | - * @return \OCP\Share\IShare[] |
|
| 116 | - * @since 9.0.0 |
|
| 117 | - */ |
|
| 118 | - public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset); |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Get share by id |
|
| 122 | - * |
|
| 123 | - * @param int $id |
|
| 124 | - * @param string|null $recipientId |
|
| 125 | - * @return \OCP\Share\IShare |
|
| 126 | - * @throws ShareNotFound |
|
| 127 | - * @since 9.0.0 |
|
| 128 | - */ |
|
| 129 | - public function getShareById($id, $recipientId = null); |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Get shares for a given path |
|
| 133 | - * |
|
| 134 | - * @param Node $path |
|
| 135 | - * @return \OCP\Share\IShare[] |
|
| 136 | - * @since 9.0.0 |
|
| 137 | - */ |
|
| 138 | - public function getSharesByPath(Node $path); |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Get shared with the given user |
|
| 142 | - * |
|
| 143 | - * @param string $userId get shares where this user is the recipient |
|
| 144 | - * @param int $shareType |
|
| 145 | - * @param Node|null $node |
|
| 146 | - * @param int $limit The max number of entries returned, -1 for all |
|
| 147 | - * @param int $offset |
|
| 148 | - * @return \OCP\Share\IShare[] |
|
| 149 | - * @since 9.0.0 |
|
| 150 | - */ |
|
| 151 | - public function getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Get a share by token |
|
| 155 | - * |
|
| 156 | - * @param string $token |
|
| 157 | - * @return \OCP\Share\IShare |
|
| 158 | - * @throws ShareNotFound |
|
| 159 | - * @since 9.0.0 |
|
| 160 | - */ |
|
| 161 | - public function getShareByToken($token); |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * A user is deleted from the system |
|
| 165 | - * So clean up the relevant shares. |
|
| 166 | - * |
|
| 167 | - * @param string $uid |
|
| 168 | - * @param int $shareType |
|
| 169 | - * @since 9.1.0 |
|
| 170 | - */ |
|
| 171 | - public function userDeleted($uid, $shareType); |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * A group is deleted from the system. |
|
| 175 | - * We have to clean up all shares to this group. |
|
| 176 | - * Providers not handling group shares should just return |
|
| 177 | - * |
|
| 178 | - * @param string $gid |
|
| 179 | - * @since 9.1.0 |
|
| 180 | - */ |
|
| 181 | - public function groupDeleted($gid); |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * A user is deleted from a group |
|
| 185 | - * We have to clean up all the related user specific group shares |
|
| 186 | - * Providers not handling group shares should just return |
|
| 187 | - * |
|
| 188 | - * @param string $uid |
|
| 189 | - * @param string $gid |
|
| 190 | - * @since 9.1.0 |
|
| 191 | - */ |
|
| 192 | - public function userDeletedFromGroup($uid, $gid); |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Get the access list to the array of provided nodes. |
|
| 196 | - * Return will look like: |
|
| 197 | - * |
|
| 198 | - * [ |
|
| 199 | - * users => ['user1' => ['node_id' => 42, 'node_path' => '/path'], 'user2' => [...]], |
|
| 200 | - * remote => ['user1' => ['node_id' => 42, 'node_path' => '/path'], 'user2' => [...]], |
|
| 201 | - * mail => bool |
|
| 202 | - * public => bool |
|
| 203 | - * ] |
|
| 204 | - * |
|
| 205 | - * @param Node[] $nodes The list of nodes to get access for |
|
| 206 | - * @param bool $currentAccess If current access is required (like for removed shares that might get revived later) |
|
| 207 | - * @return array |
|
| 208 | - * @since 12 |
|
| 209 | - */ |
|
| 210 | - public function getAccessList($nodes, $currentAccess); |
|
| 37 | + /** |
|
| 38 | + * Return the identifier of this provider. |
|
| 39 | + * |
|
| 40 | + * @return string Containing only [a-zA-Z0-9] |
|
| 41 | + * @since 9.0.0 |
|
| 42 | + */ |
|
| 43 | + public function identifier(); |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Create a share |
|
| 47 | + * |
|
| 48 | + * @param \OCP\Share\IShare $share |
|
| 49 | + * @return \OCP\Share\IShare The share object |
|
| 50 | + * @since 9.0.0 |
|
| 51 | + */ |
|
| 52 | + public function create(\OCP\Share\IShare $share); |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Update a share |
|
| 56 | + * |
|
| 57 | + * @param \OCP\Share\IShare $share |
|
| 58 | + * @return \OCP\Share\IShare The share object |
|
| 59 | + * @since 9.0.0 |
|
| 60 | + */ |
|
| 61 | + public function update(\OCP\Share\IShare $share); |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Delete a share |
|
| 65 | + * |
|
| 66 | + * @param \OCP\Share\IShare $share |
|
| 67 | + * @since 9.0.0 |
|
| 68 | + */ |
|
| 69 | + public function delete(\OCP\Share\IShare $share); |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Unshare a file from self as recipient. |
|
| 73 | + * This may require special handling. If a user unshares a group |
|
| 74 | + * share from their self then the original group share should still exist. |
|
| 75 | + * |
|
| 76 | + * @param \OCP\Share\IShare $share |
|
| 77 | + * @param string $recipient UserId of the recipient |
|
| 78 | + * @since 9.0.0 |
|
| 79 | + */ |
|
| 80 | + public function deleteFromSelf(\OCP\Share\IShare $share, $recipient); |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Move a share as a recipient. |
|
| 84 | + * This is updating the share target. Thus the mount point of the recipient. |
|
| 85 | + * This may require special handling. If a user moves a group share |
|
| 86 | + * the target should only be changed for them. |
|
| 87 | + * |
|
| 88 | + * @param \OCP\Share\IShare $share |
|
| 89 | + * @param string $recipient userId of recipient |
|
| 90 | + * @return \OCP\Share\IShare |
|
| 91 | + * @since 9.0.0 |
|
| 92 | + */ |
|
| 93 | + public function move(\OCP\Share\IShare $share, $recipient); |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Get all shares by the given user in a folder |
|
| 97 | + * |
|
| 98 | + * @param string $userId |
|
| 99 | + * @param Folder $node |
|
| 100 | + * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator |
|
| 101 | + * @return \OCP\Share\IShare[] |
|
| 102 | + * @since 11.0.0 |
|
| 103 | + */ |
|
| 104 | + public function getSharesInFolder($userId, Folder $node, $reshares); |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Get all shares by the given user |
|
| 108 | + * |
|
| 109 | + * @param string $userId |
|
| 110 | + * @param int $shareType |
|
| 111 | + * @param Node|null $node |
|
| 112 | + * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator |
|
| 113 | + * @param int $limit The maximum number of shares to be returned, -1 for all shares |
|
| 114 | + * @param int $offset |
|
| 115 | + * @return \OCP\Share\IShare[] |
|
| 116 | + * @since 9.0.0 |
|
| 117 | + */ |
|
| 118 | + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset); |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Get share by id |
|
| 122 | + * |
|
| 123 | + * @param int $id |
|
| 124 | + * @param string|null $recipientId |
|
| 125 | + * @return \OCP\Share\IShare |
|
| 126 | + * @throws ShareNotFound |
|
| 127 | + * @since 9.0.0 |
|
| 128 | + */ |
|
| 129 | + public function getShareById($id, $recipientId = null); |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Get shares for a given path |
|
| 133 | + * |
|
| 134 | + * @param Node $path |
|
| 135 | + * @return \OCP\Share\IShare[] |
|
| 136 | + * @since 9.0.0 |
|
| 137 | + */ |
|
| 138 | + public function getSharesByPath(Node $path); |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Get shared with the given user |
|
| 142 | + * |
|
| 143 | + * @param string $userId get shares where this user is the recipient |
|
| 144 | + * @param int $shareType |
|
| 145 | + * @param Node|null $node |
|
| 146 | + * @param int $limit The max number of entries returned, -1 for all |
|
| 147 | + * @param int $offset |
|
| 148 | + * @return \OCP\Share\IShare[] |
|
| 149 | + * @since 9.0.0 |
|
| 150 | + */ |
|
| 151 | + public function getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Get a share by token |
|
| 155 | + * |
|
| 156 | + * @param string $token |
|
| 157 | + * @return \OCP\Share\IShare |
|
| 158 | + * @throws ShareNotFound |
|
| 159 | + * @since 9.0.0 |
|
| 160 | + */ |
|
| 161 | + public function getShareByToken($token); |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * A user is deleted from the system |
|
| 165 | + * So clean up the relevant shares. |
|
| 166 | + * |
|
| 167 | + * @param string $uid |
|
| 168 | + * @param int $shareType |
|
| 169 | + * @since 9.1.0 |
|
| 170 | + */ |
|
| 171 | + public function userDeleted($uid, $shareType); |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * A group is deleted from the system. |
|
| 175 | + * We have to clean up all shares to this group. |
|
| 176 | + * Providers not handling group shares should just return |
|
| 177 | + * |
|
| 178 | + * @param string $gid |
|
| 179 | + * @since 9.1.0 |
|
| 180 | + */ |
|
| 181 | + public function groupDeleted($gid); |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * A user is deleted from a group |
|
| 185 | + * We have to clean up all the related user specific group shares |
|
| 186 | + * Providers not handling group shares should just return |
|
| 187 | + * |
|
| 188 | + * @param string $uid |
|
| 189 | + * @param string $gid |
|
| 190 | + * @since 9.1.0 |
|
| 191 | + */ |
|
| 192 | + public function userDeletedFromGroup($uid, $gid); |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Get the access list to the array of provided nodes. |
|
| 196 | + * Return will look like: |
|
| 197 | + * |
|
| 198 | + * [ |
|
| 199 | + * users => ['user1' => ['node_id' => 42, 'node_path' => '/path'], 'user2' => [...]], |
|
| 200 | + * remote => ['user1' => ['node_id' => 42, 'node_path' => '/path'], 'user2' => [...]], |
|
| 201 | + * mail => bool |
|
| 202 | + * public => bool |
|
| 203 | + * ] |
|
| 204 | + * |
|
| 205 | + * @param Node[] $nodes The list of nodes to get access for |
|
| 206 | + * @param bool $currentAccess If current access is required (like for removed shares that might get revived later) |
|
| 207 | + * @return array |
|
| 208 | + * @since 12 |
|
| 209 | + */ |
|
| 210 | + public function getAccessList($nodes, $currentAccess); |
|
| 211 | 211 | } |
@@ -32,10 +32,10 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | interface IShareHelper { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param Node $node |
|
| 37 | - * @return array [ users => [Mapping $uid => $path], remotes => [Mapping $cloudId => $path]] |
|
| 38 | - * @since 12 |
|
| 39 | - */ |
|
| 40 | - public function getPathsForAccessList(Node $node); |
|
| 35 | + /** |
|
| 36 | + * @param Node $node |
|
| 37 | + * @return array [ users => [Mapping $uid => $path], remotes => [Mapping $cloudId => $path]] |
|
| 38 | + * @since 12 |
|
| 39 | + */ |
|
| 40 | + public function getPathsForAccessList(Node $node); |
|
| 41 | 41 | } |
@@ -35,295 +35,295 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | interface IManager { |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Create a Share |
|
| 40 | - * |
|
| 41 | - * @param IShare $share |
|
| 42 | - * @return IShare The share object |
|
| 43 | - * @since 9.0.0 |
|
| 44 | - */ |
|
| 45 | - public function createShare(IShare $share); |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Update a share. |
|
| 49 | - * The target of the share can't be changed this way: use moveShare |
|
| 50 | - * The share can't be removed this way (permission 0): use deleteShare |
|
| 51 | - * |
|
| 52 | - * @param IShare $share |
|
| 53 | - * @return IShare The share object |
|
| 54 | - * @since 9.0.0 |
|
| 55 | - */ |
|
| 56 | - public function updateShare(IShare $share); |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Delete a share |
|
| 60 | - * |
|
| 61 | - * @param IShare $share |
|
| 62 | - * @throws ShareNotFound |
|
| 63 | - * @since 9.0.0 |
|
| 64 | - */ |
|
| 65 | - public function deleteShare(IShare $share); |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Unshare a file as the recipient. |
|
| 69 | - * This can be different from a regular delete for example when one of |
|
| 70 | - * the users in a groups deletes that share. But the provider should |
|
| 71 | - * handle this. |
|
| 72 | - * |
|
| 73 | - * @param IShare $share |
|
| 74 | - * @param string $recipientId |
|
| 75 | - * @since 9.0.0 |
|
| 76 | - */ |
|
| 77 | - public function deleteFromSelf(IShare $share, $recipientId); |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Move the share as a recipient of the share. |
|
| 81 | - * This is updating the share target. So where the recipient has the share mounted. |
|
| 82 | - * |
|
| 83 | - * @param IShare $share |
|
| 84 | - * @param string $recipientId |
|
| 85 | - * @return IShare |
|
| 86 | - * @throws \InvalidArgumentException If $share is a link share or the $recipient does not match |
|
| 87 | - * @since 9.0.0 |
|
| 88 | - */ |
|
| 89 | - public function moveShare(IShare $share, $recipientId); |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Get all shares shared by (initiated) by the provided user in a folder. |
|
| 93 | - * |
|
| 94 | - * @param string $userId |
|
| 95 | - * @param Folder $node |
|
| 96 | - * @param bool $reshares |
|
| 97 | - * @return IShare[][] [$fileId => IShare[], ...] |
|
| 98 | - * @since 11.0.0 |
|
| 99 | - */ |
|
| 100 | - public function getSharesInFolder($userId, Folder $node, $reshares = false); |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Get shares shared by (initiated) by the provided user. |
|
| 104 | - * |
|
| 105 | - * @param string $userId |
|
| 106 | - * @param int $shareType |
|
| 107 | - * @param Node|null $path |
|
| 108 | - * @param bool $reshares |
|
| 109 | - * @param int $limit The maximum number of returned results, -1 for all results |
|
| 110 | - * @param int $offset |
|
| 111 | - * @return IShare[] |
|
| 112 | - * @since 9.0.0 |
|
| 113 | - */ |
|
| 114 | - public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0); |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Get shares shared with $user. |
|
| 118 | - * Filter by $node if provided |
|
| 119 | - * |
|
| 120 | - * @param string $userId |
|
| 121 | - * @param int $shareType |
|
| 122 | - * @param Node|null $node |
|
| 123 | - * @param int $limit The maximum number of shares returned, -1 for all |
|
| 124 | - * @param int $offset |
|
| 125 | - * @return IShare[] |
|
| 126 | - * @since 9.0.0 |
|
| 127 | - */ |
|
| 128 | - public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0); |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Retrieve a share by the share id. |
|
| 132 | - * If the recipient is set make sure to retrieve the file for that user. |
|
| 133 | - * This makes sure that if a user has moved/deleted a group share this |
|
| 134 | - * is reflected. |
|
| 135 | - * |
|
| 136 | - * @param string $id |
|
| 137 | - * @param string|null $recipient userID of the recipient |
|
| 138 | - * @return IShare |
|
| 139 | - * @throws ShareNotFound |
|
| 140 | - * @since 9.0.0 |
|
| 141 | - */ |
|
| 142 | - public function getShareById($id, $recipient = null); |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Get the share by token possible with password |
|
| 146 | - * |
|
| 147 | - * @param string $token |
|
| 148 | - * @return IShare |
|
| 149 | - * @throws ShareNotFound |
|
| 150 | - * @since 9.0.0 |
|
| 151 | - */ |
|
| 152 | - public function getShareByToken($token); |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Verify the password of a public share |
|
| 156 | - * |
|
| 157 | - * @param IShare $share |
|
| 158 | - * @param string $password |
|
| 159 | - * @return bool |
|
| 160 | - * @since 9.0.0 |
|
| 161 | - */ |
|
| 162 | - public function checkPassword(IShare $share, $password); |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * The user with UID is deleted. |
|
| 166 | - * All share providers have to cleanup the shares with this user as well |
|
| 167 | - * as shares owned by this user. |
|
| 168 | - * Shares only initiated by this user are fine. |
|
| 169 | - * |
|
| 170 | - * @param string $uid |
|
| 171 | - * @since 9.1.0 |
|
| 172 | - */ |
|
| 173 | - public function userDeleted($uid); |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * The group with $gid is deleted |
|
| 177 | - * We need to clear up all shares to this group |
|
| 178 | - * |
|
| 179 | - * @param string $gid |
|
| 180 | - * @since 9.1.0 |
|
| 181 | - */ |
|
| 182 | - public function groupDeleted($gid); |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * The user $uid is deleted from the group $gid |
|
| 186 | - * All user specific group shares have to be removed |
|
| 187 | - * |
|
| 188 | - * @param string $uid |
|
| 189 | - * @param string $gid |
|
| 190 | - * @since 9.1.0 |
|
| 191 | - */ |
|
| 192 | - public function userDeletedFromGroup($uid, $gid); |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Get access list to a path. This means |
|
| 196 | - * all the users that can access a given path. |
|
| 197 | - * |
|
| 198 | - * Consider: |
|
| 199 | - * -root |
|
| 200 | - * |-folder1 |
|
| 201 | - * |-folder2 |
|
| 202 | - * |-fileA |
|
| 203 | - * |
|
| 204 | - * fileA is shared with user1 |
|
| 205 | - * folder2 is shared with group2 (user4 is a member of group2) |
|
| 206 | - * folder1 is shared with user2 |
|
| 207 | - * |
|
| 208 | - * Then the access list will to '/folder1/folder2/fileA' is: |
|
| 209 | - * [ |
|
| 210 | - * users => ['user1' => ['node_id' => 42, 'node_path' => '/path'], 'user2' => [...]], |
|
| 211 | - * remote => ['user1' => ['node_id' => 42, 'node_path' => '/path'], 'user2' => [...]], |
|
| 212 | - * public => bool |
|
| 213 | - * mail => bool |
|
| 214 | - * ] |
|
| 215 | - * |
|
| 216 | - * This is required for encryption/activity |
|
| 217 | - * |
|
| 218 | - * @param \OCP\Files\Node $path |
|
| 219 | - * @param bool $recursive Should we check all parent folders as well |
|
| 220 | - * @param bool $currentAccess Should the user have currently access to the file |
|
| 221 | - * @return array |
|
| 222 | - * @since 12 |
|
| 223 | - */ |
|
| 224 | - public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false); |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Instantiates a new share object. This is to be passed to |
|
| 228 | - * createShare. |
|
| 229 | - * |
|
| 230 | - * @return IShare |
|
| 231 | - * @since 9.0.0 |
|
| 232 | - */ |
|
| 233 | - public function newShare(); |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * Is the share API enabled |
|
| 237 | - * |
|
| 238 | - * @return bool |
|
| 239 | - * @since 9.0.0 |
|
| 240 | - */ |
|
| 241 | - public function shareApiEnabled(); |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Is public link sharing enabled |
|
| 245 | - * |
|
| 246 | - * @return bool |
|
| 247 | - * @since 9.0.0 |
|
| 248 | - */ |
|
| 249 | - public function shareApiAllowLinks(); |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Is password on public link requires |
|
| 253 | - * |
|
| 254 | - * @return bool |
|
| 255 | - * @since 9.0.0 |
|
| 256 | - */ |
|
| 257 | - public function shareApiLinkEnforcePassword(); |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Is default expire date enabled |
|
| 261 | - * |
|
| 262 | - * @return bool |
|
| 263 | - * @since 9.0.0 |
|
| 264 | - */ |
|
| 265 | - public function shareApiLinkDefaultExpireDate(); |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * Is default expire date enforced |
|
| 269 | - *` |
|
| 270 | - * @return bool |
|
| 271 | - * @since 9.0.0 |
|
| 272 | - */ |
|
| 273 | - public function shareApiLinkDefaultExpireDateEnforced(); |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * Number of default expire days |
|
| 277 | - * |
|
| 278 | - * @return int |
|
| 279 | - * @since 9.0.0 |
|
| 280 | - */ |
|
| 281 | - public function shareApiLinkDefaultExpireDays(); |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * Allow public upload on link shares |
|
| 285 | - * |
|
| 286 | - * @return bool |
|
| 287 | - * @since 9.0.0 |
|
| 288 | - */ |
|
| 289 | - public function shareApiLinkAllowPublicUpload(); |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * check if user can only share with group members |
|
| 293 | - * @return bool |
|
| 294 | - * @since 9.0.0 |
|
| 295 | - */ |
|
| 296 | - public function shareWithGroupMembersOnly(); |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * Check if users can share with groups |
|
| 300 | - * @return bool |
|
| 301 | - * @since 9.0.1 |
|
| 302 | - */ |
|
| 303 | - public function allowGroupSharing(); |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Check if sharing is disabled for the given user |
|
| 307 | - * |
|
| 308 | - * @param string $userId |
|
| 309 | - * @return bool |
|
| 310 | - * @since 9.0.0 |
|
| 311 | - */ |
|
| 312 | - public function sharingDisabledForUser($userId); |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * Check if outgoing server2server shares are allowed |
|
| 316 | - * @return bool |
|
| 317 | - * @since 9.0.0 |
|
| 318 | - */ |
|
| 319 | - public function outgoingServer2ServerSharesAllowed(); |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Check if a given share provider exists |
|
| 323 | - * @param int $shareType |
|
| 324 | - * @return bool |
|
| 325 | - * @since 11.0.0 |
|
| 326 | - */ |
|
| 327 | - public function shareProviderExists($shareType); |
|
| 38 | + /** |
|
| 39 | + * Create a Share |
|
| 40 | + * |
|
| 41 | + * @param IShare $share |
|
| 42 | + * @return IShare The share object |
|
| 43 | + * @since 9.0.0 |
|
| 44 | + */ |
|
| 45 | + public function createShare(IShare $share); |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Update a share. |
|
| 49 | + * The target of the share can't be changed this way: use moveShare |
|
| 50 | + * The share can't be removed this way (permission 0): use deleteShare |
|
| 51 | + * |
|
| 52 | + * @param IShare $share |
|
| 53 | + * @return IShare The share object |
|
| 54 | + * @since 9.0.0 |
|
| 55 | + */ |
|
| 56 | + public function updateShare(IShare $share); |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Delete a share |
|
| 60 | + * |
|
| 61 | + * @param IShare $share |
|
| 62 | + * @throws ShareNotFound |
|
| 63 | + * @since 9.0.0 |
|
| 64 | + */ |
|
| 65 | + public function deleteShare(IShare $share); |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Unshare a file as the recipient. |
|
| 69 | + * This can be different from a regular delete for example when one of |
|
| 70 | + * the users in a groups deletes that share. But the provider should |
|
| 71 | + * handle this. |
|
| 72 | + * |
|
| 73 | + * @param IShare $share |
|
| 74 | + * @param string $recipientId |
|
| 75 | + * @since 9.0.0 |
|
| 76 | + */ |
|
| 77 | + public function deleteFromSelf(IShare $share, $recipientId); |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Move the share as a recipient of the share. |
|
| 81 | + * This is updating the share target. So where the recipient has the share mounted. |
|
| 82 | + * |
|
| 83 | + * @param IShare $share |
|
| 84 | + * @param string $recipientId |
|
| 85 | + * @return IShare |
|
| 86 | + * @throws \InvalidArgumentException If $share is a link share or the $recipient does not match |
|
| 87 | + * @since 9.0.0 |
|
| 88 | + */ |
|
| 89 | + public function moveShare(IShare $share, $recipientId); |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Get all shares shared by (initiated) by the provided user in a folder. |
|
| 93 | + * |
|
| 94 | + * @param string $userId |
|
| 95 | + * @param Folder $node |
|
| 96 | + * @param bool $reshares |
|
| 97 | + * @return IShare[][] [$fileId => IShare[], ...] |
|
| 98 | + * @since 11.0.0 |
|
| 99 | + */ |
|
| 100 | + public function getSharesInFolder($userId, Folder $node, $reshares = false); |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Get shares shared by (initiated) by the provided user. |
|
| 104 | + * |
|
| 105 | + * @param string $userId |
|
| 106 | + * @param int $shareType |
|
| 107 | + * @param Node|null $path |
|
| 108 | + * @param bool $reshares |
|
| 109 | + * @param int $limit The maximum number of returned results, -1 for all results |
|
| 110 | + * @param int $offset |
|
| 111 | + * @return IShare[] |
|
| 112 | + * @since 9.0.0 |
|
| 113 | + */ |
|
| 114 | + public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0); |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Get shares shared with $user. |
|
| 118 | + * Filter by $node if provided |
|
| 119 | + * |
|
| 120 | + * @param string $userId |
|
| 121 | + * @param int $shareType |
|
| 122 | + * @param Node|null $node |
|
| 123 | + * @param int $limit The maximum number of shares returned, -1 for all |
|
| 124 | + * @param int $offset |
|
| 125 | + * @return IShare[] |
|
| 126 | + * @since 9.0.0 |
|
| 127 | + */ |
|
| 128 | + public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0); |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Retrieve a share by the share id. |
|
| 132 | + * If the recipient is set make sure to retrieve the file for that user. |
|
| 133 | + * This makes sure that if a user has moved/deleted a group share this |
|
| 134 | + * is reflected. |
|
| 135 | + * |
|
| 136 | + * @param string $id |
|
| 137 | + * @param string|null $recipient userID of the recipient |
|
| 138 | + * @return IShare |
|
| 139 | + * @throws ShareNotFound |
|
| 140 | + * @since 9.0.0 |
|
| 141 | + */ |
|
| 142 | + public function getShareById($id, $recipient = null); |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Get the share by token possible with password |
|
| 146 | + * |
|
| 147 | + * @param string $token |
|
| 148 | + * @return IShare |
|
| 149 | + * @throws ShareNotFound |
|
| 150 | + * @since 9.0.0 |
|
| 151 | + */ |
|
| 152 | + public function getShareByToken($token); |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Verify the password of a public share |
|
| 156 | + * |
|
| 157 | + * @param IShare $share |
|
| 158 | + * @param string $password |
|
| 159 | + * @return bool |
|
| 160 | + * @since 9.0.0 |
|
| 161 | + */ |
|
| 162 | + public function checkPassword(IShare $share, $password); |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * The user with UID is deleted. |
|
| 166 | + * All share providers have to cleanup the shares with this user as well |
|
| 167 | + * as shares owned by this user. |
|
| 168 | + * Shares only initiated by this user are fine. |
|
| 169 | + * |
|
| 170 | + * @param string $uid |
|
| 171 | + * @since 9.1.0 |
|
| 172 | + */ |
|
| 173 | + public function userDeleted($uid); |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * The group with $gid is deleted |
|
| 177 | + * We need to clear up all shares to this group |
|
| 178 | + * |
|
| 179 | + * @param string $gid |
|
| 180 | + * @since 9.1.0 |
|
| 181 | + */ |
|
| 182 | + public function groupDeleted($gid); |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * The user $uid is deleted from the group $gid |
|
| 186 | + * All user specific group shares have to be removed |
|
| 187 | + * |
|
| 188 | + * @param string $uid |
|
| 189 | + * @param string $gid |
|
| 190 | + * @since 9.1.0 |
|
| 191 | + */ |
|
| 192 | + public function userDeletedFromGroup($uid, $gid); |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Get access list to a path. This means |
|
| 196 | + * all the users that can access a given path. |
|
| 197 | + * |
|
| 198 | + * Consider: |
|
| 199 | + * -root |
|
| 200 | + * |-folder1 |
|
| 201 | + * |-folder2 |
|
| 202 | + * |-fileA |
|
| 203 | + * |
|
| 204 | + * fileA is shared with user1 |
|
| 205 | + * folder2 is shared with group2 (user4 is a member of group2) |
|
| 206 | + * folder1 is shared with user2 |
|
| 207 | + * |
|
| 208 | + * Then the access list will to '/folder1/folder2/fileA' is: |
|
| 209 | + * [ |
|
| 210 | + * users => ['user1' => ['node_id' => 42, 'node_path' => '/path'], 'user2' => [...]], |
|
| 211 | + * remote => ['user1' => ['node_id' => 42, 'node_path' => '/path'], 'user2' => [...]], |
|
| 212 | + * public => bool |
|
| 213 | + * mail => bool |
|
| 214 | + * ] |
|
| 215 | + * |
|
| 216 | + * This is required for encryption/activity |
|
| 217 | + * |
|
| 218 | + * @param \OCP\Files\Node $path |
|
| 219 | + * @param bool $recursive Should we check all parent folders as well |
|
| 220 | + * @param bool $currentAccess Should the user have currently access to the file |
|
| 221 | + * @return array |
|
| 222 | + * @since 12 |
|
| 223 | + */ |
|
| 224 | + public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false); |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Instantiates a new share object. This is to be passed to |
|
| 228 | + * createShare. |
|
| 229 | + * |
|
| 230 | + * @return IShare |
|
| 231 | + * @since 9.0.0 |
|
| 232 | + */ |
|
| 233 | + public function newShare(); |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * Is the share API enabled |
|
| 237 | + * |
|
| 238 | + * @return bool |
|
| 239 | + * @since 9.0.0 |
|
| 240 | + */ |
|
| 241 | + public function shareApiEnabled(); |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Is public link sharing enabled |
|
| 245 | + * |
|
| 246 | + * @return bool |
|
| 247 | + * @since 9.0.0 |
|
| 248 | + */ |
|
| 249 | + public function shareApiAllowLinks(); |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Is password on public link requires |
|
| 253 | + * |
|
| 254 | + * @return bool |
|
| 255 | + * @since 9.0.0 |
|
| 256 | + */ |
|
| 257 | + public function shareApiLinkEnforcePassword(); |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Is default expire date enabled |
|
| 261 | + * |
|
| 262 | + * @return bool |
|
| 263 | + * @since 9.0.0 |
|
| 264 | + */ |
|
| 265 | + public function shareApiLinkDefaultExpireDate(); |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * Is default expire date enforced |
|
| 269 | + *` |
|
| 270 | + * @return bool |
|
| 271 | + * @since 9.0.0 |
|
| 272 | + */ |
|
| 273 | + public function shareApiLinkDefaultExpireDateEnforced(); |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * Number of default expire days |
|
| 277 | + * |
|
| 278 | + * @return int |
|
| 279 | + * @since 9.0.0 |
|
| 280 | + */ |
|
| 281 | + public function shareApiLinkDefaultExpireDays(); |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Allow public upload on link shares |
|
| 285 | + * |
|
| 286 | + * @return bool |
|
| 287 | + * @since 9.0.0 |
|
| 288 | + */ |
|
| 289 | + public function shareApiLinkAllowPublicUpload(); |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * check if user can only share with group members |
|
| 293 | + * @return bool |
|
| 294 | + * @since 9.0.0 |
|
| 295 | + */ |
|
| 296 | + public function shareWithGroupMembersOnly(); |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * Check if users can share with groups |
|
| 300 | + * @return bool |
|
| 301 | + * @since 9.0.1 |
|
| 302 | + */ |
|
| 303 | + public function allowGroupSharing(); |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Check if sharing is disabled for the given user |
|
| 307 | + * |
|
| 308 | + * @param string $userId |
|
| 309 | + * @return bool |
|
| 310 | + * @since 9.0.0 |
|
| 311 | + */ |
|
| 312 | + public function sharingDisabledForUser($userId); |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * Check if outgoing server2server shares are allowed |
|
| 316 | + * @return bool |
|
| 317 | + * @since 9.0.0 |
|
| 318 | + */ |
|
| 319 | + public function outgoingServer2ServerSharesAllowed(); |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Check if a given share provider exists |
|
| 323 | + * @param int $shareType |
|
| 324 | + * @return bool |
|
| 325 | + * @since 11.0.0 |
|
| 326 | + */ |
|
| 327 | + public function shareProviderExists($shareType); |
|
| 328 | 328 | |
| 329 | 329 | } |
@@ -31,95 +31,95 @@ |
||
| 31 | 31 | |
| 32 | 32 | class File implements \OCP\Encryption\IFile { |
| 33 | 33 | |
| 34 | - /** @var Util */ |
|
| 35 | - protected $util; |
|
| 36 | - |
|
| 37 | - /** @var IRootFolder */ |
|
| 38 | - private $rootFolder; |
|
| 39 | - |
|
| 40 | - /** @var IManager */ |
|
| 41 | - private $shareManager; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * cache results of already checked folders |
|
| 45 | - * |
|
| 46 | - * @var array |
|
| 47 | - */ |
|
| 48 | - protected $cache; |
|
| 49 | - |
|
| 50 | - public function __construct(Util $util, |
|
| 51 | - IRootFolder $rootFolder, |
|
| 52 | - IManager $shareManager) { |
|
| 53 | - $this->util = $util; |
|
| 54 | - $this->cache = new CappedMemoryCache(); |
|
| 55 | - $this->rootFolder = $rootFolder; |
|
| 56 | - $this->shareManager = $shareManager; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * get list of users with access to the file |
|
| 62 | - * |
|
| 63 | - * @param string $path to the file |
|
| 64 | - * @return array ['users' => $uniqueUserIds, 'public' => $public] |
|
| 65 | - */ |
|
| 66 | - public function getAccessList($path) { |
|
| 67 | - |
|
| 68 | - // Make sure that a share key is generated for the owner too |
|
| 69 | - list($owner, $ownerPath) = $this->util->getUidAndFilename($path); |
|
| 70 | - |
|
| 71 | - // always add owner to the list of users with access to the file |
|
| 72 | - $userIds = array($owner); |
|
| 73 | - |
|
| 74 | - if (!$this->util->isFile($owner . '/' . $ownerPath)) { |
|
| 75 | - return array('users' => $userIds, 'public' => false); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - $ownerPath = substr($ownerPath, strlen('/files')); |
|
| 79 | - $userFolder = $this->rootFolder->getUserFolder($owner); |
|
| 80 | - try { |
|
| 81 | - $file = $userFolder->get($ownerPath); |
|
| 82 | - } catch (NotFoundException $e) { |
|
| 83 | - $file = null; |
|
| 84 | - } |
|
| 85 | - $ownerPath = $this->util->stripPartialFileExtension($ownerPath); |
|
| 86 | - |
|
| 87 | - // first get the shares for the parent and cache the result so that we don't |
|
| 88 | - // need to check all parents for every file |
|
| 89 | - $parent = dirname($ownerPath); |
|
| 90 | - $parentNode = $userFolder->get($parent); |
|
| 91 | - if (isset($this->cache[$parent])) { |
|
| 92 | - $resultForParents = $this->cache[$parent]; |
|
| 93 | - } else { |
|
| 94 | - $resultForParents = $this->shareManager->getAccessList($parentNode); |
|
| 95 | - $this->cache[$parent] = $resultForParents; |
|
| 96 | - } |
|
| 97 | - $userIds = \array_merge($userIds, $resultForParents['users']); |
|
| 98 | - $public = $resultForParents['public'] || !empty($resultForParents['remote']); |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - // Find out who, if anyone, is sharing the file |
|
| 102 | - if ($file !== null) { |
|
| 103 | - $resultForFile = $this->shareManager->getAccessList($file, false); |
|
| 104 | - $userIds = array_merge($userIds, $resultForFile['users']); |
|
| 105 | - $public = $resultForFile['public'] || !empty($resultForFile['remote']) || $public; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - // check if it is a group mount |
|
| 109 | - if (\OCP\App::isEnabled("files_external")) { |
|
| 110 | - $mounts = \OC_Mount_Config::getSystemMountPoints(); |
|
| 111 | - foreach ($mounts as $mount) { |
|
| 112 | - if ($mount['mountpoint'] == substr($ownerPath, 1, strlen($mount['mountpoint']))) { |
|
| 113 | - $mountedFor = $this->util->getUserWithAccessToMountPoint($mount['applicable']['users'], $mount['applicable']['groups']); |
|
| 114 | - $userIds = array_merge($userIds, $mountedFor); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - // Remove duplicate UIDs |
|
| 120 | - $uniqueUserIds = array_unique($userIds); |
|
| 121 | - |
|
| 122 | - return array('users' => $uniqueUserIds, 'public' => $public); |
|
| 123 | - } |
|
| 34 | + /** @var Util */ |
|
| 35 | + protected $util; |
|
| 36 | + |
|
| 37 | + /** @var IRootFolder */ |
|
| 38 | + private $rootFolder; |
|
| 39 | + |
|
| 40 | + /** @var IManager */ |
|
| 41 | + private $shareManager; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * cache results of already checked folders |
|
| 45 | + * |
|
| 46 | + * @var array |
|
| 47 | + */ |
|
| 48 | + protected $cache; |
|
| 49 | + |
|
| 50 | + public function __construct(Util $util, |
|
| 51 | + IRootFolder $rootFolder, |
|
| 52 | + IManager $shareManager) { |
|
| 53 | + $this->util = $util; |
|
| 54 | + $this->cache = new CappedMemoryCache(); |
|
| 55 | + $this->rootFolder = $rootFolder; |
|
| 56 | + $this->shareManager = $shareManager; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * get list of users with access to the file |
|
| 62 | + * |
|
| 63 | + * @param string $path to the file |
|
| 64 | + * @return array ['users' => $uniqueUserIds, 'public' => $public] |
|
| 65 | + */ |
|
| 66 | + public function getAccessList($path) { |
|
| 67 | + |
|
| 68 | + // Make sure that a share key is generated for the owner too |
|
| 69 | + list($owner, $ownerPath) = $this->util->getUidAndFilename($path); |
|
| 70 | + |
|
| 71 | + // always add owner to the list of users with access to the file |
|
| 72 | + $userIds = array($owner); |
|
| 73 | + |
|
| 74 | + if (!$this->util->isFile($owner . '/' . $ownerPath)) { |
|
| 75 | + return array('users' => $userIds, 'public' => false); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + $ownerPath = substr($ownerPath, strlen('/files')); |
|
| 79 | + $userFolder = $this->rootFolder->getUserFolder($owner); |
|
| 80 | + try { |
|
| 81 | + $file = $userFolder->get($ownerPath); |
|
| 82 | + } catch (NotFoundException $e) { |
|
| 83 | + $file = null; |
|
| 84 | + } |
|
| 85 | + $ownerPath = $this->util->stripPartialFileExtension($ownerPath); |
|
| 86 | + |
|
| 87 | + // first get the shares for the parent and cache the result so that we don't |
|
| 88 | + // need to check all parents for every file |
|
| 89 | + $parent = dirname($ownerPath); |
|
| 90 | + $parentNode = $userFolder->get($parent); |
|
| 91 | + if (isset($this->cache[$parent])) { |
|
| 92 | + $resultForParents = $this->cache[$parent]; |
|
| 93 | + } else { |
|
| 94 | + $resultForParents = $this->shareManager->getAccessList($parentNode); |
|
| 95 | + $this->cache[$parent] = $resultForParents; |
|
| 96 | + } |
|
| 97 | + $userIds = \array_merge($userIds, $resultForParents['users']); |
|
| 98 | + $public = $resultForParents['public'] || !empty($resultForParents['remote']); |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + // Find out who, if anyone, is sharing the file |
|
| 102 | + if ($file !== null) { |
|
| 103 | + $resultForFile = $this->shareManager->getAccessList($file, false); |
|
| 104 | + $userIds = array_merge($userIds, $resultForFile['users']); |
|
| 105 | + $public = $resultForFile['public'] || !empty($resultForFile['remote']) || $public; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + // check if it is a group mount |
|
| 109 | + if (\OCP\App::isEnabled("files_external")) { |
|
| 110 | + $mounts = \OC_Mount_Config::getSystemMountPoints(); |
|
| 111 | + foreach ($mounts as $mount) { |
|
| 112 | + if ($mount['mountpoint'] == substr($ownerPath, 1, strlen($mount['mountpoint']))) { |
|
| 113 | + $mountedFor = $this->util->getUserWithAccessToMountPoint($mount['applicable']['users'], $mount['applicable']['groups']); |
|
| 114 | + $userIds = array_merge($userIds, $mountedFor); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + // Remove duplicate UIDs |
|
| 120 | + $uniqueUserIds = array_unique($userIds); |
|
| 121 | + |
|
| 122 | + return array('users' => $uniqueUserIds, 'public' => $public); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | 125 | } |
@@ -58,1326 +58,1326 @@ |
||
| 58 | 58 | */ |
| 59 | 59 | class Manager implements IManager { |
| 60 | 60 | |
| 61 | - /** @var IProviderFactory */ |
|
| 62 | - private $factory; |
|
| 63 | - /** @var ILogger */ |
|
| 64 | - private $logger; |
|
| 65 | - /** @var IConfig */ |
|
| 66 | - private $config; |
|
| 67 | - /** @var ISecureRandom */ |
|
| 68 | - private $secureRandom; |
|
| 69 | - /** @var IHasher */ |
|
| 70 | - private $hasher; |
|
| 71 | - /** @var IMountManager */ |
|
| 72 | - private $mountManager; |
|
| 73 | - /** @var IGroupManager */ |
|
| 74 | - private $groupManager; |
|
| 75 | - /** @var IL10N */ |
|
| 76 | - private $l; |
|
| 77 | - /** @var IUserManager */ |
|
| 78 | - private $userManager; |
|
| 79 | - /** @var IRootFolder */ |
|
| 80 | - private $rootFolder; |
|
| 81 | - /** @var CappedMemoryCache */ |
|
| 82 | - private $sharingDisabledForUsersCache; |
|
| 83 | - /** @var EventDispatcher */ |
|
| 84 | - private $eventDispatcher; |
|
| 85 | - /** @var LegacyHooks */ |
|
| 86 | - private $legacyHooks; |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Manager constructor. |
|
| 91 | - * |
|
| 92 | - * @param ILogger $logger |
|
| 93 | - * @param IConfig $config |
|
| 94 | - * @param ISecureRandom $secureRandom |
|
| 95 | - * @param IHasher $hasher |
|
| 96 | - * @param IMountManager $mountManager |
|
| 97 | - * @param IGroupManager $groupManager |
|
| 98 | - * @param IL10N $l |
|
| 99 | - * @param IProviderFactory $factory |
|
| 100 | - * @param IUserManager $userManager |
|
| 101 | - * @param IRootFolder $rootFolder |
|
| 102 | - * @param EventDispatcher $eventDispatcher |
|
| 103 | - */ |
|
| 104 | - public function __construct( |
|
| 105 | - ILogger $logger, |
|
| 106 | - IConfig $config, |
|
| 107 | - ISecureRandom $secureRandom, |
|
| 108 | - IHasher $hasher, |
|
| 109 | - IMountManager $mountManager, |
|
| 110 | - IGroupManager $groupManager, |
|
| 111 | - IL10N $l, |
|
| 112 | - IProviderFactory $factory, |
|
| 113 | - IUserManager $userManager, |
|
| 114 | - IRootFolder $rootFolder, |
|
| 115 | - EventDispatcher $eventDispatcher |
|
| 116 | - ) { |
|
| 117 | - $this->logger = $logger; |
|
| 118 | - $this->config = $config; |
|
| 119 | - $this->secureRandom = $secureRandom; |
|
| 120 | - $this->hasher = $hasher; |
|
| 121 | - $this->mountManager = $mountManager; |
|
| 122 | - $this->groupManager = $groupManager; |
|
| 123 | - $this->l = $l; |
|
| 124 | - $this->factory = $factory; |
|
| 125 | - $this->userManager = $userManager; |
|
| 126 | - $this->rootFolder = $rootFolder; |
|
| 127 | - $this->eventDispatcher = $eventDispatcher; |
|
| 128 | - $this->sharingDisabledForUsersCache = new CappedMemoryCache(); |
|
| 129 | - $this->legacyHooks = new LegacyHooks($this->eventDispatcher); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Convert from a full share id to a tuple (providerId, shareId) |
|
| 134 | - * |
|
| 135 | - * @param string $id |
|
| 136 | - * @return string[] |
|
| 137 | - */ |
|
| 138 | - private function splitFullId($id) { |
|
| 139 | - return explode(':', $id, 2); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Verify if a password meets all requirements |
|
| 144 | - * |
|
| 145 | - * @param string $password |
|
| 146 | - * @throws \Exception |
|
| 147 | - */ |
|
| 148 | - protected function verifyPassword($password) { |
|
| 149 | - if ($password === null) { |
|
| 150 | - // No password is set, check if this is allowed. |
|
| 151 | - if ($this->shareApiLinkEnforcePassword()) { |
|
| 152 | - throw new \InvalidArgumentException('Passwords are enforced for link shares'); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - return; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - // Let others verify the password |
|
| 159 | - try { |
|
| 160 | - $event = new GenericEvent($password); |
|
| 161 | - $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event); |
|
| 162 | - } catch (HintException $e) { |
|
| 163 | - throw new \Exception($e->getHint()); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Check for generic requirements before creating a share |
|
| 169 | - * |
|
| 170 | - * @param \OCP\Share\IShare $share |
|
| 171 | - * @throws \InvalidArgumentException |
|
| 172 | - * @throws GenericShareException |
|
| 173 | - */ |
|
| 174 | - protected function generalCreateChecks(\OCP\Share\IShare $share) { |
|
| 175 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 176 | - // We expect a valid user as sharedWith for user shares |
|
| 177 | - if (!$this->userManager->userExists($share->getSharedWith())) { |
|
| 178 | - throw new \InvalidArgumentException('SharedWith is not a valid user'); |
|
| 179 | - } |
|
| 180 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 181 | - // We expect a valid group as sharedWith for group shares |
|
| 182 | - if (!$this->groupManager->groupExists($share->getSharedWith())) { |
|
| 183 | - throw new \InvalidArgumentException('SharedWith is not a valid group'); |
|
| 184 | - } |
|
| 185 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 186 | - if ($share->getSharedWith() !== null) { |
|
| 187 | - throw new \InvalidArgumentException('SharedWith should be empty'); |
|
| 188 | - } |
|
| 189 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 190 | - if ($share->getSharedWith() === null) { |
|
| 191 | - throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
| 192 | - } |
|
| 193 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 194 | - if ($share->getSharedWith() === null) { |
|
| 195 | - throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
| 196 | - } |
|
| 197 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 198 | - $circle = \OCA\Circles\Api\Circles::detailsCircle($share->getSharedWith()); |
|
| 199 | - if ($circle === null) { |
|
| 200 | - throw new \InvalidArgumentException('SharedWith is not a valid circle'); |
|
| 201 | - } |
|
| 202 | - } else { |
|
| 203 | - // We can't handle other types yet |
|
| 204 | - throw new \InvalidArgumentException('unknown share type'); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - // Verify the initiator of the share is set |
|
| 208 | - if ($share->getSharedBy() === null) { |
|
| 209 | - throw new \InvalidArgumentException('SharedBy should be set'); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - // Cannot share with yourself |
|
| 213 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
| 214 | - $share->getSharedWith() === $share->getSharedBy()) { |
|
| 215 | - throw new \InvalidArgumentException('Can\'t share with yourself'); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - // The path should be set |
|
| 219 | - if ($share->getNode() === null) { |
|
| 220 | - throw new \InvalidArgumentException('Path should be set'); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - // And it should be a file or a folder |
|
| 224 | - if (!($share->getNode() instanceof \OCP\Files\File) && |
|
| 225 | - !($share->getNode() instanceof \OCP\Files\Folder)) { |
|
| 226 | - throw new \InvalidArgumentException('Path should be either a file or a folder'); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // And you can't share your rootfolder |
|
| 230 | - if ($this->userManager->userExists($share->getSharedBy())) { |
|
| 231 | - $sharedPath = $this->rootFolder->getUserFolder($share->getSharedBy())->getPath(); |
|
| 232 | - } else { |
|
| 233 | - $sharedPath = $this->rootFolder->getUserFolder($share->getShareOwner())->getPath(); |
|
| 234 | - } |
|
| 235 | - if ($sharedPath === $share->getNode()->getPath()) { |
|
| 236 | - throw new \InvalidArgumentException('You can\'t share your root folder'); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - // Check if we actually have share permissions |
|
| 240 | - if (!$share->getNode()->isShareable()) { |
|
| 241 | - $message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getPath()]); |
|
| 242 | - throw new GenericShareException($message_t, $message_t, 404); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - // Permissions should be set |
|
| 246 | - if ($share->getPermissions() === null) { |
|
| 247 | - throw new \InvalidArgumentException('A share requires permissions'); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /* |
|
| 61 | + /** @var IProviderFactory */ |
|
| 62 | + private $factory; |
|
| 63 | + /** @var ILogger */ |
|
| 64 | + private $logger; |
|
| 65 | + /** @var IConfig */ |
|
| 66 | + private $config; |
|
| 67 | + /** @var ISecureRandom */ |
|
| 68 | + private $secureRandom; |
|
| 69 | + /** @var IHasher */ |
|
| 70 | + private $hasher; |
|
| 71 | + /** @var IMountManager */ |
|
| 72 | + private $mountManager; |
|
| 73 | + /** @var IGroupManager */ |
|
| 74 | + private $groupManager; |
|
| 75 | + /** @var IL10N */ |
|
| 76 | + private $l; |
|
| 77 | + /** @var IUserManager */ |
|
| 78 | + private $userManager; |
|
| 79 | + /** @var IRootFolder */ |
|
| 80 | + private $rootFolder; |
|
| 81 | + /** @var CappedMemoryCache */ |
|
| 82 | + private $sharingDisabledForUsersCache; |
|
| 83 | + /** @var EventDispatcher */ |
|
| 84 | + private $eventDispatcher; |
|
| 85 | + /** @var LegacyHooks */ |
|
| 86 | + private $legacyHooks; |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Manager constructor. |
|
| 91 | + * |
|
| 92 | + * @param ILogger $logger |
|
| 93 | + * @param IConfig $config |
|
| 94 | + * @param ISecureRandom $secureRandom |
|
| 95 | + * @param IHasher $hasher |
|
| 96 | + * @param IMountManager $mountManager |
|
| 97 | + * @param IGroupManager $groupManager |
|
| 98 | + * @param IL10N $l |
|
| 99 | + * @param IProviderFactory $factory |
|
| 100 | + * @param IUserManager $userManager |
|
| 101 | + * @param IRootFolder $rootFolder |
|
| 102 | + * @param EventDispatcher $eventDispatcher |
|
| 103 | + */ |
|
| 104 | + public function __construct( |
|
| 105 | + ILogger $logger, |
|
| 106 | + IConfig $config, |
|
| 107 | + ISecureRandom $secureRandom, |
|
| 108 | + IHasher $hasher, |
|
| 109 | + IMountManager $mountManager, |
|
| 110 | + IGroupManager $groupManager, |
|
| 111 | + IL10N $l, |
|
| 112 | + IProviderFactory $factory, |
|
| 113 | + IUserManager $userManager, |
|
| 114 | + IRootFolder $rootFolder, |
|
| 115 | + EventDispatcher $eventDispatcher |
|
| 116 | + ) { |
|
| 117 | + $this->logger = $logger; |
|
| 118 | + $this->config = $config; |
|
| 119 | + $this->secureRandom = $secureRandom; |
|
| 120 | + $this->hasher = $hasher; |
|
| 121 | + $this->mountManager = $mountManager; |
|
| 122 | + $this->groupManager = $groupManager; |
|
| 123 | + $this->l = $l; |
|
| 124 | + $this->factory = $factory; |
|
| 125 | + $this->userManager = $userManager; |
|
| 126 | + $this->rootFolder = $rootFolder; |
|
| 127 | + $this->eventDispatcher = $eventDispatcher; |
|
| 128 | + $this->sharingDisabledForUsersCache = new CappedMemoryCache(); |
|
| 129 | + $this->legacyHooks = new LegacyHooks($this->eventDispatcher); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Convert from a full share id to a tuple (providerId, shareId) |
|
| 134 | + * |
|
| 135 | + * @param string $id |
|
| 136 | + * @return string[] |
|
| 137 | + */ |
|
| 138 | + private function splitFullId($id) { |
|
| 139 | + return explode(':', $id, 2); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Verify if a password meets all requirements |
|
| 144 | + * |
|
| 145 | + * @param string $password |
|
| 146 | + * @throws \Exception |
|
| 147 | + */ |
|
| 148 | + protected function verifyPassword($password) { |
|
| 149 | + if ($password === null) { |
|
| 150 | + // No password is set, check if this is allowed. |
|
| 151 | + if ($this->shareApiLinkEnforcePassword()) { |
|
| 152 | + throw new \InvalidArgumentException('Passwords are enforced for link shares'); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + return; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + // Let others verify the password |
|
| 159 | + try { |
|
| 160 | + $event = new GenericEvent($password); |
|
| 161 | + $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event); |
|
| 162 | + } catch (HintException $e) { |
|
| 163 | + throw new \Exception($e->getHint()); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Check for generic requirements before creating a share |
|
| 169 | + * |
|
| 170 | + * @param \OCP\Share\IShare $share |
|
| 171 | + * @throws \InvalidArgumentException |
|
| 172 | + * @throws GenericShareException |
|
| 173 | + */ |
|
| 174 | + protected function generalCreateChecks(\OCP\Share\IShare $share) { |
|
| 175 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 176 | + // We expect a valid user as sharedWith for user shares |
|
| 177 | + if (!$this->userManager->userExists($share->getSharedWith())) { |
|
| 178 | + throw new \InvalidArgumentException('SharedWith is not a valid user'); |
|
| 179 | + } |
|
| 180 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 181 | + // We expect a valid group as sharedWith for group shares |
|
| 182 | + if (!$this->groupManager->groupExists($share->getSharedWith())) { |
|
| 183 | + throw new \InvalidArgumentException('SharedWith is not a valid group'); |
|
| 184 | + } |
|
| 185 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 186 | + if ($share->getSharedWith() !== null) { |
|
| 187 | + throw new \InvalidArgumentException('SharedWith should be empty'); |
|
| 188 | + } |
|
| 189 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 190 | + if ($share->getSharedWith() === null) { |
|
| 191 | + throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
| 192 | + } |
|
| 193 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 194 | + if ($share->getSharedWith() === null) { |
|
| 195 | + throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
| 196 | + } |
|
| 197 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 198 | + $circle = \OCA\Circles\Api\Circles::detailsCircle($share->getSharedWith()); |
|
| 199 | + if ($circle === null) { |
|
| 200 | + throw new \InvalidArgumentException('SharedWith is not a valid circle'); |
|
| 201 | + } |
|
| 202 | + } else { |
|
| 203 | + // We can't handle other types yet |
|
| 204 | + throw new \InvalidArgumentException('unknown share type'); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + // Verify the initiator of the share is set |
|
| 208 | + if ($share->getSharedBy() === null) { |
|
| 209 | + throw new \InvalidArgumentException('SharedBy should be set'); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + // Cannot share with yourself |
|
| 213 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
| 214 | + $share->getSharedWith() === $share->getSharedBy()) { |
|
| 215 | + throw new \InvalidArgumentException('Can\'t share with yourself'); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + // The path should be set |
|
| 219 | + if ($share->getNode() === null) { |
|
| 220 | + throw new \InvalidArgumentException('Path should be set'); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + // And it should be a file or a folder |
|
| 224 | + if (!($share->getNode() instanceof \OCP\Files\File) && |
|
| 225 | + !($share->getNode() instanceof \OCP\Files\Folder)) { |
|
| 226 | + throw new \InvalidArgumentException('Path should be either a file or a folder'); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // And you can't share your rootfolder |
|
| 230 | + if ($this->userManager->userExists($share->getSharedBy())) { |
|
| 231 | + $sharedPath = $this->rootFolder->getUserFolder($share->getSharedBy())->getPath(); |
|
| 232 | + } else { |
|
| 233 | + $sharedPath = $this->rootFolder->getUserFolder($share->getShareOwner())->getPath(); |
|
| 234 | + } |
|
| 235 | + if ($sharedPath === $share->getNode()->getPath()) { |
|
| 236 | + throw new \InvalidArgumentException('You can\'t share your root folder'); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + // Check if we actually have share permissions |
|
| 240 | + if (!$share->getNode()->isShareable()) { |
|
| 241 | + $message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getPath()]); |
|
| 242 | + throw new GenericShareException($message_t, $message_t, 404); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + // Permissions should be set |
|
| 246 | + if ($share->getPermissions() === null) { |
|
| 247 | + throw new \InvalidArgumentException('A share requires permissions'); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /* |
|
| 251 | 251 | * Quick fix for #23536 |
| 252 | 252 | * Non moveable mount points do not have update and delete permissions |
| 253 | 253 | * while we 'most likely' do have that on the storage. |
| 254 | 254 | */ |
| 255 | - $permissions = $share->getNode()->getPermissions(); |
|
| 256 | - $mount = $share->getNode()->getMountPoint(); |
|
| 257 | - if (!($mount instanceof MoveableMount)) { |
|
| 258 | - $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - // Check that we do not share with more permissions than we have |
|
| 262 | - if ($share->getPermissions() & ~$permissions) { |
|
| 263 | - $message_t = $this->l->t('Cannot increase permissions of %s', [$share->getNode()->getPath()]); |
|
| 264 | - throw new GenericShareException($message_t, $message_t, 404); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - // Check that read permissions are always set |
|
| 269 | - // Link shares are allowed to have no read permissions to allow upload to hidden folders |
|
| 270 | - if ($share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK && |
|
| 271 | - ($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) { |
|
| 272 | - throw new \InvalidArgumentException('Shares need at least read permissions'); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - if ($share->getNode() instanceof \OCP\Files\File) { |
|
| 276 | - if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { |
|
| 277 | - $message_t = $this->l->t('Files can\'t be shared with delete permissions'); |
|
| 278 | - throw new GenericShareException($message_t); |
|
| 279 | - } |
|
| 280 | - if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { |
|
| 281 | - $message_t = $this->l->t('Files can\'t be shared with create permissions'); |
|
| 282 | - throw new GenericShareException($message_t); |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * Validate if the expiration date fits the system settings |
|
| 289 | - * |
|
| 290 | - * @param \OCP\Share\IShare $share The share to validate the expiration date of |
|
| 291 | - * @return \OCP\Share\IShare The modified share object |
|
| 292 | - * @throws GenericShareException |
|
| 293 | - * @throws \InvalidArgumentException |
|
| 294 | - * @throws \Exception |
|
| 295 | - */ |
|
| 296 | - protected function validateExpirationDate(\OCP\Share\IShare $share) { |
|
| 297 | - |
|
| 298 | - $expirationDate = $share->getExpirationDate(); |
|
| 299 | - |
|
| 300 | - if ($expirationDate !== null) { |
|
| 301 | - //Make sure the expiration date is a date |
|
| 302 | - $expirationDate->setTime(0, 0, 0); |
|
| 303 | - |
|
| 304 | - $date = new \DateTime(); |
|
| 305 | - $date->setTime(0, 0, 0); |
|
| 306 | - if ($date >= $expirationDate) { |
|
| 307 | - $message = $this->l->t('Expiration date is in the past'); |
|
| 308 | - throw new GenericShareException($message, $message, 404); |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - // If expiredate is empty set a default one if there is a default |
|
| 313 | - $fullId = null; |
|
| 314 | - try { |
|
| 315 | - $fullId = $share->getFullId(); |
|
| 316 | - } catch (\UnexpectedValueException $e) { |
|
| 317 | - // This is a new share |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) { |
|
| 321 | - $expirationDate = new \DateTime(); |
|
| 322 | - $expirationDate->setTime(0,0,0); |
|
| 323 | - $expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - // If we enforce the expiration date check that is does not exceed |
|
| 327 | - if ($this->shareApiLinkDefaultExpireDateEnforced()) { |
|
| 328 | - if ($expirationDate === null) { |
|
| 329 | - throw new \InvalidArgumentException('Expiration date is enforced'); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - $date = new \DateTime(); |
|
| 333 | - $date->setTime(0, 0, 0); |
|
| 334 | - $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); |
|
| 335 | - if ($date < $expirationDate) { |
|
| 336 | - $message = $this->l->t('Cannot set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]); |
|
| 337 | - throw new GenericShareException($message, $message, 404); |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - $accepted = true; |
|
| 342 | - $message = ''; |
|
| 343 | - \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [ |
|
| 344 | - 'expirationDate' => &$expirationDate, |
|
| 345 | - 'accepted' => &$accepted, |
|
| 346 | - 'message' => &$message, |
|
| 347 | - 'passwordSet' => $share->getPassword() !== null, |
|
| 348 | - ]); |
|
| 349 | - |
|
| 350 | - if (!$accepted) { |
|
| 351 | - throw new \Exception($message); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - $share->setExpirationDate($expirationDate); |
|
| 355 | - |
|
| 356 | - return $share; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * Check for pre share requirements for user shares |
|
| 361 | - * |
|
| 362 | - * @param \OCP\Share\IShare $share |
|
| 363 | - * @throws \Exception |
|
| 364 | - */ |
|
| 365 | - protected function userCreateChecks(\OCP\Share\IShare $share) { |
|
| 366 | - // Check if we can share with group members only |
|
| 367 | - if ($this->shareWithGroupMembersOnly()) { |
|
| 368 | - $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
| 369 | - $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
| 370 | - // Verify we can share with this user |
|
| 371 | - $groups = array_intersect( |
|
| 372 | - $this->groupManager->getUserGroupIds($sharedBy), |
|
| 373 | - $this->groupManager->getUserGroupIds($sharedWith) |
|
| 374 | - ); |
|
| 375 | - if (empty($groups)) { |
|
| 376 | - throw new \Exception('Only sharing with group members is allowed'); |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /* |
|
| 255 | + $permissions = $share->getNode()->getPermissions(); |
|
| 256 | + $mount = $share->getNode()->getMountPoint(); |
|
| 257 | + if (!($mount instanceof MoveableMount)) { |
|
| 258 | + $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + // Check that we do not share with more permissions than we have |
|
| 262 | + if ($share->getPermissions() & ~$permissions) { |
|
| 263 | + $message_t = $this->l->t('Cannot increase permissions of %s', [$share->getNode()->getPath()]); |
|
| 264 | + throw new GenericShareException($message_t, $message_t, 404); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + // Check that read permissions are always set |
|
| 269 | + // Link shares are allowed to have no read permissions to allow upload to hidden folders |
|
| 270 | + if ($share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK && |
|
| 271 | + ($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) { |
|
| 272 | + throw new \InvalidArgumentException('Shares need at least read permissions'); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + if ($share->getNode() instanceof \OCP\Files\File) { |
|
| 276 | + if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { |
|
| 277 | + $message_t = $this->l->t('Files can\'t be shared with delete permissions'); |
|
| 278 | + throw new GenericShareException($message_t); |
|
| 279 | + } |
|
| 280 | + if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { |
|
| 281 | + $message_t = $this->l->t('Files can\'t be shared with create permissions'); |
|
| 282 | + throw new GenericShareException($message_t); |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * Validate if the expiration date fits the system settings |
|
| 289 | + * |
|
| 290 | + * @param \OCP\Share\IShare $share The share to validate the expiration date of |
|
| 291 | + * @return \OCP\Share\IShare The modified share object |
|
| 292 | + * @throws GenericShareException |
|
| 293 | + * @throws \InvalidArgumentException |
|
| 294 | + * @throws \Exception |
|
| 295 | + */ |
|
| 296 | + protected function validateExpirationDate(\OCP\Share\IShare $share) { |
|
| 297 | + |
|
| 298 | + $expirationDate = $share->getExpirationDate(); |
|
| 299 | + |
|
| 300 | + if ($expirationDate !== null) { |
|
| 301 | + //Make sure the expiration date is a date |
|
| 302 | + $expirationDate->setTime(0, 0, 0); |
|
| 303 | + |
|
| 304 | + $date = new \DateTime(); |
|
| 305 | + $date->setTime(0, 0, 0); |
|
| 306 | + if ($date >= $expirationDate) { |
|
| 307 | + $message = $this->l->t('Expiration date is in the past'); |
|
| 308 | + throw new GenericShareException($message, $message, 404); |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + // If expiredate is empty set a default one if there is a default |
|
| 313 | + $fullId = null; |
|
| 314 | + try { |
|
| 315 | + $fullId = $share->getFullId(); |
|
| 316 | + } catch (\UnexpectedValueException $e) { |
|
| 317 | + // This is a new share |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) { |
|
| 321 | + $expirationDate = new \DateTime(); |
|
| 322 | + $expirationDate->setTime(0,0,0); |
|
| 323 | + $expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + // If we enforce the expiration date check that is does not exceed |
|
| 327 | + if ($this->shareApiLinkDefaultExpireDateEnforced()) { |
|
| 328 | + if ($expirationDate === null) { |
|
| 329 | + throw new \InvalidArgumentException('Expiration date is enforced'); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + $date = new \DateTime(); |
|
| 333 | + $date->setTime(0, 0, 0); |
|
| 334 | + $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); |
|
| 335 | + if ($date < $expirationDate) { |
|
| 336 | + $message = $this->l->t('Cannot set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]); |
|
| 337 | + throw new GenericShareException($message, $message, 404); |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + $accepted = true; |
|
| 342 | + $message = ''; |
|
| 343 | + \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [ |
|
| 344 | + 'expirationDate' => &$expirationDate, |
|
| 345 | + 'accepted' => &$accepted, |
|
| 346 | + 'message' => &$message, |
|
| 347 | + 'passwordSet' => $share->getPassword() !== null, |
|
| 348 | + ]); |
|
| 349 | + |
|
| 350 | + if (!$accepted) { |
|
| 351 | + throw new \Exception($message); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + $share->setExpirationDate($expirationDate); |
|
| 355 | + |
|
| 356 | + return $share; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * Check for pre share requirements for user shares |
|
| 361 | + * |
|
| 362 | + * @param \OCP\Share\IShare $share |
|
| 363 | + * @throws \Exception |
|
| 364 | + */ |
|
| 365 | + protected function userCreateChecks(\OCP\Share\IShare $share) { |
|
| 366 | + // Check if we can share with group members only |
|
| 367 | + if ($this->shareWithGroupMembersOnly()) { |
|
| 368 | + $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
| 369 | + $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
| 370 | + // Verify we can share with this user |
|
| 371 | + $groups = array_intersect( |
|
| 372 | + $this->groupManager->getUserGroupIds($sharedBy), |
|
| 373 | + $this->groupManager->getUserGroupIds($sharedWith) |
|
| 374 | + ); |
|
| 375 | + if (empty($groups)) { |
|
| 376 | + throw new \Exception('Only sharing with group members is allowed'); |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + /* |
|
| 381 | 381 | * TODO: Could be costly, fix |
| 382 | 382 | * |
| 383 | 383 | * Also this is not what we want in the future.. then we want to squash identical shares. |
| 384 | 384 | */ |
| 385 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_USER); |
|
| 386 | - $existingShares = $provider->getSharesByPath($share->getNode()); |
|
| 387 | - foreach($existingShares as $existingShare) { |
|
| 388 | - // Ignore if it is the same share |
|
| 389 | - try { |
|
| 390 | - if ($existingShare->getFullId() === $share->getFullId()) { |
|
| 391 | - continue; |
|
| 392 | - } |
|
| 393 | - } catch (\UnexpectedValueException $e) { |
|
| 394 | - //Shares are not identical |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - // Identical share already existst |
|
| 398 | - if ($existingShare->getSharedWith() === $share->getSharedWith()) { |
|
| 399 | - throw new \Exception('Path already shared with this user'); |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - // The share is already shared with this user via a group share |
|
| 403 | - if ($existingShare->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 404 | - $group = $this->groupManager->get($existingShare->getSharedWith()); |
|
| 405 | - if (!is_null($group)) { |
|
| 406 | - $user = $this->userManager->get($share->getSharedWith()); |
|
| 407 | - |
|
| 408 | - if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) { |
|
| 409 | - throw new \Exception('Path already shared with this user'); |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * Check for pre share requirements for group shares |
|
| 418 | - * |
|
| 419 | - * @param \OCP\Share\IShare $share |
|
| 420 | - * @throws \Exception |
|
| 421 | - */ |
|
| 422 | - protected function groupCreateChecks(\OCP\Share\IShare $share) { |
|
| 423 | - // Verify group shares are allowed |
|
| 424 | - if (!$this->allowGroupSharing()) { |
|
| 425 | - throw new \Exception('Group sharing is now allowed'); |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - // Verify if the user can share with this group |
|
| 429 | - if ($this->shareWithGroupMembersOnly()) { |
|
| 430 | - $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
| 431 | - $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
| 432 | - if (is_null($sharedWith) || !$sharedWith->inGroup($sharedBy)) { |
|
| 433 | - throw new \Exception('Only sharing within your own groups is allowed'); |
|
| 434 | - } |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - /* |
|
| 385 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_USER); |
|
| 386 | + $existingShares = $provider->getSharesByPath($share->getNode()); |
|
| 387 | + foreach($existingShares as $existingShare) { |
|
| 388 | + // Ignore if it is the same share |
|
| 389 | + try { |
|
| 390 | + if ($existingShare->getFullId() === $share->getFullId()) { |
|
| 391 | + continue; |
|
| 392 | + } |
|
| 393 | + } catch (\UnexpectedValueException $e) { |
|
| 394 | + //Shares are not identical |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + // Identical share already existst |
|
| 398 | + if ($existingShare->getSharedWith() === $share->getSharedWith()) { |
|
| 399 | + throw new \Exception('Path already shared with this user'); |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + // The share is already shared with this user via a group share |
|
| 403 | + if ($existingShare->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 404 | + $group = $this->groupManager->get($existingShare->getSharedWith()); |
|
| 405 | + if (!is_null($group)) { |
|
| 406 | + $user = $this->userManager->get($share->getSharedWith()); |
|
| 407 | + |
|
| 408 | + if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) { |
|
| 409 | + throw new \Exception('Path already shared with this user'); |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * Check for pre share requirements for group shares |
|
| 418 | + * |
|
| 419 | + * @param \OCP\Share\IShare $share |
|
| 420 | + * @throws \Exception |
|
| 421 | + */ |
|
| 422 | + protected function groupCreateChecks(\OCP\Share\IShare $share) { |
|
| 423 | + // Verify group shares are allowed |
|
| 424 | + if (!$this->allowGroupSharing()) { |
|
| 425 | + throw new \Exception('Group sharing is now allowed'); |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + // Verify if the user can share with this group |
|
| 429 | + if ($this->shareWithGroupMembersOnly()) { |
|
| 430 | + $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
| 431 | + $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
| 432 | + if (is_null($sharedWith) || !$sharedWith->inGroup($sharedBy)) { |
|
| 433 | + throw new \Exception('Only sharing within your own groups is allowed'); |
|
| 434 | + } |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + /* |
|
| 438 | 438 | * TODO: Could be costly, fix |
| 439 | 439 | * |
| 440 | 440 | * Also this is not what we want in the future.. then we want to squash identical shares. |
| 441 | 441 | */ |
| 442 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
| 443 | - $existingShares = $provider->getSharesByPath($share->getNode()); |
|
| 444 | - foreach($existingShares as $existingShare) { |
|
| 445 | - try { |
|
| 446 | - if ($existingShare->getFullId() === $share->getFullId()) { |
|
| 447 | - continue; |
|
| 448 | - } |
|
| 449 | - } catch (\UnexpectedValueException $e) { |
|
| 450 | - //It is a new share so just continue |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - if ($existingShare->getSharedWith() === $share->getSharedWith()) { |
|
| 454 | - throw new \Exception('Path already shared with this group'); |
|
| 455 | - } |
|
| 456 | - } |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * Check for pre share requirements for link shares |
|
| 461 | - * |
|
| 462 | - * @param \OCP\Share\IShare $share |
|
| 463 | - * @throws \Exception |
|
| 464 | - */ |
|
| 465 | - protected function linkCreateChecks(\OCP\Share\IShare $share) { |
|
| 466 | - // Are link shares allowed? |
|
| 467 | - if (!$this->shareApiAllowLinks()) { |
|
| 468 | - throw new \Exception('Link sharing not allowed'); |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - // Link shares by definition can't have share permissions |
|
| 472 | - if ($share->getPermissions() & \OCP\Constants::PERMISSION_SHARE) { |
|
| 473 | - throw new \InvalidArgumentException('Link shares can\'t have reshare permissions'); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - // Check if public upload is allowed |
|
| 477 | - if (!$this->shareApiLinkAllowPublicUpload() && |
|
| 478 | - ($share->getPermissions() & (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE))) { |
|
| 479 | - throw new \InvalidArgumentException('Public upload not allowed'); |
|
| 480 | - } |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * To make sure we don't get invisible link shares we set the parent |
|
| 485 | - * of a link if it is a reshare. This is a quick word around |
|
| 486 | - * until we can properly display multiple link shares in the UI |
|
| 487 | - * |
|
| 488 | - * See: https://github.com/owncloud/core/issues/22295 |
|
| 489 | - * |
|
| 490 | - * FIXME: Remove once multiple link shares can be properly displayed |
|
| 491 | - * |
|
| 492 | - * @param \OCP\Share\IShare $share |
|
| 493 | - */ |
|
| 494 | - protected function setLinkParent(\OCP\Share\IShare $share) { |
|
| 495 | - |
|
| 496 | - // No sense in checking if the method is not there. |
|
| 497 | - if (method_exists($share, 'setParent')) { |
|
| 498 | - $storage = $share->getNode()->getStorage(); |
|
| 499 | - if ($storage->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
| 500 | - /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
| 501 | - $share->setParent($storage->getShareId()); |
|
| 502 | - } |
|
| 503 | - }; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * @param File|Folder $path |
|
| 508 | - */ |
|
| 509 | - protected function pathCreateChecks($path) { |
|
| 510 | - // Make sure that we do not share a path that contains a shared mountpoint |
|
| 511 | - if ($path instanceof \OCP\Files\Folder) { |
|
| 512 | - $mounts = $this->mountManager->findIn($path->getPath()); |
|
| 513 | - foreach($mounts as $mount) { |
|
| 514 | - if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
| 515 | - throw new \InvalidArgumentException('Path contains files shared with you'); |
|
| 516 | - } |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * Check if the user that is sharing can actually share |
|
| 523 | - * |
|
| 524 | - * @param \OCP\Share\IShare $share |
|
| 525 | - * @throws \Exception |
|
| 526 | - */ |
|
| 527 | - protected function canShare(\OCP\Share\IShare $share) { |
|
| 528 | - if (!$this->shareApiEnabled()) { |
|
| 529 | - throw new \Exception('The share API is disabled'); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - if ($this->sharingDisabledForUser($share->getSharedBy())) { |
|
| 533 | - throw new \Exception('You are not allowed to share'); |
|
| 534 | - } |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - /** |
|
| 538 | - * Share a path |
|
| 539 | - * |
|
| 540 | - * @param \OCP\Share\IShare $share |
|
| 541 | - * @return Share The share object |
|
| 542 | - * @throws \Exception |
|
| 543 | - * |
|
| 544 | - * TODO: handle link share permissions or check them |
|
| 545 | - */ |
|
| 546 | - public function createShare(\OCP\Share\IShare $share) { |
|
| 547 | - $this->canShare($share); |
|
| 548 | - |
|
| 549 | - $this->generalCreateChecks($share); |
|
| 550 | - |
|
| 551 | - // Verify if there are any issues with the path |
|
| 552 | - $this->pathCreateChecks($share->getNode()); |
|
| 553 | - |
|
| 554 | - /* |
|
| 442 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
| 443 | + $existingShares = $provider->getSharesByPath($share->getNode()); |
|
| 444 | + foreach($existingShares as $existingShare) { |
|
| 445 | + try { |
|
| 446 | + if ($existingShare->getFullId() === $share->getFullId()) { |
|
| 447 | + continue; |
|
| 448 | + } |
|
| 449 | + } catch (\UnexpectedValueException $e) { |
|
| 450 | + //It is a new share so just continue |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + if ($existingShare->getSharedWith() === $share->getSharedWith()) { |
|
| 454 | + throw new \Exception('Path already shared with this group'); |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * Check for pre share requirements for link shares |
|
| 461 | + * |
|
| 462 | + * @param \OCP\Share\IShare $share |
|
| 463 | + * @throws \Exception |
|
| 464 | + */ |
|
| 465 | + protected function linkCreateChecks(\OCP\Share\IShare $share) { |
|
| 466 | + // Are link shares allowed? |
|
| 467 | + if (!$this->shareApiAllowLinks()) { |
|
| 468 | + throw new \Exception('Link sharing not allowed'); |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + // Link shares by definition can't have share permissions |
|
| 472 | + if ($share->getPermissions() & \OCP\Constants::PERMISSION_SHARE) { |
|
| 473 | + throw new \InvalidArgumentException('Link shares can\'t have reshare permissions'); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + // Check if public upload is allowed |
|
| 477 | + if (!$this->shareApiLinkAllowPublicUpload() && |
|
| 478 | + ($share->getPermissions() & (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE))) { |
|
| 479 | + throw new \InvalidArgumentException('Public upload not allowed'); |
|
| 480 | + } |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * To make sure we don't get invisible link shares we set the parent |
|
| 485 | + * of a link if it is a reshare. This is a quick word around |
|
| 486 | + * until we can properly display multiple link shares in the UI |
|
| 487 | + * |
|
| 488 | + * See: https://github.com/owncloud/core/issues/22295 |
|
| 489 | + * |
|
| 490 | + * FIXME: Remove once multiple link shares can be properly displayed |
|
| 491 | + * |
|
| 492 | + * @param \OCP\Share\IShare $share |
|
| 493 | + */ |
|
| 494 | + protected function setLinkParent(\OCP\Share\IShare $share) { |
|
| 495 | + |
|
| 496 | + // No sense in checking if the method is not there. |
|
| 497 | + if (method_exists($share, 'setParent')) { |
|
| 498 | + $storage = $share->getNode()->getStorage(); |
|
| 499 | + if ($storage->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
| 500 | + /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
| 501 | + $share->setParent($storage->getShareId()); |
|
| 502 | + } |
|
| 503 | + }; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * @param File|Folder $path |
|
| 508 | + */ |
|
| 509 | + protected function pathCreateChecks($path) { |
|
| 510 | + // Make sure that we do not share a path that contains a shared mountpoint |
|
| 511 | + if ($path instanceof \OCP\Files\Folder) { |
|
| 512 | + $mounts = $this->mountManager->findIn($path->getPath()); |
|
| 513 | + foreach($mounts as $mount) { |
|
| 514 | + if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
| 515 | + throw new \InvalidArgumentException('Path contains files shared with you'); |
|
| 516 | + } |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * Check if the user that is sharing can actually share |
|
| 523 | + * |
|
| 524 | + * @param \OCP\Share\IShare $share |
|
| 525 | + * @throws \Exception |
|
| 526 | + */ |
|
| 527 | + protected function canShare(\OCP\Share\IShare $share) { |
|
| 528 | + if (!$this->shareApiEnabled()) { |
|
| 529 | + throw new \Exception('The share API is disabled'); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + if ($this->sharingDisabledForUser($share->getSharedBy())) { |
|
| 533 | + throw new \Exception('You are not allowed to share'); |
|
| 534 | + } |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + /** |
|
| 538 | + * Share a path |
|
| 539 | + * |
|
| 540 | + * @param \OCP\Share\IShare $share |
|
| 541 | + * @return Share The share object |
|
| 542 | + * @throws \Exception |
|
| 543 | + * |
|
| 544 | + * TODO: handle link share permissions or check them |
|
| 545 | + */ |
|
| 546 | + public function createShare(\OCP\Share\IShare $share) { |
|
| 547 | + $this->canShare($share); |
|
| 548 | + |
|
| 549 | + $this->generalCreateChecks($share); |
|
| 550 | + |
|
| 551 | + // Verify if there are any issues with the path |
|
| 552 | + $this->pathCreateChecks($share->getNode()); |
|
| 553 | + |
|
| 554 | + /* |
|
| 555 | 555 | * On creation of a share the owner is always the owner of the path |
| 556 | 556 | * Except for mounted federated shares. |
| 557 | 557 | */ |
| 558 | - $storage = $share->getNode()->getStorage(); |
|
| 559 | - if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
| 560 | - $parent = $share->getNode()->getParent(); |
|
| 561 | - while($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
| 562 | - $parent = $parent->getParent(); |
|
| 563 | - } |
|
| 564 | - $share->setShareOwner($parent->getOwner()->getUID()); |
|
| 565 | - } else { |
|
| 566 | - $share->setShareOwner($share->getNode()->getOwner()->getUID()); |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - //Verify share type |
|
| 570 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 571 | - $this->userCreateChecks($share); |
|
| 572 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 573 | - $this->groupCreateChecks($share); |
|
| 574 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 575 | - $this->linkCreateChecks($share); |
|
| 576 | - $this->setLinkParent($share); |
|
| 577 | - |
|
| 578 | - /* |
|
| 558 | + $storage = $share->getNode()->getStorage(); |
|
| 559 | + if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
| 560 | + $parent = $share->getNode()->getParent(); |
|
| 561 | + while($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
| 562 | + $parent = $parent->getParent(); |
|
| 563 | + } |
|
| 564 | + $share->setShareOwner($parent->getOwner()->getUID()); |
|
| 565 | + } else { |
|
| 566 | + $share->setShareOwner($share->getNode()->getOwner()->getUID()); |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + //Verify share type |
|
| 570 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 571 | + $this->userCreateChecks($share); |
|
| 572 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 573 | + $this->groupCreateChecks($share); |
|
| 574 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 575 | + $this->linkCreateChecks($share); |
|
| 576 | + $this->setLinkParent($share); |
|
| 577 | + |
|
| 578 | + /* |
|
| 579 | 579 | * For now ignore a set token. |
| 580 | 580 | */ |
| 581 | - $share->setToken( |
|
| 582 | - $this->secureRandom->generate( |
|
| 583 | - \OC\Share\Constants::TOKEN_LENGTH, |
|
| 584 | - \OCP\Security\ISecureRandom::CHAR_LOWER. |
|
| 585 | - \OCP\Security\ISecureRandom::CHAR_UPPER. |
|
| 586 | - \OCP\Security\ISecureRandom::CHAR_DIGITS |
|
| 587 | - ) |
|
| 588 | - ); |
|
| 589 | - |
|
| 590 | - //Verify the expiration date |
|
| 591 | - $this->validateExpirationDate($share); |
|
| 592 | - |
|
| 593 | - //Verify the password |
|
| 594 | - $this->verifyPassword($share->getPassword()); |
|
| 595 | - |
|
| 596 | - // If a password is set. Hash it! |
|
| 597 | - if ($share->getPassword() !== null) { |
|
| 598 | - $share->setPassword($this->hasher->hash($share->getPassword())); |
|
| 599 | - } |
|
| 600 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 601 | - $share->setToken( |
|
| 602 | - $this->secureRandom->generate( |
|
| 603 | - \OC\Share\Constants::TOKEN_LENGTH, |
|
| 604 | - \OCP\Security\ISecureRandom::CHAR_LOWER. |
|
| 605 | - \OCP\Security\ISecureRandom::CHAR_UPPER. |
|
| 606 | - \OCP\Security\ISecureRandom::CHAR_DIGITS |
|
| 607 | - ) |
|
| 608 | - ); |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - // Cannot share with the owner |
|
| 612 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
| 613 | - $share->getSharedWith() === $share->getShareOwner()) { |
|
| 614 | - throw new \InvalidArgumentException('Can\'t share with the share owner'); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - // Generate the target |
|
| 618 | - $target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getNode()->getName(); |
|
| 619 | - $target = \OC\Files\Filesystem::normalizePath($target); |
|
| 620 | - $share->setTarget($target); |
|
| 621 | - |
|
| 622 | - // Pre share hook |
|
| 623 | - $run = true; |
|
| 624 | - $error = ''; |
|
| 625 | - $preHookData = [ |
|
| 626 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 627 | - 'itemSource' => $share->getNode()->getId(), |
|
| 628 | - 'shareType' => $share->getShareType(), |
|
| 629 | - 'uidOwner' => $share->getSharedBy(), |
|
| 630 | - 'permissions' => $share->getPermissions(), |
|
| 631 | - 'fileSource' => $share->getNode()->getId(), |
|
| 632 | - 'expiration' => $share->getExpirationDate(), |
|
| 633 | - 'token' => $share->getToken(), |
|
| 634 | - 'itemTarget' => $share->getTarget(), |
|
| 635 | - 'shareWith' => $share->getSharedWith(), |
|
| 636 | - 'run' => &$run, |
|
| 637 | - 'error' => &$error, |
|
| 638 | - ]; |
|
| 639 | - \OC_Hook::emit('OCP\Share', 'pre_shared', $preHookData); |
|
| 640 | - |
|
| 641 | - if ($run === false) { |
|
| 642 | - throw new \Exception($error); |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - $oldShare = $share; |
|
| 646 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 647 | - $share = $provider->create($share); |
|
| 648 | - //reuse the node we already have |
|
| 649 | - $share->setNode($oldShare->getNode()); |
|
| 650 | - |
|
| 651 | - // Post share hook |
|
| 652 | - $postHookData = [ |
|
| 653 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 654 | - 'itemSource' => $share->getNode()->getId(), |
|
| 655 | - 'shareType' => $share->getShareType(), |
|
| 656 | - 'uidOwner' => $share->getSharedBy(), |
|
| 657 | - 'permissions' => $share->getPermissions(), |
|
| 658 | - 'fileSource' => $share->getNode()->getId(), |
|
| 659 | - 'expiration' => $share->getExpirationDate(), |
|
| 660 | - 'token' => $share->getToken(), |
|
| 661 | - 'id' => $share->getId(), |
|
| 662 | - 'shareWith' => $share->getSharedWith(), |
|
| 663 | - 'itemTarget' => $share->getTarget(), |
|
| 664 | - 'fileTarget' => $share->getTarget(), |
|
| 665 | - ]; |
|
| 666 | - |
|
| 667 | - \OC_Hook::emit('OCP\Share', 'post_shared', $postHookData); |
|
| 668 | - |
|
| 669 | - return $share; |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - /** |
|
| 673 | - * Update a share |
|
| 674 | - * |
|
| 675 | - * @param \OCP\Share\IShare $share |
|
| 676 | - * @return \OCP\Share\IShare The share object |
|
| 677 | - * @throws \InvalidArgumentException |
|
| 678 | - */ |
|
| 679 | - public function updateShare(\OCP\Share\IShare $share) { |
|
| 680 | - $expirationDateUpdated = false; |
|
| 681 | - |
|
| 682 | - $this->canShare($share); |
|
| 683 | - |
|
| 684 | - try { |
|
| 685 | - $originalShare = $this->getShareById($share->getFullId()); |
|
| 686 | - } catch (\UnexpectedValueException $e) { |
|
| 687 | - throw new \InvalidArgumentException('Share does not have a full id'); |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - // We can't change the share type! |
|
| 691 | - if ($share->getShareType() !== $originalShare->getShareType()) { |
|
| 692 | - throw new \InvalidArgumentException('Can\'t change share type'); |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - // We can only change the recipient on user shares |
|
| 696 | - if ($share->getSharedWith() !== $originalShare->getSharedWith() && |
|
| 697 | - $share->getShareType() !== \OCP\Share::SHARE_TYPE_USER) { |
|
| 698 | - throw new \InvalidArgumentException('Can only update recipient on user shares'); |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - // Cannot share with the owner |
|
| 702 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
| 703 | - $share->getSharedWith() === $share->getShareOwner()) { |
|
| 704 | - throw new \InvalidArgumentException('Can\'t share with the share owner'); |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - $this->generalCreateChecks($share); |
|
| 708 | - |
|
| 709 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 710 | - $this->userCreateChecks($share); |
|
| 711 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 712 | - $this->groupCreateChecks($share); |
|
| 713 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 714 | - $this->linkCreateChecks($share); |
|
| 715 | - |
|
| 716 | - // Password updated. |
|
| 717 | - if ($share->getPassword() !== $originalShare->getPassword()) { |
|
| 718 | - //Verify the password |
|
| 719 | - $this->verifyPassword($share->getPassword()); |
|
| 720 | - |
|
| 721 | - // If a password is set. Hash it! |
|
| 722 | - if ($share->getPassword() !== null) { |
|
| 723 | - $share->setPassword($this->hasher->hash($share->getPassword())); |
|
| 724 | - } |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
| 728 | - //Verify the expiration date |
|
| 729 | - $this->validateExpirationDate($share); |
|
| 730 | - $expirationDateUpdated = true; |
|
| 731 | - } |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - $this->pathCreateChecks($share->getNode()); |
|
| 735 | - |
|
| 736 | - // Now update the share! |
|
| 737 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 738 | - $share = $provider->update($share); |
|
| 739 | - |
|
| 740 | - if ($expirationDateUpdated === true) { |
|
| 741 | - \OC_Hook::emit('OCP\Share', 'post_set_expiration_date', [ |
|
| 742 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 743 | - 'itemSource' => $share->getNode()->getId(), |
|
| 744 | - 'date' => $share->getExpirationDate(), |
|
| 745 | - 'uidOwner' => $share->getSharedBy(), |
|
| 746 | - ]); |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - if ($share->getPassword() !== $originalShare->getPassword()) { |
|
| 750 | - \OC_Hook::emit('OCP\Share', 'post_update_password', [ |
|
| 751 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 752 | - 'itemSource' => $share->getNode()->getId(), |
|
| 753 | - 'uidOwner' => $share->getSharedBy(), |
|
| 754 | - 'token' => $share->getToken(), |
|
| 755 | - 'disabled' => is_null($share->getPassword()), |
|
| 756 | - ]); |
|
| 757 | - } |
|
| 758 | - |
|
| 759 | - if ($share->getPermissions() !== $originalShare->getPermissions()) { |
|
| 760 | - if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 761 | - $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
| 762 | - } else { |
|
| 763 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
| 764 | - } |
|
| 765 | - \OC_Hook::emit('OCP\Share', 'post_update_permissions', array( |
|
| 766 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 767 | - 'itemSource' => $share->getNode()->getId(), |
|
| 768 | - 'shareType' => $share->getShareType(), |
|
| 769 | - 'shareWith' => $share->getSharedWith(), |
|
| 770 | - 'uidOwner' => $share->getSharedBy(), |
|
| 771 | - 'permissions' => $share->getPermissions(), |
|
| 772 | - 'path' => $userFolder->getRelativePath($share->getNode()->getPath()), |
|
| 773 | - )); |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - return $share; |
|
| 777 | - } |
|
| 778 | - |
|
| 779 | - /** |
|
| 780 | - * Delete all the children of this share |
|
| 781 | - * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
| 782 | - * |
|
| 783 | - * @param \OCP\Share\IShare $share |
|
| 784 | - * @return \OCP\Share\IShare[] List of deleted shares |
|
| 785 | - */ |
|
| 786 | - protected function deleteChildren(\OCP\Share\IShare $share) { |
|
| 787 | - $deletedShares = []; |
|
| 788 | - |
|
| 789 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 790 | - |
|
| 791 | - foreach ($provider->getChildren($share) as $child) { |
|
| 792 | - $deletedChildren = $this->deleteChildren($child); |
|
| 793 | - $deletedShares = array_merge($deletedShares, $deletedChildren); |
|
| 794 | - |
|
| 795 | - $provider->delete($child); |
|
| 796 | - $deletedShares[] = $child; |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - return $deletedShares; |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - /** |
|
| 803 | - * Delete a share |
|
| 804 | - * |
|
| 805 | - * @param \OCP\Share\IShare $share |
|
| 806 | - * @throws ShareNotFound |
|
| 807 | - * @throws \InvalidArgumentException |
|
| 808 | - */ |
|
| 809 | - public function deleteShare(\OCP\Share\IShare $share) { |
|
| 810 | - |
|
| 811 | - try { |
|
| 812 | - $share->getFullId(); |
|
| 813 | - } catch (\UnexpectedValueException $e) { |
|
| 814 | - throw new \InvalidArgumentException('Share does not have a full id'); |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - $event = new GenericEvent($share); |
|
| 818 | - $this->eventDispatcher->dispatch('OCP\Share::preUnshare', $event); |
|
| 819 | - |
|
| 820 | - // Get all children and delete them as well |
|
| 821 | - $deletedShares = $this->deleteChildren($share); |
|
| 822 | - |
|
| 823 | - // Do the actual delete |
|
| 824 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 825 | - $provider->delete($share); |
|
| 826 | - |
|
| 827 | - // All the deleted shares caused by this delete |
|
| 828 | - $deletedShares[] = $share; |
|
| 829 | - |
|
| 830 | - // Emit post hook |
|
| 831 | - $event->setArgument('deletedShares', $deletedShares); |
|
| 832 | - $this->eventDispatcher->dispatch('OCP\Share::postUnshare', $event); |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - |
|
| 836 | - /** |
|
| 837 | - * Unshare a file as the recipient. |
|
| 838 | - * This can be different from a regular delete for example when one of |
|
| 839 | - * the users in a groups deletes that share. But the provider should |
|
| 840 | - * handle this. |
|
| 841 | - * |
|
| 842 | - * @param \OCP\Share\IShare $share |
|
| 843 | - * @param string $recipientId |
|
| 844 | - */ |
|
| 845 | - public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) { |
|
| 846 | - list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
| 847 | - $provider = $this->factory->getProvider($providerId); |
|
| 848 | - |
|
| 849 | - $provider->deleteFromSelf($share, $recipientId); |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - /** |
|
| 853 | - * @inheritdoc |
|
| 854 | - */ |
|
| 855 | - public function moveShare(\OCP\Share\IShare $share, $recipientId) { |
|
| 856 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 857 | - throw new \InvalidArgumentException('Can\'t change target of link share'); |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() !== $recipientId) { |
|
| 861 | - throw new \InvalidArgumentException('Invalid recipient'); |
|
| 862 | - } |
|
| 863 | - |
|
| 864 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 865 | - $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
| 866 | - if (is_null($sharedWith)) { |
|
| 867 | - throw new \InvalidArgumentException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
| 868 | - } |
|
| 869 | - $recipient = $this->userManager->get($recipientId); |
|
| 870 | - if (!$sharedWith->inGroup($recipient)) { |
|
| 871 | - throw new \InvalidArgumentException('Invalid recipient'); |
|
| 872 | - } |
|
| 873 | - } |
|
| 874 | - |
|
| 875 | - list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
| 876 | - $provider = $this->factory->getProvider($providerId); |
|
| 877 | - |
|
| 878 | - $provider->move($share, $recipientId); |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - public function getSharesInFolder($userId, Folder $node, $reshares = false) { |
|
| 882 | - $providers = $this->factory->getAllProviders(); |
|
| 883 | - |
|
| 884 | - return array_reduce($providers, function($shares, IShareProvider $provider) use ($userId, $node, $reshares) { |
|
| 885 | - $newShares = $provider->getSharesInFolder($userId, $node, $reshares); |
|
| 886 | - foreach ($newShares as $fid => $data) { |
|
| 887 | - if (!isset($shares[$fid])) { |
|
| 888 | - $shares[$fid] = []; |
|
| 889 | - } |
|
| 890 | - |
|
| 891 | - $shares[$fid] = array_merge($shares[$fid], $data); |
|
| 892 | - } |
|
| 893 | - return $shares; |
|
| 894 | - }, []); |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - /** |
|
| 898 | - * @inheritdoc |
|
| 899 | - */ |
|
| 900 | - public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) { |
|
| 901 | - if ($path !== null && |
|
| 902 | - !($path instanceof \OCP\Files\File) && |
|
| 903 | - !($path instanceof \OCP\Files\Folder)) { |
|
| 904 | - throw new \InvalidArgumentException('invalid path'); |
|
| 905 | - } |
|
| 906 | - |
|
| 907 | - try { |
|
| 908 | - $provider = $this->factory->getProviderForType($shareType); |
|
| 909 | - } catch (ProviderException $e) { |
|
| 910 | - return []; |
|
| 911 | - } |
|
| 912 | - |
|
| 913 | - $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
| 914 | - |
|
| 915 | - /* |
|
| 581 | + $share->setToken( |
|
| 582 | + $this->secureRandom->generate( |
|
| 583 | + \OC\Share\Constants::TOKEN_LENGTH, |
|
| 584 | + \OCP\Security\ISecureRandom::CHAR_LOWER. |
|
| 585 | + \OCP\Security\ISecureRandom::CHAR_UPPER. |
|
| 586 | + \OCP\Security\ISecureRandom::CHAR_DIGITS |
|
| 587 | + ) |
|
| 588 | + ); |
|
| 589 | + |
|
| 590 | + //Verify the expiration date |
|
| 591 | + $this->validateExpirationDate($share); |
|
| 592 | + |
|
| 593 | + //Verify the password |
|
| 594 | + $this->verifyPassword($share->getPassword()); |
|
| 595 | + |
|
| 596 | + // If a password is set. Hash it! |
|
| 597 | + if ($share->getPassword() !== null) { |
|
| 598 | + $share->setPassword($this->hasher->hash($share->getPassword())); |
|
| 599 | + } |
|
| 600 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 601 | + $share->setToken( |
|
| 602 | + $this->secureRandom->generate( |
|
| 603 | + \OC\Share\Constants::TOKEN_LENGTH, |
|
| 604 | + \OCP\Security\ISecureRandom::CHAR_LOWER. |
|
| 605 | + \OCP\Security\ISecureRandom::CHAR_UPPER. |
|
| 606 | + \OCP\Security\ISecureRandom::CHAR_DIGITS |
|
| 607 | + ) |
|
| 608 | + ); |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + // Cannot share with the owner |
|
| 612 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
| 613 | + $share->getSharedWith() === $share->getShareOwner()) { |
|
| 614 | + throw new \InvalidArgumentException('Can\'t share with the share owner'); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + // Generate the target |
|
| 618 | + $target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getNode()->getName(); |
|
| 619 | + $target = \OC\Files\Filesystem::normalizePath($target); |
|
| 620 | + $share->setTarget($target); |
|
| 621 | + |
|
| 622 | + // Pre share hook |
|
| 623 | + $run = true; |
|
| 624 | + $error = ''; |
|
| 625 | + $preHookData = [ |
|
| 626 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 627 | + 'itemSource' => $share->getNode()->getId(), |
|
| 628 | + 'shareType' => $share->getShareType(), |
|
| 629 | + 'uidOwner' => $share->getSharedBy(), |
|
| 630 | + 'permissions' => $share->getPermissions(), |
|
| 631 | + 'fileSource' => $share->getNode()->getId(), |
|
| 632 | + 'expiration' => $share->getExpirationDate(), |
|
| 633 | + 'token' => $share->getToken(), |
|
| 634 | + 'itemTarget' => $share->getTarget(), |
|
| 635 | + 'shareWith' => $share->getSharedWith(), |
|
| 636 | + 'run' => &$run, |
|
| 637 | + 'error' => &$error, |
|
| 638 | + ]; |
|
| 639 | + \OC_Hook::emit('OCP\Share', 'pre_shared', $preHookData); |
|
| 640 | + |
|
| 641 | + if ($run === false) { |
|
| 642 | + throw new \Exception($error); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + $oldShare = $share; |
|
| 646 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 647 | + $share = $provider->create($share); |
|
| 648 | + //reuse the node we already have |
|
| 649 | + $share->setNode($oldShare->getNode()); |
|
| 650 | + |
|
| 651 | + // Post share hook |
|
| 652 | + $postHookData = [ |
|
| 653 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 654 | + 'itemSource' => $share->getNode()->getId(), |
|
| 655 | + 'shareType' => $share->getShareType(), |
|
| 656 | + 'uidOwner' => $share->getSharedBy(), |
|
| 657 | + 'permissions' => $share->getPermissions(), |
|
| 658 | + 'fileSource' => $share->getNode()->getId(), |
|
| 659 | + 'expiration' => $share->getExpirationDate(), |
|
| 660 | + 'token' => $share->getToken(), |
|
| 661 | + 'id' => $share->getId(), |
|
| 662 | + 'shareWith' => $share->getSharedWith(), |
|
| 663 | + 'itemTarget' => $share->getTarget(), |
|
| 664 | + 'fileTarget' => $share->getTarget(), |
|
| 665 | + ]; |
|
| 666 | + |
|
| 667 | + \OC_Hook::emit('OCP\Share', 'post_shared', $postHookData); |
|
| 668 | + |
|
| 669 | + return $share; |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + /** |
|
| 673 | + * Update a share |
|
| 674 | + * |
|
| 675 | + * @param \OCP\Share\IShare $share |
|
| 676 | + * @return \OCP\Share\IShare The share object |
|
| 677 | + * @throws \InvalidArgumentException |
|
| 678 | + */ |
|
| 679 | + public function updateShare(\OCP\Share\IShare $share) { |
|
| 680 | + $expirationDateUpdated = false; |
|
| 681 | + |
|
| 682 | + $this->canShare($share); |
|
| 683 | + |
|
| 684 | + try { |
|
| 685 | + $originalShare = $this->getShareById($share->getFullId()); |
|
| 686 | + } catch (\UnexpectedValueException $e) { |
|
| 687 | + throw new \InvalidArgumentException('Share does not have a full id'); |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + // We can't change the share type! |
|
| 691 | + if ($share->getShareType() !== $originalShare->getShareType()) { |
|
| 692 | + throw new \InvalidArgumentException('Can\'t change share type'); |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + // We can only change the recipient on user shares |
|
| 696 | + if ($share->getSharedWith() !== $originalShare->getSharedWith() && |
|
| 697 | + $share->getShareType() !== \OCP\Share::SHARE_TYPE_USER) { |
|
| 698 | + throw new \InvalidArgumentException('Can only update recipient on user shares'); |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + // Cannot share with the owner |
|
| 702 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
| 703 | + $share->getSharedWith() === $share->getShareOwner()) { |
|
| 704 | + throw new \InvalidArgumentException('Can\'t share with the share owner'); |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + $this->generalCreateChecks($share); |
|
| 708 | + |
|
| 709 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 710 | + $this->userCreateChecks($share); |
|
| 711 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 712 | + $this->groupCreateChecks($share); |
|
| 713 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 714 | + $this->linkCreateChecks($share); |
|
| 715 | + |
|
| 716 | + // Password updated. |
|
| 717 | + if ($share->getPassword() !== $originalShare->getPassword()) { |
|
| 718 | + //Verify the password |
|
| 719 | + $this->verifyPassword($share->getPassword()); |
|
| 720 | + |
|
| 721 | + // If a password is set. Hash it! |
|
| 722 | + if ($share->getPassword() !== null) { |
|
| 723 | + $share->setPassword($this->hasher->hash($share->getPassword())); |
|
| 724 | + } |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
| 728 | + //Verify the expiration date |
|
| 729 | + $this->validateExpirationDate($share); |
|
| 730 | + $expirationDateUpdated = true; |
|
| 731 | + } |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + $this->pathCreateChecks($share->getNode()); |
|
| 735 | + |
|
| 736 | + // Now update the share! |
|
| 737 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 738 | + $share = $provider->update($share); |
|
| 739 | + |
|
| 740 | + if ($expirationDateUpdated === true) { |
|
| 741 | + \OC_Hook::emit('OCP\Share', 'post_set_expiration_date', [ |
|
| 742 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 743 | + 'itemSource' => $share->getNode()->getId(), |
|
| 744 | + 'date' => $share->getExpirationDate(), |
|
| 745 | + 'uidOwner' => $share->getSharedBy(), |
|
| 746 | + ]); |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + if ($share->getPassword() !== $originalShare->getPassword()) { |
|
| 750 | + \OC_Hook::emit('OCP\Share', 'post_update_password', [ |
|
| 751 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 752 | + 'itemSource' => $share->getNode()->getId(), |
|
| 753 | + 'uidOwner' => $share->getSharedBy(), |
|
| 754 | + 'token' => $share->getToken(), |
|
| 755 | + 'disabled' => is_null($share->getPassword()), |
|
| 756 | + ]); |
|
| 757 | + } |
|
| 758 | + |
|
| 759 | + if ($share->getPermissions() !== $originalShare->getPermissions()) { |
|
| 760 | + if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 761 | + $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
| 762 | + } else { |
|
| 763 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
| 764 | + } |
|
| 765 | + \OC_Hook::emit('OCP\Share', 'post_update_permissions', array( |
|
| 766 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 767 | + 'itemSource' => $share->getNode()->getId(), |
|
| 768 | + 'shareType' => $share->getShareType(), |
|
| 769 | + 'shareWith' => $share->getSharedWith(), |
|
| 770 | + 'uidOwner' => $share->getSharedBy(), |
|
| 771 | + 'permissions' => $share->getPermissions(), |
|
| 772 | + 'path' => $userFolder->getRelativePath($share->getNode()->getPath()), |
|
| 773 | + )); |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + return $share; |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + /** |
|
| 780 | + * Delete all the children of this share |
|
| 781 | + * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
| 782 | + * |
|
| 783 | + * @param \OCP\Share\IShare $share |
|
| 784 | + * @return \OCP\Share\IShare[] List of deleted shares |
|
| 785 | + */ |
|
| 786 | + protected function deleteChildren(\OCP\Share\IShare $share) { |
|
| 787 | + $deletedShares = []; |
|
| 788 | + |
|
| 789 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 790 | + |
|
| 791 | + foreach ($provider->getChildren($share) as $child) { |
|
| 792 | + $deletedChildren = $this->deleteChildren($child); |
|
| 793 | + $deletedShares = array_merge($deletedShares, $deletedChildren); |
|
| 794 | + |
|
| 795 | + $provider->delete($child); |
|
| 796 | + $deletedShares[] = $child; |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + return $deletedShares; |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + /** |
|
| 803 | + * Delete a share |
|
| 804 | + * |
|
| 805 | + * @param \OCP\Share\IShare $share |
|
| 806 | + * @throws ShareNotFound |
|
| 807 | + * @throws \InvalidArgumentException |
|
| 808 | + */ |
|
| 809 | + public function deleteShare(\OCP\Share\IShare $share) { |
|
| 810 | + |
|
| 811 | + try { |
|
| 812 | + $share->getFullId(); |
|
| 813 | + } catch (\UnexpectedValueException $e) { |
|
| 814 | + throw new \InvalidArgumentException('Share does not have a full id'); |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + $event = new GenericEvent($share); |
|
| 818 | + $this->eventDispatcher->dispatch('OCP\Share::preUnshare', $event); |
|
| 819 | + |
|
| 820 | + // Get all children and delete them as well |
|
| 821 | + $deletedShares = $this->deleteChildren($share); |
|
| 822 | + |
|
| 823 | + // Do the actual delete |
|
| 824 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 825 | + $provider->delete($share); |
|
| 826 | + |
|
| 827 | + // All the deleted shares caused by this delete |
|
| 828 | + $deletedShares[] = $share; |
|
| 829 | + |
|
| 830 | + // Emit post hook |
|
| 831 | + $event->setArgument('deletedShares', $deletedShares); |
|
| 832 | + $this->eventDispatcher->dispatch('OCP\Share::postUnshare', $event); |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + |
|
| 836 | + /** |
|
| 837 | + * Unshare a file as the recipient. |
|
| 838 | + * This can be different from a regular delete for example when one of |
|
| 839 | + * the users in a groups deletes that share. But the provider should |
|
| 840 | + * handle this. |
|
| 841 | + * |
|
| 842 | + * @param \OCP\Share\IShare $share |
|
| 843 | + * @param string $recipientId |
|
| 844 | + */ |
|
| 845 | + public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) { |
|
| 846 | + list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
| 847 | + $provider = $this->factory->getProvider($providerId); |
|
| 848 | + |
|
| 849 | + $provider->deleteFromSelf($share, $recipientId); |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + /** |
|
| 853 | + * @inheritdoc |
|
| 854 | + */ |
|
| 855 | + public function moveShare(\OCP\Share\IShare $share, $recipientId) { |
|
| 856 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 857 | + throw new \InvalidArgumentException('Can\'t change target of link share'); |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() !== $recipientId) { |
|
| 861 | + throw new \InvalidArgumentException('Invalid recipient'); |
|
| 862 | + } |
|
| 863 | + |
|
| 864 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 865 | + $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
| 866 | + if (is_null($sharedWith)) { |
|
| 867 | + throw new \InvalidArgumentException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
| 868 | + } |
|
| 869 | + $recipient = $this->userManager->get($recipientId); |
|
| 870 | + if (!$sharedWith->inGroup($recipient)) { |
|
| 871 | + throw new \InvalidArgumentException('Invalid recipient'); |
|
| 872 | + } |
|
| 873 | + } |
|
| 874 | + |
|
| 875 | + list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
| 876 | + $provider = $this->factory->getProvider($providerId); |
|
| 877 | + |
|
| 878 | + $provider->move($share, $recipientId); |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + public function getSharesInFolder($userId, Folder $node, $reshares = false) { |
|
| 882 | + $providers = $this->factory->getAllProviders(); |
|
| 883 | + |
|
| 884 | + return array_reduce($providers, function($shares, IShareProvider $provider) use ($userId, $node, $reshares) { |
|
| 885 | + $newShares = $provider->getSharesInFolder($userId, $node, $reshares); |
|
| 886 | + foreach ($newShares as $fid => $data) { |
|
| 887 | + if (!isset($shares[$fid])) { |
|
| 888 | + $shares[$fid] = []; |
|
| 889 | + } |
|
| 890 | + |
|
| 891 | + $shares[$fid] = array_merge($shares[$fid], $data); |
|
| 892 | + } |
|
| 893 | + return $shares; |
|
| 894 | + }, []); |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + /** |
|
| 898 | + * @inheritdoc |
|
| 899 | + */ |
|
| 900 | + public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) { |
|
| 901 | + if ($path !== null && |
|
| 902 | + !($path instanceof \OCP\Files\File) && |
|
| 903 | + !($path instanceof \OCP\Files\Folder)) { |
|
| 904 | + throw new \InvalidArgumentException('invalid path'); |
|
| 905 | + } |
|
| 906 | + |
|
| 907 | + try { |
|
| 908 | + $provider = $this->factory->getProviderForType($shareType); |
|
| 909 | + } catch (ProviderException $e) { |
|
| 910 | + return []; |
|
| 911 | + } |
|
| 912 | + |
|
| 913 | + $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
| 914 | + |
|
| 915 | + /* |
|
| 916 | 916 | * Work around so we don't return expired shares but still follow |
| 917 | 917 | * proper pagination. |
| 918 | 918 | */ |
| 919 | - if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 920 | - $shares2 = []; |
|
| 921 | - $today = new \DateTime(); |
|
| 922 | - |
|
| 923 | - while(true) { |
|
| 924 | - $added = 0; |
|
| 925 | - foreach ($shares as $share) { |
|
| 926 | - // Check if the share is expired and if so delete it |
|
| 927 | - if ($share->getExpirationDate() !== null && |
|
| 928 | - $share->getExpirationDate() <= $today |
|
| 929 | - ) { |
|
| 930 | - try { |
|
| 931 | - $this->deleteShare($share); |
|
| 932 | - } catch (NotFoundException $e) { |
|
| 933 | - //Ignore since this basically means the share is deleted |
|
| 934 | - } |
|
| 935 | - continue; |
|
| 936 | - } |
|
| 937 | - $added++; |
|
| 938 | - $shares2[] = $share; |
|
| 939 | - |
|
| 940 | - if (count($shares2) === $limit) { |
|
| 941 | - break; |
|
| 942 | - } |
|
| 943 | - } |
|
| 944 | - |
|
| 945 | - if (count($shares2) === $limit) { |
|
| 946 | - break; |
|
| 947 | - } |
|
| 948 | - |
|
| 949 | - // If there was no limit on the select we are done |
|
| 950 | - if ($limit === -1) { |
|
| 951 | - break; |
|
| 952 | - } |
|
| 953 | - |
|
| 954 | - $offset += $added; |
|
| 955 | - |
|
| 956 | - // Fetch again $limit shares |
|
| 957 | - $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
| 958 | - |
|
| 959 | - // No more shares means we are done |
|
| 960 | - if (empty($shares)) { |
|
| 961 | - break; |
|
| 962 | - } |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - $shares = $shares2; |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - return $shares; |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - /** |
|
| 972 | - * @inheritdoc |
|
| 973 | - */ |
|
| 974 | - public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
| 975 | - try { |
|
| 976 | - $provider = $this->factory->getProviderForType($shareType); |
|
| 977 | - } catch (ProviderException $e) { |
|
| 978 | - return []; |
|
| 979 | - } |
|
| 980 | - |
|
| 981 | - return $provider->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
| 982 | - } |
|
| 983 | - |
|
| 984 | - /** |
|
| 985 | - * @inheritdoc |
|
| 986 | - */ |
|
| 987 | - public function getShareById($id, $recipient = null) { |
|
| 988 | - if ($id === null) { |
|
| 989 | - throw new ShareNotFound(); |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - list($providerId, $id) = $this->splitFullId($id); |
|
| 993 | - |
|
| 994 | - try { |
|
| 995 | - $provider = $this->factory->getProvider($providerId); |
|
| 996 | - } catch (ProviderException $e) { |
|
| 997 | - throw new ShareNotFound(); |
|
| 998 | - } |
|
| 999 | - |
|
| 1000 | - $share = $provider->getShareById($id, $recipient); |
|
| 1001 | - |
|
| 1002 | - // Validate link shares expiration date |
|
| 1003 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK && |
|
| 1004 | - $share->getExpirationDate() !== null && |
|
| 1005 | - $share->getExpirationDate() <= new \DateTime()) { |
|
| 1006 | - $this->deleteShare($share); |
|
| 1007 | - throw new ShareNotFound(); |
|
| 1008 | - } |
|
| 1009 | - |
|
| 1010 | - return $share; |
|
| 1011 | - } |
|
| 1012 | - |
|
| 1013 | - /** |
|
| 1014 | - * Get all the shares for a given path |
|
| 1015 | - * |
|
| 1016 | - * @param \OCP\Files\Node $path |
|
| 1017 | - * @param int $page |
|
| 1018 | - * @param int $perPage |
|
| 1019 | - * |
|
| 1020 | - * @return Share[] |
|
| 1021 | - */ |
|
| 1022 | - public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) { |
|
| 1023 | - return []; |
|
| 1024 | - } |
|
| 1025 | - |
|
| 1026 | - /** |
|
| 1027 | - * Get the share by token possible with password |
|
| 1028 | - * |
|
| 1029 | - * @param string $token |
|
| 1030 | - * @return Share |
|
| 1031 | - * |
|
| 1032 | - * @throws ShareNotFound |
|
| 1033 | - */ |
|
| 1034 | - public function getShareByToken($token) { |
|
| 1035 | - $share = null; |
|
| 1036 | - try { |
|
| 1037 | - if($this->shareApiAllowLinks()) { |
|
| 1038 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_LINK); |
|
| 1039 | - $share = $provider->getShareByToken($token); |
|
| 1040 | - } |
|
| 1041 | - } catch (ProviderException $e) { |
|
| 1042 | - } catch (ShareNotFound $e) { |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - |
|
| 1046 | - // If it is not a link share try to fetch a federated share by token |
|
| 1047 | - if ($share === null) { |
|
| 1048 | - try { |
|
| 1049 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_REMOTE); |
|
| 1050 | - $share = $provider->getShareByToken($token); |
|
| 1051 | - } catch (ProviderException $e) { |
|
| 1052 | - } catch (ShareNotFound $e) { |
|
| 1053 | - } |
|
| 1054 | - } |
|
| 1055 | - |
|
| 1056 | - // If it is not a link share try to fetch a mail share by token |
|
| 1057 | - if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 1058 | - try { |
|
| 1059 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_EMAIL); |
|
| 1060 | - $share = $provider->getShareByToken($token); |
|
| 1061 | - } catch (ProviderException $e) { |
|
| 1062 | - } catch (ShareNotFound $e) { |
|
| 1063 | - } |
|
| 1064 | - } |
|
| 1065 | - |
|
| 1066 | - if ($share === null) { |
|
| 1067 | - throw new ShareNotFound(); |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - if ($share->getExpirationDate() !== null && |
|
| 1071 | - $share->getExpirationDate() <= new \DateTime()) { |
|
| 1072 | - $this->deleteShare($share); |
|
| 1073 | - throw new ShareNotFound(); |
|
| 1074 | - } |
|
| 1075 | - |
|
| 1076 | - /* |
|
| 919 | + if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 920 | + $shares2 = []; |
|
| 921 | + $today = new \DateTime(); |
|
| 922 | + |
|
| 923 | + while(true) { |
|
| 924 | + $added = 0; |
|
| 925 | + foreach ($shares as $share) { |
|
| 926 | + // Check if the share is expired and if so delete it |
|
| 927 | + if ($share->getExpirationDate() !== null && |
|
| 928 | + $share->getExpirationDate() <= $today |
|
| 929 | + ) { |
|
| 930 | + try { |
|
| 931 | + $this->deleteShare($share); |
|
| 932 | + } catch (NotFoundException $e) { |
|
| 933 | + //Ignore since this basically means the share is deleted |
|
| 934 | + } |
|
| 935 | + continue; |
|
| 936 | + } |
|
| 937 | + $added++; |
|
| 938 | + $shares2[] = $share; |
|
| 939 | + |
|
| 940 | + if (count($shares2) === $limit) { |
|
| 941 | + break; |
|
| 942 | + } |
|
| 943 | + } |
|
| 944 | + |
|
| 945 | + if (count($shares2) === $limit) { |
|
| 946 | + break; |
|
| 947 | + } |
|
| 948 | + |
|
| 949 | + // If there was no limit on the select we are done |
|
| 950 | + if ($limit === -1) { |
|
| 951 | + break; |
|
| 952 | + } |
|
| 953 | + |
|
| 954 | + $offset += $added; |
|
| 955 | + |
|
| 956 | + // Fetch again $limit shares |
|
| 957 | + $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
| 958 | + |
|
| 959 | + // No more shares means we are done |
|
| 960 | + if (empty($shares)) { |
|
| 961 | + break; |
|
| 962 | + } |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + $shares = $shares2; |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + return $shares; |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + /** |
|
| 972 | + * @inheritdoc |
|
| 973 | + */ |
|
| 974 | + public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
| 975 | + try { |
|
| 976 | + $provider = $this->factory->getProviderForType($shareType); |
|
| 977 | + } catch (ProviderException $e) { |
|
| 978 | + return []; |
|
| 979 | + } |
|
| 980 | + |
|
| 981 | + return $provider->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
| 982 | + } |
|
| 983 | + |
|
| 984 | + /** |
|
| 985 | + * @inheritdoc |
|
| 986 | + */ |
|
| 987 | + public function getShareById($id, $recipient = null) { |
|
| 988 | + if ($id === null) { |
|
| 989 | + throw new ShareNotFound(); |
|
| 990 | + } |
|
| 991 | + |
|
| 992 | + list($providerId, $id) = $this->splitFullId($id); |
|
| 993 | + |
|
| 994 | + try { |
|
| 995 | + $provider = $this->factory->getProvider($providerId); |
|
| 996 | + } catch (ProviderException $e) { |
|
| 997 | + throw new ShareNotFound(); |
|
| 998 | + } |
|
| 999 | + |
|
| 1000 | + $share = $provider->getShareById($id, $recipient); |
|
| 1001 | + |
|
| 1002 | + // Validate link shares expiration date |
|
| 1003 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK && |
|
| 1004 | + $share->getExpirationDate() !== null && |
|
| 1005 | + $share->getExpirationDate() <= new \DateTime()) { |
|
| 1006 | + $this->deleteShare($share); |
|
| 1007 | + throw new ShareNotFound(); |
|
| 1008 | + } |
|
| 1009 | + |
|
| 1010 | + return $share; |
|
| 1011 | + } |
|
| 1012 | + |
|
| 1013 | + /** |
|
| 1014 | + * Get all the shares for a given path |
|
| 1015 | + * |
|
| 1016 | + * @param \OCP\Files\Node $path |
|
| 1017 | + * @param int $page |
|
| 1018 | + * @param int $perPage |
|
| 1019 | + * |
|
| 1020 | + * @return Share[] |
|
| 1021 | + */ |
|
| 1022 | + public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) { |
|
| 1023 | + return []; |
|
| 1024 | + } |
|
| 1025 | + |
|
| 1026 | + /** |
|
| 1027 | + * Get the share by token possible with password |
|
| 1028 | + * |
|
| 1029 | + * @param string $token |
|
| 1030 | + * @return Share |
|
| 1031 | + * |
|
| 1032 | + * @throws ShareNotFound |
|
| 1033 | + */ |
|
| 1034 | + public function getShareByToken($token) { |
|
| 1035 | + $share = null; |
|
| 1036 | + try { |
|
| 1037 | + if($this->shareApiAllowLinks()) { |
|
| 1038 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_LINK); |
|
| 1039 | + $share = $provider->getShareByToken($token); |
|
| 1040 | + } |
|
| 1041 | + } catch (ProviderException $e) { |
|
| 1042 | + } catch (ShareNotFound $e) { |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + |
|
| 1046 | + // If it is not a link share try to fetch a federated share by token |
|
| 1047 | + if ($share === null) { |
|
| 1048 | + try { |
|
| 1049 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_REMOTE); |
|
| 1050 | + $share = $provider->getShareByToken($token); |
|
| 1051 | + } catch (ProviderException $e) { |
|
| 1052 | + } catch (ShareNotFound $e) { |
|
| 1053 | + } |
|
| 1054 | + } |
|
| 1055 | + |
|
| 1056 | + // If it is not a link share try to fetch a mail share by token |
|
| 1057 | + if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 1058 | + try { |
|
| 1059 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_EMAIL); |
|
| 1060 | + $share = $provider->getShareByToken($token); |
|
| 1061 | + } catch (ProviderException $e) { |
|
| 1062 | + } catch (ShareNotFound $e) { |
|
| 1063 | + } |
|
| 1064 | + } |
|
| 1065 | + |
|
| 1066 | + if ($share === null) { |
|
| 1067 | + throw new ShareNotFound(); |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + if ($share->getExpirationDate() !== null && |
|
| 1071 | + $share->getExpirationDate() <= new \DateTime()) { |
|
| 1072 | + $this->deleteShare($share); |
|
| 1073 | + throw new ShareNotFound(); |
|
| 1074 | + } |
|
| 1075 | + |
|
| 1076 | + /* |
|
| 1077 | 1077 | * Reduce the permissions for link shares if public upload is not enabled |
| 1078 | 1078 | */ |
| 1079 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK && |
|
| 1080 | - !$this->shareApiLinkAllowPublicUpload()) { |
|
| 1081 | - $share->setPermissions($share->getPermissions() & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)); |
|
| 1082 | - } |
|
| 1083 | - |
|
| 1084 | - return $share; |
|
| 1085 | - } |
|
| 1086 | - |
|
| 1087 | - /** |
|
| 1088 | - * Verify the password of a public share |
|
| 1089 | - * |
|
| 1090 | - * @param \OCP\Share\IShare $share |
|
| 1091 | - * @param string $password |
|
| 1092 | - * @return bool |
|
| 1093 | - */ |
|
| 1094 | - public function checkPassword(\OCP\Share\IShare $share, $password) { |
|
| 1095 | - if ($share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK) { |
|
| 1096 | - //TODO maybe exception? |
|
| 1097 | - return false; |
|
| 1098 | - } |
|
| 1099 | - |
|
| 1100 | - if ($password === null || $share->getPassword() === null) { |
|
| 1101 | - return false; |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - $newHash = ''; |
|
| 1105 | - if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) { |
|
| 1106 | - return false; |
|
| 1107 | - } |
|
| 1108 | - |
|
| 1109 | - if (!empty($newHash)) { |
|
| 1110 | - $share->setPassword($newHash); |
|
| 1111 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 1112 | - $provider->update($share); |
|
| 1113 | - } |
|
| 1114 | - |
|
| 1115 | - return true; |
|
| 1116 | - } |
|
| 1117 | - |
|
| 1118 | - /** |
|
| 1119 | - * @inheritdoc |
|
| 1120 | - */ |
|
| 1121 | - public function userDeleted($uid) { |
|
| 1122 | - $types = [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE, \OCP\Share::SHARE_TYPE_EMAIL]; |
|
| 1123 | - |
|
| 1124 | - foreach ($types as $type) { |
|
| 1125 | - try { |
|
| 1126 | - $provider = $this->factory->getProviderForType($type); |
|
| 1127 | - } catch (ProviderException $e) { |
|
| 1128 | - continue; |
|
| 1129 | - } |
|
| 1130 | - $provider->userDeleted($uid, $type); |
|
| 1131 | - } |
|
| 1132 | - } |
|
| 1133 | - |
|
| 1134 | - /** |
|
| 1135 | - * @inheritdoc |
|
| 1136 | - */ |
|
| 1137 | - public function groupDeleted($gid) { |
|
| 1138 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
| 1139 | - $provider->groupDeleted($gid); |
|
| 1140 | - } |
|
| 1141 | - |
|
| 1142 | - /** |
|
| 1143 | - * @inheritdoc |
|
| 1144 | - */ |
|
| 1145 | - public function userDeletedFromGroup($uid, $gid) { |
|
| 1146 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
| 1147 | - $provider->userDeletedFromGroup($uid, $gid); |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - /** |
|
| 1151 | - * Get access list to a path. This means |
|
| 1152 | - * all the users that can access a given path. |
|
| 1153 | - * |
|
| 1154 | - * Consider: |
|
| 1155 | - * -root |
|
| 1156 | - * |-folder1 |
|
| 1157 | - * |-folder2 |
|
| 1158 | - * |-fileA |
|
| 1159 | - * |
|
| 1160 | - * fileA is shared with user1 |
|
| 1161 | - * folder2 is shared with group2 (user4 is a member of group2) |
|
| 1162 | - * folder1 is shared with user2 |
|
| 1163 | - * |
|
| 1164 | - * Then the access list will to '/folder1/folder2/fileA' is: |
|
| 1165 | - * [ |
|
| 1166 | - * users => ['user1' => ['node_id' => 42, 'node_path' => '/path'], 'user2' => [...]], |
|
| 1167 | - * remote => ['user1' => ['node_id' => 42, 'node_path' => '/path'], 'user2' => [...]], |
|
| 1168 | - * public => bool |
|
| 1169 | - * mail => bool |
|
| 1170 | - * ] |
|
| 1171 | - * |
|
| 1172 | - * This is required for encryption/activity |
|
| 1173 | - * |
|
| 1174 | - * @param \OCP\Files\Node $path |
|
| 1175 | - * @param bool $recursive Should we check all parent folders as well |
|
| 1176 | - * @param bool $currentAccess Should the user have currently access to the file |
|
| 1177 | - * @return array |
|
| 1178 | - */ |
|
| 1179 | - public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false) { |
|
| 1180 | - $owner = $path->getOwner()->getUID(); |
|
| 1181 | - |
|
| 1182 | - $al = ['users' => [], 'remote' => [], 'public' => false]; |
|
| 1183 | - if (!$this->userManager->userExists($owner)) { |
|
| 1184 | - return $al; |
|
| 1185 | - } |
|
| 1186 | - |
|
| 1187 | - //Get node for the owner |
|
| 1188 | - $userFolder = $this->rootFolder->getUserFolder($owner); |
|
| 1189 | - if (!$userFolder->isSubNode($path)) { |
|
| 1190 | - $path = $userFolder->getById($path->getId())[0]; |
|
| 1191 | - } |
|
| 1192 | - |
|
| 1193 | - $providers = $this->factory->getAllProviders(); |
|
| 1194 | - |
|
| 1195 | - /** @var Node[] $nodes */ |
|
| 1196 | - $nodes = []; |
|
| 1197 | - |
|
| 1198 | - $ownerPath = $path->getPath(); |
|
| 1199 | - list(,,,$ownerPath) = explode('/', $ownerPath, 4); |
|
| 1200 | - $al['users'][$owner] = [ |
|
| 1201 | - 'node_id' => $path->getId(), |
|
| 1202 | - 'node_path' => '/' . $ownerPath, |
|
| 1203 | - ]; |
|
| 1204 | - |
|
| 1205 | - // Collect all the shares |
|
| 1206 | - while ($path->getPath() !== $userFolder->getPath()) { |
|
| 1207 | - $nodes[] = $path; |
|
| 1208 | - if (!$recursive) { |
|
| 1209 | - break; |
|
| 1210 | - } |
|
| 1211 | - $path = $path->getParent(); |
|
| 1212 | - } |
|
| 1213 | - |
|
| 1214 | - foreach ($providers as $provider) { |
|
| 1215 | - $tmp = $provider->getAccessList($nodes, $currentAccess); |
|
| 1216 | - |
|
| 1217 | - foreach ($tmp as $k => $v) { |
|
| 1218 | - if (isset($al[$k])) { |
|
| 1219 | - if (is_array($al[$k])) { |
|
| 1220 | - $al[$k] = array_merge($al[$k], $v); |
|
| 1221 | - } else { |
|
| 1222 | - $al[$k] = $al[$k] || $v; |
|
| 1223 | - } |
|
| 1224 | - } else { |
|
| 1225 | - $al[$k] = $v; |
|
| 1226 | - } |
|
| 1227 | - } |
|
| 1228 | - } |
|
| 1229 | - |
|
| 1230 | - return $al; |
|
| 1231 | - } |
|
| 1232 | - |
|
| 1233 | - /** |
|
| 1234 | - * Create a new share |
|
| 1235 | - * @return \OCP\Share\IShare; |
|
| 1236 | - */ |
|
| 1237 | - public function newShare() { |
|
| 1238 | - return new \OC\Share20\Share($this->rootFolder, $this->userManager); |
|
| 1239 | - } |
|
| 1240 | - |
|
| 1241 | - /** |
|
| 1242 | - * Is the share API enabled |
|
| 1243 | - * |
|
| 1244 | - * @return bool |
|
| 1245 | - */ |
|
| 1246 | - public function shareApiEnabled() { |
|
| 1247 | - return $this->config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes'; |
|
| 1248 | - } |
|
| 1249 | - |
|
| 1250 | - /** |
|
| 1251 | - * Is public link sharing enabled |
|
| 1252 | - * |
|
| 1253 | - * @return bool |
|
| 1254 | - */ |
|
| 1255 | - public function shareApiAllowLinks() { |
|
| 1256 | - return $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes'; |
|
| 1257 | - } |
|
| 1258 | - |
|
| 1259 | - /** |
|
| 1260 | - * Is password on public link requires |
|
| 1261 | - * |
|
| 1262 | - * @return bool |
|
| 1263 | - */ |
|
| 1264 | - public function shareApiLinkEnforcePassword() { |
|
| 1265 | - return $this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'; |
|
| 1266 | - } |
|
| 1267 | - |
|
| 1268 | - /** |
|
| 1269 | - * Is default expire date enabled |
|
| 1270 | - * |
|
| 1271 | - * @return bool |
|
| 1272 | - */ |
|
| 1273 | - public function shareApiLinkDefaultExpireDate() { |
|
| 1274 | - return $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
| 1275 | - } |
|
| 1276 | - |
|
| 1277 | - /** |
|
| 1278 | - * Is default expire date enforced |
|
| 1279 | - *` |
|
| 1280 | - * @return bool |
|
| 1281 | - */ |
|
| 1282 | - public function shareApiLinkDefaultExpireDateEnforced() { |
|
| 1283 | - return $this->shareApiLinkDefaultExpireDate() && |
|
| 1284 | - $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
| 1285 | - } |
|
| 1286 | - |
|
| 1287 | - /** |
|
| 1288 | - * Number of default expire days |
|
| 1289 | - *shareApiLinkAllowPublicUpload |
|
| 1290 | - * @return int |
|
| 1291 | - */ |
|
| 1292 | - public function shareApiLinkDefaultExpireDays() { |
|
| 1293 | - return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
| 1294 | - } |
|
| 1295 | - |
|
| 1296 | - /** |
|
| 1297 | - * Allow public upload on link shares |
|
| 1298 | - * |
|
| 1299 | - * @return bool |
|
| 1300 | - */ |
|
| 1301 | - public function shareApiLinkAllowPublicUpload() { |
|
| 1302 | - return $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes'; |
|
| 1303 | - } |
|
| 1304 | - |
|
| 1305 | - /** |
|
| 1306 | - * check if user can only share with group members |
|
| 1307 | - * @return bool |
|
| 1308 | - */ |
|
| 1309 | - public function shareWithGroupMembersOnly() { |
|
| 1310 | - return $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
| 1311 | - } |
|
| 1312 | - |
|
| 1313 | - /** |
|
| 1314 | - * Check if users can share with groups |
|
| 1315 | - * @return bool |
|
| 1316 | - */ |
|
| 1317 | - public function allowGroupSharing() { |
|
| 1318 | - return $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
| 1319 | - } |
|
| 1320 | - |
|
| 1321 | - /** |
|
| 1322 | - * Copied from \OC_Util::isSharingDisabledForUser |
|
| 1323 | - * |
|
| 1324 | - * TODO: Deprecate fuction from OC_Util |
|
| 1325 | - * |
|
| 1326 | - * @param string $userId |
|
| 1327 | - * @return bool |
|
| 1328 | - */ |
|
| 1329 | - public function sharingDisabledForUser($userId) { |
|
| 1330 | - if ($userId === null) { |
|
| 1331 | - return false; |
|
| 1332 | - } |
|
| 1333 | - |
|
| 1334 | - if (isset($this->sharingDisabledForUsersCache[$userId])) { |
|
| 1335 | - return $this->sharingDisabledForUsersCache[$userId]; |
|
| 1336 | - } |
|
| 1337 | - |
|
| 1338 | - if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
| 1339 | - $groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 1340 | - $excludedGroups = json_decode($groupsList); |
|
| 1341 | - if (is_null($excludedGroups)) { |
|
| 1342 | - $excludedGroups = explode(',', $groupsList); |
|
| 1343 | - $newValue = json_encode($excludedGroups); |
|
| 1344 | - $this->config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
| 1345 | - } |
|
| 1346 | - $user = $this->userManager->get($userId); |
|
| 1347 | - $usersGroups = $this->groupManager->getUserGroupIds($user); |
|
| 1348 | - if (!empty($usersGroups)) { |
|
| 1349 | - $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
| 1350 | - // if the user is only in groups which are disabled for sharing then |
|
| 1351 | - // sharing is also disabled for the user |
|
| 1352 | - if (empty($remainingGroups)) { |
|
| 1353 | - $this->sharingDisabledForUsersCache[$userId] = true; |
|
| 1354 | - return true; |
|
| 1355 | - } |
|
| 1356 | - } |
|
| 1357 | - } |
|
| 1358 | - |
|
| 1359 | - $this->sharingDisabledForUsersCache[$userId] = false; |
|
| 1360 | - return false; |
|
| 1361 | - } |
|
| 1362 | - |
|
| 1363 | - /** |
|
| 1364 | - * @inheritdoc |
|
| 1365 | - */ |
|
| 1366 | - public function outgoingServer2ServerSharesAllowed() { |
|
| 1367 | - return $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
| 1368 | - } |
|
| 1369 | - |
|
| 1370 | - /** |
|
| 1371 | - * @inheritdoc |
|
| 1372 | - */ |
|
| 1373 | - public function shareProviderExists($shareType) { |
|
| 1374 | - try { |
|
| 1375 | - $this->factory->getProviderForType($shareType); |
|
| 1376 | - } catch (ProviderException $e) { |
|
| 1377 | - return false; |
|
| 1378 | - } |
|
| 1379 | - |
|
| 1380 | - return true; |
|
| 1381 | - } |
|
| 1079 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK && |
|
| 1080 | + !$this->shareApiLinkAllowPublicUpload()) { |
|
| 1081 | + $share->setPermissions($share->getPermissions() & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)); |
|
| 1082 | + } |
|
| 1083 | + |
|
| 1084 | + return $share; |
|
| 1085 | + } |
|
| 1086 | + |
|
| 1087 | + /** |
|
| 1088 | + * Verify the password of a public share |
|
| 1089 | + * |
|
| 1090 | + * @param \OCP\Share\IShare $share |
|
| 1091 | + * @param string $password |
|
| 1092 | + * @return bool |
|
| 1093 | + */ |
|
| 1094 | + public function checkPassword(\OCP\Share\IShare $share, $password) { |
|
| 1095 | + if ($share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK) { |
|
| 1096 | + //TODO maybe exception? |
|
| 1097 | + return false; |
|
| 1098 | + } |
|
| 1099 | + |
|
| 1100 | + if ($password === null || $share->getPassword() === null) { |
|
| 1101 | + return false; |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + $newHash = ''; |
|
| 1105 | + if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) { |
|
| 1106 | + return false; |
|
| 1107 | + } |
|
| 1108 | + |
|
| 1109 | + if (!empty($newHash)) { |
|
| 1110 | + $share->setPassword($newHash); |
|
| 1111 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 1112 | + $provider->update($share); |
|
| 1113 | + } |
|
| 1114 | + |
|
| 1115 | + return true; |
|
| 1116 | + } |
|
| 1117 | + |
|
| 1118 | + /** |
|
| 1119 | + * @inheritdoc |
|
| 1120 | + */ |
|
| 1121 | + public function userDeleted($uid) { |
|
| 1122 | + $types = [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE, \OCP\Share::SHARE_TYPE_EMAIL]; |
|
| 1123 | + |
|
| 1124 | + foreach ($types as $type) { |
|
| 1125 | + try { |
|
| 1126 | + $provider = $this->factory->getProviderForType($type); |
|
| 1127 | + } catch (ProviderException $e) { |
|
| 1128 | + continue; |
|
| 1129 | + } |
|
| 1130 | + $provider->userDeleted($uid, $type); |
|
| 1131 | + } |
|
| 1132 | + } |
|
| 1133 | + |
|
| 1134 | + /** |
|
| 1135 | + * @inheritdoc |
|
| 1136 | + */ |
|
| 1137 | + public function groupDeleted($gid) { |
|
| 1138 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
| 1139 | + $provider->groupDeleted($gid); |
|
| 1140 | + } |
|
| 1141 | + |
|
| 1142 | + /** |
|
| 1143 | + * @inheritdoc |
|
| 1144 | + */ |
|
| 1145 | + public function userDeletedFromGroup($uid, $gid) { |
|
| 1146 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
| 1147 | + $provider->userDeletedFromGroup($uid, $gid); |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + /** |
|
| 1151 | + * Get access list to a path. This means |
|
| 1152 | + * all the users that can access a given path. |
|
| 1153 | + * |
|
| 1154 | + * Consider: |
|
| 1155 | + * -root |
|
| 1156 | + * |-folder1 |
|
| 1157 | + * |-folder2 |
|
| 1158 | + * |-fileA |
|
| 1159 | + * |
|
| 1160 | + * fileA is shared with user1 |
|
| 1161 | + * folder2 is shared with group2 (user4 is a member of group2) |
|
| 1162 | + * folder1 is shared with user2 |
|
| 1163 | + * |
|
| 1164 | + * Then the access list will to '/folder1/folder2/fileA' is: |
|
| 1165 | + * [ |
|
| 1166 | + * users => ['user1' => ['node_id' => 42, 'node_path' => '/path'], 'user2' => [...]], |
|
| 1167 | + * remote => ['user1' => ['node_id' => 42, 'node_path' => '/path'], 'user2' => [...]], |
|
| 1168 | + * public => bool |
|
| 1169 | + * mail => bool |
|
| 1170 | + * ] |
|
| 1171 | + * |
|
| 1172 | + * This is required for encryption/activity |
|
| 1173 | + * |
|
| 1174 | + * @param \OCP\Files\Node $path |
|
| 1175 | + * @param bool $recursive Should we check all parent folders as well |
|
| 1176 | + * @param bool $currentAccess Should the user have currently access to the file |
|
| 1177 | + * @return array |
|
| 1178 | + */ |
|
| 1179 | + public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false) { |
|
| 1180 | + $owner = $path->getOwner()->getUID(); |
|
| 1181 | + |
|
| 1182 | + $al = ['users' => [], 'remote' => [], 'public' => false]; |
|
| 1183 | + if (!$this->userManager->userExists($owner)) { |
|
| 1184 | + return $al; |
|
| 1185 | + } |
|
| 1186 | + |
|
| 1187 | + //Get node for the owner |
|
| 1188 | + $userFolder = $this->rootFolder->getUserFolder($owner); |
|
| 1189 | + if (!$userFolder->isSubNode($path)) { |
|
| 1190 | + $path = $userFolder->getById($path->getId())[0]; |
|
| 1191 | + } |
|
| 1192 | + |
|
| 1193 | + $providers = $this->factory->getAllProviders(); |
|
| 1194 | + |
|
| 1195 | + /** @var Node[] $nodes */ |
|
| 1196 | + $nodes = []; |
|
| 1197 | + |
|
| 1198 | + $ownerPath = $path->getPath(); |
|
| 1199 | + list(,,,$ownerPath) = explode('/', $ownerPath, 4); |
|
| 1200 | + $al['users'][$owner] = [ |
|
| 1201 | + 'node_id' => $path->getId(), |
|
| 1202 | + 'node_path' => '/' . $ownerPath, |
|
| 1203 | + ]; |
|
| 1204 | + |
|
| 1205 | + // Collect all the shares |
|
| 1206 | + while ($path->getPath() !== $userFolder->getPath()) { |
|
| 1207 | + $nodes[] = $path; |
|
| 1208 | + if (!$recursive) { |
|
| 1209 | + break; |
|
| 1210 | + } |
|
| 1211 | + $path = $path->getParent(); |
|
| 1212 | + } |
|
| 1213 | + |
|
| 1214 | + foreach ($providers as $provider) { |
|
| 1215 | + $tmp = $provider->getAccessList($nodes, $currentAccess); |
|
| 1216 | + |
|
| 1217 | + foreach ($tmp as $k => $v) { |
|
| 1218 | + if (isset($al[$k])) { |
|
| 1219 | + if (is_array($al[$k])) { |
|
| 1220 | + $al[$k] = array_merge($al[$k], $v); |
|
| 1221 | + } else { |
|
| 1222 | + $al[$k] = $al[$k] || $v; |
|
| 1223 | + } |
|
| 1224 | + } else { |
|
| 1225 | + $al[$k] = $v; |
|
| 1226 | + } |
|
| 1227 | + } |
|
| 1228 | + } |
|
| 1229 | + |
|
| 1230 | + return $al; |
|
| 1231 | + } |
|
| 1232 | + |
|
| 1233 | + /** |
|
| 1234 | + * Create a new share |
|
| 1235 | + * @return \OCP\Share\IShare; |
|
| 1236 | + */ |
|
| 1237 | + public function newShare() { |
|
| 1238 | + return new \OC\Share20\Share($this->rootFolder, $this->userManager); |
|
| 1239 | + } |
|
| 1240 | + |
|
| 1241 | + /** |
|
| 1242 | + * Is the share API enabled |
|
| 1243 | + * |
|
| 1244 | + * @return bool |
|
| 1245 | + */ |
|
| 1246 | + public function shareApiEnabled() { |
|
| 1247 | + return $this->config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes'; |
|
| 1248 | + } |
|
| 1249 | + |
|
| 1250 | + /** |
|
| 1251 | + * Is public link sharing enabled |
|
| 1252 | + * |
|
| 1253 | + * @return bool |
|
| 1254 | + */ |
|
| 1255 | + public function shareApiAllowLinks() { |
|
| 1256 | + return $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes'; |
|
| 1257 | + } |
|
| 1258 | + |
|
| 1259 | + /** |
|
| 1260 | + * Is password on public link requires |
|
| 1261 | + * |
|
| 1262 | + * @return bool |
|
| 1263 | + */ |
|
| 1264 | + public function shareApiLinkEnforcePassword() { |
|
| 1265 | + return $this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'; |
|
| 1266 | + } |
|
| 1267 | + |
|
| 1268 | + /** |
|
| 1269 | + * Is default expire date enabled |
|
| 1270 | + * |
|
| 1271 | + * @return bool |
|
| 1272 | + */ |
|
| 1273 | + public function shareApiLinkDefaultExpireDate() { |
|
| 1274 | + return $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
| 1275 | + } |
|
| 1276 | + |
|
| 1277 | + /** |
|
| 1278 | + * Is default expire date enforced |
|
| 1279 | + *` |
|
| 1280 | + * @return bool |
|
| 1281 | + */ |
|
| 1282 | + public function shareApiLinkDefaultExpireDateEnforced() { |
|
| 1283 | + return $this->shareApiLinkDefaultExpireDate() && |
|
| 1284 | + $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
| 1285 | + } |
|
| 1286 | + |
|
| 1287 | + /** |
|
| 1288 | + * Number of default expire days |
|
| 1289 | + *shareApiLinkAllowPublicUpload |
|
| 1290 | + * @return int |
|
| 1291 | + */ |
|
| 1292 | + public function shareApiLinkDefaultExpireDays() { |
|
| 1293 | + return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
| 1294 | + } |
|
| 1295 | + |
|
| 1296 | + /** |
|
| 1297 | + * Allow public upload on link shares |
|
| 1298 | + * |
|
| 1299 | + * @return bool |
|
| 1300 | + */ |
|
| 1301 | + public function shareApiLinkAllowPublicUpload() { |
|
| 1302 | + return $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes'; |
|
| 1303 | + } |
|
| 1304 | + |
|
| 1305 | + /** |
|
| 1306 | + * check if user can only share with group members |
|
| 1307 | + * @return bool |
|
| 1308 | + */ |
|
| 1309 | + public function shareWithGroupMembersOnly() { |
|
| 1310 | + return $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
| 1311 | + } |
|
| 1312 | + |
|
| 1313 | + /** |
|
| 1314 | + * Check if users can share with groups |
|
| 1315 | + * @return bool |
|
| 1316 | + */ |
|
| 1317 | + public function allowGroupSharing() { |
|
| 1318 | + return $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
| 1319 | + } |
|
| 1320 | + |
|
| 1321 | + /** |
|
| 1322 | + * Copied from \OC_Util::isSharingDisabledForUser |
|
| 1323 | + * |
|
| 1324 | + * TODO: Deprecate fuction from OC_Util |
|
| 1325 | + * |
|
| 1326 | + * @param string $userId |
|
| 1327 | + * @return bool |
|
| 1328 | + */ |
|
| 1329 | + public function sharingDisabledForUser($userId) { |
|
| 1330 | + if ($userId === null) { |
|
| 1331 | + return false; |
|
| 1332 | + } |
|
| 1333 | + |
|
| 1334 | + if (isset($this->sharingDisabledForUsersCache[$userId])) { |
|
| 1335 | + return $this->sharingDisabledForUsersCache[$userId]; |
|
| 1336 | + } |
|
| 1337 | + |
|
| 1338 | + if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
| 1339 | + $groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 1340 | + $excludedGroups = json_decode($groupsList); |
|
| 1341 | + if (is_null($excludedGroups)) { |
|
| 1342 | + $excludedGroups = explode(',', $groupsList); |
|
| 1343 | + $newValue = json_encode($excludedGroups); |
|
| 1344 | + $this->config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
| 1345 | + } |
|
| 1346 | + $user = $this->userManager->get($userId); |
|
| 1347 | + $usersGroups = $this->groupManager->getUserGroupIds($user); |
|
| 1348 | + if (!empty($usersGroups)) { |
|
| 1349 | + $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
| 1350 | + // if the user is only in groups which are disabled for sharing then |
|
| 1351 | + // sharing is also disabled for the user |
|
| 1352 | + if (empty($remainingGroups)) { |
|
| 1353 | + $this->sharingDisabledForUsersCache[$userId] = true; |
|
| 1354 | + return true; |
|
| 1355 | + } |
|
| 1356 | + } |
|
| 1357 | + } |
|
| 1358 | + |
|
| 1359 | + $this->sharingDisabledForUsersCache[$userId] = false; |
|
| 1360 | + return false; |
|
| 1361 | + } |
|
| 1362 | + |
|
| 1363 | + /** |
|
| 1364 | + * @inheritdoc |
|
| 1365 | + */ |
|
| 1366 | + public function outgoingServer2ServerSharesAllowed() { |
|
| 1367 | + return $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
| 1368 | + } |
|
| 1369 | + |
|
| 1370 | + /** |
|
| 1371 | + * @inheritdoc |
|
| 1372 | + */ |
|
| 1373 | + public function shareProviderExists($shareType) { |
|
| 1374 | + try { |
|
| 1375 | + $this->factory->getProviderForType($shareType); |
|
| 1376 | + } catch (ProviderException $e) { |
|
| 1377 | + return false; |
|
| 1378 | + } |
|
| 1379 | + |
|
| 1380 | + return true; |
|
| 1381 | + } |
|
| 1382 | 1382 | |
| 1383 | 1383 | } |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | |
| 320 | 320 | if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) { |
| 321 | 321 | $expirationDate = new \DateTime(); |
| 322 | - $expirationDate->setTime(0,0,0); |
|
| 322 | + $expirationDate->setTime(0, 0, 0); |
|
| 323 | 323 | $expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); |
| 324 | 324 | } |
| 325 | 325 | |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | |
| 332 | 332 | $date = new \DateTime(); |
| 333 | 333 | $date->setTime(0, 0, 0); |
| 334 | - $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); |
|
| 334 | + $date->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); |
|
| 335 | 335 | if ($date < $expirationDate) { |
| 336 | 336 | $message = $this->l->t('Cannot set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]); |
| 337 | 337 | throw new GenericShareException($message, $message, 404); |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | */ |
| 385 | 385 | $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_USER); |
| 386 | 386 | $existingShares = $provider->getSharesByPath($share->getNode()); |
| 387 | - foreach($existingShares as $existingShare) { |
|
| 387 | + foreach ($existingShares as $existingShare) { |
|
| 388 | 388 | // Ignore if it is the same share |
| 389 | 389 | try { |
| 390 | 390 | if ($existingShare->getFullId() === $share->getFullId()) { |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | */ |
| 442 | 442 | $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
| 443 | 443 | $existingShares = $provider->getSharesByPath($share->getNode()); |
| 444 | - foreach($existingShares as $existingShare) { |
|
| 444 | + foreach ($existingShares as $existingShare) { |
|
| 445 | 445 | try { |
| 446 | 446 | if ($existingShare->getFullId() === $share->getFullId()) { |
| 447 | 447 | continue; |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | // Make sure that we do not share a path that contains a shared mountpoint |
| 511 | 511 | if ($path instanceof \OCP\Files\Folder) { |
| 512 | 512 | $mounts = $this->mountManager->findIn($path->getPath()); |
| 513 | - foreach($mounts as $mount) { |
|
| 513 | + foreach ($mounts as $mount) { |
|
| 514 | 514 | if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
| 515 | 515 | throw new \InvalidArgumentException('Path contains files shared with you'); |
| 516 | 516 | } |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | $storage = $share->getNode()->getStorage(); |
| 559 | 559 | if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
| 560 | 560 | $parent = $share->getNode()->getParent(); |
| 561 | - while($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
| 561 | + while ($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
| 562 | 562 | $parent = $parent->getParent(); |
| 563 | 563 | } |
| 564 | 564 | $share->setShareOwner($parent->getOwner()->getUID()); |
@@ -615,7 +615,7 @@ discard block |
||
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | // Generate the target |
| 618 | - $target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getNode()->getName(); |
|
| 618 | + $target = $this->config->getSystemValue('share_folder', '/').'/'.$share->getNode()->getName(); |
|
| 619 | 619 | $target = \OC\Files\Filesystem::normalizePath($target); |
| 620 | 620 | $share->setTarget($target); |
| 621 | 621 | |
@@ -843,7 +843,7 @@ discard block |
||
| 843 | 843 | * @param string $recipientId |
| 844 | 844 | */ |
| 845 | 845 | public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) { |
| 846 | - list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
| 846 | + list($providerId,) = $this->splitFullId($share->getFullId()); |
|
| 847 | 847 | $provider = $this->factory->getProvider($providerId); |
| 848 | 848 | |
| 849 | 849 | $provider->deleteFromSelf($share, $recipientId); |
@@ -864,7 +864,7 @@ discard block |
||
| 864 | 864 | if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
| 865 | 865 | $sharedWith = $this->groupManager->get($share->getSharedWith()); |
| 866 | 866 | if (is_null($sharedWith)) { |
| 867 | - throw new \InvalidArgumentException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
| 867 | + throw new \InvalidArgumentException('Group "'.$share->getSharedWith().'" does not exist'); |
|
| 868 | 868 | } |
| 869 | 869 | $recipient = $this->userManager->get($recipientId); |
| 870 | 870 | if (!$sharedWith->inGroup($recipient)) { |
@@ -872,7 +872,7 @@ discard block |
||
| 872 | 872 | } |
| 873 | 873 | } |
| 874 | 874 | |
| 875 | - list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
| 875 | + list($providerId,) = $this->splitFullId($share->getFullId()); |
|
| 876 | 876 | $provider = $this->factory->getProvider($providerId); |
| 877 | 877 | |
| 878 | 878 | $provider->move($share, $recipientId); |
@@ -920,7 +920,7 @@ discard block |
||
| 920 | 920 | $shares2 = []; |
| 921 | 921 | $today = new \DateTime(); |
| 922 | 922 | |
| 923 | - while(true) { |
|
| 923 | + while (true) { |
|
| 924 | 924 | $added = 0; |
| 925 | 925 | foreach ($shares as $share) { |
| 926 | 926 | // Check if the share is expired and if so delete it |
@@ -1019,7 +1019,7 @@ discard block |
||
| 1019 | 1019 | * |
| 1020 | 1020 | * @return Share[] |
| 1021 | 1021 | */ |
| 1022 | - public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) { |
|
| 1022 | + public function getSharesByPath(\OCP\Files\Node $path, $page = 0, $perPage = 50) { |
|
| 1023 | 1023 | return []; |
| 1024 | 1024 | } |
| 1025 | 1025 | |
@@ -1034,7 +1034,7 @@ discard block |
||
| 1034 | 1034 | public function getShareByToken($token) { |
| 1035 | 1035 | $share = null; |
| 1036 | 1036 | try { |
| 1037 | - if($this->shareApiAllowLinks()) { |
|
| 1037 | + if ($this->shareApiAllowLinks()) { |
|
| 1038 | 1038 | $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_LINK); |
| 1039 | 1039 | $share = $provider->getShareByToken($token); |
| 1040 | 1040 | } |
@@ -1199,7 +1199,7 @@ discard block |
||
| 1199 | 1199 | list(,,,$ownerPath) = explode('/', $ownerPath, 4); |
| 1200 | 1200 | $al['users'][$owner] = [ |
| 1201 | 1201 | 'node_id' => $path->getId(), |
| 1202 | - 'node_path' => '/' . $ownerPath, |
|
| 1202 | + 'node_path' => '/'.$ownerPath, |
|
| 1203 | 1203 | ]; |
| 1204 | 1204 | |
| 1205 | 1205 | // Collect all the shares |
@@ -1290,7 +1290,7 @@ discard block |
||
| 1290 | 1290 | * @return int |
| 1291 | 1291 | */ |
| 1292 | 1292 | public function shareApiLinkDefaultExpireDays() { |
| 1293 | - return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
| 1293 | + return (int) $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
| 1294 | 1294 | } |
| 1295 | 1295 | |
| 1296 | 1296 | /** |
@@ -47,1132 +47,1132 @@ |
||
| 47 | 47 | */ |
| 48 | 48 | class DefaultShareProvider implements IShareProvider { |
| 49 | 49 | |
| 50 | - // Special share type for user modified group shares |
|
| 51 | - const SHARE_TYPE_USERGROUP = 2; |
|
| 52 | - |
|
| 53 | - /** @var IDBConnection */ |
|
| 54 | - private $dbConn; |
|
| 55 | - |
|
| 56 | - /** @var IUserManager */ |
|
| 57 | - private $userManager; |
|
| 58 | - |
|
| 59 | - /** @var IGroupManager */ |
|
| 60 | - private $groupManager; |
|
| 61 | - |
|
| 62 | - /** @var IRootFolder */ |
|
| 63 | - private $rootFolder; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * DefaultShareProvider constructor. |
|
| 67 | - * |
|
| 68 | - * @param IDBConnection $connection |
|
| 69 | - * @param IUserManager $userManager |
|
| 70 | - * @param IGroupManager $groupManager |
|
| 71 | - * @param IRootFolder $rootFolder |
|
| 72 | - */ |
|
| 73 | - public function __construct( |
|
| 74 | - IDBConnection $connection, |
|
| 75 | - IUserManager $userManager, |
|
| 76 | - IGroupManager $groupManager, |
|
| 77 | - IRootFolder $rootFolder) { |
|
| 78 | - $this->dbConn = $connection; |
|
| 79 | - $this->userManager = $userManager; |
|
| 80 | - $this->groupManager = $groupManager; |
|
| 81 | - $this->rootFolder = $rootFolder; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Return the identifier of this provider. |
|
| 86 | - * |
|
| 87 | - * @return string Containing only [a-zA-Z0-9] |
|
| 88 | - */ |
|
| 89 | - public function identifier() { |
|
| 90 | - return 'ocinternal'; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Share a path |
|
| 95 | - * |
|
| 96 | - * @param \OCP\Share\IShare $share |
|
| 97 | - * @return \OCP\Share\IShare The share object |
|
| 98 | - * @throws ShareNotFound |
|
| 99 | - * @throws \Exception |
|
| 100 | - */ |
|
| 101 | - public function create(\OCP\Share\IShare $share) { |
|
| 102 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 103 | - |
|
| 104 | - $qb->insert('share'); |
|
| 105 | - $qb->setValue('share_type', $qb->createNamedParameter($share->getShareType())); |
|
| 106 | - |
|
| 107 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 108 | - //Set the UID of the user we share with |
|
| 109 | - $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); |
|
| 110 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 111 | - //Set the GID of the group we share with |
|
| 112 | - $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); |
|
| 113 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 114 | - //Set the token of the share |
|
| 115 | - $qb->setValue('token', $qb->createNamedParameter($share->getToken())); |
|
| 116 | - |
|
| 117 | - //If a password is set store it |
|
| 118 | - if ($share->getPassword() !== null) { |
|
| 119 | - $qb->setValue('share_with', $qb->createNamedParameter($share->getPassword())); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - //If an expiration date is set store it |
|
| 123 | - if ($share->getExpirationDate() !== null) { |
|
| 124 | - $qb->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), 'datetime')); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - if (method_exists($share, 'getParent')) { |
|
| 128 | - $qb->setValue('parent', $qb->createNamedParameter($share->getParent())); |
|
| 129 | - } |
|
| 130 | - } else { |
|
| 131 | - throw new \Exception('invalid share type!'); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - // Set what is shares |
|
| 135 | - $qb->setValue('item_type', $qb->createParameter('itemType')); |
|
| 136 | - if ($share->getNode() instanceof \OCP\Files\File) { |
|
| 137 | - $qb->setParameter('itemType', 'file'); |
|
| 138 | - } else { |
|
| 139 | - $qb->setParameter('itemType', 'folder'); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - // Set the file id |
|
| 143 | - $qb->setValue('item_source', $qb->createNamedParameter($share->getNode()->getId())); |
|
| 144 | - $qb->setValue('file_source', $qb->createNamedParameter($share->getNode()->getId())); |
|
| 145 | - |
|
| 146 | - // set the permissions |
|
| 147 | - $qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions())); |
|
| 148 | - |
|
| 149 | - // Set who created this share |
|
| 150 | - $qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy())); |
|
| 151 | - |
|
| 152 | - // Set who is the owner of this file/folder (and this the owner of the share) |
|
| 153 | - $qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner())); |
|
| 154 | - |
|
| 155 | - // Set the file target |
|
| 156 | - $qb->setValue('file_target', $qb->createNamedParameter($share->getTarget())); |
|
| 157 | - |
|
| 158 | - // Set the time this share was created |
|
| 159 | - $qb->setValue('stime', $qb->createNamedParameter(time())); |
|
| 160 | - |
|
| 161 | - // insert the data and fetch the id of the share |
|
| 162 | - $this->dbConn->beginTransaction(); |
|
| 163 | - $qb->execute(); |
|
| 164 | - $id = $this->dbConn->lastInsertId('*PREFIX*share'); |
|
| 165 | - |
|
| 166 | - // Now fetch the inserted share and create a complete share object |
|
| 167 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 168 | - $qb->select('*') |
|
| 169 | - ->from('share') |
|
| 170 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
| 171 | - |
|
| 172 | - $cursor = $qb->execute(); |
|
| 173 | - $data = $cursor->fetch(); |
|
| 174 | - $this->dbConn->commit(); |
|
| 175 | - $cursor->closeCursor(); |
|
| 176 | - |
|
| 177 | - if ($data === false) { |
|
| 178 | - throw new ShareNotFound(); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $share = $this->createShare($data); |
|
| 182 | - return $share; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Update a share |
|
| 187 | - * |
|
| 188 | - * @param \OCP\Share\IShare $share |
|
| 189 | - * @return \OCP\Share\IShare The share object |
|
| 190 | - */ |
|
| 191 | - public function update(\OCP\Share\IShare $share) { |
|
| 192 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 193 | - /* |
|
| 50 | + // Special share type for user modified group shares |
|
| 51 | + const SHARE_TYPE_USERGROUP = 2; |
|
| 52 | + |
|
| 53 | + /** @var IDBConnection */ |
|
| 54 | + private $dbConn; |
|
| 55 | + |
|
| 56 | + /** @var IUserManager */ |
|
| 57 | + private $userManager; |
|
| 58 | + |
|
| 59 | + /** @var IGroupManager */ |
|
| 60 | + private $groupManager; |
|
| 61 | + |
|
| 62 | + /** @var IRootFolder */ |
|
| 63 | + private $rootFolder; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * DefaultShareProvider constructor. |
|
| 67 | + * |
|
| 68 | + * @param IDBConnection $connection |
|
| 69 | + * @param IUserManager $userManager |
|
| 70 | + * @param IGroupManager $groupManager |
|
| 71 | + * @param IRootFolder $rootFolder |
|
| 72 | + */ |
|
| 73 | + public function __construct( |
|
| 74 | + IDBConnection $connection, |
|
| 75 | + IUserManager $userManager, |
|
| 76 | + IGroupManager $groupManager, |
|
| 77 | + IRootFolder $rootFolder) { |
|
| 78 | + $this->dbConn = $connection; |
|
| 79 | + $this->userManager = $userManager; |
|
| 80 | + $this->groupManager = $groupManager; |
|
| 81 | + $this->rootFolder = $rootFolder; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Return the identifier of this provider. |
|
| 86 | + * |
|
| 87 | + * @return string Containing only [a-zA-Z0-9] |
|
| 88 | + */ |
|
| 89 | + public function identifier() { |
|
| 90 | + return 'ocinternal'; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Share a path |
|
| 95 | + * |
|
| 96 | + * @param \OCP\Share\IShare $share |
|
| 97 | + * @return \OCP\Share\IShare The share object |
|
| 98 | + * @throws ShareNotFound |
|
| 99 | + * @throws \Exception |
|
| 100 | + */ |
|
| 101 | + public function create(\OCP\Share\IShare $share) { |
|
| 102 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 103 | + |
|
| 104 | + $qb->insert('share'); |
|
| 105 | + $qb->setValue('share_type', $qb->createNamedParameter($share->getShareType())); |
|
| 106 | + |
|
| 107 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 108 | + //Set the UID of the user we share with |
|
| 109 | + $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); |
|
| 110 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 111 | + //Set the GID of the group we share with |
|
| 112 | + $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); |
|
| 113 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 114 | + //Set the token of the share |
|
| 115 | + $qb->setValue('token', $qb->createNamedParameter($share->getToken())); |
|
| 116 | + |
|
| 117 | + //If a password is set store it |
|
| 118 | + if ($share->getPassword() !== null) { |
|
| 119 | + $qb->setValue('share_with', $qb->createNamedParameter($share->getPassword())); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + //If an expiration date is set store it |
|
| 123 | + if ($share->getExpirationDate() !== null) { |
|
| 124 | + $qb->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), 'datetime')); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + if (method_exists($share, 'getParent')) { |
|
| 128 | + $qb->setValue('parent', $qb->createNamedParameter($share->getParent())); |
|
| 129 | + } |
|
| 130 | + } else { |
|
| 131 | + throw new \Exception('invalid share type!'); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + // Set what is shares |
|
| 135 | + $qb->setValue('item_type', $qb->createParameter('itemType')); |
|
| 136 | + if ($share->getNode() instanceof \OCP\Files\File) { |
|
| 137 | + $qb->setParameter('itemType', 'file'); |
|
| 138 | + } else { |
|
| 139 | + $qb->setParameter('itemType', 'folder'); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + // Set the file id |
|
| 143 | + $qb->setValue('item_source', $qb->createNamedParameter($share->getNode()->getId())); |
|
| 144 | + $qb->setValue('file_source', $qb->createNamedParameter($share->getNode()->getId())); |
|
| 145 | + |
|
| 146 | + // set the permissions |
|
| 147 | + $qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions())); |
|
| 148 | + |
|
| 149 | + // Set who created this share |
|
| 150 | + $qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy())); |
|
| 151 | + |
|
| 152 | + // Set who is the owner of this file/folder (and this the owner of the share) |
|
| 153 | + $qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner())); |
|
| 154 | + |
|
| 155 | + // Set the file target |
|
| 156 | + $qb->setValue('file_target', $qb->createNamedParameter($share->getTarget())); |
|
| 157 | + |
|
| 158 | + // Set the time this share was created |
|
| 159 | + $qb->setValue('stime', $qb->createNamedParameter(time())); |
|
| 160 | + |
|
| 161 | + // insert the data and fetch the id of the share |
|
| 162 | + $this->dbConn->beginTransaction(); |
|
| 163 | + $qb->execute(); |
|
| 164 | + $id = $this->dbConn->lastInsertId('*PREFIX*share'); |
|
| 165 | + |
|
| 166 | + // Now fetch the inserted share and create a complete share object |
|
| 167 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 168 | + $qb->select('*') |
|
| 169 | + ->from('share') |
|
| 170 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
| 171 | + |
|
| 172 | + $cursor = $qb->execute(); |
|
| 173 | + $data = $cursor->fetch(); |
|
| 174 | + $this->dbConn->commit(); |
|
| 175 | + $cursor->closeCursor(); |
|
| 176 | + |
|
| 177 | + if ($data === false) { |
|
| 178 | + throw new ShareNotFound(); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $share = $this->createShare($data); |
|
| 182 | + return $share; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Update a share |
|
| 187 | + * |
|
| 188 | + * @param \OCP\Share\IShare $share |
|
| 189 | + * @return \OCP\Share\IShare The share object |
|
| 190 | + */ |
|
| 191 | + public function update(\OCP\Share\IShare $share) { |
|
| 192 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 193 | + /* |
|
| 194 | 194 | * We allow updating the recipient on user shares. |
| 195 | 195 | */ |
| 196 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 197 | - $qb->update('share') |
|
| 198 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
| 199 | - ->set('share_with', $qb->createNamedParameter($share->getSharedWith())) |
|
| 200 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
| 201 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
| 202 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
| 203 | - ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
| 204 | - ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
| 205 | - ->execute(); |
|
| 206 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 207 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 208 | - $qb->update('share') |
|
| 209 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
| 210 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
| 211 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
| 212 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
| 213 | - ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
| 214 | - ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
| 215 | - ->execute(); |
|
| 216 | - |
|
| 217 | - /* |
|
| 196 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 197 | + $qb->update('share') |
|
| 198 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
| 199 | + ->set('share_with', $qb->createNamedParameter($share->getSharedWith())) |
|
| 200 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
| 201 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
| 202 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
| 203 | + ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
| 204 | + ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
| 205 | + ->execute(); |
|
| 206 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 207 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 208 | + $qb->update('share') |
|
| 209 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
| 210 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
| 211 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
| 212 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
| 213 | + ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
| 214 | + ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
| 215 | + ->execute(); |
|
| 216 | + |
|
| 217 | + /* |
|
| 218 | 218 | * Update all user defined group shares |
| 219 | 219 | */ |
| 220 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 221 | - $qb->update('share') |
|
| 222 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
| 223 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
| 224 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
| 225 | - ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
| 226 | - ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
| 227 | - ->execute(); |
|
| 228 | - |
|
| 229 | - /* |
|
| 220 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 221 | + $qb->update('share') |
|
| 222 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
| 223 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
| 224 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
| 225 | + ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
| 226 | + ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
| 227 | + ->execute(); |
|
| 228 | + |
|
| 229 | + /* |
|
| 230 | 230 | * Now update the permissions for all children that have not set it to 0 |
| 231 | 231 | */ |
| 232 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 233 | - $qb->update('share') |
|
| 234 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
| 235 | - ->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0))) |
|
| 236 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
| 237 | - ->execute(); |
|
| 238 | - |
|
| 239 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 240 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 241 | - $qb->update('share') |
|
| 242 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
| 243 | - ->set('share_with', $qb->createNamedParameter($share->getPassword())) |
|
| 244 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
| 245 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
| 246 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
| 247 | - ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
| 248 | - ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
| 249 | - ->set('token', $qb->createNamedParameter($share->getToken())) |
|
| 250 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
| 251 | - ->execute(); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - return $share; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * Get all children of this share |
|
| 259 | - * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
| 260 | - * |
|
| 261 | - * @param \OCP\Share\IShare $parent |
|
| 262 | - * @return \OCP\Share\IShare[] |
|
| 263 | - */ |
|
| 264 | - public function getChildren(\OCP\Share\IShare $parent) { |
|
| 265 | - $children = []; |
|
| 266 | - |
|
| 267 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 268 | - $qb->select('*') |
|
| 269 | - ->from('share') |
|
| 270 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
| 271 | - ->andWhere( |
|
| 272 | - $qb->expr()->in( |
|
| 273 | - 'share_type', |
|
| 274 | - $qb->createNamedParameter([ |
|
| 275 | - \OCP\Share::SHARE_TYPE_USER, |
|
| 276 | - \OCP\Share::SHARE_TYPE_GROUP, |
|
| 277 | - \OCP\Share::SHARE_TYPE_LINK, |
|
| 278 | - ], IQueryBuilder::PARAM_INT_ARRAY) |
|
| 279 | - ) |
|
| 280 | - ) |
|
| 281 | - ->andWhere($qb->expr()->orX( |
|
| 282 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 283 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 284 | - )) |
|
| 285 | - ->orderBy('id'); |
|
| 286 | - |
|
| 287 | - $cursor = $qb->execute(); |
|
| 288 | - while($data = $cursor->fetch()) { |
|
| 289 | - $children[] = $this->createShare($data); |
|
| 290 | - } |
|
| 291 | - $cursor->closeCursor(); |
|
| 292 | - |
|
| 293 | - return $children; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Delete a share |
|
| 298 | - * |
|
| 299 | - * @param \OCP\Share\IShare $share |
|
| 300 | - */ |
|
| 301 | - public function delete(\OCP\Share\IShare $share) { |
|
| 302 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 303 | - $qb->delete('share') |
|
| 304 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))); |
|
| 305 | - |
|
| 306 | - /* |
|
| 232 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 233 | + $qb->update('share') |
|
| 234 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
| 235 | + ->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0))) |
|
| 236 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
| 237 | + ->execute(); |
|
| 238 | + |
|
| 239 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 240 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 241 | + $qb->update('share') |
|
| 242 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
| 243 | + ->set('share_with', $qb->createNamedParameter($share->getPassword())) |
|
| 244 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
| 245 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
| 246 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
| 247 | + ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
| 248 | + ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
| 249 | + ->set('token', $qb->createNamedParameter($share->getToken())) |
|
| 250 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
| 251 | + ->execute(); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + return $share; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * Get all children of this share |
|
| 259 | + * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
| 260 | + * |
|
| 261 | + * @param \OCP\Share\IShare $parent |
|
| 262 | + * @return \OCP\Share\IShare[] |
|
| 263 | + */ |
|
| 264 | + public function getChildren(\OCP\Share\IShare $parent) { |
|
| 265 | + $children = []; |
|
| 266 | + |
|
| 267 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 268 | + $qb->select('*') |
|
| 269 | + ->from('share') |
|
| 270 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
| 271 | + ->andWhere( |
|
| 272 | + $qb->expr()->in( |
|
| 273 | + 'share_type', |
|
| 274 | + $qb->createNamedParameter([ |
|
| 275 | + \OCP\Share::SHARE_TYPE_USER, |
|
| 276 | + \OCP\Share::SHARE_TYPE_GROUP, |
|
| 277 | + \OCP\Share::SHARE_TYPE_LINK, |
|
| 278 | + ], IQueryBuilder::PARAM_INT_ARRAY) |
|
| 279 | + ) |
|
| 280 | + ) |
|
| 281 | + ->andWhere($qb->expr()->orX( |
|
| 282 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 283 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 284 | + )) |
|
| 285 | + ->orderBy('id'); |
|
| 286 | + |
|
| 287 | + $cursor = $qb->execute(); |
|
| 288 | + while($data = $cursor->fetch()) { |
|
| 289 | + $children[] = $this->createShare($data); |
|
| 290 | + } |
|
| 291 | + $cursor->closeCursor(); |
|
| 292 | + |
|
| 293 | + return $children; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Delete a share |
|
| 298 | + * |
|
| 299 | + * @param \OCP\Share\IShare $share |
|
| 300 | + */ |
|
| 301 | + public function delete(\OCP\Share\IShare $share) { |
|
| 302 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 303 | + $qb->delete('share') |
|
| 304 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))); |
|
| 305 | + |
|
| 306 | + /* |
|
| 307 | 307 | * If the share is a group share delete all possible |
| 308 | 308 | * user defined groups shares. |
| 309 | 309 | */ |
| 310 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 311 | - $qb->orWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - $qb->execute(); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * Unshare a share from the recipient. If this is a group share |
|
| 319 | - * this means we need a special entry in the share db. |
|
| 320 | - * |
|
| 321 | - * @param \OCP\Share\IShare $share |
|
| 322 | - * @param string $recipient UserId of recipient |
|
| 323 | - * @throws BackendError |
|
| 324 | - * @throws ProviderException |
|
| 325 | - */ |
|
| 326 | - public function deleteFromSelf(\OCP\Share\IShare $share, $recipient) { |
|
| 327 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 328 | - |
|
| 329 | - $group = $this->groupManager->get($share->getSharedWith()); |
|
| 330 | - $user = $this->userManager->get($recipient); |
|
| 331 | - |
|
| 332 | - if (is_null($group)) { |
|
| 333 | - throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - if (!$group->inGroup($user)) { |
|
| 337 | - throw new ProviderException('Recipient not in receiving group'); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - // Try to fetch user specific share |
|
| 341 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 342 | - $stmt = $qb->select('*') |
|
| 343 | - ->from('share') |
|
| 344 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
| 345 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) |
|
| 346 | - ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
| 347 | - ->andWhere($qb->expr()->orX( |
|
| 348 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 349 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 350 | - )) |
|
| 351 | - ->execute(); |
|
| 352 | - |
|
| 353 | - $data = $stmt->fetch(); |
|
| 354 | - |
|
| 355 | - /* |
|
| 310 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 311 | + $qb->orWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + $qb->execute(); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * Unshare a share from the recipient. If this is a group share |
|
| 319 | + * this means we need a special entry in the share db. |
|
| 320 | + * |
|
| 321 | + * @param \OCP\Share\IShare $share |
|
| 322 | + * @param string $recipient UserId of recipient |
|
| 323 | + * @throws BackendError |
|
| 324 | + * @throws ProviderException |
|
| 325 | + */ |
|
| 326 | + public function deleteFromSelf(\OCP\Share\IShare $share, $recipient) { |
|
| 327 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 328 | + |
|
| 329 | + $group = $this->groupManager->get($share->getSharedWith()); |
|
| 330 | + $user = $this->userManager->get($recipient); |
|
| 331 | + |
|
| 332 | + if (is_null($group)) { |
|
| 333 | + throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + if (!$group->inGroup($user)) { |
|
| 337 | + throw new ProviderException('Recipient not in receiving group'); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + // Try to fetch user specific share |
|
| 341 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 342 | + $stmt = $qb->select('*') |
|
| 343 | + ->from('share') |
|
| 344 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
| 345 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) |
|
| 346 | + ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
| 347 | + ->andWhere($qb->expr()->orX( |
|
| 348 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 349 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 350 | + )) |
|
| 351 | + ->execute(); |
|
| 352 | + |
|
| 353 | + $data = $stmt->fetch(); |
|
| 354 | + |
|
| 355 | + /* |
|
| 356 | 356 | * Check if there already is a user specific group share. |
| 357 | 357 | * If there is update it (if required). |
| 358 | 358 | */ |
| 359 | - if ($data === false) { |
|
| 360 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 361 | - |
|
| 362 | - $type = $share->getNodeType(); |
|
| 363 | - |
|
| 364 | - //Insert new share |
|
| 365 | - $qb->insert('share') |
|
| 366 | - ->values([ |
|
| 367 | - 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), |
|
| 368 | - 'share_with' => $qb->createNamedParameter($recipient), |
|
| 369 | - 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), |
|
| 370 | - 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), |
|
| 371 | - 'parent' => $qb->createNamedParameter($share->getId()), |
|
| 372 | - 'item_type' => $qb->createNamedParameter($type), |
|
| 373 | - 'item_source' => $qb->createNamedParameter($share->getNodeId()), |
|
| 374 | - 'file_source' => $qb->createNamedParameter($share->getNodeId()), |
|
| 375 | - 'file_target' => $qb->createNamedParameter($share->getTarget()), |
|
| 376 | - 'permissions' => $qb->createNamedParameter(0), |
|
| 377 | - 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()), |
|
| 378 | - ])->execute(); |
|
| 379 | - |
|
| 380 | - } else if ($data['permissions'] !== 0) { |
|
| 381 | - |
|
| 382 | - // Update existing usergroup share |
|
| 383 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 384 | - $qb->update('share') |
|
| 385 | - ->set('permissions', $qb->createNamedParameter(0)) |
|
| 386 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id']))) |
|
| 387 | - ->execute(); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 391 | - |
|
| 392 | - if ($share->getSharedWith() !== $recipient) { |
|
| 393 | - throw new ProviderException('Recipient does not match'); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - // We can just delete user and link shares |
|
| 397 | - $this->delete($share); |
|
| 398 | - } else { |
|
| 399 | - throw new ProviderException('Invalid shareType'); |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * @inheritdoc |
|
| 405 | - */ |
|
| 406 | - public function move(\OCP\Share\IShare $share, $recipient) { |
|
| 407 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 408 | - // Just update the target |
|
| 409 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 410 | - $qb->update('share') |
|
| 411 | - ->set('file_target', $qb->createNamedParameter($share->getTarget())) |
|
| 412 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
| 413 | - ->execute(); |
|
| 414 | - |
|
| 415 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 416 | - |
|
| 417 | - // Check if there is a usergroup share |
|
| 418 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 419 | - $stmt = $qb->select('id') |
|
| 420 | - ->from('share') |
|
| 421 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
| 422 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) |
|
| 423 | - ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
| 424 | - ->andWhere($qb->expr()->orX( |
|
| 425 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 426 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 427 | - )) |
|
| 428 | - ->setMaxResults(1) |
|
| 429 | - ->execute(); |
|
| 430 | - |
|
| 431 | - $data = $stmt->fetch(); |
|
| 432 | - $stmt->closeCursor(); |
|
| 433 | - |
|
| 434 | - if ($data === false) { |
|
| 435 | - // No usergroup share yet. Create one. |
|
| 436 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 437 | - $qb->insert('share') |
|
| 438 | - ->values([ |
|
| 439 | - 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), |
|
| 440 | - 'share_with' => $qb->createNamedParameter($recipient), |
|
| 441 | - 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), |
|
| 442 | - 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), |
|
| 443 | - 'parent' => $qb->createNamedParameter($share->getId()), |
|
| 444 | - 'item_type' => $qb->createNamedParameter($share->getNode() instanceof File ? 'file' : 'folder'), |
|
| 445 | - 'item_source' => $qb->createNamedParameter($share->getNode()->getId()), |
|
| 446 | - 'file_source' => $qb->createNamedParameter($share->getNode()->getId()), |
|
| 447 | - 'file_target' => $qb->createNamedParameter($share->getTarget()), |
|
| 448 | - 'permissions' => $qb->createNamedParameter($share->getPermissions()), |
|
| 449 | - 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()), |
|
| 450 | - ])->execute(); |
|
| 451 | - } else { |
|
| 452 | - // Already a usergroup share. Update it. |
|
| 453 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 454 | - $qb->update('share') |
|
| 455 | - ->set('file_target', $qb->createNamedParameter($share->getTarget())) |
|
| 456 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id']))) |
|
| 457 | - ->execute(); |
|
| 458 | - } |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - return $share; |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
| 465 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 466 | - $qb->select('*') |
|
| 467 | - ->from('share', 's') |
|
| 468 | - ->andWhere($qb->expr()->orX( |
|
| 469 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 470 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 471 | - )); |
|
| 472 | - |
|
| 473 | - $qb->andWhere($qb->expr()->orX( |
|
| 474 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
| 475 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
| 476 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)) |
|
| 477 | - )); |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * Reshares for this user are shares where they are the owner. |
|
| 481 | - */ |
|
| 482 | - if ($reshares === false) { |
|
| 483 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
| 484 | - } else { |
|
| 485 | - $qb->andWhere( |
|
| 486 | - $qb->expr()->orX( |
|
| 487 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 488 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 489 | - ) |
|
| 490 | - ); |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - $qb->innerJoin('s', 'filecache' ,'f', 's.file_source = f.fileid'); |
|
| 494 | - $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
| 495 | - |
|
| 496 | - $qb->orderBy('id'); |
|
| 497 | - |
|
| 498 | - $cursor = $qb->execute(); |
|
| 499 | - $shares = []; |
|
| 500 | - while ($data = $cursor->fetch()) { |
|
| 501 | - $shares[$data['fileid']][] = $this->createShare($data); |
|
| 502 | - } |
|
| 503 | - $cursor->closeCursor(); |
|
| 504 | - |
|
| 505 | - return $shares; |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * @inheritdoc |
|
| 510 | - */ |
|
| 511 | - public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
| 512 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 513 | - $qb->select('*') |
|
| 514 | - ->from('share') |
|
| 515 | - ->andWhere($qb->expr()->orX( |
|
| 516 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 517 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 518 | - )); |
|
| 519 | - |
|
| 520 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType))); |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * Reshares for this user are shares where they are the owner. |
|
| 524 | - */ |
|
| 525 | - if ($reshares === false) { |
|
| 526 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
| 527 | - } else { |
|
| 528 | - $qb->andWhere( |
|
| 529 | - $qb->expr()->orX( |
|
| 530 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 531 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 532 | - ) |
|
| 533 | - ); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - if ($node !== null) { |
|
| 537 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - if ($limit !== -1) { |
|
| 541 | - $qb->setMaxResults($limit); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - $qb->setFirstResult($offset); |
|
| 545 | - $qb->orderBy('id'); |
|
| 546 | - |
|
| 547 | - $cursor = $qb->execute(); |
|
| 548 | - $shares = []; |
|
| 549 | - while($data = $cursor->fetch()) { |
|
| 550 | - $shares[] = $this->createShare($data); |
|
| 551 | - } |
|
| 552 | - $cursor->closeCursor(); |
|
| 553 | - |
|
| 554 | - return $shares; |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - /** |
|
| 558 | - * @inheritdoc |
|
| 559 | - */ |
|
| 560 | - public function getShareById($id, $recipientId = null) { |
|
| 561 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 562 | - |
|
| 563 | - $qb->select('*') |
|
| 564 | - ->from('share') |
|
| 565 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 566 | - ->andWhere( |
|
| 567 | - $qb->expr()->in( |
|
| 568 | - 'share_type', |
|
| 569 | - $qb->createNamedParameter([ |
|
| 570 | - \OCP\Share::SHARE_TYPE_USER, |
|
| 571 | - \OCP\Share::SHARE_TYPE_GROUP, |
|
| 572 | - \OCP\Share::SHARE_TYPE_LINK, |
|
| 573 | - ], IQueryBuilder::PARAM_INT_ARRAY) |
|
| 574 | - ) |
|
| 575 | - ) |
|
| 576 | - ->andWhere($qb->expr()->orX( |
|
| 577 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 578 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 579 | - )); |
|
| 580 | - |
|
| 581 | - $cursor = $qb->execute(); |
|
| 582 | - $data = $cursor->fetch(); |
|
| 583 | - $cursor->closeCursor(); |
|
| 584 | - |
|
| 585 | - if ($data === false) { |
|
| 586 | - throw new ShareNotFound(); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - try { |
|
| 590 | - $share = $this->createShare($data); |
|
| 591 | - } catch (InvalidShare $e) { |
|
| 592 | - throw new ShareNotFound(); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - // If the recipient is set for a group share resolve to that user |
|
| 596 | - if ($recipientId !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 597 | - $share = $this->resolveGroupShares([$share], $recipientId)[0]; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - return $share; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - /** |
|
| 604 | - * Get shares for a given path |
|
| 605 | - * |
|
| 606 | - * @param \OCP\Files\Node $path |
|
| 607 | - * @return \OCP\Share\IShare[] |
|
| 608 | - */ |
|
| 609 | - public function getSharesByPath(Node $path) { |
|
| 610 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 611 | - |
|
| 612 | - $cursor = $qb->select('*') |
|
| 613 | - ->from('share') |
|
| 614 | - ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
| 615 | - ->andWhere( |
|
| 616 | - $qb->expr()->orX( |
|
| 617 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
| 618 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)) |
|
| 619 | - ) |
|
| 620 | - ) |
|
| 621 | - ->andWhere($qb->expr()->orX( |
|
| 622 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 623 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 624 | - )) |
|
| 625 | - ->execute(); |
|
| 626 | - |
|
| 627 | - $shares = []; |
|
| 628 | - while($data = $cursor->fetch()) { |
|
| 629 | - $shares[] = $this->createShare($data); |
|
| 630 | - } |
|
| 631 | - $cursor->closeCursor(); |
|
| 632 | - |
|
| 633 | - return $shares; |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - /** |
|
| 637 | - * Returns whether the given database result can be interpreted as |
|
| 638 | - * a share with accessible file (not trashed, not deleted) |
|
| 639 | - */ |
|
| 640 | - private function isAccessibleResult($data) { |
|
| 641 | - // exclude shares leading to deleted file entries |
|
| 642 | - if ($data['fileid'] === null) { |
|
| 643 | - return false; |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - // exclude shares leading to trashbin on home storages |
|
| 647 | - $pathSections = explode('/', $data['path'], 2); |
|
| 648 | - // FIXME: would not detect rare md5'd home storage case properly |
|
| 649 | - if ($pathSections[0] !== 'files' |
|
| 650 | - && in_array(explode(':', $data['storage_string_id'], 2)[0], array('home', 'object'))) { |
|
| 651 | - return false; |
|
| 652 | - } |
|
| 653 | - return true; |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - /** |
|
| 657 | - * @inheritdoc |
|
| 658 | - */ |
|
| 659 | - public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
| 660 | - /** @var Share[] $shares */ |
|
| 661 | - $shares = []; |
|
| 662 | - |
|
| 663 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
| 664 | - //Get shares directly with this user |
|
| 665 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 666 | - $qb->select('s.*', |
|
| 667 | - 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', |
|
| 668 | - 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', |
|
| 669 | - 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' |
|
| 670 | - ) |
|
| 671 | - ->selectAlias('st.id', 'storage_string_id') |
|
| 672 | - ->from('share', 's') |
|
| 673 | - ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) |
|
| 674 | - ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id')); |
|
| 675 | - |
|
| 676 | - // Order by id |
|
| 677 | - $qb->orderBy('s.id'); |
|
| 678 | - |
|
| 679 | - // Set limit and offset |
|
| 680 | - if ($limit !== -1) { |
|
| 681 | - $qb->setMaxResults($limit); |
|
| 682 | - } |
|
| 683 | - $qb->setFirstResult($offset); |
|
| 684 | - |
|
| 685 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))) |
|
| 686 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))) |
|
| 687 | - ->andWhere($qb->expr()->orX( |
|
| 688 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 689 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 690 | - )); |
|
| 691 | - |
|
| 692 | - // Filter by node if provided |
|
| 693 | - if ($node !== null) { |
|
| 694 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - $cursor = $qb->execute(); |
|
| 698 | - |
|
| 699 | - while($data = $cursor->fetch()) { |
|
| 700 | - if ($this->isAccessibleResult($data)) { |
|
| 701 | - $shares[] = $this->createShare($data); |
|
| 702 | - } |
|
| 703 | - } |
|
| 704 | - $cursor->closeCursor(); |
|
| 705 | - |
|
| 706 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 707 | - $user = $this->userManager->get($userId); |
|
| 708 | - $allGroups = $this->groupManager->getUserGroups($user); |
|
| 709 | - |
|
| 710 | - /** @var Share[] $shares2 */ |
|
| 711 | - $shares2 = []; |
|
| 712 | - |
|
| 713 | - $start = 0; |
|
| 714 | - while(true) { |
|
| 715 | - $groups = array_slice($allGroups, $start, 100); |
|
| 716 | - $start += 100; |
|
| 717 | - |
|
| 718 | - if ($groups === []) { |
|
| 719 | - break; |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 723 | - $qb->select('s.*', |
|
| 724 | - 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', |
|
| 725 | - 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', |
|
| 726 | - 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' |
|
| 727 | - ) |
|
| 728 | - ->selectAlias('st.id', 'storage_string_id') |
|
| 729 | - ->from('share', 's') |
|
| 730 | - ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) |
|
| 731 | - ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id')) |
|
| 732 | - ->orderBy('s.id') |
|
| 733 | - ->setFirstResult(0); |
|
| 734 | - |
|
| 735 | - if ($limit !== -1) { |
|
| 736 | - $qb->setMaxResults($limit - count($shares)); |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - // Filter by node if provided |
|
| 740 | - if ($node !== null) { |
|
| 741 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - $groups = array_map(function(IGroup $group) { return $group->getGID(); }, $groups); |
|
| 745 | - |
|
| 746 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
| 747 | - ->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter( |
|
| 748 | - $groups, |
|
| 749 | - IQueryBuilder::PARAM_STR_ARRAY |
|
| 750 | - ))) |
|
| 751 | - ->andWhere($qb->expr()->orX( |
|
| 752 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 753 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 754 | - )); |
|
| 755 | - |
|
| 756 | - $cursor = $qb->execute(); |
|
| 757 | - while($data = $cursor->fetch()) { |
|
| 758 | - if ($offset > 0) { |
|
| 759 | - $offset--; |
|
| 760 | - continue; |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - if ($this->isAccessibleResult($data)) { |
|
| 764 | - $shares2[] = $this->createShare($data); |
|
| 765 | - } |
|
| 766 | - } |
|
| 767 | - $cursor->closeCursor(); |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - /* |
|
| 359 | + if ($data === false) { |
|
| 360 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 361 | + |
|
| 362 | + $type = $share->getNodeType(); |
|
| 363 | + |
|
| 364 | + //Insert new share |
|
| 365 | + $qb->insert('share') |
|
| 366 | + ->values([ |
|
| 367 | + 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), |
|
| 368 | + 'share_with' => $qb->createNamedParameter($recipient), |
|
| 369 | + 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), |
|
| 370 | + 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), |
|
| 371 | + 'parent' => $qb->createNamedParameter($share->getId()), |
|
| 372 | + 'item_type' => $qb->createNamedParameter($type), |
|
| 373 | + 'item_source' => $qb->createNamedParameter($share->getNodeId()), |
|
| 374 | + 'file_source' => $qb->createNamedParameter($share->getNodeId()), |
|
| 375 | + 'file_target' => $qb->createNamedParameter($share->getTarget()), |
|
| 376 | + 'permissions' => $qb->createNamedParameter(0), |
|
| 377 | + 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()), |
|
| 378 | + ])->execute(); |
|
| 379 | + |
|
| 380 | + } else if ($data['permissions'] !== 0) { |
|
| 381 | + |
|
| 382 | + // Update existing usergroup share |
|
| 383 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 384 | + $qb->update('share') |
|
| 385 | + ->set('permissions', $qb->createNamedParameter(0)) |
|
| 386 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id']))) |
|
| 387 | + ->execute(); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 391 | + |
|
| 392 | + if ($share->getSharedWith() !== $recipient) { |
|
| 393 | + throw new ProviderException('Recipient does not match'); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + // We can just delete user and link shares |
|
| 397 | + $this->delete($share); |
|
| 398 | + } else { |
|
| 399 | + throw new ProviderException('Invalid shareType'); |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * @inheritdoc |
|
| 405 | + */ |
|
| 406 | + public function move(\OCP\Share\IShare $share, $recipient) { |
|
| 407 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 408 | + // Just update the target |
|
| 409 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 410 | + $qb->update('share') |
|
| 411 | + ->set('file_target', $qb->createNamedParameter($share->getTarget())) |
|
| 412 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
| 413 | + ->execute(); |
|
| 414 | + |
|
| 415 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 416 | + |
|
| 417 | + // Check if there is a usergroup share |
|
| 418 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 419 | + $stmt = $qb->select('id') |
|
| 420 | + ->from('share') |
|
| 421 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
| 422 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) |
|
| 423 | + ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
| 424 | + ->andWhere($qb->expr()->orX( |
|
| 425 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 426 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 427 | + )) |
|
| 428 | + ->setMaxResults(1) |
|
| 429 | + ->execute(); |
|
| 430 | + |
|
| 431 | + $data = $stmt->fetch(); |
|
| 432 | + $stmt->closeCursor(); |
|
| 433 | + |
|
| 434 | + if ($data === false) { |
|
| 435 | + // No usergroup share yet. Create one. |
|
| 436 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 437 | + $qb->insert('share') |
|
| 438 | + ->values([ |
|
| 439 | + 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), |
|
| 440 | + 'share_with' => $qb->createNamedParameter($recipient), |
|
| 441 | + 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), |
|
| 442 | + 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), |
|
| 443 | + 'parent' => $qb->createNamedParameter($share->getId()), |
|
| 444 | + 'item_type' => $qb->createNamedParameter($share->getNode() instanceof File ? 'file' : 'folder'), |
|
| 445 | + 'item_source' => $qb->createNamedParameter($share->getNode()->getId()), |
|
| 446 | + 'file_source' => $qb->createNamedParameter($share->getNode()->getId()), |
|
| 447 | + 'file_target' => $qb->createNamedParameter($share->getTarget()), |
|
| 448 | + 'permissions' => $qb->createNamedParameter($share->getPermissions()), |
|
| 449 | + 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()), |
|
| 450 | + ])->execute(); |
|
| 451 | + } else { |
|
| 452 | + // Already a usergroup share. Update it. |
|
| 453 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 454 | + $qb->update('share') |
|
| 455 | + ->set('file_target', $qb->createNamedParameter($share->getTarget())) |
|
| 456 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id']))) |
|
| 457 | + ->execute(); |
|
| 458 | + } |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + return $share; |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
| 465 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 466 | + $qb->select('*') |
|
| 467 | + ->from('share', 's') |
|
| 468 | + ->andWhere($qb->expr()->orX( |
|
| 469 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 470 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 471 | + )); |
|
| 472 | + |
|
| 473 | + $qb->andWhere($qb->expr()->orX( |
|
| 474 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
| 475 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
| 476 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)) |
|
| 477 | + )); |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * Reshares for this user are shares where they are the owner. |
|
| 481 | + */ |
|
| 482 | + if ($reshares === false) { |
|
| 483 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
| 484 | + } else { |
|
| 485 | + $qb->andWhere( |
|
| 486 | + $qb->expr()->orX( |
|
| 487 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 488 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 489 | + ) |
|
| 490 | + ); |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + $qb->innerJoin('s', 'filecache' ,'f', 's.file_source = f.fileid'); |
|
| 494 | + $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
| 495 | + |
|
| 496 | + $qb->orderBy('id'); |
|
| 497 | + |
|
| 498 | + $cursor = $qb->execute(); |
|
| 499 | + $shares = []; |
|
| 500 | + while ($data = $cursor->fetch()) { |
|
| 501 | + $shares[$data['fileid']][] = $this->createShare($data); |
|
| 502 | + } |
|
| 503 | + $cursor->closeCursor(); |
|
| 504 | + |
|
| 505 | + return $shares; |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * @inheritdoc |
|
| 510 | + */ |
|
| 511 | + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
| 512 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 513 | + $qb->select('*') |
|
| 514 | + ->from('share') |
|
| 515 | + ->andWhere($qb->expr()->orX( |
|
| 516 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 517 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 518 | + )); |
|
| 519 | + |
|
| 520 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType))); |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * Reshares for this user are shares where they are the owner. |
|
| 524 | + */ |
|
| 525 | + if ($reshares === false) { |
|
| 526 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
| 527 | + } else { |
|
| 528 | + $qb->andWhere( |
|
| 529 | + $qb->expr()->orX( |
|
| 530 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 531 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 532 | + ) |
|
| 533 | + ); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + if ($node !== null) { |
|
| 537 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + if ($limit !== -1) { |
|
| 541 | + $qb->setMaxResults($limit); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + $qb->setFirstResult($offset); |
|
| 545 | + $qb->orderBy('id'); |
|
| 546 | + |
|
| 547 | + $cursor = $qb->execute(); |
|
| 548 | + $shares = []; |
|
| 549 | + while($data = $cursor->fetch()) { |
|
| 550 | + $shares[] = $this->createShare($data); |
|
| 551 | + } |
|
| 552 | + $cursor->closeCursor(); |
|
| 553 | + |
|
| 554 | + return $shares; |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + /** |
|
| 558 | + * @inheritdoc |
|
| 559 | + */ |
|
| 560 | + public function getShareById($id, $recipientId = null) { |
|
| 561 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 562 | + |
|
| 563 | + $qb->select('*') |
|
| 564 | + ->from('share') |
|
| 565 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 566 | + ->andWhere( |
|
| 567 | + $qb->expr()->in( |
|
| 568 | + 'share_type', |
|
| 569 | + $qb->createNamedParameter([ |
|
| 570 | + \OCP\Share::SHARE_TYPE_USER, |
|
| 571 | + \OCP\Share::SHARE_TYPE_GROUP, |
|
| 572 | + \OCP\Share::SHARE_TYPE_LINK, |
|
| 573 | + ], IQueryBuilder::PARAM_INT_ARRAY) |
|
| 574 | + ) |
|
| 575 | + ) |
|
| 576 | + ->andWhere($qb->expr()->orX( |
|
| 577 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 578 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 579 | + )); |
|
| 580 | + |
|
| 581 | + $cursor = $qb->execute(); |
|
| 582 | + $data = $cursor->fetch(); |
|
| 583 | + $cursor->closeCursor(); |
|
| 584 | + |
|
| 585 | + if ($data === false) { |
|
| 586 | + throw new ShareNotFound(); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + try { |
|
| 590 | + $share = $this->createShare($data); |
|
| 591 | + } catch (InvalidShare $e) { |
|
| 592 | + throw new ShareNotFound(); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + // If the recipient is set for a group share resolve to that user |
|
| 596 | + if ($recipientId !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 597 | + $share = $this->resolveGroupShares([$share], $recipientId)[0]; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + return $share; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + /** |
|
| 604 | + * Get shares for a given path |
|
| 605 | + * |
|
| 606 | + * @param \OCP\Files\Node $path |
|
| 607 | + * @return \OCP\Share\IShare[] |
|
| 608 | + */ |
|
| 609 | + public function getSharesByPath(Node $path) { |
|
| 610 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 611 | + |
|
| 612 | + $cursor = $qb->select('*') |
|
| 613 | + ->from('share') |
|
| 614 | + ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
| 615 | + ->andWhere( |
|
| 616 | + $qb->expr()->orX( |
|
| 617 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
| 618 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)) |
|
| 619 | + ) |
|
| 620 | + ) |
|
| 621 | + ->andWhere($qb->expr()->orX( |
|
| 622 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 623 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 624 | + )) |
|
| 625 | + ->execute(); |
|
| 626 | + |
|
| 627 | + $shares = []; |
|
| 628 | + while($data = $cursor->fetch()) { |
|
| 629 | + $shares[] = $this->createShare($data); |
|
| 630 | + } |
|
| 631 | + $cursor->closeCursor(); |
|
| 632 | + |
|
| 633 | + return $shares; |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + /** |
|
| 637 | + * Returns whether the given database result can be interpreted as |
|
| 638 | + * a share with accessible file (not trashed, not deleted) |
|
| 639 | + */ |
|
| 640 | + private function isAccessibleResult($data) { |
|
| 641 | + // exclude shares leading to deleted file entries |
|
| 642 | + if ($data['fileid'] === null) { |
|
| 643 | + return false; |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + // exclude shares leading to trashbin on home storages |
|
| 647 | + $pathSections = explode('/', $data['path'], 2); |
|
| 648 | + // FIXME: would not detect rare md5'd home storage case properly |
|
| 649 | + if ($pathSections[0] !== 'files' |
|
| 650 | + && in_array(explode(':', $data['storage_string_id'], 2)[0], array('home', 'object'))) { |
|
| 651 | + return false; |
|
| 652 | + } |
|
| 653 | + return true; |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + /** |
|
| 657 | + * @inheritdoc |
|
| 658 | + */ |
|
| 659 | + public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
| 660 | + /** @var Share[] $shares */ |
|
| 661 | + $shares = []; |
|
| 662 | + |
|
| 663 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
| 664 | + //Get shares directly with this user |
|
| 665 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 666 | + $qb->select('s.*', |
|
| 667 | + 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', |
|
| 668 | + 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', |
|
| 669 | + 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' |
|
| 670 | + ) |
|
| 671 | + ->selectAlias('st.id', 'storage_string_id') |
|
| 672 | + ->from('share', 's') |
|
| 673 | + ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) |
|
| 674 | + ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id')); |
|
| 675 | + |
|
| 676 | + // Order by id |
|
| 677 | + $qb->orderBy('s.id'); |
|
| 678 | + |
|
| 679 | + // Set limit and offset |
|
| 680 | + if ($limit !== -1) { |
|
| 681 | + $qb->setMaxResults($limit); |
|
| 682 | + } |
|
| 683 | + $qb->setFirstResult($offset); |
|
| 684 | + |
|
| 685 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))) |
|
| 686 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))) |
|
| 687 | + ->andWhere($qb->expr()->orX( |
|
| 688 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 689 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 690 | + )); |
|
| 691 | + |
|
| 692 | + // Filter by node if provided |
|
| 693 | + if ($node !== null) { |
|
| 694 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + $cursor = $qb->execute(); |
|
| 698 | + |
|
| 699 | + while($data = $cursor->fetch()) { |
|
| 700 | + if ($this->isAccessibleResult($data)) { |
|
| 701 | + $shares[] = $this->createShare($data); |
|
| 702 | + } |
|
| 703 | + } |
|
| 704 | + $cursor->closeCursor(); |
|
| 705 | + |
|
| 706 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 707 | + $user = $this->userManager->get($userId); |
|
| 708 | + $allGroups = $this->groupManager->getUserGroups($user); |
|
| 709 | + |
|
| 710 | + /** @var Share[] $shares2 */ |
|
| 711 | + $shares2 = []; |
|
| 712 | + |
|
| 713 | + $start = 0; |
|
| 714 | + while(true) { |
|
| 715 | + $groups = array_slice($allGroups, $start, 100); |
|
| 716 | + $start += 100; |
|
| 717 | + |
|
| 718 | + if ($groups === []) { |
|
| 719 | + break; |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 723 | + $qb->select('s.*', |
|
| 724 | + 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', |
|
| 725 | + 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', |
|
| 726 | + 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' |
|
| 727 | + ) |
|
| 728 | + ->selectAlias('st.id', 'storage_string_id') |
|
| 729 | + ->from('share', 's') |
|
| 730 | + ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) |
|
| 731 | + ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id')) |
|
| 732 | + ->orderBy('s.id') |
|
| 733 | + ->setFirstResult(0); |
|
| 734 | + |
|
| 735 | + if ($limit !== -1) { |
|
| 736 | + $qb->setMaxResults($limit - count($shares)); |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + // Filter by node if provided |
|
| 740 | + if ($node !== null) { |
|
| 741 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + $groups = array_map(function(IGroup $group) { return $group->getGID(); }, $groups); |
|
| 745 | + |
|
| 746 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
| 747 | + ->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter( |
|
| 748 | + $groups, |
|
| 749 | + IQueryBuilder::PARAM_STR_ARRAY |
|
| 750 | + ))) |
|
| 751 | + ->andWhere($qb->expr()->orX( |
|
| 752 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 753 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 754 | + )); |
|
| 755 | + |
|
| 756 | + $cursor = $qb->execute(); |
|
| 757 | + while($data = $cursor->fetch()) { |
|
| 758 | + if ($offset > 0) { |
|
| 759 | + $offset--; |
|
| 760 | + continue; |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + if ($this->isAccessibleResult($data)) { |
|
| 764 | + $shares2[] = $this->createShare($data); |
|
| 765 | + } |
|
| 766 | + } |
|
| 767 | + $cursor->closeCursor(); |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + /* |
|
| 771 | 771 | * Resolve all group shares to user specific shares |
| 772 | 772 | */ |
| 773 | - $shares = $this->resolveGroupShares($shares2, $userId); |
|
| 774 | - } else { |
|
| 775 | - throw new BackendError('Invalid backend'); |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - |
|
| 779 | - return $shares; |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - /** |
|
| 783 | - * Get a share by token |
|
| 784 | - * |
|
| 785 | - * @param string $token |
|
| 786 | - * @return \OCP\Share\IShare |
|
| 787 | - * @throws ShareNotFound |
|
| 788 | - */ |
|
| 789 | - public function getShareByToken($token) { |
|
| 790 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 791 | - |
|
| 792 | - $cursor = $qb->select('*') |
|
| 793 | - ->from('share') |
|
| 794 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))) |
|
| 795 | - ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 796 | - ->andWhere($qb->expr()->orX( |
|
| 797 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 798 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 799 | - )) |
|
| 800 | - ->execute(); |
|
| 801 | - |
|
| 802 | - $data = $cursor->fetch(); |
|
| 803 | - |
|
| 804 | - if ($data === false) { |
|
| 805 | - throw new ShareNotFound(); |
|
| 806 | - } |
|
| 807 | - |
|
| 808 | - try { |
|
| 809 | - $share = $this->createShare($data); |
|
| 810 | - } catch (InvalidShare $e) { |
|
| 811 | - throw new ShareNotFound(); |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - return $share; |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - /** |
|
| 818 | - * Create a share object from an database row |
|
| 819 | - * |
|
| 820 | - * @param mixed[] $data |
|
| 821 | - * @return \OCP\Share\IShare |
|
| 822 | - * @throws InvalidShare |
|
| 823 | - */ |
|
| 824 | - private function createShare($data) { |
|
| 825 | - $share = new Share($this->rootFolder, $this->userManager); |
|
| 826 | - $share->setId((int)$data['id']) |
|
| 827 | - ->setShareType((int)$data['share_type']) |
|
| 828 | - ->setPermissions((int)$data['permissions']) |
|
| 829 | - ->setTarget($data['file_target']) |
|
| 830 | - ->setMailSend((bool)$data['mail_send']); |
|
| 831 | - |
|
| 832 | - $shareTime = new \DateTime(); |
|
| 833 | - $shareTime->setTimestamp((int)$data['stime']); |
|
| 834 | - $share->setShareTime($shareTime); |
|
| 835 | - |
|
| 836 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 837 | - $share->setSharedWith($data['share_with']); |
|
| 838 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 839 | - $share->setSharedWith($data['share_with']); |
|
| 840 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 841 | - $share->setPassword($data['share_with']); |
|
| 842 | - $share->setToken($data['token']); |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - $share->setSharedBy($data['uid_initiator']); |
|
| 846 | - $share->setShareOwner($data['uid_owner']); |
|
| 847 | - |
|
| 848 | - $share->setNodeId((int)$data['file_source']); |
|
| 849 | - $share->setNodeType($data['item_type']); |
|
| 850 | - |
|
| 851 | - if ($data['expiration'] !== null) { |
|
| 852 | - $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
| 853 | - $share->setExpirationDate($expiration); |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - if (isset($data['f_permissions'])) { |
|
| 857 | - $entryData = $data; |
|
| 858 | - $entryData['permissions'] = $entryData['f_permissions']; |
|
| 859 | - $entryData['parent'] = $entryData['f_parent'];; |
|
| 860 | - $share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData, |
|
| 861 | - \OC::$server->getMimeTypeLoader())); |
|
| 862 | - } |
|
| 863 | - |
|
| 864 | - $share->setProviderId($this->identifier()); |
|
| 865 | - |
|
| 866 | - return $share; |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - /** |
|
| 870 | - * @param Share[] $shares |
|
| 871 | - * @param $userId |
|
| 872 | - * @return Share[] The updates shares if no update is found for a share return the original |
|
| 873 | - */ |
|
| 874 | - private function resolveGroupShares($shares, $userId) { |
|
| 875 | - $result = []; |
|
| 876 | - |
|
| 877 | - $start = 0; |
|
| 878 | - while(true) { |
|
| 879 | - /** @var Share[] $shareSlice */ |
|
| 880 | - $shareSlice = array_slice($shares, $start, 100); |
|
| 881 | - $start += 100; |
|
| 882 | - |
|
| 883 | - if ($shareSlice === []) { |
|
| 884 | - break; |
|
| 885 | - } |
|
| 886 | - |
|
| 887 | - /** @var int[] $ids */ |
|
| 888 | - $ids = []; |
|
| 889 | - /** @var Share[] $shareMap */ |
|
| 890 | - $shareMap = []; |
|
| 891 | - |
|
| 892 | - foreach ($shareSlice as $share) { |
|
| 893 | - $ids[] = (int)$share->getId(); |
|
| 894 | - $shareMap[$share->getId()] = $share; |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 898 | - |
|
| 899 | - $query = $qb->select('*') |
|
| 900 | - ->from('share') |
|
| 901 | - ->where($qb->expr()->in('parent', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 902 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))) |
|
| 903 | - ->andWhere($qb->expr()->orX( |
|
| 904 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 905 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 906 | - )); |
|
| 907 | - |
|
| 908 | - $stmt = $query->execute(); |
|
| 909 | - |
|
| 910 | - while($data = $stmt->fetch()) { |
|
| 911 | - $shareMap[$data['parent']]->setPermissions((int)$data['permissions']); |
|
| 912 | - $shareMap[$data['parent']]->setTarget($data['file_target']); |
|
| 913 | - } |
|
| 914 | - |
|
| 915 | - $stmt->closeCursor(); |
|
| 916 | - |
|
| 917 | - foreach ($shareMap as $share) { |
|
| 918 | - $result[] = $share; |
|
| 919 | - } |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - return $result; |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - /** |
|
| 926 | - * A user is deleted from the system |
|
| 927 | - * So clean up the relevant shares. |
|
| 928 | - * |
|
| 929 | - * @param string $uid |
|
| 930 | - * @param int $shareType |
|
| 931 | - */ |
|
| 932 | - public function userDeleted($uid, $shareType) { |
|
| 933 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 934 | - |
|
| 935 | - $qb->delete('share'); |
|
| 936 | - |
|
| 937 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
| 938 | - /* |
|
| 773 | + $shares = $this->resolveGroupShares($shares2, $userId); |
|
| 774 | + } else { |
|
| 775 | + throw new BackendError('Invalid backend'); |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + |
|
| 779 | + return $shares; |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + /** |
|
| 783 | + * Get a share by token |
|
| 784 | + * |
|
| 785 | + * @param string $token |
|
| 786 | + * @return \OCP\Share\IShare |
|
| 787 | + * @throws ShareNotFound |
|
| 788 | + */ |
|
| 789 | + public function getShareByToken($token) { |
|
| 790 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 791 | + |
|
| 792 | + $cursor = $qb->select('*') |
|
| 793 | + ->from('share') |
|
| 794 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))) |
|
| 795 | + ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 796 | + ->andWhere($qb->expr()->orX( |
|
| 797 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 798 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 799 | + )) |
|
| 800 | + ->execute(); |
|
| 801 | + |
|
| 802 | + $data = $cursor->fetch(); |
|
| 803 | + |
|
| 804 | + if ($data === false) { |
|
| 805 | + throw new ShareNotFound(); |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + try { |
|
| 809 | + $share = $this->createShare($data); |
|
| 810 | + } catch (InvalidShare $e) { |
|
| 811 | + throw new ShareNotFound(); |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + return $share; |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + /** |
|
| 818 | + * Create a share object from an database row |
|
| 819 | + * |
|
| 820 | + * @param mixed[] $data |
|
| 821 | + * @return \OCP\Share\IShare |
|
| 822 | + * @throws InvalidShare |
|
| 823 | + */ |
|
| 824 | + private function createShare($data) { |
|
| 825 | + $share = new Share($this->rootFolder, $this->userManager); |
|
| 826 | + $share->setId((int)$data['id']) |
|
| 827 | + ->setShareType((int)$data['share_type']) |
|
| 828 | + ->setPermissions((int)$data['permissions']) |
|
| 829 | + ->setTarget($data['file_target']) |
|
| 830 | + ->setMailSend((bool)$data['mail_send']); |
|
| 831 | + |
|
| 832 | + $shareTime = new \DateTime(); |
|
| 833 | + $shareTime->setTimestamp((int)$data['stime']); |
|
| 834 | + $share->setShareTime($shareTime); |
|
| 835 | + |
|
| 836 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 837 | + $share->setSharedWith($data['share_with']); |
|
| 838 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 839 | + $share->setSharedWith($data['share_with']); |
|
| 840 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 841 | + $share->setPassword($data['share_with']); |
|
| 842 | + $share->setToken($data['token']); |
|
| 843 | + } |
|
| 844 | + |
|
| 845 | + $share->setSharedBy($data['uid_initiator']); |
|
| 846 | + $share->setShareOwner($data['uid_owner']); |
|
| 847 | + |
|
| 848 | + $share->setNodeId((int)$data['file_source']); |
|
| 849 | + $share->setNodeType($data['item_type']); |
|
| 850 | + |
|
| 851 | + if ($data['expiration'] !== null) { |
|
| 852 | + $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
| 853 | + $share->setExpirationDate($expiration); |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + if (isset($data['f_permissions'])) { |
|
| 857 | + $entryData = $data; |
|
| 858 | + $entryData['permissions'] = $entryData['f_permissions']; |
|
| 859 | + $entryData['parent'] = $entryData['f_parent'];; |
|
| 860 | + $share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData, |
|
| 861 | + \OC::$server->getMimeTypeLoader())); |
|
| 862 | + } |
|
| 863 | + |
|
| 864 | + $share->setProviderId($this->identifier()); |
|
| 865 | + |
|
| 866 | + return $share; |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + /** |
|
| 870 | + * @param Share[] $shares |
|
| 871 | + * @param $userId |
|
| 872 | + * @return Share[] The updates shares if no update is found for a share return the original |
|
| 873 | + */ |
|
| 874 | + private function resolveGroupShares($shares, $userId) { |
|
| 875 | + $result = []; |
|
| 876 | + |
|
| 877 | + $start = 0; |
|
| 878 | + while(true) { |
|
| 879 | + /** @var Share[] $shareSlice */ |
|
| 880 | + $shareSlice = array_slice($shares, $start, 100); |
|
| 881 | + $start += 100; |
|
| 882 | + |
|
| 883 | + if ($shareSlice === []) { |
|
| 884 | + break; |
|
| 885 | + } |
|
| 886 | + |
|
| 887 | + /** @var int[] $ids */ |
|
| 888 | + $ids = []; |
|
| 889 | + /** @var Share[] $shareMap */ |
|
| 890 | + $shareMap = []; |
|
| 891 | + |
|
| 892 | + foreach ($shareSlice as $share) { |
|
| 893 | + $ids[] = (int)$share->getId(); |
|
| 894 | + $shareMap[$share->getId()] = $share; |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 898 | + |
|
| 899 | + $query = $qb->select('*') |
|
| 900 | + ->from('share') |
|
| 901 | + ->where($qb->expr()->in('parent', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 902 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))) |
|
| 903 | + ->andWhere($qb->expr()->orX( |
|
| 904 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 905 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 906 | + )); |
|
| 907 | + |
|
| 908 | + $stmt = $query->execute(); |
|
| 909 | + |
|
| 910 | + while($data = $stmt->fetch()) { |
|
| 911 | + $shareMap[$data['parent']]->setPermissions((int)$data['permissions']); |
|
| 912 | + $shareMap[$data['parent']]->setTarget($data['file_target']); |
|
| 913 | + } |
|
| 914 | + |
|
| 915 | + $stmt->closeCursor(); |
|
| 916 | + |
|
| 917 | + foreach ($shareMap as $share) { |
|
| 918 | + $result[] = $share; |
|
| 919 | + } |
|
| 920 | + } |
|
| 921 | + |
|
| 922 | + return $result; |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + /** |
|
| 926 | + * A user is deleted from the system |
|
| 927 | + * So clean up the relevant shares. |
|
| 928 | + * |
|
| 929 | + * @param string $uid |
|
| 930 | + * @param int $shareType |
|
| 931 | + */ |
|
| 932 | + public function userDeleted($uid, $shareType) { |
|
| 933 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 934 | + |
|
| 935 | + $qb->delete('share'); |
|
| 936 | + |
|
| 937 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
| 938 | + /* |
|
| 939 | 939 | * Delete all user shares that are owned by this user |
| 940 | 940 | * or that are received by this user |
| 941 | 941 | */ |
| 942 | 942 | |
| 943 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))); |
|
| 943 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))); |
|
| 944 | 944 | |
| 945 | - $qb->andWhere( |
|
| 946 | - $qb->expr()->orX( |
|
| 947 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), |
|
| 948 | - $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) |
|
| 949 | - ) |
|
| 950 | - ); |
|
| 951 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 952 | - /* |
|
| 945 | + $qb->andWhere( |
|
| 946 | + $qb->expr()->orX( |
|
| 947 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), |
|
| 948 | + $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) |
|
| 949 | + ) |
|
| 950 | + ); |
|
| 951 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 952 | + /* |
|
| 953 | 953 | * Delete all group shares that are owned by this user |
| 954 | 954 | * Or special user group shares that are received by this user |
| 955 | 955 | */ |
| 956 | - $qb->where( |
|
| 957 | - $qb->expr()->andX( |
|
| 958 | - $qb->expr()->orX( |
|
| 959 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
| 960 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)) |
|
| 961 | - ), |
|
| 962 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)) |
|
| 963 | - ) |
|
| 964 | - ); |
|
| 965 | - |
|
| 966 | - $qb->orWhere( |
|
| 967 | - $qb->expr()->andX( |
|
| 968 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)), |
|
| 969 | - $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) |
|
| 970 | - ) |
|
| 971 | - ); |
|
| 972 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 973 | - /* |
|
| 956 | + $qb->where( |
|
| 957 | + $qb->expr()->andX( |
|
| 958 | + $qb->expr()->orX( |
|
| 959 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
| 960 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)) |
|
| 961 | + ), |
|
| 962 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)) |
|
| 963 | + ) |
|
| 964 | + ); |
|
| 965 | + |
|
| 966 | + $qb->orWhere( |
|
| 967 | + $qb->expr()->andX( |
|
| 968 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)), |
|
| 969 | + $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) |
|
| 970 | + ) |
|
| 971 | + ); |
|
| 972 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 973 | + /* |
|
| 974 | 974 | * Delete all link shares owned by this user. |
| 975 | 975 | * And all link shares initiated by this user (until #22327 is in) |
| 976 | 976 | */ |
| 977 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))); |
|
| 978 | - |
|
| 979 | - $qb->andWhere( |
|
| 980 | - $qb->expr()->orX( |
|
| 981 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), |
|
| 982 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($uid)) |
|
| 983 | - ) |
|
| 984 | - ); |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - $qb->execute(); |
|
| 988 | - } |
|
| 989 | - |
|
| 990 | - /** |
|
| 991 | - * Delete all shares received by this group. As well as any custom group |
|
| 992 | - * shares for group members. |
|
| 993 | - * |
|
| 994 | - * @param string $gid |
|
| 995 | - */ |
|
| 996 | - public function groupDeleted($gid) { |
|
| 997 | - /* |
|
| 977 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))); |
|
| 978 | + |
|
| 979 | + $qb->andWhere( |
|
| 980 | + $qb->expr()->orX( |
|
| 981 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), |
|
| 982 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($uid)) |
|
| 983 | + ) |
|
| 984 | + ); |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + $qb->execute(); |
|
| 988 | + } |
|
| 989 | + |
|
| 990 | + /** |
|
| 991 | + * Delete all shares received by this group. As well as any custom group |
|
| 992 | + * shares for group members. |
|
| 993 | + * |
|
| 994 | + * @param string $gid |
|
| 995 | + */ |
|
| 996 | + public function groupDeleted($gid) { |
|
| 997 | + /* |
|
| 998 | 998 | * First delete all custom group shares for group members |
| 999 | 999 | */ |
| 1000 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 1001 | - $qb->select('id') |
|
| 1002 | - ->from('share') |
|
| 1003 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
| 1004 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
| 1005 | - |
|
| 1006 | - $cursor = $qb->execute(); |
|
| 1007 | - $ids = []; |
|
| 1008 | - while($row = $cursor->fetch()) { |
|
| 1009 | - $ids[] = (int)$row['id']; |
|
| 1010 | - } |
|
| 1011 | - $cursor->closeCursor(); |
|
| 1012 | - |
|
| 1013 | - if (!empty($ids)) { |
|
| 1014 | - $chunks = array_chunk($ids, 100); |
|
| 1015 | - foreach ($chunks as $chunk) { |
|
| 1016 | - $qb->delete('share') |
|
| 1017 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
| 1018 | - ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); |
|
| 1019 | - $qb->execute(); |
|
| 1020 | - } |
|
| 1021 | - } |
|
| 1022 | - |
|
| 1023 | - /* |
|
| 1000 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 1001 | + $qb->select('id') |
|
| 1002 | + ->from('share') |
|
| 1003 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
| 1004 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
| 1005 | + |
|
| 1006 | + $cursor = $qb->execute(); |
|
| 1007 | + $ids = []; |
|
| 1008 | + while($row = $cursor->fetch()) { |
|
| 1009 | + $ids[] = (int)$row['id']; |
|
| 1010 | + } |
|
| 1011 | + $cursor->closeCursor(); |
|
| 1012 | + |
|
| 1013 | + if (!empty($ids)) { |
|
| 1014 | + $chunks = array_chunk($ids, 100); |
|
| 1015 | + foreach ($chunks as $chunk) { |
|
| 1016 | + $qb->delete('share') |
|
| 1017 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
| 1018 | + ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); |
|
| 1019 | + $qb->execute(); |
|
| 1020 | + } |
|
| 1021 | + } |
|
| 1022 | + |
|
| 1023 | + /* |
|
| 1024 | 1024 | * Now delete all the group shares |
| 1025 | 1025 | */ |
| 1026 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 1027 | - $qb->delete('share') |
|
| 1028 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
| 1029 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
| 1030 | - $qb->execute(); |
|
| 1031 | - } |
|
| 1032 | - |
|
| 1033 | - /** |
|
| 1034 | - * Delete custom group shares to this group for this user |
|
| 1035 | - * |
|
| 1036 | - * @param string $uid |
|
| 1037 | - * @param string $gid |
|
| 1038 | - */ |
|
| 1039 | - public function userDeletedFromGroup($uid, $gid) { |
|
| 1040 | - /* |
|
| 1026 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 1027 | + $qb->delete('share') |
|
| 1028 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
| 1029 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
| 1030 | + $qb->execute(); |
|
| 1031 | + } |
|
| 1032 | + |
|
| 1033 | + /** |
|
| 1034 | + * Delete custom group shares to this group for this user |
|
| 1035 | + * |
|
| 1036 | + * @param string $uid |
|
| 1037 | + * @param string $gid |
|
| 1038 | + */ |
|
| 1039 | + public function userDeletedFromGroup($uid, $gid) { |
|
| 1040 | + /* |
|
| 1041 | 1041 | * Get all group shares |
| 1042 | 1042 | */ |
| 1043 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 1044 | - $qb->select('id') |
|
| 1045 | - ->from('share') |
|
| 1046 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
| 1047 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
| 1048 | - |
|
| 1049 | - $cursor = $qb->execute(); |
|
| 1050 | - $ids = []; |
|
| 1051 | - while($row = $cursor->fetch()) { |
|
| 1052 | - $ids[] = (int)$row['id']; |
|
| 1053 | - } |
|
| 1054 | - $cursor->closeCursor(); |
|
| 1055 | - |
|
| 1056 | - if (!empty($ids)) { |
|
| 1057 | - $chunks = array_chunk($ids, 100); |
|
| 1058 | - foreach ($chunks as $chunk) { |
|
| 1059 | - /* |
|
| 1043 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 1044 | + $qb->select('id') |
|
| 1045 | + ->from('share') |
|
| 1046 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
| 1047 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
| 1048 | + |
|
| 1049 | + $cursor = $qb->execute(); |
|
| 1050 | + $ids = []; |
|
| 1051 | + while($row = $cursor->fetch()) { |
|
| 1052 | + $ids[] = (int)$row['id']; |
|
| 1053 | + } |
|
| 1054 | + $cursor->closeCursor(); |
|
| 1055 | + |
|
| 1056 | + if (!empty($ids)) { |
|
| 1057 | + $chunks = array_chunk($ids, 100); |
|
| 1058 | + foreach ($chunks as $chunk) { |
|
| 1059 | + /* |
|
| 1060 | 1060 | * Delete all special shares wit this users for the found group shares |
| 1061 | 1061 | */ |
| 1062 | - $qb->delete('share') |
|
| 1063 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
| 1064 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($uid))) |
|
| 1065 | - ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); |
|
| 1066 | - $qb->execute(); |
|
| 1067 | - } |
|
| 1068 | - } |
|
| 1069 | - } |
|
| 1070 | - |
|
| 1071 | - /** |
|
| 1072 | - * @inheritdoc |
|
| 1073 | - */ |
|
| 1074 | - public function getAccessList($nodes, $currentAccess) { |
|
| 1075 | - $ids = []; |
|
| 1076 | - foreach ($nodes as $node) { |
|
| 1077 | - $ids[] = $node->getId(); |
|
| 1078 | - } |
|
| 1079 | - |
|
| 1080 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 1081 | - |
|
| 1082 | - $or = $qb->expr()->orX( |
|
| 1083 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
| 1084 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
| 1085 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)) |
|
| 1086 | - ); |
|
| 1087 | - |
|
| 1088 | - if ($currentAccess) { |
|
| 1089 | - $or->add($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))); |
|
| 1090 | - } |
|
| 1091 | - |
|
| 1092 | - $qb->select('id', 'parent', 'share_type', 'share_with', 'file_source', 'file_target', 'permissions') |
|
| 1093 | - ->from('share') |
|
| 1094 | - ->where( |
|
| 1095 | - $or |
|
| 1096 | - ) |
|
| 1097 | - ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 1098 | - ->andWhere($qb->expr()->orX( |
|
| 1099 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 1100 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 1101 | - )); |
|
| 1102 | - $cursor = $qb->execute(); |
|
| 1103 | - |
|
| 1104 | - $users = []; |
|
| 1105 | - $link = false; |
|
| 1106 | - while($row = $cursor->fetch()) { |
|
| 1107 | - $type = (int)$row['share_type']; |
|
| 1108 | - if ($type === \OCP\Share::SHARE_TYPE_USER) { |
|
| 1109 | - $uid = $row['share_with']; |
|
| 1110 | - $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
| 1111 | - $users[$uid][$row['id']] = $row; |
|
| 1112 | - } else if ($type === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 1113 | - $gid = $row['share_with']; |
|
| 1114 | - $group = $this->groupManager->get($gid); |
|
| 1115 | - |
|
| 1116 | - if ($gid === null) { |
|
| 1117 | - continue; |
|
| 1118 | - } |
|
| 1119 | - |
|
| 1120 | - $userList = $group->getUsers(); |
|
| 1121 | - foreach ($userList as $user) { |
|
| 1122 | - $uid = $user->getUID(); |
|
| 1123 | - $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
| 1124 | - $users[$uid][$row['id']] = $row; |
|
| 1125 | - } |
|
| 1126 | - } else if ($type === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 1127 | - $link = true; |
|
| 1128 | - } else if ($type === self::SHARE_TYPE_USERGROUP) { |
|
| 1129 | - if ($currentAccess === true) { |
|
| 1130 | - $uid = $row['share_with']; |
|
| 1131 | - $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
| 1132 | - $users[$uid][$row['id']] = $row; |
|
| 1133 | - } |
|
| 1134 | - } |
|
| 1135 | - } |
|
| 1136 | - $cursor->closeCursor(); |
|
| 1137 | - |
|
| 1138 | - $users = array_map([$this, 'filterSharesOfUser'], $users); |
|
| 1139 | - |
|
| 1140 | - return ['users' => $users, 'public' => $link]; |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - /** |
|
| 1144 | - * For each user the path with the fewest slashes is returned |
|
| 1145 | - * @param array $shares |
|
| 1146 | - * @return array |
|
| 1147 | - */ |
|
| 1148 | - protected function filterSharesOfUser(array $shares) { |
|
| 1149 | - // Group shares when the user has a share exception |
|
| 1150 | - foreach ($shares as $id => $share) { |
|
| 1151 | - $type = (int) $share['share_type']; |
|
| 1152 | - $permissions = (int) $share['permissions']; |
|
| 1153 | - |
|
| 1154 | - if ($type === self::SHARE_TYPE_USERGROUP) { |
|
| 1155 | - unset($shares[$share['parent']]); |
|
| 1156 | - |
|
| 1157 | - if ($permissions === 0) { |
|
| 1158 | - unset($shares[$id]); |
|
| 1159 | - } |
|
| 1160 | - } |
|
| 1161 | - } |
|
| 1162 | - |
|
| 1163 | - $best = []; |
|
| 1164 | - $bestDepth = 0; |
|
| 1165 | - foreach ($shares as $id => $share) { |
|
| 1166 | - $depth = substr_count($share['file_target'], '/'); |
|
| 1167 | - if (empty($best) || $depth < $bestDepth) { |
|
| 1168 | - $bestDepth = $depth; |
|
| 1169 | - $best = [ |
|
| 1170 | - 'node_id' => $share['file_source'], |
|
| 1171 | - 'node_path' => $share['file_target'], |
|
| 1172 | - ]; |
|
| 1173 | - } |
|
| 1174 | - } |
|
| 1175 | - |
|
| 1176 | - return $best; |
|
| 1177 | - } |
|
| 1062 | + $qb->delete('share') |
|
| 1063 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
| 1064 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($uid))) |
|
| 1065 | + ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); |
|
| 1066 | + $qb->execute(); |
|
| 1067 | + } |
|
| 1068 | + } |
|
| 1069 | + } |
|
| 1070 | + |
|
| 1071 | + /** |
|
| 1072 | + * @inheritdoc |
|
| 1073 | + */ |
|
| 1074 | + public function getAccessList($nodes, $currentAccess) { |
|
| 1075 | + $ids = []; |
|
| 1076 | + foreach ($nodes as $node) { |
|
| 1077 | + $ids[] = $node->getId(); |
|
| 1078 | + } |
|
| 1079 | + |
|
| 1080 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 1081 | + |
|
| 1082 | + $or = $qb->expr()->orX( |
|
| 1083 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
| 1084 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
| 1085 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)) |
|
| 1086 | + ); |
|
| 1087 | + |
|
| 1088 | + if ($currentAccess) { |
|
| 1089 | + $or->add($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))); |
|
| 1090 | + } |
|
| 1091 | + |
|
| 1092 | + $qb->select('id', 'parent', 'share_type', 'share_with', 'file_source', 'file_target', 'permissions') |
|
| 1093 | + ->from('share') |
|
| 1094 | + ->where( |
|
| 1095 | + $or |
|
| 1096 | + ) |
|
| 1097 | + ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 1098 | + ->andWhere($qb->expr()->orX( |
|
| 1099 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 1100 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 1101 | + )); |
|
| 1102 | + $cursor = $qb->execute(); |
|
| 1103 | + |
|
| 1104 | + $users = []; |
|
| 1105 | + $link = false; |
|
| 1106 | + while($row = $cursor->fetch()) { |
|
| 1107 | + $type = (int)$row['share_type']; |
|
| 1108 | + if ($type === \OCP\Share::SHARE_TYPE_USER) { |
|
| 1109 | + $uid = $row['share_with']; |
|
| 1110 | + $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
| 1111 | + $users[$uid][$row['id']] = $row; |
|
| 1112 | + } else if ($type === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 1113 | + $gid = $row['share_with']; |
|
| 1114 | + $group = $this->groupManager->get($gid); |
|
| 1115 | + |
|
| 1116 | + if ($gid === null) { |
|
| 1117 | + continue; |
|
| 1118 | + } |
|
| 1119 | + |
|
| 1120 | + $userList = $group->getUsers(); |
|
| 1121 | + foreach ($userList as $user) { |
|
| 1122 | + $uid = $user->getUID(); |
|
| 1123 | + $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
| 1124 | + $users[$uid][$row['id']] = $row; |
|
| 1125 | + } |
|
| 1126 | + } else if ($type === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 1127 | + $link = true; |
|
| 1128 | + } else if ($type === self::SHARE_TYPE_USERGROUP) { |
|
| 1129 | + if ($currentAccess === true) { |
|
| 1130 | + $uid = $row['share_with']; |
|
| 1131 | + $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
| 1132 | + $users[$uid][$row['id']] = $row; |
|
| 1133 | + } |
|
| 1134 | + } |
|
| 1135 | + } |
|
| 1136 | + $cursor->closeCursor(); |
|
| 1137 | + |
|
| 1138 | + $users = array_map([$this, 'filterSharesOfUser'], $users); |
|
| 1139 | + |
|
| 1140 | + return ['users' => $users, 'public' => $link]; |
|
| 1141 | + } |
|
| 1142 | + |
|
| 1143 | + /** |
|
| 1144 | + * For each user the path with the fewest slashes is returned |
|
| 1145 | + * @param array $shares |
|
| 1146 | + * @return array |
|
| 1147 | + */ |
|
| 1148 | + protected function filterSharesOfUser(array $shares) { |
|
| 1149 | + // Group shares when the user has a share exception |
|
| 1150 | + foreach ($shares as $id => $share) { |
|
| 1151 | + $type = (int) $share['share_type']; |
|
| 1152 | + $permissions = (int) $share['permissions']; |
|
| 1153 | + |
|
| 1154 | + if ($type === self::SHARE_TYPE_USERGROUP) { |
|
| 1155 | + unset($shares[$share['parent']]); |
|
| 1156 | + |
|
| 1157 | + if ($permissions === 0) { |
|
| 1158 | + unset($shares[$id]); |
|
| 1159 | + } |
|
| 1160 | + } |
|
| 1161 | + } |
|
| 1162 | + |
|
| 1163 | + $best = []; |
|
| 1164 | + $bestDepth = 0; |
|
| 1165 | + foreach ($shares as $id => $share) { |
|
| 1166 | + $depth = substr_count($share['file_target'], '/'); |
|
| 1167 | + if (empty($best) || $depth < $bestDepth) { |
|
| 1168 | + $bestDepth = $depth; |
|
| 1169 | + $best = [ |
|
| 1170 | + 'node_id' => $share['file_source'], |
|
| 1171 | + 'node_path' => $share['file_target'], |
|
| 1172 | + ]; |
|
| 1173 | + } |
|
| 1174 | + } |
|
| 1175 | + |
|
| 1176 | + return $best; |
|
| 1177 | + } |
|
| 1178 | 1178 | } |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | ->orderBy('id'); |
| 286 | 286 | |
| 287 | 287 | $cursor = $qb->execute(); |
| 288 | - while($data = $cursor->fetch()) { |
|
| 288 | + while ($data = $cursor->fetch()) { |
|
| 289 | 289 | $children[] = $this->createShare($data); |
| 290 | 290 | } |
| 291 | 291 | $cursor->closeCursor(); |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | $user = $this->userManager->get($recipient); |
| 331 | 331 | |
| 332 | 332 | if (is_null($group)) { |
| 333 | - throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
| 333 | + throw new ProviderException('Group "'.$share->getSharedWith().'" does not exist'); |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | if (!$group->inGroup($user)) { |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | ); |
| 491 | 491 | } |
| 492 | 492 | |
| 493 | - $qb->innerJoin('s', 'filecache' ,'f', 's.file_source = f.fileid'); |
|
| 493 | + $qb->innerJoin('s', 'filecache', 'f', 's.file_source = f.fileid'); |
|
| 494 | 494 | $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
| 495 | 495 | |
| 496 | 496 | $qb->orderBy('id'); |
@@ -546,7 +546,7 @@ discard block |
||
| 546 | 546 | |
| 547 | 547 | $cursor = $qb->execute(); |
| 548 | 548 | $shares = []; |
| 549 | - while($data = $cursor->fetch()) { |
|
| 549 | + while ($data = $cursor->fetch()) { |
|
| 550 | 550 | $shares[] = $this->createShare($data); |
| 551 | 551 | } |
| 552 | 552 | $cursor->closeCursor(); |
@@ -625,7 +625,7 @@ discard block |
||
| 625 | 625 | ->execute(); |
| 626 | 626 | |
| 627 | 627 | $shares = []; |
| 628 | - while($data = $cursor->fetch()) { |
|
| 628 | + while ($data = $cursor->fetch()) { |
|
| 629 | 629 | $shares[] = $this->createShare($data); |
| 630 | 630 | } |
| 631 | 631 | $cursor->closeCursor(); |
@@ -696,7 +696,7 @@ discard block |
||
| 696 | 696 | |
| 697 | 697 | $cursor = $qb->execute(); |
| 698 | 698 | |
| 699 | - while($data = $cursor->fetch()) { |
|
| 699 | + while ($data = $cursor->fetch()) { |
|
| 700 | 700 | if ($this->isAccessibleResult($data)) { |
| 701 | 701 | $shares[] = $this->createShare($data); |
| 702 | 702 | } |
@@ -711,7 +711,7 @@ discard block |
||
| 711 | 711 | $shares2 = []; |
| 712 | 712 | |
| 713 | 713 | $start = 0; |
| 714 | - while(true) { |
|
| 714 | + while (true) { |
|
| 715 | 715 | $groups = array_slice($allGroups, $start, 100); |
| 716 | 716 | $start += 100; |
| 717 | 717 | |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | )); |
| 755 | 755 | |
| 756 | 756 | $cursor = $qb->execute(); |
| 757 | - while($data = $cursor->fetch()) { |
|
| 757 | + while ($data = $cursor->fetch()) { |
|
| 758 | 758 | if ($offset > 0) { |
| 759 | 759 | $offset--; |
| 760 | 760 | continue; |
@@ -823,14 +823,14 @@ discard block |
||
| 823 | 823 | */ |
| 824 | 824 | private function createShare($data) { |
| 825 | 825 | $share = new Share($this->rootFolder, $this->userManager); |
| 826 | - $share->setId((int)$data['id']) |
|
| 827 | - ->setShareType((int)$data['share_type']) |
|
| 828 | - ->setPermissions((int)$data['permissions']) |
|
| 826 | + $share->setId((int) $data['id']) |
|
| 827 | + ->setShareType((int) $data['share_type']) |
|
| 828 | + ->setPermissions((int) $data['permissions']) |
|
| 829 | 829 | ->setTarget($data['file_target']) |
| 830 | - ->setMailSend((bool)$data['mail_send']); |
|
| 830 | + ->setMailSend((bool) $data['mail_send']); |
|
| 831 | 831 | |
| 832 | 832 | $shareTime = new \DateTime(); |
| 833 | - $shareTime->setTimestamp((int)$data['stime']); |
|
| 833 | + $shareTime->setTimestamp((int) $data['stime']); |
|
| 834 | 834 | $share->setShareTime($shareTime); |
| 835 | 835 | |
| 836 | 836 | if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
@@ -845,7 +845,7 @@ discard block |
||
| 845 | 845 | $share->setSharedBy($data['uid_initiator']); |
| 846 | 846 | $share->setShareOwner($data['uid_owner']); |
| 847 | 847 | |
| 848 | - $share->setNodeId((int)$data['file_source']); |
|
| 848 | + $share->setNodeId((int) $data['file_source']); |
|
| 849 | 849 | $share->setNodeType($data['item_type']); |
| 850 | 850 | |
| 851 | 851 | if ($data['expiration'] !== null) { |
@@ -856,7 +856,7 @@ discard block |
||
| 856 | 856 | if (isset($data['f_permissions'])) { |
| 857 | 857 | $entryData = $data; |
| 858 | 858 | $entryData['permissions'] = $entryData['f_permissions']; |
| 859 | - $entryData['parent'] = $entryData['f_parent'];; |
|
| 859 | + $entryData['parent'] = $entryData['f_parent']; ; |
|
| 860 | 860 | $share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData, |
| 861 | 861 | \OC::$server->getMimeTypeLoader())); |
| 862 | 862 | } |
@@ -875,7 +875,7 @@ discard block |
||
| 875 | 875 | $result = []; |
| 876 | 876 | |
| 877 | 877 | $start = 0; |
| 878 | - while(true) { |
|
| 878 | + while (true) { |
|
| 879 | 879 | /** @var Share[] $shareSlice */ |
| 880 | 880 | $shareSlice = array_slice($shares, $start, 100); |
| 881 | 881 | $start += 100; |
@@ -890,7 +890,7 @@ discard block |
||
| 890 | 890 | $shareMap = []; |
| 891 | 891 | |
| 892 | 892 | foreach ($shareSlice as $share) { |
| 893 | - $ids[] = (int)$share->getId(); |
|
| 893 | + $ids[] = (int) $share->getId(); |
|
| 894 | 894 | $shareMap[$share->getId()] = $share; |
| 895 | 895 | } |
| 896 | 896 | |
@@ -907,8 +907,8 @@ discard block |
||
| 907 | 907 | |
| 908 | 908 | $stmt = $query->execute(); |
| 909 | 909 | |
| 910 | - while($data = $stmt->fetch()) { |
|
| 911 | - $shareMap[$data['parent']]->setPermissions((int)$data['permissions']); |
|
| 910 | + while ($data = $stmt->fetch()) { |
|
| 911 | + $shareMap[$data['parent']]->setPermissions((int) $data['permissions']); |
|
| 912 | 912 | $shareMap[$data['parent']]->setTarget($data['file_target']); |
| 913 | 913 | } |
| 914 | 914 | |
@@ -1005,8 +1005,8 @@ discard block |
||
| 1005 | 1005 | |
| 1006 | 1006 | $cursor = $qb->execute(); |
| 1007 | 1007 | $ids = []; |
| 1008 | - while($row = $cursor->fetch()) { |
|
| 1009 | - $ids[] = (int)$row['id']; |
|
| 1008 | + while ($row = $cursor->fetch()) { |
|
| 1009 | + $ids[] = (int) $row['id']; |
|
| 1010 | 1010 | } |
| 1011 | 1011 | $cursor->closeCursor(); |
| 1012 | 1012 | |
@@ -1048,8 +1048,8 @@ discard block |
||
| 1048 | 1048 | |
| 1049 | 1049 | $cursor = $qb->execute(); |
| 1050 | 1050 | $ids = []; |
| 1051 | - while($row = $cursor->fetch()) { |
|
| 1052 | - $ids[] = (int)$row['id']; |
|
| 1051 | + while ($row = $cursor->fetch()) { |
|
| 1052 | + $ids[] = (int) $row['id']; |
|
| 1053 | 1053 | } |
| 1054 | 1054 | $cursor->closeCursor(); |
| 1055 | 1055 | |
@@ -1103,8 +1103,8 @@ discard block |
||
| 1103 | 1103 | |
| 1104 | 1104 | $users = []; |
| 1105 | 1105 | $link = false; |
| 1106 | - while($row = $cursor->fetch()) { |
|
| 1107 | - $type = (int)$row['share_type']; |
|
| 1106 | + while ($row = $cursor->fetch()) { |
|
| 1107 | + $type = (int) $row['share_type']; |
|
| 1108 | 1108 | if ($type === \OCP\Share::SHARE_TYPE_USER) { |
| 1109 | 1109 | $uid = $row['share_with']; |
| 1110 | 1110 | $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
@@ -62,357 +62,357 @@ |
||
| 62 | 62 | |
| 63 | 63 | class DIContainer extends SimpleContainer implements IAppContainer { |
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @var array |
|
| 67 | - */ |
|
| 68 | - private $middleWares = array(); |
|
| 69 | - |
|
| 70 | - /** @var ServerContainer */ |
|
| 71 | - private $server; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Put your class dependencies in here |
|
| 75 | - * @param string $appName the name of the app |
|
| 76 | - * @param array $urlParams |
|
| 77 | - * @param ServerContainer $server |
|
| 78 | - */ |
|
| 79 | - public function __construct($appName, $urlParams = array(), ServerContainer $server = null){ |
|
| 80 | - parent::__construct(); |
|
| 81 | - $this['AppName'] = $appName; |
|
| 82 | - $this['urlParams'] = $urlParams; |
|
| 83 | - |
|
| 84 | - /** @var \OC\ServerContainer $server */ |
|
| 85 | - if ($server === null) { |
|
| 86 | - $server = \OC::$server; |
|
| 87 | - } |
|
| 88 | - $this->server = $server; |
|
| 89 | - $this->server->registerAppContainer($appName, $this); |
|
| 90 | - |
|
| 91 | - // aliases |
|
| 92 | - $this->registerAlias('appName', 'AppName'); |
|
| 93 | - $this->registerAlias('webRoot', 'WebRoot'); |
|
| 94 | - $this->registerAlias('userId', 'UserId'); |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Core services |
|
| 98 | - */ |
|
| 99 | - $this->registerService(IOutput::class, function($c){ |
|
| 100 | - return new Output($this->getServer()->getWebRoot()); |
|
| 101 | - }); |
|
| 102 | - |
|
| 103 | - $this->registerService(Folder::class, function() { |
|
| 104 | - return $this->getServer()->getUserFolder(); |
|
| 105 | - }); |
|
| 106 | - |
|
| 107 | - $this->registerService(IAppData::class, function (SimpleContainer $c) { |
|
| 108 | - return $this->getServer()->getAppDataDir($c->query('AppName')); |
|
| 109 | - }); |
|
| 110 | - |
|
| 111 | - $this->registerService(IL10N::class, function($c) { |
|
| 112 | - return $this->getServer()->getL10N($c->query('AppName')); |
|
| 113 | - }); |
|
| 114 | - |
|
| 115 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 116 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 117 | - |
|
| 118 | - $this->registerService(IRequest::class, function() { |
|
| 119 | - return $this->getServer()->query(IRequest::class); |
|
| 120 | - }); |
|
| 121 | - $this->registerAlias('Request', IRequest::class); |
|
| 122 | - |
|
| 123 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 124 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 125 | - |
|
| 126 | - $this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class); |
|
| 127 | - |
|
| 128 | - $this->registerService(IServerContainer::class, function ($c) { |
|
| 129 | - return $this->getServer(); |
|
| 130 | - }); |
|
| 131 | - $this->registerAlias('ServerContainer', IServerContainer::class); |
|
| 132 | - |
|
| 133 | - $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) { |
|
| 134 | - return $c->query('OCA\WorkflowEngine\Manager'); |
|
| 135 | - }); |
|
| 136 | - |
|
| 137 | - $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) { |
|
| 138 | - return $c; |
|
| 139 | - }); |
|
| 140 | - |
|
| 141 | - // commonly used attributes |
|
| 142 | - $this->registerService('UserId', function ($c) { |
|
| 143 | - return $c->query('OCP\\IUserSession')->getSession()->get('user_id'); |
|
| 144 | - }); |
|
| 145 | - |
|
| 146 | - $this->registerService('WebRoot', function ($c) { |
|
| 147 | - return $c->query('ServerContainer')->getWebRoot(); |
|
| 148 | - }); |
|
| 149 | - |
|
| 150 | - $this->registerService('fromMailAddress', function() { |
|
| 151 | - return Util::getDefaultEmailAddress('no-reply'); |
|
| 152 | - }); |
|
| 153 | - |
|
| 154 | - $this->registerService('OC_Defaults', function ($c) { |
|
| 155 | - return $c->getServer()->getThemingDefaults(); |
|
| 156 | - }); |
|
| 157 | - |
|
| 158 | - $this->registerService('OCP\Encryption\IManager', function ($c) { |
|
| 159 | - return $this->getServer()->getEncryptionManager(); |
|
| 160 | - }); |
|
| 161 | - |
|
| 162 | - $this->registerService(IValidator::class, function($c) { |
|
| 163 | - return $c->query(Validator::class); |
|
| 164 | - }); |
|
| 165 | - |
|
| 166 | - $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) { |
|
| 167 | - return new \OC\Security\IdentityProof\Manager( |
|
| 168 | - $this->getServer()->getAppDataDir('identityproof'), |
|
| 169 | - $this->getServer()->getCrypto() |
|
| 170 | - ); |
|
| 171 | - }); |
|
| 172 | - |
|
| 173 | - $this->registerService(IShareHelper::class, function (SimpleContainer $c) { |
|
| 174 | - return $c->query(IShareHelper::class); |
|
| 175 | - }); |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * App Framework APIs |
|
| 180 | - */ |
|
| 181 | - $this->registerService('API', function($c){ |
|
| 182 | - $c->query('OCP\\ILogger')->debug( |
|
| 183 | - 'Accessing the API class is deprecated! Use the appropriate ' . |
|
| 184 | - 'services instead!' |
|
| 185 | - ); |
|
| 186 | - return new API($c['AppName']); |
|
| 187 | - }); |
|
| 188 | - |
|
| 189 | - $this->registerService('Protocol', function($c){ |
|
| 190 | - /** @var \OC\Server $server */ |
|
| 191 | - $server = $c->query('ServerContainer'); |
|
| 192 | - $protocol = $server->getRequest()->getHttpProtocol(); |
|
| 193 | - return new Http($_SERVER, $protocol); |
|
| 194 | - }); |
|
| 195 | - |
|
| 196 | - $this->registerService('Dispatcher', function($c) { |
|
| 197 | - return new Dispatcher( |
|
| 198 | - $c['Protocol'], |
|
| 199 | - $c['MiddlewareDispatcher'], |
|
| 200 | - $c['ControllerMethodReflector'], |
|
| 201 | - $c['Request'] |
|
| 202 | - ); |
|
| 203 | - }); |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * App Framework default arguments |
|
| 207 | - */ |
|
| 208 | - $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
|
| 209 | - $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
|
| 210 | - $this->registerParameter('corsMaxAge', 1728000); |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Middleware |
|
| 214 | - */ |
|
| 215 | - $app = $this; |
|
| 216 | - $this->registerService('SecurityMiddleware', function($c) use ($app){ |
|
| 217 | - /** @var \OC\Server $server */ |
|
| 218 | - $server = $app->getServer(); |
|
| 219 | - |
|
| 220 | - return new SecurityMiddleware( |
|
| 221 | - $c['Request'], |
|
| 222 | - $c['ControllerMethodReflector'], |
|
| 223 | - $server->getNavigationManager(), |
|
| 224 | - $server->getURLGenerator(), |
|
| 225 | - $server->getLogger(), |
|
| 226 | - $server->getSession(), |
|
| 227 | - $c['AppName'], |
|
| 228 | - $app->isLoggedIn(), |
|
| 229 | - $app->isAdminUser(), |
|
| 230 | - $server->getContentSecurityPolicyManager(), |
|
| 231 | - $server->getCsrfTokenManager(), |
|
| 232 | - $server->getContentSecurityPolicyNonceManager(), |
|
| 233 | - $server->getBruteForceThrottler() |
|
| 234 | - ); |
|
| 235 | - |
|
| 236 | - }); |
|
| 237 | - |
|
| 238 | - $this->registerService('CORSMiddleware', function($c) { |
|
| 239 | - return new CORSMiddleware( |
|
| 240 | - $c['Request'], |
|
| 241 | - $c['ControllerMethodReflector'], |
|
| 242 | - $c->query(IUserSession::class), |
|
| 243 | - $c->getServer()->getBruteForceThrottler() |
|
| 244 | - ); |
|
| 245 | - }); |
|
| 246 | - |
|
| 247 | - $this->registerService('SessionMiddleware', function($c) use ($app) { |
|
| 248 | - return new SessionMiddleware( |
|
| 249 | - $c['Request'], |
|
| 250 | - $c['ControllerMethodReflector'], |
|
| 251 | - $app->getServer()->getSession() |
|
| 252 | - ); |
|
| 253 | - }); |
|
| 254 | - |
|
| 255 | - $this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) { |
|
| 256 | - $twoFactorManager = $c->getServer()->getTwoFactorAuthManager(); |
|
| 257 | - $userSession = $app->getServer()->getUserSession(); |
|
| 258 | - $session = $app->getServer()->getSession(); |
|
| 259 | - $urlGenerator = $app->getServer()->getURLGenerator(); |
|
| 260 | - $reflector = $c['ControllerMethodReflector']; |
|
| 261 | - $request = $app->getServer()->getRequest(); |
|
| 262 | - return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request); |
|
| 263 | - }); |
|
| 264 | - |
|
| 265 | - $this->registerService('OCSMiddleware', function (SimpleContainer $c) { |
|
| 266 | - return new OCSMiddleware( |
|
| 267 | - $c['Request'] |
|
| 268 | - ); |
|
| 269 | - }); |
|
| 270 | - |
|
| 271 | - $middleWares = &$this->middleWares; |
|
| 272 | - $this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) { |
|
| 273 | - $dispatcher = new MiddlewareDispatcher(); |
|
| 274 | - $dispatcher->registerMiddleware($c['CORSMiddleware']); |
|
| 275 | - $dispatcher->registerMiddleware($c['OCSMiddleware']); |
|
| 276 | - $dispatcher->registerMiddleware($c['SecurityMiddleware']); |
|
| 277 | - $dispatcher->registerMiddleWare($c['TwoFactorMiddleware']); |
|
| 278 | - |
|
| 279 | - foreach($middleWares as $middleWare) { |
|
| 280 | - $dispatcher->registerMiddleware($c[$middleWare]); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - $dispatcher->registerMiddleware($c['SessionMiddleware']); |
|
| 284 | - return $dispatcher; |
|
| 285 | - }); |
|
| 286 | - |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * @deprecated implements only deprecated methods |
|
| 292 | - * @return IApi |
|
| 293 | - */ |
|
| 294 | - function getCoreApi() |
|
| 295 | - { |
|
| 296 | - return $this->query('API'); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * @return \OCP\IServerContainer |
|
| 301 | - */ |
|
| 302 | - function getServer() |
|
| 303 | - { |
|
| 304 | - return $this->server; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * @param string $middleWare |
|
| 309 | - * @return boolean|null |
|
| 310 | - */ |
|
| 311 | - function registerMiddleWare($middleWare) { |
|
| 312 | - array_push($this->middleWares, $middleWare); |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * used to return the appname of the set application |
|
| 317 | - * @return string the name of your application |
|
| 318 | - */ |
|
| 319 | - function getAppName() { |
|
| 320 | - return $this->query('AppName'); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * @deprecated use IUserSession->isLoggedIn() |
|
| 325 | - * @return boolean |
|
| 326 | - */ |
|
| 327 | - function isLoggedIn() { |
|
| 328 | - return \OC::$server->getUserSession()->isLoggedIn(); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * @deprecated use IGroupManager->isAdmin($userId) |
|
| 333 | - * @return boolean |
|
| 334 | - */ |
|
| 335 | - function isAdminUser() { |
|
| 336 | - $uid = $this->getUserId(); |
|
| 337 | - return \OC_User::isAdminUser($uid); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - private function getUserId() { |
|
| 341 | - return $this->getServer()->getSession()->get('user_id'); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * @deprecated use the ILogger instead |
|
| 346 | - * @param string $message |
|
| 347 | - * @param string $level |
|
| 348 | - * @return mixed |
|
| 349 | - */ |
|
| 350 | - function log($message, $level) { |
|
| 351 | - switch($level){ |
|
| 352 | - case 'debug': |
|
| 353 | - $level = \OCP\Util::DEBUG; |
|
| 354 | - break; |
|
| 355 | - case 'info': |
|
| 356 | - $level = \OCP\Util::INFO; |
|
| 357 | - break; |
|
| 358 | - case 'warn': |
|
| 359 | - $level = \OCP\Util::WARN; |
|
| 360 | - break; |
|
| 361 | - case 'fatal': |
|
| 362 | - $level = \OCP\Util::FATAL; |
|
| 363 | - break; |
|
| 364 | - default: |
|
| 365 | - $level = \OCP\Util::ERROR; |
|
| 366 | - break; |
|
| 367 | - } |
|
| 368 | - \OCP\Util::writeLog($this->getAppName(), $message, $level); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Register a capability |
|
| 373 | - * |
|
| 374 | - * @param string $serviceName e.g. 'OCA\Files\Capabilities' |
|
| 375 | - */ |
|
| 376 | - public function registerCapability($serviceName) { |
|
| 377 | - $this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) { |
|
| 378 | - return $this->query($serviceName); |
|
| 379 | - }); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * @param string $name |
|
| 384 | - * @return mixed |
|
| 385 | - * @throws QueryException if the query could not be resolved |
|
| 386 | - */ |
|
| 387 | - public function query($name) { |
|
| 388 | - try { |
|
| 389 | - return $this->queryNoFallback($name); |
|
| 390 | - } catch (QueryException $e) { |
|
| 391 | - return $this->getServer()->query($name); |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * @param string $name |
|
| 397 | - * @return mixed |
|
| 398 | - * @throws QueryException if the query could not be resolved |
|
| 399 | - */ |
|
| 400 | - public function queryNoFallback($name) { |
|
| 401 | - $name = $this->sanitizeName($name); |
|
| 402 | - |
|
| 403 | - if ($this->offsetExists($name)) { |
|
| 404 | - return parent::query($name); |
|
| 405 | - } else { |
|
| 406 | - if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) { |
|
| 407 | - return parent::query($name); |
|
| 408 | - } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { |
|
| 409 | - return parent::query($name); |
|
| 410 | - } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { |
|
| 411 | - return parent::query($name); |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - throw new QueryException('Could not resolve ' . $name . '!' . |
|
| 416 | - ' Class can not be instantiated'); |
|
| 417 | - } |
|
| 65 | + /** |
|
| 66 | + * @var array |
|
| 67 | + */ |
|
| 68 | + private $middleWares = array(); |
|
| 69 | + |
|
| 70 | + /** @var ServerContainer */ |
|
| 71 | + private $server; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Put your class dependencies in here |
|
| 75 | + * @param string $appName the name of the app |
|
| 76 | + * @param array $urlParams |
|
| 77 | + * @param ServerContainer $server |
|
| 78 | + */ |
|
| 79 | + public function __construct($appName, $urlParams = array(), ServerContainer $server = null){ |
|
| 80 | + parent::__construct(); |
|
| 81 | + $this['AppName'] = $appName; |
|
| 82 | + $this['urlParams'] = $urlParams; |
|
| 83 | + |
|
| 84 | + /** @var \OC\ServerContainer $server */ |
|
| 85 | + if ($server === null) { |
|
| 86 | + $server = \OC::$server; |
|
| 87 | + } |
|
| 88 | + $this->server = $server; |
|
| 89 | + $this->server->registerAppContainer($appName, $this); |
|
| 90 | + |
|
| 91 | + // aliases |
|
| 92 | + $this->registerAlias('appName', 'AppName'); |
|
| 93 | + $this->registerAlias('webRoot', 'WebRoot'); |
|
| 94 | + $this->registerAlias('userId', 'UserId'); |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Core services |
|
| 98 | + */ |
|
| 99 | + $this->registerService(IOutput::class, function($c){ |
|
| 100 | + return new Output($this->getServer()->getWebRoot()); |
|
| 101 | + }); |
|
| 102 | + |
|
| 103 | + $this->registerService(Folder::class, function() { |
|
| 104 | + return $this->getServer()->getUserFolder(); |
|
| 105 | + }); |
|
| 106 | + |
|
| 107 | + $this->registerService(IAppData::class, function (SimpleContainer $c) { |
|
| 108 | + return $this->getServer()->getAppDataDir($c->query('AppName')); |
|
| 109 | + }); |
|
| 110 | + |
|
| 111 | + $this->registerService(IL10N::class, function($c) { |
|
| 112 | + return $this->getServer()->getL10N($c->query('AppName')); |
|
| 113 | + }); |
|
| 114 | + |
|
| 115 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 116 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 117 | + |
|
| 118 | + $this->registerService(IRequest::class, function() { |
|
| 119 | + return $this->getServer()->query(IRequest::class); |
|
| 120 | + }); |
|
| 121 | + $this->registerAlias('Request', IRequest::class); |
|
| 122 | + |
|
| 123 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 124 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 125 | + |
|
| 126 | + $this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class); |
|
| 127 | + |
|
| 128 | + $this->registerService(IServerContainer::class, function ($c) { |
|
| 129 | + return $this->getServer(); |
|
| 130 | + }); |
|
| 131 | + $this->registerAlias('ServerContainer', IServerContainer::class); |
|
| 132 | + |
|
| 133 | + $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) { |
|
| 134 | + return $c->query('OCA\WorkflowEngine\Manager'); |
|
| 135 | + }); |
|
| 136 | + |
|
| 137 | + $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) { |
|
| 138 | + return $c; |
|
| 139 | + }); |
|
| 140 | + |
|
| 141 | + // commonly used attributes |
|
| 142 | + $this->registerService('UserId', function ($c) { |
|
| 143 | + return $c->query('OCP\\IUserSession')->getSession()->get('user_id'); |
|
| 144 | + }); |
|
| 145 | + |
|
| 146 | + $this->registerService('WebRoot', function ($c) { |
|
| 147 | + return $c->query('ServerContainer')->getWebRoot(); |
|
| 148 | + }); |
|
| 149 | + |
|
| 150 | + $this->registerService('fromMailAddress', function() { |
|
| 151 | + return Util::getDefaultEmailAddress('no-reply'); |
|
| 152 | + }); |
|
| 153 | + |
|
| 154 | + $this->registerService('OC_Defaults', function ($c) { |
|
| 155 | + return $c->getServer()->getThemingDefaults(); |
|
| 156 | + }); |
|
| 157 | + |
|
| 158 | + $this->registerService('OCP\Encryption\IManager', function ($c) { |
|
| 159 | + return $this->getServer()->getEncryptionManager(); |
|
| 160 | + }); |
|
| 161 | + |
|
| 162 | + $this->registerService(IValidator::class, function($c) { |
|
| 163 | + return $c->query(Validator::class); |
|
| 164 | + }); |
|
| 165 | + |
|
| 166 | + $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) { |
|
| 167 | + return new \OC\Security\IdentityProof\Manager( |
|
| 168 | + $this->getServer()->getAppDataDir('identityproof'), |
|
| 169 | + $this->getServer()->getCrypto() |
|
| 170 | + ); |
|
| 171 | + }); |
|
| 172 | + |
|
| 173 | + $this->registerService(IShareHelper::class, function (SimpleContainer $c) { |
|
| 174 | + return $c->query(IShareHelper::class); |
|
| 175 | + }); |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * App Framework APIs |
|
| 180 | + */ |
|
| 181 | + $this->registerService('API', function($c){ |
|
| 182 | + $c->query('OCP\\ILogger')->debug( |
|
| 183 | + 'Accessing the API class is deprecated! Use the appropriate ' . |
|
| 184 | + 'services instead!' |
|
| 185 | + ); |
|
| 186 | + return new API($c['AppName']); |
|
| 187 | + }); |
|
| 188 | + |
|
| 189 | + $this->registerService('Protocol', function($c){ |
|
| 190 | + /** @var \OC\Server $server */ |
|
| 191 | + $server = $c->query('ServerContainer'); |
|
| 192 | + $protocol = $server->getRequest()->getHttpProtocol(); |
|
| 193 | + return new Http($_SERVER, $protocol); |
|
| 194 | + }); |
|
| 195 | + |
|
| 196 | + $this->registerService('Dispatcher', function($c) { |
|
| 197 | + return new Dispatcher( |
|
| 198 | + $c['Protocol'], |
|
| 199 | + $c['MiddlewareDispatcher'], |
|
| 200 | + $c['ControllerMethodReflector'], |
|
| 201 | + $c['Request'] |
|
| 202 | + ); |
|
| 203 | + }); |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * App Framework default arguments |
|
| 207 | + */ |
|
| 208 | + $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
|
| 209 | + $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
|
| 210 | + $this->registerParameter('corsMaxAge', 1728000); |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Middleware |
|
| 214 | + */ |
|
| 215 | + $app = $this; |
|
| 216 | + $this->registerService('SecurityMiddleware', function($c) use ($app){ |
|
| 217 | + /** @var \OC\Server $server */ |
|
| 218 | + $server = $app->getServer(); |
|
| 219 | + |
|
| 220 | + return new SecurityMiddleware( |
|
| 221 | + $c['Request'], |
|
| 222 | + $c['ControllerMethodReflector'], |
|
| 223 | + $server->getNavigationManager(), |
|
| 224 | + $server->getURLGenerator(), |
|
| 225 | + $server->getLogger(), |
|
| 226 | + $server->getSession(), |
|
| 227 | + $c['AppName'], |
|
| 228 | + $app->isLoggedIn(), |
|
| 229 | + $app->isAdminUser(), |
|
| 230 | + $server->getContentSecurityPolicyManager(), |
|
| 231 | + $server->getCsrfTokenManager(), |
|
| 232 | + $server->getContentSecurityPolicyNonceManager(), |
|
| 233 | + $server->getBruteForceThrottler() |
|
| 234 | + ); |
|
| 235 | + |
|
| 236 | + }); |
|
| 237 | + |
|
| 238 | + $this->registerService('CORSMiddleware', function($c) { |
|
| 239 | + return new CORSMiddleware( |
|
| 240 | + $c['Request'], |
|
| 241 | + $c['ControllerMethodReflector'], |
|
| 242 | + $c->query(IUserSession::class), |
|
| 243 | + $c->getServer()->getBruteForceThrottler() |
|
| 244 | + ); |
|
| 245 | + }); |
|
| 246 | + |
|
| 247 | + $this->registerService('SessionMiddleware', function($c) use ($app) { |
|
| 248 | + return new SessionMiddleware( |
|
| 249 | + $c['Request'], |
|
| 250 | + $c['ControllerMethodReflector'], |
|
| 251 | + $app->getServer()->getSession() |
|
| 252 | + ); |
|
| 253 | + }); |
|
| 254 | + |
|
| 255 | + $this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) { |
|
| 256 | + $twoFactorManager = $c->getServer()->getTwoFactorAuthManager(); |
|
| 257 | + $userSession = $app->getServer()->getUserSession(); |
|
| 258 | + $session = $app->getServer()->getSession(); |
|
| 259 | + $urlGenerator = $app->getServer()->getURLGenerator(); |
|
| 260 | + $reflector = $c['ControllerMethodReflector']; |
|
| 261 | + $request = $app->getServer()->getRequest(); |
|
| 262 | + return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request); |
|
| 263 | + }); |
|
| 264 | + |
|
| 265 | + $this->registerService('OCSMiddleware', function (SimpleContainer $c) { |
|
| 266 | + return new OCSMiddleware( |
|
| 267 | + $c['Request'] |
|
| 268 | + ); |
|
| 269 | + }); |
|
| 270 | + |
|
| 271 | + $middleWares = &$this->middleWares; |
|
| 272 | + $this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) { |
|
| 273 | + $dispatcher = new MiddlewareDispatcher(); |
|
| 274 | + $dispatcher->registerMiddleware($c['CORSMiddleware']); |
|
| 275 | + $dispatcher->registerMiddleware($c['OCSMiddleware']); |
|
| 276 | + $dispatcher->registerMiddleware($c['SecurityMiddleware']); |
|
| 277 | + $dispatcher->registerMiddleWare($c['TwoFactorMiddleware']); |
|
| 278 | + |
|
| 279 | + foreach($middleWares as $middleWare) { |
|
| 280 | + $dispatcher->registerMiddleware($c[$middleWare]); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + $dispatcher->registerMiddleware($c['SessionMiddleware']); |
|
| 284 | + return $dispatcher; |
|
| 285 | + }); |
|
| 286 | + |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * @deprecated implements only deprecated methods |
|
| 292 | + * @return IApi |
|
| 293 | + */ |
|
| 294 | + function getCoreApi() |
|
| 295 | + { |
|
| 296 | + return $this->query('API'); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * @return \OCP\IServerContainer |
|
| 301 | + */ |
|
| 302 | + function getServer() |
|
| 303 | + { |
|
| 304 | + return $this->server; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * @param string $middleWare |
|
| 309 | + * @return boolean|null |
|
| 310 | + */ |
|
| 311 | + function registerMiddleWare($middleWare) { |
|
| 312 | + array_push($this->middleWares, $middleWare); |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * used to return the appname of the set application |
|
| 317 | + * @return string the name of your application |
|
| 318 | + */ |
|
| 319 | + function getAppName() { |
|
| 320 | + return $this->query('AppName'); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * @deprecated use IUserSession->isLoggedIn() |
|
| 325 | + * @return boolean |
|
| 326 | + */ |
|
| 327 | + function isLoggedIn() { |
|
| 328 | + return \OC::$server->getUserSession()->isLoggedIn(); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * @deprecated use IGroupManager->isAdmin($userId) |
|
| 333 | + * @return boolean |
|
| 334 | + */ |
|
| 335 | + function isAdminUser() { |
|
| 336 | + $uid = $this->getUserId(); |
|
| 337 | + return \OC_User::isAdminUser($uid); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + private function getUserId() { |
|
| 341 | + return $this->getServer()->getSession()->get('user_id'); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * @deprecated use the ILogger instead |
|
| 346 | + * @param string $message |
|
| 347 | + * @param string $level |
|
| 348 | + * @return mixed |
|
| 349 | + */ |
|
| 350 | + function log($message, $level) { |
|
| 351 | + switch($level){ |
|
| 352 | + case 'debug': |
|
| 353 | + $level = \OCP\Util::DEBUG; |
|
| 354 | + break; |
|
| 355 | + case 'info': |
|
| 356 | + $level = \OCP\Util::INFO; |
|
| 357 | + break; |
|
| 358 | + case 'warn': |
|
| 359 | + $level = \OCP\Util::WARN; |
|
| 360 | + break; |
|
| 361 | + case 'fatal': |
|
| 362 | + $level = \OCP\Util::FATAL; |
|
| 363 | + break; |
|
| 364 | + default: |
|
| 365 | + $level = \OCP\Util::ERROR; |
|
| 366 | + break; |
|
| 367 | + } |
|
| 368 | + \OCP\Util::writeLog($this->getAppName(), $message, $level); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Register a capability |
|
| 373 | + * |
|
| 374 | + * @param string $serviceName e.g. 'OCA\Files\Capabilities' |
|
| 375 | + */ |
|
| 376 | + public function registerCapability($serviceName) { |
|
| 377 | + $this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) { |
|
| 378 | + return $this->query($serviceName); |
|
| 379 | + }); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * @param string $name |
|
| 384 | + * @return mixed |
|
| 385 | + * @throws QueryException if the query could not be resolved |
|
| 386 | + */ |
|
| 387 | + public function query($name) { |
|
| 388 | + try { |
|
| 389 | + return $this->queryNoFallback($name); |
|
| 390 | + } catch (QueryException $e) { |
|
| 391 | + return $this->getServer()->query($name); |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * @param string $name |
|
| 397 | + * @return mixed |
|
| 398 | + * @throws QueryException if the query could not be resolved |
|
| 399 | + */ |
|
| 400 | + public function queryNoFallback($name) { |
|
| 401 | + $name = $this->sanitizeName($name); |
|
| 402 | + |
|
| 403 | + if ($this->offsetExists($name)) { |
|
| 404 | + return parent::query($name); |
|
| 405 | + } else { |
|
| 406 | + if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) { |
|
| 407 | + return parent::query($name); |
|
| 408 | + } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { |
|
| 409 | + return parent::query($name); |
|
| 410 | + } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { |
|
| 411 | + return parent::query($name); |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + throw new QueryException('Could not resolve ' . $name . '!' . |
|
| 416 | + ' Class can not be instantiated'); |
|
| 417 | + } |
|
| 418 | 418 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * @param array $urlParams |
| 77 | 77 | * @param ServerContainer $server |
| 78 | 78 | */ |
| 79 | - public function __construct($appName, $urlParams = array(), ServerContainer $server = null){ |
|
| 79 | + public function __construct($appName, $urlParams = array(), ServerContainer $server = null) { |
|
| 80 | 80 | parent::__construct(); |
| 81 | 81 | $this['AppName'] = $appName; |
| 82 | 82 | $this['urlParams'] = $urlParams; |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | /** |
| 97 | 97 | * Core services |
| 98 | 98 | */ |
| 99 | - $this->registerService(IOutput::class, function($c){ |
|
| 99 | + $this->registerService(IOutput::class, function($c) { |
|
| 100 | 100 | return new Output($this->getServer()->getWebRoot()); |
| 101 | 101 | }); |
| 102 | 102 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | return $this->getServer()->getUserFolder(); |
| 105 | 105 | }); |
| 106 | 106 | |
| 107 | - $this->registerService(IAppData::class, function (SimpleContainer $c) { |
|
| 107 | + $this->registerService(IAppData::class, function(SimpleContainer $c) { |
|
| 108 | 108 | return $this->getServer()->getAppDataDir($c->query('AppName')); |
| 109 | 109 | }); |
| 110 | 110 | |
@@ -125,25 +125,25 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | $this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class); |
| 127 | 127 | |
| 128 | - $this->registerService(IServerContainer::class, function ($c) { |
|
| 128 | + $this->registerService(IServerContainer::class, function($c) { |
|
| 129 | 129 | return $this->getServer(); |
| 130 | 130 | }); |
| 131 | 131 | $this->registerAlias('ServerContainer', IServerContainer::class); |
| 132 | 132 | |
| 133 | - $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) { |
|
| 133 | + $this->registerService(\OCP\WorkflowEngine\IManager::class, function($c) { |
|
| 134 | 134 | return $c->query('OCA\WorkflowEngine\Manager'); |
| 135 | 135 | }); |
| 136 | 136 | |
| 137 | - $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) { |
|
| 137 | + $this->registerService(\OCP\AppFramework\IAppContainer::class, function($c) { |
|
| 138 | 138 | return $c; |
| 139 | 139 | }); |
| 140 | 140 | |
| 141 | 141 | // commonly used attributes |
| 142 | - $this->registerService('UserId', function ($c) { |
|
| 142 | + $this->registerService('UserId', function($c) { |
|
| 143 | 143 | return $c->query('OCP\\IUserSession')->getSession()->get('user_id'); |
| 144 | 144 | }); |
| 145 | 145 | |
| 146 | - $this->registerService('WebRoot', function ($c) { |
|
| 146 | + $this->registerService('WebRoot', function($c) { |
|
| 147 | 147 | return $c->query('ServerContainer')->getWebRoot(); |
| 148 | 148 | }); |
| 149 | 149 | |
@@ -151,11 +151,11 @@ discard block |
||
| 151 | 151 | return Util::getDefaultEmailAddress('no-reply'); |
| 152 | 152 | }); |
| 153 | 153 | |
| 154 | - $this->registerService('OC_Defaults', function ($c) { |
|
| 154 | + $this->registerService('OC_Defaults', function($c) { |
|
| 155 | 155 | return $c->getServer()->getThemingDefaults(); |
| 156 | 156 | }); |
| 157 | 157 | |
| 158 | - $this->registerService('OCP\Encryption\IManager', function ($c) { |
|
| 158 | + $this->registerService('OCP\Encryption\IManager', function($c) { |
|
| 159 | 159 | return $this->getServer()->getEncryptionManager(); |
| 160 | 160 | }); |
| 161 | 161 | |
@@ -163,14 +163,14 @@ discard block |
||
| 163 | 163 | return $c->query(Validator::class); |
| 164 | 164 | }); |
| 165 | 165 | |
| 166 | - $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) { |
|
| 166 | + $this->registerService(\OC\Security\IdentityProof\Manager::class, function($c) { |
|
| 167 | 167 | return new \OC\Security\IdentityProof\Manager( |
| 168 | 168 | $this->getServer()->getAppDataDir('identityproof'), |
| 169 | 169 | $this->getServer()->getCrypto() |
| 170 | 170 | ); |
| 171 | 171 | }); |
| 172 | 172 | |
| 173 | - $this->registerService(IShareHelper::class, function (SimpleContainer $c) { |
|
| 173 | + $this->registerService(IShareHelper::class, function(SimpleContainer $c) { |
|
| 174 | 174 | return $c->query(IShareHelper::class); |
| 175 | 175 | }); |
| 176 | 176 | |
@@ -178,15 +178,15 @@ discard block |
||
| 178 | 178 | /** |
| 179 | 179 | * App Framework APIs |
| 180 | 180 | */ |
| 181 | - $this->registerService('API', function($c){ |
|
| 181 | + $this->registerService('API', function($c) { |
|
| 182 | 182 | $c->query('OCP\\ILogger')->debug( |
| 183 | - 'Accessing the API class is deprecated! Use the appropriate ' . |
|
| 183 | + 'Accessing the API class is deprecated! Use the appropriate '. |
|
| 184 | 184 | 'services instead!' |
| 185 | 185 | ); |
| 186 | 186 | return new API($c['AppName']); |
| 187 | 187 | }); |
| 188 | 188 | |
| 189 | - $this->registerService('Protocol', function($c){ |
|
| 189 | + $this->registerService('Protocol', function($c) { |
|
| 190 | 190 | /** @var \OC\Server $server */ |
| 191 | 191 | $server = $c->query('ServerContainer'); |
| 192 | 192 | $protocol = $server->getRequest()->getHttpProtocol(); |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | ); |
| 253 | 253 | }); |
| 254 | 254 | |
| 255 | - $this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) { |
|
| 255 | + $this->registerService('TwoFactorMiddleware', function(SimpleContainer $c) use ($app) { |
|
| 256 | 256 | $twoFactorManager = $c->getServer()->getTwoFactorAuthManager(); |
| 257 | 257 | $userSession = $app->getServer()->getUserSession(); |
| 258 | 258 | $session = $app->getServer()->getSession(); |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request); |
| 263 | 263 | }); |
| 264 | 264 | |
| 265 | - $this->registerService('OCSMiddleware', function (SimpleContainer $c) { |
|
| 265 | + $this->registerService('OCSMiddleware', function(SimpleContainer $c) { |
|
| 266 | 266 | return new OCSMiddleware( |
| 267 | 267 | $c['Request'] |
| 268 | 268 | ); |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | $dispatcher->registerMiddleware($c['SecurityMiddleware']); |
| 277 | 277 | $dispatcher->registerMiddleWare($c['TwoFactorMiddleware']); |
| 278 | 278 | |
| 279 | - foreach($middleWares as $middleWare) { |
|
| 279 | + foreach ($middleWares as $middleWare) { |
|
| 280 | 280 | $dispatcher->registerMiddleware($c[$middleWare]); |
| 281 | 281 | } |
| 282 | 282 | |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | * @return mixed |
| 349 | 349 | */ |
| 350 | 350 | function log($message, $level) { |
| 351 | - switch($level){ |
|
| 351 | + switch ($level) { |
|
| 352 | 352 | case 'debug': |
| 353 | 353 | $level = \OCP\Util::DEBUG; |
| 354 | 354 | break; |
@@ -407,12 +407,12 @@ discard block |
||
| 407 | 407 | return parent::query($name); |
| 408 | 408 | } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { |
| 409 | 409 | return parent::query($name); |
| 410 | - } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { |
|
| 410 | + } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']).'\\') === 0) { |
|
| 411 | 411 | return parent::query($name); |
| 412 | 412 | } |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | - throw new QueryException('Could not resolve ' . $name . '!' . |
|
| 415 | + throw new QueryException('Could not resolve '.$name.'!'. |
|
| 416 | 416 | ' Class can not be instantiated'); |
| 417 | 417 | } |
| 418 | 418 | } |