Exemple #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $mountId = $input->getArgument('mount_id');
     $configInput = $input->getOption('config');
     try {
         $mount = $this->globalService->getStorage($mountId);
     } catch (NotFoundException $e) {
         $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>');
         return 404;
     }
     $this->updateStorageStatus($mount, $configInput, $output);
     $this->writeArrayInOutputFormat($input, $output, ['status' => StorageNotAvailableException::getStateCodeName($mount->getStatus()), 'code' => $mount->getStatus(), 'message' => $mount->getStatusMessage()]);
 }
Exemple #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption('all')) {
         /** @var  $mounts StorageConfig[] */
         $mounts = $this->globalService->getStorageForAllUsers();
         $userId = self::ALL;
     } else {
         $userId = $input->getArgument('user_id');
         $storageService = $this->getStorageService($userId);
         /** @var  $mounts StorageConfig[] */
         $mounts = $storageService->getAllStorages();
     }
     $this->listMounts($userId, $mounts, $input, $output);
 }
 /**
  * Read legacy config data
  *
  * @return array list of mount configs
  */
 protected function readLegacyConfig()
 {
     // read global config
     $data = parent::readLegacyConfig();
     $userId = $this->getUser()->getUID();
     // don't use array_filter() with ARRAY_FILTER_USE_KEY, it's PHP 5.6+
     if (isset($data[\OC_Mount_Config::MOUNT_TYPE_USER])) {
         $newData = [];
         foreach ($data[\OC_Mount_Config::MOUNT_TYPE_USER] as $key => $value) {
             if (strtolower($key) === strtolower($userId) || $key === 'all') {
                 $newData[$key] = $value;
             }
         }
         $data[\OC_Mount_Config::MOUNT_TYPE_USER] = $newData;
     }
     if (isset($data[\OC_Mount_Config::MOUNT_TYPE_GROUP])) {
         $newData = [];
         foreach ($data[\OC_Mount_Config::MOUNT_TYPE_GROUP] as $key => $value) {
             if ($this->groupManager->isInGroup($userId, $key)) {
                 $newData[$key] = $value;
             }
         }
         $data[\OC_Mount_Config::MOUNT_TYPE_GROUP] = $newData;
     }
     return $data;
 }
 /**
  * @dataProvider validateStorageProvider
  */
 public function testValidateStorage($backendValidate, $authMechValidate, $expectSuccess)
 {
     $backend = $this->getBackendMock();
     $backend->method('validateStorage')->willReturn($backendValidate);
     $backend->method('isVisibleFor')->willReturn(true);
     $authMech = $this->getAuthMechMock();
     $authMech->method('validateStorage')->will($this->returnValue($authMechValidate));
     $storageConfig = new StorageConfig();
     $storageConfig->setMountPoint('mount');
     $storageConfig->setBackend($backend);
     $storageConfig->setAuthMechanism($authMech);
     $storageConfig->setBackendOptions([]);
     $this->service->expects($this->once())->method('createStorage')->will($this->returnValue($storageConfig));
     if ($expectSuccess) {
         $this->service->expects($this->once())->method('addStorage')->with($storageConfig)->will($this->returnValue($storageConfig));
     } else {
         $this->service->expects($this->never())->method('addStorage');
     }
     $response = $this->controller->create('mount', '\\OC\\Files\\Storage\\SMB', '\\OCA\\Files_External\\Lib\\Auth\\NullMechanism', array(), [], [], [], null);
     if ($expectSuccess) {
         $this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
     } else {
         $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
     }
 }
Exemple #5
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $mountId = $input->getArgument('mount_id');
     try {
         $mount = $this->globalService->getStorage($mountId);
     } catch (NotFoundException $e) {
         $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts</error>');
         return 404;
     }
     if ($mount->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) {
         $output->writeln('<error>Can\'t change applicables on personal mounts</error>');
         return 1;
     }
     $addUsers = $input->getOption('add-user');
     $removeUsers = $input->getOption('remove-user');
     $addGroups = $input->getOption('add-group');
     $removeGroups = $input->getOption('remove-group');
     $applicableUsers = $mount->getApplicableUsers();
     $applicableGroups = $mount->getApplicableGroups();
     if (count($addUsers) + count($removeUsers) + count($addGroups) + count($removeGroups) > 0 || $input->getOption('remove-all')) {
         foreach ($addUsers as $addUser) {
             if (!$this->userManager->userExists($addUser)) {
                 $output->writeln('<error>User "' . $addUser . '" not found</error>');
                 return 404;
             }
         }
         foreach ($addGroups as $addGroup) {
             if (!$this->groupManager->groupExists($addGroup)) {
                 $output->writeln('<error>Group "' . $addGroup . '" not found</error>');
                 return 404;
             }
         }
         if ($input->getOption('remove-all')) {
             $applicableUsers = [];
             $applicableGroups = [];
         } else {
             $applicableUsers = array_unique(array_merge($applicableUsers, $addUsers));
             $applicableUsers = array_values(array_diff($applicableUsers, $removeUsers));
             $applicableGroups = array_unique(array_merge($applicableGroups, $addGroups));
             $applicableGroups = array_values(array_diff($applicableGroups, $removeGroups));
         }
         $mount->setApplicableUsers($applicableUsers);
         $mount->setApplicableGroups($applicableGroups);
         $this->globalService->updateStorage($mount);
     }
     $this->writeArrayInOutputFormat($input, $output, ['users' => $applicableUsers, 'groups' => $applicableGroups]);
 }
Exemple #6
0
 /**
  * @param StorageConfig $mount
  * @param string $key
  * @param string $value
  * @param OutputInterface $output
  */
 protected function setOption(StorageConfig $mount, $key, $value, OutputInterface $output)
 {
     $decoded = json_decode($value, true);
     if (!is_null($decoded)) {
         $value = $decoded;
     }
     $mount->setBackendOption($key, $value);
     $this->globalService->updateStorage($mount);
 }
 public function testGetStorage()
 {
     $storageConfig = new StorageConfig(1);
     $storageConfig->setMountPoint('test');
     $storageConfig->setBackendClass('\\OC\\Files\\Storage\\SMB');
     $storageConfig->setBackendOptions(['user' => 'test', 'password', 'password123']);
     $storageConfig->setMountOptions(['priority' => false]);
     $this->service->expects($this->once())->method('getStorage')->with(1)->will($this->returnValue($storageConfig));
     $response = $this->controller->show(1);
     $this->assertEquals(Http::STATUS_OK, $response->getStatus());
     $this->assertEquals($storageConfig, $response->getData());
 }
Exemple #8
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $mountId = $input->getArgument('mount_id');
     try {
         $mount = $this->globalService->getStorage($mountId);
     } catch (NotFoundException $e) {
         $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>');
         return 404;
     }
     $noConfirm = $input->getOption('yes');
     if (!$noConfirm) {
         $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
         $listInput = new ArrayInput([], $listCommand->getDefinition());
         $listInput->setOption('output', $input->getOption('output'));
         $listCommand->listMounts(null, [$mount], $listInput, $output);
         $questionHelper = $this->getHelper('question');
         $question = new ConfirmationQuestion('Delete this mount? [y/N] ', false);
         if (!$questionHelper->ask($input, $output, $question)) {
             return;
         }
     }
     $this->globalService->removeStorage($mountId);
 }
 /**
  * Read legacy config data
  *
  * @return array list of mount configs
  */
 protected function readLegacyConfig()
 {
     // read global config
     $data = parent::readLegacyConfig();
     $userId = $this->getUser()->getUID();
     if (isset($data[\OC_Mount_Config::MOUNT_TYPE_USER])) {
         $data[\OC_Mount_Config::MOUNT_TYPE_USER] = array_filter($data[\OC_Mount_Config::MOUNT_TYPE_USER], function ($key) use($userId) {
             return strtolower($key) === strtolower($userId) || $key === 'all';
         }, ARRAY_FILTER_USE_KEY);
     }
     if (isset($data[\OC_Mount_Config::MOUNT_TYPE_GROUP])) {
         $data[\OC_Mount_Config::MOUNT_TYPE_GROUP] = array_filter($data[\OC_Mount_Config::MOUNT_TYPE_GROUP], function ($key) use($userId) {
             return $this->groupManager->isInGroup($userId, $key);
         }, ARRAY_FILTER_USE_KEY);
     }
     return $data;
 }
 /**
  * @param BackendService $backendService
  * @param DBConfigService $dbConfig
  * @param IUserSession $userSession
  * @param IGroupManager $groupManager
  * @param IUserMountCache $userMountCache
  */
 public function __construct(BackendService $backendService, DBConfigService $dbConfig, IUserSession $userSession, IGroupManager $groupManager, IUserMountCache $userMountCache)
 {
     parent::__construct($backendService, $dbConfig, $userMountCache);
     $this->userSession = $userSession;
     $this->groupManager = $groupManager;
 }