Passed
Push — master ( 5579b1...b37397 )
by Christoph
13:29 queued 10s
created
apps/testing/appinfo/routes.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -21,62 +21,62 @@
 block discarded – undo
21 21
  */
22 22
 
23 23
 return [
24
-	'routes' => [
25
-		[
26
-			'name' => 'RateLimitTest#userAndAnonProtected',
27
-			'url' => '/userAndAnonProtected',
28
-			'verb' => 'GET',
29
-		],
30
-		[
31
-			'name' => 'RateLimitTest#onlyAnonProtected',
32
-			'url' => '/anonProtected',
33
-			'verb' => 'GET',
34
-		],
35
-	],
24
+    'routes' => [
25
+        [
26
+            'name' => 'RateLimitTest#userAndAnonProtected',
27
+            'url' => '/userAndAnonProtected',
28
+            'verb' => 'GET',
29
+        ],
30
+        [
31
+            'name' => 'RateLimitTest#onlyAnonProtected',
32
+            'url' => '/anonProtected',
33
+            'verb' => 'GET',
34
+        ],
35
+    ],
36 36
 
37
-	'ocs' => [
38
-		[
39
-			'name' => 'Config#setAppValue',
40
-			'url' => '/api/v1/app/{appid}/{configkey}',
41
-			'verb' => 'POST',
42
-		],
43
-		[
44
-			'name' => 'Config#deleteAppValue',
45
-			'url' => '/api/v1/app/{appid}/{configkey}',
46
-			'verb' => 'DELETE',
47
-		],
48
-		[
49
-			'name' => 'Locking#isLockingEnabled',
50
-			'url' => '/api/v1/lockprovisioning',
51
-			'verb' => 'GET',
52
-		],
53
-		[
54
-			'name' => 'Locking#isLocked',
55
-			'url' => '/api/v1/lockprovisioning/{type}/{user}',
56
-			'verb' => 'GET',
57
-		],
58
-		[
59
-			'name' => 'Locking#acquireLock',
60
-			'url' => '/api/v1/lockprovisioning/{type}/{user}',
61
-			'verb' => 'POST',
62
-		],
63
-		[
64
-			'name' => 'Locking#changeLock',
65
-			'url' => '/api/v1/lockprovisioning/{type}/{user}',
66
-			'verb' => 'PUT',
67
-		],
68
-		[
69
-			'name' => 'Locking#releaseLock',
70
-			'url' => '/api/v1/lockprovisioning/{type}/{user}',
71
-			'verb' => 'DELETE',
72
-		],
73
-		[
74
-			'name' => 'Locking#releaseAll',
75
-			'url' => '/api/v1/lockprovisioning/{type}',
76
-			'verb' => 'DELETE',
77
-			'defaults' => [
78
-				'type' => null
79
-			]
80
-		],
81
-	],
37
+    'ocs' => [
38
+        [
39
+            'name' => 'Config#setAppValue',
40
+            'url' => '/api/v1/app/{appid}/{configkey}',
41
+            'verb' => 'POST',
42
+        ],
43
+        [
44
+            'name' => 'Config#deleteAppValue',
45
+            'url' => '/api/v1/app/{appid}/{configkey}',
46
+            'verb' => 'DELETE',
47
+        ],
48
+        [
49
+            'name' => 'Locking#isLockingEnabled',
50
+            'url' => '/api/v1/lockprovisioning',
51
+            'verb' => 'GET',
52
+        ],
53
+        [
54
+            'name' => 'Locking#isLocked',
55
+            'url' => '/api/v1/lockprovisioning/{type}/{user}',
56
+            'verb' => 'GET',
57
+        ],
58
+        [
59
+            'name' => 'Locking#acquireLock',
60
+            'url' => '/api/v1/lockprovisioning/{type}/{user}',
61
+            'verb' => 'POST',
62
+        ],
63
+        [
64
+            'name' => 'Locking#changeLock',
65
+            'url' => '/api/v1/lockprovisioning/{type}/{user}',
66
+            'verb' => 'PUT',
67
+        ],
68
+        [
69
+            'name' => 'Locking#releaseLock',
70
+            'url' => '/api/v1/lockprovisioning/{type}/{user}',
71
+            'verb' => 'DELETE',
72
+        ],
73
+        [
74
+            'name' => 'Locking#releaseAll',
75
+            'url' => '/api/v1/lockprovisioning/{type}',
76
+            'verb' => 'DELETE',
77
+            'defaults' => [
78
+                'type' => null
79
+            ]
80
+        ],
81
+    ],
82 82
 ];
Please login to merge, or discard this patch.
apps/files_external/lib/Controller/UserStoragesController.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -197,7 +197,7 @@
 block discarded – undo
197 197
 		} catch (NotFoundException $e) {
198 198
 			return new DataResponse(
199 199
 				[
200
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', [$id])
200
+					'message' => (string) $this->l10n->t('Storage with ID "%d" not found', [$id])
201 201
 				],
202 202
 				Http::STATUS_NOT_FOUND
203 203
 			);
Please login to merge, or discard this patch.
Indentation   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -44,183 +44,183 @@
 block discarded – undo
44 44
  * User storages controller
45 45
  */
46 46
 class UserStoragesController extends StoragesController {
47
-	/**
48
-	 * @var IUserSession
49
-	 */
50
-	private $userSession;
51
-
52
-	/**
53
-	 * Creates a new user storages controller.
54
-	 *
55
-	 * @param string $AppName application name
56
-	 * @param IRequest $request request object
57
-	 * @param IL10N $l10n l10n service
58
-	 * @param UserStoragesService $userStoragesService storage service
59
-	 * @param IUserSession $userSession
60
-	 * @param ILogger $logger
61
-	 */
62
-	public function __construct(
63
-		$AppName,
64
-		IRequest $request,
65
-		IL10N $l10n,
66
-		UserStoragesService $userStoragesService,
67
-		IUserSession $userSession,
68
-		ILogger $logger
69
-	) {
70
-		parent::__construct(
71
-			$AppName,
72
-			$request,
73
-			$l10n,
74
-			$userStoragesService,
75
-			$logger
76
-		);
77
-		$this->userSession = $userSession;
78
-	}
79
-
80
-	protected function manipulateStorageConfig(StorageConfig $storage) {
81
-		/** @var AuthMechanism */
82
-		$authMechanism = $storage->getAuthMechanism();
83
-		$authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
84
-		/** @var Backend */
85
-		$backend = $storage->getBackend();
86
-		$backend->manipulateStorageConfig($storage, $this->userSession->getUser());
87
-	}
88
-
89
-	/**
90
-	 * Get all storage entries
91
-	 *
92
-	 * @NoAdminRequired
93
-	 *
94
-	 * @return DataResponse
95
-	 */
96
-	public function index() {
97
-		return parent::index();
98
-	}
99
-
100
-	/**
101
-	 * Return storage
102
-	 *
103
-	 * @NoAdminRequired
104
-	 *
105
-	 * {@inheritdoc}
106
-	 */
107
-	public function show($id, $testOnly = true) {
108
-		return parent::show($id, $testOnly);
109
-	}
110
-
111
-	/**
112
-	 * Create an external storage entry.
113
-	 *
114
-	 * @param string $mountPoint storage mount point
115
-	 * @param string $backend backend identifier
116
-	 * @param string $authMechanism authentication mechanism identifier
117
-	 * @param array $backendOptions backend-specific options
118
-	 * @param array $mountOptions backend-specific mount options
119
-	 *
120
-	 * @return DataResponse
121
-	 *
122
-	 * @NoAdminRequired
123
-	 */
124
-	public function create(
125
-		$mountPoint,
126
-		$backend,
127
-		$authMechanism,
128
-		$backendOptions,
129
-		$mountOptions
130
-	) {
131
-		$newStorage = $this->createStorage(
132
-			$mountPoint,
133
-			$backend,
134
-			$authMechanism,
135
-			$backendOptions,
136
-			$mountOptions
137
-		);
138
-		if ($newStorage instanceof DataResponse) {
139
-			return $newStorage;
140
-		}
141
-
142
-		$response = $this->validate($newStorage);
143
-		if (!empty($response)) {
144
-			return $response;
145
-		}
146
-
147
-		$newStorage = $this->service->addStorage($newStorage);
148
-		$this->updateStorageStatus($newStorage);
149
-
150
-		return new DataResponse(
151
-			$this->formatStorageForUI($newStorage),
152
-			Http::STATUS_CREATED
153
-		);
154
-	}
155
-
156
-	/**
157
-	 * Update an external storage entry.
158
-	 *
159
-	 * @param int $id storage id
160
-	 * @param string $mountPoint storage mount point
161
-	 * @param string $backend backend identifier
162
-	 * @param string $authMechanism authentication mechanism identifier
163
-	 * @param array $backendOptions backend-specific options
164
-	 * @param array $mountOptions backend-specific mount options
165
-	 * @param bool $testOnly whether to storage should only test the connection or do more things
166
-	 *
167
-	 * @return DataResponse
168
-	 *
169
-	 * @NoAdminRequired
170
-	 */
171
-	public function update(
172
-		$id,
173
-		$mountPoint,
174
-		$backend,
175
-		$authMechanism,
176
-		$backendOptions,
177
-		$mountOptions,
178
-		$testOnly = true
179
-	) {
180
-		$storage = $this->createStorage(
181
-			$mountPoint,
182
-			$backend,
183
-			$authMechanism,
184
-			$backendOptions,
185
-			$mountOptions
186
-		);
187
-		if ($storage instanceof DataResponse) {
188
-			return $storage;
189
-		}
190
-		$storage->setId($id);
191
-
192
-		$response = $this->validate($storage);
193
-		if (!empty($response)) {
194
-			return $response;
195
-		}
196
-
197
-		try {
198
-			$storage = $this->service->updateStorage($storage);
199
-		} catch (NotFoundException $e) {
200
-			return new DataResponse(
201
-				[
202
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', [$id])
203
-				],
204
-				Http::STATUS_NOT_FOUND
205
-			);
206
-		}
207
-
208
-		$this->updateStorageStatus($storage, $testOnly);
209
-
210
-		return new DataResponse(
211
-			$this->formatStorageForUI($storage),
212
-			Http::STATUS_OK
213
-		);
214
-	}
215
-
216
-	/**
217
-	 * Delete storage
218
-	 *
219
-	 * @NoAdminRequired
220
-	 *
221
-	 * {@inheritdoc}
222
-	 */
223
-	public function destroy($id) {
224
-		return parent::destroy($id);
225
-	}
47
+    /**
48
+     * @var IUserSession
49
+     */
50
+    private $userSession;
51
+
52
+    /**
53
+     * Creates a new user storages controller.
54
+     *
55
+     * @param string $AppName application name
56
+     * @param IRequest $request request object
57
+     * @param IL10N $l10n l10n service
58
+     * @param UserStoragesService $userStoragesService storage service
59
+     * @param IUserSession $userSession
60
+     * @param ILogger $logger
61
+     */
62
+    public function __construct(
63
+        $AppName,
64
+        IRequest $request,
65
+        IL10N $l10n,
66
+        UserStoragesService $userStoragesService,
67
+        IUserSession $userSession,
68
+        ILogger $logger
69
+    ) {
70
+        parent::__construct(
71
+            $AppName,
72
+            $request,
73
+            $l10n,
74
+            $userStoragesService,
75
+            $logger
76
+        );
77
+        $this->userSession = $userSession;
78
+    }
79
+
80
+    protected function manipulateStorageConfig(StorageConfig $storage) {
81
+        /** @var AuthMechanism */
82
+        $authMechanism = $storage->getAuthMechanism();
83
+        $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
84
+        /** @var Backend */
85
+        $backend = $storage->getBackend();
86
+        $backend->manipulateStorageConfig($storage, $this->userSession->getUser());
87
+    }
88
+
89
+    /**
90
+     * Get all storage entries
91
+     *
92
+     * @NoAdminRequired
93
+     *
94
+     * @return DataResponse
95
+     */
96
+    public function index() {
97
+        return parent::index();
98
+    }
99
+
100
+    /**
101
+     * Return storage
102
+     *
103
+     * @NoAdminRequired
104
+     *
105
+     * {@inheritdoc}
106
+     */
107
+    public function show($id, $testOnly = true) {
108
+        return parent::show($id, $testOnly);
109
+    }
110
+
111
+    /**
112
+     * Create an external storage entry.
113
+     *
114
+     * @param string $mountPoint storage mount point
115
+     * @param string $backend backend identifier
116
+     * @param string $authMechanism authentication mechanism identifier
117
+     * @param array $backendOptions backend-specific options
118
+     * @param array $mountOptions backend-specific mount options
119
+     *
120
+     * @return DataResponse
121
+     *
122
+     * @NoAdminRequired
123
+     */
124
+    public function create(
125
+        $mountPoint,
126
+        $backend,
127
+        $authMechanism,
128
+        $backendOptions,
129
+        $mountOptions
130
+    ) {
131
+        $newStorage = $this->createStorage(
132
+            $mountPoint,
133
+            $backend,
134
+            $authMechanism,
135
+            $backendOptions,
136
+            $mountOptions
137
+        );
138
+        if ($newStorage instanceof DataResponse) {
139
+            return $newStorage;
140
+        }
141
+
142
+        $response = $this->validate($newStorage);
143
+        if (!empty($response)) {
144
+            return $response;
145
+        }
146
+
147
+        $newStorage = $this->service->addStorage($newStorage);
148
+        $this->updateStorageStatus($newStorage);
149
+
150
+        return new DataResponse(
151
+            $this->formatStorageForUI($newStorage),
152
+            Http::STATUS_CREATED
153
+        );
154
+    }
155
+
156
+    /**
157
+     * Update an external storage entry.
158
+     *
159
+     * @param int $id storage id
160
+     * @param string $mountPoint storage mount point
161
+     * @param string $backend backend identifier
162
+     * @param string $authMechanism authentication mechanism identifier
163
+     * @param array $backendOptions backend-specific options
164
+     * @param array $mountOptions backend-specific mount options
165
+     * @param bool $testOnly whether to storage should only test the connection or do more things
166
+     *
167
+     * @return DataResponse
168
+     *
169
+     * @NoAdminRequired
170
+     */
171
+    public function update(
172
+        $id,
173
+        $mountPoint,
174
+        $backend,
175
+        $authMechanism,
176
+        $backendOptions,
177
+        $mountOptions,
178
+        $testOnly = true
179
+    ) {
180
+        $storage = $this->createStorage(
181
+            $mountPoint,
182
+            $backend,
183
+            $authMechanism,
184
+            $backendOptions,
185
+            $mountOptions
186
+        );
187
+        if ($storage instanceof DataResponse) {
188
+            return $storage;
189
+        }
190
+        $storage->setId($id);
191
+
192
+        $response = $this->validate($storage);
193
+        if (!empty($response)) {
194
+            return $response;
195
+        }
196
+
197
+        try {
198
+            $storage = $this->service->updateStorage($storage);
199
+        } catch (NotFoundException $e) {
200
+            return new DataResponse(
201
+                [
202
+                    'message' => (string)$this->l10n->t('Storage with ID "%d" not found', [$id])
203
+                ],
204
+                Http::STATUS_NOT_FOUND
205
+            );
206
+        }
207
+
208
+        $this->updateStorageStatus($storage, $testOnly);
209
+
210
+        return new DataResponse(
211
+            $this->formatStorageForUI($storage),
212
+            Http::STATUS_OK
213
+        );
214
+    }
215
+
216
+    /**
217
+     * Delete storage
218
+     *
219
+     * @NoAdminRequired
220
+     *
221
+     * {@inheritdoc}
222
+     */
223
+    public function destroy($id) {
224
+        return parent::destroy($id);
225
+    }
226 226
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Controller/UserGlobalStoragesController.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 		} catch (NotFoundException $e) {
123 123
 			return new DataResponse(
124 124
 				[
125
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', [$id])
125
+					'message' => (string) $this->l10n->t('Storage with ID "%d" not found', [$id])
126 126
 				],
127 127
 				Http::STATUS_NOT_FOUND
128 128
 			);
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 			} else {
163 163
 				return new DataResponse(
164 164
 					[
165
-						'message' => (string)$this->l10n->t('Storage with ID "%d" is not user editable', [$id])
165
+						'message' => (string) $this->l10n->t('Storage with ID "%d" is not user editable', [$id])
166 166
 					],
167 167
 					Http::STATUS_FORBIDDEN
168 168
 				);
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 		} catch (NotFoundException $e) {
171 171
 			return new DataResponse(
172 172
 				[
173
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', [$id])
173
+					'message' => (string) $this->l10n->t('Storage with ID "%d" not found', [$id])
174 174
 				],
175 175
 				Http::STATUS_NOT_FOUND
176 176
 			);
Please login to merge, or discard this patch.
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -46,163 +46,163 @@
 block discarded – undo
46 46
  * User global storages controller
47 47
  */
48 48
 class UserGlobalStoragesController extends StoragesController {
49
-	/**
50
-	 * @var IUserSession
51
-	 */
52
-	private $userSession;
53
-
54
-	/**
55
-	 * Creates a new user global storages controller.
56
-	 *
57
-	 * @param string $AppName application name
58
-	 * @param IRequest $request request object
59
-	 * @param IL10N $l10n l10n service
60
-	 * @param UserGlobalStoragesService $userGlobalStoragesService storage service
61
-	 * @param IUserSession $userSession
62
-	 */
63
-	public function __construct(
64
-		$AppName,
65
-		IRequest $request,
66
-		IL10N $l10n,
67
-		UserGlobalStoragesService $userGlobalStoragesService,
68
-		IUserSession $userSession,
69
-		ILogger $logger
70
-	) {
71
-		parent::__construct(
72
-			$AppName,
73
-			$request,
74
-			$l10n,
75
-			$userGlobalStoragesService,
76
-			$logger
77
-		);
78
-		$this->userSession = $userSession;
79
-	}
80
-
81
-	/**
82
-	 * Get all storage entries
83
-	 *
84
-	 * @return DataResponse
85
-	 *
86
-	 * @NoAdminRequired
87
-	 */
88
-	public function index() {
89
-		$storages = $this->formatStoragesForUI($this->service->getUniqueStorages());
90
-
91
-		// remove configuration data, this must be kept private
92
-		foreach ($storages as $storage) {
93
-			$this->sanitizeStorage($storage);
94
-		}
95
-
96
-		return new DataResponse(
97
-			$storages,
98
-			Http::STATUS_OK
99
-		);
100
-	}
101
-
102
-	protected function manipulateStorageConfig(StorageConfig $storage) {
103
-		/** @var AuthMechanism */
104
-		$authMechanism = $storage->getAuthMechanism();
105
-		$authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
106
-		/** @var Backend */
107
-		$backend = $storage->getBackend();
108
-		$backend->manipulateStorageConfig($storage, $this->userSession->getUser());
109
-	}
110
-
111
-	/**
112
-	 * Get an external storage entry.
113
-	 *
114
-	 * @param int $id storage id
115
-	 * @param bool $testOnly whether to storage should only test the connection or do more things
116
-	 * @return DataResponse
117
-	 *
118
-	 * @NoAdminRequired
119
-	 */
120
-	public function show($id, $testOnly = true) {
121
-		try {
122
-			$storage = $this->service->getStorage($id);
123
-
124
-			$this->updateStorageStatus($storage, $testOnly);
125
-		} catch (NotFoundException $e) {
126
-			return new DataResponse(
127
-				[
128
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', [$id])
129
-				],
130
-				Http::STATUS_NOT_FOUND
131
-			);
132
-		}
133
-
134
-		$this->sanitizeStorage($storage);
135
-
136
-		return new DataResponse(
137
-			$this->formatStorageForUI($storage),
138
-			Http::STATUS_OK
139
-		);
140
-	}
141
-
142
-	/**
143
-	 * Update an external storage entry.
144
-	 * Only allows setting user provided backend fields
145
-	 *
146
-	 * @param int $id storage id
147
-	 * @param array $backendOptions backend-specific options
148
-	 * @param bool $testOnly whether to storage should only test the connection or do more things
149
-	 *
150
-	 * @return DataResponse
151
-	 *
152
-	 * @NoAdminRequired
153
-	 */
154
-	public function update(
155
-		$id,
156
-		$backendOptions,
157
-		$testOnly = true
158
-	) {
159
-		try {
160
-			$storage = $this->service->getStorage($id);
161
-			$authMechanism = $storage->getAuthMechanism();
162
-			if ($authMechanism instanceof IUserProvided || $authMechanism instanceof  UserGlobalAuth) {
163
-				$authMechanism->saveBackendOptions($this->userSession->getUser(), $id, $backendOptions);
164
-				$authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
165
-			} else {
166
-				return new DataResponse(
167
-					[
168
-						'message' => (string)$this->l10n->t('Storage with ID "%d" is not user editable', [$id])
169
-					],
170
-					Http::STATUS_FORBIDDEN
171
-				);
172
-			}
173
-		} catch (NotFoundException $e) {
174
-			return new DataResponse(
175
-				[
176
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', [$id])
177
-				],
178
-				Http::STATUS_NOT_FOUND
179
-			);
180
-		}
181
-
182
-		$this->updateStorageStatus($storage, $testOnly);
183
-		$this->sanitizeStorage($storage);
184
-
185
-		return new DataResponse(
186
-			$this->formatStorageForUI($storage),
187
-			Http::STATUS_OK
188
-		);
189
-	}
190
-
191
-	/**
192
-	 * Remove sensitive data from a StorageConfig before returning it to the user
193
-	 *
194
-	 * @param StorageConfig $storage
195
-	 */
196
-	protected function sanitizeStorage(StorageConfig $storage) {
197
-		$storage->setBackendOptions([]);
198
-		$storage->setMountOptions([]);
199
-
200
-		if ($storage->getAuthMechanism() instanceof IUserProvided) {
201
-			try {
202
-				$storage->getAuthMechanism()->manipulateStorageConfig($storage, $this->userSession->getUser());
203
-			} catch (InsufficientDataForMeaningfulAnswerException $e) {
204
-				// not configured yet
205
-			}
206
-		}
207
-	}
49
+    /**
50
+     * @var IUserSession
51
+     */
52
+    private $userSession;
53
+
54
+    /**
55
+     * Creates a new user global storages controller.
56
+     *
57
+     * @param string $AppName application name
58
+     * @param IRequest $request request object
59
+     * @param IL10N $l10n l10n service
60
+     * @param UserGlobalStoragesService $userGlobalStoragesService storage service
61
+     * @param IUserSession $userSession
62
+     */
63
+    public function __construct(
64
+        $AppName,
65
+        IRequest $request,
66
+        IL10N $l10n,
67
+        UserGlobalStoragesService $userGlobalStoragesService,
68
+        IUserSession $userSession,
69
+        ILogger $logger
70
+    ) {
71
+        parent::__construct(
72
+            $AppName,
73
+            $request,
74
+            $l10n,
75
+            $userGlobalStoragesService,
76
+            $logger
77
+        );
78
+        $this->userSession = $userSession;
79
+    }
80
+
81
+    /**
82
+     * Get all storage entries
83
+     *
84
+     * @return DataResponse
85
+     *
86
+     * @NoAdminRequired
87
+     */
88
+    public function index() {
89
+        $storages = $this->formatStoragesForUI($this->service->getUniqueStorages());
90
+
91
+        // remove configuration data, this must be kept private
92
+        foreach ($storages as $storage) {
93
+            $this->sanitizeStorage($storage);
94
+        }
95
+
96
+        return new DataResponse(
97
+            $storages,
98
+            Http::STATUS_OK
99
+        );
100
+    }
101
+
102
+    protected function manipulateStorageConfig(StorageConfig $storage) {
103
+        /** @var AuthMechanism */
104
+        $authMechanism = $storage->getAuthMechanism();
105
+        $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
106
+        /** @var Backend */
107
+        $backend = $storage->getBackend();
108
+        $backend->manipulateStorageConfig($storage, $this->userSession->getUser());
109
+    }
110
+
111
+    /**
112
+     * Get an external storage entry.
113
+     *
114
+     * @param int $id storage id
115
+     * @param bool $testOnly whether to storage should only test the connection or do more things
116
+     * @return DataResponse
117
+     *
118
+     * @NoAdminRequired
119
+     */
120
+    public function show($id, $testOnly = true) {
121
+        try {
122
+            $storage = $this->service->getStorage($id);
123
+
124
+            $this->updateStorageStatus($storage, $testOnly);
125
+        } catch (NotFoundException $e) {
126
+            return new DataResponse(
127
+                [
128
+                    'message' => (string)$this->l10n->t('Storage with ID "%d" not found', [$id])
129
+                ],
130
+                Http::STATUS_NOT_FOUND
131
+            );
132
+        }
133
+
134
+        $this->sanitizeStorage($storage);
135
+
136
+        return new DataResponse(
137
+            $this->formatStorageForUI($storage),
138
+            Http::STATUS_OK
139
+        );
140
+    }
141
+
142
+    /**
143
+     * Update an external storage entry.
144
+     * Only allows setting user provided backend fields
145
+     *
146
+     * @param int $id storage id
147
+     * @param array $backendOptions backend-specific options
148
+     * @param bool $testOnly whether to storage should only test the connection or do more things
149
+     *
150
+     * @return DataResponse
151
+     *
152
+     * @NoAdminRequired
153
+     */
154
+    public function update(
155
+        $id,
156
+        $backendOptions,
157
+        $testOnly = true
158
+    ) {
159
+        try {
160
+            $storage = $this->service->getStorage($id);
161
+            $authMechanism = $storage->getAuthMechanism();
162
+            if ($authMechanism instanceof IUserProvided || $authMechanism instanceof  UserGlobalAuth) {
163
+                $authMechanism->saveBackendOptions($this->userSession->getUser(), $id, $backendOptions);
164
+                $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
165
+            } else {
166
+                return new DataResponse(
167
+                    [
168
+                        'message' => (string)$this->l10n->t('Storage with ID "%d" is not user editable', [$id])
169
+                    ],
170
+                    Http::STATUS_FORBIDDEN
171
+                );
172
+            }
173
+        } catch (NotFoundException $e) {
174
+            return new DataResponse(
175
+                [
176
+                    'message' => (string)$this->l10n->t('Storage with ID "%d" not found', [$id])
177
+                ],
178
+                Http::STATUS_NOT_FOUND
179
+            );
180
+        }
181
+
182
+        $this->updateStorageStatus($storage, $testOnly);
183
+        $this->sanitizeStorage($storage);
184
+
185
+        return new DataResponse(
186
+            $this->formatStorageForUI($storage),
187
+            Http::STATUS_OK
188
+        );
189
+    }
190
+
191
+    /**
192
+     * Remove sensitive data from a StorageConfig before returning it to the user
193
+     *
194
+     * @param StorageConfig $storage
195
+     */
196
+    protected function sanitizeStorage(StorageConfig $storage) {
197
+        $storage->setBackendOptions([]);
198
+        $storage->setMountOptions([]);
199
+
200
+        if ($storage->getAuthMechanism() instanceof IUserProvided) {
201
+            try {
202
+                $storage->getAuthMechanism()->manipulateStorageConfig($storage, $this->userSession->getUser());
203
+            } catch (InsufficientDataForMeaningfulAnswerException $e) {
204
+                // not configured yet
205
+            }
206
+        }
207
+    }
208 208
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/PriorityTrait.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -29,31 +29,31 @@
 block discarded – undo
29 29
  */
30 30
 trait PriorityTrait {
31 31
 
32
-	/** @var int initial priority */
33
-	protected $priority = BackendService::PRIORITY_DEFAULT;
32
+    /** @var int initial priority */
33
+    protected $priority = BackendService::PRIORITY_DEFAULT;
34 34
 
35
-	/**
36
-	 * @return int
37
-	 */
38
-	public function getPriority() {
39
-		return $this->priority;
40
-	}
35
+    /**
36
+     * @return int
37
+     */
38
+    public function getPriority() {
39
+        return $this->priority;
40
+    }
41 41
 
42
-	/**
43
-	 * @param int $priority
44
-	 * @return self
45
-	 */
46
-	public function setPriority($priority) {
47
-		$this->priority = $priority;
48
-		return $this;
49
-	}
42
+    /**
43
+     * @param int $priority
44
+     * @return self
45
+     */
46
+    public function setPriority($priority) {
47
+        $this->priority = $priority;
48
+        return $this;
49
+    }
50 50
 
51
-	/**
52
-	 * @param PriorityTrait $a
53
-	 * @param PriorityTrait $b
54
-	 * @return int
55
-	 */
56
-	public static function priorityCompare(PriorityTrait $a, PriorityTrait $b) {
57
-		return ($a->getPriority() - $b->getPriority());
58
-	}
51
+    /**
52
+     * @param PriorityTrait $a
53
+     * @param PriorityTrait $b
54
+     * @return int
55
+     */
56
+    public static function priorityCompare(PriorityTrait $a, PriorityTrait $b) {
57
+        return ($a->getPriority() - $b->getPriority());
58
+    }
59 59
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/StorageConfig.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 				if (isset($parameters[$key])) {
221 221
 					switch ($parameters[$key]->getType()) {
222 222
 						case \OCA\Files_External\Lib\DefinitionParameter::VALUE_BOOLEAN:
223
-							$value = (bool)$value;
223
+							$value = (bool) $value;
224 224
 							break;
225 225
 					}
226 226
 					$backendOptions[$key] = $value;
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 			$result['statusMessage'] = $this->statusMessage;
427 427
 		}
428 428
 		$result['userProvided'] = $this->authMechanism instanceof IUserProvided;
429
-		$result['type'] = ($this->getType() === self::MOUNT_TYPE_PERSONAl) ? 'personal': 'system';
429
+		$result['type'] = ($this->getType() === self::MOUNT_TYPE_PERSONAl) ? 'personal' : 'system';
430 430
 		return $result;
431 431
 	}
432 432
 }
Please login to merge, or discard this patch.
Indentation   +394 added lines, -394 removed lines patch added patch discarded remove patch
@@ -37,398 +37,398 @@
 block discarded – undo
37 37
  * External storage configuration
38 38
  */
39 39
 class StorageConfig implements \JsonSerializable {
40
-	public const MOUNT_TYPE_ADMIN = 1;
41
-	public const MOUNT_TYPE_PERSONAl = 2;
42
-
43
-	/**
44
-	 * Storage config id
45
-	 *
46
-	 * @var int
47
-	 */
48
-	private $id;
49
-
50
-	/**
51
-	 * Backend
52
-	 *
53
-	 * @var Backend
54
-	 */
55
-	private $backend;
56
-
57
-	/**
58
-	 * Authentication mechanism
59
-	 *
60
-	 * @var AuthMechanism
61
-	 */
62
-	private $authMechanism;
63
-
64
-	/**
65
-	 * Backend options
66
-	 *
67
-	 * @var array
68
-	 */
69
-	private $backendOptions = [];
70
-
71
-	/**
72
-	 * Mount point path, relative to the user's "files" folder
73
-	 *
74
-	 * @var string
75
-	 */
76
-	private $mountPoint;
77
-
78
-	/**
79
-	 * Storage status
80
-	 *
81
-	 * @var int
82
-	 */
83
-	private $status;
84
-
85
-	/**
86
-	 * Status message
87
-	 *
88
-	 * @var string
89
-	 */
90
-	private $statusMessage;
91
-
92
-	/**
93
-	 * Priority
94
-	 *
95
-	 * @var int
96
-	 */
97
-	private $priority;
98
-
99
-	/**
100
-	 * List of users who have access to this storage
101
-	 *
102
-	 * @var array
103
-	 */
104
-	private $applicableUsers = [];
105
-
106
-	/**
107
-	 * List of groups that have access to this storage
108
-	 *
109
-	 * @var array
110
-	 */
111
-	private $applicableGroups = [];
112
-
113
-	/**
114
-	 * Mount-specific options
115
-	 *
116
-	 * @var array
117
-	 */
118
-	private $mountOptions = [];
119
-
120
-	/**
121
-	 * Whether it's a personal or admin mount
122
-	 *
123
-	 * @var int
124
-	 */
125
-	private $type;
126
-
127
-	/**
128
-	 * Creates a storage config
129
-	 *
130
-	 * @param int|null $id config id or null for a new config
131
-	 */
132
-	public function __construct($id = null) {
133
-		$this->id = $id;
134
-		$this->mountOptions['enable_sharing'] = false;
135
-	}
136
-
137
-	/**
138
-	 * Returns the configuration id
139
-	 *
140
-	 * @return int
141
-	 */
142
-	public function getId() {
143
-		return $this->id;
144
-	}
145
-
146
-	/**
147
-	 * Sets the configuration id
148
-	 *
149
-	 * @param int $id configuration id
150
-	 */
151
-	public function setId($id) {
152
-		$this->id = $id;
153
-	}
154
-
155
-	/**
156
-	 * Returns mount point path relative to the user's
157
-	 * "files" folder.
158
-	 *
159
-	 * @return string path
160
-	 */
161
-	public function getMountPoint() {
162
-		return $this->mountPoint;
163
-	}
164
-
165
-	/**
166
-	 * Sets mount point path relative to the user's
167
-	 * "files" folder.
168
-	 * The path will be normalized.
169
-	 *
170
-	 * @param string $mountPoint path
171
-	 */
172
-	public function setMountPoint($mountPoint) {
173
-		$this->mountPoint = \OC\Files\Filesystem::normalizePath($mountPoint);
174
-	}
175
-
176
-	/**
177
-	 * @return Backend
178
-	 */
179
-	public function getBackend() {
180
-		return $this->backend;
181
-	}
182
-
183
-	/**
184
-	 * @param Backend $backend
185
-	 */
186
-	public function setBackend(Backend $backend) {
187
-		$this->backend = $backend;
188
-	}
189
-
190
-	/**
191
-	 * @return AuthMechanism
192
-	 */
193
-	public function getAuthMechanism() {
194
-		return $this->authMechanism;
195
-	}
196
-
197
-	/**
198
-	 * @param AuthMechanism $authMechanism
199
-	 */
200
-	public function setAuthMechanism(AuthMechanism $authMechanism) {
201
-		$this->authMechanism = $authMechanism;
202
-	}
203
-
204
-	/**
205
-	 * Returns the external storage backend-specific options
206
-	 *
207
-	 * @return array backend options
208
-	 */
209
-	public function getBackendOptions() {
210
-		return $this->backendOptions;
211
-	}
212
-
213
-	/**
214
-	 * Sets the external storage backend-specific options
215
-	 *
216
-	 * @param array $backendOptions backend options
217
-	 */
218
-	public function setBackendOptions($backendOptions) {
219
-		if ($this->getBackend() instanceof  Backend) {
220
-			$parameters = $this->getBackend()->getParameters();
221
-			foreach ($backendOptions as $key => $value) {
222
-				if (isset($parameters[$key])) {
223
-					switch ($parameters[$key]->getType()) {
224
-						case \OCA\Files_External\Lib\DefinitionParameter::VALUE_BOOLEAN:
225
-							$value = (bool)$value;
226
-							break;
227
-					}
228
-					$backendOptions[$key] = $value;
229
-				}
230
-			}
231
-		}
232
-
233
-		$this->backendOptions = $backendOptions;
234
-	}
235
-
236
-	/**
237
-	 * @param string $key
238
-	 * @return mixed
239
-	 */
240
-	public function getBackendOption($key) {
241
-		if (isset($this->backendOptions[$key])) {
242
-			return $this->backendOptions[$key];
243
-		}
244
-		return null;
245
-	}
246
-
247
-	/**
248
-	 * @param string $key
249
-	 * @param mixed $value
250
-	 */
251
-	public function setBackendOption($key, $value) {
252
-		$this->backendOptions[$key] = $value;
253
-	}
254
-
255
-	/**
256
-	 * Returns the mount priority
257
-	 *
258
-	 * @return int priority
259
-	 */
260
-	public function getPriority() {
261
-		return $this->priority;
262
-	}
263
-
264
-	/**
265
-	 * Sets the mount priotity
266
-	 *
267
-	 * @param int $priority priority
268
-	 */
269
-	public function setPriority($priority) {
270
-		$this->priority = $priority;
271
-	}
272
-
273
-	/**
274
-	 * Returns the users for which to mount this storage
275
-	 *
276
-	 * @return array applicable users
277
-	 */
278
-	public function getApplicableUsers() {
279
-		return $this->applicableUsers;
280
-	}
281
-
282
-	/**
283
-	 * Sets the users for which to mount this storage
284
-	 *
285
-	 * @param array|null $applicableUsers applicable users
286
-	 */
287
-	public function setApplicableUsers($applicableUsers) {
288
-		if (is_null($applicableUsers)) {
289
-			$applicableUsers = [];
290
-		}
291
-		$this->applicableUsers = $applicableUsers;
292
-	}
293
-
294
-	/**
295
-	 * Returns the groups for which to mount this storage
296
-	 *
297
-	 * @return array applicable groups
298
-	 */
299
-	public function getApplicableGroups() {
300
-		return $this->applicableGroups;
301
-	}
302
-
303
-	/**
304
-	 * Sets the groups for which to mount this storage
305
-	 *
306
-	 * @param array|null $applicableGroups applicable groups
307
-	 */
308
-	public function setApplicableGroups($applicableGroups) {
309
-		if (is_null($applicableGroups)) {
310
-			$applicableGroups = [];
311
-		}
312
-		$this->applicableGroups = $applicableGroups;
313
-	}
314
-
315
-	/**
316
-	 * Returns the mount-specific options
317
-	 *
318
-	 * @return array mount specific options
319
-	 */
320
-	public function getMountOptions() {
321
-		return $this->mountOptions;
322
-	}
323
-
324
-	/**
325
-	 * Sets the mount-specific options
326
-	 *
327
-	 * @param array $mountOptions applicable groups
328
-	 */
329
-	public function setMountOptions($mountOptions) {
330
-		if (is_null($mountOptions)) {
331
-			$mountOptions = [];
332
-		}
333
-		$this->mountOptions = $mountOptions;
334
-	}
335
-
336
-	/**
337
-	 * @param string $key
338
-	 * @return mixed
339
-	 */
340
-	public function getMountOption($key) {
341
-		if (isset($this->mountOptions[$key])) {
342
-			return $this->mountOptions[$key];
343
-		}
344
-		return null;
345
-	}
346
-
347
-	/**
348
-	 * @param string $key
349
-	 * @param mixed $value
350
-	 */
351
-	public function setMountOption($key, $value) {
352
-		$this->mountOptions[$key] = $value;
353
-	}
354
-
355
-	/**
356
-	 * Gets the storage status, whether the config worked last time
357
-	 *
358
-	 * @return int $status status
359
-	 */
360
-	public function getStatus() {
361
-		return $this->status;
362
-	}
363
-
364
-	/**
365
-	 * Gets the message describing the storage status
366
-	 *
367
-	 * @return string|null
368
-	 */
369
-	public function getStatusMessage() {
370
-		return $this->statusMessage;
371
-	}
372
-
373
-	/**
374
-	 * Sets the storage status, whether the config worked last time
375
-	 *
376
-	 * @param int $status status
377
-	 * @param string|null $message optional message
378
-	 */
379
-	public function setStatus($status, $message = null) {
380
-		$this->status = $status;
381
-		$this->statusMessage = $message;
382
-	}
383
-
384
-	/**
385
-	 * @return int self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl
386
-	 */
387
-	public function getType() {
388
-		return $this->type;
389
-	}
390
-
391
-	/**
392
-	 * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl
393
-	 */
394
-	public function setType($type) {
395
-		$this->type = $type;
396
-	}
397
-
398
-	/**
399
-	 * Serialize config to JSON
400
-	 *
401
-	 * @return array
402
-	 */
403
-	public function jsonSerialize() {
404
-		$result = [];
405
-		if (!is_null($this->id)) {
406
-			$result['id'] = $this->id;
407
-		}
408
-		$result['mountPoint'] = $this->mountPoint;
409
-		$result['backend'] = $this->backend->getIdentifier();
410
-		$result['authMechanism'] = $this->authMechanism->getIdentifier();
411
-		$result['backendOptions'] = $this->backendOptions;
412
-		if (!is_null($this->priority)) {
413
-			$result['priority'] = $this->priority;
414
-		}
415
-		if (!empty($this->applicableUsers)) {
416
-			$result['applicableUsers'] = $this->applicableUsers;
417
-		}
418
-		if (!empty($this->applicableGroups)) {
419
-			$result['applicableGroups'] = $this->applicableGroups;
420
-		}
421
-		if (!empty($this->mountOptions)) {
422
-			$result['mountOptions'] = $this->mountOptions;
423
-		}
424
-		if (!is_null($this->status)) {
425
-			$result['status'] = $this->status;
426
-		}
427
-		if (!is_null($this->statusMessage)) {
428
-			$result['statusMessage'] = $this->statusMessage;
429
-		}
430
-		$result['userProvided'] = $this->authMechanism instanceof IUserProvided;
431
-		$result['type'] = ($this->getType() === self::MOUNT_TYPE_PERSONAl) ? 'personal': 'system';
432
-		return $result;
433
-	}
40
+    public const MOUNT_TYPE_ADMIN = 1;
41
+    public const MOUNT_TYPE_PERSONAl = 2;
42
+
43
+    /**
44
+     * Storage config id
45
+     *
46
+     * @var int
47
+     */
48
+    private $id;
49
+
50
+    /**
51
+     * Backend
52
+     *
53
+     * @var Backend
54
+     */
55
+    private $backend;
56
+
57
+    /**
58
+     * Authentication mechanism
59
+     *
60
+     * @var AuthMechanism
61
+     */
62
+    private $authMechanism;
63
+
64
+    /**
65
+     * Backend options
66
+     *
67
+     * @var array
68
+     */
69
+    private $backendOptions = [];
70
+
71
+    /**
72
+     * Mount point path, relative to the user's "files" folder
73
+     *
74
+     * @var string
75
+     */
76
+    private $mountPoint;
77
+
78
+    /**
79
+     * Storage status
80
+     *
81
+     * @var int
82
+     */
83
+    private $status;
84
+
85
+    /**
86
+     * Status message
87
+     *
88
+     * @var string
89
+     */
90
+    private $statusMessage;
91
+
92
+    /**
93
+     * Priority
94
+     *
95
+     * @var int
96
+     */
97
+    private $priority;
98
+
99
+    /**
100
+     * List of users who have access to this storage
101
+     *
102
+     * @var array
103
+     */
104
+    private $applicableUsers = [];
105
+
106
+    /**
107
+     * List of groups that have access to this storage
108
+     *
109
+     * @var array
110
+     */
111
+    private $applicableGroups = [];
112
+
113
+    /**
114
+     * Mount-specific options
115
+     *
116
+     * @var array
117
+     */
118
+    private $mountOptions = [];
119
+
120
+    /**
121
+     * Whether it's a personal or admin mount
122
+     *
123
+     * @var int
124
+     */
125
+    private $type;
126
+
127
+    /**
128
+     * Creates a storage config
129
+     *
130
+     * @param int|null $id config id or null for a new config
131
+     */
132
+    public function __construct($id = null) {
133
+        $this->id = $id;
134
+        $this->mountOptions['enable_sharing'] = false;
135
+    }
136
+
137
+    /**
138
+     * Returns the configuration id
139
+     *
140
+     * @return int
141
+     */
142
+    public function getId() {
143
+        return $this->id;
144
+    }
145
+
146
+    /**
147
+     * Sets the configuration id
148
+     *
149
+     * @param int $id configuration id
150
+     */
151
+    public function setId($id) {
152
+        $this->id = $id;
153
+    }
154
+
155
+    /**
156
+     * Returns mount point path relative to the user's
157
+     * "files" folder.
158
+     *
159
+     * @return string path
160
+     */
161
+    public function getMountPoint() {
162
+        return $this->mountPoint;
163
+    }
164
+
165
+    /**
166
+     * Sets mount point path relative to the user's
167
+     * "files" folder.
168
+     * The path will be normalized.
169
+     *
170
+     * @param string $mountPoint path
171
+     */
172
+    public function setMountPoint($mountPoint) {
173
+        $this->mountPoint = \OC\Files\Filesystem::normalizePath($mountPoint);
174
+    }
175
+
176
+    /**
177
+     * @return Backend
178
+     */
179
+    public function getBackend() {
180
+        return $this->backend;
181
+    }
182
+
183
+    /**
184
+     * @param Backend $backend
185
+     */
186
+    public function setBackend(Backend $backend) {
187
+        $this->backend = $backend;
188
+    }
189
+
190
+    /**
191
+     * @return AuthMechanism
192
+     */
193
+    public function getAuthMechanism() {
194
+        return $this->authMechanism;
195
+    }
196
+
197
+    /**
198
+     * @param AuthMechanism $authMechanism
199
+     */
200
+    public function setAuthMechanism(AuthMechanism $authMechanism) {
201
+        $this->authMechanism = $authMechanism;
202
+    }
203
+
204
+    /**
205
+     * Returns the external storage backend-specific options
206
+     *
207
+     * @return array backend options
208
+     */
209
+    public function getBackendOptions() {
210
+        return $this->backendOptions;
211
+    }
212
+
213
+    /**
214
+     * Sets the external storage backend-specific options
215
+     *
216
+     * @param array $backendOptions backend options
217
+     */
218
+    public function setBackendOptions($backendOptions) {
219
+        if ($this->getBackend() instanceof  Backend) {
220
+            $parameters = $this->getBackend()->getParameters();
221
+            foreach ($backendOptions as $key => $value) {
222
+                if (isset($parameters[$key])) {
223
+                    switch ($parameters[$key]->getType()) {
224
+                        case \OCA\Files_External\Lib\DefinitionParameter::VALUE_BOOLEAN:
225
+                            $value = (bool)$value;
226
+                            break;
227
+                    }
228
+                    $backendOptions[$key] = $value;
229
+                }
230
+            }
231
+        }
232
+
233
+        $this->backendOptions = $backendOptions;
234
+    }
235
+
236
+    /**
237
+     * @param string $key
238
+     * @return mixed
239
+     */
240
+    public function getBackendOption($key) {
241
+        if (isset($this->backendOptions[$key])) {
242
+            return $this->backendOptions[$key];
243
+        }
244
+        return null;
245
+    }
246
+
247
+    /**
248
+     * @param string $key
249
+     * @param mixed $value
250
+     */
251
+    public function setBackendOption($key, $value) {
252
+        $this->backendOptions[$key] = $value;
253
+    }
254
+
255
+    /**
256
+     * Returns the mount priority
257
+     *
258
+     * @return int priority
259
+     */
260
+    public function getPriority() {
261
+        return $this->priority;
262
+    }
263
+
264
+    /**
265
+     * Sets the mount priotity
266
+     *
267
+     * @param int $priority priority
268
+     */
269
+    public function setPriority($priority) {
270
+        $this->priority = $priority;
271
+    }
272
+
273
+    /**
274
+     * Returns the users for which to mount this storage
275
+     *
276
+     * @return array applicable users
277
+     */
278
+    public function getApplicableUsers() {
279
+        return $this->applicableUsers;
280
+    }
281
+
282
+    /**
283
+     * Sets the users for which to mount this storage
284
+     *
285
+     * @param array|null $applicableUsers applicable users
286
+     */
287
+    public function setApplicableUsers($applicableUsers) {
288
+        if (is_null($applicableUsers)) {
289
+            $applicableUsers = [];
290
+        }
291
+        $this->applicableUsers = $applicableUsers;
292
+    }
293
+
294
+    /**
295
+     * Returns the groups for which to mount this storage
296
+     *
297
+     * @return array applicable groups
298
+     */
299
+    public function getApplicableGroups() {
300
+        return $this->applicableGroups;
301
+    }
302
+
303
+    /**
304
+     * Sets the groups for which to mount this storage
305
+     *
306
+     * @param array|null $applicableGroups applicable groups
307
+     */
308
+    public function setApplicableGroups($applicableGroups) {
309
+        if (is_null($applicableGroups)) {
310
+            $applicableGroups = [];
311
+        }
312
+        $this->applicableGroups = $applicableGroups;
313
+    }
314
+
315
+    /**
316
+     * Returns the mount-specific options
317
+     *
318
+     * @return array mount specific options
319
+     */
320
+    public function getMountOptions() {
321
+        return $this->mountOptions;
322
+    }
323
+
324
+    /**
325
+     * Sets the mount-specific options
326
+     *
327
+     * @param array $mountOptions applicable groups
328
+     */
329
+    public function setMountOptions($mountOptions) {
330
+        if (is_null($mountOptions)) {
331
+            $mountOptions = [];
332
+        }
333
+        $this->mountOptions = $mountOptions;
334
+    }
335
+
336
+    /**
337
+     * @param string $key
338
+     * @return mixed
339
+     */
340
+    public function getMountOption($key) {
341
+        if (isset($this->mountOptions[$key])) {
342
+            return $this->mountOptions[$key];
343
+        }
344
+        return null;
345
+    }
346
+
347
+    /**
348
+     * @param string $key
349
+     * @param mixed $value
350
+     */
351
+    public function setMountOption($key, $value) {
352
+        $this->mountOptions[$key] = $value;
353
+    }
354
+
355
+    /**
356
+     * Gets the storage status, whether the config worked last time
357
+     *
358
+     * @return int $status status
359
+     */
360
+    public function getStatus() {
361
+        return $this->status;
362
+    }
363
+
364
+    /**
365
+     * Gets the message describing the storage status
366
+     *
367
+     * @return string|null
368
+     */
369
+    public function getStatusMessage() {
370
+        return $this->statusMessage;
371
+    }
372
+
373
+    /**
374
+     * Sets the storage status, whether the config worked last time
375
+     *
376
+     * @param int $status status
377
+     * @param string|null $message optional message
378
+     */
379
+    public function setStatus($status, $message = null) {
380
+        $this->status = $status;
381
+        $this->statusMessage = $message;
382
+    }
383
+
384
+    /**
385
+     * @return int self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl
386
+     */
387
+    public function getType() {
388
+        return $this->type;
389
+    }
390
+
391
+    /**
392
+     * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl
393
+     */
394
+    public function setType($type) {
395
+        $this->type = $type;
396
+    }
397
+
398
+    /**
399
+     * Serialize config to JSON
400
+     *
401
+     * @return array
402
+     */
403
+    public function jsonSerialize() {
404
+        $result = [];
405
+        if (!is_null($this->id)) {
406
+            $result['id'] = $this->id;
407
+        }
408
+        $result['mountPoint'] = $this->mountPoint;
409
+        $result['backend'] = $this->backend->getIdentifier();
410
+        $result['authMechanism'] = $this->authMechanism->getIdentifier();
411
+        $result['backendOptions'] = $this->backendOptions;
412
+        if (!is_null($this->priority)) {
413
+            $result['priority'] = $this->priority;
414
+        }
415
+        if (!empty($this->applicableUsers)) {
416
+            $result['applicableUsers'] = $this->applicableUsers;
417
+        }
418
+        if (!empty($this->applicableGroups)) {
419
+            $result['applicableGroups'] = $this->applicableGroups;
420
+        }
421
+        if (!empty($this->mountOptions)) {
422
+            $result['mountOptions'] = $this->mountOptions;
423
+        }
424
+        if (!is_null($this->status)) {
425
+            $result['status'] = $this->status;
426
+        }
427
+        if (!is_null($this->statusMessage)) {
428
+            $result['statusMessage'] = $this->statusMessage;
429
+        }
430
+        $result['userProvided'] = $this->authMechanism instanceof IUserProvided;
431
+        $result['type'] = ($this->getType() === self::MOUNT_TYPE_PERSONAl) ? 'personal': 'system';
432
+        return $result;
433
+    }
434 434
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Backend/Swift.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@
 block discarded – undo
50 50
 					->setFlag(DefinitionParameter::FLAG_OPTIONAL),
51 51
 			])
52 52
 			->addAuthScheme(AuthMechanism::SCHEME_OPENSTACK)
53
-			->setLegacyAuthMechanismCallback(function (array $params) use ($openstackAuth, $rackspaceAuth) {
53
+			->setLegacyAuthMechanismCallback(function(array $params) use ($openstackAuth, $rackspaceAuth) {
54 54
 				if (isset($params['options']['key']) && $params['options']['key']) {
55 55
 					return $rackspaceAuth;
56 56
 				}
Please login to merge, or discard this patch.
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -33,29 +33,29 @@
 block discarded – undo
33 33
 use OCP\IL10N;
34 34
 
35 35
 class Swift extends Backend {
36
-	use LegacyDependencyCheckPolyfill;
36
+    use LegacyDependencyCheckPolyfill;
37 37
 
38
-	public function __construct(IL10N $l, OpenStackV2 $openstackAuth, Rackspace $rackspaceAuth) {
39
-		$this
40
-			->setIdentifier('swift')
41
-			->addIdentifierAlias('\OC\Files\Storage\Swift') // legacy compat
42
-			->setStorageClass('\OCA\Files_External\Lib\Storage\Swift')
43
-			->setText($l->t('OpenStack Object Storage'))
44
-			->addParameters([
45
-				(new DefinitionParameter('service_name', $l->t('Service name')))
46
-					->setFlag(DefinitionParameter::FLAG_OPTIONAL),
47
-				new DefinitionParameter('region', $l->t('Region')),
48
-				new DefinitionParameter('bucket', $l->t('Bucket')),
49
-				(new DefinitionParameter('timeout', $l->t('Request timeout (seconds)')))
50
-					->setFlag(DefinitionParameter::FLAG_OPTIONAL),
51
-			])
52
-			->addAuthScheme(AuthMechanism::SCHEME_OPENSTACK)
53
-			->setLegacyAuthMechanismCallback(function (array $params) use ($openstackAuth, $rackspaceAuth) {
54
-				if (isset($params['options']['key']) && $params['options']['key']) {
55
-					return $rackspaceAuth;
56
-				}
57
-				return $openstackAuth;
58
-			})
59
-		;
60
-	}
38
+    public function __construct(IL10N $l, OpenStackV2 $openstackAuth, Rackspace $rackspaceAuth) {
39
+        $this
40
+            ->setIdentifier('swift')
41
+            ->addIdentifierAlias('\OC\Files\Storage\Swift') // legacy compat
42
+            ->setStorageClass('\OCA\Files_External\Lib\Storage\Swift')
43
+            ->setText($l->t('OpenStack Object Storage'))
44
+            ->addParameters([
45
+                (new DefinitionParameter('service_name', $l->t('Service name')))
46
+                    ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
47
+                new DefinitionParameter('region', $l->t('Region')),
48
+                new DefinitionParameter('bucket', $l->t('Bucket')),
49
+                (new DefinitionParameter('timeout', $l->t('Request timeout (seconds)')))
50
+                    ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
51
+            ])
52
+            ->addAuthScheme(AuthMechanism::SCHEME_OPENSTACK)
53
+            ->setLegacyAuthMechanismCallback(function (array $params) use ($openstackAuth, $rackspaceAuth) {
54
+                if (isset($params['options']['key']) && $params['options']['key']) {
55
+                    return $rackspaceAuth;
56
+                }
57
+                return $openstackAuth;
58
+            })
59
+        ;
60
+    }
61 61
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/VisibilityTrait.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -36,101 +36,101 @@
 block discarded – undo
36 36
  */
37 37
 trait VisibilityTrait {
38 38
 
39
-	/** @var int visibility */
40
-	protected $visibility = BackendService::VISIBILITY_DEFAULT;
39
+    /** @var int visibility */
40
+    protected $visibility = BackendService::VISIBILITY_DEFAULT;
41 41
 
42
-	/** @var int allowed visibilities */
43
-	protected $allowedVisibility = BackendService::VISIBILITY_DEFAULT;
42
+    /** @var int allowed visibilities */
43
+    protected $allowedVisibility = BackendService::VISIBILITY_DEFAULT;
44 44
 
45
-	/**
46
-	 * @return int
47
-	 */
48
-	public function getVisibility() {
49
-		return $this->visibility;
50
-	}
45
+    /**
46
+     * @return int
47
+     */
48
+    public function getVisibility() {
49
+        return $this->visibility;
50
+    }
51 51
 
52
-	/**
53
-	 * Check if the backend is visible for a user type
54
-	 *
55
-	 * @param int $visibility
56
-	 * @return bool
57
-	 */
58
-	public function isVisibleFor($visibility) {
59
-		if ($this->visibility & $visibility) {
60
-			return true;
61
-		}
62
-		return false;
63
-	}
52
+    /**
53
+     * Check if the backend is visible for a user type
54
+     *
55
+     * @param int $visibility
56
+     * @return bool
57
+     */
58
+    public function isVisibleFor($visibility) {
59
+        if ($this->visibility & $visibility) {
60
+            return true;
61
+        }
62
+        return false;
63
+    }
64 64
 
65
-	/**
66
-	 * @param int $visibility
67
-	 * @return self
68
-	 */
69
-	public function setVisibility($visibility) {
70
-		$this->visibility = $visibility;
71
-		$this->allowedVisibility |= $visibility;
72
-		return $this;
73
-	}
65
+    /**
66
+     * @param int $visibility
67
+     * @return self
68
+     */
69
+    public function setVisibility($visibility) {
70
+        $this->visibility = $visibility;
71
+        $this->allowedVisibility |= $visibility;
72
+        return $this;
73
+    }
74 74
 
75
-	/**
76
-	 * @param int $visibility
77
-	 * @return self
78
-	 */
79
-	public function addVisibility($visibility) {
80
-		return $this->setVisibility($this->visibility | $visibility);
81
-	}
75
+    /**
76
+     * @param int $visibility
77
+     * @return self
78
+     */
79
+    public function addVisibility($visibility) {
80
+        return $this->setVisibility($this->visibility | $visibility);
81
+    }
82 82
 
83
-	/**
84
-	 * @param int $visibility
85
-	 * @return self
86
-	 */
87
-	public function removeVisibility($visibility) {
88
-		return $this->setVisibility($this->visibility & ~$visibility);
89
-	}
83
+    /**
84
+     * @param int $visibility
85
+     * @return self
86
+     */
87
+    public function removeVisibility($visibility) {
88
+        return $this->setVisibility($this->visibility & ~$visibility);
89
+    }
90 90
 
91
-	/**
92
-	 * @return int
93
-	 */
94
-	public function getAllowedVisibility() {
95
-		return $this->allowedVisibility;
96
-	}
91
+    /**
92
+     * @return int
93
+     */
94
+    public function getAllowedVisibility() {
95
+        return $this->allowedVisibility;
96
+    }
97 97
 
98
-	/**
99
-	 * Check if the backend is allowed to be visible for a user type
100
-	 *
101
-	 * @param int $allowedVisibility
102
-	 * @return bool
103
-	 */
104
-	public function isAllowedVisibleFor($allowedVisibility) {
105
-		if ($this->allowedVisibility & $allowedVisibility) {
106
-			return true;
107
-		}
108
-		return false;
109
-	}
98
+    /**
99
+     * Check if the backend is allowed to be visible for a user type
100
+     *
101
+     * @param int $allowedVisibility
102
+     * @return bool
103
+     */
104
+    public function isAllowedVisibleFor($allowedVisibility) {
105
+        if ($this->allowedVisibility & $allowedVisibility) {
106
+            return true;
107
+        }
108
+        return false;
109
+    }
110 110
 
111
-	/**
112
-	 * @param int $allowedVisibility
113
-	 * @return self
114
-	 */
115
-	public function setAllowedVisibility($allowedVisibility) {
116
-		$this->allowedVisibility = $allowedVisibility;
117
-		$this->visibility &= $allowedVisibility;
118
-		return $this;
119
-	}
111
+    /**
112
+     * @param int $allowedVisibility
113
+     * @return self
114
+     */
115
+    public function setAllowedVisibility($allowedVisibility) {
116
+        $this->allowedVisibility = $allowedVisibility;
117
+        $this->visibility &= $allowedVisibility;
118
+        return $this;
119
+    }
120 120
 
121
-	/**
122
-	 * @param int $allowedVisibility
123
-	 * @return self
124
-	 */
125
-	public function addAllowedVisibility($allowedVisibility) {
126
-		return $this->setAllowedVisibility($this->allowedVisibility | $allowedVisibility);
127
-	}
121
+    /**
122
+     * @param int $allowedVisibility
123
+     * @return self
124
+     */
125
+    public function addAllowedVisibility($allowedVisibility) {
126
+        return $this->setAllowedVisibility($this->allowedVisibility | $allowedVisibility);
127
+    }
128 128
 
129
-	/**
130
-	 * @param int $allowedVisibility
131
-	 * @return self
132
-	 */
133
-	public function removeAllowedVisibility($allowedVisibility) {
134
-		return $this->setAllowedVisibility($this->allowedVisibility & ~$allowedVisibility);
135
-	}
129
+    /**
130
+     * @param int $allowedVisibility
131
+     * @return self
132
+     */
133
+    public function removeAllowedVisibility($allowedVisibility) {
134
+        return $this->setAllowedVisibility($this->allowedVisibility & ~$allowedVisibility);
135
+    }
136 136
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Auth/Builtin.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -28,11 +28,11 @@
 block discarded – undo
28 28
  * Builtin authentication mechanism, for legacy backends
29 29
  */
30 30
 class Builtin extends AuthMechanism {
31
-	public function __construct(IL10N $l) {
32
-		$this
33
-			->setIdentifier('builtin::builtin')
34
-			->setScheme(self::SCHEME_BUILTIN)
35
-			->setText($l->t('Builtin'))
36
-		;
37
-	}
31
+    public function __construct(IL10N $l) {
32
+        $this
33
+            ->setIdentifier('builtin::builtin')
34
+            ->setScheme(self::SCHEME_BUILTIN)
35
+            ->setText($l->t('Builtin'))
36
+        ;
37
+    }
38 38
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Auth/NullMechanism.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -28,11 +28,11 @@
 block discarded – undo
28 28
  * Null authentication mechanism
29 29
  */
30 30
 class NullMechanism extends AuthMechanism {
31
-	public function __construct(IL10N $l) {
32
-		$this
33
-			->setIdentifier('null::null')
34
-			->setScheme(self::SCHEME_NULL)
35
-			->setText($l->t('None'))
36
-		;
37
-	}
31
+    public function __construct(IL10N $l) {
32
+        $this
33
+            ->setIdentifier('null::null')
34
+            ->setScheme(self::SCHEME_NULL)
35
+            ->setText($l->t('None'))
36
+        ;
37
+    }
38 38
 }
Please login to merge, or discard this patch.