@@ -197,7 +197,7 @@ |
||
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 | ); |
@@ -44,183 +44,183 @@ |
||
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 | } |
@@ -122,7 +122,7 @@ discard block |
||
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 |
||
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 |
||
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 | ); |
@@ -46,163 +46,163 @@ |
||
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 | } |
@@ -29,31 +29,31 @@ |
||
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 | } |
@@ -50,7 +50,7 @@ |
||
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 | } |
@@ -33,29 +33,29 @@ |
||
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 | } |
@@ -36,101 +36,101 @@ |
||
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 | } |
@@ -28,11 +28,11 @@ |
||
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 | } |
@@ -28,11 +28,11 @@ |
||
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 | } |
@@ -41,48 +41,48 @@ |
||
41 | 41 | $is_optional = $parameter->isFlagSet(DefinitionParameter::FLAG_OPTIONAL); |
42 | 42 | |
43 | 43 | switch ($parameter->getType()) { |
44 | - case DefinitionParameter::VALUE_PASSWORD: ?> |
|
45 | - <?php if ($is_optional) { |
|
46 | - $classes[] = 'optional'; |
|
47 | - } ?> |
|
48 | - <input type="password" |
|
44 | + case DefinitionParameter::VALUE_PASSWORD: ?> |
|
45 | + <?php if ($is_optional) { |
|
46 | + $classes[] = 'optional'; |
|
47 | + } ?> |
|
48 | + <input type="password" |
|
49 | 49 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
50 | - data-parameter="<?php p($parameter->getName()); ?>" |
|
50 | + data-parameter="<?php p($parameter->getName()); ?>" |
|
51 | 51 | value="<?php p($value); ?>" |
52 | 52 | placeholder="<?php p($placeholder); ?>" |
53 | 53 | /> |
54 | 54 | <?php |
55 | - break; |
|
56 | - case DefinitionParameter::VALUE_BOOLEAN: ?> |
|
57 | - <?php $checkboxId = uniqid("checkbox_"); ?> |
|
55 | + break; |
|
56 | + case DefinitionParameter::VALUE_BOOLEAN: ?> |
|
57 | + <?php $checkboxId = uniqid("checkbox_"); ?> |
|
58 | 58 | <div> |
59 | 59 | <label> |
60 | 60 | <input type="checkbox" |
61 | 61 | id="<?php p($checkboxId); ?>" |
62 | 62 | <?php if (!empty($classes)): ?> class="checkbox <?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
63 | - data-parameter="<?php p($parameter->getName()); ?>" |
|
63 | + data-parameter="<?php p($parameter->getName()); ?>" |
|
64 | 64 | <?php if ($value === true): ?> checked="checked"<?php endif; ?> |
65 | - /> |
|
65 | + /> |
|
66 | 66 | <?php p($placeholder); ?> |
67 | 67 | </label> |
68 | 68 | </div> |
69 | 69 | <?php |
70 | - break; |
|
71 | - case DefinitionParameter::VALUE_HIDDEN: ?> |
|
72 | - <input type="hidden" |
|
70 | + break; |
|
71 | + case DefinitionParameter::VALUE_HIDDEN: ?> |
|
72 | + <input type="hidden" |
|
73 | 73 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
74 | - data-parameter="<?php p($parameter->getName()); ?>" |
|
74 | + data-parameter="<?php p($parameter->getName()); ?>" |
|
75 | 75 | value="<?php p($value); ?>" |
76 | 76 | /> |
77 | 77 | <?php |
78 | - break; |
|
79 | - default: ?> |
|
80 | - <?php if ($is_optional) { |
|
81 | - $classes[] = 'optional'; |
|
82 | - } ?> |
|
83 | - <input type="text" |
|
78 | + break; |
|
79 | + default: ?> |
|
80 | + <?php if ($is_optional) { |
|
81 | + $classes[] = 'optional'; |
|
82 | + } ?> |
|
83 | + <input type="text" |
|
84 | 84 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
85 | - data-parameter="<?php p($parameter->getName()); ?>" |
|
85 | + data-parameter="<?php p($parameter->getName()); ?>" |
|
86 | 86 | value="<?php p($value); ?>" |
87 | 87 | placeholder="<?php p($placeholder); ?>" |
88 | 88 | /> |
@@ -194,8 +194,11 @@ |
||
194 | 194 | <?php $i = 0; foreach ($userBackends as $backend): ?> |
195 | 195 | <?php if ($deprecateTo = $backend->getDeprecateTo()): ?> |
196 | 196 | <input type="hidden" id="allowUserMountingBackends<?php p($i); ?>" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" data-deprecate-to="<?php p($deprecateTo->getIdentifier()); ?>" /> |
197 | - <?php else: ?> |
|
198 | - <input type="checkbox" id="allowUserMountingBackends<?php p($i); ?>" class="checkbox" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" <?php if ($backend->isVisibleFor(BackendService::VISIBILITY_PERSONAL)) { |
|
197 | + <?php else { |
|
198 | + : ?> |
|
199 | + <input type="checkbox" id="allowUserMountingBackends<?php p($i); |
|
200 | +} |
|
201 | +?>" class="checkbox" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" <?php if ($backend->isVisibleFor(BackendService::VISIBILITY_PERSONAL)) { |
|
199 | 202 | print_unescaped(' checked="checked"'); |
200 | 203 | } ?> /> |
201 | 204 | <label for="allowUserMountingBackends<?php p($i); ?>"><?php p($backend->getText()); ?></label> <br /> |
@@ -1,54 +1,54 @@ discard block |
||
1 | 1 | <?php |
2 | - use \OCA\Files_External\Lib\Backend\Backend; |
|
2 | + use \OCA\Files_External\Lib\Backend\Backend; |
|
3 | 3 | use \OCA\Files_External\Lib\Auth\AuthMechanism; |
4 | 4 | use \OCA\Files_External\Lib\DefinitionParameter; |
5 | 5 | use \OCA\Files_External\Service\BackendService; |
6 | 6 | |
7 | 7 | $canCreateMounts = $_['visibilityType'] === BackendService::VISIBILITY_ADMIN || $_['allowUserMounting']; |
8 | 8 | |
9 | - $l->t("Enable encryption"); |
|
10 | - $l->t("Enable previews"); |
|
11 | - $l->t("Enable sharing"); |
|
12 | - $l->t("Check for changes"); |
|
13 | - $l->t("Never"); |
|
14 | - $l->t("Once every direct access"); |
|
15 | - $l->t('Read only'); |
|
9 | + $l->t("Enable encryption"); |
|
10 | + $l->t("Enable previews"); |
|
11 | + $l->t("Enable sharing"); |
|
12 | + $l->t("Check for changes"); |
|
13 | + $l->t("Never"); |
|
14 | + $l->t("Once every direct access"); |
|
15 | + $l->t('Read only'); |
|
16 | 16 | |
17 | - script('files_external', [ |
|
18 | - 'settings', |
|
19 | - 'templates' |
|
20 | - ]); |
|
21 | - style('files_external', 'settings'); |
|
17 | + script('files_external', [ |
|
18 | + 'settings', |
|
19 | + 'templates' |
|
20 | + ]); |
|
21 | + style('files_external', 'settings'); |
|
22 | 22 | |
23 | - // load custom JS |
|
24 | - foreach ($_['backends'] as $backend) { |
|
25 | - /** @var Backend $backend */ |
|
26 | - $scripts = $backend->getCustomJs(); |
|
27 | - foreach ($scripts as $script) { |
|
28 | - script('files_external', $script); |
|
29 | - } |
|
30 | - } |
|
31 | - foreach ($_['authMechanisms'] as $authMechanism) { |
|
32 | - /** @var AuthMechanism $authMechanism */ |
|
33 | - $scripts = $authMechanism->getCustomJs(); |
|
34 | - foreach ($scripts as $script) { |
|
35 | - script('files_external', $script); |
|
36 | - } |
|
37 | - } |
|
23 | + // load custom JS |
|
24 | + foreach ($_['backends'] as $backend) { |
|
25 | + /** @var Backend $backend */ |
|
26 | + $scripts = $backend->getCustomJs(); |
|
27 | + foreach ($scripts as $script) { |
|
28 | + script('files_external', $script); |
|
29 | + } |
|
30 | + } |
|
31 | + foreach ($_['authMechanisms'] as $authMechanism) { |
|
32 | + /** @var AuthMechanism $authMechanism */ |
|
33 | + $scripts = $authMechanism->getCustomJs(); |
|
34 | + foreach ($scripts as $script) { |
|
35 | + script('files_external', $script); |
|
36 | + } |
|
37 | + } |
|
38 | 38 | |
39 | - function writeParameterInput($parameter, $options, $classes = []) { |
|
40 | - $value = ''; |
|
41 | - if (isset($options[$parameter->getName()])) { |
|
42 | - $value = $options[$parameter->getName()]; |
|
43 | - } |
|
44 | - $placeholder = $parameter->getText(); |
|
45 | - $is_optional = $parameter->isFlagSet(DefinitionParameter::FLAG_OPTIONAL); |
|
39 | + function writeParameterInput($parameter, $options, $classes = []) { |
|
40 | + $value = ''; |
|
41 | + if (isset($options[$parameter->getName()])) { |
|
42 | + $value = $options[$parameter->getName()]; |
|
43 | + } |
|
44 | + $placeholder = $parameter->getText(); |
|
45 | + $is_optional = $parameter->isFlagSet(DefinitionParameter::FLAG_OPTIONAL); |
|
46 | 46 | |
47 | - switch ($parameter->getType()) { |
|
48 | - case DefinitionParameter::VALUE_PASSWORD: ?> |
|
47 | + switch ($parameter->getType()) { |
|
48 | + case DefinitionParameter::VALUE_PASSWORD: ?> |
|
49 | 49 | <?php if ($is_optional) { |
50 | - $classes[] = 'optional'; |
|
51 | - } ?> |
|
50 | + $classes[] = 'optional'; |
|
51 | + } ?> |
|
52 | 52 | <input type="password" |
53 | 53 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
54 | 54 | data-parameter="<?php p($parameter->getName()); ?>" |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | placeholder="<?php p($placeholder); ?>" |
57 | 57 | /> |
58 | 58 | <?php |
59 | - break; |
|
60 | - case DefinitionParameter::VALUE_BOOLEAN: ?> |
|
59 | + break; |
|
60 | + case DefinitionParameter::VALUE_BOOLEAN: ?> |
|
61 | 61 | <?php $checkboxId = uniqid("checkbox_"); ?> |
62 | 62 | <div> |
63 | 63 | <label> |
@@ -71,19 +71,19 @@ discard block |
||
71 | 71 | </label> |
72 | 72 | </div> |
73 | 73 | <?php |
74 | - break; |
|
75 | - case DefinitionParameter::VALUE_HIDDEN: ?> |
|
74 | + break; |
|
75 | + case DefinitionParameter::VALUE_HIDDEN: ?> |
|
76 | 76 | <input type="hidden" |
77 | 77 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
78 | 78 | data-parameter="<?php p($parameter->getName()); ?>" |
79 | 79 | value="<?php p($value); ?>" |
80 | 80 | /> |
81 | 81 | <?php |
82 | - break; |
|
83 | - default: ?> |
|
82 | + break; |
|
83 | + default: ?> |
|
84 | 84 | <?php if ($is_optional) { |
85 | - $classes[] = 'optional'; |
|
86 | - } ?> |
|
85 | + $classes[] = 'optional'; |
|
86 | + } ?> |
|
87 | 87 | <input type="text" |
88 | 88 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
89 | 89 | data-parameter="<?php p($parameter->getName()); ?>" |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | placeholder="<?php p($placeholder); ?>" |
92 | 92 | /> |
93 | 93 | <?php |
94 | - } |
|
95 | - } |
|
94 | + } |
|
95 | + } |
|
96 | 96 | ?> |
97 | 97 | |
98 | 98 | <div id="emptycontent" class="hidden"> |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | <a target="_blank" rel="noreferrer" class="icon-info" title="<?php p($l->t('Open documentation'));?>" href="<?php p(link_to_docs('admin-external-storage')); ?>"></a> |
106 | 106 | <p class="settings-hint"><?php p($l->t('External storage enables you to mount external storage services and devices as secondary Nextcloud storage devices. You may also allow users to mount their own external storage services.')); ?></p> |
107 | 107 | <?php if (isset($_['dependencies']) and ($_['dependencies'] !== '') and $canCreateMounts) { |
108 | - print_unescaped(''.$_['dependencies'].''); |
|
108 | + print_unescaped(''.$_['dependencies'].''); |
|
109 | 109 | } ?> |
110 | 110 | <table id="externalStorage" class="grid" data-admin='<?php print_unescaped(json_encode($_['visibilityType'] === BackendService::VISIBILITY_ADMIN)); ?>'> |
111 | 111 | <thead> |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | <th><?php p($l->t('Authentication')); ?></th> |
117 | 117 | <th><?php p($l->t('Configuration')); ?></th> |
118 | 118 | <?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN) { |
119 | - print_unescaped('<th>'.$l->t('Available for').'</th>'); |
|
119 | + print_unescaped('<th>'.$l->t('Available for').'</th>'); |
|
120 | 120 | } ?> |
121 | 121 | <th> </th> |
122 | 122 | <th> </th> |
@@ -142,17 +142,17 @@ discard block |
||
142 | 142 | <?php p($l->t('Add storage')); ?> |
143 | 143 | </option> |
144 | 144 | <?php |
145 | - $sortedBackends = array_filter($_['backends'], function ($backend) use ($_) { |
|
146 | - return $backend->isVisibleFor($_['visibilityType']); |
|
147 | - }); |
|
148 | - uasort($sortedBackends, function ($a, $b) { |
|
149 | - return strcasecmp($a->getText(), $b->getText()); |
|
150 | - }); |
|
151 | - ?> |
|
145 | + $sortedBackends = array_filter($_['backends'], function ($backend) use ($_) { |
|
146 | + return $backend->isVisibleFor($_['visibilityType']); |
|
147 | + }); |
|
148 | + uasort($sortedBackends, function ($a, $b) { |
|
149 | + return strcasecmp($a->getText(), $b->getText()); |
|
150 | + }); |
|
151 | + ?> |
|
152 | 152 | <?php foreach ($sortedBackends as $backend): ?> |
153 | 153 | <?php if ($backend->getDeprecateTo()) { |
154 | - continue; |
|
155 | - } // ignore deprecated backends?> |
|
154 | + continue; |
|
155 | + } // ignore deprecated backends?> |
|
156 | 156 | <option value="<?php p($backend->getIdentifier()); ?>"><?php p($backend->getText()); ?></option> |
157 | 157 | <?php endforeach; ?> |
158 | 158 | </select> |
@@ -178,23 +178,23 @@ discard block |
||
178 | 178 | <?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN): ?> |
179 | 179 | <input type="checkbox" name="allowUserMounting" id="allowUserMounting" class="checkbox" |
180 | 180 | value="1" <?php if ($_['allowUserMounting']) { |
181 | - print_unescaped(' checked="checked"'); |
|
182 | - } ?> /> |
|
181 | + print_unescaped(' checked="checked"'); |
|
182 | + } ?> /> |
|
183 | 183 | <label for="allowUserMounting"><?php p($l->t('Allow users to mount external storage')); ?></label> <span id="userMountingMsg" class="msg"></span> |
184 | 184 | |
185 | 185 | <p id="userMountingBackends"<?php if (!$_['allowUserMounting']): ?> class="hidden"<?php endif; ?>> |
186 | 186 | <?php |
187 | - $userBackends = array_filter($_['backends'], function ($backend) { |
|
188 | - return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL); |
|
189 | - }); |
|
190 | - ?> |
|
187 | + $userBackends = array_filter($_['backends'], function ($backend) { |
|
188 | + return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL); |
|
189 | + }); |
|
190 | + ?> |
|
191 | 191 | <?php $i = 0; foreach ($userBackends as $backend): ?> |
192 | 192 | <?php if ($deprecateTo = $backend->getDeprecateTo()): ?> |
193 | 193 | <input type="hidden" id="allowUserMountingBackends<?php p($i); ?>" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" data-deprecate-to="<?php p($deprecateTo->getIdentifier()); ?>" /> |
194 | 194 | <?php else: ?> |
195 | 195 | <input type="checkbox" id="allowUserMountingBackends<?php p($i); ?>" class="checkbox" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" <?php if ($backend->isVisibleFor(BackendService::VISIBILITY_PERSONAL)) { |
196 | - print_unescaped(' checked="checked"'); |
|
197 | - } ?> /> |
|
196 | + print_unescaped(' checked="checked"'); |
|
197 | + } ?> /> |
|
198 | 198 | <label for="allowUserMountingBackends<?php p($i); ?>"><?php p($backend->getText()); ?></label> <br /> |
199 | 199 | <?php endif; ?> |
200 | 200 | <?php $i++; ?> |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | <h2><?php p($l->t('No external storage configured or you don\'t have the permission to configure them')); ?></h2> |
101 | 101 | </div> |
102 | 102 | |
103 | -<form data-can-create="<?php echo $canCreateMounts?'true':'false' ?>" id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled']?'true': 'false'; ?>"> |
|
103 | +<form data-can-create="<?php echo $canCreateMounts ? 'true' : 'false' ?>" id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled'] ? 'true' : 'false'; ?>"> |
|
104 | 104 | <h2 class="inlineblock" data-anchor-name="external-storage"><?php p($l->t('External storages')); ?></h2> |
105 | - <a target="_blank" rel="noreferrer" class="icon-info" title="<?php p($l->t('Open documentation'));?>" href="<?php p(link_to_docs('admin-external-storage')); ?>"></a> |
|
105 | + <a target="_blank" rel="noreferrer" class="icon-info" title="<?php p($l->t('Open documentation')); ?>" href="<?php p(link_to_docs('admin-external-storage')); ?>"></a> |
|
106 | 106 | <p class="settings-hint"><?php p($l->t('External storage enables you to mount external storage services and devices as secondary Nextcloud storage devices. You may also allow users to mount their own external storage services.')); ?></p> |
107 | 107 | <?php if (isset($_['dependencies']) and ($_['dependencies'] !== '') and $canCreateMounts) { |
108 | 108 | print_unescaped(''.$_['dependencies'].''); |
@@ -142,10 +142,10 @@ discard block |
||
142 | 142 | <?php p($l->t('Add storage')); ?> |
143 | 143 | </option> |
144 | 144 | <?php |
145 | - $sortedBackends = array_filter($_['backends'], function ($backend) use ($_) { |
|
145 | + $sortedBackends = array_filter($_['backends'], function($backend) use ($_) { |
|
146 | 146 | return $backend->isVisibleFor($_['visibilityType']); |
147 | 147 | }); |
148 | - uasort($sortedBackends, function ($a, $b) { |
|
148 | + uasort($sortedBackends, function($a, $b) { |
|
149 | 149 | return strcasecmp($a->getText(), $b->getText()); |
150 | 150 | }); |
151 | 151 | ?> |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | |
185 | 185 | <p id="userMountingBackends"<?php if (!$_['allowUserMounting']): ?> class="hidden"<?php endif; ?>> |
186 | 186 | <?php |
187 | - $userBackends = array_filter($_['backends'], function ($backend) { |
|
187 | + $userBackends = array_filter($_['backends'], function($backend) { |
|
188 | 188 | return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL); |
189 | 189 | }); |
190 | 190 | ?> |
@@ -30,43 +30,43 @@ |
||
30 | 30 | |
31 | 31 | class SyncFederationAddressBooks extends Command { |
32 | 32 | |
33 | - /** @var \OCA\Federation\SyncFederationAddressBooks */ |
|
34 | - private $syncService; |
|
33 | + /** @var \OCA\Federation\SyncFederationAddressBooks */ |
|
34 | + private $syncService; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param \OCA\Federation\SyncFederationAddressBooks $syncService |
|
38 | - */ |
|
39 | - public function __construct(\OCA\Federation\SyncFederationAddressBooks $syncService) { |
|
40 | - parent::__construct(); |
|
36 | + /** |
|
37 | + * @param \OCA\Federation\SyncFederationAddressBooks $syncService |
|
38 | + */ |
|
39 | + public function __construct(\OCA\Federation\SyncFederationAddressBooks $syncService) { |
|
40 | + parent::__construct(); |
|
41 | 41 | |
42 | - $this->syncService = $syncService; |
|
43 | - } |
|
42 | + $this->syncService = $syncService; |
|
43 | + } |
|
44 | 44 | |
45 | - protected function configure() { |
|
46 | - $this |
|
47 | - ->setName('federation:sync-addressbooks') |
|
48 | - ->setDescription('Synchronizes addressbooks of all federated clouds'); |
|
49 | - } |
|
45 | + protected function configure() { |
|
46 | + $this |
|
47 | + ->setName('federation:sync-addressbooks') |
|
48 | + ->setDescription('Synchronizes addressbooks of all federated clouds'); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param InputInterface $input |
|
53 | - * @param OutputInterface $output |
|
54 | - * @return int |
|
55 | - */ |
|
56 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
57 | - $progress = new ProgressBar($output); |
|
58 | - $progress->start(); |
|
59 | - $this->syncService->syncThemAll(function ($url, $ex) use ($progress, $output) { |
|
60 | - if ($ex instanceof \Exception) { |
|
61 | - $output->writeln("Error while syncing $url : " . $ex->getMessage()); |
|
62 | - } else { |
|
63 | - $progress->advance(); |
|
64 | - } |
|
65 | - }); |
|
51 | + /** |
|
52 | + * @param InputInterface $input |
|
53 | + * @param OutputInterface $output |
|
54 | + * @return int |
|
55 | + */ |
|
56 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
57 | + $progress = new ProgressBar($output); |
|
58 | + $progress->start(); |
|
59 | + $this->syncService->syncThemAll(function ($url, $ex) use ($progress, $output) { |
|
60 | + if ($ex instanceof \Exception) { |
|
61 | + $output->writeln("Error while syncing $url : " . $ex->getMessage()); |
|
62 | + } else { |
|
63 | + $progress->advance(); |
|
64 | + } |
|
65 | + }); |
|
66 | 66 | |
67 | - $progress->finish(); |
|
68 | - $output->writeln(''); |
|
67 | + $progress->finish(); |
|
68 | + $output->writeln(''); |
|
69 | 69 | |
70 | - return 0; |
|
71 | - } |
|
70 | + return 0; |
|
71 | + } |
|
72 | 72 | } |
@@ -56,9 +56,9 @@ |
||
56 | 56 | protected function execute(InputInterface $input, OutputInterface $output) { |
57 | 57 | $progress = new ProgressBar($output); |
58 | 58 | $progress->start(); |
59 | - $this->syncService->syncThemAll(function ($url, $ex) use ($progress, $output) { |
|
59 | + $this->syncService->syncThemAll(function($url, $ex) use ($progress, $output) { |
|
60 | 60 | if ($ex instanceof \Exception) { |
61 | - $output->writeln("Error while syncing $url : " . $ex->getMessage()); |
|
61 | + $output->writeln("Error while syncing $url : ".$ex->getMessage()); |
|
62 | 62 | } else { |
63 | 63 | $progress->advance(); |
64 | 64 | } |