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;
 }
Example #2
0
 /**
  * Formats the file info to be returned as JSON to the client.
  *
  * @param \OCP\Files\FileInfo $i
  * @return array formatted file info
  */
 public static function formatFileInfo(FileInfo $i)
 {
     $entry = array();
     $entry['id'] = $i['fileid'];
     $entry['parentId'] = $i['parent'];
     $entry['mtime'] = $i['mtime'] * 1000;
     // only pick out the needed attributes
     $entry['name'] = $i->getName();
     $entry['permissions'] = $i['permissions'];
     $entry['mimetype'] = $i['mimetype'];
     $entry['size'] = $i['size'];
     $entry['type'] = $i['type'];
     $entry['etag'] = $i['etag'];
     if (isset($i['tags'])) {
         $entry['tags'] = $i['tags'];
     }
     if (isset($i['displayname_owner'])) {
         $entry['shareOwner'] = $i['displayname_owner'];
     }
     if (isset($i['is_share_mount_point'])) {
         $entry['isShareMountPoint'] = $i['is_share_mount_point'];
     }
     $mountType = null;
     if ($i->isShared()) {
         $mountType = 'shared';
     } else {
         if ($i->isMounted()) {
             $mountType = 'external';
         }
     }
     if ($mountType !== null) {
         if ($i->getInternalPath() === '') {
             $mountType .= '-root';
         }
         $entry['mountType'] = $mountType;
     }
     if (isset($i['extraData'])) {
         $entry['extraData'] = $i['extraData'];
     }
     return $entry;
 }