Пример #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;
 }
Пример #2
0
 /**
  * Check if a preview can be generated for a file
  *
  * @param \OCP\Files\FileInfo $file
  * @return bool
  */
 public function isAvailable(\OCP\Files\FileInfo $file)
 {
     if (!$this->config->getSystemValue('enable_previews', true)) {
         return false;
     }
     $this->registerCoreProviders();
     if (!$this->isMimeSupported($file->getMimetype())) {
         return false;
     }
     $mount = $file->getMountPoint();
     if ($mount and !$mount->getOption('previews', true)) {
         return false;
     }
     foreach ($this->providers as $supportedMimeType => $providers) {
         if (preg_match($supportedMimeType, $file->getMimetype())) {
             foreach ($providers as $closure) {
                 $provider = $closure();
                 if (!$provider instanceof IProvider) {
                     continue;
                 }
                 /** @var $provider IProvider */
                 if ($provider->isAvailable($file)) {
                     return true;
                 }
             }
         }
     }
     return false;
 }