31
31
use OCP \Files \External \IStorageConfig ;
32
32
use OCP \Files \External \NotFoundException ;
33
33
use OCP \Files \External \Service \IUserStoragesService ;
34
+ use OCP \IConfig ;
34
35
use OCP \IL10N ;
35
36
use OCP \ILogger ;
36
37
use OCP \IRequest ;
@@ -44,23 +45,15 @@ class UserStoragesController extends StoragesController {
44
45
* @var IUserSession
45
46
*/
46
47
private $ userSession ;
48
+ private IConfig $ config ;
47
49
48
- /**
49
- * Creates a new user storages controller.
50
- *
51
- * @param string $AppName application name
52
- * @param IRequest $request request object
53
- * @param IL10N $l10n l10n service
54
- * @param IUserStoragesService $userStoragesService storage service
55
- * @param IUserSession $userSession
56
- * @param ILogger $logger
57
- */
58
50
public function __construct (
59
51
$ AppName ,
60
52
IRequest $ request ,
61
53
IL10N $ l10n ,
62
54
IUserStoragesService $ userStoragesService ,
63
55
IUserSession $ userSession ,
56
+ IConfig $ config ,
64
57
ILogger $ logger
65
58
) {
66
59
parent ::__construct (
@@ -71,6 +64,7 @@ public function __construct(
71
64
$ logger
72
65
);
73
66
$ this ->userSession = $ userSession ;
67
+ $ this ->config = $ config ;
74
68
}
75
69
76
70
protected function manipulateStorageConfig (IStorageConfig $ storage ) {
@@ -88,6 +82,12 @@ protected function manipulateStorageConfig(IStorageConfig $storage) {
88
82
* @return DataResponse
89
83
*/
90
84
public function index () {
85
+ if (!$ this ->isUserMountingAllowed ()) {
86
+ return new DataResponse (
87
+ null ,
88
+ Http::STATUS_FORBIDDEN
89
+ );
90
+ }
91
91
return parent ::index ();
92
92
}
93
93
@@ -122,8 +122,13 @@ public function create(
122
122
$ backendOptions ,
123
123
$ mountOptions
124
124
) {
125
+ if (!$ this ->isUserMountingAllowed ()) {
126
+ return new DataResponse (
127
+ null ,
128
+ Http::STATUS_FORBIDDEN
129
+ );
130
+ }
125
131
$ canCreateNewLocalStorage = \OC ::$ server ->getConfig ()->getSystemValue ('files_external_allow_create_new_local ' , false );
126
-
127
132
if ($ backend === 'local ' && $ canCreateNewLocalStorage === false ) {
128
133
return new DataResponse (
129
134
null ,
@@ -183,6 +188,12 @@ public function update(
183
188
$ mountOptions ,
184
189
$ testOnly = true
185
190
) {
191
+ if (!$ this ->isUserMountingAllowed ()) {
192
+ return new DataResponse (
193
+ null ,
194
+ Http::STATUS_FORBIDDEN
195
+ );
196
+ }
186
197
$ storage = $ this ->createStorage (
187
198
$ mountPoint ,
188
199
$ backend ,
@@ -230,6 +241,17 @@ public function update(
230
241
* {@inheritdoc}
231
242
*/
232
243
public function destroy ($ id ) {
244
+ if (!$ this ->isUserMountingAllowed ()) {
245
+ return new DataResponse (
246
+ null ,
247
+ Http::STATUS_FORBIDDEN
248
+ );
249
+ }
250
+
233
251
return parent ::destroy ($ id );
234
252
}
253
+
254
+ private function isUserMountingAllowed (): bool {
255
+ return $ this ->config ->getAppValue ('files_external ' , 'allow_user_mounting ' , 'yes ' ) === 'yes ' ;
256
+ }
235
257
}
0 commit comments