diff options
author | Roeland Jago Douma <rullzer@owncloud.com> | 2016-01-22 14:52:20 +0100 |
---|---|---|
committer | Roeland Jago Douma <rullzer@owncloud.com> | 2016-01-26 13:59:58 +0100 |
commit | 46045ecc528566edcbe302339ce37819e5320e86 (patch) | |
tree | 1519220491b9b3563c6b55a2bdf5e9b1bb3c3aad /apps/files_sharing | |
parent | 3da78c8f1c9355a726f289e834fa237366c3df20 (diff) | |
download | nextcloud-server-46045ecc528566edcbe302339ce37819e5320e86.tar.gz nextcloud-server-46045ecc528566edcbe302339ce37819e5320e86.zip |
[Share 2.0] Add update share
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/api/ocssharewrapper.php | 3 | ||||
-rw-r--r-- | apps/files_sharing/api/share20ocs.php | 66 |
2 files changed, 68 insertions, 1 deletions
diff --git a/apps/files_sharing/api/ocssharewrapper.php b/apps/files_sharing/api/ocssharewrapper.php index cc52d478615..9f63e864cec 100644 --- a/apps/files_sharing/api/ocssharewrapper.php +++ b/apps/files_sharing/api/ocssharewrapper.php @@ -50,7 +50,8 @@ class OCSShareWrapper { } public function updateShare($params) { - return \OCA\Files_Sharing\API\Local::updateShare($params); + $id = $params['id']; + return $this->getShare20OCS()->updateShare($id); } public function deleteShare($params) { diff --git a/apps/files_sharing/api/share20ocs.php b/apps/files_sharing/api/share20ocs.php index c2ff94db790..c5e7dcff824 100644 --- a/apps/files_sharing/api/share20ocs.php +++ b/apps/files_sharing/api/share20ocs.php @@ -426,6 +426,72 @@ class Share20OCS { } /** + * @param int $id + * @return \OC_OCS_Result + */ + public function updateShare($id) { + // Try both our default and our federated provider + $share = null; + + try { + $share = $this->shareManager->getShareById('ocinternal:' . $id); + } catch (\OC\Share20\Exception\ShareNotFound $e) { + //Ignore for now + //return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.'); + } + + // Could not find the share as internal share... maybe it is a federated share + if ($share === null) { + return \OCA\Files_Sharing\API\Local::updateShare(['id' => $id]); + } + + if (!$this->canAccessShare($share)) { + return new \OC_OCS_Result(null, 404, "wrong share Id, share doesn't exist."); + } + + $permissions = $this->request->getParam('permissions', null); + $password = $this->request->getParam('password', null); + $publicUpload = $this->request->getParam('publicUpload', null); + $expireDate = $this->request->getParam('expireDate', null); + + if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) { + return new \OC_OCS_Result(null, 400, 'Wrong or no update parameter given'); + } + + if ($expireDate !== null) { + try { + $expireDate = $this->parseDate($expireDate); + } catch (\Exception $e) { + return new \OC_OCS_Result(null, 400, $e->getMessage()); + } + $share->setExpirationDate($expireDate); + } + + if ($permissions !== null) { + $permissions = (int)$permissions; + $share->setPermissions($permissions); + } + + if ($password !== null) { + $share->setPassword($password); + } + + if ($publicUpload === 'true') { + $share->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE); + } else if ($publicUpload === 'false') { + $share->setPermissions(\OCP\Constants::PERMISSION_READ); + } + + try { + $share = $this->shareManager->updateShare($share); + } catch (\Exception $e) { + return new \OC_OCS_Result(null, 400, $e->getMessage()); + } + + return new \OC_OCS_Result($this->formatShare($share)); + } + + /** * @param IShare $share * @return bool */ |