Completed
Pull Request — master (#9345)
by Björn
46:21 queued 21:44
created
apps/federatedfilesharing/lib/ocm/CloudFederationProviderFiles.php 1 patch
Indentation   +707 added lines, -707 removed lines patch added patch discarded remove patch
@@ -50,713 +50,713 @@
 block discarded – undo
50 50
 
51 51
 class CloudFederationProviderFiles implements ICloudFederationProvider {
52 52
 
53
-	/** @var IAppManager */
54
-	private $appManager;
55
-
56
-	/** @var FederatedShareProvider */
57
-	private $federatedShareProvider;
58
-
59
-	/** @var AddressHandler */
60
-	private $addressHandler;
61
-
62
-	/** @var ILogger */
63
-	private $logger;
64
-
65
-	/** @var IUserManager */
66
-	private $userManager;
67
-
68
-	/** @var ICloudIdManager */
69
-	private $cloudIdManager;
70
-
71
-	/** @var IActivityManager */
72
-	private $activityManager;
73
-
74
-	/** @var INotificationManager */
75
-	private $notificationManager;
76
-
77
-	/** @var IURLGenerator */
78
-	private $urlGenerator;
79
-
80
-	/** @var ICloudFederationFactory */
81
-	private $cloudFederationFactory;
82
-
83
-	/** @var ICloudFederationProviderManager */
84
-	private $cloudFederationProviderManager;
85
-
86
-	/** @var IDBConnection */
87
-	private $connection;
88
-
89
-	/**
90
-	 * CloudFederationProvider constructor.
91
-	 *
92
-	 * @param IAppManager $appManager
93
-	 * @param FederatedShareProvider $federatedShareProvider
94
-	 * @param AddressHandler $addressHandler
95
-	 * @param ILogger $logger
96
-	 * @param IUserManager $userManager
97
-	 * @param ICloudIdManager $cloudIdManager
98
-	 * @param IActivityManager $activityManager
99
-	 * @param INotificationManager $notificationManager
100
-	 * @param IURLGenerator $urlGenerator
101
-	 * @param ICloudFederationFactory $cloudFederationFactory
102
-	 * @param ICloudFederationProviderManager $cloudFederationProviderManager
103
-	 * @param IDBConnection $connection
104
-	 */
105
-	public function __construct(IAppManager $appManager,
106
-								FederatedShareProvider $federatedShareProvider,
107
-								AddressHandler $addressHandler,
108
-								ILogger $logger,
109
-								IUserManager $userManager,
110
-								ICloudIdManager $cloudIdManager,
111
-								IActivityManager $activityManager,
112
-								INotificationManager $notificationManager,
113
-								IURLGenerator $urlGenerator,
114
-								ICloudFederationFactory $cloudFederationFactory,
115
-								ICloudFederationProviderManager $cloudFederationProviderManager,
116
-								IDBConnection $connection
117
-	) {
118
-		$this->appManager = $appManager;
119
-		$this->federatedShareProvider = $federatedShareProvider;
120
-		$this->addressHandler = $addressHandler;
121
-		$this->logger = $logger;
122
-		$this->userManager = $userManager;
123
-		$this->cloudIdManager = $cloudIdManager;
124
-		$this->activityManager = $activityManager;
125
-		$this->notificationManager = $notificationManager;
126
-		$this->urlGenerator = $urlGenerator;
127
-		$this->cloudFederationFactory = $cloudFederationFactory;
128
-		$this->cloudFederationProviderManager = $cloudFederationProviderManager;
129
-		$this->connection = $connection;
130
-	}
131
-
132
-
133
-
134
-	/**
135
-	 * @return string
136
-	 */
137
-	public function getShareType() {
138
-		return 'file';
139
-	}
140
-
141
-	/**
142
-	 * share received from another server
143
-	 *
144
-	 * @param ICloudFederationShare $share
145
-	 * @return string provider specific unique ID of the share
146
-	 *
147
-	 * @throws ProviderCouldNotAddShareException
148
-	 * @throws \OCP\AppFramework\QueryException
149
-	 * @throws \OC\HintException
150
-	 * @since 14.0.0
151
-	 */
152
-	public function shareReceived(ICloudFederationShare $share) {
153
-
154
-		if (!$this->isS2SEnabled(true)) {
155
-			throw new ProviderCouldNotAddShareException('Server does not support federated cloud sharing', '', Http::STATUS_SERVICE_UNAVAILABLE);
156
-		}
157
-
158
-		$protocol = $share->getProtocol();
159
-		if ($protocol['name'] !== 'webdav') {
160
-			throw new ProviderCouldNotAddShareException('Unsupported protocol for data exchange.', '', Http::STATUS_NOT_IMPLEMENTED);
161
-		}
162
-
163
-		list($ownerUid, $remote) = $this->addressHandler->splitUserRemote($share->getOwner());
164
-
165
-		$token = $share->getShareSecret();
166
-		$name = $share->getResourceName();
167
-		$owner = $share->getOwnerDisplayName();
168
-		$sharedBy = $share->getSharedByDisplayName();
169
-		$shareWith = $share->getShareWith();
170
-		$remoteId = $share->getProviderId();
171
-		$sharedByFederatedId = $share->getSharedBy();
172
-		$ownerFederatedId = $share->getOwner();
173
-
174
-		// if no explicit information about the person who created the share was send
175
-		// we assume that the share comes from the owner
176
-		if ($sharedByFederatedId === null) {
177
-			$sharedBy = $owner;
178
-			$sharedByFederatedId = $ownerFederatedId;
179
-		}
180
-
181
-		if ($remote && $token && $name && $owner && $remoteId && $shareWith) {
182
-
183
-			if (!Util::isValidFileName($name)) {
184
-				throw new ProviderCouldNotAddShareException('The mountpoint name contains invalid characters.', '', Http::STATUS_BAD_REQUEST);
185
-			}
186
-
187
-			// FIXME this should be a method in the user management instead
188
-			$this->logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']);
189
-			Util::emitHook(
190
-				'\OCA\Files_Sharing\API\Server2Server',
191
-				'preLoginNameUsedAsUserName',
192
-				array('uid' => &$shareWith)
193
-			);
194
-			$this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']);
195
-
196
-			if (!$this->userManager->userExists($shareWith)) {
197
-				throw new ProviderCouldNotAddShareException('User does not exists', '',Http::STATUS_BAD_REQUEST);
198
-			}
199
-
200
-			\OC_Util::setupFS($shareWith);
201
-
202
-			$externalManager = new \OCA\Files_Sharing\External\Manager(
203
-				\OC::$server->getDatabaseConnection(),
204
-				Filesystem::getMountManager(),
205
-				Filesystem::getLoader(),
206
-				\OC::$server->getHTTPClientService(),
207
-				\OC::$server->getNotificationManager(),
208
-				\OC::$server->query(\OCP\OCS\IDiscoveryService::class),
209
-				\OC::$server->getCloudFederationProviderManager(),
210
-				\OC::$server->getCloudFederationFactory(),
211
-				$shareWith
212
-			);
213
-
214
-			try {
215
-				$externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId);
216
-				$shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external');
217
-
218
-				$event = $this->activityManager->generateEvent();
219
-				$event->setApp('files_sharing')
220
-					->setType('remote_share')
221
-					->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')])
222
-					->setAffectedUser($shareWith)
223
-					->setObject('remote_share', (int)$shareId, $name);
224
-				\OC::$server->getActivityManager()->publish($event);
225
-
226
-				$notification = $this->notificationManager->createNotification();
227
-				$notification->setApp('files_sharing')
228
-					->setUser($shareWith)
229
-					->setDateTime(new \DateTime())
230
-					->setObject('remote_share', $shareId)
231
-					->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]);
232
-
233
-				$declineAction = $notification->createAction();
234
-				$declineAction->setLabel('decline')
235
-					->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE');
236
-				$notification->addAction($declineAction);
237
-
238
-				$acceptAction = $notification->createAction();
239
-				$acceptAction->setLabel('accept')
240
-					->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST');
241
-				$notification->addAction($acceptAction);
242
-
243
-				$this->notificationManager->notify($notification);
244
-
245
-				return $shareId;
246
-			} catch (\Exception $e) {
247
-				$this->logger->logException($e, [
248
-					'message' => 'Server can not add remote share.',
249
-					'level' => ILogger::ERROR,
250
-					'app' => 'files_sharing'
251
-				]);
252
-				throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from ' . $remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR);
253
-			}
254
-		}
255
-
256
-		throw new ProviderCouldNotAddShareException('server can not add remote share, missing parameter', '', HTTP::STATUS_BAD_REQUEST);
257
-
258
-	}
259
-
260
-	/**
261
-	 * notification received from another server
262
-	 *
263
-	 * @param string $notificationType (e.g. SHARE_ACCEPTED)
264
-	 * @param string $providerId id of the share
265
-	 * @param array $notification payload of the notification
266
-	 * @return array data send back to the sender
267
-	 *
268
-	 * @throws ActionNotSupportedException
269
-	 * @throws AuthenticationFailedException
270
-	 * @throws BadRequestException
271
-	 * @throws \OC\HintException
272
-	 * @since 14.0.0
273
-	 */
274
-	public function notificationReceived($notificationType, $providerId, array $notification) {
275
-
276
-		switch ($notificationType) {
277
-			case 'SHARE_ACCEPTED':
278
-				return $this->shareAccepted($providerId, $notification);
279
-			case 'SHARE_DECLINED':
280
-				return $this->shareDeclined($providerId, $notification);
281
-			case 'SHARE_UNSHARED':
282
-				return $this->unshare($providerId, $notification);
283
-			case 'REQUEST_RESHARE':
284
-				return $this->reshareRequested($providerId, $notification);
285
-			case 'RESHARE_UNDO':
286
-				return $this->undoReshare($providerId, $notification);
287
-			case 'RESHARE_CHANGE_PERMISSION':
288
-				return $this->updateResharePermissions($providerId, $notification);
289
-		}
290
-
291
-
292
-		throw new BadRequestException([$notificationType]);
293
-	}
294
-
295
-	/**
296
-	 * process notification that the recipient accepted a share
297
-	 *
298
-	 * @param string $id
299
-	 * @param array $notification
300
-	 * @return array
301
-	 * @throws ActionNotSupportedException
302
-	 * @throws AuthenticationFailedException
303
-	 * @throws BadRequestException
304
-	 * @throws \OC\HintException
305
-	 */
306
-	private function shareAccepted($id, array $notification) {
307
-
308
-		if (!$this->isS2SEnabled()) {
309
-			throw new ActionNotSupportedException('Server does not support federated cloud sharing');
310
-		}
311
-
312
-		if (!isset($notification['sharedSecret'])) {
313
-			throw new BadRequestException(['sharedSecret']);
314
-		}
315
-
316
-		$token = $notification['sharedSecret'];
317
-
318
-		$share = $this->federatedShareProvider->getShareById($id);
319
-
320
-		$this->verifyShare($share, $token);
321
-		$this->executeAcceptShare($share);
322
-		if ($share->getShareOwner() !== $share->getSharedBy()) {
323
-			list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
324
-			$remoteId = $this->federatedShareProvider->getRemoteId($share);
325
-			$notification = $this->cloudFederationFactory->getCloudFederationNotification();
326
-			$notification->setMessage(
327
-				'SHARE_ACCEPTED',
328
-				'file',
329
-				$remoteId,
330
-				[
331
-					'sharedSecret' => $token,
332
-					'message' => 'Recipient accepted the re-share'
333
-				]
334
-
335
-			);
336
-			$this->cloudFederationProviderManager->sendNotification($remote, $notification);
337
-
338
-		}
339
-
340
-		return [];
341
-	}
342
-
343
-	/**
344
-	 * @param IShare $share
345
-	 * @throws ShareNotFound
346
-	 */
347
-	protected function executeAcceptShare(IShare $share) {
348
-		try {
349
-			$fileId = (int)$share->getNode()->getId();
350
-			list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId);
351
-		} catch (\Exception $e) {
352
-			throw new ShareNotFound();
353
-		}
354
-
355
-		$event = $this->activityManager->generateEvent();
356
-		$event->setApp('files_sharing')
357
-			->setType('remote_share')
358
-			->setAffectedUser($this->getCorrectUid($share))
359
-			->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_ACCEPTED, [$share->getSharedWith(), [$fileId => $file]])
360
-			->setObject('files', $fileId, $file)
361
-			->setLink($link);
362
-		$this->activityManager->publish($event);
363
-	}
364
-
365
-	/**
366
-	 * process notification that the recipient declined a share
367
-	 *
368
-	 * @param string $id
369
-	 * @param array $notification
370
-	 * @return array
371
-	 * @throws ActionNotSupportedException
372
-	 * @throws AuthenticationFailedException
373
-	 * @throws BadRequestException
374
-	 * @throws ShareNotFound
375
-	 * @throws \OC\HintException
376
-	 *
377
-	 */
378
-	protected function shareDeclined($id, array $notification) {
379
-
380
-		if (!$this->isS2SEnabled()) {
381
-			throw new ActionNotSupportedException('Server does not support federated cloud sharing');
382
-		}
383
-
384
-		if (!isset($notification['sharedSecret'])) {
385
-			throw new BadRequestException(['sharedSecret']);
386
-		}
387
-
388
-		$token = $notification['sharedSecret'];
389
-
390
-		$share = $this->federatedShareProvider->getShareById($id);
391
-
392
-		$this->verifyShare($share, $token);
393
-
394
-		if ($share->getShareOwner() !== $share->getSharedBy()) {
395
-			list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
396
-			$remoteId = $this->federatedShareProvider->getRemoteId($share);
397
-			$notification = $this->cloudFederationFactory->getCloudFederationNotification();
398
-			$notification->setMessage(
399
-				'SHARE_DECLINED',
400
-				'file',
401
-				$remoteId,
402
-				[
403
-					'sharedSecret' => $token,
404
-					'message' => 'Recipient declined the re-share'
405
-				]
406
-
407
-			);
408
-			$this->cloudFederationProviderManager->sendNotification($remote, $notification);
409
-		}
410
-
411
-		$this->executeDeclineShare($share);
412
-
413
-		return [];
414
-
415
-	}
416
-
417
-	/**
418
-	 * delete declined share and create a activity
419
-	 *
420
-	 * @param IShare $share
421
-	 * @throws ShareNotFound
422
-	 */
423
-	protected function executeDeclineShare(IShare $share) {
424
-		$this->federatedShareProvider->removeShareFromTable($share);
425
-
426
-		try {
427
-			$fileId = (int)$share->getNode()->getId();
428
-			list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId);
429
-		} catch (\Exception $e) {
430
-			throw new ShareNotFound();
431
-		}
432
-
433
-		$event = $this->activityManager->generateEvent();
434
-		$event->setApp('files_sharing')
435
-			->setType('remote_share')
436
-			->setAffectedUser($this->getCorrectUid($share))
437
-			->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_DECLINED, [$share->getSharedWith(), [$fileId => $file]])
438
-			->setObject('files', $fileId, $file)
439
-			->setLink($link);
440
-		$this->activityManager->publish($event);
441
-
442
-	}
443
-
444
-	/**
445
-	 * received the notification that the owner unshared a file from you
446
-	 *
447
-	 * @param string $id
448
-	 * @param array $notification
449
-	 * @return array
450
-	 * @throws AuthenticationFailedException
451
-	 * @throws BadRequestException
452
-	 */
453
-	private function undoReshare($id, array $notification) {
454
-		if (!isset($notification['sharedSecret'])) {
455
-			throw new BadRequestException(['sharedSecret']);
456
-		}
457
-		$token = $notification['sharedSecret'];
458
-
459
-		$share = $this->federatedShareProvider->getShareById($id);
460
-
461
-		$this->verifyShare($share, $token);
462
-		$this->federatedShareProvider->removeShareFromTable($share);
463
-		return [];
464
-	}
465
-
466
-	/**
467
-	 * unshare file from self
468
-	 *
469
-	 * @param string $id
470
-	 * @param array $notification
471
-	 * @return array
472
-	 * @throws ActionNotSupportedException
473
-	 * @throws BadRequestException
474
-	 */
475
-	private function unshare($id, array $notification) {
476
-
477
-		if (!$this->isS2SEnabled(true)) {
478
-			throw new ActionNotSupportedException("incoming shares disabled!");
479
-		}
480
-
481
-		if (!isset($notification['sharedSecret'])) {
482
-			throw new BadRequestException(['sharedSecret']);
483
-		}
484
-		$token = $notification['sharedSecret'];
485
-
486
-		$qb = $this->connection->getQueryBuilder();
487
-		$qb->select('*')
488
-			->from('share_external')
489
-			->where(
490
-				$qb->expr()->andX(
491
-					$qb->expr()->eq('remote_id', $qb->createNamedParameter($id)),
492
-					$qb->expr()->eq('share_token', $qb->createNamedParameter($token))
493
-				)
494
-			);
495
-
496
-		$result = $qb->execute();
497
-		$share = $result->fetch();
498
-		$result->closeCursor();
499
-
500
-		if ($token && $id && !empty($share)) {
501
-
502
-			$remote = $this->cleanupRemote($share['remote']);
503
-
504
-			$owner = $this->cloudIdManager->getCloudId($share['owner'], $remote);
505
-			$mountpoint = $share['mountpoint'];
506
-			$user = $share['user'];
507
-
508
-			$qb = $this->connection->getQueryBuilder();
509
-			$qb->delete('share_external')
510
-				->where(
511
-					$qb->expr()->andX(
512
-						$qb->expr()->eq('remote_id', $qb->createNamedParameter($id)),
513
-						$qb->expr()->eq('share_token', $qb->createNamedParameter($token))
514
-					)
515
-				);
516
-
517
-			$qb->execute();
518
-
519
-			if ($share['accepted']) {
520
-				$path = trim($mountpoint, '/');
521
-			} else {
522
-				$path = trim($share['name'], '/');
523
-			}
524
-
525
-			$notification = $this->notificationManager->createNotification();
526
-			$notification->setApp('files_sharing')
527
-				->setUser($share['user'])
528
-				->setObject('remote_share', (int)$share['id']);
529
-			$this->notificationManager->markProcessed($notification);
530
-
531
-			$event = $this->activityManager->generateEvent();
532
-			$event->setApp('files_sharing')
533
-				->setType('remote_share')
534
-				->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner->getId(), $path])
535
-				->setAffectedUser($user)
536
-				->setObject('remote_share', (int)$share['id'], $path);
537
-			\OC::$server->getActivityManager()->publish($event);
538
-		}
539
-
540
-		return [];
541
-	}
542
-
543
-	private function cleanupRemote($remote) {
544
-		$remote = substr($remote, strpos($remote, '://') + 3);
545
-
546
-		return rtrim($remote, '/');
547
-	}
548
-
549
-	/**
550
-	 * recipient of a share request to re-share the file with another user
551
-	 *
552
-	 * @param string $id
553
-	 * @param array $notification
554
-	 * @return array
555
-	 * @throws AuthenticationFailedException
556
-	 * @throws BadRequestException
557
-	 * @throws ProviderCouldNotAddShareException
558
-	 * @throws ShareNotFound
559
-	 */
560
-	protected function reshareRequested($id, array $notification) {
561
-
562
-		if (!isset($notification['sharedSecret'])) {
563
-			throw new BadRequestException(['sharedSecret']);
564
-		}
565
-		$token = $notification['sharedSecret'];
566
-
567
-		if (!isset($notification['shareWith'])) {
568
-			throw new BadRequestException(['shareWith']);
569
-		}
570
-		$shareWith = $notification['shareWith'];
571
-
572
-		if (!isset($notification['senderId'])) {
573
-			throw new BadRequestException(['senderId']);
574
-		}
575
-		$senderId = $notification['senderId'];
576
-
577
-		$share = $this->federatedShareProvider->getShareById($id);
578
-		// don't allow to share a file back to the owner
579
-		try {
580
-			list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith);
581
-			$owner = $share->getShareOwner();
582
-			$currentServer = $this->addressHandler->generateRemoteURL();
583
-			if ($this->addressHandler->compareAddresses($user, $remote, $owner, $currentServer)) {
584
-				throw new ProviderCouldNotAddShareException('Resharing back to the owner is not allowed: ' . $id);
585
-			}
586
-		} catch (\Exception $e) {
587
-			throw new ProviderCouldNotAddShareException($e->getMessage());
588
-		}
589
-
590
-		$this->verifyShare($share, $token);
591
-
592
-		// check if re-sharing is allowed
593
-		if ($share->getPermissions() & Constants::PERMISSION_SHARE) {
594
-			// the recipient of the initial share is now the initiator for the re-share
595
-			$share->setSharedBy($share->getSharedWith());
596
-			$share->setSharedWith($shareWith);
597
-			$result = $this->federatedShareProvider->create($share);
598
-			$this->federatedShareProvider->storeRemoteId((int)$result->getId(), $senderId);
599
-			return ['token' => $result->getToken(), 'providerId' => $result->getId()];
600
-		} else {
601
-			throw new ProviderCouldNotAddShareException('resharing not allowed for share: ' . $id);
602
-		}
603
-
604
-	}
605
-
606
-	/**
607
-	 * update permission of a re-share so that the share dialog shows the right
608
-	 * permission if the owner or the sender changes the permission
609
-	 *
610
-	 * @param string $id
611
-	 * @param array $notification
612
-	 * @return array
613
-	 * @throws AuthenticationFailedException
614
-	 * @throws BadRequestException
615
-	 */
616
-	protected function updateResharePermissions($id, array $notification) {
617
-
618
-		if (!isset($notification['sharedSecret'])) {
619
-			throw new BadRequestException(['sharedSecret']);
620
-		}
621
-		$token = $notification['sharedSecret'];
622
-
623
-		if (!isset($notification['permission'])) {
624
-			throw new BadRequestException(['permission']);
625
-		}
626
-		$ocmPermissions = $notification['permission'];
627
-
628
-		$share = $this->federatedShareProvider->getShareById($id);
629
-
630
-		$ncPermission = $this->ocmPermissions2ncPermissions($ocmPermissions);
631
-
632
-		$this->verifyShare($share, $token);
633
-		$this->updatePermissionsInDatabase($share, $ncPermission);
634
-
635
-		return [];
636
-	}
637
-
638
-	/**
639
-	 * translate OCM Permissions to Nextcloud permissions
640
-	 *
641
-	 * @param array $ocmPermissions
642
-	 * @return int
643
-	 * @throws BadRequestException
644
-	 */
645
-	protected function ocmPermissions2ncPermissions(array $ocmPermissions) {
646
-		$ncPermissions = 0;
647
-		foreach($ocmPermissions as $permission) {
648
-			switch (strtolower($permission)) {
649
-				case 'read':
650
-					$ncPermissions += Constants::PERMISSION_READ;
651
-					break;
652
-				case 'write':
653
-					$ncPermissions += Constants::PERMISSION_CREATE + Constants::PERMISSION_UPDATE;
654
-					break;
655
-				case 'share':
656
-					$ncPermissions += Constants::PERMISSION_SHARE;
657
-					break;
658
-				default:
659
-					throw new BadRequestException(['permission']);
660
-			}
661
-
662
-			error_log("new permissions: " . $ncPermissions);
663
-		}
664
-
665
-		return $ncPermissions;
666
-	}
667
-
668
-	/**
669
-	 * update permissions in database
670
-	 *
671
-	 * @param IShare $share
672
-	 * @param int $permissions
673
-	 */
674
-	protected function updatePermissionsInDatabase(IShare $share, $permissions) {
675
-		$query = $this->connection->getQueryBuilder();
676
-		$query->update('share')
677
-			->where($query->expr()->eq('id', $query->createNamedParameter($share->getId())))
678
-			->set('permissions', $query->createNamedParameter($permissions))
679
-			->execute();
680
-	}
681
-
682
-
683
-	/**
684
-	 * get file
685
-	 *
686
-	 * @param string $user
687
-	 * @param int $fileSource
688
-	 * @return array with internal path of the file and a absolute link to it
689
-	 */
690
-	private function getFile($user, $fileSource) {
691
-		\OC_Util::setupFS($user);
692
-
693
-		try {
694
-			$file = Filesystem::getPath($fileSource);
695
-		} catch (NotFoundException $e) {
696
-			$file = null;
697
-		}
698
-		$args = Filesystem::is_dir($file) ? array('dir' => $file) : array('dir' => dirname($file), 'scrollto' => $file);
699
-		$link = Util::linkToAbsolute('files', 'index.php', $args);
700
-
701
-		return [$file, $link];
702
-
703
-	}
704
-
705
-	/**
706
-	 * check if we are the initiator or the owner of a re-share and return the correct UID
707
-	 *
708
-	 * @param IShare $share
709
-	 * @return string
710
-	 */
711
-	protected function getCorrectUid(IShare $share) {
712
-		if ($this->userManager->userExists($share->getShareOwner())) {
713
-			return $share->getShareOwner();
714
-		}
715
-
716
-		return $share->getSharedBy();
717
-	}
718
-
719
-
720
-
721
-	/**
722
-	 * check if we got the right share
723
-	 *
724
-	 * @param IShare $share
725
-	 * @param string $token
726
-	 * @return bool
727
-	 * @throws AuthenticationFailedException
728
-	 */
729
-	protected function verifyShare(IShare $share, $token) {
730
-		if (
731
-			$share->getShareType() === FederatedShareProvider::SHARE_TYPE_REMOTE &&
732
-			$share->getToken() === $token
733
-		) {
734
-			return true;
735
-		}
736
-
737
-		throw new AuthenticationFailedException();
738
-	}
739
-
740
-
741
-
742
-	/**
743
-	 * check if server-to-server sharing is enabled
744
-	 *
745
-	 * @param bool $incoming
746
-	 * @return bool
747
-	 */
748
-	private function isS2SEnabled($incoming = false) {
749
-
750
-		$result = $this->appManager->isEnabledForUser('files_sharing');
751
-
752
-		if ($incoming) {
753
-			$result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled();
754
-		} else {
755
-			$result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled();
756
-		}
757
-
758
-		return $result;
759
-	}
53
+    /** @var IAppManager */
54
+    private $appManager;
55
+
56
+    /** @var FederatedShareProvider */
57
+    private $federatedShareProvider;
58
+
59
+    /** @var AddressHandler */
60
+    private $addressHandler;
61
+
62
+    /** @var ILogger */
63
+    private $logger;
64
+
65
+    /** @var IUserManager */
66
+    private $userManager;
67
+
68
+    /** @var ICloudIdManager */
69
+    private $cloudIdManager;
70
+
71
+    /** @var IActivityManager */
72
+    private $activityManager;
73
+
74
+    /** @var INotificationManager */
75
+    private $notificationManager;
76
+
77
+    /** @var IURLGenerator */
78
+    private $urlGenerator;
79
+
80
+    /** @var ICloudFederationFactory */
81
+    private $cloudFederationFactory;
82
+
83
+    /** @var ICloudFederationProviderManager */
84
+    private $cloudFederationProviderManager;
85
+
86
+    /** @var IDBConnection */
87
+    private $connection;
88
+
89
+    /**
90
+     * CloudFederationProvider constructor.
91
+     *
92
+     * @param IAppManager $appManager
93
+     * @param FederatedShareProvider $federatedShareProvider
94
+     * @param AddressHandler $addressHandler
95
+     * @param ILogger $logger
96
+     * @param IUserManager $userManager
97
+     * @param ICloudIdManager $cloudIdManager
98
+     * @param IActivityManager $activityManager
99
+     * @param INotificationManager $notificationManager
100
+     * @param IURLGenerator $urlGenerator
101
+     * @param ICloudFederationFactory $cloudFederationFactory
102
+     * @param ICloudFederationProviderManager $cloudFederationProviderManager
103
+     * @param IDBConnection $connection
104
+     */
105
+    public function __construct(IAppManager $appManager,
106
+                                FederatedShareProvider $federatedShareProvider,
107
+                                AddressHandler $addressHandler,
108
+                                ILogger $logger,
109
+                                IUserManager $userManager,
110
+                                ICloudIdManager $cloudIdManager,
111
+                                IActivityManager $activityManager,
112
+                                INotificationManager $notificationManager,
113
+                                IURLGenerator $urlGenerator,
114
+                                ICloudFederationFactory $cloudFederationFactory,
115
+                                ICloudFederationProviderManager $cloudFederationProviderManager,
116
+                                IDBConnection $connection
117
+    ) {
118
+        $this->appManager = $appManager;
119
+        $this->federatedShareProvider = $federatedShareProvider;
120
+        $this->addressHandler = $addressHandler;
121
+        $this->logger = $logger;
122
+        $this->userManager = $userManager;
123
+        $this->cloudIdManager = $cloudIdManager;
124
+        $this->activityManager = $activityManager;
125
+        $this->notificationManager = $notificationManager;
126
+        $this->urlGenerator = $urlGenerator;
127
+        $this->cloudFederationFactory = $cloudFederationFactory;
128
+        $this->cloudFederationProviderManager = $cloudFederationProviderManager;
129
+        $this->connection = $connection;
130
+    }
131
+
132
+
133
+
134
+    /**
135
+     * @return string
136
+     */
137
+    public function getShareType() {
138
+        return 'file';
139
+    }
140
+
141
+    /**
142
+     * share received from another server
143
+     *
144
+     * @param ICloudFederationShare $share
145
+     * @return string provider specific unique ID of the share
146
+     *
147
+     * @throws ProviderCouldNotAddShareException
148
+     * @throws \OCP\AppFramework\QueryException
149
+     * @throws \OC\HintException
150
+     * @since 14.0.0
151
+     */
152
+    public function shareReceived(ICloudFederationShare $share) {
153
+
154
+        if (!$this->isS2SEnabled(true)) {
155
+            throw new ProviderCouldNotAddShareException('Server does not support federated cloud sharing', '', Http::STATUS_SERVICE_UNAVAILABLE);
156
+        }
157
+
158
+        $protocol = $share->getProtocol();
159
+        if ($protocol['name'] !== 'webdav') {
160
+            throw new ProviderCouldNotAddShareException('Unsupported protocol for data exchange.', '', Http::STATUS_NOT_IMPLEMENTED);
161
+        }
162
+
163
+        list($ownerUid, $remote) = $this->addressHandler->splitUserRemote($share->getOwner());
164
+
165
+        $token = $share->getShareSecret();
166
+        $name = $share->getResourceName();
167
+        $owner = $share->getOwnerDisplayName();
168
+        $sharedBy = $share->getSharedByDisplayName();
169
+        $shareWith = $share->getShareWith();
170
+        $remoteId = $share->getProviderId();
171
+        $sharedByFederatedId = $share->getSharedBy();
172
+        $ownerFederatedId = $share->getOwner();
173
+
174
+        // if no explicit information about the person who created the share was send
175
+        // we assume that the share comes from the owner
176
+        if ($sharedByFederatedId === null) {
177
+            $sharedBy = $owner;
178
+            $sharedByFederatedId = $ownerFederatedId;
179
+        }
180
+
181
+        if ($remote && $token && $name && $owner && $remoteId && $shareWith) {
182
+
183
+            if (!Util::isValidFileName($name)) {
184
+                throw new ProviderCouldNotAddShareException('The mountpoint name contains invalid characters.', '', Http::STATUS_BAD_REQUEST);
185
+            }
186
+
187
+            // FIXME this should be a method in the user management instead
188
+            $this->logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']);
189
+            Util::emitHook(
190
+                '\OCA\Files_Sharing\API\Server2Server',
191
+                'preLoginNameUsedAsUserName',
192
+                array('uid' => &$shareWith)
193
+            );
194
+            $this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']);
195
+
196
+            if (!$this->userManager->userExists($shareWith)) {
197
+                throw new ProviderCouldNotAddShareException('User does not exists', '',Http::STATUS_BAD_REQUEST);
198
+            }
199
+
200
+            \OC_Util::setupFS($shareWith);
201
+
202
+            $externalManager = new \OCA\Files_Sharing\External\Manager(
203
+                \OC::$server->getDatabaseConnection(),
204
+                Filesystem::getMountManager(),
205
+                Filesystem::getLoader(),
206
+                \OC::$server->getHTTPClientService(),
207
+                \OC::$server->getNotificationManager(),
208
+                \OC::$server->query(\OCP\OCS\IDiscoveryService::class),
209
+                \OC::$server->getCloudFederationProviderManager(),
210
+                \OC::$server->getCloudFederationFactory(),
211
+                $shareWith
212
+            );
213
+
214
+            try {
215
+                $externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId);
216
+                $shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external');
217
+
218
+                $event = $this->activityManager->generateEvent();
219
+                $event->setApp('files_sharing')
220
+                    ->setType('remote_share')
221
+                    ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')])
222
+                    ->setAffectedUser($shareWith)
223
+                    ->setObject('remote_share', (int)$shareId, $name);
224
+                \OC::$server->getActivityManager()->publish($event);
225
+
226
+                $notification = $this->notificationManager->createNotification();
227
+                $notification->setApp('files_sharing')
228
+                    ->setUser($shareWith)
229
+                    ->setDateTime(new \DateTime())
230
+                    ->setObject('remote_share', $shareId)
231
+                    ->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]);
232
+
233
+                $declineAction = $notification->createAction();
234
+                $declineAction->setLabel('decline')
235
+                    ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE');
236
+                $notification->addAction($declineAction);
237
+
238
+                $acceptAction = $notification->createAction();
239
+                $acceptAction->setLabel('accept')
240
+                    ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST');
241
+                $notification->addAction($acceptAction);
242
+
243
+                $this->notificationManager->notify($notification);
244
+
245
+                return $shareId;
246
+            } catch (\Exception $e) {
247
+                $this->logger->logException($e, [
248
+                    'message' => 'Server can not add remote share.',
249
+                    'level' => ILogger::ERROR,
250
+                    'app' => 'files_sharing'
251
+                ]);
252
+                throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from ' . $remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR);
253
+            }
254
+        }
255
+
256
+        throw new ProviderCouldNotAddShareException('server can not add remote share, missing parameter', '', HTTP::STATUS_BAD_REQUEST);
257
+
258
+    }
259
+
260
+    /**
261
+     * notification received from another server
262
+     *
263
+     * @param string $notificationType (e.g. SHARE_ACCEPTED)
264
+     * @param string $providerId id of the share
265
+     * @param array $notification payload of the notification
266
+     * @return array data send back to the sender
267
+     *
268
+     * @throws ActionNotSupportedException
269
+     * @throws AuthenticationFailedException
270
+     * @throws BadRequestException
271
+     * @throws \OC\HintException
272
+     * @since 14.0.0
273
+     */
274
+    public function notificationReceived($notificationType, $providerId, array $notification) {
275
+
276
+        switch ($notificationType) {
277
+            case 'SHARE_ACCEPTED':
278
+                return $this->shareAccepted($providerId, $notification);
279
+            case 'SHARE_DECLINED':
280
+                return $this->shareDeclined($providerId, $notification);
281
+            case 'SHARE_UNSHARED':
282
+                return $this->unshare($providerId, $notification);
283
+            case 'REQUEST_RESHARE':
284
+                return $this->reshareRequested($providerId, $notification);
285
+            case 'RESHARE_UNDO':
286
+                return $this->undoReshare($providerId, $notification);
287
+            case 'RESHARE_CHANGE_PERMISSION':
288
+                return $this->updateResharePermissions($providerId, $notification);
289
+        }
290
+
291
+
292
+        throw new BadRequestException([$notificationType]);
293
+    }
294
+
295
+    /**
296
+     * process notification that the recipient accepted a share
297
+     *
298
+     * @param string $id
299
+     * @param array $notification
300
+     * @return array
301
+     * @throws ActionNotSupportedException
302
+     * @throws AuthenticationFailedException
303
+     * @throws BadRequestException
304
+     * @throws \OC\HintException
305
+     */
306
+    private function shareAccepted($id, array $notification) {
307
+
308
+        if (!$this->isS2SEnabled()) {
309
+            throw new ActionNotSupportedException('Server does not support federated cloud sharing');
310
+        }
311
+
312
+        if (!isset($notification['sharedSecret'])) {
313
+            throw new BadRequestException(['sharedSecret']);
314
+        }
315
+
316
+        $token = $notification['sharedSecret'];
317
+
318
+        $share = $this->federatedShareProvider->getShareById($id);
319
+
320
+        $this->verifyShare($share, $token);
321
+        $this->executeAcceptShare($share);
322
+        if ($share->getShareOwner() !== $share->getSharedBy()) {
323
+            list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
324
+            $remoteId = $this->federatedShareProvider->getRemoteId($share);
325
+            $notification = $this->cloudFederationFactory->getCloudFederationNotification();
326
+            $notification->setMessage(
327
+                'SHARE_ACCEPTED',
328
+                'file',
329
+                $remoteId,
330
+                [
331
+                    'sharedSecret' => $token,
332
+                    'message' => 'Recipient accepted the re-share'
333
+                ]
334
+
335
+            );
336
+            $this->cloudFederationProviderManager->sendNotification($remote, $notification);
337
+
338
+        }
339
+
340
+        return [];
341
+    }
342
+
343
+    /**
344
+     * @param IShare $share
345
+     * @throws ShareNotFound
346
+     */
347
+    protected function executeAcceptShare(IShare $share) {
348
+        try {
349
+            $fileId = (int)$share->getNode()->getId();
350
+            list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId);
351
+        } catch (\Exception $e) {
352
+            throw new ShareNotFound();
353
+        }
354
+
355
+        $event = $this->activityManager->generateEvent();
356
+        $event->setApp('files_sharing')
357
+            ->setType('remote_share')
358
+            ->setAffectedUser($this->getCorrectUid($share))
359
+            ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_ACCEPTED, [$share->getSharedWith(), [$fileId => $file]])
360
+            ->setObject('files', $fileId, $file)
361
+            ->setLink($link);
362
+        $this->activityManager->publish($event);
363
+    }
364
+
365
+    /**
366
+     * process notification that the recipient declined a share
367
+     *
368
+     * @param string $id
369
+     * @param array $notification
370
+     * @return array
371
+     * @throws ActionNotSupportedException
372
+     * @throws AuthenticationFailedException
373
+     * @throws BadRequestException
374
+     * @throws ShareNotFound
375
+     * @throws \OC\HintException
376
+     *
377
+     */
378
+    protected function shareDeclined($id, array $notification) {
379
+
380
+        if (!$this->isS2SEnabled()) {
381
+            throw new ActionNotSupportedException('Server does not support federated cloud sharing');
382
+        }
383
+
384
+        if (!isset($notification['sharedSecret'])) {
385
+            throw new BadRequestException(['sharedSecret']);
386
+        }
387
+
388
+        $token = $notification['sharedSecret'];
389
+
390
+        $share = $this->federatedShareProvider->getShareById($id);
391
+
392
+        $this->verifyShare($share, $token);
393
+
394
+        if ($share->getShareOwner() !== $share->getSharedBy()) {
395
+            list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
396
+            $remoteId = $this->federatedShareProvider->getRemoteId($share);
397
+            $notification = $this->cloudFederationFactory->getCloudFederationNotification();
398
+            $notification->setMessage(
399
+                'SHARE_DECLINED',
400
+                'file',
401
+                $remoteId,
402
+                [
403
+                    'sharedSecret' => $token,
404
+                    'message' => 'Recipient declined the re-share'
405
+                ]
406
+
407
+            );
408
+            $this->cloudFederationProviderManager->sendNotification($remote, $notification);
409
+        }
410
+
411
+        $this->executeDeclineShare($share);
412
+
413
+        return [];
414
+
415
+    }
416
+
417
+    /**
418
+     * delete declined share and create a activity
419
+     *
420
+     * @param IShare $share
421
+     * @throws ShareNotFound
422
+     */
423
+    protected function executeDeclineShare(IShare $share) {
424
+        $this->federatedShareProvider->removeShareFromTable($share);
425
+
426
+        try {
427
+            $fileId = (int)$share->getNode()->getId();
428
+            list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId);
429
+        } catch (\Exception $e) {
430
+            throw new ShareNotFound();
431
+        }
432
+
433
+        $event = $this->activityManager->generateEvent();
434
+        $event->setApp('files_sharing')
435
+            ->setType('remote_share')
436
+            ->setAffectedUser($this->getCorrectUid($share))
437
+            ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_DECLINED, [$share->getSharedWith(), [$fileId => $file]])
438
+            ->setObject('files', $fileId, $file)
439
+            ->setLink($link);
440
+        $this->activityManager->publish($event);
441
+
442
+    }
443
+
444
+    /**
445
+     * received the notification that the owner unshared a file from you
446
+     *
447
+     * @param string $id
448
+     * @param array $notification
449
+     * @return array
450
+     * @throws AuthenticationFailedException
451
+     * @throws BadRequestException
452
+     */
453
+    private function undoReshare($id, array $notification) {
454
+        if (!isset($notification['sharedSecret'])) {
455
+            throw new BadRequestException(['sharedSecret']);
456
+        }
457
+        $token = $notification['sharedSecret'];
458
+
459
+        $share = $this->federatedShareProvider->getShareById($id);
460
+
461
+        $this->verifyShare($share, $token);
462
+        $this->federatedShareProvider->removeShareFromTable($share);
463
+        return [];
464
+    }
465
+
466
+    /**
467
+     * unshare file from self
468
+     *
469
+     * @param string $id
470
+     * @param array $notification
471
+     * @return array
472
+     * @throws ActionNotSupportedException
473
+     * @throws BadRequestException
474
+     */
475
+    private function unshare($id, array $notification) {
476
+
477
+        if (!$this->isS2SEnabled(true)) {
478
+            throw new ActionNotSupportedException("incoming shares disabled!");
479
+        }
480
+
481
+        if (!isset($notification['sharedSecret'])) {
482
+            throw new BadRequestException(['sharedSecret']);
483
+        }
484
+        $token = $notification['sharedSecret'];
485
+
486
+        $qb = $this->connection->getQueryBuilder();
487
+        $qb->select('*')
488
+            ->from('share_external')
489
+            ->where(
490
+                $qb->expr()->andX(
491
+                    $qb->expr()->eq('remote_id', $qb->createNamedParameter($id)),
492
+                    $qb->expr()->eq('share_token', $qb->createNamedParameter($token))
493
+                )
494
+            );
495
+
496
+        $result = $qb->execute();
497
+        $share = $result->fetch();
498
+        $result->closeCursor();
499
+
500
+        if ($token && $id && !empty($share)) {
501
+
502
+            $remote = $this->cleanupRemote($share['remote']);
503
+
504
+            $owner = $this->cloudIdManager->getCloudId($share['owner'], $remote);
505
+            $mountpoint = $share['mountpoint'];
506
+            $user = $share['user'];
507
+
508
+            $qb = $this->connection->getQueryBuilder();
509
+            $qb->delete('share_external')
510
+                ->where(
511
+                    $qb->expr()->andX(
512
+                        $qb->expr()->eq('remote_id', $qb->createNamedParameter($id)),
513
+                        $qb->expr()->eq('share_token', $qb->createNamedParameter($token))
514
+                    )
515
+                );
516
+
517
+            $qb->execute();
518
+
519
+            if ($share['accepted']) {
520
+                $path = trim($mountpoint, '/');
521
+            } else {
522
+                $path = trim($share['name'], '/');
523
+            }
524
+
525
+            $notification = $this->notificationManager->createNotification();
526
+            $notification->setApp('files_sharing')
527
+                ->setUser($share['user'])
528
+                ->setObject('remote_share', (int)$share['id']);
529
+            $this->notificationManager->markProcessed($notification);
530
+
531
+            $event = $this->activityManager->generateEvent();
532
+            $event->setApp('files_sharing')
533
+                ->setType('remote_share')
534
+                ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner->getId(), $path])
535
+                ->setAffectedUser($user)
536
+                ->setObject('remote_share', (int)$share['id'], $path);
537
+            \OC::$server->getActivityManager()->publish($event);
538
+        }
539
+
540
+        return [];
541
+    }
542
+
543
+    private function cleanupRemote($remote) {
544
+        $remote = substr($remote, strpos($remote, '://') + 3);
545
+
546
+        return rtrim($remote, '/');
547
+    }
548
+
549
+    /**
550
+     * recipient of a share request to re-share the file with another user
551
+     *
552
+     * @param string $id
553
+     * @param array $notification
554
+     * @return array
555
+     * @throws AuthenticationFailedException
556
+     * @throws BadRequestException
557
+     * @throws ProviderCouldNotAddShareException
558
+     * @throws ShareNotFound
559
+     */
560
+    protected function reshareRequested($id, array $notification) {
561
+
562
+        if (!isset($notification['sharedSecret'])) {
563
+            throw new BadRequestException(['sharedSecret']);
564
+        }
565
+        $token = $notification['sharedSecret'];
566
+
567
+        if (!isset($notification['shareWith'])) {
568
+            throw new BadRequestException(['shareWith']);
569
+        }
570
+        $shareWith = $notification['shareWith'];
571
+
572
+        if (!isset($notification['senderId'])) {
573
+            throw new BadRequestException(['senderId']);
574
+        }
575
+        $senderId = $notification['senderId'];
576
+
577
+        $share = $this->federatedShareProvider->getShareById($id);
578
+        // don't allow to share a file back to the owner
579
+        try {
580
+            list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith);
581
+            $owner = $share->getShareOwner();
582
+            $currentServer = $this->addressHandler->generateRemoteURL();
583
+            if ($this->addressHandler->compareAddresses($user, $remote, $owner, $currentServer)) {
584
+                throw new ProviderCouldNotAddShareException('Resharing back to the owner is not allowed: ' . $id);
585
+            }
586
+        } catch (\Exception $e) {
587
+            throw new ProviderCouldNotAddShareException($e->getMessage());
588
+        }
589
+
590
+        $this->verifyShare($share, $token);
591
+
592
+        // check if re-sharing is allowed
593
+        if ($share->getPermissions() & Constants::PERMISSION_SHARE) {
594
+            // the recipient of the initial share is now the initiator for the re-share
595
+            $share->setSharedBy($share->getSharedWith());
596
+            $share->setSharedWith($shareWith);
597
+            $result = $this->federatedShareProvider->create($share);
598
+            $this->federatedShareProvider->storeRemoteId((int)$result->getId(), $senderId);
599
+            return ['token' => $result->getToken(), 'providerId' => $result->getId()];
600
+        } else {
601
+            throw new ProviderCouldNotAddShareException('resharing not allowed for share: ' . $id);
602
+        }
603
+
604
+    }
605
+
606
+    /**
607
+     * update permission of a re-share so that the share dialog shows the right
608
+     * permission if the owner or the sender changes the permission
609
+     *
610
+     * @param string $id
611
+     * @param array $notification
612
+     * @return array
613
+     * @throws AuthenticationFailedException
614
+     * @throws BadRequestException
615
+     */
616
+    protected function updateResharePermissions($id, array $notification) {
617
+
618
+        if (!isset($notification['sharedSecret'])) {
619
+            throw new BadRequestException(['sharedSecret']);
620
+        }
621
+        $token = $notification['sharedSecret'];
622
+
623
+        if (!isset($notification['permission'])) {
624
+            throw new BadRequestException(['permission']);
625
+        }
626
+        $ocmPermissions = $notification['permission'];
627
+
628
+        $share = $this->federatedShareProvider->getShareById($id);
629
+
630
+        $ncPermission = $this->ocmPermissions2ncPermissions($ocmPermissions);
631
+
632
+        $this->verifyShare($share, $token);
633
+        $this->updatePermissionsInDatabase($share, $ncPermission);
634
+
635
+        return [];
636
+    }
637
+
638
+    /**
639
+     * translate OCM Permissions to Nextcloud permissions
640
+     *
641
+     * @param array $ocmPermissions
642
+     * @return int
643
+     * @throws BadRequestException
644
+     */
645
+    protected function ocmPermissions2ncPermissions(array $ocmPermissions) {
646
+        $ncPermissions = 0;
647
+        foreach($ocmPermissions as $permission) {
648
+            switch (strtolower($permission)) {
649
+                case 'read':
650
+                    $ncPermissions += Constants::PERMISSION_READ;
651
+                    break;
652
+                case 'write':
653
+                    $ncPermissions += Constants::PERMISSION_CREATE + Constants::PERMISSION_UPDATE;
654
+                    break;
655
+                case 'share':
656
+                    $ncPermissions += Constants::PERMISSION_SHARE;
657
+                    break;
658
+                default:
659
+                    throw new BadRequestException(['permission']);
660
+            }
661
+
662
+            error_log("new permissions: " . $ncPermissions);
663
+        }
664
+
665
+        return $ncPermissions;
666
+    }
667
+
668
+    /**
669
+     * update permissions in database
670
+     *
671
+     * @param IShare $share
672
+     * @param int $permissions
673
+     */
674
+    protected function updatePermissionsInDatabase(IShare $share, $permissions) {
675
+        $query = $this->connection->getQueryBuilder();
676
+        $query->update('share')
677
+            ->where($query->expr()->eq('id', $query->createNamedParameter($share->getId())))
678
+            ->set('permissions', $query->createNamedParameter($permissions))
679
+            ->execute();
680
+    }
681
+
682
+
683
+    /**
684
+     * get file
685
+     *
686
+     * @param string $user
687
+     * @param int $fileSource
688
+     * @return array with internal path of the file and a absolute link to it
689
+     */
690
+    private function getFile($user, $fileSource) {
691
+        \OC_Util::setupFS($user);
692
+
693
+        try {
694
+            $file = Filesystem::getPath($fileSource);
695
+        } catch (NotFoundException $e) {
696
+            $file = null;
697
+        }
698
+        $args = Filesystem::is_dir($file) ? array('dir' => $file) : array('dir' => dirname($file), 'scrollto' => $file);
699
+        $link = Util::linkToAbsolute('files', 'index.php', $args);
700
+
701
+        return [$file, $link];
702
+
703
+    }
704
+
705
+    /**
706
+     * check if we are the initiator or the owner of a re-share and return the correct UID
707
+     *
708
+     * @param IShare $share
709
+     * @return string
710
+     */
711
+    protected function getCorrectUid(IShare $share) {
712
+        if ($this->userManager->userExists($share->getShareOwner())) {
713
+            return $share->getShareOwner();
714
+        }
715
+
716
+        return $share->getSharedBy();
717
+    }
718
+
719
+
720
+
721
+    /**
722
+     * check if we got the right share
723
+     *
724
+     * @param IShare $share
725
+     * @param string $token
726
+     * @return bool
727
+     * @throws AuthenticationFailedException
728
+     */
729
+    protected function verifyShare(IShare $share, $token) {
730
+        if (
731
+            $share->getShareType() === FederatedShareProvider::SHARE_TYPE_REMOTE &&
732
+            $share->getToken() === $token
733
+        ) {
734
+            return true;
735
+        }
736
+
737
+        throw new AuthenticationFailedException();
738
+    }
739
+
740
+
741
+
742
+    /**
743
+     * check if server-to-server sharing is enabled
744
+     *
745
+     * @param bool $incoming
746
+     * @return bool
747
+     */
748
+    private function isS2SEnabled($incoming = false) {
749
+
750
+        $result = $this->appManager->isEnabledForUser('files_sharing');
751
+
752
+        if ($incoming) {
753
+            $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled();
754
+        } else {
755
+            $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled();
756
+        }
757
+
758
+        return $result;
759
+    }
760 760
 
761 761
 
762 762
 }
Please login to merge, or discard this patch.
lib/private/Federation/CloudFederationNotification.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -32,36 +32,36 @@
 block discarded – undo
32 32
  */
33 33
 class CloudFederationNotification implements ICloudFederationNotification {
34 34
 
35
-	private $message = [];
35
+    private $message = [];
36 36
 
37
-	/**
38
-	 * add a message to the notification
39
-	 *
40
-	 * @param string $notificationType (e.g. SHARE_ACCEPTED)
41
-	 * @param string $resourceType (e.g. file, calendar, contact,...)
42
-	 * @param string $providerId id of the share
43
-	 * @param array $notification payload of the notification
44
-	 *
45
-	 * @since 14.0.0
46
-	 */
47
-	public function setMessage($notificationType, $resourceType, $providerId, array $notification) {
48
-		$this->message = [
49
-			'notificationType' => $notificationType,
50
-			'resourceType' => $resourceType,
51
-			'providerId' => $providerId,
52
-			'notification' => $notification,
53
-		];
37
+    /**
38
+     * add a message to the notification
39
+     *
40
+     * @param string $notificationType (e.g. SHARE_ACCEPTED)
41
+     * @param string $resourceType (e.g. file, calendar, contact,...)
42
+     * @param string $providerId id of the share
43
+     * @param array $notification payload of the notification
44
+     *
45
+     * @since 14.0.0
46
+     */
47
+    public function setMessage($notificationType, $resourceType, $providerId, array $notification) {
48
+        $this->message = [
49
+            'notificationType' => $notificationType,
50
+            'resourceType' => $resourceType,
51
+            'providerId' => $providerId,
52
+            'notification' => $notification,
53
+        ];
54 54
 
55
-	}
55
+    }
56 56
 
57
-	/**
58
-	 * get message, ready to send out
59
-	 *
60
-	 * @return array
61
-	 *
62
-	 * @since 14.0.0
63
-	 */
64
-	public function getMessage() {
65
-		return $this->message;
66
-	}
57
+    /**
58
+     * get message, ready to send out
59
+     *
60
+     * @return array
61
+     *
62
+     * @since 14.0.0
63
+     */
64
+    public function getMessage() {
65
+        return $this->message;
66
+    }
67 67
 }
Please login to merge, or discard this patch.
lib/private/Federation/CloudFederationProviderManager.php 1 patch
Indentation   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -42,191 +42,191 @@
 block discarded – undo
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 $shareType which share 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($shareType, $displayName, callable $callback) {
90
-		\OC::$server->getRemoteApiFactory();
91
-
92
-		$this->cloudFederationProvider[$shareType] = [
93
-			'shareType' => $shareType,
94
-			'displayName' => $displayName,
95
-			'callback' => $callback,
96
-		];
97
-
98
-	}
99
-
100
-	/**
101
-	 * remove cloud federation provider
102
-	 *
103
-	 * @param string $providerId
104
-	 */
105
-	public function removeCloudFederationProvider($providerId) {
106
-		unset($this->cloudFederationProvider[$providerId]);
107
-	}
108
-
109
-	/**
110
-	 * get a list of all cloudFederationProviders
111
-	 *
112
-	 * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]]
113
-	 */
114
-	public function getAllCloudFederationProviders() {
115
-		return $this->cloudFederationProvider;
116
-	}
117
-
118
-	/**
119
-	 * get a specific cloud federation provider
120
-	 *
121
-	 * @param string $shareType
122
-	 * @return ICloudFederationProvider
123
-	 * @throws ProviderDoesNotExistsException
124
-	 */
125
-	public function getCloudFederationProvider($shareType) {
126
-		if (isset($this->cloudFederationProvider[$shareType])) {
127
-			return call_user_func($this->cloudFederationProvider[$shareType]['callback']);
128
-		} else {
129
-			throw new ProviderDoesNotExistsException($shareType);
130
-		}
131
-	}
132
-
133
-	public function sendShare(ICloudFederationShare $share) {
134
-		$cloudID = $this->cloudIdManager->resolveCloudId($share->getShareWith());
135
-		$ocmEndPoint = $this->getOCMEndPoint($cloudID->getRemote());
136
-
137
-		if (empty($ocmEndPoint)) {
138
-			return false;
139
-		}
140
-
141
-		$client = $this->httpClientService->newClient();
142
-		try {
143
-			$response = $client->post($ocmEndPoint . '/shares', [
144
-				'body' => $share->getShare(),
145
-				'timeout' => 10,
146
-				'connect_timeout' => 10,
147
-			]);
148
-
149
-			if ($response->getStatusCode() === Http::STATUS_CREATED) {
150
-				return true;
151
-			}
152
-
153
-		} catch (\Exception $e) {
154
-			// if flat re-sharing is not supported by the remote server
155
-			// we re-throw the exception and fall back to the old behaviour.
156
-			// (flat re-shares has been introduced in Nextcloud 9.1)
157
-			if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) {
158
-				throw $e;
159
-			}
160
-		}
161
-
162
-		return false;
163
-
164
-	}
165
-
166
-	/**
167
-	 * @param string $url
168
-	 * @param ICloudFederationNotification $notification
169
-	 * @return mixed
170
-	 */
171
-	public function sendNotification($url, ICloudFederationNotification $notification) {
172
-		$ocmEndPoint = $this->getOCMEndPoint($url);
173
-
174
-		if (empty($ocmEndPoint)) {
175
-			return false;
176
-		}
177
-
178
-		$client = $this->httpClientService->newClient();
179
-		try {
180
-			$response = $client->post($ocmEndPoint . '/notifications', [
181
-				'body' => $notification->getMessage(),
182
-				'timeout' => 10,
183
-				'connect_timeout' => 10,
184
-			]);
185
-			if ($response->getStatusCode() === Http::STATUS_CREATED) {
186
-				$result = json_decode($response->getBody(), true);
187
-				return (is_array($result)) ? $result : [];
188
-			}
189
-		} catch (\Exception $e) {
190
-			// log the error and return false
191
-			$this->logger->error('error while sending notification for federated share: ' . $e->getMessage());
192
-		}
193
-
194
-		return false;
195
-	}
196
-
197
-	/**
198
-	 * check if the new cloud federation API is ready to be used
199
-	 *
200
-	 * @return bool
201
-	 */
202
-	public function isReady() {
203
-		return $this->appManager->isEnabledForUser('cloud_federation_api');
204
-	}
205
-	/**
206
-	 * check if server supports the new OCM api and ask for the correct end-point
207
-	 *
208
-	 * @param string $url full base URL of the cloud server
209
-	 * @return string
210
-	 */
211
-	protected function getOCMEndPoint($url) {
212
-		$client = $this->httpClientService->newClient();
213
-		try {
214
-			$response = $client->get($url . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]);
215
-		} catch (\Exception $e) {
216
-			return '';
217
-		}
218
-
219
-		$result = $response->getBody();
220
-		$result = json_decode($result, true);
221
-
222
-		$supportedVersion = isset($result['apiVersion']) && $result['apiVersion'] === $this->supportedAPIVersion;
223
-
224
-		if (isset($result['endPoint']) && $supportedVersion) {
225
-			return $result['endPoint'];
226
-		}
227
-
228
-		return '';
229
-	}
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 $shareType which share 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($shareType, $displayName, callable $callback) {
90
+        \OC::$server->getRemoteApiFactory();
91
+
92
+        $this->cloudFederationProvider[$shareType] = [
93
+            'shareType' => $shareType,
94
+            'displayName' => $displayName,
95
+            'callback' => $callback,
96
+        ];
97
+
98
+    }
99
+
100
+    /**
101
+     * remove cloud federation provider
102
+     *
103
+     * @param string $providerId
104
+     */
105
+    public function removeCloudFederationProvider($providerId) {
106
+        unset($this->cloudFederationProvider[$providerId]);
107
+    }
108
+
109
+    /**
110
+     * get a list of all cloudFederationProviders
111
+     *
112
+     * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]]
113
+     */
114
+    public function getAllCloudFederationProviders() {
115
+        return $this->cloudFederationProvider;
116
+    }
117
+
118
+    /**
119
+     * get a specific cloud federation provider
120
+     *
121
+     * @param string $shareType
122
+     * @return ICloudFederationProvider
123
+     * @throws ProviderDoesNotExistsException
124
+     */
125
+    public function getCloudFederationProvider($shareType) {
126
+        if (isset($this->cloudFederationProvider[$shareType])) {
127
+            return call_user_func($this->cloudFederationProvider[$shareType]['callback']);
128
+        } else {
129
+            throw new ProviderDoesNotExistsException($shareType);
130
+        }
131
+    }
132
+
133
+    public function sendShare(ICloudFederationShare $share) {
134
+        $cloudID = $this->cloudIdManager->resolveCloudId($share->getShareWith());
135
+        $ocmEndPoint = $this->getOCMEndPoint($cloudID->getRemote());
136
+
137
+        if (empty($ocmEndPoint)) {
138
+            return false;
139
+        }
140
+
141
+        $client = $this->httpClientService->newClient();
142
+        try {
143
+            $response = $client->post($ocmEndPoint . '/shares', [
144
+                'body' => $share->getShare(),
145
+                'timeout' => 10,
146
+                'connect_timeout' => 10,
147
+            ]);
148
+
149
+            if ($response->getStatusCode() === Http::STATUS_CREATED) {
150
+                return true;
151
+            }
152
+
153
+        } catch (\Exception $e) {
154
+            // if flat re-sharing is not supported by the remote server
155
+            // we re-throw the exception and fall back to the old behaviour.
156
+            // (flat re-shares has been introduced in Nextcloud 9.1)
157
+            if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) {
158
+                throw $e;
159
+            }
160
+        }
161
+
162
+        return false;
163
+
164
+    }
165
+
166
+    /**
167
+     * @param string $url
168
+     * @param ICloudFederationNotification $notification
169
+     * @return mixed
170
+     */
171
+    public function sendNotification($url, ICloudFederationNotification $notification) {
172
+        $ocmEndPoint = $this->getOCMEndPoint($url);
173
+
174
+        if (empty($ocmEndPoint)) {
175
+            return false;
176
+        }
177
+
178
+        $client = $this->httpClientService->newClient();
179
+        try {
180
+            $response = $client->post($ocmEndPoint . '/notifications', [
181
+                'body' => $notification->getMessage(),
182
+                'timeout' => 10,
183
+                'connect_timeout' => 10,
184
+            ]);
185
+            if ($response->getStatusCode() === Http::STATUS_CREATED) {
186
+                $result = json_decode($response->getBody(), true);
187
+                return (is_array($result)) ? $result : [];
188
+            }
189
+        } catch (\Exception $e) {
190
+            // log the error and return false
191
+            $this->logger->error('error while sending notification for federated share: ' . $e->getMessage());
192
+        }
193
+
194
+        return false;
195
+    }
196
+
197
+    /**
198
+     * check if the new cloud federation API is ready to be used
199
+     *
200
+     * @return bool
201
+     */
202
+    public function isReady() {
203
+        return $this->appManager->isEnabledForUser('cloud_federation_api');
204
+    }
205
+    /**
206
+     * check if server supports the new OCM api and ask for the correct end-point
207
+     *
208
+     * @param string $url full base URL of the cloud server
209
+     * @return string
210
+     */
211
+    protected function getOCMEndPoint($url) {
212
+        $client = $this->httpClientService->newClient();
213
+        try {
214
+            $response = $client->get($url . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]);
215
+        } catch (\Exception $e) {
216
+            return '';
217
+        }
218
+
219
+        $result = $response->getBody();
220
+        $result = json_decode($result, true);
221
+
222
+        $supportedVersion = isset($result['apiVersion']) && $result['apiVersion'] === $this->supportedAPIVersion;
223
+
224
+        if (isset($result['endPoint']) && $supportedVersion) {
225
+            return $result['endPoint'];
226
+        }
227
+
228
+        return '';
229
+    }
230 230
 
231 231
 
232 232
 }
Please login to merge, or discard this patch.
lib/public/Federation/ICloudFederationNotification.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -30,24 +30,24 @@
 block discarded – undo
30 30
  */
31 31
 interface ICloudFederationNotification {
32 32
 
33
-	/**
34
-	 * add a message to the notification
35
-	 *
36
-	 * @param string $notificationType (e.g. SHARE_ACCEPTED)
37
-	 * @param string $resourceType (e.g. file, calendar, contact,...)
38
-	 * @param $providerId id of the share
39
-	 * @param array $notification , payload of the notification
40
-	 *
41
-	 * @since 14.0.0
42
-	 */
43
-	public function setMessage($notificationType, $resourceType, $providerId, array $notification);
33
+    /**
34
+     * add a message to the notification
35
+     *
36
+     * @param string $notificationType (e.g. SHARE_ACCEPTED)
37
+     * @param string $resourceType (e.g. file, calendar, contact,...)
38
+     * @param $providerId id of the share
39
+     * @param array $notification , payload of the notification
40
+     *
41
+     * @since 14.0.0
42
+     */
43
+    public function setMessage($notificationType, $resourceType, $providerId, array $notification);
44 44
 
45
-	/**
46
-	 * get message, ready to send out
47
-	 *
48
-	 * @return array
49
-	 *
50
-	 * @since 14.0.0
51
-	 */
52
-	public function getMessage();
45
+    /**
46
+     * get message, ready to send out
47
+     *
48
+     * @return array
49
+     *
50
+     * @since 14.0.0
51
+     */
52
+    public function getMessage();
53 53
 }
Please login to merge, or discard this patch.
lib/public/Federation/ICloudFederationShare.php 1 patch
Indentation   +216 added lines, -216 removed lines patch added patch discarded remove patch
@@ -30,221 +30,221 @@
 block discarded – undo
30 30
  */
31 31
 interface ICloudFederationShare {
32 32
 
33
-	/**
34
-	 * set uid of the recipient
35
-	 *
36
-	 * @param string $user
37
-	 *
38
-	 * @since 14.0.0
39
-	 */
40
-	public function setShareWith($user);
41
-
42
-	/**
43
-	 * set resource name (e.g. file, calendar, contact,...)
44
-	 *
45
-	 * @param string $name
46
-	 *
47
-	 * @since 14.0.0
48
-	 */
49
-	public function setResourceName($name);
50
-
51
-	/**
52
-	 * set resource type (e.g. file, calendar, contact,...)
53
-	 *
54
-	 * @param string $resourceType
55
-	 *
56
-	 * @since 14.0.0
57
-	 */
58
-	public function setResourceType($resourceType);
59
-
60
-	/**
61
-	 * set resource description (optional)
62
-	 *
63
-	 * @param string $description
64
-	 *
65
-	 * @since 14.0.0
66
-	 */
67
-	public function setDescription($description);
68
-
69
-	/**
70
-	 * set provider ID (e.g. file ID)
71
-	 *
72
-	 * @param string $providerId
73
-	 *
74
-	 * @since 14.0.0
75
-	 */
76
-	public function setProviderId($providerId);
77
-
78
-	/**
79
-	 * set owner UID
80
-	 *
81
-	 * @param string $owner
82
-	 *
83
-	 * @since 14.0.0
84
-	 */
85
-	public function setOwner($owner);
86
-
87
-	/**
88
-	 * set owner display name
89
-	 *
90
-	 * @param string $ownerDisplayName
91
-	 *
92
-	 * @since 14.0.0
93
-	 */
94
-	public function setOwnerDisplayName($ownerDisplayName);
95
-
96
-	/**
97
-	 * set UID of the user who sends the share
98
-	 *
99
-	 * @param string $sharedBy
100
-	 *
101
-	 * @since 14.0.0
102
-	 */
103
-	public function setSharedBy($sharedBy);
104
-
105
-	/**
106
-	 * set display name of the user who sends the share
107
-	 *
108
-	 * @param $sharedByDisplayName
109
-	 *
110
-	 * @since 14.0.0
111
-	 */
112
-	public function setSharedByDisplayName($sharedByDisplayName);
113
-
114
-	/**
115
-	 * set protocol specification
116
-	 *
117
-	 * @param array $protocol
118
-	 *
119
-	 * @since 14.0.0
120
-	 */
121
-	public function setProtocol(array $protocol);
122
-
123
-	/**
124
-	 * share type (group or user)
125
-	 *
126
-	 * @param string $shareType
127
-	 *
128
-	 * @since 14.0.0
129
-	 */
130
-	public function setShareType($shareType);
131
-
132
-	/**
133
-	 * get the whole share, ready to send out
134
-	 *
135
-	 * @return array
136
-	 *
137
-	 * @since 14.0.0
138
-	 */
139
-	public function getShare();
140
-
141
-	/**
142
-	 * get uid of the recipient
143
-	 *
144
-	 * @return string
145
-	 *
146
-	 * @since 14.0.0
147
-	 */
148
-	public function getShareWith();
149
-
150
-	/**
151
-	 * get resource name (e.g. file, calendar, contact,...)
152
-	 *
153
-	 * @return string
154
-	 *
155
-	 * @since 14.0.0
156
-	 */
157
-	public function getResourceName();
158
-
159
-	/**
160
-	 * get resource type (e.g. file, calendar, contact,...)
161
-	 *
162
-	 * @return string
163
-	 *
164
-	 * @since 14.0.0
165
-	 */
166
-	public function getResourceType();
167
-
168
-	/**
169
-	 * get resource description (optional)
170
-	 *
171
-	 * @return string
172
-	 *
173
-	 * @since 14.0.0
174
-	 */
175
-	public function getDescription();
176
-
177
-	/**
178
-	 * get provider ID (e.g. file ID)
179
-	 *
180
-	 * @return string
181
-	 *
182
-	 * @since 14.0.0
183
-	 */
184
-	public function getProviderId();
185
-
186
-	/**
187
-	 * get owner UID
188
-	 *
189
-	 * @return string
190
-	 *
191
-	 * @since 14.0.0
192
-	 */
193
-	public function getOwner();
194
-
195
-	/**
196
-	 * get owner display name
197
-	 *
198
-	 * @return string
199
-	 *
200
-	 * @since 14.0.0
201
-	 */
202
-	public function getOwnerDisplayName();
203
-
204
-	/**
205
-	 * get UID of the user who sends the share
206
-	 *
207
-	 * @return string
208
-	 *
209
-	 * @since 14.0.0
210
-	 */
211
-	public function getSharedBy();
212
-
213
-	/**
214
-	 * get display name of the user who sends the share
215
-	 *
216
-	 * @return string
217
-	 *
218
-	 * @since 14.0.0
219
-	 */
220
-	public function getSharedByDisplayName();
221
-
222
-	/**
223
-	 * get share type (group or user)
224
-	 *
225
-	 * @return string
226
-	 *
227
-	 * @since 14.0.0
228
-	 */
229
-	public function getShareType();
230
-
231
-	/**
232
-	 * get share Secret
233
-	 *
234
-	 * @return string
235
-	 *
236
-	 * @since 14.0.0
237
-	 */
238
-	public function getShareSecret();
239
-
240
-
241
-	/**
242
-	 * get protocol specification
243
-	 *
244
-	 * @return array
245
-	 *
246
-	 * @since 14.0.0
247
-	 */
248
-	public function getProtocol();
33
+    /**
34
+     * set uid of the recipient
35
+     *
36
+     * @param string $user
37
+     *
38
+     * @since 14.0.0
39
+     */
40
+    public function setShareWith($user);
41
+
42
+    /**
43
+     * set resource name (e.g. file, calendar, contact,...)
44
+     *
45
+     * @param string $name
46
+     *
47
+     * @since 14.0.0
48
+     */
49
+    public function setResourceName($name);
50
+
51
+    /**
52
+     * set resource type (e.g. file, calendar, contact,...)
53
+     *
54
+     * @param string $resourceType
55
+     *
56
+     * @since 14.0.0
57
+     */
58
+    public function setResourceType($resourceType);
59
+
60
+    /**
61
+     * set resource description (optional)
62
+     *
63
+     * @param string $description
64
+     *
65
+     * @since 14.0.0
66
+     */
67
+    public function setDescription($description);
68
+
69
+    /**
70
+     * set provider ID (e.g. file ID)
71
+     *
72
+     * @param string $providerId
73
+     *
74
+     * @since 14.0.0
75
+     */
76
+    public function setProviderId($providerId);
77
+
78
+    /**
79
+     * set owner UID
80
+     *
81
+     * @param string $owner
82
+     *
83
+     * @since 14.0.0
84
+     */
85
+    public function setOwner($owner);
86
+
87
+    /**
88
+     * set owner display name
89
+     *
90
+     * @param string $ownerDisplayName
91
+     *
92
+     * @since 14.0.0
93
+     */
94
+    public function setOwnerDisplayName($ownerDisplayName);
95
+
96
+    /**
97
+     * set UID of the user who sends the share
98
+     *
99
+     * @param string $sharedBy
100
+     *
101
+     * @since 14.0.0
102
+     */
103
+    public function setSharedBy($sharedBy);
104
+
105
+    /**
106
+     * set display name of the user who sends the share
107
+     *
108
+     * @param $sharedByDisplayName
109
+     *
110
+     * @since 14.0.0
111
+     */
112
+    public function setSharedByDisplayName($sharedByDisplayName);
113
+
114
+    /**
115
+     * set protocol specification
116
+     *
117
+     * @param array $protocol
118
+     *
119
+     * @since 14.0.0
120
+     */
121
+    public function setProtocol(array $protocol);
122
+
123
+    /**
124
+     * share type (group or user)
125
+     *
126
+     * @param string $shareType
127
+     *
128
+     * @since 14.0.0
129
+     */
130
+    public function setShareType($shareType);
131
+
132
+    /**
133
+     * get the whole share, ready to send out
134
+     *
135
+     * @return array
136
+     *
137
+     * @since 14.0.0
138
+     */
139
+    public function getShare();
140
+
141
+    /**
142
+     * get uid of the recipient
143
+     *
144
+     * @return string
145
+     *
146
+     * @since 14.0.0
147
+     */
148
+    public function getShareWith();
149
+
150
+    /**
151
+     * get resource name (e.g. file, calendar, contact,...)
152
+     *
153
+     * @return string
154
+     *
155
+     * @since 14.0.0
156
+     */
157
+    public function getResourceName();
158
+
159
+    /**
160
+     * get resource type (e.g. file, calendar, contact,...)
161
+     *
162
+     * @return string
163
+     *
164
+     * @since 14.0.0
165
+     */
166
+    public function getResourceType();
167
+
168
+    /**
169
+     * get resource description (optional)
170
+     *
171
+     * @return string
172
+     *
173
+     * @since 14.0.0
174
+     */
175
+    public function getDescription();
176
+
177
+    /**
178
+     * get provider ID (e.g. file ID)
179
+     *
180
+     * @return string
181
+     *
182
+     * @since 14.0.0
183
+     */
184
+    public function getProviderId();
185
+
186
+    /**
187
+     * get owner UID
188
+     *
189
+     * @return string
190
+     *
191
+     * @since 14.0.0
192
+     */
193
+    public function getOwner();
194
+
195
+    /**
196
+     * get owner display name
197
+     *
198
+     * @return string
199
+     *
200
+     * @since 14.0.0
201
+     */
202
+    public function getOwnerDisplayName();
203
+
204
+    /**
205
+     * get UID of the user who sends the share
206
+     *
207
+     * @return string
208
+     *
209
+     * @since 14.0.0
210
+     */
211
+    public function getSharedBy();
212
+
213
+    /**
214
+     * get display name of the user who sends the share
215
+     *
216
+     * @return string
217
+     *
218
+     * @since 14.0.0
219
+     */
220
+    public function getSharedByDisplayName();
221
+
222
+    /**
223
+     * get share type (group or user)
224
+     *
225
+     * @return string
226
+     *
227
+     * @since 14.0.0
228
+     */
229
+    public function getShareType();
230
+
231
+    /**
232
+     * get share Secret
233
+     *
234
+     * @return string
235
+     *
236
+     * @since 14.0.0
237
+     */
238
+    public function getShareSecret();
239
+
240
+
241
+    /**
242
+     * get protocol specification
243
+     *
244
+     * @return array
245
+     *
246
+     * @since 14.0.0
247
+     */
248
+    public function getProtocol();
249 249
 
250 250
 }
Please login to merge, or discard this patch.
lib/public/Federation/Exceptions/ProviderAlreadyExistsException.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -32,19 +32,19 @@
 block discarded – undo
32 32
  */
33 33
 class ProviderAlreadyExistsException extends HintException {
34 34
 
35
-	/**
36
-	 * ProviderAlreadyExistsException constructor.
37
-	 *
38
-	 * @since 14.0.0
39
-	 *
40
-	 * @param string $newProviderId cloud federation provider ID of the new provider
41
-	 * @param string $existingProviderName name of cloud federation provider which already use the same ID
42
-	 */
43
-	public function __construct($newProviderId, $existingProviderName) {
44
-		$l = \OC::$server->getL10N('federation');
45
-		$message = 'Id "' . $newProviderId . '" already used by cloud federation provider "' . $existingProviderName . '"';
46
-		$hint = $l->t('Id "%s" already used by cloud federation provider "%s"', [$newProviderId, $existingProviderName]);
47
-		parent::__construct($message, $hint);
48
-	}
35
+    /**
36
+     * ProviderAlreadyExistsException constructor.
37
+     *
38
+     * @since 14.0.0
39
+     *
40
+     * @param string $newProviderId cloud federation provider ID of the new provider
41
+     * @param string $existingProviderName name of cloud federation provider which already use the same ID
42
+     */
43
+    public function __construct($newProviderId, $existingProviderName) {
44
+        $l = \OC::$server->getL10N('federation');
45
+        $message = 'Id "' . $newProviderId . '" already used by cloud federation provider "' . $existingProviderName . '"';
46
+        $hint = $l->t('Id "%s" already used by cloud federation provider "%s"', [$newProviderId, $existingProviderName]);
47
+        parent::__construct($message, $hint);
48
+    }
49 49
 
50 50
 }
Please login to merge, or discard this patch.
lib/public/Federation/Exceptions/BadRequestException.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -32,46 +32,46 @@
 block discarded – undo
32 32
  */
33 33
 class BadRequestException extends HintException {
34 34
 
35
-	private $parameterList;
35
+    private $parameterList;
36 36
 
37
-	/**
38
-	 * BadRequestException constructor.
39
-	 *
40
-	 * @since 14.0.0
41
-	 *
42
-	 * @param array $missingParameters
43
-	 */
44
-	public function __construct(array $missingParameters) {
45
-		$l = \OC::$server->getL10N('federation');
46
-		$this->parameterList = $missingParameters;
47
-		$parameterList = implode(',', $missingParameters);
48
-		$message = 'Parameters missing in order to complete the request. Missing Parameters: ' . $parameterList;
49
-		$hint = $l->t('Parameters missing in order to complete the request. Missing Parameters: "%s"', [$parameterList]);
50
-		parent::__construct($message, $hint);
51
-	}
37
+    /**
38
+     * BadRequestException constructor.
39
+     *
40
+     * @since 14.0.0
41
+     *
42
+     * @param array $missingParameters
43
+     */
44
+    public function __construct(array $missingParameters) {
45
+        $l = \OC::$server->getL10N('federation');
46
+        $this->parameterList = $missingParameters;
47
+        $parameterList = implode(',', $missingParameters);
48
+        $message = 'Parameters missing in order to complete the request. Missing Parameters: ' . $parameterList;
49
+        $hint = $l->t('Parameters missing in order to complete the request. Missing Parameters: "%s"', [$parameterList]);
50
+        parent::__construct($message, $hint);
51
+    }
52 52
 
53
-	/**
54
-	 * get array with the return message as defined in the OCM API
55
-	 *
56
-	 * @since 14.0.0
57
-	 *
58
-	 * @return array
59
-	 */
60
-	public function getReturnMessage() {
61
-		$result = [
62
-			'message' => 'RESOURCE_NOT_FOUND',
63
-			'validationErrors' =>[
64
-			]
65
-		];
53
+    /**
54
+     * get array with the return message as defined in the OCM API
55
+     *
56
+     * @since 14.0.0
57
+     *
58
+     * @return array
59
+     */
60
+    public function getReturnMessage() {
61
+        $result = [
62
+            'message' => 'RESOURCE_NOT_FOUND',
63
+            'validationErrors' =>[
64
+            ]
65
+        ];
66 66
 
67
-		foreach ($this->parameterList as $missingParameter) {
68
-			$result['validationErrors'] = [
69
-				'name' => $missingParameter,
70
-				'message' => 'NOT_FOUND'
71
-			];
72
-		}
67
+        foreach ($this->parameterList as $missingParameter) {
68
+            $result['validationErrors'] = [
69
+                'name' => $missingParameter,
70
+                'message' => 'NOT_FOUND'
71
+            ];
72
+        }
73 73
 
74
-		return $result;
75
-	}
74
+        return $result;
75
+    }
76 76
 
77 77
 }
Please login to merge, or discard this patch.
lib/public/Federation/Exceptions/ProviderCouldNotAddShareException.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -33,19 +33,19 @@
 block discarded – undo
33 33
  */
34 34
 class ProviderCouldNotAddShareException extends HintException {
35 35
 
36
-	/**
37
-	 * ProviderCouldNotAddShareException constructor.
38
-	 *
39
-	 * @since 14.0.0
40
-	 *
41
-	 * @param string $message
42
-	 * @param string $hint
43
-	 * @param int $code
44
-	 * @param \Exception|null $previous
45
-	 */
46
-	public function __construct($message, $hint = '', $code = Http::STATUS_BAD_REQUEST, \Exception $previous = null) {
47
-		parent::__construct($message, $hint, $code, $previous);
48
-	}
36
+    /**
37
+     * ProviderCouldNotAddShareException constructor.
38
+     *
39
+     * @since 14.0.0
40
+     *
41
+     * @param string $message
42
+     * @param string $hint
43
+     * @param int $code
44
+     * @param \Exception|null $previous
45
+     */
46
+    public function __construct($message, $hint = '', $code = Http::STATUS_BAD_REQUEST, \Exception $previous = null) {
47
+        parent::__construct($message, $hint, $code, $previous);
48
+    }
49 49
 
50 50
 
51 51
 }
Please login to merge, or discard this patch.
lib/public/Federation/Exceptions/ProviderDoesNotExistsException.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -32,18 +32,18 @@
 block discarded – undo
32 32
  */
33 33
 class ProviderDoesNotExistsException extends HintException {
34 34
 
35
-	/**
36
-	 * ProviderDoesNotExistsException constructor.
37
-	 *
38
-	 * @since 14.0.0
39
-	 *
40
-	 * @param string $providerId cloud federation provider ID
41
-	 */
42
-	public function __construct($providerId) {
43
-		$l = \OC::$server->getL10N('federation');
44
-		$message = 'Cloud Federation Provider with ID: "' . $providerId . '" does not exist.';
45
-		$hint = $l->t('Cloud Federation Provider with ID: "%s" does not exist.', [$providerId]);
46
-		parent::__construct($message, $hint);
47
-	}
35
+    /**
36
+     * ProviderDoesNotExistsException constructor.
37
+     *
38
+     * @since 14.0.0
39
+     *
40
+     * @param string $providerId cloud federation provider ID
41
+     */
42
+    public function __construct($providerId) {
43
+        $l = \OC::$server->getL10N('federation');
44
+        $message = 'Cloud Federation Provider with ID: "' . $providerId . '" does not exist.';
45
+        $hint = $l->t('Cloud Federation Provider with ID: "%s" does not exist.', [$providerId]);
46
+        parent::__construct($message, $hint);
47
+    }
48 48
 
49 49
 }
Please login to merge, or discard this patch.