diff options
author | Joas Schilling <coding@schilljs.com> | 2019-08-22 04:17:17 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2019-11-12 19:33:50 +0300 |
commit | e96c9e0e4a402277a9f18470c77503dd914c6de4 (patch) | |
tree | 5d1442e925f976578354224abdfe4ef2b56d16b5 /apps/files_sharing/lib/Controller | |
parent | dcdbea54e60d13d2508b71ebdcb7992f2ae5ef34 (diff) |
Add the notifier and the API endpoint for user shares
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/files_sharing/lib/Controller')
-rw-r--r-- | apps/files_sharing/lib/Controller/ShareAPIController.php | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 66b2383ea7d..acb95a0a3d3 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -947,6 +947,45 @@ class ShareAPIController extends OCSController { } /** + * @NoAdminRequired + * + * @param string $id + * @return DataResponse + * @throws OCSNotFoundException + * @throws OCSException + * @throws OCSBadRequestException + */ + public function acceptShare(string $id): DataResponse { + try { + $share = $this->getShareById($id); + } catch (ShareNotFound $e) { + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); + } + + if (!$this->canAccessShare($share, false)) { + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); + } + + if ($share->getShareType() !== Share::SHARE_TYPE_USER || + $share->getSharedWith() !== $this->currentUser) { + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); + } + + $share->setStatus(IShare::STATUS_ACCEPTED); + + try { + $this->shareManager->updateShare($share); + } catch (GenericShareException $e) { + $code = $e->getCode() === 0 ? 403 : $e->getCode(); + throw new OCSException($e->getHint(), $code); + } catch (\Exception $e) { + throw new OCSBadRequestException($e->getMessage(), $e); + } + + return new DataResponse(); + } + + /** * Does the user have read permission on the share * * @param \OCP\Share\IShare $share the share to check |