Passed
Push — master ( 615cf6...cbbbbe )
by Morris
13:19 queued 12s
created
apps/files_external/appinfo/routes.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -31,41 +31,41 @@
 block discarded – undo
31 31
  * @var $this \OCP\Route\IRouter
32 32
  **/
33 33
 \OCA\Files_External\MountConfig::$app->registerRoutes(
34
-	$this,
35
-	[
36
-		'resources' => [
37
-			'global_storages' => ['url' => '/globalstorages'],
38
-			'user_storages' => ['url' => '/userstorages'],
39
-			'user_global_storages' => ['url' => '/userglobalstorages'],
40
-		],
41
-		'routes' => [
42
-			[
43
-				'name' => 'Ajax#getSshKeys',
44
-				'url' => '/ajax/public_key.php',
45
-				'verb' => 'POST',
46
-				'requirements' => [],
47
-			],
48
-			[
49
-				'name' => 'Ajax#saveGlobalCredentials',
50
-				'url' => '/globalcredentials',
51
-				'verb' => 'POST',
52
-			],
53
-		],
54
-		'ocs' => [
55
-			[
56
-				'name' => 'Api#getUserMounts',
57
-				'url' => '/api/v1/mounts',
58
-				'verb' => 'GET',
59
-			],
60
-		],
61
-	]
34
+    $this,
35
+    [
36
+        'resources' => [
37
+            'global_storages' => ['url' => '/globalstorages'],
38
+            'user_storages' => ['url' => '/userstorages'],
39
+            'user_global_storages' => ['url' => '/userglobalstorages'],
40
+        ],
41
+        'routes' => [
42
+            [
43
+                'name' => 'Ajax#getSshKeys',
44
+                'url' => '/ajax/public_key.php',
45
+                'verb' => 'POST',
46
+                'requirements' => [],
47
+            ],
48
+            [
49
+                'name' => 'Ajax#saveGlobalCredentials',
50
+                'url' => '/globalcredentials',
51
+                'verb' => 'POST',
52
+            ],
53
+        ],
54
+        'ocs' => [
55
+            [
56
+                'name' => 'Api#getUserMounts',
57
+                'url' => '/api/v1/mounts',
58
+                'verb' => 'GET',
59
+            ],
60
+        ],
61
+    ]
62 62
 );
63 63
 
64 64
 $this->create('files_external_oauth1', 'apps/files_external/ajax/oauth1.php')
65
-	->actionInclude('files_external/ajax/oauth1.php');
65
+    ->actionInclude('files_external/ajax/oauth1.php');
66 66
 $this->create('files_external_oauth2', 'apps/files_external/ajax/oauth2.php')
67
-	->actionInclude('files_external/ajax/oauth2.php');
67
+    ->actionInclude('files_external/ajax/oauth2.php');
68 68
 
69 69
 
70 70
 $this->create('files_external_list_applicable', '/apps/files_external/applicable')
71
-	->actionInclude('files_external/ajax/applicable.php');
71
+    ->actionInclude('files_external/ajax/applicable.php');
Please login to merge, or discard this patch.
apps/files_external/appinfo/app.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -39,14 +39,14 @@
 block discarded – undo
39 39
 $appContainer = \OCA\Files_External\MountConfig::$app->getContainer();
40 40
 
41 41
 \OCA\Files\App::getNavigationManager()->add(function () {
42
-	$l = \OC::$server->getL10N('files_external');
43
-	return [
44
-		'id' => 'extstoragemounts',
45
-		'appname' => 'files_external',
46
-		'script' => 'list.php',
47
-		'order' => 30,
48
-		'name' => $l->t('External storages'),
49
-	];
42
+    $l = \OC::$server->getL10N('files_external');
43
+    return [
44
+        'id' => 'extstoragemounts',
45
+        'appname' => 'files_external',
46
+        'script' => 'list.php',
47
+        'order' => 30,
48
+        'name' => $l->t('External storages'),
49
+    ];
50 50
 });
51 51
 
52 52
 $mountProvider = $appContainer->query(ConfigAdapter::class);
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 
31 31
 use OCA\Files_External\Config\ConfigAdapter;
32 32
 
33
-require_once __DIR__ . '/../3rdparty/autoload.php';
33
+require_once __DIR__.'/../3rdparty/autoload.php';
34 34
 
35 35
 // register Application object singleton
36 36
 \OCA\Files_External\MountConfig::$app = \OC::$server->query(\OCA\Files_External\AppInfo\Application::class);
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 
39 39
 $appContainer = \OCA\Files_External\MountConfig::$app->getContainer();
40 40
 
41
-\OCA\Files\App::getNavigationManager()->add(function () {
41
+\OCA\Files\App::getNavigationManager()->add(function() {
42 42
 	$l = \OC::$server->getL10N('files_external');
43 43
 	return [
44 44
 		'id' => 'extstoragemounts',
Please login to merge, or discard this patch.
apps/files_external/lib/Settings/Admin.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -32,64 +32,64 @@
 block discarded – undo
32 32
 
33 33
 class Admin implements ISettings {
34 34
 
35
-	/** @var IManager */
36
-	private $encryptionManager;
35
+    /** @var IManager */
36
+    private $encryptionManager;
37 37
 
38
-	/** @var GlobalStoragesService */
39
-	private $globalStoragesService;
38
+    /** @var GlobalStoragesService */
39
+    private $globalStoragesService;
40 40
 
41
-	/** @var BackendService */
42
-	private $backendService;
41
+    /** @var BackendService */
42
+    private $backendService;
43 43
 
44
-	/** @var GlobalAuth	 */
45
-	private $globalAuth;
44
+    /** @var GlobalAuth	 */
45
+    private $globalAuth;
46 46
 
47
-	public function __construct(
48
-		IManager $encryptionManager,
49
-		GlobalStoragesService $globalStoragesService,
50
-		BackendService $backendService,
51
-		GlobalAuth $globalAuth
52
-	) {
53
-		$this->encryptionManager = $encryptionManager;
54
-		$this->globalStoragesService = $globalStoragesService;
55
-		$this->backendService = $backendService;
56
-		$this->globalAuth = $globalAuth;
57
-	}
47
+    public function __construct(
48
+        IManager $encryptionManager,
49
+        GlobalStoragesService $globalStoragesService,
50
+        BackendService $backendService,
51
+        GlobalAuth $globalAuth
52
+    ) {
53
+        $this->encryptionManager = $encryptionManager;
54
+        $this->globalStoragesService = $globalStoragesService;
55
+        $this->backendService = $backendService;
56
+        $this->globalAuth = $globalAuth;
57
+    }
58 58
 
59
-	/**
60
-	 * @return TemplateResponse
61
-	 */
62
-	public function getForm() {
63
-		$parameters = [
64
-			'encryptionEnabled'    => $this->encryptionManager->isEnabled(),
65
-			'visibilityType'       => BackendService::VISIBILITY_ADMIN,
66
-			'storages'             => $this->globalStoragesService->getStorages(),
67
-			'backends'             => $this->backendService->getAvailableBackends(),
68
-			'authMechanisms'       => $this->backendService->getAuthMechanisms(),
69
-			'dependencies'         => \OCA\Files_External\MountConfig::dependencyMessage($this->backendService->getBackends()),
70
-			'allowUserMounting'    => $this->backendService->isUserMountingAllowed(),
71
-			'globalCredentials'    => $this->globalAuth->getAuth(''),
72
-			'globalCredentialsUid' => '',
73
-		];
59
+    /**
60
+     * @return TemplateResponse
61
+     */
62
+    public function getForm() {
63
+        $parameters = [
64
+            'encryptionEnabled'    => $this->encryptionManager->isEnabled(),
65
+            'visibilityType'       => BackendService::VISIBILITY_ADMIN,
66
+            'storages'             => $this->globalStoragesService->getStorages(),
67
+            'backends'             => $this->backendService->getAvailableBackends(),
68
+            'authMechanisms'       => $this->backendService->getAuthMechanisms(),
69
+            'dependencies'         => \OCA\Files_External\MountConfig::dependencyMessage($this->backendService->getBackends()),
70
+            'allowUserMounting'    => $this->backendService->isUserMountingAllowed(),
71
+            'globalCredentials'    => $this->globalAuth->getAuth(''),
72
+            'globalCredentialsUid' => '',
73
+        ];
74 74
 
75
-		return new TemplateResponse('files_external', 'settings', $parameters, '');
76
-	}
75
+        return new TemplateResponse('files_external', 'settings', $parameters, '');
76
+    }
77 77
 
78
-	/**
79
-	 * @return string the section ID, e.g. 'sharing'
80
-	 */
81
-	public function getSection() {
82
-		return 'externalstorages';
83
-	}
78
+    /**
79
+     * @return string the section ID, e.g. 'sharing'
80
+     */
81
+    public function getSection() {
82
+        return 'externalstorages';
83
+    }
84 84
 
85
-	/**
86
-	 * @return int whether the form should be rather on the top or bottom of
87
-	 * the admin section. The forms are arranged in ascending order of the
88
-	 * priority values. It is required to return a value between 0 and 100.
89
-	 *
90
-	 * E.g.: 70
91
-	 */
92
-	public function getPriority() {
93
-		return 40;
94
-	}
85
+    /**
86
+     * @return int whether the form should be rather on the top or bottom of
87
+     * the admin section. The forms are arranged in ascending order of the
88
+     * priority values. It is required to return a value between 0 and 100.
89
+     *
90
+     * E.g.: 70
91
+     */
92
+    public function getPriority() {
93
+        return 40;
94
+    }
95 95
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Settings/Personal.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -33,71 +33,71 @@
 block discarded – undo
33 33
 
34 34
 class Personal implements ISettings {
35 35
 
36
-	/** @var IManager */
37
-	private $encryptionManager;
36
+    /** @var IManager */
37
+    private $encryptionManager;
38 38
 
39
-	/** @var UserGlobalStoragesService */
40
-	private $userGlobalStoragesService;
39
+    /** @var UserGlobalStoragesService */
40
+    private $userGlobalStoragesService;
41 41
 
42
-	/** @var BackendService */
43
-	private $backendService;
42
+    /** @var BackendService */
43
+    private $backendService;
44 44
 
45
-	/** @var GlobalAuth	 */
46
-	private $globalAuth;
45
+    /** @var GlobalAuth	 */
46
+    private $globalAuth;
47 47
 
48
-	/** @var IUserSession */
49
-	private $userSession;
48
+    /** @var IUserSession */
49
+    private $userSession;
50 50
 
51
-	public function __construct(
52
-		IManager $encryptionManager,
53
-		UserGlobalStoragesService $userGlobalStoragesService,
54
-		BackendService $backendService,
55
-		GlobalAuth $globalAuth,
56
-		IUserSession $userSession
57
-	) {
58
-		$this->encryptionManager = $encryptionManager;
59
-		$this->userGlobalStoragesService = $userGlobalStoragesService;
60
-		$this->backendService = $backendService;
61
-		$this->globalAuth = $globalAuth;
62
-		$this->userSession = $userSession;
63
-	}
51
+    public function __construct(
52
+        IManager $encryptionManager,
53
+        UserGlobalStoragesService $userGlobalStoragesService,
54
+        BackendService $backendService,
55
+        GlobalAuth $globalAuth,
56
+        IUserSession $userSession
57
+    ) {
58
+        $this->encryptionManager = $encryptionManager;
59
+        $this->userGlobalStoragesService = $userGlobalStoragesService;
60
+        $this->backendService = $backendService;
61
+        $this->globalAuth = $globalAuth;
62
+        $this->userSession = $userSession;
63
+    }
64 64
 
65
-	/**
66
-	 * @return TemplateResponse
67
-	 */
68
-	public function getForm() {
69
-		$uid = $this->userSession->getUser()->getUID();
65
+    /**
66
+     * @return TemplateResponse
67
+     */
68
+    public function getForm() {
69
+        $uid = $this->userSession->getUser()->getUID();
70 70
 
71
-		$parameters = [
72
-			'encryptionEnabled'    => $this->encryptionManager->isEnabled(),
73
-			'visibilityType'       => BackendService::VISIBILITY_PERSONAL,
74
-			'storages'             => $this->userGlobalStoragesService->getStorages(),
75
-			'backends'             => $this->backendService->getAvailableBackends(),
76
-			'authMechanisms'       => $this->backendService->getAuthMechanisms(),
77
-			'dependencies'         => \OCA\Files_External\MountConfig::dependencyMessage($this->backendService->getBackends()),
78
-			'allowUserMounting'    => $this->backendService->isUserMountingAllowed(),
79
-			'globalCredentials'    => $this->globalAuth->getAuth($uid),
80
-			'globalCredentialsUid' => $uid,
81
-		];
71
+        $parameters = [
72
+            'encryptionEnabled'    => $this->encryptionManager->isEnabled(),
73
+            'visibilityType'       => BackendService::VISIBILITY_PERSONAL,
74
+            'storages'             => $this->userGlobalStoragesService->getStorages(),
75
+            'backends'             => $this->backendService->getAvailableBackends(),
76
+            'authMechanisms'       => $this->backendService->getAuthMechanisms(),
77
+            'dependencies'         => \OCA\Files_External\MountConfig::dependencyMessage($this->backendService->getBackends()),
78
+            'allowUserMounting'    => $this->backendService->isUserMountingAllowed(),
79
+            'globalCredentials'    => $this->globalAuth->getAuth($uid),
80
+            'globalCredentialsUid' => $uid,
81
+        ];
82 82
 
83
-		return new TemplateResponse('files_external', 'settings', $parameters, '');
84
-	}
83
+        return new TemplateResponse('files_external', 'settings', $parameters, '');
84
+    }
85 85
 
86
-	/**
87
-	 * @return string the section ID, e.g. 'sharing'
88
-	 */
89
-	public function getSection() {
90
-		return 'externalstorages';
91
-	}
86
+    /**
87
+     * @return string the section ID, e.g. 'sharing'
88
+     */
89
+    public function getSection() {
90
+        return 'externalstorages';
91
+    }
92 92
 
93
-	/**
94
-	 * @return int whether the form should be rather on the top or bottom of
95
-	 * the admin section. The forms are arranged in ascending order of the
96
-	 * priority values. It is required to return a value between 0 and 100.
97
-	 *
98
-	 * E.g.: 70
99
-	 */
100
-	public function getPriority() {
101
-		return 40;
102
-	}
93
+    /**
94
+     * @return int whether the form should be rather on the top or bottom of
95
+     * the admin section. The forms are arranged in ascending order of the
96
+     * priority values. It is required to return a value between 0 and 100.
97
+     *
98
+     * E.g.: 70
99
+     */
100
+    public function getPriority() {
101
+        return 40;
102
+    }
103 103
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Service/LegacyStoragesService.php 1 patch
Indentation   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -34,179 +34,179 @@
 block discarded – undo
34 34
  * Read mount config from legacy mount.json
35 35
  */
36 36
 abstract class LegacyStoragesService {
37
-	/** @var BackendService */
38
-	protected $backendService;
37
+    /** @var BackendService */
38
+    protected $backendService;
39 39
 
40
-	/**
41
-	 * Read legacy config data
42
-	 *
43
-	 * @return array list of mount configs
44
-	 */
45
-	abstract protected function readLegacyConfig();
40
+    /**
41
+     * Read legacy config data
42
+     *
43
+     * @return array list of mount configs
44
+     */
45
+    abstract protected function readLegacyConfig();
46 46
 
47
-	/**
48
-	 * Copy legacy storage options into the given storage config object.
49
-	 *
50
-	 * @param StorageConfig $storageConfig storage config to populate
51
-	 * @param string $mountType mount type
52
-	 * @param string $applicable applicable user or group
53
-	 * @param array $storageOptions legacy storage options
54
-	 *
55
-	 * @return StorageConfig populated storage config
56
-	 */
57
-	protected function populateStorageConfigWithLegacyOptions(
58
-		&$storageConfig,
59
-		$mountType,
60
-		$applicable,
61
-		$storageOptions
62
-	) {
63
-		$backend = $this->backendService->getBackend($storageOptions['backend']);
64
-		if (!$backend) {
65
-			throw new \UnexpectedValueException('Invalid backend ' . $storageOptions['backend']);
66
-		}
67
-		$storageConfig->setBackend($backend);
68
-		if (isset($storageOptions['authMechanism']) && $storageOptions['authMechanism'] !== 'builtin::builtin') {
69
-			$authMechanism = $this->backendService->getAuthMechanism($storageOptions['authMechanism']);
70
-		} else {
71
-			$authMechanism = $backend->getLegacyAuthMechanism($storageOptions);
72
-			$storageOptions['authMechanism'] = 'null'; // to make error handling easier
73
-		}
74
-		if (!$authMechanism) {
75
-			throw new \UnexpectedValueException('Invalid authentication mechanism ' . $storageOptions['authMechanism']);
76
-		}
77
-		$storageConfig->setAuthMechanism($authMechanism);
78
-		$storageConfig->setBackendOptions($storageOptions['options']);
79
-		if (isset($storageOptions['mountOptions'])) {
80
-			$storageConfig->setMountOptions($storageOptions['mountOptions']);
81
-		}
82
-		if (!isset($storageOptions['priority'])) {
83
-			$storageOptions['priority'] = $backend->getPriority();
84
-		}
85
-		$storageConfig->setPriority($storageOptions['priority']);
86
-		if ($mountType === \OCA\Files_External\MountConfig::MOUNT_TYPE_USER) {
87
-			$applicableUsers = $storageConfig->getApplicableUsers();
88
-			if ($applicable !== 'all') {
89
-				$applicableUsers[] = $applicable;
90
-				$storageConfig->setApplicableUsers($applicableUsers);
91
-			}
92
-		} elseif ($mountType === \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP) {
93
-			$applicableGroups = $storageConfig->getApplicableGroups();
94
-			$applicableGroups[] = $applicable;
95
-			$storageConfig->setApplicableGroups($applicableGroups);
96
-		}
97
-		return $storageConfig;
98
-	}
47
+    /**
48
+     * Copy legacy storage options into the given storage config object.
49
+     *
50
+     * @param StorageConfig $storageConfig storage config to populate
51
+     * @param string $mountType mount type
52
+     * @param string $applicable applicable user or group
53
+     * @param array $storageOptions legacy storage options
54
+     *
55
+     * @return StorageConfig populated storage config
56
+     */
57
+    protected function populateStorageConfigWithLegacyOptions(
58
+        &$storageConfig,
59
+        $mountType,
60
+        $applicable,
61
+        $storageOptions
62
+    ) {
63
+        $backend = $this->backendService->getBackend($storageOptions['backend']);
64
+        if (!$backend) {
65
+            throw new \UnexpectedValueException('Invalid backend ' . $storageOptions['backend']);
66
+        }
67
+        $storageConfig->setBackend($backend);
68
+        if (isset($storageOptions['authMechanism']) && $storageOptions['authMechanism'] !== 'builtin::builtin') {
69
+            $authMechanism = $this->backendService->getAuthMechanism($storageOptions['authMechanism']);
70
+        } else {
71
+            $authMechanism = $backend->getLegacyAuthMechanism($storageOptions);
72
+            $storageOptions['authMechanism'] = 'null'; // to make error handling easier
73
+        }
74
+        if (!$authMechanism) {
75
+            throw new \UnexpectedValueException('Invalid authentication mechanism ' . $storageOptions['authMechanism']);
76
+        }
77
+        $storageConfig->setAuthMechanism($authMechanism);
78
+        $storageConfig->setBackendOptions($storageOptions['options']);
79
+        if (isset($storageOptions['mountOptions'])) {
80
+            $storageConfig->setMountOptions($storageOptions['mountOptions']);
81
+        }
82
+        if (!isset($storageOptions['priority'])) {
83
+            $storageOptions['priority'] = $backend->getPriority();
84
+        }
85
+        $storageConfig->setPriority($storageOptions['priority']);
86
+        if ($mountType === \OCA\Files_External\MountConfig::MOUNT_TYPE_USER) {
87
+            $applicableUsers = $storageConfig->getApplicableUsers();
88
+            if ($applicable !== 'all') {
89
+                $applicableUsers[] = $applicable;
90
+                $storageConfig->setApplicableUsers($applicableUsers);
91
+            }
92
+        } elseif ($mountType === \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP) {
93
+            $applicableGroups = $storageConfig->getApplicableGroups();
94
+            $applicableGroups[] = $applicable;
95
+            $storageConfig->setApplicableGroups($applicableGroups);
96
+        }
97
+        return $storageConfig;
98
+    }
99 99
 
100
-	/**
101
-	 * Read the external storages config
102
-	 *
103
-	 * @return StorageConfig[] map of storage id to storage config
104
-	 */
105
-	public function getAllStorages() {
106
-		$mountPoints = $this->readLegacyConfig();
107
-		/**
108
-		 * Here is the how the horribly messy mount point array looks like
109
-		 * from the mount.json file:
110
-		 *
111
-		 * $storageOptions = $mountPoints[$mountType][$applicable][$mountPath]
112
-		 *
113
-		 * - $mountType is either "user" or "group"
114
-		 * - $applicable is the name of a user or group (or the current user for personal mounts)
115
-		 * - $mountPath is the mount point path (where the storage must be mounted)
116
-		 * - $storageOptions is a map of storage options:
117
-		 *     - "priority": storage priority
118
-		 *     - "backend": backend identifier
119
-		 *     - "class": LEGACY backend class name
120
-		 *     - "options": backend-specific options
121
-		 *     - "authMechanism": authentication mechanism identifier
122
-		 *     - "mountOptions": mount-specific options (ex: disable previews, scanner, etc)
123
-		 */
124
-		// group by storage id
125
-		/** @var StorageConfig[] $storages */
126
-		$storages = [];
127
-		// for storages without id (legacy), group by config hash for
128
-		// later processing
129
-		$storagesWithConfigHash = [];
130
-		foreach ($mountPoints as $mountType => $applicables) {
131
-			foreach ($applicables as $applicable => $mountPaths) {
132
-				foreach ($mountPaths as $rootMountPath => $storageOptions) {
133
-					$currentStorage = null;
134
-					/**
135
-					 * Flag whether the config that was read already has an id.
136
-					 * If not, it will use a config hash instead and generate
137
-					 * a proper id later
138
-					 *
139
-					 * @var boolean
140
-					 */
141
-					$hasId = false;
142
-					// the root mount point is in the format "/$user/files/the/mount/point"
143
-					// we remove the "/$user/files" prefix
144
-					$parts = explode('/', ltrim($rootMountPath, '/'), 3);
145
-					if (count($parts) < 3) {
146
-						// something went wrong, skip
147
-						\OC::$server->getLogger()->error('Could not parse mount point "' . $rootMountPath . '"', ['app' => 'files_external']);
148
-						continue;
149
-					}
150
-					$relativeMountPath = rtrim($parts[2], '/');
151
-					// note: we cannot do this after the loop because the decrypted config
152
-					// options might be needed for the config hash
153
-					$storageOptions['options'] = \OCA\Files_External\MountConfig::decryptPasswords($storageOptions['options']);
154
-					if (!isset($storageOptions['backend'])) {
155
-						$storageOptions['backend'] = $storageOptions['class']; // legacy compat
156
-					}
157
-					if (!isset($storageOptions['authMechanism'])) {
158
-						$storageOptions['authMechanism'] = null; // ensure config hash works
159
-					}
160
-					if (isset($storageOptions['id'])) {
161
-						$configId = (int)$storageOptions['id'];
162
-						if (isset($storages[$configId])) {
163
-							$currentStorage = $storages[$configId];
164
-						}
165
-						$hasId = true;
166
-					} else {
167
-						// missing id in legacy config, need to generate
168
-						// but at this point we don't know the max-id, so use
169
-						// first group it by config hash
170
-						$storageOptions['mountpoint'] = $rootMountPath;
171
-						$configId = \OCA\Files_External\MountConfig::makeConfigHash($storageOptions);
172
-						if (isset($storagesWithConfigHash[$configId])) {
173
-							$currentStorage = $storagesWithConfigHash[$configId];
174
-						}
175
-					}
176
-					if (is_null($currentStorage)) {
177
-						// create new
178
-						$currentStorage = new StorageConfig($configId);
179
-						$currentStorage->setMountPoint($relativeMountPath);
180
-					}
181
-					try {
182
-						$this->populateStorageConfigWithLegacyOptions(
183
-							$currentStorage,
184
-							$mountType,
185
-							$applicable,
186
-							$storageOptions
187
-						);
188
-						if ($hasId) {
189
-							$storages[$configId] = $currentStorage;
190
-						} else {
191
-							$storagesWithConfigHash[$configId] = $currentStorage;
192
-						}
193
-					} catch (\UnexpectedValueException $e) {
194
-						// don't die if a storage backend doesn't exist
195
-						\OC::$server->getLogger()->logException($e, [
196
-							'message' => 'Could not load storage.',
197
-							'level' => ILogger::ERROR,
198
-							'app' => 'files_external',
199
-						]);
200
-					}
201
-				}
202
-			}
203
-		}
100
+    /**
101
+     * Read the external storages config
102
+     *
103
+     * @return StorageConfig[] map of storage id to storage config
104
+     */
105
+    public function getAllStorages() {
106
+        $mountPoints = $this->readLegacyConfig();
107
+        /**
108
+         * Here is the how the horribly messy mount point array looks like
109
+         * from the mount.json file:
110
+         *
111
+         * $storageOptions = $mountPoints[$mountType][$applicable][$mountPath]
112
+         *
113
+         * - $mountType is either "user" or "group"
114
+         * - $applicable is the name of a user or group (or the current user for personal mounts)
115
+         * - $mountPath is the mount point path (where the storage must be mounted)
116
+         * - $storageOptions is a map of storage options:
117
+         *     - "priority": storage priority
118
+         *     - "backend": backend identifier
119
+         *     - "class": LEGACY backend class name
120
+         *     - "options": backend-specific options
121
+         *     - "authMechanism": authentication mechanism identifier
122
+         *     - "mountOptions": mount-specific options (ex: disable previews, scanner, etc)
123
+         */
124
+        // group by storage id
125
+        /** @var StorageConfig[] $storages */
126
+        $storages = [];
127
+        // for storages without id (legacy), group by config hash for
128
+        // later processing
129
+        $storagesWithConfigHash = [];
130
+        foreach ($mountPoints as $mountType => $applicables) {
131
+            foreach ($applicables as $applicable => $mountPaths) {
132
+                foreach ($mountPaths as $rootMountPath => $storageOptions) {
133
+                    $currentStorage = null;
134
+                    /**
135
+                     * Flag whether the config that was read already has an id.
136
+                     * If not, it will use a config hash instead and generate
137
+                     * a proper id later
138
+                     *
139
+                     * @var boolean
140
+                     */
141
+                    $hasId = false;
142
+                    // the root mount point is in the format "/$user/files/the/mount/point"
143
+                    // we remove the "/$user/files" prefix
144
+                    $parts = explode('/', ltrim($rootMountPath, '/'), 3);
145
+                    if (count($parts) < 3) {
146
+                        // something went wrong, skip
147
+                        \OC::$server->getLogger()->error('Could not parse mount point "' . $rootMountPath . '"', ['app' => 'files_external']);
148
+                        continue;
149
+                    }
150
+                    $relativeMountPath = rtrim($parts[2], '/');
151
+                    // note: we cannot do this after the loop because the decrypted config
152
+                    // options might be needed for the config hash
153
+                    $storageOptions['options'] = \OCA\Files_External\MountConfig::decryptPasswords($storageOptions['options']);
154
+                    if (!isset($storageOptions['backend'])) {
155
+                        $storageOptions['backend'] = $storageOptions['class']; // legacy compat
156
+                    }
157
+                    if (!isset($storageOptions['authMechanism'])) {
158
+                        $storageOptions['authMechanism'] = null; // ensure config hash works
159
+                    }
160
+                    if (isset($storageOptions['id'])) {
161
+                        $configId = (int)$storageOptions['id'];
162
+                        if (isset($storages[$configId])) {
163
+                            $currentStorage = $storages[$configId];
164
+                        }
165
+                        $hasId = true;
166
+                    } else {
167
+                        // missing id in legacy config, need to generate
168
+                        // but at this point we don't know the max-id, so use
169
+                        // first group it by config hash
170
+                        $storageOptions['mountpoint'] = $rootMountPath;
171
+                        $configId = \OCA\Files_External\MountConfig::makeConfigHash($storageOptions);
172
+                        if (isset($storagesWithConfigHash[$configId])) {
173
+                            $currentStorage = $storagesWithConfigHash[$configId];
174
+                        }
175
+                    }
176
+                    if (is_null($currentStorage)) {
177
+                        // create new
178
+                        $currentStorage = new StorageConfig($configId);
179
+                        $currentStorage->setMountPoint($relativeMountPath);
180
+                    }
181
+                    try {
182
+                        $this->populateStorageConfigWithLegacyOptions(
183
+                            $currentStorage,
184
+                            $mountType,
185
+                            $applicable,
186
+                            $storageOptions
187
+                        );
188
+                        if ($hasId) {
189
+                            $storages[$configId] = $currentStorage;
190
+                        } else {
191
+                            $storagesWithConfigHash[$configId] = $currentStorage;
192
+                        }
193
+                    } catch (\UnexpectedValueException $e) {
194
+                        // don't die if a storage backend doesn't exist
195
+                        \OC::$server->getLogger()->logException($e, [
196
+                            'message' => 'Could not load storage.',
197
+                            'level' => ILogger::ERROR,
198
+                            'app' => 'files_external',
199
+                        ]);
200
+                    }
201
+                }
202
+            }
203
+        }
204 204
 
205
-		// convert parameter values
206
-		foreach ($storages as $storage) {
207
-			$storage->getBackend()->validateStorageDefinition($storage);
208
-			$storage->getAuthMechanism()->validateStorageDefinition($storage);
209
-		}
210
-		return $storages;
211
-	}
205
+        // convert parameter values
206
+        foreach ($storages as $storage) {
207
+            $storage->getBackend()->validateStorageDefinition($storage);
208
+            $storage->getAuthMechanism()->validateStorageDefinition($storage);
209
+        }
210
+        return $storages;
211
+    }
212 212
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Service/UserStoragesService.php 1 patch
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -40,104 +40,104 @@
 block discarded – undo
40 40
  * (aka personal storages)
41 41
  */
42 42
 class UserStoragesService extends StoragesService {
43
-	use UserTrait;
43
+    use UserTrait;
44 44
 
45
-	/**
46
-	 * Create a user storages service
47
-	 *
48
-	 * @param BackendService $backendService
49
-	 * @param DBConfigService $dbConfig
50
-	 * @param IUserSession $userSession user session
51
-	 * @param IUserMountCache $userMountCache
52
-	 */
53
-	public function __construct(
54
-		BackendService $backendService,
55
-		DBConfigService $dbConfig,
56
-		IUserSession $userSession,
57
-		IUserMountCache $userMountCache
58
-	) {
59
-		$this->userSession = $userSession;
60
-		parent::__construct($backendService, $dbConfig, $userMountCache);
61
-	}
45
+    /**
46
+     * Create a user storages service
47
+     *
48
+     * @param BackendService $backendService
49
+     * @param DBConfigService $dbConfig
50
+     * @param IUserSession $userSession user session
51
+     * @param IUserMountCache $userMountCache
52
+     */
53
+    public function __construct(
54
+        BackendService $backendService,
55
+        DBConfigService $dbConfig,
56
+        IUserSession $userSession,
57
+        IUserMountCache $userMountCache
58
+    ) {
59
+        $this->userSession = $userSession;
60
+        parent::__construct($backendService, $dbConfig, $userMountCache);
61
+    }
62 62
 
63
-	protected function readDBConfig() {
64
-		return $this->dbConfig->getUserMountsFor(DBConfigService::APPLICABLE_TYPE_USER, $this->getUser()->getUID());
65
-	}
63
+    protected function readDBConfig() {
64
+        return $this->dbConfig->getUserMountsFor(DBConfigService::APPLICABLE_TYPE_USER, $this->getUser()->getUID());
65
+    }
66 66
 
67
-	/**
68
-	 * Triggers $signal for all applicable users of the given
69
-	 * storage
70
-	 *
71
-	 * @param StorageConfig $storage storage data
72
-	 * @param string $signal signal to trigger
73
-	 */
74
-	protected function triggerHooks(StorageConfig $storage, $signal) {
75
-		$user = $this->getUser()->getUID();
67
+    /**
68
+     * Triggers $signal for all applicable users of the given
69
+     * storage
70
+     *
71
+     * @param StorageConfig $storage storage data
72
+     * @param string $signal signal to trigger
73
+     */
74
+    protected function triggerHooks(StorageConfig $storage, $signal) {
75
+        $user = $this->getUser()->getUID();
76 76
 
77
-		// trigger hook for the current user
78
-		$this->triggerApplicableHooks(
79
-			$signal,
80
-			$storage->getMountPoint(),
81
-			\OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
82
-			[$user]
83
-		);
84
-	}
77
+        // trigger hook for the current user
78
+        $this->triggerApplicableHooks(
79
+            $signal,
80
+            $storage->getMountPoint(),
81
+            \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
82
+            [$user]
83
+        );
84
+    }
85 85
 
86
-	/**
87
-	 * Triggers signal_create_mount or signal_delete_mount to
88
-	 * accommodate for additions/deletions in applicableUsers
89
-	 * and applicableGroups fields.
90
-	 *
91
-	 * @param StorageConfig $oldStorage old storage data
92
-	 * @param StorageConfig $newStorage new storage data
93
-	 */
94
-	protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage) {
95
-		// if mount point changed, it's like a deletion + creation
96
-		if ($oldStorage->getMountPoint() !== $newStorage->getMountPoint()) {
97
-			$this->triggerHooks($oldStorage, Filesystem::signal_delete_mount);
98
-			$this->triggerHooks($newStorage, Filesystem::signal_create_mount);
99
-		}
100
-	}
86
+    /**
87
+     * Triggers signal_create_mount or signal_delete_mount to
88
+     * accommodate for additions/deletions in applicableUsers
89
+     * and applicableGroups fields.
90
+     *
91
+     * @param StorageConfig $oldStorage old storage data
92
+     * @param StorageConfig $newStorage new storage data
93
+     */
94
+    protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage) {
95
+        // if mount point changed, it's like a deletion + creation
96
+        if ($oldStorage->getMountPoint() !== $newStorage->getMountPoint()) {
97
+            $this->triggerHooks($oldStorage, Filesystem::signal_delete_mount);
98
+            $this->triggerHooks($newStorage, Filesystem::signal_create_mount);
99
+        }
100
+    }
101 101
 
102
-	protected function getType() {
103
-		return DBConfigService::MOUNT_TYPE_PERSONAl;
104
-	}
102
+    protected function getType() {
103
+        return DBConfigService::MOUNT_TYPE_PERSONAl;
104
+    }
105 105
 
106
-	/**
107
-	 * Add new storage to the configuration
108
-	 *
109
-	 * @param StorageConfig $newStorage storage attributes
110
-	 *
111
-	 * @return StorageConfig storage config, with added id
112
-	 */
113
-	public function addStorage(StorageConfig $newStorage) {
114
-		$newStorage->setApplicableUsers([$this->getUser()->getUID()]);
115
-		return parent::addStorage($newStorage);
116
-	}
106
+    /**
107
+     * Add new storage to the configuration
108
+     *
109
+     * @param StorageConfig $newStorage storage attributes
110
+     *
111
+     * @return StorageConfig storage config, with added id
112
+     */
113
+    public function addStorage(StorageConfig $newStorage) {
114
+        $newStorage->setApplicableUsers([$this->getUser()->getUID()]);
115
+        return parent::addStorage($newStorage);
116
+    }
117 117
 
118
-	/**
119
-	 * Update storage to the configuration
120
-	 *
121
-	 * @param StorageConfig $updatedStorage storage attributes
122
-	 *
123
-	 * @return StorageConfig storage config
124
-	 * @throws NotFoundException if the given storage does not exist in the config
125
-	 */
126
-	public function updateStorage(StorageConfig $updatedStorage) {
127
-		$updatedStorage->setApplicableUsers([$this->getUser()->getUID()]);
128
-		return parent::updateStorage($updatedStorage);
129
-	}
118
+    /**
119
+     * Update storage to the configuration
120
+     *
121
+     * @param StorageConfig $updatedStorage storage attributes
122
+     *
123
+     * @return StorageConfig storage config
124
+     * @throws NotFoundException if the given storage does not exist in the config
125
+     */
126
+    public function updateStorage(StorageConfig $updatedStorage) {
127
+        $updatedStorage->setApplicableUsers([$this->getUser()->getUID()]);
128
+        return parent::updateStorage($updatedStorage);
129
+    }
130 130
 
131
-	/**
132
-	 * Get the visibility type for this controller, used in validation
133
-	 *
134
-	 * @return string BackendService::VISIBILITY_* constants
135
-	 */
136
-	public function getVisibilityType() {
137
-		return BackendService::VISIBILITY_PERSONAL;
138
-	}
131
+    /**
132
+     * Get the visibility type for this controller, used in validation
133
+     *
134
+     * @return string BackendService::VISIBILITY_* constants
135
+     */
136
+    public function getVisibilityType() {
137
+        return BackendService::VISIBILITY_PERSONAL;
138
+    }
139 139
 
140
-	protected function isApplicable(StorageConfig $config) {
141
-		return ($config->getApplicableUsers() === [$this->getUser()->getUID()]) && $config->getType() === StorageConfig::MOUNT_TYPE_PERSONAl;
142
-	}
140
+    protected function isApplicable(StorageConfig $config) {
141
+        return ($config->getApplicableUsers() === [$this->getUser()->getUID()]) && $config->getType() === StorageConfig::MOUNT_TYPE_PERSONAl;
142
+    }
143 143
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Service/UserLegacyStoragesService.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -29,28 +29,28 @@
 block discarded – undo
29 29
  * Read user defined mounts from the legacy mount.json
30 30
  */
31 31
 class UserLegacyStoragesService extends LegacyStoragesService {
32
-	/**
33
-	 * @var IUserSession
34
-	 */
35
-	private $userSession;
32
+    /**
33
+     * @var IUserSession
34
+     */
35
+    private $userSession;
36 36
 
37
-	/**
38
-	 * @param BackendService $backendService
39
-	 * @param IUserSession $userSession
40
-	 */
41
-	public function __construct(BackendService $backendService, IUserSession $userSession) {
42
-		$this->backendService = $backendService;
43
-		$this->userSession = $userSession;
44
-	}
37
+    /**
38
+     * @param BackendService $backendService
39
+     * @param IUserSession $userSession
40
+     */
41
+    public function __construct(BackendService $backendService, IUserSession $userSession) {
42
+        $this->backendService = $backendService;
43
+        $this->userSession = $userSession;
44
+    }
45 45
 
46
-	/**
47
-	 * Read legacy config data
48
-	 *
49
-	 * @return array list of storage configs
50
-	 */
51
-	protected function readLegacyConfig() {
52
-		// read user config
53
-		$user = $this->userSession->getUser()->getUID();
54
-		return \OCA\Files_External\MountConfig::readData($user);
55
-	}
46
+    /**
47
+     * Read legacy config data
48
+     *
49
+     * @return array list of storage configs
50
+     */
51
+    protected function readLegacyConfig() {
52
+        // read user config
53
+        $user = $this->userSession->getUser()->getUID();
54
+        return \OCA\Files_External\MountConfig::readData($user);
55
+    }
56 56
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Service/GlobalStoragesService.php 1 patch
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -35,151 +35,151 @@
 block discarded – undo
35 35
  * Service class to manage global external storages
36 36
  */
37 37
 class GlobalStoragesService extends StoragesService {
38
-	/**
39
-	 * Triggers $signal for all applicable users of the given
40
-	 * storage
41
-	 *
42
-	 * @param StorageConfig $storage storage data
43
-	 * @param string $signal signal to trigger
44
-	 */
45
-	protected function triggerHooks(StorageConfig $storage, $signal) {
46
-		// FIXME: Use as expression in empty once PHP 5.4 support is dropped
47
-		$applicableUsers = $storage->getApplicableUsers();
48
-		$applicableGroups = $storage->getApplicableGroups();
49
-		if (empty($applicableUsers) && empty($applicableGroups)) {
50
-			// raise for user "all"
51
-			$this->triggerApplicableHooks(
52
-				$signal,
53
-				$storage->getMountPoint(),
54
-				\OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
55
-				['all']
56
-			);
57
-			return;
58
-		}
59
-
60
-		$this->triggerApplicableHooks(
61
-			$signal,
62
-			$storage->getMountPoint(),
63
-			\OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
64
-			$applicableUsers
65
-		);
66
-		$this->triggerApplicableHooks(
67
-			$signal,
68
-			$storage->getMountPoint(),
69
-			\OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
70
-			$applicableGroups
71
-		);
72
-	}
73
-
74
-	/**
75
-	 * Triggers signal_create_mount or signal_delete_mount to
76
-	 * accommodate for additions/deletions in applicableUsers
77
-	 * and applicableGroups fields.
78
-	 *
79
-	 * @param StorageConfig $oldStorage old storage config
80
-	 * @param StorageConfig $newStorage new storage config
81
-	 */
82
-	protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage) {
83
-		// if mount point changed, it's like a deletion + creation
84
-		if ($oldStorage->getMountPoint() !== $newStorage->getMountPoint()) {
85
-			$this->triggerHooks($oldStorage, Filesystem::signal_delete_mount);
86
-			$this->triggerHooks($newStorage, Filesystem::signal_create_mount);
87
-			return;
88
-		}
89
-
90
-		$userAdditions = array_diff($newStorage->getApplicableUsers(), $oldStorage->getApplicableUsers());
91
-		$userDeletions = array_diff($oldStorage->getApplicableUsers(), $newStorage->getApplicableUsers());
92
-		$groupAdditions = array_diff($newStorage->getApplicableGroups(), $oldStorage->getApplicableGroups());
93
-		$groupDeletions = array_diff($oldStorage->getApplicableGroups(), $newStorage->getApplicableGroups());
94
-
95
-		// FIXME: Use as expression in empty once PHP 5.4 support is dropped
96
-		// if no applicable were set, raise a signal for "all"
97
-		$oldApplicableUsers = $oldStorage->getApplicableUsers();
98
-		$oldApplicableGroups = $oldStorage->getApplicableGroups();
99
-		if (empty($oldApplicableUsers) && empty($oldApplicableGroups)) {
100
-			$this->triggerApplicableHooks(
101
-				Filesystem::signal_delete_mount,
102
-				$oldStorage->getMountPoint(),
103
-				\OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
104
-				['all']
105
-			);
106
-		}
107
-
108
-		// trigger delete for removed users
109
-		$this->triggerApplicableHooks(
110
-			Filesystem::signal_delete_mount,
111
-			$oldStorage->getMountPoint(),
112
-			\OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
113
-			$userDeletions
114
-		);
115
-
116
-		// trigger delete for removed groups
117
-		$this->triggerApplicableHooks(
118
-			Filesystem::signal_delete_mount,
119
-			$oldStorage->getMountPoint(),
120
-			\OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
121
-			$groupDeletions
122
-		);
123
-
124
-		// and now add the new users
125
-		$this->triggerApplicableHooks(
126
-			Filesystem::signal_create_mount,
127
-			$newStorage->getMountPoint(),
128
-			\OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
129
-			$userAdditions
130
-		);
131
-
132
-		// and now add the new groups
133
-		$this->triggerApplicableHooks(
134
-			Filesystem::signal_create_mount,
135
-			$newStorage->getMountPoint(),
136
-			\OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
137
-			$groupAdditions
138
-		);
139
-
140
-		// FIXME: Use as expression in empty once PHP 5.4 support is dropped
141
-		// if no applicable, raise a signal for "all"
142
-		$newApplicableUsers = $newStorage->getApplicableUsers();
143
-		$newApplicableGroups = $newStorage->getApplicableGroups();
144
-		if (empty($newApplicableUsers) && empty($newApplicableGroups)) {
145
-			$this->triggerApplicableHooks(
146
-				Filesystem::signal_create_mount,
147
-				$newStorage->getMountPoint(),
148
-				\OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
149
-				['all']
150
-			);
151
-		}
152
-	}
153
-
154
-	/**
155
-	 * Get the visibility type for this controller, used in validation
156
-	 *
157
-	 * @return string BackendService::VISIBILITY_* constants
158
-	 */
159
-	public function getVisibilityType() {
160
-		return BackendService::VISIBILITY_ADMIN;
161
-	}
162
-
163
-	protected function isApplicable(StorageConfig $config) {
164
-		return true;
165
-	}
166
-
167
-	/**
168
-	 * Get all configured admin and personal mounts
169
-	 *
170
-	 * @return array map of storage id to storage config
171
-	 */
172
-	public function getStorageForAllUsers() {
173
-		$mounts = $this->dbConfig->getAllMounts();
174
-		$configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts);
175
-		$configs = array_filter($configs, function ($config) {
176
-			return $config instanceof StorageConfig;
177
-		});
178
-
179
-		$keys = array_map(function (StorageConfig $config) {
180
-			return $config->getId();
181
-		}, $configs);
182
-
183
-		return array_combine($keys, $configs);
184
-	}
38
+    /**
39
+     * Triggers $signal for all applicable users of the given
40
+     * storage
41
+     *
42
+     * @param StorageConfig $storage storage data
43
+     * @param string $signal signal to trigger
44
+     */
45
+    protected function triggerHooks(StorageConfig $storage, $signal) {
46
+        // FIXME: Use as expression in empty once PHP 5.4 support is dropped
47
+        $applicableUsers = $storage->getApplicableUsers();
48
+        $applicableGroups = $storage->getApplicableGroups();
49
+        if (empty($applicableUsers) && empty($applicableGroups)) {
50
+            // raise for user "all"
51
+            $this->triggerApplicableHooks(
52
+                $signal,
53
+                $storage->getMountPoint(),
54
+                \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
55
+                ['all']
56
+            );
57
+            return;
58
+        }
59
+
60
+        $this->triggerApplicableHooks(
61
+            $signal,
62
+            $storage->getMountPoint(),
63
+            \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
64
+            $applicableUsers
65
+        );
66
+        $this->triggerApplicableHooks(
67
+            $signal,
68
+            $storage->getMountPoint(),
69
+            \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
70
+            $applicableGroups
71
+        );
72
+    }
73
+
74
+    /**
75
+     * Triggers signal_create_mount or signal_delete_mount to
76
+     * accommodate for additions/deletions in applicableUsers
77
+     * and applicableGroups fields.
78
+     *
79
+     * @param StorageConfig $oldStorage old storage config
80
+     * @param StorageConfig $newStorage new storage config
81
+     */
82
+    protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage) {
83
+        // if mount point changed, it's like a deletion + creation
84
+        if ($oldStorage->getMountPoint() !== $newStorage->getMountPoint()) {
85
+            $this->triggerHooks($oldStorage, Filesystem::signal_delete_mount);
86
+            $this->triggerHooks($newStorage, Filesystem::signal_create_mount);
87
+            return;
88
+        }
89
+
90
+        $userAdditions = array_diff($newStorage->getApplicableUsers(), $oldStorage->getApplicableUsers());
91
+        $userDeletions = array_diff($oldStorage->getApplicableUsers(), $newStorage->getApplicableUsers());
92
+        $groupAdditions = array_diff($newStorage->getApplicableGroups(), $oldStorage->getApplicableGroups());
93
+        $groupDeletions = array_diff($oldStorage->getApplicableGroups(), $newStorage->getApplicableGroups());
94
+
95
+        // FIXME: Use as expression in empty once PHP 5.4 support is dropped
96
+        // if no applicable were set, raise a signal for "all"
97
+        $oldApplicableUsers = $oldStorage->getApplicableUsers();
98
+        $oldApplicableGroups = $oldStorage->getApplicableGroups();
99
+        if (empty($oldApplicableUsers) && empty($oldApplicableGroups)) {
100
+            $this->triggerApplicableHooks(
101
+                Filesystem::signal_delete_mount,
102
+                $oldStorage->getMountPoint(),
103
+                \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
104
+                ['all']
105
+            );
106
+        }
107
+
108
+        // trigger delete for removed users
109
+        $this->triggerApplicableHooks(
110
+            Filesystem::signal_delete_mount,
111
+            $oldStorage->getMountPoint(),
112
+            \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
113
+            $userDeletions
114
+        );
115
+
116
+        // trigger delete for removed groups
117
+        $this->triggerApplicableHooks(
118
+            Filesystem::signal_delete_mount,
119
+            $oldStorage->getMountPoint(),
120
+            \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
121
+            $groupDeletions
122
+        );
123
+
124
+        // and now add the new users
125
+        $this->triggerApplicableHooks(
126
+            Filesystem::signal_create_mount,
127
+            $newStorage->getMountPoint(),
128
+            \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
129
+            $userAdditions
130
+        );
131
+
132
+        // and now add the new groups
133
+        $this->triggerApplicableHooks(
134
+            Filesystem::signal_create_mount,
135
+            $newStorage->getMountPoint(),
136
+            \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
137
+            $groupAdditions
138
+        );
139
+
140
+        // FIXME: Use as expression in empty once PHP 5.4 support is dropped
141
+        // if no applicable, raise a signal for "all"
142
+        $newApplicableUsers = $newStorage->getApplicableUsers();
143
+        $newApplicableGroups = $newStorage->getApplicableGroups();
144
+        if (empty($newApplicableUsers) && empty($newApplicableGroups)) {
145
+            $this->triggerApplicableHooks(
146
+                Filesystem::signal_create_mount,
147
+                $newStorage->getMountPoint(),
148
+                \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
149
+                ['all']
150
+            );
151
+        }
152
+    }
153
+
154
+    /**
155
+     * Get the visibility type for this controller, used in validation
156
+     *
157
+     * @return string BackendService::VISIBILITY_* constants
158
+     */
159
+    public function getVisibilityType() {
160
+        return BackendService::VISIBILITY_ADMIN;
161
+    }
162
+
163
+    protected function isApplicable(StorageConfig $config) {
164
+        return true;
165
+    }
166
+
167
+    /**
168
+     * Get all configured admin and personal mounts
169
+     *
170
+     * @return array map of storage id to storage config
171
+     */
172
+    public function getStorageForAllUsers() {
173
+        $mounts = $this->dbConfig->getAllMounts();
174
+        $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts);
175
+        $configs = array_filter($configs, function ($config) {
176
+            return $config instanceof StorageConfig;
177
+        });
178
+
179
+        $keys = array_map(function (StorageConfig $config) {
180
+            return $config->getId();
181
+        }, $configs);
182
+
183
+        return array_combine($keys, $configs);
184
+    }
185 185
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Controller/ApiController.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -37,73 +37,73 @@
 block discarded – undo
37 37
 
38 38
 class ApiController extends OCSController {
39 39
 
40
-	/** @var IUserSession */
41
-	private $userSession;
42
-
43
-	public function __construct(string $appName,
44
-								IRequest $request,
45
-								IUserSession $userSession) {
46
-		parent::__construct($appName, $request);
47
-
48
-		$this->userSession = $userSession;
49
-	}
50
-
51
-	/**
52
-	 * Formats the given mount config to a mount entry.
53
-	 *
54
-	 * @param string $mountPoint mount point name, relative to the data dir
55
-	 * @param array $mountConfig mount config to format
56
-	 *
57
-	 * @return array entry
58
-	 */
59
-	private function formatMount(string $mountPoint, array $mountConfig): array {
60
-		// strip "/$user/files" from mount point
61
-		$mountPoint = explode('/', trim($mountPoint, '/'), 3);
62
-		$mountPoint = $mountPoint[2] ?? '';
63
-
64
-		// split path from mount point
65
-		$path = \dirname($mountPoint);
66
-		if ($path === '.') {
67
-			$path = '';
68
-		}
69
-
70
-		$isSystemMount = !$mountConfig['personal'];
71
-
72
-		$permissions = \OCP\Constants::PERMISSION_READ;
73
-		// personal mounts can be deleted
74
-		if (!$isSystemMount) {
75
-			$permissions |= \OCP\Constants::PERMISSION_DELETE;
76
-		}
77
-
78
-		$entry = [
79
-			'name' => basename($mountPoint),
80
-			'path' => $path,
81
-			'type' => 'dir',
82
-			'backend' => $mountConfig['backend'],
83
-			'scope' => $isSystemMount ? 'system' : 'personal',
84
-			'permissions' => $permissions,
85
-			'id' => $mountConfig['id'],
86
-			'class' => $mountConfig['class']
87
-		];
88
-		return $entry;
89
-	}
90
-
91
-	/**
92
-	 * @NoAdminRequired
93
-	 *
94
-	 * Returns the mount points visible for this user.
95
-	 *
96
-	 * @return DataResponse share information
97
-	 */
98
-	public function getUserMounts(): DataResponse {
99
-		$entries = [];
100
-		$user = $this->userSession->getUser()->getUID();
101
-
102
-		$mounts = \OCA\Files_External\MountConfig::getAbsoluteMountPoints($user);
103
-		foreach ($mounts as $mountPoint => $mount) {
104
-			$entries[] = $this->formatMount($mountPoint, $mount);
105
-		}
106
-
107
-		return new DataResponse($entries);
108
-	}
40
+    /** @var IUserSession */
41
+    private $userSession;
42
+
43
+    public function __construct(string $appName,
44
+                                IRequest $request,
45
+                                IUserSession $userSession) {
46
+        parent::__construct($appName, $request);
47
+
48
+        $this->userSession = $userSession;
49
+    }
50
+
51
+    /**
52
+     * Formats the given mount config to a mount entry.
53
+     *
54
+     * @param string $mountPoint mount point name, relative to the data dir
55
+     * @param array $mountConfig mount config to format
56
+     *
57
+     * @return array entry
58
+     */
59
+    private function formatMount(string $mountPoint, array $mountConfig): array {
60
+        // strip "/$user/files" from mount point
61
+        $mountPoint = explode('/', trim($mountPoint, '/'), 3);
62
+        $mountPoint = $mountPoint[2] ?? '';
63
+
64
+        // split path from mount point
65
+        $path = \dirname($mountPoint);
66
+        if ($path === '.') {
67
+            $path = '';
68
+        }
69
+
70
+        $isSystemMount = !$mountConfig['personal'];
71
+
72
+        $permissions = \OCP\Constants::PERMISSION_READ;
73
+        // personal mounts can be deleted
74
+        if (!$isSystemMount) {
75
+            $permissions |= \OCP\Constants::PERMISSION_DELETE;
76
+        }
77
+
78
+        $entry = [
79
+            'name' => basename($mountPoint),
80
+            'path' => $path,
81
+            'type' => 'dir',
82
+            'backend' => $mountConfig['backend'],
83
+            'scope' => $isSystemMount ? 'system' : 'personal',
84
+            'permissions' => $permissions,
85
+            'id' => $mountConfig['id'],
86
+            'class' => $mountConfig['class']
87
+        ];
88
+        return $entry;
89
+    }
90
+
91
+    /**
92
+     * @NoAdminRequired
93
+     *
94
+     * Returns the mount points visible for this user.
95
+     *
96
+     * @return DataResponse share information
97
+     */
98
+    public function getUserMounts(): DataResponse {
99
+        $entries = [];
100
+        $user = $this->userSession->getUser()->getUID();
101
+
102
+        $mounts = \OCA\Files_External\MountConfig::getAbsoluteMountPoints($user);
103
+        foreach ($mounts as $mountPoint => $mount) {
104
+            $entries[] = $this->formatMount($mountPoint, $mount);
105
+        }
106
+
107
+        return new DataResponse($entries);
108
+    }
109 109
 }
Please login to merge, or discard this patch.