Example #1
0
 /**
  * @param string $user
  * @return int
  */
 public function getSharePermissions($user)
 {
     // check of we access a federated share
     if ($user !== null) {
         try {
             $share = $this->shareManager->getShareByToken($user);
             return $share->getPermissions();
         } catch (ShareNotFound $e) {
             // ignore
         }
     }
     $storage = $this->info->getStorage();
     $path = $this->info->getInternalPath();
     if ($storage->instanceOfStorage('\\OC\\Files\\Storage\\Shared')) {
         /** @var \OC\Files\Storage\Shared $storage */
         $permissions = (int) $storage->getShare()->getPermissions();
     } else {
         $permissions = $storage->getPermissions($path);
     }
     /*
      * We can always share non moveable mount points with DELETE and UPDATE
      * Eventually we need to do this properly
      */
     $mountpoint = $this->info->getMountPoint();
     if (!$mountpoint instanceof MoveableMount) {
         $mountpointpath = $mountpoint->getMountPoint();
         if (substr($mountpointpath, -1) === '/') {
             $mountpointpath = substr($mountpointpath, 0, -1);
         }
         if ($mountpointpath === $this->info->getPath()) {
             $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE;
         }
     }
     /*
      * Files can't have create or delete permissions
      */
     if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
         $permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE);
     }
     return $permissions;
 }