diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-08-26 13:11:09 +0200 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-10-04 19:25:11 +0200 |
commit | f02cff1304f5a8d4ff4f2f42add72fdfa688dedf (patch) | |
tree | 2253b8a9a04452e789ff6e2a6cce62db42e551ce | |
parent | 6d4f4c1c700ca6fb017f01c5272d48db74221f86 (diff) | |
download | nextcloud-server-f02cff1304f5a8d4ff4f2f42add72fdfa688dedf.tar.gz nextcloud-server-f02cff1304f5a8d4ff4f2f42add72fdfa688dedf.zip |
Extract check for whether a user with access to a share can edit it
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
-rw-r--r-- | apps/files_sharing/lib/Controller/ShareAPIController.php | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 5bd059219bb..f7b297909b5 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -823,7 +823,7 @@ class ShareAPIController extends OCSController { throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); } - if ($share->getShareOwner() !== $this->currentUser && $share->getSharedBy() !== $this->currentUser) { + if (!$this->canEditShare($share)) { throw new OCSForbiddenException('You are not allowed to edit incoming shares'); } @@ -1026,6 +1026,33 @@ class ShareAPIController extends OCSController { } /** + * Does the user have edit permission on the share + * + * @param \OCP\Share\IShare $share the share to check + * @return boolean + */ + protected function canEditShare(\OCP\Share\IShare $share): bool { + // A file with permissions 0 can't be accessed by us. So Don't show it + if ($share->getPermissions() === 0) { + return false; + } + + // The owner of the file and the creator of the share + // can always edit the share + if ($share->getShareOwner() === $this->currentUser || + $share->getSharedBy() === $this->currentUser + ) { + return true; + } + + //! we do NOT support some kind of `admin` in groups. + //! You cannot edit shares shared to a group you're + //! a member of if you're not the share owner or the file owner! + + return false; + } + + /** * Make sure that the passed date is valid ISO 8601 * So YYYY-MM-DD * If not throw an exception |