@@ -60,510 +60,510 @@ |
||
60 | 60 | */ |
61 | 61 | interface IServerContainer extends IContainer { |
62 | 62 | |
63 | - /** |
|
64 | - * The calendar manager will act as a broker between consumers for calendar information and |
|
65 | - * providers which actual deliver the calendar information. |
|
66 | - * |
|
67 | - * @return \OCP\Calendar\IManager |
|
68 | - * @since 13.0.0 |
|
69 | - */ |
|
70 | - public function getCalendarManager(); |
|
71 | - |
|
72 | - /** |
|
73 | - * The contacts manager will act as a broker between consumers for contacts information and |
|
74 | - * providers which actual deliver the contact information. |
|
75 | - * |
|
76 | - * @return \OCP\Contacts\IManager |
|
77 | - * @since 6.0.0 |
|
78 | - */ |
|
79 | - public function getContactsManager(); |
|
80 | - |
|
81 | - /** |
|
82 | - * The current request object holding all information about the request currently being processed |
|
83 | - * is returned from this method. |
|
84 | - * In case the current execution was not initiated by a web request null is returned |
|
85 | - * |
|
86 | - * @return \OCP\IRequest |
|
87 | - * @since 6.0.0 |
|
88 | - */ |
|
89 | - public function getRequest(); |
|
90 | - |
|
91 | - /** |
|
92 | - * Returns the preview manager which can create preview images for a given file |
|
93 | - * |
|
94 | - * @return \OCP\IPreview |
|
95 | - * @since 6.0.0 |
|
96 | - */ |
|
97 | - public function getPreviewManager(); |
|
98 | - |
|
99 | - /** |
|
100 | - * Returns the tag manager which can get and set tags for different object types |
|
101 | - * |
|
102 | - * @see \OCP\ITagManager::load() |
|
103 | - * @return \OCP\ITagManager |
|
104 | - * @since 6.0.0 |
|
105 | - */ |
|
106 | - public function getTagManager(); |
|
107 | - |
|
108 | - /** |
|
109 | - * Returns the root folder of ownCloud's data directory |
|
110 | - * |
|
111 | - * @return \OCP\Files\IRootFolder |
|
112 | - * @since 6.0.0 - between 6.0.0 and 8.0.0 this returned \OCP\Files\Folder |
|
113 | - */ |
|
114 | - public function getRootFolder(); |
|
115 | - |
|
116 | - /** |
|
117 | - * Returns a view to ownCloud's files folder |
|
118 | - * |
|
119 | - * @param string $userId user ID |
|
120 | - * @return \OCP\Files\Folder |
|
121 | - * @since 6.0.0 - parameter $userId was added in 8.0.0 |
|
122 | - * @see getUserFolder in \OCP\Files\IRootFolder |
|
123 | - */ |
|
124 | - public function getUserFolder($userId = null); |
|
125 | - |
|
126 | - /** |
|
127 | - * Returns an app-specific view in ownClouds data directory |
|
128 | - * |
|
129 | - * @return \OCP\Files\Folder |
|
130 | - * @since 6.0.0 |
|
131 | - * @deprecated 9.2.0 use IAppData |
|
132 | - */ |
|
133 | - public function getAppFolder(); |
|
134 | - |
|
135 | - /** |
|
136 | - * Returns a user manager |
|
137 | - * |
|
138 | - * @return \OCP\IUserManager |
|
139 | - * @since 8.0.0 |
|
140 | - */ |
|
141 | - public function getUserManager(); |
|
142 | - |
|
143 | - /** |
|
144 | - * Returns a group manager |
|
145 | - * |
|
146 | - * @return \OCP\IGroupManager |
|
147 | - * @since 8.0.0 |
|
148 | - */ |
|
149 | - public function getGroupManager(); |
|
150 | - |
|
151 | - /** |
|
152 | - * Returns the user session |
|
153 | - * |
|
154 | - * @return \OCP\IUserSession |
|
155 | - * @since 6.0.0 |
|
156 | - */ |
|
157 | - public function getUserSession(); |
|
158 | - |
|
159 | - /** |
|
160 | - * Returns the navigation manager |
|
161 | - * |
|
162 | - * @return \OCP\INavigationManager |
|
163 | - * @since 6.0.0 |
|
164 | - */ |
|
165 | - public function getNavigationManager(); |
|
166 | - |
|
167 | - /** |
|
168 | - * Returns the config manager |
|
169 | - * |
|
170 | - * @return \OCP\IConfig |
|
171 | - * @since 6.0.0 |
|
172 | - */ |
|
173 | - public function getConfig(); |
|
174 | - |
|
175 | - /** |
|
176 | - * Returns a Crypto instance |
|
177 | - * |
|
178 | - * @return \OCP\Security\ICrypto |
|
179 | - * @since 8.0.0 |
|
180 | - */ |
|
181 | - public function getCrypto(); |
|
182 | - |
|
183 | - /** |
|
184 | - * Returns a Hasher instance |
|
185 | - * |
|
186 | - * @return \OCP\Security\IHasher |
|
187 | - * @since 8.0.0 |
|
188 | - */ |
|
189 | - public function getHasher(); |
|
190 | - |
|
191 | - /** |
|
192 | - * Returns a SecureRandom instance |
|
193 | - * |
|
194 | - * @return \OCP\Security\ISecureRandom |
|
195 | - * @since 8.1.0 |
|
196 | - */ |
|
197 | - public function getSecureRandom(); |
|
198 | - |
|
199 | - /** |
|
200 | - * Returns a CredentialsManager instance |
|
201 | - * |
|
202 | - * @return \OCP\Security\ICredentialsManager |
|
203 | - * @since 9.0.0 |
|
204 | - */ |
|
205 | - public function getCredentialsManager(); |
|
206 | - |
|
207 | - /** |
|
208 | - * Returns the app config manager |
|
209 | - * |
|
210 | - * @return \OCP\IAppConfig |
|
211 | - * @since 7.0.0 |
|
212 | - */ |
|
213 | - public function getAppConfig(); |
|
214 | - |
|
215 | - /** |
|
216 | - * @return \OCP\L10N\IFactory |
|
217 | - * @since 8.2.0 |
|
218 | - */ |
|
219 | - public function getL10NFactory(); |
|
220 | - |
|
221 | - /** |
|
222 | - * get an L10N instance |
|
223 | - * @param string $app appid |
|
224 | - * @param string $lang |
|
225 | - * @return \OCP\IL10N |
|
226 | - * @since 6.0.0 - parameter $lang was added in 8.0.0 |
|
227 | - */ |
|
228 | - public function getL10N($app, $lang = null); |
|
229 | - |
|
230 | - /** |
|
231 | - * @return \OC\Encryption\Manager |
|
232 | - * @since 8.1.0 |
|
233 | - */ |
|
234 | - public function getEncryptionManager(); |
|
235 | - |
|
236 | - /** |
|
237 | - * @return \OC\Encryption\File |
|
238 | - * @since 8.1.0 |
|
239 | - */ |
|
240 | - public function getEncryptionFilesHelper(); |
|
241 | - |
|
242 | - /** |
|
243 | - * @return \OCP\Encryption\Keys\IStorage |
|
244 | - * @since 8.1.0 |
|
245 | - */ |
|
246 | - public function getEncryptionKeyStorage(); |
|
247 | - |
|
248 | - /** |
|
249 | - * Returns the URL generator |
|
250 | - * |
|
251 | - * @return \OCP\IURLGenerator |
|
252 | - * @since 6.0.0 |
|
253 | - */ |
|
254 | - public function getURLGenerator(); |
|
255 | - |
|
256 | - /** |
|
257 | - * Returns an ICache instance |
|
258 | - * |
|
259 | - * @return \OCP\ICache |
|
260 | - * @since 6.0.0 |
|
261 | - */ |
|
262 | - public function getCache(); |
|
263 | - |
|
264 | - /** |
|
265 | - * Returns an \OCP\CacheFactory instance |
|
266 | - * |
|
267 | - * @return \OCP\ICacheFactory |
|
268 | - * @since 7.0.0 |
|
269 | - */ |
|
270 | - public function getMemCacheFactory(); |
|
271 | - |
|
272 | - /** |
|
273 | - * Returns the current session |
|
274 | - * |
|
275 | - * @return \OCP\ISession |
|
276 | - * @since 6.0.0 |
|
277 | - */ |
|
278 | - public function getSession(); |
|
279 | - |
|
280 | - /** |
|
281 | - * Returns the activity manager |
|
282 | - * |
|
283 | - * @return \OCP\Activity\IManager |
|
284 | - * @since 6.0.0 |
|
285 | - */ |
|
286 | - public function getActivityManager(); |
|
287 | - |
|
288 | - /** |
|
289 | - * Returns the current session |
|
290 | - * |
|
291 | - * @return \OCP\IDBConnection |
|
292 | - * @since 6.0.0 |
|
293 | - */ |
|
294 | - public function getDatabaseConnection(); |
|
295 | - |
|
296 | - /** |
|
297 | - * Returns an avatar manager, used for avatar functionality |
|
298 | - * |
|
299 | - * @return \OCP\IAvatarManager |
|
300 | - * @since 6.0.0 |
|
301 | - */ |
|
302 | - public function getAvatarManager(); |
|
303 | - |
|
304 | - /** |
|
305 | - * Returns an job list for controlling background jobs |
|
306 | - * |
|
307 | - * @return \OCP\BackgroundJob\IJobList |
|
308 | - * @since 7.0.0 |
|
309 | - */ |
|
310 | - public function getJobList(); |
|
311 | - |
|
312 | - /** |
|
313 | - * Returns a logger instance |
|
314 | - * |
|
315 | - * @return \OCP\ILogger |
|
316 | - * @since 8.0.0 |
|
317 | - */ |
|
318 | - public function getLogger(); |
|
319 | - |
|
320 | - /** |
|
321 | - * returns a log factory instance |
|
322 | - * |
|
323 | - * @return ILogFactory |
|
324 | - * @since 14.0.0 |
|
325 | - */ |
|
326 | - public function getLogFactory(); |
|
327 | - |
|
328 | - /** |
|
329 | - * Returns a router for generating and matching urls |
|
330 | - * |
|
331 | - * @return \OCP\Route\IRouter |
|
332 | - * @since 7.0.0 |
|
333 | - */ |
|
334 | - public function getRouter(); |
|
335 | - |
|
336 | - /** |
|
337 | - * Returns a search instance |
|
338 | - * |
|
339 | - * @return \OCP\ISearch |
|
340 | - * @since 7.0.0 |
|
341 | - */ |
|
342 | - public function getSearch(); |
|
343 | - |
|
344 | - /** |
|
345 | - * Get the certificate manager for the user |
|
346 | - * |
|
347 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
348 | - * @return \OCP\ICertificateManager | null if $userId is null and no user is logged in |
|
349 | - * @since 8.0.0 |
|
350 | - */ |
|
351 | - public function getCertificateManager($userId = null); |
|
352 | - |
|
353 | - /** |
|
354 | - * Create a new event source |
|
355 | - * |
|
356 | - * @return \OCP\IEventSource |
|
357 | - * @since 8.0.0 |
|
358 | - */ |
|
359 | - public function createEventSource(); |
|
360 | - |
|
361 | - /** |
|
362 | - * Returns an instance of the HTTP client service |
|
363 | - * |
|
364 | - * @return \OCP\Http\Client\IClientService |
|
365 | - * @since 8.1.0 |
|
366 | - */ |
|
367 | - public function getHTTPClientService(); |
|
368 | - |
|
369 | - /** |
|
370 | - * Get the active event logger |
|
371 | - * |
|
372 | - * @return \OCP\Diagnostics\IEventLogger |
|
373 | - * @since 8.0.0 |
|
374 | - */ |
|
375 | - public function getEventLogger(); |
|
376 | - |
|
377 | - /** |
|
378 | - * Get the active query logger |
|
379 | - * |
|
380 | - * The returned logger only logs data when debug mode is enabled |
|
381 | - * |
|
382 | - * @return \OCP\Diagnostics\IQueryLogger |
|
383 | - * @since 8.0.0 |
|
384 | - */ |
|
385 | - public function getQueryLogger(); |
|
386 | - |
|
387 | - /** |
|
388 | - * Get the manager for temporary files and folders |
|
389 | - * |
|
390 | - * @return \OCP\ITempManager |
|
391 | - * @since 8.0.0 |
|
392 | - */ |
|
393 | - public function getTempManager(); |
|
394 | - |
|
395 | - /** |
|
396 | - * Get the app manager |
|
397 | - * |
|
398 | - * @return \OCP\App\IAppManager |
|
399 | - * @since 8.0.0 |
|
400 | - */ |
|
401 | - public function getAppManager(); |
|
402 | - |
|
403 | - /** |
|
404 | - * Get the webroot |
|
405 | - * |
|
406 | - * @return string |
|
407 | - * @since 8.0.0 |
|
408 | - */ |
|
409 | - public function getWebRoot(); |
|
410 | - |
|
411 | - /** |
|
412 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
413 | - * @since 8.0.0 |
|
414 | - */ |
|
415 | - public function getMountProviderCollection(); |
|
416 | - |
|
417 | - /** |
|
418 | - * Get the IniWrapper |
|
419 | - * |
|
420 | - * @return \bantu\IniGetWrapper\IniGetWrapper |
|
421 | - * @since 8.0.0 |
|
422 | - */ |
|
423 | - public function getIniWrapper(); |
|
424 | - /** |
|
425 | - * @return \OCP\Command\IBus |
|
426 | - * @since 8.1.0 |
|
427 | - */ |
|
428 | - public function getCommandBus(); |
|
429 | - |
|
430 | - /** |
|
431 | - * Creates a new mailer |
|
432 | - * |
|
433 | - * @return \OCP\Mail\IMailer |
|
434 | - * @since 8.1.0 |
|
435 | - */ |
|
436 | - public function getMailer(); |
|
437 | - |
|
438 | - /** |
|
439 | - * Get the locking provider |
|
440 | - * |
|
441 | - * @return \OCP\Lock\ILockingProvider |
|
442 | - * @since 8.1.0 |
|
443 | - */ |
|
444 | - public function getLockingProvider(); |
|
445 | - |
|
446 | - /** |
|
447 | - * @return \OCP\Files\Mount\IMountManager |
|
448 | - * @since 8.2.0 |
|
449 | - */ |
|
450 | - public function getMountManager(); |
|
451 | - |
|
452 | - /** |
|
453 | - * Get the MimeTypeDetector |
|
454 | - * |
|
455 | - * @return \OCP\Files\IMimeTypeDetector |
|
456 | - * @since 8.2.0 |
|
457 | - */ |
|
458 | - public function getMimeTypeDetector(); |
|
459 | - |
|
460 | - /** |
|
461 | - * Get the MimeTypeLoader |
|
462 | - * |
|
463 | - * @return \OCP\Files\IMimeTypeLoader |
|
464 | - * @since 8.2.0 |
|
465 | - */ |
|
466 | - public function getMimeTypeLoader(); |
|
467 | - |
|
468 | - /** |
|
469 | - * Get the EventDispatcher |
|
470 | - * |
|
471 | - * @return EventDispatcherInterface |
|
472 | - * @since 8.2.0 |
|
473 | - */ |
|
474 | - public function getEventDispatcher(); |
|
475 | - |
|
476 | - /** |
|
477 | - * Get the Notification Manager |
|
478 | - * |
|
479 | - * @return \OCP\Notification\IManager |
|
480 | - * @since 9.0.0 |
|
481 | - */ |
|
482 | - public function getNotificationManager(); |
|
483 | - |
|
484 | - /** |
|
485 | - * @return \OCP\Comments\ICommentsManager |
|
486 | - * @since 9.0.0 |
|
487 | - */ |
|
488 | - public function getCommentsManager(); |
|
489 | - |
|
490 | - /** |
|
491 | - * Returns the system-tag manager |
|
492 | - * |
|
493 | - * @return \OCP\SystemTag\ISystemTagManager |
|
494 | - * |
|
495 | - * @since 9.0.0 |
|
496 | - */ |
|
497 | - public function getSystemTagManager(); |
|
498 | - |
|
499 | - /** |
|
500 | - * Returns the system-tag object mapper |
|
501 | - * |
|
502 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
503 | - * |
|
504 | - * @since 9.0.0 |
|
505 | - */ |
|
506 | - public function getSystemTagObjectMapper(); |
|
507 | - |
|
508 | - /** |
|
509 | - * Returns the share manager |
|
510 | - * |
|
511 | - * @return \OCP\Share\IManager |
|
512 | - * @since 9.0.0 |
|
513 | - */ |
|
514 | - public function getShareManager(); |
|
515 | - |
|
516 | - /** |
|
517 | - * @return IContentSecurityPolicyManager |
|
518 | - * @since 9.0.0 |
|
519 | - */ |
|
520 | - public function getContentSecurityPolicyManager(); |
|
521 | - |
|
522 | - /** |
|
523 | - * @return \OCP\IDateTimeZone |
|
524 | - * @since 8.0.0 |
|
525 | - */ |
|
526 | - public function getDateTimeZone(); |
|
527 | - |
|
528 | - /** |
|
529 | - * @return \OCP\IDateTimeFormatter |
|
530 | - * @since 8.0.0 |
|
531 | - */ |
|
532 | - public function getDateTimeFormatter(); |
|
533 | - |
|
534 | - /** |
|
535 | - * @return \OCP\Federation\ICloudIdManager |
|
536 | - * @since 12.0.0 |
|
537 | - */ |
|
538 | - public function getCloudIdManager(); |
|
539 | - |
|
540 | - /** |
|
541 | - * @return \OCP\GlobalScale\IConfig |
|
542 | - * @since 14.0.0 |
|
543 | - */ |
|
544 | - public function getGlobalScaleConfig(); |
|
545 | - |
|
546 | - /** |
|
547 | - * @return ICloudFederationFactory |
|
548 | - * @since 14.0.0 |
|
549 | - */ |
|
550 | - public function getCloudFederationFactory(); |
|
551 | - |
|
552 | - /** |
|
553 | - * @return ICloudFederationProviderManager |
|
554 | - * @since 14.0.0 |
|
555 | - */ |
|
556 | - public function getCloudFederationProviderManager(); |
|
557 | - |
|
558 | - /** |
|
559 | - * @return \OCP\Remote\Api\IApiFactory |
|
560 | - * @since 13.0.0 |
|
561 | - */ |
|
562 | - public function getRemoteApiFactory(); |
|
563 | - |
|
564 | - /** |
|
565 | - * @return \OCP\Remote\IInstanceFactory |
|
566 | - * @since 13.0.0 |
|
567 | - */ |
|
568 | - public function getRemoteInstanceFactory(); |
|
63 | + /** |
|
64 | + * The calendar manager will act as a broker between consumers for calendar information and |
|
65 | + * providers which actual deliver the calendar information. |
|
66 | + * |
|
67 | + * @return \OCP\Calendar\IManager |
|
68 | + * @since 13.0.0 |
|
69 | + */ |
|
70 | + public function getCalendarManager(); |
|
71 | + |
|
72 | + /** |
|
73 | + * The contacts manager will act as a broker between consumers for contacts information and |
|
74 | + * providers which actual deliver the contact information. |
|
75 | + * |
|
76 | + * @return \OCP\Contacts\IManager |
|
77 | + * @since 6.0.0 |
|
78 | + */ |
|
79 | + public function getContactsManager(); |
|
80 | + |
|
81 | + /** |
|
82 | + * The current request object holding all information about the request currently being processed |
|
83 | + * is returned from this method. |
|
84 | + * In case the current execution was not initiated by a web request null is returned |
|
85 | + * |
|
86 | + * @return \OCP\IRequest |
|
87 | + * @since 6.0.0 |
|
88 | + */ |
|
89 | + public function getRequest(); |
|
90 | + |
|
91 | + /** |
|
92 | + * Returns the preview manager which can create preview images for a given file |
|
93 | + * |
|
94 | + * @return \OCP\IPreview |
|
95 | + * @since 6.0.0 |
|
96 | + */ |
|
97 | + public function getPreviewManager(); |
|
98 | + |
|
99 | + /** |
|
100 | + * Returns the tag manager which can get and set tags for different object types |
|
101 | + * |
|
102 | + * @see \OCP\ITagManager::load() |
|
103 | + * @return \OCP\ITagManager |
|
104 | + * @since 6.0.0 |
|
105 | + */ |
|
106 | + public function getTagManager(); |
|
107 | + |
|
108 | + /** |
|
109 | + * Returns the root folder of ownCloud's data directory |
|
110 | + * |
|
111 | + * @return \OCP\Files\IRootFolder |
|
112 | + * @since 6.0.0 - between 6.0.0 and 8.0.0 this returned \OCP\Files\Folder |
|
113 | + */ |
|
114 | + public function getRootFolder(); |
|
115 | + |
|
116 | + /** |
|
117 | + * Returns a view to ownCloud's files folder |
|
118 | + * |
|
119 | + * @param string $userId user ID |
|
120 | + * @return \OCP\Files\Folder |
|
121 | + * @since 6.0.0 - parameter $userId was added in 8.0.0 |
|
122 | + * @see getUserFolder in \OCP\Files\IRootFolder |
|
123 | + */ |
|
124 | + public function getUserFolder($userId = null); |
|
125 | + |
|
126 | + /** |
|
127 | + * Returns an app-specific view in ownClouds data directory |
|
128 | + * |
|
129 | + * @return \OCP\Files\Folder |
|
130 | + * @since 6.0.0 |
|
131 | + * @deprecated 9.2.0 use IAppData |
|
132 | + */ |
|
133 | + public function getAppFolder(); |
|
134 | + |
|
135 | + /** |
|
136 | + * Returns a user manager |
|
137 | + * |
|
138 | + * @return \OCP\IUserManager |
|
139 | + * @since 8.0.0 |
|
140 | + */ |
|
141 | + public function getUserManager(); |
|
142 | + |
|
143 | + /** |
|
144 | + * Returns a group manager |
|
145 | + * |
|
146 | + * @return \OCP\IGroupManager |
|
147 | + * @since 8.0.0 |
|
148 | + */ |
|
149 | + public function getGroupManager(); |
|
150 | + |
|
151 | + /** |
|
152 | + * Returns the user session |
|
153 | + * |
|
154 | + * @return \OCP\IUserSession |
|
155 | + * @since 6.0.0 |
|
156 | + */ |
|
157 | + public function getUserSession(); |
|
158 | + |
|
159 | + /** |
|
160 | + * Returns the navigation manager |
|
161 | + * |
|
162 | + * @return \OCP\INavigationManager |
|
163 | + * @since 6.0.0 |
|
164 | + */ |
|
165 | + public function getNavigationManager(); |
|
166 | + |
|
167 | + /** |
|
168 | + * Returns the config manager |
|
169 | + * |
|
170 | + * @return \OCP\IConfig |
|
171 | + * @since 6.0.0 |
|
172 | + */ |
|
173 | + public function getConfig(); |
|
174 | + |
|
175 | + /** |
|
176 | + * Returns a Crypto instance |
|
177 | + * |
|
178 | + * @return \OCP\Security\ICrypto |
|
179 | + * @since 8.0.0 |
|
180 | + */ |
|
181 | + public function getCrypto(); |
|
182 | + |
|
183 | + /** |
|
184 | + * Returns a Hasher instance |
|
185 | + * |
|
186 | + * @return \OCP\Security\IHasher |
|
187 | + * @since 8.0.0 |
|
188 | + */ |
|
189 | + public function getHasher(); |
|
190 | + |
|
191 | + /** |
|
192 | + * Returns a SecureRandom instance |
|
193 | + * |
|
194 | + * @return \OCP\Security\ISecureRandom |
|
195 | + * @since 8.1.0 |
|
196 | + */ |
|
197 | + public function getSecureRandom(); |
|
198 | + |
|
199 | + /** |
|
200 | + * Returns a CredentialsManager instance |
|
201 | + * |
|
202 | + * @return \OCP\Security\ICredentialsManager |
|
203 | + * @since 9.0.0 |
|
204 | + */ |
|
205 | + public function getCredentialsManager(); |
|
206 | + |
|
207 | + /** |
|
208 | + * Returns the app config manager |
|
209 | + * |
|
210 | + * @return \OCP\IAppConfig |
|
211 | + * @since 7.0.0 |
|
212 | + */ |
|
213 | + public function getAppConfig(); |
|
214 | + |
|
215 | + /** |
|
216 | + * @return \OCP\L10N\IFactory |
|
217 | + * @since 8.2.0 |
|
218 | + */ |
|
219 | + public function getL10NFactory(); |
|
220 | + |
|
221 | + /** |
|
222 | + * get an L10N instance |
|
223 | + * @param string $app appid |
|
224 | + * @param string $lang |
|
225 | + * @return \OCP\IL10N |
|
226 | + * @since 6.0.0 - parameter $lang was added in 8.0.0 |
|
227 | + */ |
|
228 | + public function getL10N($app, $lang = null); |
|
229 | + |
|
230 | + /** |
|
231 | + * @return \OC\Encryption\Manager |
|
232 | + * @since 8.1.0 |
|
233 | + */ |
|
234 | + public function getEncryptionManager(); |
|
235 | + |
|
236 | + /** |
|
237 | + * @return \OC\Encryption\File |
|
238 | + * @since 8.1.0 |
|
239 | + */ |
|
240 | + public function getEncryptionFilesHelper(); |
|
241 | + |
|
242 | + /** |
|
243 | + * @return \OCP\Encryption\Keys\IStorage |
|
244 | + * @since 8.1.0 |
|
245 | + */ |
|
246 | + public function getEncryptionKeyStorage(); |
|
247 | + |
|
248 | + /** |
|
249 | + * Returns the URL generator |
|
250 | + * |
|
251 | + * @return \OCP\IURLGenerator |
|
252 | + * @since 6.0.0 |
|
253 | + */ |
|
254 | + public function getURLGenerator(); |
|
255 | + |
|
256 | + /** |
|
257 | + * Returns an ICache instance |
|
258 | + * |
|
259 | + * @return \OCP\ICache |
|
260 | + * @since 6.0.0 |
|
261 | + */ |
|
262 | + public function getCache(); |
|
263 | + |
|
264 | + /** |
|
265 | + * Returns an \OCP\CacheFactory instance |
|
266 | + * |
|
267 | + * @return \OCP\ICacheFactory |
|
268 | + * @since 7.0.0 |
|
269 | + */ |
|
270 | + public function getMemCacheFactory(); |
|
271 | + |
|
272 | + /** |
|
273 | + * Returns the current session |
|
274 | + * |
|
275 | + * @return \OCP\ISession |
|
276 | + * @since 6.0.0 |
|
277 | + */ |
|
278 | + public function getSession(); |
|
279 | + |
|
280 | + /** |
|
281 | + * Returns the activity manager |
|
282 | + * |
|
283 | + * @return \OCP\Activity\IManager |
|
284 | + * @since 6.0.0 |
|
285 | + */ |
|
286 | + public function getActivityManager(); |
|
287 | + |
|
288 | + /** |
|
289 | + * Returns the current session |
|
290 | + * |
|
291 | + * @return \OCP\IDBConnection |
|
292 | + * @since 6.0.0 |
|
293 | + */ |
|
294 | + public function getDatabaseConnection(); |
|
295 | + |
|
296 | + /** |
|
297 | + * Returns an avatar manager, used for avatar functionality |
|
298 | + * |
|
299 | + * @return \OCP\IAvatarManager |
|
300 | + * @since 6.0.0 |
|
301 | + */ |
|
302 | + public function getAvatarManager(); |
|
303 | + |
|
304 | + /** |
|
305 | + * Returns an job list for controlling background jobs |
|
306 | + * |
|
307 | + * @return \OCP\BackgroundJob\IJobList |
|
308 | + * @since 7.0.0 |
|
309 | + */ |
|
310 | + public function getJobList(); |
|
311 | + |
|
312 | + /** |
|
313 | + * Returns a logger instance |
|
314 | + * |
|
315 | + * @return \OCP\ILogger |
|
316 | + * @since 8.0.0 |
|
317 | + */ |
|
318 | + public function getLogger(); |
|
319 | + |
|
320 | + /** |
|
321 | + * returns a log factory instance |
|
322 | + * |
|
323 | + * @return ILogFactory |
|
324 | + * @since 14.0.0 |
|
325 | + */ |
|
326 | + public function getLogFactory(); |
|
327 | + |
|
328 | + /** |
|
329 | + * Returns a router for generating and matching urls |
|
330 | + * |
|
331 | + * @return \OCP\Route\IRouter |
|
332 | + * @since 7.0.0 |
|
333 | + */ |
|
334 | + public function getRouter(); |
|
335 | + |
|
336 | + /** |
|
337 | + * Returns a search instance |
|
338 | + * |
|
339 | + * @return \OCP\ISearch |
|
340 | + * @since 7.0.0 |
|
341 | + */ |
|
342 | + public function getSearch(); |
|
343 | + |
|
344 | + /** |
|
345 | + * Get the certificate manager for the user |
|
346 | + * |
|
347 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
348 | + * @return \OCP\ICertificateManager | null if $userId is null and no user is logged in |
|
349 | + * @since 8.0.0 |
|
350 | + */ |
|
351 | + public function getCertificateManager($userId = null); |
|
352 | + |
|
353 | + /** |
|
354 | + * Create a new event source |
|
355 | + * |
|
356 | + * @return \OCP\IEventSource |
|
357 | + * @since 8.0.0 |
|
358 | + */ |
|
359 | + public function createEventSource(); |
|
360 | + |
|
361 | + /** |
|
362 | + * Returns an instance of the HTTP client service |
|
363 | + * |
|
364 | + * @return \OCP\Http\Client\IClientService |
|
365 | + * @since 8.1.0 |
|
366 | + */ |
|
367 | + public function getHTTPClientService(); |
|
368 | + |
|
369 | + /** |
|
370 | + * Get the active event logger |
|
371 | + * |
|
372 | + * @return \OCP\Diagnostics\IEventLogger |
|
373 | + * @since 8.0.0 |
|
374 | + */ |
|
375 | + public function getEventLogger(); |
|
376 | + |
|
377 | + /** |
|
378 | + * Get the active query logger |
|
379 | + * |
|
380 | + * The returned logger only logs data when debug mode is enabled |
|
381 | + * |
|
382 | + * @return \OCP\Diagnostics\IQueryLogger |
|
383 | + * @since 8.0.0 |
|
384 | + */ |
|
385 | + public function getQueryLogger(); |
|
386 | + |
|
387 | + /** |
|
388 | + * Get the manager for temporary files and folders |
|
389 | + * |
|
390 | + * @return \OCP\ITempManager |
|
391 | + * @since 8.0.0 |
|
392 | + */ |
|
393 | + public function getTempManager(); |
|
394 | + |
|
395 | + /** |
|
396 | + * Get the app manager |
|
397 | + * |
|
398 | + * @return \OCP\App\IAppManager |
|
399 | + * @since 8.0.0 |
|
400 | + */ |
|
401 | + public function getAppManager(); |
|
402 | + |
|
403 | + /** |
|
404 | + * Get the webroot |
|
405 | + * |
|
406 | + * @return string |
|
407 | + * @since 8.0.0 |
|
408 | + */ |
|
409 | + public function getWebRoot(); |
|
410 | + |
|
411 | + /** |
|
412 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
413 | + * @since 8.0.0 |
|
414 | + */ |
|
415 | + public function getMountProviderCollection(); |
|
416 | + |
|
417 | + /** |
|
418 | + * Get the IniWrapper |
|
419 | + * |
|
420 | + * @return \bantu\IniGetWrapper\IniGetWrapper |
|
421 | + * @since 8.0.0 |
|
422 | + */ |
|
423 | + public function getIniWrapper(); |
|
424 | + /** |
|
425 | + * @return \OCP\Command\IBus |
|
426 | + * @since 8.1.0 |
|
427 | + */ |
|
428 | + public function getCommandBus(); |
|
429 | + |
|
430 | + /** |
|
431 | + * Creates a new mailer |
|
432 | + * |
|
433 | + * @return \OCP\Mail\IMailer |
|
434 | + * @since 8.1.0 |
|
435 | + */ |
|
436 | + public function getMailer(); |
|
437 | + |
|
438 | + /** |
|
439 | + * Get the locking provider |
|
440 | + * |
|
441 | + * @return \OCP\Lock\ILockingProvider |
|
442 | + * @since 8.1.0 |
|
443 | + */ |
|
444 | + public function getLockingProvider(); |
|
445 | + |
|
446 | + /** |
|
447 | + * @return \OCP\Files\Mount\IMountManager |
|
448 | + * @since 8.2.0 |
|
449 | + */ |
|
450 | + public function getMountManager(); |
|
451 | + |
|
452 | + /** |
|
453 | + * Get the MimeTypeDetector |
|
454 | + * |
|
455 | + * @return \OCP\Files\IMimeTypeDetector |
|
456 | + * @since 8.2.0 |
|
457 | + */ |
|
458 | + public function getMimeTypeDetector(); |
|
459 | + |
|
460 | + /** |
|
461 | + * Get the MimeTypeLoader |
|
462 | + * |
|
463 | + * @return \OCP\Files\IMimeTypeLoader |
|
464 | + * @since 8.2.0 |
|
465 | + */ |
|
466 | + public function getMimeTypeLoader(); |
|
467 | + |
|
468 | + /** |
|
469 | + * Get the EventDispatcher |
|
470 | + * |
|
471 | + * @return EventDispatcherInterface |
|
472 | + * @since 8.2.0 |
|
473 | + */ |
|
474 | + public function getEventDispatcher(); |
|
475 | + |
|
476 | + /** |
|
477 | + * Get the Notification Manager |
|
478 | + * |
|
479 | + * @return \OCP\Notification\IManager |
|
480 | + * @since 9.0.0 |
|
481 | + */ |
|
482 | + public function getNotificationManager(); |
|
483 | + |
|
484 | + /** |
|
485 | + * @return \OCP\Comments\ICommentsManager |
|
486 | + * @since 9.0.0 |
|
487 | + */ |
|
488 | + public function getCommentsManager(); |
|
489 | + |
|
490 | + /** |
|
491 | + * Returns the system-tag manager |
|
492 | + * |
|
493 | + * @return \OCP\SystemTag\ISystemTagManager |
|
494 | + * |
|
495 | + * @since 9.0.0 |
|
496 | + */ |
|
497 | + public function getSystemTagManager(); |
|
498 | + |
|
499 | + /** |
|
500 | + * Returns the system-tag object mapper |
|
501 | + * |
|
502 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
503 | + * |
|
504 | + * @since 9.0.0 |
|
505 | + */ |
|
506 | + public function getSystemTagObjectMapper(); |
|
507 | + |
|
508 | + /** |
|
509 | + * Returns the share manager |
|
510 | + * |
|
511 | + * @return \OCP\Share\IManager |
|
512 | + * @since 9.0.0 |
|
513 | + */ |
|
514 | + public function getShareManager(); |
|
515 | + |
|
516 | + /** |
|
517 | + * @return IContentSecurityPolicyManager |
|
518 | + * @since 9.0.0 |
|
519 | + */ |
|
520 | + public function getContentSecurityPolicyManager(); |
|
521 | + |
|
522 | + /** |
|
523 | + * @return \OCP\IDateTimeZone |
|
524 | + * @since 8.0.0 |
|
525 | + */ |
|
526 | + public function getDateTimeZone(); |
|
527 | + |
|
528 | + /** |
|
529 | + * @return \OCP\IDateTimeFormatter |
|
530 | + * @since 8.0.0 |
|
531 | + */ |
|
532 | + public function getDateTimeFormatter(); |
|
533 | + |
|
534 | + /** |
|
535 | + * @return \OCP\Federation\ICloudIdManager |
|
536 | + * @since 12.0.0 |
|
537 | + */ |
|
538 | + public function getCloudIdManager(); |
|
539 | + |
|
540 | + /** |
|
541 | + * @return \OCP\GlobalScale\IConfig |
|
542 | + * @since 14.0.0 |
|
543 | + */ |
|
544 | + public function getGlobalScaleConfig(); |
|
545 | + |
|
546 | + /** |
|
547 | + * @return ICloudFederationFactory |
|
548 | + * @since 14.0.0 |
|
549 | + */ |
|
550 | + public function getCloudFederationFactory(); |
|
551 | + |
|
552 | + /** |
|
553 | + * @return ICloudFederationProviderManager |
|
554 | + * @since 14.0.0 |
|
555 | + */ |
|
556 | + public function getCloudFederationProviderManager(); |
|
557 | + |
|
558 | + /** |
|
559 | + * @return \OCP\Remote\Api\IApiFactory |
|
560 | + * @since 13.0.0 |
|
561 | + */ |
|
562 | + public function getRemoteApiFactory(); |
|
563 | + |
|
564 | + /** |
|
565 | + * @return \OCP\Remote\IInstanceFactory |
|
566 | + * @since 13.0.0 |
|
567 | + */ |
|
568 | + public function getRemoteInstanceFactory(); |
|
569 | 569 | } |
@@ -32,17 +32,17 @@ |
||
32 | 32 | */ |
33 | 33 | class AuthenticationFailedException extends HintException { |
34 | 34 | |
35 | - /** |
|
36 | - * BadRequestException constructor. |
|
37 | - * |
|
38 | - * @since 14.0.0 |
|
39 | - * |
|
40 | - */ |
|
41 | - public function __construct() { |
|
42 | - $l = \OC::$server->getL10N('federation'); |
|
43 | - $message = 'Authentication failed, wrong token or provider ID given'; |
|
44 | - $hint = $l->t('Authentication failed, wrong token or provider ID given'); |
|
45 | - parent::__construct($message, $hint); |
|
46 | - } |
|
35 | + /** |
|
36 | + * BadRequestException constructor. |
|
37 | + * |
|
38 | + * @since 14.0.0 |
|
39 | + * |
|
40 | + */ |
|
41 | + public function __construct() { |
|
42 | + $l = \OC::$server->getL10N('federation'); |
|
43 | + $message = 'Authentication failed, wrong token or provider ID given'; |
|
44 | + $hint = $l->t('Authentication failed, wrong token or provider ID given'); |
|
45 | + parent::__construct($message, $hint); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | } |
@@ -52,431 +52,431 @@ |
||
52 | 52 | |
53 | 53 | class RequestHandlerController extends OCSController { |
54 | 54 | |
55 | - /** @var FederatedShareProvider */ |
|
56 | - private $federatedShareProvider; |
|
57 | - |
|
58 | - /** @var IDBConnection */ |
|
59 | - private $connection; |
|
60 | - |
|
61 | - /** @var Share\IManager */ |
|
62 | - private $shareManager; |
|
63 | - |
|
64 | - /** @var Notifications */ |
|
65 | - private $notifications; |
|
66 | - |
|
67 | - /** @var AddressHandler */ |
|
68 | - private $addressHandler; |
|
69 | - |
|
70 | - /** @var IUserManager */ |
|
71 | - private $userManager; |
|
72 | - |
|
73 | - /** @var string */ |
|
74 | - private $shareTable = 'share'; |
|
75 | - |
|
76 | - /** @var ICloudIdManager */ |
|
77 | - private $cloudIdManager; |
|
78 | - |
|
79 | - /** @var ILogger */ |
|
80 | - private $logger; |
|
81 | - |
|
82 | - /** @var ICloudFederationFactory */ |
|
83 | - private $cloudFederationFactory; |
|
84 | - |
|
85 | - /** @var ICloudFederationProviderManager */ |
|
86 | - private $cloudFederationProviderManager; |
|
87 | - |
|
88 | - /** |
|
89 | - * Server2Server constructor. |
|
90 | - * |
|
91 | - * @param string $appName |
|
92 | - * @param IRequest $request |
|
93 | - * @param FederatedShareProvider $federatedShareProvider |
|
94 | - * @param IDBConnection $connection |
|
95 | - * @param Share\IManager $shareManager |
|
96 | - * @param Notifications $notifications |
|
97 | - * @param AddressHandler $addressHandler |
|
98 | - * @param IUserManager $userManager |
|
99 | - * @param ICloudIdManager $cloudIdManager |
|
100 | - * @param ILogger $logger |
|
101 | - * @param ICloudFederationFactory $cloudFederationFactory |
|
102 | - * @param ICloudFederationProviderManager $cloudFederationProviderManager |
|
103 | - */ |
|
104 | - public function __construct($appName, |
|
105 | - IRequest $request, |
|
106 | - FederatedShareProvider $federatedShareProvider, |
|
107 | - IDBConnection $connection, |
|
108 | - Share\IManager $shareManager, |
|
109 | - Notifications $notifications, |
|
110 | - AddressHandler $addressHandler, |
|
111 | - IUserManager $userManager, |
|
112 | - ICloudIdManager $cloudIdManager, |
|
113 | - ILogger $logger, |
|
114 | - ICloudFederationFactory $cloudFederationFactory, |
|
115 | - ICloudFederationProviderManager $cloudFederationProviderManager |
|
116 | - ) { |
|
117 | - parent::__construct($appName, $request); |
|
118 | - |
|
119 | - $this->federatedShareProvider = $federatedShareProvider; |
|
120 | - $this->connection = $connection; |
|
121 | - $this->shareManager = $shareManager; |
|
122 | - $this->notifications = $notifications; |
|
123 | - $this->addressHandler = $addressHandler; |
|
124 | - $this->userManager = $userManager; |
|
125 | - $this->cloudIdManager = $cloudIdManager; |
|
126 | - $this->logger = $logger; |
|
127 | - $this->cloudFederationFactory = $cloudFederationFactory; |
|
128 | - $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * @NoCSRFRequired |
|
133 | - * @PublicPage |
|
134 | - * |
|
135 | - * create a new share |
|
136 | - * |
|
137 | - * @return Http\DataResponse |
|
138 | - * @throws OCSException |
|
139 | - */ |
|
140 | - public function createShare() { |
|
141 | - |
|
142 | - $remote = isset($_POST['remote']) ? $_POST['remote'] : null; |
|
143 | - $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
144 | - $name = isset($_POST['name']) ? $_POST['name'] : null; |
|
145 | - $owner = isset($_POST['owner']) ? $_POST['owner'] : null; |
|
146 | - $sharedBy = isset($_POST['sharedBy']) ? $_POST['sharedBy'] : null; |
|
147 | - $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null; |
|
148 | - $remoteId = isset($_POST['remoteId']) ? (int)$_POST['remoteId'] : null; |
|
149 | - $sharedByFederatedId = isset($_POST['sharedByFederatedId']) ? $_POST['sharedByFederatedId'] : null; |
|
150 | - $ownerFederatedId = isset($_POST['ownerFederatedId']) ? $_POST['ownerFederatedId'] : null; |
|
151 | - |
|
152 | - if ($ownerFederatedId === null) { |
|
153 | - $ownerFederatedId = $this->cloudIdManager->getCloudId($owner, $this->cleanupRemote($remote))->getId(); |
|
154 | - } |
|
155 | - // if the owner of the share and the initiator are the same user |
|
156 | - // we also complete the federated share ID for the initiator |
|
157 | - if ($sharedByFederatedId === null && $owner === $sharedBy) { |
|
158 | - $sharedByFederatedId = $ownerFederatedId; |
|
159 | - } |
|
160 | - |
|
161 | - $share = $this->cloudFederationFactory->getCloudFederationShare( |
|
162 | - $shareWith, |
|
163 | - $name, |
|
164 | - '', |
|
165 | - $remoteId, |
|
166 | - $ownerFederatedId, |
|
167 | - $owner, |
|
168 | - $sharedByFederatedId, |
|
169 | - $sharedBy, |
|
170 | - $token, |
|
171 | - 'user', |
|
172 | - 'file' |
|
173 | - ); |
|
174 | - |
|
175 | - try { |
|
176 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
177 | - $provider->shareReceived($share); |
|
178 | - } catch (ProviderDoesNotExistsException $e) { |
|
179 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
180 | - } catch (ProviderCouldNotAddShareException $e) { |
|
181 | - throw new OCSException($e->getMessage(), 400); |
|
182 | - } catch (\Exception $e) { |
|
183 | - throw new OCSException('internal server error, was not able to add share from ' . $remote, 500); |
|
184 | - } |
|
185 | - |
|
186 | - return new Http\DataResponse(); |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * @NoCSRFRequired |
|
191 | - * @PublicPage |
|
192 | - * |
|
193 | - * create re-share on behalf of another user |
|
194 | - * |
|
195 | - * @param int $id |
|
196 | - * @return Http\DataResponse |
|
197 | - * @throws OCSBadRequestException |
|
198 | - * @throws OCSException |
|
199 | - * @throws OCSForbiddenException |
|
200 | - */ |
|
201 | - public function reShare($id) { |
|
202 | - |
|
203 | - $token = $this->request->getParam('token', null); |
|
204 | - $shareWith = $this->request->getParam('shareWith', null); |
|
205 | - $permission = (int)$this->request->getParam('permission', null); |
|
206 | - $remoteId = (int)$this->request->getParam('remoteId', null); |
|
207 | - |
|
208 | - if ($id === null || |
|
209 | - $token === null || |
|
210 | - $shareWith === null || |
|
211 | - $permission === null || |
|
212 | - $remoteId === null |
|
213 | - ) { |
|
214 | - throw new OCSBadRequestException(); |
|
215 | - } |
|
216 | - |
|
217 | - $notification = [ |
|
218 | - 'sharedSecret' => $token, |
|
219 | - 'shareWith' => $shareWith, |
|
220 | - 'senderId' => $remoteId, |
|
221 | - 'message' => 'Recipient of a share ask the owner to reshare the file' |
|
222 | - ]; |
|
223 | - |
|
224 | - try { |
|
225 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
226 | - list($newToken, $localId) = $provider->notificationReceived('REQUEST_RESHARE', $id, $notification); |
|
227 | - return new Http\DataResponse([ |
|
228 | - 'token' => $newToken, |
|
229 | - 'remoteId' => $localId |
|
230 | - ]); |
|
231 | - } catch (ProviderDoesNotExistsException $e) { |
|
232 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
233 | - } catch (ShareNotFound $e) { |
|
234 | - $this->logger->debug('Share not found: ' . $e->getMessage()); |
|
235 | - } catch (\Exception $e) { |
|
236 | - $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); |
|
237 | - } |
|
238 | - |
|
239 | - throw new OCSBadRequestException(); |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * @NoCSRFRequired |
|
245 | - * @PublicPage |
|
246 | - * |
|
247 | - * accept server-to-server share |
|
248 | - * |
|
249 | - * @param int $id |
|
250 | - * @return Http\DataResponse |
|
251 | - * @throws OCSException |
|
252 | - * @throws ShareNotFound |
|
253 | - * @throws \OC\HintException |
|
254 | - */ |
|
255 | - public function acceptShare($id) { |
|
256 | - |
|
257 | - $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
258 | - |
|
259 | - $notification = [ |
|
260 | - 'sharedSecret' => $token, |
|
261 | - 'message' => 'Recipient accept the share' |
|
262 | - ]; |
|
263 | - |
|
264 | - try { |
|
265 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
266 | - $provider->notificationReceived('SHARE_ACCEPTED', $id, $notification); |
|
267 | - } catch (ProviderDoesNotExistsException $e) { |
|
268 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
269 | - } catch (ShareNotFound $e) { |
|
270 | - $this->logger->debug('Share not found: ' . $e->getMessage()); |
|
271 | - } catch (\Exception $e) { |
|
272 | - $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); |
|
273 | - } |
|
274 | - |
|
275 | - return new Http\DataResponse(); |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * @NoCSRFRequired |
|
280 | - * @PublicPage |
|
281 | - * |
|
282 | - * decline server-to-server share |
|
283 | - * |
|
284 | - * @param int $id |
|
285 | - * @return Http\DataResponse |
|
286 | - * @throws OCSException |
|
287 | - */ |
|
288 | - public function declineShare($id) { |
|
289 | - |
|
290 | - $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
291 | - |
|
292 | - $notification = [ |
|
293 | - 'sharedSecret' => $token, |
|
294 | - 'message' => 'Recipient declined the share' |
|
295 | - ]; |
|
296 | - |
|
297 | - try { |
|
298 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
299 | - $provider->notificationReceived('SHARE_DECLINED', $id, $notification); |
|
300 | - } catch (ProviderDoesNotExistsException $e) { |
|
301 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
302 | - } catch (ShareNotFound $e) { |
|
303 | - $this->logger->debug('Share not found: ' . $e->getMessage()); |
|
304 | - } catch (\Exception $e) { |
|
305 | - $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); |
|
306 | - } |
|
307 | - |
|
308 | - return new Http\DataResponse(); |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * @NoCSRFRequired |
|
313 | - * @PublicPage |
|
314 | - * |
|
315 | - * remove server-to-server share if it was unshared by the owner |
|
316 | - * |
|
317 | - * @param int $id |
|
318 | - * @return Http\DataResponse |
|
319 | - * @throws OCSException |
|
320 | - */ |
|
321 | - public function unshare($id) { |
|
322 | - |
|
323 | - if (!$this->isS2SEnabled()) { |
|
324 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
325 | - } |
|
326 | - |
|
327 | - $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
328 | - |
|
329 | - try { |
|
330 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
331 | - $notification = ['sharedSecret' => $token]; |
|
332 | - $provider->notificationReceived('SHARE_UNSHARED', $id, $notification); |
|
333 | - } catch (\Exception $e) { |
|
334 | - $this->logger->debug('processing unshare notification failed: ' . $e->getMessage()); |
|
335 | - } |
|
336 | - |
|
337 | - return new Http\DataResponse(); |
|
338 | - } |
|
339 | - |
|
340 | - private function cleanupRemote($remote) { |
|
341 | - $remote = substr($remote, strpos($remote, '://') + 3); |
|
342 | - |
|
343 | - return rtrim($remote, '/'); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * @NoCSRFRequired |
|
349 | - * @PublicPage |
|
350 | - * |
|
351 | - * federated share was revoked, either by the owner or the re-sharer |
|
352 | - * |
|
353 | - * @param int $id |
|
354 | - * @return Http\DataResponse |
|
355 | - * @throws OCSBadRequestException |
|
356 | - */ |
|
357 | - public function revoke($id) { |
|
358 | - |
|
359 | - $token = $this->request->getParam('token'); |
|
360 | - |
|
361 | - try { |
|
362 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
363 | - $notification = ['sharedSecret' => $token]; |
|
364 | - $provider->notificationReceived('RESHARE_UNDO', $id, $notification); |
|
365 | - return new Http\DataResponse(); |
|
366 | - } catch (\Exception $e) { |
|
367 | - throw new OCSBadRequestException(); |
|
368 | - } |
|
369 | - |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * check if server-to-server sharing is enabled |
|
374 | - * |
|
375 | - * @param bool $incoming |
|
376 | - * @return bool |
|
377 | - */ |
|
378 | - private function isS2SEnabled($incoming = false) { |
|
379 | - |
|
380 | - $result = \OCP\App::isEnabled('files_sharing'); |
|
381 | - |
|
382 | - if ($incoming) { |
|
383 | - $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled(); |
|
384 | - } else { |
|
385 | - $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
386 | - } |
|
387 | - |
|
388 | - return $result; |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * @NoCSRFRequired |
|
393 | - * @PublicPage |
|
394 | - * |
|
395 | - * update share information to keep federated re-shares in sync |
|
396 | - * |
|
397 | - * @param int $id |
|
398 | - * @return Http\DataResponse |
|
399 | - * @throws OCSBadRequestException |
|
400 | - */ |
|
401 | - public function updatePermissions($id) { |
|
402 | - $token = $this->request->getParam('token', null); |
|
403 | - $ncPermissions = $this->request->getParam('permissions', null); |
|
404 | - |
|
405 | - try { |
|
406 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
407 | - $ocmPermissions = $this->ncPermissions2ocmPermissions((int)$ncPermissions); |
|
408 | - $notification = ['sharedSecret' => $token, 'permission' => $ocmPermissions]; |
|
409 | - $provider->notificationReceived('RESHARE_CHANGE_PERMISSION', $id, $notification); |
|
410 | - } catch (\Exception $e) { |
|
411 | - $this->logger->debug($e->getMessage()); |
|
412 | - throw new OCSBadRequestException(); |
|
413 | - } |
|
414 | - |
|
415 | - return new Http\DataResponse(); |
|
416 | - } |
|
417 | - |
|
418 | - /** |
|
419 | - * translate Nextcloud permissions to OCM Permissions |
|
420 | - * |
|
421 | - * @param $ncPermissions |
|
422 | - * @return array |
|
423 | - */ |
|
424 | - protected function ncPermissions2ocmPermissions($ncPermissions) { |
|
425 | - |
|
426 | - $ocmPermissions = []; |
|
427 | - |
|
428 | - if ($ncPermissions & Constants::PERMISSION_SHARE) { |
|
429 | - $ocmPermissions[] = 'share'; |
|
430 | - } |
|
431 | - |
|
432 | - if ($ncPermissions & Constants::PERMISSION_READ) { |
|
433 | - $ocmPermissions[] = 'read'; |
|
434 | - } |
|
435 | - |
|
436 | - if (($ncPermissions & Constants::PERMISSION_CREATE) || |
|
437 | - ($ncPermissions & Constants::PERMISSION_UPDATE)) { |
|
438 | - $ocmPermissions[] = 'write'; |
|
439 | - } |
|
440 | - |
|
441 | - return $ocmPermissions; |
|
442 | - |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * @NoCSRFRequired |
|
447 | - * @PublicPage |
|
448 | - * |
|
449 | - * change the owner of a server-to-server share |
|
450 | - * |
|
451 | - * @param int $id |
|
452 | - * @return Http\DataResponse |
|
453 | - * @throws \InvalidArgumentException |
|
454 | - * @throws OCSException |
|
455 | - */ |
|
456 | - public function move($id) { |
|
457 | - |
|
458 | - if (!$this->isS2SEnabled()) { |
|
459 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
460 | - } |
|
461 | - |
|
462 | - $token = $this->request->getParam('token'); |
|
463 | - $remote = $this->request->getParam('remote'); |
|
464 | - $newRemoteId = $this->request->getParam('remote_id', $id); |
|
465 | - $cloudId = $this->cloudIdManager->resolveCloudId($remote); |
|
466 | - |
|
467 | - $qb = $this->connection->getQueryBuilder(); |
|
468 | - $query = $qb->update('share_external') |
|
469 | - ->set('remote', $qb->createNamedParameter($cloudId->getRemote())) |
|
470 | - ->set('owner', $qb->createNamedParameter($cloudId->getUser())) |
|
471 | - ->set('remote_id', $qb->createNamedParameter($newRemoteId)) |
|
472 | - ->where($qb->expr()->eq('remote_id', $qb->createNamedParameter($id))) |
|
473 | - ->andWhere($qb->expr()->eq('share_token', $qb->createNamedParameter($token))); |
|
474 | - $affected = $query->execute(); |
|
475 | - |
|
476 | - if ($affected > 0) { |
|
477 | - return new Http\DataResponse(['remote' => $cloudId->getRemote(), 'owner' => $cloudId->getUser()]); |
|
478 | - } else { |
|
479 | - throw new OCSBadRequestException('Share not found or token invalid'); |
|
480 | - } |
|
481 | - } |
|
55 | + /** @var FederatedShareProvider */ |
|
56 | + private $federatedShareProvider; |
|
57 | + |
|
58 | + /** @var IDBConnection */ |
|
59 | + private $connection; |
|
60 | + |
|
61 | + /** @var Share\IManager */ |
|
62 | + private $shareManager; |
|
63 | + |
|
64 | + /** @var Notifications */ |
|
65 | + private $notifications; |
|
66 | + |
|
67 | + /** @var AddressHandler */ |
|
68 | + private $addressHandler; |
|
69 | + |
|
70 | + /** @var IUserManager */ |
|
71 | + private $userManager; |
|
72 | + |
|
73 | + /** @var string */ |
|
74 | + private $shareTable = 'share'; |
|
75 | + |
|
76 | + /** @var ICloudIdManager */ |
|
77 | + private $cloudIdManager; |
|
78 | + |
|
79 | + /** @var ILogger */ |
|
80 | + private $logger; |
|
81 | + |
|
82 | + /** @var ICloudFederationFactory */ |
|
83 | + private $cloudFederationFactory; |
|
84 | + |
|
85 | + /** @var ICloudFederationProviderManager */ |
|
86 | + private $cloudFederationProviderManager; |
|
87 | + |
|
88 | + /** |
|
89 | + * Server2Server constructor. |
|
90 | + * |
|
91 | + * @param string $appName |
|
92 | + * @param IRequest $request |
|
93 | + * @param FederatedShareProvider $federatedShareProvider |
|
94 | + * @param IDBConnection $connection |
|
95 | + * @param Share\IManager $shareManager |
|
96 | + * @param Notifications $notifications |
|
97 | + * @param AddressHandler $addressHandler |
|
98 | + * @param IUserManager $userManager |
|
99 | + * @param ICloudIdManager $cloudIdManager |
|
100 | + * @param ILogger $logger |
|
101 | + * @param ICloudFederationFactory $cloudFederationFactory |
|
102 | + * @param ICloudFederationProviderManager $cloudFederationProviderManager |
|
103 | + */ |
|
104 | + public function __construct($appName, |
|
105 | + IRequest $request, |
|
106 | + FederatedShareProvider $federatedShareProvider, |
|
107 | + IDBConnection $connection, |
|
108 | + Share\IManager $shareManager, |
|
109 | + Notifications $notifications, |
|
110 | + AddressHandler $addressHandler, |
|
111 | + IUserManager $userManager, |
|
112 | + ICloudIdManager $cloudIdManager, |
|
113 | + ILogger $logger, |
|
114 | + ICloudFederationFactory $cloudFederationFactory, |
|
115 | + ICloudFederationProviderManager $cloudFederationProviderManager |
|
116 | + ) { |
|
117 | + parent::__construct($appName, $request); |
|
118 | + |
|
119 | + $this->federatedShareProvider = $federatedShareProvider; |
|
120 | + $this->connection = $connection; |
|
121 | + $this->shareManager = $shareManager; |
|
122 | + $this->notifications = $notifications; |
|
123 | + $this->addressHandler = $addressHandler; |
|
124 | + $this->userManager = $userManager; |
|
125 | + $this->cloudIdManager = $cloudIdManager; |
|
126 | + $this->logger = $logger; |
|
127 | + $this->cloudFederationFactory = $cloudFederationFactory; |
|
128 | + $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * @NoCSRFRequired |
|
133 | + * @PublicPage |
|
134 | + * |
|
135 | + * create a new share |
|
136 | + * |
|
137 | + * @return Http\DataResponse |
|
138 | + * @throws OCSException |
|
139 | + */ |
|
140 | + public function createShare() { |
|
141 | + |
|
142 | + $remote = isset($_POST['remote']) ? $_POST['remote'] : null; |
|
143 | + $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
144 | + $name = isset($_POST['name']) ? $_POST['name'] : null; |
|
145 | + $owner = isset($_POST['owner']) ? $_POST['owner'] : null; |
|
146 | + $sharedBy = isset($_POST['sharedBy']) ? $_POST['sharedBy'] : null; |
|
147 | + $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null; |
|
148 | + $remoteId = isset($_POST['remoteId']) ? (int)$_POST['remoteId'] : null; |
|
149 | + $sharedByFederatedId = isset($_POST['sharedByFederatedId']) ? $_POST['sharedByFederatedId'] : null; |
|
150 | + $ownerFederatedId = isset($_POST['ownerFederatedId']) ? $_POST['ownerFederatedId'] : null; |
|
151 | + |
|
152 | + if ($ownerFederatedId === null) { |
|
153 | + $ownerFederatedId = $this->cloudIdManager->getCloudId($owner, $this->cleanupRemote($remote))->getId(); |
|
154 | + } |
|
155 | + // if the owner of the share and the initiator are the same user |
|
156 | + // we also complete the federated share ID for the initiator |
|
157 | + if ($sharedByFederatedId === null && $owner === $sharedBy) { |
|
158 | + $sharedByFederatedId = $ownerFederatedId; |
|
159 | + } |
|
160 | + |
|
161 | + $share = $this->cloudFederationFactory->getCloudFederationShare( |
|
162 | + $shareWith, |
|
163 | + $name, |
|
164 | + '', |
|
165 | + $remoteId, |
|
166 | + $ownerFederatedId, |
|
167 | + $owner, |
|
168 | + $sharedByFederatedId, |
|
169 | + $sharedBy, |
|
170 | + $token, |
|
171 | + 'user', |
|
172 | + 'file' |
|
173 | + ); |
|
174 | + |
|
175 | + try { |
|
176 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
177 | + $provider->shareReceived($share); |
|
178 | + } catch (ProviderDoesNotExistsException $e) { |
|
179 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
180 | + } catch (ProviderCouldNotAddShareException $e) { |
|
181 | + throw new OCSException($e->getMessage(), 400); |
|
182 | + } catch (\Exception $e) { |
|
183 | + throw new OCSException('internal server error, was not able to add share from ' . $remote, 500); |
|
184 | + } |
|
185 | + |
|
186 | + return new Http\DataResponse(); |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * @NoCSRFRequired |
|
191 | + * @PublicPage |
|
192 | + * |
|
193 | + * create re-share on behalf of another user |
|
194 | + * |
|
195 | + * @param int $id |
|
196 | + * @return Http\DataResponse |
|
197 | + * @throws OCSBadRequestException |
|
198 | + * @throws OCSException |
|
199 | + * @throws OCSForbiddenException |
|
200 | + */ |
|
201 | + public function reShare($id) { |
|
202 | + |
|
203 | + $token = $this->request->getParam('token', null); |
|
204 | + $shareWith = $this->request->getParam('shareWith', null); |
|
205 | + $permission = (int)$this->request->getParam('permission', null); |
|
206 | + $remoteId = (int)$this->request->getParam('remoteId', null); |
|
207 | + |
|
208 | + if ($id === null || |
|
209 | + $token === null || |
|
210 | + $shareWith === null || |
|
211 | + $permission === null || |
|
212 | + $remoteId === null |
|
213 | + ) { |
|
214 | + throw new OCSBadRequestException(); |
|
215 | + } |
|
216 | + |
|
217 | + $notification = [ |
|
218 | + 'sharedSecret' => $token, |
|
219 | + 'shareWith' => $shareWith, |
|
220 | + 'senderId' => $remoteId, |
|
221 | + 'message' => 'Recipient of a share ask the owner to reshare the file' |
|
222 | + ]; |
|
223 | + |
|
224 | + try { |
|
225 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
226 | + list($newToken, $localId) = $provider->notificationReceived('REQUEST_RESHARE', $id, $notification); |
|
227 | + return new Http\DataResponse([ |
|
228 | + 'token' => $newToken, |
|
229 | + 'remoteId' => $localId |
|
230 | + ]); |
|
231 | + } catch (ProviderDoesNotExistsException $e) { |
|
232 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
233 | + } catch (ShareNotFound $e) { |
|
234 | + $this->logger->debug('Share not found: ' . $e->getMessage()); |
|
235 | + } catch (\Exception $e) { |
|
236 | + $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); |
|
237 | + } |
|
238 | + |
|
239 | + throw new OCSBadRequestException(); |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * @NoCSRFRequired |
|
245 | + * @PublicPage |
|
246 | + * |
|
247 | + * accept server-to-server share |
|
248 | + * |
|
249 | + * @param int $id |
|
250 | + * @return Http\DataResponse |
|
251 | + * @throws OCSException |
|
252 | + * @throws ShareNotFound |
|
253 | + * @throws \OC\HintException |
|
254 | + */ |
|
255 | + public function acceptShare($id) { |
|
256 | + |
|
257 | + $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
258 | + |
|
259 | + $notification = [ |
|
260 | + 'sharedSecret' => $token, |
|
261 | + 'message' => 'Recipient accept the share' |
|
262 | + ]; |
|
263 | + |
|
264 | + try { |
|
265 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
266 | + $provider->notificationReceived('SHARE_ACCEPTED', $id, $notification); |
|
267 | + } catch (ProviderDoesNotExistsException $e) { |
|
268 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
269 | + } catch (ShareNotFound $e) { |
|
270 | + $this->logger->debug('Share not found: ' . $e->getMessage()); |
|
271 | + } catch (\Exception $e) { |
|
272 | + $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); |
|
273 | + } |
|
274 | + |
|
275 | + return new Http\DataResponse(); |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * @NoCSRFRequired |
|
280 | + * @PublicPage |
|
281 | + * |
|
282 | + * decline server-to-server share |
|
283 | + * |
|
284 | + * @param int $id |
|
285 | + * @return Http\DataResponse |
|
286 | + * @throws OCSException |
|
287 | + */ |
|
288 | + public function declineShare($id) { |
|
289 | + |
|
290 | + $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
291 | + |
|
292 | + $notification = [ |
|
293 | + 'sharedSecret' => $token, |
|
294 | + 'message' => 'Recipient declined the share' |
|
295 | + ]; |
|
296 | + |
|
297 | + try { |
|
298 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
299 | + $provider->notificationReceived('SHARE_DECLINED', $id, $notification); |
|
300 | + } catch (ProviderDoesNotExistsException $e) { |
|
301 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
302 | + } catch (ShareNotFound $e) { |
|
303 | + $this->logger->debug('Share not found: ' . $e->getMessage()); |
|
304 | + } catch (\Exception $e) { |
|
305 | + $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); |
|
306 | + } |
|
307 | + |
|
308 | + return new Http\DataResponse(); |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * @NoCSRFRequired |
|
313 | + * @PublicPage |
|
314 | + * |
|
315 | + * remove server-to-server share if it was unshared by the owner |
|
316 | + * |
|
317 | + * @param int $id |
|
318 | + * @return Http\DataResponse |
|
319 | + * @throws OCSException |
|
320 | + */ |
|
321 | + public function unshare($id) { |
|
322 | + |
|
323 | + if (!$this->isS2SEnabled()) { |
|
324 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
325 | + } |
|
326 | + |
|
327 | + $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
328 | + |
|
329 | + try { |
|
330 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
331 | + $notification = ['sharedSecret' => $token]; |
|
332 | + $provider->notificationReceived('SHARE_UNSHARED', $id, $notification); |
|
333 | + } catch (\Exception $e) { |
|
334 | + $this->logger->debug('processing unshare notification failed: ' . $e->getMessage()); |
|
335 | + } |
|
336 | + |
|
337 | + return new Http\DataResponse(); |
|
338 | + } |
|
339 | + |
|
340 | + private function cleanupRemote($remote) { |
|
341 | + $remote = substr($remote, strpos($remote, '://') + 3); |
|
342 | + |
|
343 | + return rtrim($remote, '/'); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * @NoCSRFRequired |
|
349 | + * @PublicPage |
|
350 | + * |
|
351 | + * federated share was revoked, either by the owner or the re-sharer |
|
352 | + * |
|
353 | + * @param int $id |
|
354 | + * @return Http\DataResponse |
|
355 | + * @throws OCSBadRequestException |
|
356 | + */ |
|
357 | + public function revoke($id) { |
|
358 | + |
|
359 | + $token = $this->request->getParam('token'); |
|
360 | + |
|
361 | + try { |
|
362 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
363 | + $notification = ['sharedSecret' => $token]; |
|
364 | + $provider->notificationReceived('RESHARE_UNDO', $id, $notification); |
|
365 | + return new Http\DataResponse(); |
|
366 | + } catch (\Exception $e) { |
|
367 | + throw new OCSBadRequestException(); |
|
368 | + } |
|
369 | + |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * check if server-to-server sharing is enabled |
|
374 | + * |
|
375 | + * @param bool $incoming |
|
376 | + * @return bool |
|
377 | + */ |
|
378 | + private function isS2SEnabled($incoming = false) { |
|
379 | + |
|
380 | + $result = \OCP\App::isEnabled('files_sharing'); |
|
381 | + |
|
382 | + if ($incoming) { |
|
383 | + $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled(); |
|
384 | + } else { |
|
385 | + $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
386 | + } |
|
387 | + |
|
388 | + return $result; |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * @NoCSRFRequired |
|
393 | + * @PublicPage |
|
394 | + * |
|
395 | + * update share information to keep federated re-shares in sync |
|
396 | + * |
|
397 | + * @param int $id |
|
398 | + * @return Http\DataResponse |
|
399 | + * @throws OCSBadRequestException |
|
400 | + */ |
|
401 | + public function updatePermissions($id) { |
|
402 | + $token = $this->request->getParam('token', null); |
|
403 | + $ncPermissions = $this->request->getParam('permissions', null); |
|
404 | + |
|
405 | + try { |
|
406 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
407 | + $ocmPermissions = $this->ncPermissions2ocmPermissions((int)$ncPermissions); |
|
408 | + $notification = ['sharedSecret' => $token, 'permission' => $ocmPermissions]; |
|
409 | + $provider->notificationReceived('RESHARE_CHANGE_PERMISSION', $id, $notification); |
|
410 | + } catch (\Exception $e) { |
|
411 | + $this->logger->debug($e->getMessage()); |
|
412 | + throw new OCSBadRequestException(); |
|
413 | + } |
|
414 | + |
|
415 | + return new Http\DataResponse(); |
|
416 | + } |
|
417 | + |
|
418 | + /** |
|
419 | + * translate Nextcloud permissions to OCM Permissions |
|
420 | + * |
|
421 | + * @param $ncPermissions |
|
422 | + * @return array |
|
423 | + */ |
|
424 | + protected function ncPermissions2ocmPermissions($ncPermissions) { |
|
425 | + |
|
426 | + $ocmPermissions = []; |
|
427 | + |
|
428 | + if ($ncPermissions & Constants::PERMISSION_SHARE) { |
|
429 | + $ocmPermissions[] = 'share'; |
|
430 | + } |
|
431 | + |
|
432 | + if ($ncPermissions & Constants::PERMISSION_READ) { |
|
433 | + $ocmPermissions[] = 'read'; |
|
434 | + } |
|
435 | + |
|
436 | + if (($ncPermissions & Constants::PERMISSION_CREATE) || |
|
437 | + ($ncPermissions & Constants::PERMISSION_UPDATE)) { |
|
438 | + $ocmPermissions[] = 'write'; |
|
439 | + } |
|
440 | + |
|
441 | + return $ocmPermissions; |
|
442 | + |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * @NoCSRFRequired |
|
447 | + * @PublicPage |
|
448 | + * |
|
449 | + * change the owner of a server-to-server share |
|
450 | + * |
|
451 | + * @param int $id |
|
452 | + * @return Http\DataResponse |
|
453 | + * @throws \InvalidArgumentException |
|
454 | + * @throws OCSException |
|
455 | + */ |
|
456 | + public function move($id) { |
|
457 | + |
|
458 | + if (!$this->isS2SEnabled()) { |
|
459 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
460 | + } |
|
461 | + |
|
462 | + $token = $this->request->getParam('token'); |
|
463 | + $remote = $this->request->getParam('remote'); |
|
464 | + $newRemoteId = $this->request->getParam('remote_id', $id); |
|
465 | + $cloudId = $this->cloudIdManager->resolveCloudId($remote); |
|
466 | + |
|
467 | + $qb = $this->connection->getQueryBuilder(); |
|
468 | + $query = $qb->update('share_external') |
|
469 | + ->set('remote', $qb->createNamedParameter($cloudId->getRemote())) |
|
470 | + ->set('owner', $qb->createNamedParameter($cloudId->getUser())) |
|
471 | + ->set('remote_id', $qb->createNamedParameter($newRemoteId)) |
|
472 | + ->where($qb->expr()->eq('remote_id', $qb->createNamedParameter($id))) |
|
473 | + ->andWhere($qb->expr()->eq('share_token', $qb->createNamedParameter($token))); |
|
474 | + $affected = $query->execute(); |
|
475 | + |
|
476 | + if ($affected > 0) { |
|
477 | + return new Http\DataResponse(['remote' => $cloudId->getRemote(), 'owner' => $cloudId->getUser()]); |
|
478 | + } else { |
|
479 | + throw new OCSBadRequestException('Share not found or token invalid'); |
|
480 | + } |
|
481 | + } |
|
482 | 482 | } |
@@ -39,49 +39,49 @@ |
||
39 | 39 | |
40 | 40 | interface ICloudFederationProvider { |
41 | 41 | |
42 | - /** |
|
43 | - * get the name of the share type, handled by this provider |
|
44 | - * |
|
45 | - * @return string |
|
46 | - * |
|
47 | - * @since 14.0.0 |
|
48 | - */ |
|
49 | - public function getShareType(); |
|
42 | + /** |
|
43 | + * get the name of the share type, handled by this provider |
|
44 | + * |
|
45 | + * @return string |
|
46 | + * |
|
47 | + * @since 14.0.0 |
|
48 | + */ |
|
49 | + public function getShareType(); |
|
50 | 50 | |
51 | - /** |
|
52 | - * share received from another server |
|
53 | - * |
|
54 | - * @param ICloudFederationShare $share |
|
55 | - * @return string provider specific unique ID of the share |
|
56 | - * |
|
57 | - * @throws ProviderCouldNotAddShareException |
|
58 | - * |
|
59 | - * @since 14.0.0 |
|
60 | - */ |
|
61 | - public function shareReceived(ICloudFederationShare $share); |
|
51 | + /** |
|
52 | + * share received from another server |
|
53 | + * |
|
54 | + * @param ICloudFederationShare $share |
|
55 | + * @return string provider specific unique ID of the share |
|
56 | + * |
|
57 | + * @throws ProviderCouldNotAddShareException |
|
58 | + * |
|
59 | + * @since 14.0.0 |
|
60 | + */ |
|
61 | + public function shareReceived(ICloudFederationShare $share); |
|
62 | 62 | |
63 | - /** |
|
64 | - * notification received from another server |
|
65 | - * |
|
66 | - * @param string $notificationType (e.g SHARE_ACCEPTED) |
|
67 | - * @param string $providerId share ID |
|
68 | - * @param array $notification provider specific notification |
|
69 | - * @return array $data send back to sender |
|
70 | - * |
|
71 | - * @throws ShareNotFound |
|
72 | - * @throws ActionNotSupportedException |
|
73 | - * @throws BadRequestException |
|
74 | - * @throws AuthenticationFailedException |
|
75 | - * |
|
76 | - * @since 14.0.0 |
|
77 | - */ |
|
78 | - public function notificationReceived($notificationType, $providerId, array $notification); |
|
63 | + /** |
|
64 | + * notification received from another server |
|
65 | + * |
|
66 | + * @param string $notificationType (e.g SHARE_ACCEPTED) |
|
67 | + * @param string $providerId share ID |
|
68 | + * @param array $notification provider specific notification |
|
69 | + * @return array $data send back to sender |
|
70 | + * |
|
71 | + * @throws ShareNotFound |
|
72 | + * @throws ActionNotSupportedException |
|
73 | + * @throws BadRequestException |
|
74 | + * @throws AuthenticationFailedException |
|
75 | + * |
|
76 | + * @since 14.0.0 |
|
77 | + */ |
|
78 | + public function notificationReceived($notificationType, $providerId, array $notification); |
|
79 | 79 | |
80 | - /** |
|
81 | - * get the supported share types, e.g. "user", "group", etc. |
|
82 | - * |
|
83 | - * @return array |
|
84 | - */ |
|
85 | - public function getSupportedShareTypes(); |
|
80 | + /** |
|
81 | + * get the supported share types, e.g. "user", "group", etc. |
|
82 | + * |
|
83 | + * @return array |
|
84 | + */ |
|
85 | + public function getSupportedShareTypes(); |
|
86 | 86 | |
87 | 87 | } |
@@ -32,76 +32,76 @@ |
||
32 | 32 | */ |
33 | 33 | interface ICloudFederationProviderManager { |
34 | 34 | |
35 | - /** |
|
36 | - * Registers an callback function which must return an cloud federation provider |
|
37 | - * |
|
38 | - * @param string $resourceType which resource type does the provider handles |
|
39 | - * @param string $displayName user facing name of the federated share provider |
|
40 | - * @param callable $callback |
|
41 | - * @throws Exceptions\ProviderAlreadyExistsException |
|
42 | - * |
|
43 | - * @since 14.0.0 |
|
44 | - */ |
|
45 | - public function addCloudFederationProvider($resourceType, $displayName, callable $callback); |
|
35 | + /** |
|
36 | + * Registers an callback function which must return an cloud federation provider |
|
37 | + * |
|
38 | + * @param string $resourceType which resource type does the provider handles |
|
39 | + * @param string $displayName user facing name of the federated share provider |
|
40 | + * @param callable $callback |
|
41 | + * @throws Exceptions\ProviderAlreadyExistsException |
|
42 | + * |
|
43 | + * @since 14.0.0 |
|
44 | + */ |
|
45 | + public function addCloudFederationProvider($resourceType, $displayName, callable $callback); |
|
46 | 46 | |
47 | - /** |
|
48 | - * remove cloud federation provider |
|
49 | - * |
|
50 | - * @param string $resourceType |
|
51 | - * |
|
52 | - * @since 14.0.0 |
|
53 | - */ |
|
54 | - public function removeCloudFederationProvider($resourceType); |
|
47 | + /** |
|
48 | + * remove cloud federation provider |
|
49 | + * |
|
50 | + * @param string $resourceType |
|
51 | + * |
|
52 | + * @since 14.0.0 |
|
53 | + */ |
|
54 | + public function removeCloudFederationProvider($resourceType); |
|
55 | 55 | |
56 | - /** |
|
57 | - * get a list of all cloudFederationProviders |
|
58 | - * |
|
59 | - * @return array [resourceType => ['resourceType' => $resourceType, 'displayName' => $displayName, 'callback' => callback]] |
|
60 | - * |
|
61 | - * @since 14.0.0 |
|
62 | - */ |
|
63 | - public function getAllCloudFederationProviders(); |
|
56 | + /** |
|
57 | + * get a list of all cloudFederationProviders |
|
58 | + * |
|
59 | + * @return array [resourceType => ['resourceType' => $resourceType, 'displayName' => $displayName, 'callback' => callback]] |
|
60 | + * |
|
61 | + * @since 14.0.0 |
|
62 | + */ |
|
63 | + public function getAllCloudFederationProviders(); |
|
64 | 64 | |
65 | - /** |
|
66 | - * get a specific cloud federation provider |
|
67 | - * |
|
68 | - * @param string $resourceType |
|
69 | - * @return ICloudFederationProvider |
|
70 | - * @throws Exceptions\ProviderDoesNotExistsException; |
|
71 | - * |
|
72 | - * @since 14.0.0 |
|
73 | - */ |
|
74 | - public function getCloudFederationProvider($resourceType); |
|
65 | + /** |
|
66 | + * get a specific cloud federation provider |
|
67 | + * |
|
68 | + * @param string $resourceType |
|
69 | + * @return ICloudFederationProvider |
|
70 | + * @throws Exceptions\ProviderDoesNotExistsException; |
|
71 | + * |
|
72 | + * @since 14.0.0 |
|
73 | + */ |
|
74 | + public function getCloudFederationProvider($resourceType); |
|
75 | 75 | |
76 | - /** |
|
77 | - * send federated share |
|
78 | - * |
|
79 | - * @param ICloudFederationShare $share |
|
80 | - * @return bool |
|
81 | - * |
|
82 | - * @since 14.0.0 |
|
83 | - */ |
|
84 | - public function sendShare(ICloudFederationShare $share); |
|
76 | + /** |
|
77 | + * send federated share |
|
78 | + * |
|
79 | + * @param ICloudFederationShare $share |
|
80 | + * @return bool |
|
81 | + * |
|
82 | + * @since 14.0.0 |
|
83 | + */ |
|
84 | + public function sendShare(ICloudFederationShare $share); |
|
85 | 85 | |
86 | - /** |
|
87 | - * send notification about existing share |
|
88 | - * |
|
89 | - * @param string $url |
|
90 | - * @param ICloudFederationNotification $notification |
|
91 | - * @return mixed |
|
92 | - * |
|
93 | - * @since 14.0.0 |
|
94 | - */ |
|
95 | - public function sendNotification($url, ICloudFederationNotification $notification); |
|
86 | + /** |
|
87 | + * send notification about existing share |
|
88 | + * |
|
89 | + * @param string $url |
|
90 | + * @param ICloudFederationNotification $notification |
|
91 | + * @return mixed |
|
92 | + * |
|
93 | + * @since 14.0.0 |
|
94 | + */ |
|
95 | + public function sendNotification($url, ICloudFederationNotification $notification); |
|
96 | 96 | |
97 | - /** |
|
98 | - * check if the new cloud federation API is ready to be used |
|
99 | - * |
|
100 | - * @return bool |
|
101 | - * |
|
102 | - * @since 14.0.0 |
|
103 | - */ |
|
104 | - public function isReady(); |
|
97 | + /** |
|
98 | + * check if the new cloud federation API is ready to be used |
|
99 | + * |
|
100 | + * @return bool |
|
101 | + * |
|
102 | + * @since 14.0.0 |
|
103 | + */ |
|
104 | + public function isReady(); |
|
105 | 105 | |
106 | 106 | |
107 | 107 | } |
@@ -42,189 +42,189 @@ |
||
42 | 42 | */ |
43 | 43 | class CloudFederationProviderManager implements ICloudFederationProviderManager { |
44 | 44 | |
45 | - /** @var array list of available cloud federation providers */ |
|
46 | - private $cloudFederationProvider; |
|
47 | - |
|
48 | - /** @var IAppManager */ |
|
49 | - private $appManager; |
|
50 | - |
|
51 | - /** @var IClientService */ |
|
52 | - private $httpClientService; |
|
53 | - |
|
54 | - /** @var ICloudIdManager */ |
|
55 | - private $cloudIdManager; |
|
56 | - |
|
57 | - /** @var ILogger */ |
|
58 | - private $logger; |
|
59 | - |
|
60 | - private $supportedAPIVersion = '1.0-proposal1'; |
|
61 | - |
|
62 | - /** |
|
63 | - * CloudFederationProviderManager constructor. |
|
64 | - * |
|
65 | - * @param IAppManager $appManager |
|
66 | - * @param IClientService $httpClientService |
|
67 | - * @param ICloudIdManager $cloudIdManager |
|
68 | - * @param ILogger $logger |
|
69 | - */ |
|
70 | - public function __construct(IAppManager $appManager, |
|
71 | - IClientService $httpClientService, |
|
72 | - ICloudIdManager $cloudIdManager, |
|
73 | - ILogger $logger) { |
|
74 | - $this->cloudFederationProvider= []; |
|
75 | - $this->appManager = $appManager; |
|
76 | - $this->httpClientService = $httpClientService; |
|
77 | - $this->cloudIdManager = $cloudIdManager; |
|
78 | - $this->logger = $logger; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * Registers an callback function which must return an cloud federation provider |
|
84 | - * |
|
85 | - * @param string $resourceType which resource type does the provider handles |
|
86 | - * @param string $displayName user facing name of the federated share provider |
|
87 | - * @param callable $callback |
|
88 | - */ |
|
89 | - public function addCloudFederationProvider($resourceType, $displayName, callable $callback) { |
|
90 | - $this->cloudFederationProvider[$resourceType] = [ |
|
91 | - 'resourceType' => $resourceType, |
|
92 | - 'displayName' => $displayName, |
|
93 | - 'callback' => $callback, |
|
94 | - ]; |
|
95 | - |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * remove cloud federation provider |
|
100 | - * |
|
101 | - * @param string $providerId |
|
102 | - */ |
|
103 | - public function removeCloudFederationProvider($providerId) { |
|
104 | - unset($this->cloudFederationProvider[$providerId]); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * get a list of all cloudFederationProviders |
|
109 | - * |
|
110 | - * @return array [resourceType => ['resourceType' => $resourceType, 'displayName' => $displayName, 'callback' => callback]] |
|
111 | - */ |
|
112 | - public function getAllCloudFederationProviders() { |
|
113 | - return $this->cloudFederationProvider; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * get a specific cloud federation provider |
|
118 | - * |
|
119 | - * @param string $resourceType |
|
120 | - * @return ICloudFederationProvider |
|
121 | - * @throws ProviderDoesNotExistsException |
|
122 | - */ |
|
123 | - public function getCloudFederationProvider($resourceType) { |
|
124 | - if (isset($this->cloudFederationProvider[$resourceType])) { |
|
125 | - return call_user_func($this->cloudFederationProvider[$resourceType]['callback']); |
|
126 | - } else { |
|
127 | - throw new ProviderDoesNotExistsException($resourceType); |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - public function sendShare(ICloudFederationShare $share) { |
|
132 | - $cloudID = $this->cloudIdManager->resolveCloudId($share->getShareWith()); |
|
133 | - $ocmEndPoint = $this->getOCMEndPoint($cloudID->getRemote()); |
|
134 | - |
|
135 | - if (empty($ocmEndPoint)) { |
|
136 | - return false; |
|
137 | - } |
|
138 | - |
|
139 | - $client = $this->httpClientService->newClient(); |
|
140 | - try { |
|
141 | - $response = $client->post($ocmEndPoint . '/shares', [ |
|
142 | - 'body' => $share->getShare(), |
|
143 | - 'timeout' => 10, |
|
144 | - 'connect_timeout' => 10, |
|
145 | - ]); |
|
146 | - |
|
147 | - if ($response->getStatusCode() === Http::STATUS_CREATED) { |
|
148 | - return true; |
|
149 | - } |
|
150 | - |
|
151 | - } catch (\Exception $e) { |
|
152 | - // if flat re-sharing is not supported by the remote server |
|
153 | - // we re-throw the exception and fall back to the old behaviour. |
|
154 | - // (flat re-shares has been introduced in Nextcloud 9.1) |
|
155 | - if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
156 | - throw $e; |
|
157 | - } |
|
158 | - } |
|
159 | - |
|
160 | - return false; |
|
161 | - |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * @param string $url |
|
166 | - * @param ICloudFederationNotification $notification |
|
167 | - * @return mixed |
|
168 | - */ |
|
169 | - public function sendNotification($url, ICloudFederationNotification $notification) { |
|
170 | - $ocmEndPoint = $this->getOCMEndPoint($url); |
|
171 | - |
|
172 | - if (empty($ocmEndPoint)) { |
|
173 | - return false; |
|
174 | - } |
|
175 | - |
|
176 | - $client = $this->httpClientService->newClient(); |
|
177 | - try { |
|
178 | - $response = $client->post($ocmEndPoint . '/notifications', [ |
|
179 | - 'body' => $notification->getMessage(), |
|
180 | - 'timeout' => 10, |
|
181 | - 'connect_timeout' => 10, |
|
182 | - ]); |
|
183 | - if ($response->getStatusCode() === Http::STATUS_CREATED) { |
|
184 | - $result = json_decode($response->getBody(), true); |
|
185 | - return (is_array($result)) ? $result : []; |
|
186 | - } |
|
187 | - } catch (\Exception $e) { |
|
188 | - // log the error and return false |
|
189 | - $this->logger->error('error while sending notification for federated share: ' . $e->getMessage()); |
|
190 | - } |
|
191 | - |
|
192 | - return false; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * check if the new cloud federation API is ready to be used |
|
197 | - * |
|
198 | - * @return bool |
|
199 | - */ |
|
200 | - public function isReady() { |
|
201 | - return $this->appManager->isEnabledForUser('cloud_federation_api'); |
|
202 | - } |
|
203 | - /** |
|
204 | - * check if server supports the new OCM api and ask for the correct end-point |
|
205 | - * |
|
206 | - * @param string $url full base URL of the cloud server |
|
207 | - * @return string |
|
208 | - */ |
|
209 | - protected function getOCMEndPoint($url) { |
|
210 | - $client = $this->httpClientService->newClient(); |
|
211 | - try { |
|
212 | - $response = $client->get($url . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]); |
|
213 | - } catch (\Exception $e) { |
|
214 | - return ''; |
|
215 | - } |
|
216 | - |
|
217 | - $result = $response->getBody(); |
|
218 | - $result = json_decode($result, true); |
|
219 | - |
|
220 | - $supportedVersion = isset($result['apiVersion']) && $result['apiVersion'] === $this->supportedAPIVersion; |
|
221 | - |
|
222 | - if (isset($result['endPoint']) && $supportedVersion) { |
|
223 | - return $result['endPoint']; |
|
224 | - } |
|
225 | - |
|
226 | - return ''; |
|
227 | - } |
|
45 | + /** @var array list of available cloud federation providers */ |
|
46 | + private $cloudFederationProvider; |
|
47 | + |
|
48 | + /** @var IAppManager */ |
|
49 | + private $appManager; |
|
50 | + |
|
51 | + /** @var IClientService */ |
|
52 | + private $httpClientService; |
|
53 | + |
|
54 | + /** @var ICloudIdManager */ |
|
55 | + private $cloudIdManager; |
|
56 | + |
|
57 | + /** @var ILogger */ |
|
58 | + private $logger; |
|
59 | + |
|
60 | + private $supportedAPIVersion = '1.0-proposal1'; |
|
61 | + |
|
62 | + /** |
|
63 | + * CloudFederationProviderManager constructor. |
|
64 | + * |
|
65 | + * @param IAppManager $appManager |
|
66 | + * @param IClientService $httpClientService |
|
67 | + * @param ICloudIdManager $cloudIdManager |
|
68 | + * @param ILogger $logger |
|
69 | + */ |
|
70 | + public function __construct(IAppManager $appManager, |
|
71 | + IClientService $httpClientService, |
|
72 | + ICloudIdManager $cloudIdManager, |
|
73 | + ILogger $logger) { |
|
74 | + $this->cloudFederationProvider= []; |
|
75 | + $this->appManager = $appManager; |
|
76 | + $this->httpClientService = $httpClientService; |
|
77 | + $this->cloudIdManager = $cloudIdManager; |
|
78 | + $this->logger = $logger; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * Registers an callback function which must return an cloud federation provider |
|
84 | + * |
|
85 | + * @param string $resourceType which resource type does the provider handles |
|
86 | + * @param string $displayName user facing name of the federated share provider |
|
87 | + * @param callable $callback |
|
88 | + */ |
|
89 | + public function addCloudFederationProvider($resourceType, $displayName, callable $callback) { |
|
90 | + $this->cloudFederationProvider[$resourceType] = [ |
|
91 | + 'resourceType' => $resourceType, |
|
92 | + 'displayName' => $displayName, |
|
93 | + 'callback' => $callback, |
|
94 | + ]; |
|
95 | + |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * remove cloud federation provider |
|
100 | + * |
|
101 | + * @param string $providerId |
|
102 | + */ |
|
103 | + public function removeCloudFederationProvider($providerId) { |
|
104 | + unset($this->cloudFederationProvider[$providerId]); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * get a list of all cloudFederationProviders |
|
109 | + * |
|
110 | + * @return array [resourceType => ['resourceType' => $resourceType, 'displayName' => $displayName, 'callback' => callback]] |
|
111 | + */ |
|
112 | + public function getAllCloudFederationProviders() { |
|
113 | + return $this->cloudFederationProvider; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * get a specific cloud federation provider |
|
118 | + * |
|
119 | + * @param string $resourceType |
|
120 | + * @return ICloudFederationProvider |
|
121 | + * @throws ProviderDoesNotExistsException |
|
122 | + */ |
|
123 | + public function getCloudFederationProvider($resourceType) { |
|
124 | + if (isset($this->cloudFederationProvider[$resourceType])) { |
|
125 | + return call_user_func($this->cloudFederationProvider[$resourceType]['callback']); |
|
126 | + } else { |
|
127 | + throw new ProviderDoesNotExistsException($resourceType); |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + public function sendShare(ICloudFederationShare $share) { |
|
132 | + $cloudID = $this->cloudIdManager->resolveCloudId($share->getShareWith()); |
|
133 | + $ocmEndPoint = $this->getOCMEndPoint($cloudID->getRemote()); |
|
134 | + |
|
135 | + if (empty($ocmEndPoint)) { |
|
136 | + return false; |
|
137 | + } |
|
138 | + |
|
139 | + $client = $this->httpClientService->newClient(); |
|
140 | + try { |
|
141 | + $response = $client->post($ocmEndPoint . '/shares', [ |
|
142 | + 'body' => $share->getShare(), |
|
143 | + 'timeout' => 10, |
|
144 | + 'connect_timeout' => 10, |
|
145 | + ]); |
|
146 | + |
|
147 | + if ($response->getStatusCode() === Http::STATUS_CREATED) { |
|
148 | + return true; |
|
149 | + } |
|
150 | + |
|
151 | + } catch (\Exception $e) { |
|
152 | + // if flat re-sharing is not supported by the remote server |
|
153 | + // we re-throw the exception and fall back to the old behaviour. |
|
154 | + // (flat re-shares has been introduced in Nextcloud 9.1) |
|
155 | + if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
156 | + throw $e; |
|
157 | + } |
|
158 | + } |
|
159 | + |
|
160 | + return false; |
|
161 | + |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * @param string $url |
|
166 | + * @param ICloudFederationNotification $notification |
|
167 | + * @return mixed |
|
168 | + */ |
|
169 | + public function sendNotification($url, ICloudFederationNotification $notification) { |
|
170 | + $ocmEndPoint = $this->getOCMEndPoint($url); |
|
171 | + |
|
172 | + if (empty($ocmEndPoint)) { |
|
173 | + return false; |
|
174 | + } |
|
175 | + |
|
176 | + $client = $this->httpClientService->newClient(); |
|
177 | + try { |
|
178 | + $response = $client->post($ocmEndPoint . '/notifications', [ |
|
179 | + 'body' => $notification->getMessage(), |
|
180 | + 'timeout' => 10, |
|
181 | + 'connect_timeout' => 10, |
|
182 | + ]); |
|
183 | + if ($response->getStatusCode() === Http::STATUS_CREATED) { |
|
184 | + $result = json_decode($response->getBody(), true); |
|
185 | + return (is_array($result)) ? $result : []; |
|
186 | + } |
|
187 | + } catch (\Exception $e) { |
|
188 | + // log the error and return false |
|
189 | + $this->logger->error('error while sending notification for federated share: ' . $e->getMessage()); |
|
190 | + } |
|
191 | + |
|
192 | + return false; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * check if the new cloud federation API is ready to be used |
|
197 | + * |
|
198 | + * @return bool |
|
199 | + */ |
|
200 | + public function isReady() { |
|
201 | + return $this->appManager->isEnabledForUser('cloud_federation_api'); |
|
202 | + } |
|
203 | + /** |
|
204 | + * check if server supports the new OCM api and ask for the correct end-point |
|
205 | + * |
|
206 | + * @param string $url full base URL of the cloud server |
|
207 | + * @return string |
|
208 | + */ |
|
209 | + protected function getOCMEndPoint($url) { |
|
210 | + $client = $this->httpClientService->newClient(); |
|
211 | + try { |
|
212 | + $response = $client->get($url . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]); |
|
213 | + } catch (\Exception $e) { |
|
214 | + return ''; |
|
215 | + } |
|
216 | + |
|
217 | + $result = $response->getBody(); |
|
218 | + $result = json_decode($result, true); |
|
219 | + |
|
220 | + $supportedVersion = isset($result['apiVersion']) && $result['apiVersion'] === $this->supportedAPIVersion; |
|
221 | + |
|
222 | + if (isset($result['endPoint']) && $supportedVersion) { |
|
223 | + return $result['endPoint']; |
|
224 | + } |
|
225 | + |
|
226 | + return ''; |
|
227 | + } |
|
228 | 228 | |
229 | 229 | |
230 | 230 | } |
@@ -29,27 +29,27 @@ |
||
29 | 29 | |
30 | 30 | class Constants { |
31 | 31 | |
32 | - const SHARE_TYPE_USER = 0; |
|
33 | - const SHARE_TYPE_GROUP = 1; |
|
34 | - const SHARE_TYPE_LINK = 3; |
|
35 | - const SHARE_TYPE_EMAIL = 4; |
|
36 | - const SHARE_TYPE_CONTACT = 5; // ToDo Check if it is still in use otherwise remove it |
|
37 | - const SHARE_TYPE_REMOTE = 6; |
|
38 | - const SHARE_TYPE_CIRCLE = 7; |
|
39 | - const SHARE_TYPE_GUEST = 8; |
|
40 | - const SHARE_TYPE_REMOTE_GROUP = 9; |
|
32 | + const SHARE_TYPE_USER = 0; |
|
33 | + const SHARE_TYPE_GROUP = 1; |
|
34 | + const SHARE_TYPE_LINK = 3; |
|
35 | + const SHARE_TYPE_EMAIL = 4; |
|
36 | + const SHARE_TYPE_CONTACT = 5; // ToDo Check if it is still in use otherwise remove it |
|
37 | + const SHARE_TYPE_REMOTE = 6; |
|
38 | + const SHARE_TYPE_CIRCLE = 7; |
|
39 | + const SHARE_TYPE_GUEST = 8; |
|
40 | + const SHARE_TYPE_REMOTE_GROUP = 9; |
|
41 | 41 | |
42 | - const FORMAT_NONE = -1; |
|
43 | - const FORMAT_STATUSES = -2; |
|
44 | - const FORMAT_SOURCES = -3; // ToDo Check if it is still in use otherwise remove it |
|
42 | + const FORMAT_NONE = -1; |
|
43 | + const FORMAT_STATUSES = -2; |
|
44 | + const FORMAT_SOURCES = -3; // ToDo Check if it is still in use otherwise remove it |
|
45 | 45 | |
46 | - const RESPONSE_FORMAT = 'json'; // default resonse format for ocs calls |
|
46 | + const RESPONSE_FORMAT = 'json'; // default resonse format for ocs calls |
|
47 | 47 | |
48 | - const TOKEN_LENGTH = 15; // old (oc7) length is 32, keep token length in db at least that for compatibility |
|
48 | + const TOKEN_LENGTH = 15; // old (oc7) length is 32, keep token length in db at least that for compatibility |
|
49 | 49 | |
50 | - protected static $shareTypeUserAndGroups = -1; |
|
51 | - protected static $shareTypeGroupUserUnique = 2; |
|
52 | - protected static $backends = array(); |
|
53 | - protected static $backendTypes = array(); |
|
54 | - protected static $isResharingAllowed; |
|
50 | + protected static $shareTypeUserAndGroups = -1; |
|
51 | + protected static $shareTypeGroupUserUnique = 2; |
|
52 | + protected static $backends = array(); |
|
53 | + protected static $backendTypes = array(); |
|
54 | + protected static $isResharingAllowed; |
|
55 | 55 | } |
@@ -44,520 +44,520 @@ |
||
44 | 44 | use OCP\Share; |
45 | 45 | |
46 | 46 | class Manager { |
47 | - const STORAGE = '\OCA\Files_Sharing\External\Storage'; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - private $uid; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var IDBConnection |
|
56 | - */ |
|
57 | - private $connection; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var \OC\Files\Mount\Manager |
|
61 | - */ |
|
62 | - private $mountManager; |
|
63 | - |
|
64 | - /** |
|
65 | - * @var IStorageFactory |
|
66 | - */ |
|
67 | - private $storageLoader; |
|
68 | - |
|
69 | - /** |
|
70 | - * @var IClientService |
|
71 | - */ |
|
72 | - private $clientService; |
|
73 | - |
|
74 | - /** |
|
75 | - * @var IManager |
|
76 | - */ |
|
77 | - private $notificationManager; |
|
78 | - |
|
79 | - /** |
|
80 | - * @var IDiscoveryService |
|
81 | - */ |
|
82 | - private $discoveryService; |
|
83 | - |
|
84 | - /** @var ICloudFederationProviderManager */ |
|
85 | - private $cloudFederationProviderManager; |
|
86 | - |
|
87 | - /** @var ICloudFederationFactory */ |
|
88 | - private $cloudFederationFactory; |
|
89 | - |
|
90 | - /** |
|
91 | - * @param IDBConnection $connection |
|
92 | - * @param \OC\Files\Mount\Manager $mountManager |
|
93 | - * @param IStorageFactory $storageLoader |
|
94 | - * @param IClientService $clientService |
|
95 | - * @param IManager $notificationManager |
|
96 | - * @param IDiscoveryService $discoveryService |
|
97 | - * @param ICloudFederationProviderManager $cloudFederationProviderManager |
|
98 | - * @param ICloudFederationFactory $cloudFederationFactory |
|
99 | - * @param string $uid |
|
100 | - */ |
|
101 | - public function __construct(IDBConnection $connection, |
|
102 | - \OC\Files\Mount\Manager $mountManager, |
|
103 | - IStorageFactory $storageLoader, |
|
104 | - IClientService $clientService, |
|
105 | - IManager $notificationManager, |
|
106 | - IDiscoveryService $discoveryService, |
|
107 | - ICloudFederationProviderManager $cloudFederationProviderManager, |
|
108 | - ICloudFederationFactory $cloudFederationFactory, |
|
109 | - $uid) { |
|
110 | - $this->connection = $connection; |
|
111 | - $this->mountManager = $mountManager; |
|
112 | - $this->storageLoader = $storageLoader; |
|
113 | - $this->clientService = $clientService; |
|
114 | - $this->uid = $uid; |
|
115 | - $this->notificationManager = $notificationManager; |
|
116 | - $this->discoveryService = $discoveryService; |
|
117 | - $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
118 | - $this->cloudFederationFactory = $cloudFederationFactory; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * add new server-to-server share |
|
123 | - * |
|
124 | - * @param string $remote |
|
125 | - * @param string $token |
|
126 | - * @param string $password |
|
127 | - * @param string $name |
|
128 | - * @param string $owner |
|
129 | - * @param int $shareType |
|
130 | - * @param boolean $accepted |
|
131 | - * @param string $user |
|
132 | - * @param int $remoteId |
|
133 | - * @param int $parent |
|
134 | - * @return Mount|null |
|
135 | - * @throws \Doctrine\DBAL\DBALException |
|
136 | - */ |
|
137 | - public function addShare($remote, $token, $password, $name, $owner, $shareType, $accepted=false, $user = null, $remoteId = -1, $parent = -1) { |
|
138 | - |
|
139 | - $user = $user ? $user : $this->uid; |
|
140 | - $accepted = $accepted ? 1 : 0; |
|
141 | - $name = Filesystem::normalizePath('/' . $name); |
|
142 | - |
|
143 | - if (!$accepted) { |
|
144 | - // To avoid conflicts with the mount point generation later, |
|
145 | - // we only use a temporary mount point name here. The real |
|
146 | - // mount point name will be generated when accepting the share, |
|
147 | - // using the original share item name. |
|
148 | - $tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}'; |
|
149 | - $mountPoint = $tmpMountPointName; |
|
150 | - $hash = md5($tmpMountPointName); |
|
151 | - $data = [ |
|
152 | - 'remote' => $remote, |
|
153 | - 'share_token' => $token, |
|
154 | - 'password' => $password, |
|
155 | - 'name' => $name, |
|
156 | - 'owner' => $owner, |
|
157 | - 'user' => $user, |
|
158 | - 'mountpoint' => $mountPoint, |
|
159 | - 'mountpoint_hash' => $hash, |
|
160 | - 'accepted' => $accepted, |
|
161 | - 'remote_id' => $remoteId, |
|
162 | - 'share_type' => $shareType, |
|
163 | - ]; |
|
164 | - |
|
165 | - $i = 1; |
|
166 | - while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) { |
|
167 | - // The external share already exists for the user |
|
168 | - $data['mountpoint'] = $tmpMountPointName . '-' . $i; |
|
169 | - $data['mountpoint_hash'] = md5($data['mountpoint']); |
|
170 | - $i++; |
|
171 | - } |
|
172 | - return null; |
|
173 | - } |
|
174 | - |
|
175 | - $mountPoint = Files::buildNotExistingFileName('/', $name); |
|
176 | - $mountPoint = Filesystem::normalizePath('/' . $mountPoint); |
|
177 | - $hash = md5($mountPoint); |
|
178 | - |
|
179 | - $query = $this->connection->prepare(' |
|
47 | + const STORAGE = '\OCA\Files_Sharing\External\Storage'; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + private $uid; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var IDBConnection |
|
56 | + */ |
|
57 | + private $connection; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var \OC\Files\Mount\Manager |
|
61 | + */ |
|
62 | + private $mountManager; |
|
63 | + |
|
64 | + /** |
|
65 | + * @var IStorageFactory |
|
66 | + */ |
|
67 | + private $storageLoader; |
|
68 | + |
|
69 | + /** |
|
70 | + * @var IClientService |
|
71 | + */ |
|
72 | + private $clientService; |
|
73 | + |
|
74 | + /** |
|
75 | + * @var IManager |
|
76 | + */ |
|
77 | + private $notificationManager; |
|
78 | + |
|
79 | + /** |
|
80 | + * @var IDiscoveryService |
|
81 | + */ |
|
82 | + private $discoveryService; |
|
83 | + |
|
84 | + /** @var ICloudFederationProviderManager */ |
|
85 | + private $cloudFederationProviderManager; |
|
86 | + |
|
87 | + /** @var ICloudFederationFactory */ |
|
88 | + private $cloudFederationFactory; |
|
89 | + |
|
90 | + /** |
|
91 | + * @param IDBConnection $connection |
|
92 | + * @param \OC\Files\Mount\Manager $mountManager |
|
93 | + * @param IStorageFactory $storageLoader |
|
94 | + * @param IClientService $clientService |
|
95 | + * @param IManager $notificationManager |
|
96 | + * @param IDiscoveryService $discoveryService |
|
97 | + * @param ICloudFederationProviderManager $cloudFederationProviderManager |
|
98 | + * @param ICloudFederationFactory $cloudFederationFactory |
|
99 | + * @param string $uid |
|
100 | + */ |
|
101 | + public function __construct(IDBConnection $connection, |
|
102 | + \OC\Files\Mount\Manager $mountManager, |
|
103 | + IStorageFactory $storageLoader, |
|
104 | + IClientService $clientService, |
|
105 | + IManager $notificationManager, |
|
106 | + IDiscoveryService $discoveryService, |
|
107 | + ICloudFederationProviderManager $cloudFederationProviderManager, |
|
108 | + ICloudFederationFactory $cloudFederationFactory, |
|
109 | + $uid) { |
|
110 | + $this->connection = $connection; |
|
111 | + $this->mountManager = $mountManager; |
|
112 | + $this->storageLoader = $storageLoader; |
|
113 | + $this->clientService = $clientService; |
|
114 | + $this->uid = $uid; |
|
115 | + $this->notificationManager = $notificationManager; |
|
116 | + $this->discoveryService = $discoveryService; |
|
117 | + $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
118 | + $this->cloudFederationFactory = $cloudFederationFactory; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * add new server-to-server share |
|
123 | + * |
|
124 | + * @param string $remote |
|
125 | + * @param string $token |
|
126 | + * @param string $password |
|
127 | + * @param string $name |
|
128 | + * @param string $owner |
|
129 | + * @param int $shareType |
|
130 | + * @param boolean $accepted |
|
131 | + * @param string $user |
|
132 | + * @param int $remoteId |
|
133 | + * @param int $parent |
|
134 | + * @return Mount|null |
|
135 | + * @throws \Doctrine\DBAL\DBALException |
|
136 | + */ |
|
137 | + public function addShare($remote, $token, $password, $name, $owner, $shareType, $accepted=false, $user = null, $remoteId = -1, $parent = -1) { |
|
138 | + |
|
139 | + $user = $user ? $user : $this->uid; |
|
140 | + $accepted = $accepted ? 1 : 0; |
|
141 | + $name = Filesystem::normalizePath('/' . $name); |
|
142 | + |
|
143 | + if (!$accepted) { |
|
144 | + // To avoid conflicts with the mount point generation later, |
|
145 | + // we only use a temporary mount point name here. The real |
|
146 | + // mount point name will be generated when accepting the share, |
|
147 | + // using the original share item name. |
|
148 | + $tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}'; |
|
149 | + $mountPoint = $tmpMountPointName; |
|
150 | + $hash = md5($tmpMountPointName); |
|
151 | + $data = [ |
|
152 | + 'remote' => $remote, |
|
153 | + 'share_token' => $token, |
|
154 | + 'password' => $password, |
|
155 | + 'name' => $name, |
|
156 | + 'owner' => $owner, |
|
157 | + 'user' => $user, |
|
158 | + 'mountpoint' => $mountPoint, |
|
159 | + 'mountpoint_hash' => $hash, |
|
160 | + 'accepted' => $accepted, |
|
161 | + 'remote_id' => $remoteId, |
|
162 | + 'share_type' => $shareType, |
|
163 | + ]; |
|
164 | + |
|
165 | + $i = 1; |
|
166 | + while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) { |
|
167 | + // The external share already exists for the user |
|
168 | + $data['mountpoint'] = $tmpMountPointName . '-' . $i; |
|
169 | + $data['mountpoint_hash'] = md5($data['mountpoint']); |
|
170 | + $i++; |
|
171 | + } |
|
172 | + return null; |
|
173 | + } |
|
174 | + |
|
175 | + $mountPoint = Files::buildNotExistingFileName('/', $name); |
|
176 | + $mountPoint = Filesystem::normalizePath('/' . $mountPoint); |
|
177 | + $hash = md5($mountPoint); |
|
178 | + |
|
179 | + $query = $this->connection->prepare(' |
|
180 | 180 | INSERT INTO `*PREFIX*share_external` |
181 | 181 | (`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`, `accepted`, `remote_id`, `parent`, `share_type`) |
182 | 182 | VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
183 | 183 | '); |
184 | - $query->execute(array($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType)); |
|
185 | - |
|
186 | - $options = array( |
|
187 | - 'remote' => $remote, |
|
188 | - 'token' => $token, |
|
189 | - 'password' => $password, |
|
190 | - 'mountpoint' => $mountPoint, |
|
191 | - 'owner' => $owner |
|
192 | - ); |
|
193 | - return $this->mountShare($options); |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * get share |
|
198 | - * |
|
199 | - * @param int $id share id |
|
200 | - * @return mixed share of false |
|
201 | - */ |
|
202 | - public function getShare($id) { |
|
203 | - $getShare = $this->connection->prepare(' |
|
184 | + $query->execute(array($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType)); |
|
185 | + |
|
186 | + $options = array( |
|
187 | + 'remote' => $remote, |
|
188 | + 'token' => $token, |
|
189 | + 'password' => $password, |
|
190 | + 'mountpoint' => $mountPoint, |
|
191 | + 'owner' => $owner |
|
192 | + ); |
|
193 | + return $this->mountShare($options); |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * get share |
|
198 | + * |
|
199 | + * @param int $id share id |
|
200 | + * @return mixed share of false |
|
201 | + */ |
|
202 | + public function getShare($id) { |
|
203 | + $getShare = $this->connection->prepare(' |
|
204 | 204 | SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
205 | 205 | FROM `*PREFIX*share_external` |
206 | 206 | WHERE `id` = ? AND `user` = ?'); |
207 | - $result = $getShare->execute(array($id, $this->uid)); |
|
208 | - |
|
209 | - return $result ? $getShare->fetch() : false; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * accept server-to-server share |
|
214 | - * |
|
215 | - * @param int $id |
|
216 | - * @return bool True if the share could be accepted, false otherwise |
|
217 | - */ |
|
218 | - public function acceptShare($id) { |
|
219 | - |
|
220 | - $share = $this->getShare($id); |
|
221 | - $result = false; |
|
222 | - |
|
223 | - if ($share) { |
|
224 | - \OC_Util::setupFS($this->uid); |
|
225 | - $shareFolder = Helper::getShareFolder(); |
|
226 | - $mountPoint = Files::buildNotExistingFileName($shareFolder, $share['name']); |
|
227 | - $mountPoint = Filesystem::normalizePath($mountPoint); |
|
228 | - $hash = md5($mountPoint); |
|
229 | - |
|
230 | - if($share['share_type'] === \OCP\Share::SHARE_TYPE_USER) { |
|
231 | - $acceptShare = $this->connection->prepare(' |
|
207 | + $result = $getShare->execute(array($id, $this->uid)); |
|
208 | + |
|
209 | + return $result ? $getShare->fetch() : false; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * accept server-to-server share |
|
214 | + * |
|
215 | + * @param int $id |
|
216 | + * @return bool True if the share could be accepted, false otherwise |
|
217 | + */ |
|
218 | + public function acceptShare($id) { |
|
219 | + |
|
220 | + $share = $this->getShare($id); |
|
221 | + $result = false; |
|
222 | + |
|
223 | + if ($share) { |
|
224 | + \OC_Util::setupFS($this->uid); |
|
225 | + $shareFolder = Helper::getShareFolder(); |
|
226 | + $mountPoint = Files::buildNotExistingFileName($shareFolder, $share['name']); |
|
227 | + $mountPoint = Filesystem::normalizePath($mountPoint); |
|
228 | + $hash = md5($mountPoint); |
|
229 | + |
|
230 | + if($share['share_type'] === \OCP\Share::SHARE_TYPE_USER) { |
|
231 | + $acceptShare = $this->connection->prepare(' |
|
232 | 232 | UPDATE `*PREFIX*share_external` |
233 | 233 | SET `accepted` = ?, |
234 | 234 | `mountpoint` = ?, |
235 | 235 | `mountpoint_hash` = ? |
236 | 236 | WHERE `id` = ? AND `user` = ?'); |
237 | - $updated = $acceptShare->execute(array(1, $mountPoint, $hash, $id, $this->uid)); |
|
238 | - } else { |
|
239 | - // TODO group share, add additional row for the user who accepted it |
|
240 | - } |
|
241 | - if ($updated === true) { |
|
242 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept'); |
|
243 | - \OC_Hook::emit(Share::class, 'federated_share_added', ['server' => $share['remote']]); |
|
244 | - $result = true; |
|
245 | - } |
|
246 | - } |
|
247 | - |
|
248 | - // Make sure the user has no notification for something that does not exist anymore. |
|
249 | - $this->processNotification($id); |
|
250 | - |
|
251 | - return $result; |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * decline server-to-server share |
|
256 | - * |
|
257 | - * @param int $id |
|
258 | - * @return bool True if the share could be declined, false otherwise |
|
259 | - */ |
|
260 | - public function declineShare($id) { |
|
261 | - |
|
262 | - $share = $this->getShare($id); |
|
263 | - |
|
264 | - if ($share) { |
|
265 | - $removeShare = $this->connection->prepare(' |
|
237 | + $updated = $acceptShare->execute(array(1, $mountPoint, $hash, $id, $this->uid)); |
|
238 | + } else { |
|
239 | + // TODO group share, add additional row for the user who accepted it |
|
240 | + } |
|
241 | + if ($updated === true) { |
|
242 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept'); |
|
243 | + \OC_Hook::emit(Share::class, 'federated_share_added', ['server' => $share['remote']]); |
|
244 | + $result = true; |
|
245 | + } |
|
246 | + } |
|
247 | + |
|
248 | + // Make sure the user has no notification for something that does not exist anymore. |
|
249 | + $this->processNotification($id); |
|
250 | + |
|
251 | + return $result; |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * decline server-to-server share |
|
256 | + * |
|
257 | + * @param int $id |
|
258 | + * @return bool True if the share could be declined, false otherwise |
|
259 | + */ |
|
260 | + public function declineShare($id) { |
|
261 | + |
|
262 | + $share = $this->getShare($id); |
|
263 | + |
|
264 | + if ($share) { |
|
265 | + $removeShare = $this->connection->prepare(' |
|
266 | 266 | DELETE FROM `*PREFIX*share_external` WHERE `id` = ? AND `user` = ?'); |
267 | - $removeShare->execute(array($id, $this->uid)); |
|
268 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
269 | - |
|
270 | - $this->processNotification($id); |
|
271 | - return true; |
|
272 | - } |
|
273 | - |
|
274 | - return false; |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * @param int $remoteShare |
|
279 | - */ |
|
280 | - public function processNotification($remoteShare) { |
|
281 | - $filter = $this->notificationManager->createNotification(); |
|
282 | - $filter->setApp('files_sharing') |
|
283 | - ->setUser($this->uid) |
|
284 | - ->setObject('remote_share', (int) $remoteShare); |
|
285 | - $this->notificationManager->markProcessed($filter); |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * inform remote server whether server-to-server share was accepted/declined |
|
290 | - * |
|
291 | - * @param string $remote |
|
292 | - * @param string $token |
|
293 | - * @param int $remoteId Share id on the remote host |
|
294 | - * @param string $feedback |
|
295 | - * @return boolean |
|
296 | - */ |
|
297 | - private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) { |
|
298 | - |
|
299 | - $result = $this->tryOCMEndPoint($remote, $token, $remoteId, $feedback); |
|
300 | - |
|
301 | - if($result === true) { |
|
302 | - return true; |
|
303 | - } |
|
304 | - |
|
305 | - $federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING'); |
|
306 | - $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
307 | - |
|
308 | - $url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT; |
|
309 | - $fields = array('token' => $token); |
|
310 | - |
|
311 | - $client = $this->clientService->newClient(); |
|
312 | - |
|
313 | - try { |
|
314 | - $response = $client->post( |
|
315 | - $url, |
|
316 | - [ |
|
317 | - 'body' => $fields, |
|
318 | - 'connect_timeout' => 10, |
|
319 | - ] |
|
320 | - ); |
|
321 | - } catch (\Exception $e) { |
|
322 | - return false; |
|
323 | - } |
|
324 | - |
|
325 | - $status = json_decode($response->getBody(), true); |
|
326 | - |
|
327 | - return ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * try send accept message to ocm end-point |
|
332 | - * |
|
333 | - * @param string $remoteDomain |
|
334 | - * @param string $token |
|
335 | - * @param $remoteId id of the share |
|
336 | - * @param string $feedback |
|
337 | - * @return bool |
|
338 | - */ |
|
339 | - protected function tryOCMEndPoint($remoteDomain, $token, $remoteId, $feedback) { |
|
340 | - switch ($feedback) { |
|
341 | - case 'accept': |
|
342 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
343 | - $notification->setMessage( |
|
344 | - 'SHARE_ACCEPTED', |
|
345 | - 'file', |
|
346 | - $remoteId, |
|
347 | - [ |
|
348 | - 'sharedSecret' => $token, |
|
349 | - 'message' => 'Recipient accept the share' |
|
350 | - ] |
|
351 | - |
|
352 | - ); |
|
353 | - return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
354 | - case 'decline': |
|
355 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
356 | - $notification->setMessage( |
|
357 | - 'SHARE_DECLINED', |
|
358 | - 'file', |
|
359 | - $remoteId, |
|
360 | - [ |
|
361 | - 'sharedSecret' => $token, |
|
362 | - 'message' => 'Recipient declined the share' |
|
363 | - ] |
|
364 | - |
|
365 | - ); |
|
366 | - return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
367 | - } |
|
368 | - |
|
369 | - return false; |
|
370 | - |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * remove '/user/files' from the path and trailing slashes |
|
376 | - * |
|
377 | - * @param string $path |
|
378 | - * @return string |
|
379 | - */ |
|
380 | - protected function stripPath($path) { |
|
381 | - $prefix = '/' . $this->uid . '/files'; |
|
382 | - return rtrim(substr($path, strlen($prefix)), '/'); |
|
383 | - } |
|
384 | - |
|
385 | - public function getMount($data) { |
|
386 | - $data['manager'] = $this; |
|
387 | - $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; |
|
388 | - $data['mountpoint'] = $mountPoint; |
|
389 | - $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); |
|
390 | - return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * @param array $data |
|
395 | - * @return Mount |
|
396 | - */ |
|
397 | - protected function mountShare($data) { |
|
398 | - $mount = $this->getMount($data); |
|
399 | - $this->mountManager->addMount($mount); |
|
400 | - return $mount; |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * @return \OC\Files\Mount\Manager |
|
405 | - */ |
|
406 | - public function getMountManager() { |
|
407 | - return $this->mountManager; |
|
408 | - } |
|
409 | - |
|
410 | - /** |
|
411 | - * @param string $source |
|
412 | - * @param string $target |
|
413 | - * @return bool |
|
414 | - */ |
|
415 | - public function setMountPoint($source, $target) { |
|
416 | - $source = $this->stripPath($source); |
|
417 | - $target = $this->stripPath($target); |
|
418 | - $sourceHash = md5($source); |
|
419 | - $targetHash = md5($target); |
|
420 | - |
|
421 | - $query = $this->connection->prepare(' |
|
267 | + $removeShare->execute(array($id, $this->uid)); |
|
268 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
269 | + |
|
270 | + $this->processNotification($id); |
|
271 | + return true; |
|
272 | + } |
|
273 | + |
|
274 | + return false; |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * @param int $remoteShare |
|
279 | + */ |
|
280 | + public function processNotification($remoteShare) { |
|
281 | + $filter = $this->notificationManager->createNotification(); |
|
282 | + $filter->setApp('files_sharing') |
|
283 | + ->setUser($this->uid) |
|
284 | + ->setObject('remote_share', (int) $remoteShare); |
|
285 | + $this->notificationManager->markProcessed($filter); |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * inform remote server whether server-to-server share was accepted/declined |
|
290 | + * |
|
291 | + * @param string $remote |
|
292 | + * @param string $token |
|
293 | + * @param int $remoteId Share id on the remote host |
|
294 | + * @param string $feedback |
|
295 | + * @return boolean |
|
296 | + */ |
|
297 | + private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) { |
|
298 | + |
|
299 | + $result = $this->tryOCMEndPoint($remote, $token, $remoteId, $feedback); |
|
300 | + |
|
301 | + if($result === true) { |
|
302 | + return true; |
|
303 | + } |
|
304 | + |
|
305 | + $federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING'); |
|
306 | + $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
307 | + |
|
308 | + $url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT; |
|
309 | + $fields = array('token' => $token); |
|
310 | + |
|
311 | + $client = $this->clientService->newClient(); |
|
312 | + |
|
313 | + try { |
|
314 | + $response = $client->post( |
|
315 | + $url, |
|
316 | + [ |
|
317 | + 'body' => $fields, |
|
318 | + 'connect_timeout' => 10, |
|
319 | + ] |
|
320 | + ); |
|
321 | + } catch (\Exception $e) { |
|
322 | + return false; |
|
323 | + } |
|
324 | + |
|
325 | + $status = json_decode($response->getBody(), true); |
|
326 | + |
|
327 | + return ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * try send accept message to ocm end-point |
|
332 | + * |
|
333 | + * @param string $remoteDomain |
|
334 | + * @param string $token |
|
335 | + * @param $remoteId id of the share |
|
336 | + * @param string $feedback |
|
337 | + * @return bool |
|
338 | + */ |
|
339 | + protected function tryOCMEndPoint($remoteDomain, $token, $remoteId, $feedback) { |
|
340 | + switch ($feedback) { |
|
341 | + case 'accept': |
|
342 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
343 | + $notification->setMessage( |
|
344 | + 'SHARE_ACCEPTED', |
|
345 | + 'file', |
|
346 | + $remoteId, |
|
347 | + [ |
|
348 | + 'sharedSecret' => $token, |
|
349 | + 'message' => 'Recipient accept the share' |
|
350 | + ] |
|
351 | + |
|
352 | + ); |
|
353 | + return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
354 | + case 'decline': |
|
355 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
356 | + $notification->setMessage( |
|
357 | + 'SHARE_DECLINED', |
|
358 | + 'file', |
|
359 | + $remoteId, |
|
360 | + [ |
|
361 | + 'sharedSecret' => $token, |
|
362 | + 'message' => 'Recipient declined the share' |
|
363 | + ] |
|
364 | + |
|
365 | + ); |
|
366 | + return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
367 | + } |
|
368 | + |
|
369 | + return false; |
|
370 | + |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * remove '/user/files' from the path and trailing slashes |
|
376 | + * |
|
377 | + * @param string $path |
|
378 | + * @return string |
|
379 | + */ |
|
380 | + protected function stripPath($path) { |
|
381 | + $prefix = '/' . $this->uid . '/files'; |
|
382 | + return rtrim(substr($path, strlen($prefix)), '/'); |
|
383 | + } |
|
384 | + |
|
385 | + public function getMount($data) { |
|
386 | + $data['manager'] = $this; |
|
387 | + $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; |
|
388 | + $data['mountpoint'] = $mountPoint; |
|
389 | + $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); |
|
390 | + return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * @param array $data |
|
395 | + * @return Mount |
|
396 | + */ |
|
397 | + protected function mountShare($data) { |
|
398 | + $mount = $this->getMount($data); |
|
399 | + $this->mountManager->addMount($mount); |
|
400 | + return $mount; |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * @return \OC\Files\Mount\Manager |
|
405 | + */ |
|
406 | + public function getMountManager() { |
|
407 | + return $this->mountManager; |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | + * @param string $source |
|
412 | + * @param string $target |
|
413 | + * @return bool |
|
414 | + */ |
|
415 | + public function setMountPoint($source, $target) { |
|
416 | + $source = $this->stripPath($source); |
|
417 | + $target = $this->stripPath($target); |
|
418 | + $sourceHash = md5($source); |
|
419 | + $targetHash = md5($target); |
|
420 | + |
|
421 | + $query = $this->connection->prepare(' |
|
422 | 422 | UPDATE `*PREFIX*share_external` |
423 | 423 | SET `mountpoint` = ?, `mountpoint_hash` = ? |
424 | 424 | WHERE `mountpoint_hash` = ? |
425 | 425 | AND `user` = ? |
426 | 426 | '); |
427 | - $result = (bool)$query->execute(array($target, $targetHash, $sourceHash, $this->uid)); |
|
427 | + $result = (bool)$query->execute(array($target, $targetHash, $sourceHash, $this->uid)); |
|
428 | 428 | |
429 | - return $result; |
|
430 | - } |
|
429 | + return $result; |
|
430 | + } |
|
431 | 431 | |
432 | - public function removeShare($mountPoint) { |
|
432 | + public function removeShare($mountPoint) { |
|
433 | 433 | |
434 | - $mountPointObj = $this->mountManager->find($mountPoint); |
|
435 | - $id = $mountPointObj->getStorage()->getCache()->getId(''); |
|
434 | + $mountPointObj = $this->mountManager->find($mountPoint); |
|
435 | + $id = $mountPointObj->getStorage()->getCache()->getId(''); |
|
436 | 436 | |
437 | - $mountPoint = $this->stripPath($mountPoint); |
|
438 | - $hash = md5($mountPoint); |
|
437 | + $mountPoint = $this->stripPath($mountPoint); |
|
438 | + $hash = md5($mountPoint); |
|
439 | 439 | |
440 | - $getShare = $this->connection->prepare(' |
|
440 | + $getShare = $this->connection->prepare(' |
|
441 | 441 | SELECT `remote`, `share_token`, `remote_id` |
442 | 442 | FROM `*PREFIX*share_external` |
443 | 443 | WHERE `mountpoint_hash` = ? AND `user` = ?'); |
444 | - $result = $getShare->execute(array($hash, $this->uid)); |
|
445 | - |
|
446 | - if ($result) { |
|
447 | - try { |
|
448 | - $share = $getShare->fetch(); |
|
449 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
450 | - } catch (\Exception $e) { |
|
451 | - // if we fail to notify the remote (probably cause the remote is down) |
|
452 | - // we still want the share to be gone to prevent undeletable remotes |
|
453 | - } |
|
454 | - } |
|
455 | - $getShare->closeCursor(); |
|
456 | - |
|
457 | - $query = $this->connection->prepare(' |
|
444 | + $result = $getShare->execute(array($hash, $this->uid)); |
|
445 | + |
|
446 | + if ($result) { |
|
447 | + try { |
|
448 | + $share = $getShare->fetch(); |
|
449 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
450 | + } catch (\Exception $e) { |
|
451 | + // if we fail to notify the remote (probably cause the remote is down) |
|
452 | + // we still want the share to be gone to prevent undeletable remotes |
|
453 | + } |
|
454 | + } |
|
455 | + $getShare->closeCursor(); |
|
456 | + |
|
457 | + $query = $this->connection->prepare(' |
|
458 | 458 | DELETE FROM `*PREFIX*share_external` |
459 | 459 | WHERE `mountpoint_hash` = ? |
460 | 460 | AND `user` = ? |
461 | 461 | '); |
462 | - $result = (bool)$query->execute(array($hash, $this->uid)); |
|
463 | - |
|
464 | - if($result) { |
|
465 | - $this->removeReShares($id); |
|
466 | - } |
|
467 | - |
|
468 | - return $result; |
|
469 | - } |
|
470 | - |
|
471 | - /** |
|
472 | - * remove re-shares from share table and mapping in the federated_reshares table |
|
473 | - * |
|
474 | - * @param $mountPointId |
|
475 | - */ |
|
476 | - protected function removeReShares($mountPointId) { |
|
477 | - $selectQuery = $this->connection->getQueryBuilder(); |
|
478 | - $query = $this->connection->getQueryBuilder(); |
|
479 | - $selectQuery->select('id')->from('share') |
|
480 | - ->where($selectQuery->expr()->eq('file_source', $query->createNamedParameter($mountPointId))); |
|
481 | - $select = $selectQuery->getSQL(); |
|
482 | - |
|
483 | - |
|
484 | - $query->delete('federated_reshares') |
|
485 | - ->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')'))); |
|
486 | - $query->execute(); |
|
487 | - |
|
488 | - $deleteReShares = $this->connection->getQueryBuilder(); |
|
489 | - $deleteReShares->delete('share') |
|
490 | - ->where($deleteReShares->expr()->eq('file_source', $deleteReShares->createNamedParameter($mountPointId))); |
|
491 | - $deleteReShares->execute(); |
|
492 | - } |
|
493 | - |
|
494 | - /** |
|
495 | - * remove all shares for user $uid if the user was deleted |
|
496 | - * |
|
497 | - * @param string $uid |
|
498 | - * @return bool |
|
499 | - */ |
|
500 | - public function removeUserShares($uid) { |
|
501 | - $getShare = $this->connection->prepare(' |
|
462 | + $result = (bool)$query->execute(array($hash, $this->uid)); |
|
463 | + |
|
464 | + if($result) { |
|
465 | + $this->removeReShares($id); |
|
466 | + } |
|
467 | + |
|
468 | + return $result; |
|
469 | + } |
|
470 | + |
|
471 | + /** |
|
472 | + * remove re-shares from share table and mapping in the federated_reshares table |
|
473 | + * |
|
474 | + * @param $mountPointId |
|
475 | + */ |
|
476 | + protected function removeReShares($mountPointId) { |
|
477 | + $selectQuery = $this->connection->getQueryBuilder(); |
|
478 | + $query = $this->connection->getQueryBuilder(); |
|
479 | + $selectQuery->select('id')->from('share') |
|
480 | + ->where($selectQuery->expr()->eq('file_source', $query->createNamedParameter($mountPointId))); |
|
481 | + $select = $selectQuery->getSQL(); |
|
482 | + |
|
483 | + |
|
484 | + $query->delete('federated_reshares') |
|
485 | + ->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')'))); |
|
486 | + $query->execute(); |
|
487 | + |
|
488 | + $deleteReShares = $this->connection->getQueryBuilder(); |
|
489 | + $deleteReShares->delete('share') |
|
490 | + ->where($deleteReShares->expr()->eq('file_source', $deleteReShares->createNamedParameter($mountPointId))); |
|
491 | + $deleteReShares->execute(); |
|
492 | + } |
|
493 | + |
|
494 | + /** |
|
495 | + * remove all shares for user $uid if the user was deleted |
|
496 | + * |
|
497 | + * @param string $uid |
|
498 | + * @return bool |
|
499 | + */ |
|
500 | + public function removeUserShares($uid) { |
|
501 | + $getShare = $this->connection->prepare(' |
|
502 | 502 | SELECT `remote`, `share_token`, `remote_id` |
503 | 503 | FROM `*PREFIX*share_external` |
504 | 504 | WHERE `user` = ?'); |
505 | - $result = $getShare->execute(array($uid)); |
|
505 | + $result = $getShare->execute(array($uid)); |
|
506 | 506 | |
507 | - if ($result) { |
|
508 | - $shares = $getShare->fetchAll(); |
|
509 | - foreach($shares as $share) { |
|
510 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
511 | - } |
|
512 | - } |
|
507 | + if ($result) { |
|
508 | + $shares = $getShare->fetchAll(); |
|
509 | + foreach($shares as $share) { |
|
510 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
511 | + } |
|
512 | + } |
|
513 | 513 | |
514 | - $query = $this->connection->prepare(' |
|
514 | + $query = $this->connection->prepare(' |
|
515 | 515 | DELETE FROM `*PREFIX*share_external` |
516 | 516 | WHERE `user` = ? |
517 | 517 | '); |
518 | - return (bool)$query->execute(array($uid)); |
|
519 | - } |
|
520 | - |
|
521 | - /** |
|
522 | - * return a list of shares which are not yet accepted by the user |
|
523 | - * |
|
524 | - * @return array list of open server-to-server shares |
|
525 | - */ |
|
526 | - public function getOpenShares() { |
|
527 | - return $this->getShares(false); |
|
528 | - } |
|
529 | - |
|
530 | - /** |
|
531 | - * return a list of shares which are accepted by the user |
|
532 | - * |
|
533 | - * @return array list of accepted server-to-server shares |
|
534 | - */ |
|
535 | - public function getAcceptedShares() { |
|
536 | - return $this->getShares(true); |
|
537 | - } |
|
538 | - |
|
539 | - /** |
|
540 | - * return a list of shares for the user |
|
541 | - * |
|
542 | - * @param bool|null $accepted True for accepted only, |
|
543 | - * false for not accepted, |
|
544 | - * null for all shares of the user |
|
545 | - * @return array list of open server-to-server shares |
|
546 | - */ |
|
547 | - private function getShares($accepted) { |
|
548 | - $query = 'SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
|
518 | + return (bool)$query->execute(array($uid)); |
|
519 | + } |
|
520 | + |
|
521 | + /** |
|
522 | + * return a list of shares which are not yet accepted by the user |
|
523 | + * |
|
524 | + * @return array list of open server-to-server shares |
|
525 | + */ |
|
526 | + public function getOpenShares() { |
|
527 | + return $this->getShares(false); |
|
528 | + } |
|
529 | + |
|
530 | + /** |
|
531 | + * return a list of shares which are accepted by the user |
|
532 | + * |
|
533 | + * @return array list of accepted server-to-server shares |
|
534 | + */ |
|
535 | + public function getAcceptedShares() { |
|
536 | + return $this->getShares(true); |
|
537 | + } |
|
538 | + |
|
539 | + /** |
|
540 | + * return a list of shares for the user |
|
541 | + * |
|
542 | + * @param bool|null $accepted True for accepted only, |
|
543 | + * false for not accepted, |
|
544 | + * null for all shares of the user |
|
545 | + * @return array list of open server-to-server shares |
|
546 | + */ |
|
547 | + private function getShares($accepted) { |
|
548 | + $query = 'SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
|
549 | 549 | FROM `*PREFIX*share_external` |
550 | 550 | WHERE `user` = ?'; |
551 | - $parameters = [$this->uid]; |
|
552 | - if (!is_null($accepted)) { |
|
553 | - $query .= ' AND `accepted` = ?'; |
|
554 | - $parameters[] = (int) $accepted; |
|
555 | - } |
|
556 | - $query .= ' ORDER BY `id` ASC'; |
|
557 | - |
|
558 | - $shares = $this->connection->prepare($query); |
|
559 | - $result = $shares->execute($parameters); |
|
560 | - |
|
561 | - return $result ? $shares->fetchAll() : []; |
|
562 | - } |
|
551 | + $parameters = [$this->uid]; |
|
552 | + if (!is_null($accepted)) { |
|
553 | + $query .= ' AND `accepted` = ?'; |
|
554 | + $parameters[] = (int) $accepted; |
|
555 | + } |
|
556 | + $query .= ' ORDER BY `id` ASC'; |
|
557 | + |
|
558 | + $shares = $this->connection->prepare($query); |
|
559 | + $result = $shares->execute($parameters); |
|
560 | + |
|
561 | + return $result ? $shares->fetchAll() : []; |
|
562 | + } |
|
563 | 563 | } |
@@ -52,250 +52,250 @@ |
||
52 | 52 | */ |
53 | 53 | class RequestHandlerController extends Controller { |
54 | 54 | |
55 | - /** @var ILogger */ |
|
56 | - private $logger; |
|
57 | - |
|
58 | - /** @var IUserManager */ |
|
59 | - private $userManager; |
|
60 | - |
|
61 | - /** @var IGroupManager */ |
|
62 | - private $groupManager; |
|
63 | - |
|
64 | - /** @var IURLGenerator */ |
|
65 | - private $urlGenerator; |
|
66 | - |
|
67 | - /** @var ICloudFederationProviderManager */ |
|
68 | - private $cloudFederationProviderManager; |
|
69 | - |
|
70 | - /** @var Config */ |
|
71 | - private $config; |
|
72 | - |
|
73 | - /** @var ICloudFederationFactory */ |
|
74 | - private $factory; |
|
75 | - |
|
76 | - /** @var ICloudIdManager */ |
|
77 | - private $cloudIdManager; |
|
78 | - |
|
79 | - public function __construct($appName, |
|
80 | - IRequest $request, |
|
81 | - ILogger $logger, |
|
82 | - IUserManager $userManager, |
|
83 | - IGroupManager $groupManager, |
|
84 | - IURLGenerator $urlGenerator, |
|
85 | - ICloudFederationProviderManager $cloudFederationProviderManager, |
|
86 | - Config $config, |
|
87 | - ICloudFederationFactory $factory, |
|
88 | - ICloudIdManager $cloudIdManager |
|
89 | - ) { |
|
90 | - parent::__construct($appName, $request); |
|
91 | - |
|
92 | - $this->logger = $logger; |
|
93 | - $this->userManager = $userManager; |
|
94 | - $this->groupManager = $groupManager; |
|
95 | - $this->urlGenerator = $urlGenerator; |
|
96 | - $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
97 | - $this->config = $config; |
|
98 | - $this->factory = $factory; |
|
99 | - $this->cloudIdManager = $cloudIdManager; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * add share |
|
104 | - * |
|
105 | - * @NoCSRFRequired |
|
106 | - * @PublicPage |
|
107 | - * @BruteForceProtection(action=receiveFederatedShare) |
|
108 | - * |
|
109 | - * @param string $shareWith |
|
110 | - * @param string $name resource name (e.g. document.odt) |
|
111 | - * @param string $description share description (optional) |
|
112 | - * @param string $providerId resource UID on the provider side |
|
113 | - * @param string $owner provider specific UID of the user who owns the resource |
|
114 | - * @param string $ownerDisplayName display name of the user who shared the item |
|
115 | - * @param string $sharedBy provider specific UID of the user who shared the resource |
|
116 | - * @param string $sharedByDisplayName display name of the user who shared the resource |
|
117 | - * @param array $protocol (e,.g. ['name' => 'webdav', 'options' => ['username' => 'john', 'permissions' => 31]]) |
|
118 | - * @param string $shareType ('group' or 'user' share) |
|
119 | - * @param $resourceType ('file', 'calendar',...) |
|
120 | - * @return Http\DataResponse|JSONResponse |
|
121 | - * |
|
122 | - * Example: curl -H "Content-Type: application/json" -X POST -d '{"shareWith":"admin1@serve1","name":"welcome server2.txt","description":"desc","providerId":"2","owner":"admin2@http://localhost/server2","ownerDisplayName":"admin2 display","shareType":"user","resourceType":"file","protocol":{"name":"webdav","options":{"sharedSecret":"secret","permissions":"webdav-property"}}}' http://localhost/server/index.php/ocm/shares |
|
123 | - */ |
|
124 | - public function addShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $protocol, $shareType, $resourceType) { |
|
125 | - |
|
126 | - // check if all required parameters are set |
|
127 | - if ($shareWith === null || |
|
128 | - $name === null || |
|
129 | - $providerId === null || |
|
130 | - $owner === null || |
|
131 | - $resourceType === null || |
|
132 | - $shareType === null || |
|
133 | - !is_array($protocol) || |
|
134 | - !isset($protocol['name']) || |
|
135 | - !isset ($protocol['options']) || |
|
136 | - !is_array($protocol['options']) || |
|
137 | - !isset($protocol['options']['sharedSecret']) |
|
138 | - ) { |
|
139 | - return new JSONResponse( |
|
140 | - ['message' => 'Missing arguments'], |
|
141 | - Http::STATUS_BAD_REQUEST |
|
142 | - ); |
|
143 | - } |
|
144 | - |
|
145 | - $supportedShareTypes = $this->config->getSupportedShareTypes($resourceType); |
|
146 | - if (!in_array($shareType, $supportedShareTypes)) { |
|
147 | - return new JSONResponse( |
|
148 | - ['message' => 'Share type "' . $shareType . '" not implemented'], |
|
149 | - Http::STATUS_NOT_IMPLEMENTED |
|
150 | - ); |
|
151 | - } |
|
152 | - |
|
153 | - $cloudId = $this->cloudIdManager->resolveCloudId($shareWith); |
|
154 | - $shareWithLocalId = $cloudId->getUser(); |
|
155 | - |
|
156 | - if ($shareType === 'user') { |
|
157 | - $shareWith = $this->mapUid($shareWithLocalId); |
|
158 | - |
|
159 | - if (!$this->userManager->userExists($shareWith)) { |
|
160 | - return new JSONResponse( |
|
161 | - ['message' => 'User "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()], |
|
162 | - Http::STATUS_BAD_REQUEST |
|
163 | - ); |
|
164 | - } |
|
165 | - } |
|
166 | - |
|
167 | - if ($shareType === 'group') { |
|
168 | - if(!$this->groupManager->groupExists($shareWithLocalId)) { |
|
169 | - return new JSONResponse( |
|
170 | - ['message' => 'Group "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()], |
|
171 | - Http::STATUS_BAD_REQUEST |
|
172 | - ); |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - // if no explicit display name is given, we use the uid as display name |
|
177 | - $ownerDisplayName = $ownerDisplayName === null ? $owner : $ownerDisplayName; |
|
178 | - $sharedByDisplayName = $sharedByDisplayName === null ? $sharedBy : $sharedByDisplayName; |
|
179 | - |
|
180 | - // sharedBy* parameter is optional, if nothing is set we assume that it is the same user as the owner |
|
181 | - if ($sharedBy === null) { |
|
182 | - $sharedBy = $owner; |
|
183 | - $sharedByDisplayName = $ownerDisplayName; |
|
184 | - } |
|
185 | - |
|
186 | - try { |
|
187 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); |
|
188 | - $share = $this->factory->getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, '', $shareType, $resourceType); |
|
189 | - $share->setProtocol($protocol); |
|
190 | - $provider->shareReceived($share); |
|
191 | - } catch (ProviderDoesNotExistsException $e) { |
|
192 | - return new JSONResponse( |
|
193 | - ['message' => $e->getMessage()], |
|
194 | - Http::STATUS_NOT_IMPLEMENTED |
|
195 | - ); |
|
196 | - } catch (ProviderCouldNotAddShareException $e) { |
|
197 | - return new JSONResponse( |
|
198 | - ['message' => $e->getMessage()], |
|
199 | - $e->getCode() |
|
200 | - ); |
|
201 | - } catch (\Exception $e) { |
|
202 | - return new JSONResponse( |
|
203 | - ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], |
|
204 | - Http::STATUS_BAD_REQUEST |
|
205 | - ); |
|
206 | - } |
|
207 | - |
|
208 | - $user = $this->userManager->get($shareWithLocalId); |
|
209 | - $recipientDisplayName = ''; |
|
210 | - if($user) { |
|
211 | - $recipientDisplayName = $user->getDisplayName(); |
|
212 | - } |
|
213 | - |
|
214 | - return new JSONResponse( |
|
215 | - ['recipientDisplayName' => $recipientDisplayName], |
|
216 | - Http::STATUS_CREATED); |
|
217 | - |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * receive notification about existing share |
|
222 | - * |
|
223 | - * @NoCSRFRequired |
|
224 | - * @PublicPage |
|
225 | - * @BruteForceProtection(action=receiveFederatedShareNotification) |
|
226 | - * |
|
227 | - * @param string $notificationType (notification type, e.g. SHARE_ACCEPTED) |
|
228 | - * @param string $resourceType (calendar, file, contact,...) |
|
229 | - * @param string $providerId id of the share |
|
230 | - * @param array $notification the actual payload of the notification |
|
231 | - * @return JSONResponse |
|
232 | - */ |
|
233 | - public function receiveNotification($notificationType, $resourceType, $providerId, array $notification) { |
|
234 | - |
|
235 | - // check if all required parameters are set |
|
236 | - if ($notificationType === null || |
|
237 | - $resourceType === null || |
|
238 | - $providerId === null || |
|
239 | - !is_array($notification) |
|
240 | - ) { |
|
241 | - return new JSONResponse( |
|
242 | - ['message' => 'Missing arguments'], |
|
243 | - Http::STATUS_BAD_REQUEST |
|
244 | - ); |
|
245 | - } |
|
246 | - |
|
247 | - try { |
|
248 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); |
|
249 | - $result = $provider->notificationReceived($notificationType, $providerId, $notification); |
|
250 | - } catch (ProviderDoesNotExistsException $e) { |
|
251 | - return new JSONResponse( |
|
252 | - ['message' => $e->getMessage()], |
|
253 | - Http::STATUS_BAD_REQUEST |
|
254 | - ); |
|
255 | - } catch (ShareNotFound $e) { |
|
256 | - return new JSONResponse( |
|
257 | - ['message' => $e->getMessage()], |
|
258 | - Http::STATUS_BAD_REQUEST |
|
259 | - ); |
|
260 | - } catch (ActionNotSupportedException $e) { |
|
261 | - return new JSONResponse( |
|
262 | - ['message' => $e->getMessage()], |
|
263 | - Http::STATUS_NOT_IMPLEMENTED |
|
264 | - ); |
|
265 | - } catch (BadRequestException $e) { |
|
266 | - return new JSONResponse($e->getReturnMessage(), Http::STATUS_BAD_REQUEST); |
|
267 | - } catch (AuthenticationFailedException $e) { |
|
268 | - return new JSONResponse(["message" => "RESOURCE_NOT_FOUND"], Http::STATUS_FORBIDDEN); |
|
269 | - } |
|
270 | - catch (\Exception $e) { |
|
271 | - return new JSONResponse( |
|
272 | - ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], |
|
273 | - Http::STATUS_BAD_REQUEST |
|
274 | - ); |
|
275 | - } |
|
276 | - |
|
277 | - return new JSONResponse($result,Http::STATUS_CREATED); |
|
278 | - |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * map login name to internal LDAP UID if a LDAP backend is in use |
|
283 | - * |
|
284 | - * @param string $uid |
|
285 | - * @return string mixed |
|
286 | - */ |
|
287 | - private function mapUid($uid) { |
|
288 | - \OC::$server->getURLGenerator()->linkToDocs('key'); |
|
289 | - // FIXME this should be a method in the user management instead |
|
290 | - $this->logger->debug('shareWith before, ' . $uid, ['app' => $this->appName]); |
|
291 | - \OCP\Util::emitHook( |
|
292 | - '\OCA\Files_Sharing\API\Server2Server', |
|
293 | - 'preLoginNameUsedAsUserName', |
|
294 | - array('uid' => &$uid) |
|
295 | - ); |
|
296 | - $this->logger->debug('shareWith after, ' . $uid, ['app' => $this->appName]); |
|
297 | - |
|
298 | - return $uid; |
|
299 | - } |
|
55 | + /** @var ILogger */ |
|
56 | + private $logger; |
|
57 | + |
|
58 | + /** @var IUserManager */ |
|
59 | + private $userManager; |
|
60 | + |
|
61 | + /** @var IGroupManager */ |
|
62 | + private $groupManager; |
|
63 | + |
|
64 | + /** @var IURLGenerator */ |
|
65 | + private $urlGenerator; |
|
66 | + |
|
67 | + /** @var ICloudFederationProviderManager */ |
|
68 | + private $cloudFederationProviderManager; |
|
69 | + |
|
70 | + /** @var Config */ |
|
71 | + private $config; |
|
72 | + |
|
73 | + /** @var ICloudFederationFactory */ |
|
74 | + private $factory; |
|
75 | + |
|
76 | + /** @var ICloudIdManager */ |
|
77 | + private $cloudIdManager; |
|
78 | + |
|
79 | + public function __construct($appName, |
|
80 | + IRequest $request, |
|
81 | + ILogger $logger, |
|
82 | + IUserManager $userManager, |
|
83 | + IGroupManager $groupManager, |
|
84 | + IURLGenerator $urlGenerator, |
|
85 | + ICloudFederationProviderManager $cloudFederationProviderManager, |
|
86 | + Config $config, |
|
87 | + ICloudFederationFactory $factory, |
|
88 | + ICloudIdManager $cloudIdManager |
|
89 | + ) { |
|
90 | + parent::__construct($appName, $request); |
|
91 | + |
|
92 | + $this->logger = $logger; |
|
93 | + $this->userManager = $userManager; |
|
94 | + $this->groupManager = $groupManager; |
|
95 | + $this->urlGenerator = $urlGenerator; |
|
96 | + $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
97 | + $this->config = $config; |
|
98 | + $this->factory = $factory; |
|
99 | + $this->cloudIdManager = $cloudIdManager; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * add share |
|
104 | + * |
|
105 | + * @NoCSRFRequired |
|
106 | + * @PublicPage |
|
107 | + * @BruteForceProtection(action=receiveFederatedShare) |
|
108 | + * |
|
109 | + * @param string $shareWith |
|
110 | + * @param string $name resource name (e.g. document.odt) |
|
111 | + * @param string $description share description (optional) |
|
112 | + * @param string $providerId resource UID on the provider side |
|
113 | + * @param string $owner provider specific UID of the user who owns the resource |
|
114 | + * @param string $ownerDisplayName display name of the user who shared the item |
|
115 | + * @param string $sharedBy provider specific UID of the user who shared the resource |
|
116 | + * @param string $sharedByDisplayName display name of the user who shared the resource |
|
117 | + * @param array $protocol (e,.g. ['name' => 'webdav', 'options' => ['username' => 'john', 'permissions' => 31]]) |
|
118 | + * @param string $shareType ('group' or 'user' share) |
|
119 | + * @param $resourceType ('file', 'calendar',...) |
|
120 | + * @return Http\DataResponse|JSONResponse |
|
121 | + * |
|
122 | + * Example: curl -H "Content-Type: application/json" -X POST -d '{"shareWith":"admin1@serve1","name":"welcome server2.txt","description":"desc","providerId":"2","owner":"admin2@http://localhost/server2","ownerDisplayName":"admin2 display","shareType":"user","resourceType":"file","protocol":{"name":"webdav","options":{"sharedSecret":"secret","permissions":"webdav-property"}}}' http://localhost/server/index.php/ocm/shares |
|
123 | + */ |
|
124 | + public function addShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $protocol, $shareType, $resourceType) { |
|
125 | + |
|
126 | + // check if all required parameters are set |
|
127 | + if ($shareWith === null || |
|
128 | + $name === null || |
|
129 | + $providerId === null || |
|
130 | + $owner === null || |
|
131 | + $resourceType === null || |
|
132 | + $shareType === null || |
|
133 | + !is_array($protocol) || |
|
134 | + !isset($protocol['name']) || |
|
135 | + !isset ($protocol['options']) || |
|
136 | + !is_array($protocol['options']) || |
|
137 | + !isset($protocol['options']['sharedSecret']) |
|
138 | + ) { |
|
139 | + return new JSONResponse( |
|
140 | + ['message' => 'Missing arguments'], |
|
141 | + Http::STATUS_BAD_REQUEST |
|
142 | + ); |
|
143 | + } |
|
144 | + |
|
145 | + $supportedShareTypes = $this->config->getSupportedShareTypes($resourceType); |
|
146 | + if (!in_array($shareType, $supportedShareTypes)) { |
|
147 | + return new JSONResponse( |
|
148 | + ['message' => 'Share type "' . $shareType . '" not implemented'], |
|
149 | + Http::STATUS_NOT_IMPLEMENTED |
|
150 | + ); |
|
151 | + } |
|
152 | + |
|
153 | + $cloudId = $this->cloudIdManager->resolveCloudId($shareWith); |
|
154 | + $shareWithLocalId = $cloudId->getUser(); |
|
155 | + |
|
156 | + if ($shareType === 'user') { |
|
157 | + $shareWith = $this->mapUid($shareWithLocalId); |
|
158 | + |
|
159 | + if (!$this->userManager->userExists($shareWith)) { |
|
160 | + return new JSONResponse( |
|
161 | + ['message' => 'User "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()], |
|
162 | + Http::STATUS_BAD_REQUEST |
|
163 | + ); |
|
164 | + } |
|
165 | + } |
|
166 | + |
|
167 | + if ($shareType === 'group') { |
|
168 | + if(!$this->groupManager->groupExists($shareWithLocalId)) { |
|
169 | + return new JSONResponse( |
|
170 | + ['message' => 'Group "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()], |
|
171 | + Http::STATUS_BAD_REQUEST |
|
172 | + ); |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + // if no explicit display name is given, we use the uid as display name |
|
177 | + $ownerDisplayName = $ownerDisplayName === null ? $owner : $ownerDisplayName; |
|
178 | + $sharedByDisplayName = $sharedByDisplayName === null ? $sharedBy : $sharedByDisplayName; |
|
179 | + |
|
180 | + // sharedBy* parameter is optional, if nothing is set we assume that it is the same user as the owner |
|
181 | + if ($sharedBy === null) { |
|
182 | + $sharedBy = $owner; |
|
183 | + $sharedByDisplayName = $ownerDisplayName; |
|
184 | + } |
|
185 | + |
|
186 | + try { |
|
187 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); |
|
188 | + $share = $this->factory->getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, '', $shareType, $resourceType); |
|
189 | + $share->setProtocol($protocol); |
|
190 | + $provider->shareReceived($share); |
|
191 | + } catch (ProviderDoesNotExistsException $e) { |
|
192 | + return new JSONResponse( |
|
193 | + ['message' => $e->getMessage()], |
|
194 | + Http::STATUS_NOT_IMPLEMENTED |
|
195 | + ); |
|
196 | + } catch (ProviderCouldNotAddShareException $e) { |
|
197 | + return new JSONResponse( |
|
198 | + ['message' => $e->getMessage()], |
|
199 | + $e->getCode() |
|
200 | + ); |
|
201 | + } catch (\Exception $e) { |
|
202 | + return new JSONResponse( |
|
203 | + ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], |
|
204 | + Http::STATUS_BAD_REQUEST |
|
205 | + ); |
|
206 | + } |
|
207 | + |
|
208 | + $user = $this->userManager->get($shareWithLocalId); |
|
209 | + $recipientDisplayName = ''; |
|
210 | + if($user) { |
|
211 | + $recipientDisplayName = $user->getDisplayName(); |
|
212 | + } |
|
213 | + |
|
214 | + return new JSONResponse( |
|
215 | + ['recipientDisplayName' => $recipientDisplayName], |
|
216 | + Http::STATUS_CREATED); |
|
217 | + |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * receive notification about existing share |
|
222 | + * |
|
223 | + * @NoCSRFRequired |
|
224 | + * @PublicPage |
|
225 | + * @BruteForceProtection(action=receiveFederatedShareNotification) |
|
226 | + * |
|
227 | + * @param string $notificationType (notification type, e.g. SHARE_ACCEPTED) |
|
228 | + * @param string $resourceType (calendar, file, contact,...) |
|
229 | + * @param string $providerId id of the share |
|
230 | + * @param array $notification the actual payload of the notification |
|
231 | + * @return JSONResponse |
|
232 | + */ |
|
233 | + public function receiveNotification($notificationType, $resourceType, $providerId, array $notification) { |
|
234 | + |
|
235 | + // check if all required parameters are set |
|
236 | + if ($notificationType === null || |
|
237 | + $resourceType === null || |
|
238 | + $providerId === null || |
|
239 | + !is_array($notification) |
|
240 | + ) { |
|
241 | + return new JSONResponse( |
|
242 | + ['message' => 'Missing arguments'], |
|
243 | + Http::STATUS_BAD_REQUEST |
|
244 | + ); |
|
245 | + } |
|
246 | + |
|
247 | + try { |
|
248 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); |
|
249 | + $result = $provider->notificationReceived($notificationType, $providerId, $notification); |
|
250 | + } catch (ProviderDoesNotExistsException $e) { |
|
251 | + return new JSONResponse( |
|
252 | + ['message' => $e->getMessage()], |
|
253 | + Http::STATUS_BAD_REQUEST |
|
254 | + ); |
|
255 | + } catch (ShareNotFound $e) { |
|
256 | + return new JSONResponse( |
|
257 | + ['message' => $e->getMessage()], |
|
258 | + Http::STATUS_BAD_REQUEST |
|
259 | + ); |
|
260 | + } catch (ActionNotSupportedException $e) { |
|
261 | + return new JSONResponse( |
|
262 | + ['message' => $e->getMessage()], |
|
263 | + Http::STATUS_NOT_IMPLEMENTED |
|
264 | + ); |
|
265 | + } catch (BadRequestException $e) { |
|
266 | + return new JSONResponse($e->getReturnMessage(), Http::STATUS_BAD_REQUEST); |
|
267 | + } catch (AuthenticationFailedException $e) { |
|
268 | + return new JSONResponse(["message" => "RESOURCE_NOT_FOUND"], Http::STATUS_FORBIDDEN); |
|
269 | + } |
|
270 | + catch (\Exception $e) { |
|
271 | + return new JSONResponse( |
|
272 | + ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], |
|
273 | + Http::STATUS_BAD_REQUEST |
|
274 | + ); |
|
275 | + } |
|
276 | + |
|
277 | + return new JSONResponse($result,Http::STATUS_CREATED); |
|
278 | + |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * map login name to internal LDAP UID if a LDAP backend is in use |
|
283 | + * |
|
284 | + * @param string $uid |
|
285 | + * @return string mixed |
|
286 | + */ |
|
287 | + private function mapUid($uid) { |
|
288 | + \OC::$server->getURLGenerator()->linkToDocs('key'); |
|
289 | + // FIXME this should be a method in the user management instead |
|
290 | + $this->logger->debug('shareWith before, ' . $uid, ['app' => $this->appName]); |
|
291 | + \OCP\Util::emitHook( |
|
292 | + '\OCA\Files_Sharing\API\Server2Server', |
|
293 | + 'preLoginNameUsedAsUserName', |
|
294 | + array('uid' => &$uid) |
|
295 | + ); |
|
296 | + $this->logger->debug('shareWith after, ' . $uid, ['app' => $this->appName]); |
|
297 | + |
|
298 | + return $uid; |
|
299 | + } |
|
300 | 300 | |
301 | 301 | } |