コード例 #1
0
 /**
  * Copy legacy storage options into the given storage config object.
  *
  * @param StorageConfig $storageConfig storage config to populate
  * @param string $mountType mount type
  * @param string $applicable applicable user or group
  * @param array $storageOptions legacy storage options
  *
  * @return StorageConfig populated storage config
  */
 protected function populateStorageConfigWithLegacyOptions(&$storageConfig, $mountType, $applicable, $storageOptions)
 {
     $storageConfig->setBackendClass($storageOptions['class']);
     $storageConfig->setBackendOptions($storageOptions['options']);
     if (isset($storageOptions['mountOptions'])) {
         $storageConfig->setMountOptions($storageOptions['mountOptions']);
     }
     if (isset($storageOptions['priority'])) {
         $storageConfig->setPriority($storageOptions['priority']);
     }
     if ($mountType === \OC_Mount_Config::MOUNT_TYPE_USER) {
         $applicableUsers = $storageConfig->getApplicableUsers();
         if ($applicable !== 'all') {
             $applicableUsers[] = $applicable;
             $storageConfig->setApplicableUsers($applicableUsers);
         }
     } else {
         if ($mountType === \OC_Mount_Config::MOUNT_TYPE_GROUP) {
             $applicableGroups = $storageConfig->getApplicableGroups();
             $applicableGroups[] = $applicable;
             $storageConfig->setApplicableGroups($applicableGroups);
         }
     }
     return $storageConfig;
 }
コード例 #2
0
ファイル: globalstoragesservice.php プロジェクト: kenwi/core
 /**
  * Triggers $signal for all applicable users of the given
  * storage
  *
  * @param StorageConfig $storage storage data
  * @param string $signal signal to trigger
  */
 protected function triggerHooks(StorageConfig $storage, $signal)
 {
     // FIXME: Use as expression in empty once PHP 5.4 support is dropped
     $applicableUsers = $storage->getApplicableUsers();
     $applicableGroups = $storage->getApplicableGroups();
     if (empty($applicableUsers) && empty($applicableGroups)) {
         // raise for user "all"
         $this->triggerApplicableHooks($signal, $storage->getMountPoint(), \OC_Mount_Config::MOUNT_TYPE_USER, ['all']);
         return;
     }
     $this->triggerApplicableHooks($signal, $storage->getMountPoint(), \OC_Mount_Config::MOUNT_TYPE_USER, $applicableUsers);
     $this->triggerApplicableHooks($signal, $storage->getMountPoint(), \OC_Mount_Config::MOUNT_TYPE_GROUP, $applicableGroups);
 }
コード例 #3
0
 /**
  * Copy legacy storage options into the given storage config object.
  *
  * @param StorageConfig $storageConfig storage config to populate
  * @param string $mountType mount type
  * @param string $applicable applicable user or group
  * @param array $storageOptions legacy storage options
  *
  * @return StorageConfig populated storage config
  */
 protected function populateStorageConfigWithLegacyOptions(&$storageConfig, $mountType, $applicable, $storageOptions)
 {
     $backend = $this->backendService->getBackend($storageOptions['backend']);
     if (!$backend) {
         throw new \UnexpectedValueException('Invalid backend ' . $storageOptions['backend']);
     }
     $storageConfig->setBackend($backend);
     if (isset($storageOptions['authMechanism']) && $storageOptions['authMechanism'] !== 'builtin::builtin') {
         $authMechanism = $this->backendService->getAuthMechanism($storageOptions['authMechanism']);
     } else {
         $authMechanism = $backend->getLegacyAuthMechanism($storageOptions);
         $storageOptions['authMechanism'] = 'null';
         // to make error handling easier
     }
     if (!$authMechanism) {
         throw new \UnexpectedValueException('Invalid authentication mechanism ' . $storageOptions['authMechanism']);
     }
     $storageConfig->setAuthMechanism($authMechanism);
     $storageConfig->setBackendOptions($storageOptions['options']);
     if (isset($storageOptions['mountOptions'])) {
         $storageConfig->setMountOptions($storageOptions['mountOptions']);
     }
     if (!isset($storageOptions['priority'])) {
         $storageOptions['priority'] = $backend->getPriority();
     }
     $storageConfig->setPriority($storageOptions['priority']);
     if ($mountType === \OC_Mount_Config::MOUNT_TYPE_USER) {
         $applicableUsers = $storageConfig->getApplicableUsers();
         if ($applicable !== 'all') {
             $applicableUsers[] = $applicable;
             $storageConfig->setApplicableUsers($applicableUsers);
         }
     } else {
         if ($mountType === \OC_Mount_Config::MOUNT_TYPE_GROUP) {
             $applicableGroups = $storageConfig->getApplicableGroups();
             $applicableGroups[] = $applicable;
             $storageConfig->setApplicableGroups($applicableGroups);
         }
     }
     return $storageConfig;
 }
コード例 #4
0
ファイル: config.php プロジェクト: DaubaKao/owncloud-core
 /**
  * Convert a StorageConfig to the legacy mountPoints array format
  * There's a lot of extra information in here, to satisfy all of the legacy functions
  *
  * @param StorageConfig $storage
  * @param bool $isPersonal
  * @return array
  */
 private static function prepareMountPointEntry(StorageConfig $storage, $isPersonal)
 {
     $mountEntry = [];
     $mountEntry['mountpoint'] = substr($storage->getMountPoint(), 1);
     // remove leading slash
     $mountEntry['class'] = $storage->getBackend()->getIdentifier();
     $mountEntry['backend'] = $storage->getBackend()->getText();
     $mountEntry['authMechanism'] = $storage->getAuthMechanism()->getIdentifier();
     $mountEntry['personal'] = $isPersonal;
     $mountEntry['options'] = self::decryptPasswords($storage->getBackendOptions());
     $mountEntry['mountOptions'] = $storage->getMountOptions();
     $mountEntry['priority'] = $storage->getPriority();
     $mountEntry['applicable'] = ['groups' => $storage->getApplicableGroups(), 'users' => $storage->getApplicableUsers()];
     // if mountpoint is applicable to all users the old API expects ['all']
     if (empty($mountEntry['applicable']['groups']) && empty($mountEntry['applicable']['users'])) {
         $mountEntry['applicable']['users'] = ['all'];
     }
     $mountEntry['id'] = $storage->getId();
     return $mountEntry;
 }
コード例 #5
0
ファイル: storagesservice.php プロジェクト: loulancn/core
 /**
  * Update storage to the configuration
  *
  * @param StorageConfig $updatedStorage storage attributes
  *
  * @return StorageConfig storage config
  * @throws NotFoundException if the given storage does not exist in the config
  */
 public function updateStorage(StorageConfig $updatedStorage)
 {
     $id = $updatedStorage->getId();
     $existingMount = $this->dbConfig->getMountById($id);
     if (!is_array($existingMount)) {
         throw new NotFoundException('Storage with id "' . $id . '" not found while updating storage');
     }
     $oldStorage = $this->getStorageConfigFromDBMount($existingMount);
     $removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers());
     $removedGroups = array_diff($oldStorage->getApplicableGroups(), $updatedStorage->getApplicableGroups());
     $addedUsers = array_diff($updatedStorage->getApplicableUsers(), $oldStorage->getApplicableUsers());
     $addedGroups = array_diff($updatedStorage->getApplicableGroups(), $oldStorage->getApplicableGroups());
     $oldUserCount = count($oldStorage->getApplicableUsers());
     $oldGroupCount = count($oldStorage->getApplicableGroups());
     $newUserCount = count($oldStorage->getApplicableUsers());
     $newGroupCount = count($oldStorage->getApplicableGroups());
     $wasGlobal = $oldUserCount + $oldGroupCount === 0;
     $isGlobal = $newUserCount + $newGroupCount === 0;
     foreach ($removedUsers as $user) {
         $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user);
     }
     foreach ($removedGroups as $group) {
         $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
     }
     foreach ($addedUsers as $user) {
         $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user);
     }
     foreach ($addedGroups as $group) {
         $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
     }
     if ($wasGlobal && !$isGlobal) {
         $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
     } else {
         if (!$wasGlobal && $isGlobal) {
             $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
         }
     }
     $changedConfig = array_diff_assoc($updatedStorage->getBackendOptions(), $oldStorage->getBackendOptions());
     $changedOptions = array_diff_assoc($updatedStorage->getMountOptions(), $oldStorage->getMountOptions());
     foreach ($changedConfig as $key => $value) {
         $this->dbConfig->setConfig($id, $key, $value);
     }
     foreach ($changedOptions as $key => $value) {
         $this->dbConfig->setOption($id, $key, $value);
     }
     $this->triggerChangeHooks($oldStorage, $updatedStorage);
     return $this->getStorage($id);
 }
コード例 #6
0
 protected function isApplicable(StorageConfig $config)
 {
     $applicableUsers = $config->getApplicableUsers();
     $applicableGroups = $config->getApplicableGroups();
     if (count($applicableUsers) === 0 && count($applicableGroups) === 0) {
         return true;
     }
     if (in_array($this->getUser()->getUID(), $applicableUsers, true)) {
         return true;
     }
     $groupIds = $this->groupManager->getUserGroupIds($this->getUser());
     foreach ($groupIds as $groupId) {
         if (in_array($groupId, $applicableGroups, true)) {
             return true;
         }
     }
     return false;
 }
コード例 #7
0
 /**
  * Get a priority 'type', where a bigger number means higher priority
  * user applicable > group applicable > 'all'
  *
  * @param StorageConfig $storage
  * @return int
  */
 protected function getPriorityType(StorageConfig $storage)
 {
     $applicableUsers = $storage->getApplicableUsers();
     $applicableGroups = $storage->getApplicableGroups();
     if ($applicableUsers && $applicableUsers[0] !== 'all') {
         return 2;
     }
     if ($applicableGroups) {
         return 1;
     }
     return 0;
 }
コード例 #8
0
ファイル: userstoragesservice.php プロジェクト: kenwi/core
 protected function isApplicable(StorageConfig $config)
 {
     return $config->getApplicableUsers() === [$this->getUser()->getUID()] && $config->getType() === StorageConfig::MOUNT_TYPE_PERSONAl;
 }
コード例 #9
0
ファイル: config.php プロジェクト: GrumpyCrouton/core
 /**
  * Convert a StorageConfig to the legacy mountPoints array format
  * There's a lot of extra information in here, to satisfy all of the legacy functions
  *
  * @param StorageConfig $storage
  * @param bool $isPersonal
  * @return array
  */
 private static function prepareMountPointEntry(StorageConfig $storage, $isPersonal)
 {
     $mountEntry = [];
     $mountEntry['mountpoint'] = substr($storage->getMountPoint(), 1);
     // remove leading slash
     $mountEntry['class'] = $storage->getBackend()->getIdentifier();
     $mountEntry['backend'] = $storage->getBackend()->getText();
     $mountEntry['authMechanism'] = $storage->getAuthMechanism()->getIdentifier();
     $mountEntry['personal'] = $isPersonal;
     $mountEntry['options'] = self::decryptPasswords($storage->getBackendOptions());
     $mountEntry['mountOptions'] = $storage->getMountOptions();
     $mountEntry['priority'] = $storage->getPriority();
     $mountEntry['applicable'] = ['groups' => $storage->getApplicableGroups(), 'users' => $storage->getApplicableUsers()];
     $mountEntry['id'] = $storage->getId();
     // $mountEntry['storage_id'] = null; // we don't store this!
     return $mountEntry;
 }