示例#1
0
 /**
  * @param int $id
  * @return \OC_OCS_Result
  */
 public function updateShare($id)
 {
     if (!$this->shareManager->shareApiEnabled()) {
         return new \OC_OCS_Result(null, 404, $this->l->t('Share API is disabled'));
     }
     try {
         $share = $this->getShareById($id);
     } catch (ShareNotFound $e) {
         return new \OC_OCS_Result(null, 404, $this->l->t('Wrong share ID, share doesn\'t exist'));
     }
     $share->getNode()->lock(\OCP\Lock\ILockingProvider::LOCK_SHARED);
     if (!$this->canAccessShare($share)) {
         $share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
         return new \OC_OCS_Result(null, 404, $this->l->t('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);
     /*
      * expirationdate, password and publicUpload only make sense for link shares
      */
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
         if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) {
             $share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
             return new \OC_OCS_Result(null, 400, 'Wrong or no update parameter given');
         }
         $newPermissions = null;
         if ($publicUpload === 'true') {
             $newPermissions = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE;
         } else {
             if ($publicUpload === 'false') {
                 $newPermissions = \OCP\Constants::PERMISSION_READ;
             }
         }
         if ($permissions !== null) {
             $newPermissions = (int) $permissions;
         }
         if ($newPermissions !== null && $newPermissions !== \OCP\Constants::PERMISSION_READ && $newPermissions !== (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE) && $newPermissions !== (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE)) {
             $share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
             return new \OC_OCS_Result(null, 400, $this->l->t('Can\'t change permissions for public share links'));
         }
         if ($newPermissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE) || $newPermissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE)) {
             if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
                 $share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
                 return new \OC_OCS_Result(null, 403, $this->l->t('Public upload disabled by the administrator'));
             }
             if (!$share->getNode() instanceof \OCP\Files\Folder) {
                 $share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
                 return new \OC_OCS_Result(null, 400, $this->l->t('Public upload is only possible for publicly shared folders'));
             }
             // normalize to correct public upload permissions
             $newPermissions = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE;
         }
         if ($newPermissions !== null) {
             $share->setPermissions($newPermissions);
         }
         if ($expireDate === '') {
             $share->setExpirationDate(null);
         } else {
             if ($expireDate !== null) {
                 try {
                     $expireDate = $this->parseDate($expireDate);
                 } catch (\Exception $e) {
                     $share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
                     return new \OC_OCS_Result(null, 400, $e->getMessage());
                 }
                 $share->setExpirationDate($expireDate);
             }
         }
         if ($password === '') {
             $share->setPassword(null);
         } else {
             if ($password !== null) {
                 $share->setPassword($password);
             }
         }
     } else {
         // For other shares only permissions is valid.
         if ($permissions === null) {
             $share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
             return new \OC_OCS_Result(null, 400, $this->l->t('Wrong or no update parameter given'));
         } else {
             $permissions = (int) $permissions;
             $share->setPermissions($permissions);
         }
     }
     if ($permissions !== null) {
         /* Check if this is an incomming share */
         $incomingShares = $this->shareManager->getSharedWith($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0);
         $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0));
         if (!empty($incomingShares)) {
             $maxPermissions = 0;
             foreach ($incomingShares as $incomingShare) {
                 $maxPermissions |= $incomingShare->getPermissions();
             }
             if ($share->getPermissions() & ~$maxPermissions) {
                 $share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
                 return new \OC_OCS_Result(null, 404, $this->l->t('Cannot increase permissions'));
             }
         }
     }
     try {
         $share = $this->shareManager->updateShare($share);
     } catch (\Exception $e) {
         $share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
         return new \OC_OCS_Result(null, 400, $e->getMessage());
     }
     $share->getNode()->unlock(\OCP\Lock\ILockingProvider::LOCK_SHARED);
     return new \OC_OCS_Result($this->formatShare($share));
 }