Completed
Pull Request — master (#9895)
by Björn
64:23 queued 40:48
created
apps/federatedfilesharing/lib/AppInfo/Application.php 2 patches
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -39,114 +39,114 @@
 block discarded – undo
39 39
 
40 40
 class Application extends App {
41 41
 
42
-	/** @var FederatedShareProvider */
43
-	protected $federatedShareProvider;
42
+    /** @var FederatedShareProvider */
43
+    protected $federatedShareProvider;
44 44
 
45
-	public function __construct() {
46
-		parent::__construct('federatedfilesharing');
45
+    public function __construct() {
46
+        parent::__construct('federatedfilesharing');
47 47
 
48
-		$container = $this->getContainer();
49
-		$server = $container->getServer();
48
+        $container = $this->getContainer();
49
+        $server = $container->getServer();
50 50
 
51
-		$cloudFederationManager = $server->getCloudFederationProviderManager();
52
-		$cloudFederationManager->addCloudFederationProvider('file',
53
-			'Federated Files Sharing',
54
-			function() use ($container) {
55
-				$server = $container->getServer();
56
-				return new CloudFederationProviderFiles(
57
-					$server->getAppManager(),
58
-					$server->query(FederatedShareProvider::class),
59
-					$server->query(AddressHandler::class),
60
-					$server->getLogger(),
61
-					$server->getUserManager(),
62
-					$server->getCloudIdManager(),
63
-					$server->getActivityManager(),
64
-					$server->getNotificationManager(),
65
-					$server->getURLGenerator(),
66
-					$server->getCloudFederationFactory(),
67
-					$server->getCloudFederationProviderManager(),
68
-					$server->getDatabaseConnection()
69
-				);
70
-			});
51
+        $cloudFederationManager = $server->getCloudFederationProviderManager();
52
+        $cloudFederationManager->addCloudFederationProvider('file',
53
+            'Federated Files Sharing',
54
+            function() use ($container) {
55
+                $server = $container->getServer();
56
+                return new CloudFederationProviderFiles(
57
+                    $server->getAppManager(),
58
+                    $server->query(FederatedShareProvider::class),
59
+                    $server->query(AddressHandler::class),
60
+                    $server->getLogger(),
61
+                    $server->getUserManager(),
62
+                    $server->getCloudIdManager(),
63
+                    $server->getActivityManager(),
64
+                    $server->getNotificationManager(),
65
+                    $server->getURLGenerator(),
66
+                    $server->getCloudFederationFactory(),
67
+                    $server->getCloudFederationProviderManager(),
68
+                    $server->getDatabaseConnection()
69
+                );
70
+            });
71 71
 
72
-		$container->registerService('RequestHandlerController', function(SimpleContainer $c) use ($server) {
73
-			$addressHandler = new AddressHandler(
74
-				$server->getURLGenerator(),
75
-				$server->getL10N('federatedfilesharing'),
76
-				$server->getCloudIdManager()
77
-			);
78
-			$notification = new Notifications(
79
-				$addressHandler,
80
-				$server->getHTTPClientService(),
81
-				$server->query(\OCP\OCS\IDiscoveryService::class),
82
-				\OC::$server->getJobList(),
83
-				\OC::$server->getCloudFederationProviderManager(),
84
-				\OC::$server->getCloudFederationFactory()
85
-			);
86
-			return new RequestHandlerController(
87
-				$c->query('AppName'),
88
-				$server->getRequest(),
89
-				$this->getFederatedShareProvider(),
90
-				$server->getDatabaseConnection(),
91
-				$server->getShareManager(),
92
-				$notification,
93
-				$addressHandler,
94
-				$server->getUserManager(),
95
-				$server->getCloudIdManager(),
96
-				$server->getLogger(),
97
-				$server->getCloudFederationFactory(),
98
-				$server->getCloudFederationProviderManager()
99
-			);
100
-		});
101
-	}
72
+        $container->registerService('RequestHandlerController', function(SimpleContainer $c) use ($server) {
73
+            $addressHandler = new AddressHandler(
74
+                $server->getURLGenerator(),
75
+                $server->getL10N('federatedfilesharing'),
76
+                $server->getCloudIdManager()
77
+            );
78
+            $notification = new Notifications(
79
+                $addressHandler,
80
+                $server->getHTTPClientService(),
81
+                $server->query(\OCP\OCS\IDiscoveryService::class),
82
+                \OC::$server->getJobList(),
83
+                \OC::$server->getCloudFederationProviderManager(),
84
+                \OC::$server->getCloudFederationFactory()
85
+            );
86
+            return new RequestHandlerController(
87
+                $c->query('AppName'),
88
+                $server->getRequest(),
89
+                $this->getFederatedShareProvider(),
90
+                $server->getDatabaseConnection(),
91
+                $server->getShareManager(),
92
+                $notification,
93
+                $addressHandler,
94
+                $server->getUserManager(),
95
+                $server->getCloudIdManager(),
96
+                $server->getLogger(),
97
+                $server->getCloudFederationFactory(),
98
+                $server->getCloudFederationProviderManager()
99
+            );
100
+        });
101
+    }
102 102
 
103
-	/**
104
-	 * get instance of federated share provider
105
-	 *
106
-	 * @return FederatedShareProvider
107
-	 */
108
-	public function getFederatedShareProvider() {
109
-		if ($this->federatedShareProvider === null) {
110
-			$this->initFederatedShareProvider();
111
-		}
112
-		return $this->federatedShareProvider;
113
-	}
103
+    /**
104
+     * get instance of federated share provider
105
+     *
106
+     * @return FederatedShareProvider
107
+     */
108
+    public function getFederatedShareProvider() {
109
+        if ($this->federatedShareProvider === null) {
110
+            $this->initFederatedShareProvider();
111
+        }
112
+        return $this->federatedShareProvider;
113
+    }
114 114
 
115
-	/**
116
-	 * initialize federated share provider
117
-	 */
118
-	protected function initFederatedShareProvider() {
119
-		$c = $this->getContainer();
120
-		$addressHandler = new \OCA\FederatedFileSharing\AddressHandler(
121
-			\OC::$server->getURLGenerator(),
122
-			\OC::$server->getL10N('federatedfilesharing'),
123
-			\OC::$server->getCloudIdManager()
124
-		);
125
-		$notifications = new \OCA\FederatedFileSharing\Notifications(
126
-			$addressHandler,
127
-			\OC::$server->getHTTPClientService(),
128
-			\OC::$server->query(\OCP\OCS\IDiscoveryService::class),
129
-			\OC::$server->getJobList(),
130
-			\OC::$server->getCloudFederationProviderManager(),
131
-			\OC::$server->getCloudFederationFactory()
132
-		);
133
-		$tokenHandler = new \OCA\FederatedFileSharing\TokenHandler(
134
-			\OC::$server->getSecureRandom()
135
-		);
115
+    /**
116
+     * initialize federated share provider
117
+     */
118
+    protected function initFederatedShareProvider() {
119
+        $c = $this->getContainer();
120
+        $addressHandler = new \OCA\FederatedFileSharing\AddressHandler(
121
+            \OC::$server->getURLGenerator(),
122
+            \OC::$server->getL10N('federatedfilesharing'),
123
+            \OC::$server->getCloudIdManager()
124
+        );
125
+        $notifications = new \OCA\FederatedFileSharing\Notifications(
126
+            $addressHandler,
127
+            \OC::$server->getHTTPClientService(),
128
+            \OC::$server->query(\OCP\OCS\IDiscoveryService::class),
129
+            \OC::$server->getJobList(),
130
+            \OC::$server->getCloudFederationProviderManager(),
131
+            \OC::$server->getCloudFederationFactory()
132
+        );
133
+        $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler(
134
+            \OC::$server->getSecureRandom()
135
+        );
136 136
 
137
-		$this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider(
138
-			\OC::$server->getDatabaseConnection(),
139
-			$addressHandler,
140
-			$notifications,
141
-			$tokenHandler,
142
-			\OC::$server->getL10N('federatedfilesharing'),
143
-			\OC::$server->getLogger(),
144
-			\OC::$server->getLazyRootFolder(),
145
-			\OC::$server->getConfig(),
146
-			\OC::$server->getUserManager(),
147
-			\OC::$server->getCloudIdManager(),
148
-			$c->query(IConfig::class)
149
-		);
150
-	}
137
+        $this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider(
138
+            \OC::$server->getDatabaseConnection(),
139
+            $addressHandler,
140
+            $notifications,
141
+            $tokenHandler,
142
+            \OC::$server->getL10N('federatedfilesharing'),
143
+            \OC::$server->getLogger(),
144
+            \OC::$server->getLazyRootFolder(),
145
+            \OC::$server->getConfig(),
146
+            \OC::$server->getUserManager(),
147
+            \OC::$server->getCloudIdManager(),
148
+            $c->query(IConfig::class)
149
+        );
150
+    }
151 151
 
152 152
 }
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,6 @@
 block discarded – undo
32 32
 use OCA\FederatedFileSharing\Controller\RequestHandlerController;
33 33
 use OCA\FederatedFileSharing\FederatedShareProvider;
34 34
 use OCA\FederatedFileSharing\Notifications;
35
-use OCA\FederatedFileSharing\OCM\CloudFederationProvider;
36 35
 use OCA\FederatedFileSharing\OCM\CloudFederationProviderFiles;
37 36
 use OCP\AppFramework\App;
38 37
 use OCP\GlobalScale\IConfig;
Please login to merge, or discard this patch.
apps/federatedfilesharing/lib/Controller/RequestHandlerController.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -450,7 +450,7 @@
 block discarded – undo
450 450
 	/**
451 451
 	 * translate Nextcloud permissions to OCM Permissions
452 452
 	 *
453
-	 * @param $ncPermissions
453
+	 * @param integer $ncPermissions
454 454
 	 * @return array
455 455
 	 */
456 456
 	protected function ncPermissions2ocmPermissions($ncPermissions) {
Please login to merge, or discard this patch.
Indentation   +427 added lines, -427 removed lines patch added patch discarded remove patch
@@ -52,431 +52,431 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 		$owner = isset($_POST['owner']) ? $_POST['owner'] : null;
146 146
 		$sharedBy = isset($_POST['sharedBy']) ? $_POST['sharedBy'] : null;
147 147
 		$shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null;
148
-		$remoteId = isset($_POST['remoteId']) ? (int)$_POST['remoteId'] : null;
148
+		$remoteId = isset($_POST['remoteId']) ? (int) $_POST['remoteId'] : null;
149 149
 		$sharedByFederatedId = isset($_POST['sharedByFederatedId']) ? $_POST['sharedByFederatedId'] : null;
150 150
 		$ownerFederatedId = isset($_POST['ownerFederatedId']) ? $_POST['ownerFederatedId'] : null;
151 151
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 		} catch (ProviderCouldNotAddShareException $e) {
181 181
 			throw new OCSException($e->getMessage(), 400);
182 182
 		} catch (\Exception $e) {
183
-			throw new OCSException('internal server error, was not able to add share from ' . $remote, 500);
183
+			throw new OCSException('internal server error, was not able to add share from '.$remote, 500);
184 184
 		}
185 185
 
186 186
 		return new Http\DataResponse();
@@ -202,8 +202,8 @@  discard block
 block discarded – undo
202 202
 
203 203
 		$token = $this->request->getParam('token', null);
204 204
 		$shareWith = $this->request->getParam('shareWith', null);
205
-		$permission = (int)$this->request->getParam('permission', null);
206
-		$remoteId = (int)$this->request->getParam('remoteId', null);
205
+		$permission = (int) $this->request->getParam('permission', null);
206
+		$remoteId = (int) $this->request->getParam('remoteId', null);
207 207
 
208 208
 		if ($id === null ||
209 209
 			$token === null ||
@@ -231,9 +231,9 @@  discard block
 block discarded – undo
231 231
 		} catch (ProviderDoesNotExistsException $e) {
232 232
 			throw new OCSException('Server does not support federated cloud sharing', 503);
233 233
 		} catch (ShareNotFound $e) {
234
-			$this->logger->debug('Share not found: ' . $e->getMessage());
234
+			$this->logger->debug('Share not found: '.$e->getMessage());
235 235
 		} catch (\Exception $e) {
236
-			$this->logger->debug('internal server error, can not process notification: ' . $e->getMessage());
236
+			$this->logger->debug('internal server error, can not process notification: '.$e->getMessage());
237 237
 		}
238 238
 
239 239
 		throw new OCSBadRequestException();
@@ -267,9 +267,9 @@  discard block
 block discarded – undo
267 267
 		} catch (ProviderDoesNotExistsException $e) {
268 268
 			throw new OCSException('Server does not support federated cloud sharing', 503);
269 269
 		} catch (ShareNotFound $e) {
270
-			$this->logger->debug('Share not found: ' . $e->getMessage());
270
+			$this->logger->debug('Share not found: '.$e->getMessage());
271 271
 		} catch (\Exception $e) {
272
-			$this->logger->debug('internal server error, can not process notification: ' . $e->getMessage());
272
+			$this->logger->debug('internal server error, can not process notification: '.$e->getMessage());
273 273
 		}
274 274
 
275 275
 		return new Http\DataResponse();
@@ -300,9 +300,9 @@  discard block
 block discarded – undo
300 300
 		} catch (ProviderDoesNotExistsException $e) {
301 301
 			throw new OCSException('Server does not support federated cloud sharing', 503);
302 302
 		} catch (ShareNotFound $e) {
303
-			$this->logger->debug('Share not found: ' . $e->getMessage());
303
+			$this->logger->debug('Share not found: '.$e->getMessage());
304 304
 		} catch (\Exception $e) {
305
-			$this->logger->debug('internal server error, can not process notification: ' . $e->getMessage());
305
+			$this->logger->debug('internal server error, can not process notification: '.$e->getMessage());
306 306
 		}
307 307
 
308 308
 		return new Http\DataResponse();
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 			$notification = ['sharedSecret' => $token];
332 332
 			$provider->notificationReceived('SHARE_UNSHARED', $id, $notification);
333 333
 		} catch (\Exception $e) {
334
-			$this->logger->debug('processing unshare notification failed: ' . $e->getMessage());
334
+			$this->logger->debug('processing unshare notification failed: '.$e->getMessage());
335 335
 		}
336 336
 
337 337
 		return new Http\DataResponse();
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
 
405 405
 		try {
406 406
 			$provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file');
407
-			$ocmPermissions = $this->ncPermissions2ocmPermissions((int)$ncPermissions);
407
+			$ocmPermissions = $this->ncPermissions2ocmPermissions((int) $ncPermissions);
408 408
 			$notification = ['sharedSecret' => $token, 'permission' => $ocmPermissions];
409 409
 			$provider->notificationReceived('RESHARE_CHANGE_PERMISSION', $id, $notification);
410 410
 		} catch (\Exception $e) {
Please login to merge, or discard this patch.
apps/federatedfilesharing/lib/FederatedShareProvider.php 2 patches
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 		if ($remoteShare) {
193 193
 			try {
194 194
 				$ownerCloudId = $this->cloudIdManager->getCloudId($remoteShare['owner'], $remoteShare['remote']);
195
-				$shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time());
195
+				$shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_'.time());
196 196
 				$share->setId($shareId);
197 197
 				list($token, $remoteId) = $this->askOwnerToReShare($shareWith, $share, $shareId);
198 198
 				// remote share was create successfully if we get a valid token as return
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 			$failure = true;
273 273
 		}
274 274
 
275
-		if($failure) {
275
+		if ($failure) {
276 276
 			$this->removeShareFromTableById($shareId);
277 277
 			$message_t = $this->l->t('Sharing %s failed, could not find %s, maybe the server is currently unreachable or uses a self-signed certificate.',
278 278
 				[$share->getNode()->getName(), $share->getSharedWith()]);
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 			->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($share->getTarget())));
325 325
 		$result = $query->execute()->fetchAll();
326 326
 
327
-		if (isset($result[0]) && (int)$result[0]['remote_id'] > 0) {
327
+		if (isset($result[0]) && (int) $result[0]['remote_id'] > 0) {
328 328
 			return $result[0];
329 329
 		}
330 330
 
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 		$qb->execute();
367 367
 		$id = $qb->getLastInsertId();
368 368
 
369
-		return (int)$id;
369
+		return (int) $id;
370 370
 	}
371 371
 
372 372
 	/**
@@ -456,14 +456,14 @@  discard block
 block discarded – undo
456 456
 	public function getRemoteId(IShare $share) {
457 457
 		$query = $this->dbConnection->getQueryBuilder();
458 458
 		$query->select('remote_id')->from('federated_reshares')
459
-			->where($query->expr()->eq('share_id', $query->createNamedParameter((int)$share->getId())));
459
+			->where($query->expr()->eq('share_id', $query->createNamedParameter((int) $share->getId())));
460 460
 		$data = $query->execute()->fetch();
461 461
 
462 462
 		if (!is_array($data) || !isset($data['remote_id'])) {
463 463
 			throw new ShareNotFound();
464 464
 		}
465 465
 
466
-		return (int)$data['remote_id'];
466
+		return (int) $data['remote_id'];
467 467
 	}
468 468
 
469 469
 	/**
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
 			->orderBy('id');
495 495
 
496 496
 		$cursor = $qb->execute();
497
-		while($data = $cursor->fetch()) {
497
+		while ($data = $cursor->fetch()) {
498 498
 			$children[] = $this->createShareObject($data);
499 499
 		}
500 500
 		$cursor->closeCursor();
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
 			);
613 613
 		}
614 614
 
615
-		$qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
615
+		$qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
616 616
 		$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
617 617
 
618 618
 		$qb->orderBy('id');
@@ -675,7 +675,7 @@  discard block
 block discarded – undo
675 675
 
676 676
 		$cursor = $qb->execute();
677 677
 		$shares = [];
678
-		while($data = $cursor->fetch()) {
678
+		while ($data = $cursor->fetch()) {
679 679
 			$shares[] = $this->createShareObject($data);
680 680
 		}
681 681
 		$cursor->closeCursor();
@@ -699,7 +699,7 @@  discard block
 block discarded – undo
699 699
 		$cursor->closeCursor();
700 700
 
701 701
 		if ($data === false) {
702
-			throw new ShareNotFound('Can not find share with ID: ' . $id);
702
+			throw new ShareNotFound('Can not find share with ID: '.$id);
703 703
 		}
704 704
 
705 705
 		try {
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
 			->execute();
728 728
 
729 729
 		$shares = [];
730
-		while($data = $cursor->fetch()) {
730
+		while ($data = $cursor->fetch()) {
731 731
 			$shares[] = $this->createShareObject($data);
732 732
 		}
733 733
 		$cursor->closeCursor();
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
 
767 767
 		$cursor = $qb->execute();
768 768
 
769
-		while($data = $cursor->fetch()) {
769
+		while ($data = $cursor->fetch()) {
770 770
 			$shares[] = $this->createShareObject($data);
771 771
 		}
772 772
 		$cursor->closeCursor();
@@ -843,15 +843,15 @@  discard block
 block discarded – undo
843 843
 	private function createShareObject($data) {
844 844
 
845 845
 		$share = new Share($this->rootFolder, $this->userManager);
846
-		$share->setId((int)$data['id'])
847
-			->setShareType((int)$data['share_type'])
848
-			->setPermissions((int)$data['permissions'])
846
+		$share->setId((int) $data['id'])
847
+			->setShareType((int) $data['share_type'])
848
+			->setPermissions((int) $data['permissions'])
849 849
 			->setTarget($data['file_target'])
850
-			->setMailSend((bool)$data['mail_send'])
850
+			->setMailSend((bool) $data['mail_send'])
851 851
 			->setToken($data['token']);
852 852
 
853 853
 		$shareTime = new \DateTime();
854
-		$shareTime->setTimestamp((int)$data['stime']);
854
+		$shareTime->setTimestamp((int) $data['stime']);
855 855
 		$share->setShareTime($shareTime);
856 856
 		$share->setSharedWith($data['share_with']);
857 857
 
@@ -861,13 +861,13 @@  discard block
 block discarded – undo
861 861
 		} else {
862 862
 			//OLD SHARE
863 863
 			$share->setSharedBy($data['uid_owner']);
864
-			$path = $this->getNode($share->getSharedBy(), (int)$data['file_source']);
864
+			$path = $this->getNode($share->getSharedBy(), (int) $data['file_source']);
865 865
 
866 866
 			$owner = $path->getOwner();
867 867
 			$share->setShareOwner($owner->getUID());
868 868
 		}
869 869
 
870
-		$share->setNodeId((int)$data['file_source']);
870
+		$share->setNodeId((int) $data['file_source']);
871 871
 		$share->setNodeType($data['item_type']);
872 872
 
873 873
 		$share->setProviderId($this->identifier());
Please login to merge, or discard this patch.
Indentation   +1009 added lines, -1009 removed lines patch added patch discarded remove patch
@@ -54,1023 +54,1023 @@
 block discarded – undo
54 54
  */
55 55
 class FederatedShareProvider implements IShareProvider {
56 56
 
57
-	const SHARE_TYPE_REMOTE = 6;
58
-
59
-	/** @var IDBConnection */
60
-	private $dbConnection;
61
-
62
-	/** @var AddressHandler */
63
-	private $addressHandler;
64
-
65
-	/** @var Notifications */
66
-	private $notifications;
67
-
68
-	/** @var TokenHandler */
69
-	private $tokenHandler;
70
-
71
-	/** @var IL10N */
72
-	private $l;
73
-
74
-	/** @var ILogger */
75
-	private $logger;
76
-
77
-	/** @var IRootFolder */
78
-	private $rootFolder;
79
-
80
-	/** @var IConfig */
81
-	private $config;
82
-
83
-	/** @var string */
84
-	private $externalShareTable = 'share_external';
85
-
86
-	/** @var IUserManager */
87
-	private $userManager;
88
-
89
-	/** @var ICloudIdManager */
90
-	private $cloudIdManager;
91
-
92
-	/** @var \OCP\GlobalScale\IConfig */
93
-	private $gsConfig;
94
-
95
-	/** @var ICloudFederationProviderManager */
96
-	private $cloudFederationProviderManager;
97
-
98
-	/**
99
-	 * DefaultShareProvider constructor.
100
-	 *
101
-	 * @param IDBConnection $connection
102
-	 * @param AddressHandler $addressHandler
103
-	 * @param Notifications $notifications
104
-	 * @param TokenHandler $tokenHandler
105
-	 * @param IL10N $l10n
106
-	 * @param ILogger $logger
107
-	 * @param IRootFolder $rootFolder
108
-	 * @param IConfig $config
109
-	 * @param IUserManager $userManager
110
-	 * @param ICloudIdManager $cloudIdManager
111
-	 * @param \OCP\GlobalScale\IConfig $globalScaleConfig
112
-	 * @param ICloudFederationProviderManager $cloudFederationProviderManager
113
-	 */
114
-	public function __construct(
115
-			IDBConnection $connection,
116
-			AddressHandler $addressHandler,
117
-			Notifications $notifications,
118
-			TokenHandler $tokenHandler,
119
-			IL10N $l10n,
120
-			ILogger $logger,
121
-			IRootFolder $rootFolder,
122
-			IConfig $config,
123
-			IUserManager $userManager,
124
-			ICloudIdManager $cloudIdManager,
125
-			\OCP\GlobalScale\IConfig $globalScaleConfig,
126
-			ICloudFederationProviderManager $cloudFederationProviderManager
127
-	) {
128
-		$this->dbConnection = $connection;
129
-		$this->addressHandler = $addressHandler;
130
-		$this->notifications = $notifications;
131
-		$this->tokenHandler = $tokenHandler;
132
-		$this->l = $l10n;
133
-		$this->logger = $logger;
134
-		$this->rootFolder = $rootFolder;
135
-		$this->config = $config;
136
-		$this->userManager = $userManager;
137
-		$this->cloudIdManager = $cloudIdManager;
138
-		$this->gsConfig = $globalScaleConfig;
139
-		$this->cloudFederationProviderManager = $cloudFederationProviderManager;
140
-	}
141
-
142
-	/**
143
-	 * Return the identifier of this provider.
144
-	 *
145
-	 * @return string Containing only [a-zA-Z0-9]
146
-	 */
147
-	public function identifier() {
148
-		return 'ocFederatedSharing';
149
-	}
150
-
151
-	/**
152
-	 * Share a path
153
-	 *
154
-	 * @param IShare $share
155
-	 * @return IShare The share object
156
-	 * @throws ShareNotFound
157
-	 * @throws \Exception
158
-	 */
159
-	public function create(IShare $share) {
160
-
161
-		$shareWith = $share->getSharedWith();
162
-		$itemSource = $share->getNodeId();
163
-		$itemType = $share->getNodeType();
164
-		$permissions = $share->getPermissions();
165
-		$sharedBy = $share->getSharedBy();
166
-
167
-		/*
57
+    const SHARE_TYPE_REMOTE = 6;
58
+
59
+    /** @var IDBConnection */
60
+    private $dbConnection;
61
+
62
+    /** @var AddressHandler */
63
+    private $addressHandler;
64
+
65
+    /** @var Notifications */
66
+    private $notifications;
67
+
68
+    /** @var TokenHandler */
69
+    private $tokenHandler;
70
+
71
+    /** @var IL10N */
72
+    private $l;
73
+
74
+    /** @var ILogger */
75
+    private $logger;
76
+
77
+    /** @var IRootFolder */
78
+    private $rootFolder;
79
+
80
+    /** @var IConfig */
81
+    private $config;
82
+
83
+    /** @var string */
84
+    private $externalShareTable = 'share_external';
85
+
86
+    /** @var IUserManager */
87
+    private $userManager;
88
+
89
+    /** @var ICloudIdManager */
90
+    private $cloudIdManager;
91
+
92
+    /** @var \OCP\GlobalScale\IConfig */
93
+    private $gsConfig;
94
+
95
+    /** @var ICloudFederationProviderManager */
96
+    private $cloudFederationProviderManager;
97
+
98
+    /**
99
+     * DefaultShareProvider constructor.
100
+     *
101
+     * @param IDBConnection $connection
102
+     * @param AddressHandler $addressHandler
103
+     * @param Notifications $notifications
104
+     * @param TokenHandler $tokenHandler
105
+     * @param IL10N $l10n
106
+     * @param ILogger $logger
107
+     * @param IRootFolder $rootFolder
108
+     * @param IConfig $config
109
+     * @param IUserManager $userManager
110
+     * @param ICloudIdManager $cloudIdManager
111
+     * @param \OCP\GlobalScale\IConfig $globalScaleConfig
112
+     * @param ICloudFederationProviderManager $cloudFederationProviderManager
113
+     */
114
+    public function __construct(
115
+            IDBConnection $connection,
116
+            AddressHandler $addressHandler,
117
+            Notifications $notifications,
118
+            TokenHandler $tokenHandler,
119
+            IL10N $l10n,
120
+            ILogger $logger,
121
+            IRootFolder $rootFolder,
122
+            IConfig $config,
123
+            IUserManager $userManager,
124
+            ICloudIdManager $cloudIdManager,
125
+            \OCP\GlobalScale\IConfig $globalScaleConfig,
126
+            ICloudFederationProviderManager $cloudFederationProviderManager
127
+    ) {
128
+        $this->dbConnection = $connection;
129
+        $this->addressHandler = $addressHandler;
130
+        $this->notifications = $notifications;
131
+        $this->tokenHandler = $tokenHandler;
132
+        $this->l = $l10n;
133
+        $this->logger = $logger;
134
+        $this->rootFolder = $rootFolder;
135
+        $this->config = $config;
136
+        $this->userManager = $userManager;
137
+        $this->cloudIdManager = $cloudIdManager;
138
+        $this->gsConfig = $globalScaleConfig;
139
+        $this->cloudFederationProviderManager = $cloudFederationProviderManager;
140
+    }
141
+
142
+    /**
143
+     * Return the identifier of this provider.
144
+     *
145
+     * @return string Containing only [a-zA-Z0-9]
146
+     */
147
+    public function identifier() {
148
+        return 'ocFederatedSharing';
149
+    }
150
+
151
+    /**
152
+     * Share a path
153
+     *
154
+     * @param IShare $share
155
+     * @return IShare The share object
156
+     * @throws ShareNotFound
157
+     * @throws \Exception
158
+     */
159
+    public function create(IShare $share) {
160
+
161
+        $shareWith = $share->getSharedWith();
162
+        $itemSource = $share->getNodeId();
163
+        $itemType = $share->getNodeType();
164
+        $permissions = $share->getPermissions();
165
+        $sharedBy = $share->getSharedBy();
166
+
167
+        /*
168 168
 		 * Check if file is not already shared with the remote user
169 169
 		 */
170
-		$alreadyShared = $this->getSharedWith($shareWith, self::SHARE_TYPE_REMOTE, $share->getNode(), 1, 0);
171
-		if (!empty($alreadyShared)) {
172
-			$message = 'Sharing %s failed, because this item is already shared with %s';
173
-			$message_t = $this->l->t('Sharing %s failed, because this item is already shared with %s', array($share->getNode()->getName(), $shareWith));
174
-			$this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']);
175
-			throw new \Exception($message_t);
176
-		}
177
-
178
-
179
-		// don't allow federated shares if source and target server are the same
180
-		$cloudId = $this->cloudIdManager->resolveCloudId($shareWith);
181
-		$currentServer = $this->addressHandler->generateRemoteURL();
182
-		$currentUser = $sharedBy;
183
-		if ($this->addressHandler->compareAddresses($cloudId->getUser(), $cloudId->getRemote(), $currentUser, $currentServer)) {
184
-			$message = 'Not allowed to create a federated share with the same user.';
185
-			$message_t = $this->l->t('Not allowed to create a federated share with the same user');
186
-			$this->logger->debug($message, ['app' => 'Federated File Sharing']);
187
-			throw new \Exception($message_t);
188
-		}
189
-
190
-
191
-		$share->setSharedWith($cloudId->getId());
192
-
193
-		try {
194
-			$remoteShare = $this->getShareFromExternalShareTable($share);
195
-		} catch (ShareNotFound $e) {
196
-			$remoteShare = null;
197
-		}
198
-
199
-		if ($remoteShare) {
200
-			try {
201
-				$ownerCloudId = $this->cloudIdManager->getCloudId($remoteShare['owner'], $remoteShare['remote']);
202
-				$shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time());
203
-				$share->setId($shareId);
204
-				list($token, $remoteId) = $this->askOwnerToReShare($shareWith, $share, $shareId);
205
-				// remote share was create successfully if we get a valid token as return
206
-				$send = is_string($token) && $token !== '';
207
-			} catch (\Exception $e) {
208
-				// fall back to old re-share behavior if the remote server
209
-				// doesn't support flat re-shares (was introduced with Nextcloud 9.1)
210
-				$this->removeShareFromTable($share);
211
-				$shareId = $this->createFederatedShare($share);
212
-			}
213
-			if ($send) {
214
-				$this->updateSuccessfulReshare($shareId, $token);
215
-				$this->storeRemoteId($shareId, $remoteId);
216
-			} else {
217
-				$this->removeShareFromTable($share);
218
-				$message_t = $this->l->t('File is already shared with %s', [$shareWith]);
219
-				throw new \Exception($message_t);
220
-			}
221
-
222
-		} else {
223
-			$shareId = $this->createFederatedShare($share);
224
-		}
225
-
226
-		$data = $this->getRawShare($shareId);
227
-		return $this->createShareObject($data);
228
-	}
229
-
230
-	/**
231
-	 * create federated share and inform the recipient
232
-	 *
233
-	 * @param IShare $share
234
-	 * @return int
235
-	 * @throws ShareNotFound
236
-	 * @throws \Exception
237
-	 */
238
-	protected function createFederatedShare(IShare $share) {
239
-		$token = $this->tokenHandler->generateToken();
240
-		$shareId = $this->addShareToDB(
241
-			$share->getNodeId(),
242
-			$share->getNodeType(),
243
-			$share->getSharedWith(),
244
-			$share->getSharedBy(),
245
-			$share->getShareOwner(),
246
-			$share->getPermissions(),
247
-			$token
248
-		);
249
-
250
-		$failure = false;
251
-
252
-		try {
253
-			$sharedByFederatedId = $share->getSharedBy();
254
-			if ($this->userManager->userExists($sharedByFederatedId)) {
255
-				$cloudId = $this->cloudIdManager->getCloudId($sharedByFederatedId, $this->addressHandler->generateRemoteURL());
256
-				$sharedByFederatedId = $cloudId->getId();
257
-			}
258
-			$ownerCloudId = $this->cloudIdManager->getCloudId($share->getShareOwner(), $this->addressHandler->generateRemoteURL());
259
-			$send = $this->notifications->sendRemoteShare(
260
-				$token,
261
-				$share->getSharedWith(),
262
-				$share->getNode()->getName(),
263
-				$shareId,
264
-				$share->getShareOwner(),
265
-				$ownerCloudId->getId(),
266
-				$share->getSharedBy(),
267
-				$sharedByFederatedId,
268
-				$share->setShareType()
269
-			);
270
-
271
-			if ($send === false) {
272
-				$failure = true;
273
-			}
274
-		} catch (\Exception $e) {
275
-			$this->logger->logException($e, [
276
-				'message' => 'Failed to notify remote server of federated share, removing share.',
277
-				'level' => ILogger::ERROR,
278
-				'app' => 'federatedfilesharing',
279
-			]);
280
-			$failure = true;
281
-		}
282
-
283
-		if($failure) {
284
-			$this->removeShareFromTableById($shareId);
285
-			$message_t = $this->l->t('Sharing %s failed, could not find %s, maybe the server is currently unreachable or uses a self-signed certificate.',
286
-				[$share->getNode()->getName(), $share->getSharedWith()]);
287
-			throw new \Exception($message_t);
288
-		}
289
-
290
-		return $shareId;
291
-
292
-	}
293
-
294
-	/**
295
-	 * @param string $shareWith
296
-	 * @param IShare $share
297
-	 * @param string $shareId internal share Id
298
-	 * @return array
299
-	 * @throws \Exception
300
-	 */
301
-	protected function askOwnerToReShare($shareWith, IShare $share, $shareId) {
302
-
303
-		$remoteShare = $this->getShareFromExternalShareTable($share);
304
-		$token = $remoteShare['share_token'];
305
-		$remoteId = $remoteShare['remote_id'];
306
-		$remote = $remoteShare['remote'];
307
-
308
-		list($token, $remoteId) = $this->notifications->requestReShare(
309
-			$token,
310
-			$remoteId,
311
-			$shareId,
312
-			$remote,
313
-			$shareWith,
314
-			$share->getPermissions(),
315
-			$share->getNode()->getName()
316
-		);
317
-
318
-		return [$token, $remoteId];
319
-	}
320
-
321
-	/**
322
-	 * get federated share from the share_external table but exclude mounted link shares
323
-	 *
324
-	 * @param IShare $share
325
-	 * @return array
326
-	 * @throws ShareNotFound
327
-	 */
328
-	protected function getShareFromExternalShareTable(IShare $share) {
329
-		$query = $this->dbConnection->getQueryBuilder();
330
-		$query->select('*')->from($this->externalShareTable)
331
-			->where($query->expr()->eq('user', $query->createNamedParameter($share->getShareOwner())))
332
-			->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($share->getTarget())));
333
-		$result = $query->execute()->fetchAll();
334
-
335
-		if (isset($result[0]) && (int)$result[0]['remote_id'] > 0) {
336
-			return $result[0];
337
-		}
338
-
339
-		throw new ShareNotFound('share not found in share_external table');
340
-	}
341
-
342
-	/**
343
-	 * add share to the database and return the ID
344
-	 *
345
-	 * @param int $itemSource
346
-	 * @param string $itemType
347
-	 * @param string $shareWith
348
-	 * @param string $sharedBy
349
-	 * @param string $uidOwner
350
-	 * @param int $permissions
351
-	 * @param string $token
352
-	 * @return int
353
-	 */
354
-	private function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) {
355
-		$qb = $this->dbConnection->getQueryBuilder();
356
-		$qb->insert('share')
357
-			->setValue('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))
358
-			->setValue('item_type', $qb->createNamedParameter($itemType))
359
-			->setValue('item_source', $qb->createNamedParameter($itemSource))
360
-			->setValue('file_source', $qb->createNamedParameter($itemSource))
361
-			->setValue('share_with', $qb->createNamedParameter($shareWith))
362
-			->setValue('uid_owner', $qb->createNamedParameter($uidOwner))
363
-			->setValue('uid_initiator', $qb->createNamedParameter($sharedBy))
364
-			->setValue('permissions', $qb->createNamedParameter($permissions))
365
-			->setValue('token', $qb->createNamedParameter($token))
366
-			->setValue('stime', $qb->createNamedParameter(time()));
367
-
368
-		/*
170
+        $alreadyShared = $this->getSharedWith($shareWith, self::SHARE_TYPE_REMOTE, $share->getNode(), 1, 0);
171
+        if (!empty($alreadyShared)) {
172
+            $message = 'Sharing %s failed, because this item is already shared with %s';
173
+            $message_t = $this->l->t('Sharing %s failed, because this item is already shared with %s', array($share->getNode()->getName(), $shareWith));
174
+            $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']);
175
+            throw new \Exception($message_t);
176
+        }
177
+
178
+
179
+        // don't allow federated shares if source and target server are the same
180
+        $cloudId = $this->cloudIdManager->resolveCloudId($shareWith);
181
+        $currentServer = $this->addressHandler->generateRemoteURL();
182
+        $currentUser = $sharedBy;
183
+        if ($this->addressHandler->compareAddresses($cloudId->getUser(), $cloudId->getRemote(), $currentUser, $currentServer)) {
184
+            $message = 'Not allowed to create a federated share with the same user.';
185
+            $message_t = $this->l->t('Not allowed to create a federated share with the same user');
186
+            $this->logger->debug($message, ['app' => 'Federated File Sharing']);
187
+            throw new \Exception($message_t);
188
+        }
189
+
190
+
191
+        $share->setSharedWith($cloudId->getId());
192
+
193
+        try {
194
+            $remoteShare = $this->getShareFromExternalShareTable($share);
195
+        } catch (ShareNotFound $e) {
196
+            $remoteShare = null;
197
+        }
198
+
199
+        if ($remoteShare) {
200
+            try {
201
+                $ownerCloudId = $this->cloudIdManager->getCloudId($remoteShare['owner'], $remoteShare['remote']);
202
+                $shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time());
203
+                $share->setId($shareId);
204
+                list($token, $remoteId) = $this->askOwnerToReShare($shareWith, $share, $shareId);
205
+                // remote share was create successfully if we get a valid token as return
206
+                $send = is_string($token) && $token !== '';
207
+            } catch (\Exception $e) {
208
+                // fall back to old re-share behavior if the remote server
209
+                // doesn't support flat re-shares (was introduced with Nextcloud 9.1)
210
+                $this->removeShareFromTable($share);
211
+                $shareId = $this->createFederatedShare($share);
212
+            }
213
+            if ($send) {
214
+                $this->updateSuccessfulReshare($shareId, $token);
215
+                $this->storeRemoteId($shareId, $remoteId);
216
+            } else {
217
+                $this->removeShareFromTable($share);
218
+                $message_t = $this->l->t('File is already shared with %s', [$shareWith]);
219
+                throw new \Exception($message_t);
220
+            }
221
+
222
+        } else {
223
+            $shareId = $this->createFederatedShare($share);
224
+        }
225
+
226
+        $data = $this->getRawShare($shareId);
227
+        return $this->createShareObject($data);
228
+    }
229
+
230
+    /**
231
+     * create federated share and inform the recipient
232
+     *
233
+     * @param IShare $share
234
+     * @return int
235
+     * @throws ShareNotFound
236
+     * @throws \Exception
237
+     */
238
+    protected function createFederatedShare(IShare $share) {
239
+        $token = $this->tokenHandler->generateToken();
240
+        $shareId = $this->addShareToDB(
241
+            $share->getNodeId(),
242
+            $share->getNodeType(),
243
+            $share->getSharedWith(),
244
+            $share->getSharedBy(),
245
+            $share->getShareOwner(),
246
+            $share->getPermissions(),
247
+            $token
248
+        );
249
+
250
+        $failure = false;
251
+
252
+        try {
253
+            $sharedByFederatedId = $share->getSharedBy();
254
+            if ($this->userManager->userExists($sharedByFederatedId)) {
255
+                $cloudId = $this->cloudIdManager->getCloudId($sharedByFederatedId, $this->addressHandler->generateRemoteURL());
256
+                $sharedByFederatedId = $cloudId->getId();
257
+            }
258
+            $ownerCloudId = $this->cloudIdManager->getCloudId($share->getShareOwner(), $this->addressHandler->generateRemoteURL());
259
+            $send = $this->notifications->sendRemoteShare(
260
+                $token,
261
+                $share->getSharedWith(),
262
+                $share->getNode()->getName(),
263
+                $shareId,
264
+                $share->getShareOwner(),
265
+                $ownerCloudId->getId(),
266
+                $share->getSharedBy(),
267
+                $sharedByFederatedId,
268
+                $share->setShareType()
269
+            );
270
+
271
+            if ($send === false) {
272
+                $failure = true;
273
+            }
274
+        } catch (\Exception $e) {
275
+            $this->logger->logException($e, [
276
+                'message' => 'Failed to notify remote server of federated share, removing share.',
277
+                'level' => ILogger::ERROR,
278
+                'app' => 'federatedfilesharing',
279
+            ]);
280
+            $failure = true;
281
+        }
282
+
283
+        if($failure) {
284
+            $this->removeShareFromTableById($shareId);
285
+            $message_t = $this->l->t('Sharing %s failed, could not find %s, maybe the server is currently unreachable or uses a self-signed certificate.',
286
+                [$share->getNode()->getName(), $share->getSharedWith()]);
287
+            throw new \Exception($message_t);
288
+        }
289
+
290
+        return $shareId;
291
+
292
+    }
293
+
294
+    /**
295
+     * @param string $shareWith
296
+     * @param IShare $share
297
+     * @param string $shareId internal share Id
298
+     * @return array
299
+     * @throws \Exception
300
+     */
301
+    protected function askOwnerToReShare($shareWith, IShare $share, $shareId) {
302
+
303
+        $remoteShare = $this->getShareFromExternalShareTable($share);
304
+        $token = $remoteShare['share_token'];
305
+        $remoteId = $remoteShare['remote_id'];
306
+        $remote = $remoteShare['remote'];
307
+
308
+        list($token, $remoteId) = $this->notifications->requestReShare(
309
+            $token,
310
+            $remoteId,
311
+            $shareId,
312
+            $remote,
313
+            $shareWith,
314
+            $share->getPermissions(),
315
+            $share->getNode()->getName()
316
+        );
317
+
318
+        return [$token, $remoteId];
319
+    }
320
+
321
+    /**
322
+     * get federated share from the share_external table but exclude mounted link shares
323
+     *
324
+     * @param IShare $share
325
+     * @return array
326
+     * @throws ShareNotFound
327
+     */
328
+    protected function getShareFromExternalShareTable(IShare $share) {
329
+        $query = $this->dbConnection->getQueryBuilder();
330
+        $query->select('*')->from($this->externalShareTable)
331
+            ->where($query->expr()->eq('user', $query->createNamedParameter($share->getShareOwner())))
332
+            ->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($share->getTarget())));
333
+        $result = $query->execute()->fetchAll();
334
+
335
+        if (isset($result[0]) && (int)$result[0]['remote_id'] > 0) {
336
+            return $result[0];
337
+        }
338
+
339
+        throw new ShareNotFound('share not found in share_external table');
340
+    }
341
+
342
+    /**
343
+     * add share to the database and return the ID
344
+     *
345
+     * @param int $itemSource
346
+     * @param string $itemType
347
+     * @param string $shareWith
348
+     * @param string $sharedBy
349
+     * @param string $uidOwner
350
+     * @param int $permissions
351
+     * @param string $token
352
+     * @return int
353
+     */
354
+    private function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) {
355
+        $qb = $this->dbConnection->getQueryBuilder();
356
+        $qb->insert('share')
357
+            ->setValue('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))
358
+            ->setValue('item_type', $qb->createNamedParameter($itemType))
359
+            ->setValue('item_source', $qb->createNamedParameter($itemSource))
360
+            ->setValue('file_source', $qb->createNamedParameter($itemSource))
361
+            ->setValue('share_with', $qb->createNamedParameter($shareWith))
362
+            ->setValue('uid_owner', $qb->createNamedParameter($uidOwner))
363
+            ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy))
364
+            ->setValue('permissions', $qb->createNamedParameter($permissions))
365
+            ->setValue('token', $qb->createNamedParameter($token))
366
+            ->setValue('stime', $qb->createNamedParameter(time()));
367
+
368
+        /*
369 369
 		 * Added to fix https://github.com/owncloud/core/issues/22215
370 370
 		 * Can be removed once we get rid of ajax/share.php
371 371
 		 */
372
-		$qb->setValue('file_target', $qb->createNamedParameter(''));
373
-
374
-		$qb->execute();
375
-		$id = $qb->getLastInsertId();
376
-
377
-		return (int)$id;
378
-	}
379
-
380
-	/**
381
-	 * Update a share
382
-	 *
383
-	 * @param IShare $share
384
-	 * @return IShare The share object
385
-	 */
386
-	public function update(IShare $share) {
387
-		/*
372
+        $qb->setValue('file_target', $qb->createNamedParameter(''));
373
+
374
+        $qb->execute();
375
+        $id = $qb->getLastInsertId();
376
+
377
+        return (int)$id;
378
+    }
379
+
380
+    /**
381
+     * Update a share
382
+     *
383
+     * @param IShare $share
384
+     * @return IShare The share object
385
+     */
386
+    public function update(IShare $share) {
387
+        /*
388 388
 		 * We allow updating the permissions of federated shares
389 389
 		 */
390
-		$qb = $this->dbConnection->getQueryBuilder();
391
-			$qb->update('share')
392
-				->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
393
-				->set('permissions', $qb->createNamedParameter($share->getPermissions()))
394
-				->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
395
-				->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
396
-				->execute();
397
-
398
-		// send the updated permission to the owner/initiator, if they are not the same
399
-		if ($share->getShareOwner() !== $share->getSharedBy()) {
400
-			$this->sendPermissionUpdate($share);
401
-		}
402
-
403
-		return $share;
404
-	}
405
-
406
-	/**
407
-	 * send the updated permission to the owner/initiator, if they are not the same
408
-	 *
409
-	 * @param IShare $share
410
-	 * @throws ShareNotFound
411
-	 * @throws \OC\HintException
412
-	 */
413
-	protected function sendPermissionUpdate(IShare $share) {
414
-		$remoteId = $this->getRemoteId($share);
415
-		// if the local user is the owner we send the permission change to the initiator
416
-		if ($this->userManager->userExists($share->getShareOwner())) {
417
-			list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
418
-		} else { // ... if not we send the permission change to the owner
419
-			list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner());
420
-		}
421
-		$this->notifications->sendPermissionChange($remote, $remoteId, $share->getToken(), $share->getPermissions());
422
-	}
423
-
424
-
425
-	/**
426
-	 * update successful reShare with the correct token
427
-	 *
428
-	 * @param int $shareId
429
-	 * @param string $token
430
-	 */
431
-	protected function updateSuccessfulReShare($shareId, $token) {
432
-		$query = $this->dbConnection->getQueryBuilder();
433
-		$query->update('share')
434
-			->where($query->expr()->eq('id', $query->createNamedParameter($shareId)))
435
-			->set('token', $query->createNamedParameter($token))
436
-			->execute();
437
-	}
438
-
439
-	/**
440
-	 * store remote ID in federated reShare table
441
-	 *
442
-	 * @param $shareId
443
-	 * @param $remoteId
444
-	 */
445
-	public function storeRemoteId($shareId, $remoteId) {
446
-		$query = $this->dbConnection->getQueryBuilder();
447
-		$query->insert('federated_reshares')
448
-			->values(
449
-				[
450
-					'share_id' =>  $query->createNamedParameter($shareId),
451
-					'remote_id' => $query->createNamedParameter($remoteId),
452
-				]
453
-			);
454
-		$query->execute();
455
-	}
456
-
457
-	/**
458
-	 * get share ID on remote server for federated re-shares
459
-	 *
460
-	 * @param IShare $share
461
-	 * @return int
462
-	 * @throws ShareNotFound
463
-	 */
464
-	public function getRemoteId(IShare $share) {
465
-		$query = $this->dbConnection->getQueryBuilder();
466
-		$query->select('remote_id')->from('federated_reshares')
467
-			->where($query->expr()->eq('share_id', $query->createNamedParameter((int)$share->getId())));
468
-		$data = $query->execute()->fetch();
469
-
470
-		if (!is_array($data) || !isset($data['remote_id'])) {
471
-			throw new ShareNotFound();
472
-		}
473
-
474
-		return (int)$data['remote_id'];
475
-	}
476
-
477
-	/**
478
-	 * @inheritdoc
479
-	 */
480
-	public function move(IShare $share, $recipient) {
481
-		/*
390
+        $qb = $this->dbConnection->getQueryBuilder();
391
+            $qb->update('share')
392
+                ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
393
+                ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
394
+                ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
395
+                ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
396
+                ->execute();
397
+
398
+        // send the updated permission to the owner/initiator, if they are not the same
399
+        if ($share->getShareOwner() !== $share->getSharedBy()) {
400
+            $this->sendPermissionUpdate($share);
401
+        }
402
+
403
+        return $share;
404
+    }
405
+
406
+    /**
407
+     * send the updated permission to the owner/initiator, if they are not the same
408
+     *
409
+     * @param IShare $share
410
+     * @throws ShareNotFound
411
+     * @throws \OC\HintException
412
+     */
413
+    protected function sendPermissionUpdate(IShare $share) {
414
+        $remoteId = $this->getRemoteId($share);
415
+        // if the local user is the owner we send the permission change to the initiator
416
+        if ($this->userManager->userExists($share->getShareOwner())) {
417
+            list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
418
+        } else { // ... if not we send the permission change to the owner
419
+            list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner());
420
+        }
421
+        $this->notifications->sendPermissionChange($remote, $remoteId, $share->getToken(), $share->getPermissions());
422
+    }
423
+
424
+
425
+    /**
426
+     * update successful reShare with the correct token
427
+     *
428
+     * @param int $shareId
429
+     * @param string $token
430
+     */
431
+    protected function updateSuccessfulReShare($shareId, $token) {
432
+        $query = $this->dbConnection->getQueryBuilder();
433
+        $query->update('share')
434
+            ->where($query->expr()->eq('id', $query->createNamedParameter($shareId)))
435
+            ->set('token', $query->createNamedParameter($token))
436
+            ->execute();
437
+    }
438
+
439
+    /**
440
+     * store remote ID in federated reShare table
441
+     *
442
+     * @param $shareId
443
+     * @param $remoteId
444
+     */
445
+    public function storeRemoteId($shareId, $remoteId) {
446
+        $query = $this->dbConnection->getQueryBuilder();
447
+        $query->insert('federated_reshares')
448
+            ->values(
449
+                [
450
+                    'share_id' =>  $query->createNamedParameter($shareId),
451
+                    'remote_id' => $query->createNamedParameter($remoteId),
452
+                ]
453
+            );
454
+        $query->execute();
455
+    }
456
+
457
+    /**
458
+     * get share ID on remote server for federated re-shares
459
+     *
460
+     * @param IShare $share
461
+     * @return int
462
+     * @throws ShareNotFound
463
+     */
464
+    public function getRemoteId(IShare $share) {
465
+        $query = $this->dbConnection->getQueryBuilder();
466
+        $query->select('remote_id')->from('federated_reshares')
467
+            ->where($query->expr()->eq('share_id', $query->createNamedParameter((int)$share->getId())));
468
+        $data = $query->execute()->fetch();
469
+
470
+        if (!is_array($data) || !isset($data['remote_id'])) {
471
+            throw new ShareNotFound();
472
+        }
473
+
474
+        return (int)$data['remote_id'];
475
+    }
476
+
477
+    /**
478
+     * @inheritdoc
479
+     */
480
+    public function move(IShare $share, $recipient) {
481
+        /*
482 482
 		 * This function does nothing yet as it is just for outgoing
483 483
 		 * federated shares.
484 484
 		 */
485
-		return $share;
486
-	}
487
-
488
-	/**
489
-	 * Get all children of this share
490
-	 *
491
-	 * @param IShare $parent
492
-	 * @return IShare[]
493
-	 */
494
-	public function getChildren(IShare $parent) {
495
-		$children = [];
496
-
497
-		$qb = $this->dbConnection->getQueryBuilder();
498
-		$qb->select('*')
499
-			->from('share')
500
-			->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId())))
501
-			->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)))
502
-			->orderBy('id');
503
-
504
-		$cursor = $qb->execute();
505
-		while($data = $cursor->fetch()) {
506
-			$children[] = $this->createShareObject($data);
507
-		}
508
-		$cursor->closeCursor();
509
-
510
-		return $children;
511
-	}
512
-
513
-	/**
514
-	 * Delete a share (owner unShares the file)
515
-	 *
516
-	 * @param IShare $share
517
-	 * @throws ShareNotFound
518
-	 * @throws \OC\HintException
519
-	 */
520
-	public function delete(IShare $share) {
521
-
522
-		list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedWith());
523
-
524
-		// if the local user is the owner we can send the unShare request directly...
525
-		if ($this->userManager->userExists($share->getShareOwner())) {
526
-			$this->notifications->sendRemoteUnShare($remote, $share->getId(), $share->getToken());
527
-			$this->revokeShare($share, true);
528
-		} else { // ... if not we need to correct ID for the unShare request
529
-			$remoteId = $this->getRemoteId($share);
530
-			$this->notifications->sendRemoteUnShare($remote, $remoteId, $share->getToken());
531
-			$this->revokeShare($share, false);
532
-		}
533
-
534
-		// only remove the share when all messages are send to not lose information
535
-		// about the share to early
536
-		$this->removeShareFromTable($share);
537
-	}
538
-
539
-	/**
540
-	 * in case of a re-share we need to send the other use (initiator or owner)
541
-	 * a message that the file was unshared
542
-	 *
543
-	 * @param IShare $share
544
-	 * @param bool $isOwner the user can either be the owner or the user who re-sahred it
545
-	 * @throws ShareNotFound
546
-	 * @throws \OC\HintException
547
-	 */
548
-	protected function revokeShare($share, $isOwner) {
549
-		// also send a unShare request to the initiator, if this is a different user than the owner
550
-		if ($share->getShareOwner() !== $share->getSharedBy()) {
551
-			if ($isOwner) {
552
-				list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
553
-			} else {
554
-				list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner());
555
-			}
556
-			$remoteId = $this->getRemoteId($share);
557
-			$this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken());
558
-		}
559
-	}
560
-
561
-	/**
562
-	 * remove share from table
563
-	 *
564
-	 * @param IShare $share
565
-	 */
566
-	public function removeShareFromTable(IShare $share) {
567
-		$this->removeShareFromTableById($share->getId());
568
-	}
569
-
570
-	/**
571
-	 * remove share from table
572
-	 *
573
-	 * @param string $shareId
574
-	 */
575
-	private function removeShareFromTableById($shareId) {
576
-		$qb = $this->dbConnection->getQueryBuilder();
577
-		$qb->delete('share')
578
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId)));
579
-		$qb->execute();
580
-
581
-		$qb->delete('federated_reshares')
582
-			->where($qb->expr()->eq('share_id', $qb->createNamedParameter($shareId)));
583
-		$qb->execute();
584
-	}
585
-
586
-	/**
587
-	 * @inheritdoc
588
-	 */
589
-	public function deleteFromSelf(IShare $share, $recipient) {
590
-		// nothing to do here. Technically deleteFromSelf in the context of federated
591
-		// shares is a umount of a external storage. This is handled here
592
-		// apps/files_sharing/lib/external/manager.php
593
-		// TODO move this code over to this app
594
-	}
595
-
596
-
597
-	public function getSharesInFolder($userId, Folder $node, $reshares) {
598
-		$qb = $this->dbConnection->getQueryBuilder();
599
-		$qb->select('*')
600
-			->from('share', 's')
601
-			->andWhere($qb->expr()->orX(
602
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
603
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
604
-			))
605
-			->andWhere(
606
-				$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE))
607
-			);
608
-
609
-		/**
610
-		 * Reshares for this user are shares where they are the owner.
611
-		 */
612
-		if ($reshares === false) {
613
-			$qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
614
-		} else {
615
-			$qb->andWhere(
616
-				$qb->expr()->orX(
617
-					$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
618
-					$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
619
-				)
620
-			);
621
-		}
622
-
623
-		$qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
624
-		$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
625
-
626
-		$qb->orderBy('id');
627
-
628
-		$cursor = $qb->execute();
629
-		$shares = [];
630
-		while ($data = $cursor->fetch()) {
631
-			$shares[$data['fileid']][] = $this->createShareObject($data);
632
-		}
633
-		$cursor->closeCursor();
634
-
635
-		return $shares;
636
-	}
637
-
638
-	/**
639
-	 * @inheritdoc
640
-	 */
641
-	public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) {
642
-		$qb = $this->dbConnection->getQueryBuilder();
643
-		$qb->select('*')
644
-			->from('share');
645
-
646
-		$qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)));
647
-
648
-		/**
649
-		 * Reshares for this user are shares where they are the owner.
650
-		 */
651
-		if ($reshares === false) {
652
-			//Special case for old shares created via the web UI
653
-			$or1 = $qb->expr()->andX(
654
-				$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
655
-				$qb->expr()->isNull('uid_initiator')
656
-			);
657
-
658
-			$qb->andWhere(
659
-				$qb->expr()->orX(
660
-					$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)),
661
-					$or1
662
-				)
663
-			);
664
-		} else {
665
-			$qb->andWhere(
666
-				$qb->expr()->orX(
667
-					$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
668
-					$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
669
-				)
670
-			);
671
-		}
672
-
673
-		if ($node !== null) {
674
-			$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
675
-		}
676
-
677
-		if ($limit !== -1) {
678
-			$qb->setMaxResults($limit);
679
-		}
680
-
681
-		$qb->setFirstResult($offset);
682
-		$qb->orderBy('id');
683
-
684
-		$cursor = $qb->execute();
685
-		$shares = [];
686
-		while($data = $cursor->fetch()) {
687
-			$shares[] = $this->createShareObject($data);
688
-		}
689
-		$cursor->closeCursor();
690
-
691
-		return $shares;
692
-	}
693
-
694
-	/**
695
-	 * @inheritdoc
696
-	 */
697
-	public function getShareById($id, $recipientId = null) {
698
-		$qb = $this->dbConnection->getQueryBuilder();
699
-
700
-		$qb->select('*')
701
-			->from('share')
702
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
703
-			->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)));
704
-
705
-		$cursor = $qb->execute();
706
-		$data = $cursor->fetch();
707
-		$cursor->closeCursor();
708
-
709
-		if ($data === false) {
710
-			throw new ShareNotFound('Can not find share with ID: ' . $id);
711
-		}
712
-
713
-		try {
714
-			$share = $this->createShareObject($data);
715
-		} catch (InvalidShare $e) {
716
-			throw new ShareNotFound();
717
-		}
718
-
719
-		return $share;
720
-	}
721
-
722
-	/**
723
-	 * Get shares for a given path
724
-	 *
725
-	 * @param \OCP\Files\Node $path
726
-	 * @return IShare[]
727
-	 */
728
-	public function getSharesByPath(Node $path) {
729
-		$qb = $this->dbConnection->getQueryBuilder();
730
-
731
-		$cursor = $qb->select('*')
732
-			->from('share')
733
-			->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId())))
734
-			->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)))
735
-			->execute();
736
-
737
-		$shares = [];
738
-		while($data = $cursor->fetch()) {
739
-			$shares[] = $this->createShareObject($data);
740
-		}
741
-		$cursor->closeCursor();
742
-
743
-		return $shares;
744
-	}
745
-
746
-	/**
747
-	 * @inheritdoc
748
-	 */
749
-	public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
750
-		/** @var IShare[] $shares */
751
-		$shares = [];
752
-
753
-		//Get shares directly with this user
754
-		$qb = $this->dbConnection->getQueryBuilder();
755
-		$qb->select('*')
756
-			->from('share');
757
-
758
-		// Order by id
759
-		$qb->orderBy('id');
760
-
761
-		// Set limit and offset
762
-		if ($limit !== -1) {
763
-			$qb->setMaxResults($limit);
764
-		}
765
-		$qb->setFirstResult($offset);
766
-
767
-		$qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)));
768
-		$qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)));
769
-
770
-		// Filter by node if provided
771
-		if ($node !== null) {
772
-			$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
773
-		}
774
-
775
-		$cursor = $qb->execute();
776
-
777
-		while($data = $cursor->fetch()) {
778
-			$shares[] = $this->createShareObject($data);
779
-		}
780
-		$cursor->closeCursor();
781
-
782
-
783
-		return $shares;
784
-	}
785
-
786
-	/**
787
-	 * Get a share by token
788
-	 *
789
-	 * @param string $token
790
-	 * @return IShare
791
-	 * @throws ShareNotFound
792
-	 */
793
-	public function getShareByToken($token) {
794
-		$qb = $this->dbConnection->getQueryBuilder();
795
-
796
-		$cursor = $qb->select('*')
797
-			->from('share')
798
-			->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)))
799
-			->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)))
800
-			->execute();
801
-
802
-		$data = $cursor->fetch();
803
-
804
-		if ($data === false) {
805
-			throw new ShareNotFound('Share not found', $this->l->t('Could not find share'));
806
-		}
807
-
808
-		try {
809
-			$share = $this->createShareObject($data);
810
-		} catch (InvalidShare $e) {
811
-			throw new ShareNotFound('Share not found', $this->l->t('Could not find share'));
812
-		}
813
-
814
-		return $share;
815
-	}
816
-
817
-	/**
818
-	 * get database row of a give share
819
-	 *
820
-	 * @param $id
821
-	 * @return array
822
-	 * @throws ShareNotFound
823
-	 */
824
-	private function getRawShare($id) {
825
-
826
-		// Now fetch the inserted share and create a complete share object
827
-		$qb = $this->dbConnection->getQueryBuilder();
828
-		$qb->select('*')
829
-			->from('share')
830
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
831
-
832
-		$cursor = $qb->execute();
833
-		$data = $cursor->fetch();
834
-		$cursor->closeCursor();
835
-
836
-		if ($data === false) {
837
-			throw new ShareNotFound;
838
-		}
839
-
840
-		return $data;
841
-	}
842
-
843
-	/**
844
-	 * Create a share object from an database row
845
-	 *
846
-	 * @param array $data
847
-	 * @return IShare
848
-	 * @throws InvalidShare
849
-	 * @throws ShareNotFound
850
-	 */
851
-	private function createShareObject($data) {
852
-
853
-		$share = new Share($this->rootFolder, $this->userManager);
854
-		$share->setId((int)$data['id'])
855
-			->setShareType((int)$data['share_type'])
856
-			->setPermissions((int)$data['permissions'])
857
-			->setTarget($data['file_target'])
858
-			->setMailSend((bool)$data['mail_send'])
859
-			->setToken($data['token']);
860
-
861
-		$shareTime = new \DateTime();
862
-		$shareTime->setTimestamp((int)$data['stime']);
863
-		$share->setShareTime($shareTime);
864
-		$share->setSharedWith($data['share_with']);
865
-
866
-		if ($data['uid_initiator'] !== null) {
867
-			$share->setShareOwner($data['uid_owner']);
868
-			$share->setSharedBy($data['uid_initiator']);
869
-		} else {
870
-			//OLD SHARE
871
-			$share->setSharedBy($data['uid_owner']);
872
-			$path = $this->getNode($share->getSharedBy(), (int)$data['file_source']);
873
-
874
-			$owner = $path->getOwner();
875
-			$share->setShareOwner($owner->getUID());
876
-		}
877
-
878
-		$share->setNodeId((int)$data['file_source']);
879
-		$share->setNodeType($data['item_type']);
880
-
881
-		$share->setProviderId($this->identifier());
882
-
883
-		return $share;
884
-	}
885
-
886
-	/**
887
-	 * Get the node with file $id for $user
888
-	 *
889
-	 * @param string $userId
890
-	 * @param int $id
891
-	 * @return \OCP\Files\File|\OCP\Files\Folder
892
-	 * @throws InvalidShare
893
-	 */
894
-	private function getNode($userId, $id) {
895
-		try {
896
-			$userFolder = $this->rootFolder->getUserFolder($userId);
897
-		} catch (NotFoundException $e) {
898
-			throw new InvalidShare();
899
-		}
900
-
901
-		$nodes = $userFolder->getById($id);
902
-
903
-		if (empty($nodes)) {
904
-			throw new InvalidShare();
905
-		}
906
-
907
-		return $nodes[0];
908
-	}
909
-
910
-	/**
911
-	 * A user is deleted from the system
912
-	 * So clean up the relevant shares.
913
-	 *
914
-	 * @param string $uid
915
-	 * @param int $shareType
916
-	 */
917
-	public function userDeleted($uid, $shareType) {
918
-		//TODO: probabaly a good idea to send unshare info to remote servers
919
-
920
-		$qb = $this->dbConnection->getQueryBuilder();
921
-
922
-		$qb->delete('share')
923
-			->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE)))
924
-			->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)))
925
-			->execute();
926
-	}
927
-
928
-	/**
929
-	 * This provider does not handle groups
930
-	 *
931
-	 * @param string $gid
932
-	 */
933
-	public function groupDeleted($gid) {
934
-		// We don't handle groups here
935
-	}
936
-
937
-	/**
938
-	 * This provider does not handle groups
939
-	 *
940
-	 * @param string $uid
941
-	 * @param string $gid
942
-	 */
943
-	public function userDeletedFromGroup($uid, $gid) {
944
-		// We don't handle groups here
945
-	}
946
-
947
-	/**
948
-	 * check if users from other Nextcloud instances are allowed to mount public links share by this instance
949
-	 *
950
-	 * @return bool
951
-	 */
952
-	public function isOutgoingServer2serverShareEnabled() {
953
-		if ($this->gsConfig->onlyInternalFederation()) {
954
-			return false;
955
-		}
956
-		$result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes');
957
-		return ($result === 'yes');
958
-	}
959
-
960
-	/**
961
-	 * check if users are allowed to mount public links from other Nextclouds
962
-	 *
963
-	 * @return bool
964
-	 */
965
-	public function isIncomingServer2serverShareEnabled() {
966
-		if ($this->gsConfig->onlyInternalFederation()) {
967
-			return false;
968
-		}
969
-		$result = $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes');
970
-		return ($result === 'yes');
971
-	}
972
-
973
-
974
-	/**
975
-	 * check if users from other Nextcloud instances are allowed to send federated group shares
976
-	 *
977
-	 * @return bool
978
-	 */
979
-	public function isOutgoingServer2serverGroupShareEnabled() {
980
-		if ($this->gsConfig->onlyInternalFederation()) {
981
-			return false;
982
-		}
983
-		$result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_group_share_enabled', 'no');
984
-		return ($result === 'yes');
985
-	}
986
-
987
-	/**
988
-	 * check if users are allowed to receive federated group shares
989
-	 *
990
-	 * @return bool
991
-	 */
992
-	public function isIncomingServer2serverGroupShareEnabled() {
993
-		if ($this->gsConfig->onlyInternalFederation()) {
994
-			return false;
995
-		}
996
-		$result = $this->config->getAppValue('files_sharing', 'incoming_server2server_group_share_enabled', 'no');
997
-		return ($result === 'yes');
998
-	}
999
-
1000
-	/**
1001
-	 * check if federated group sharing is supported, therefore the OCM API need to be enabled
1002
-	 *
1003
-	 * @return bool
1004
-	 */
1005
-	public function isFederatedGroupSharingSupported() {
1006
-		return $this->cloudFederationProviderManager->isReady();
1007
-	}
1008
-
1009
-	/**
1010
-	 * Check if querying sharees on the lookup server is enabled
1011
-	 *
1012
-	 * @return bool
1013
-	 */
1014
-	public function isLookupServerQueriesEnabled() {
1015
-		// in a global scale setup we should always query the lookup server
1016
-		if ($this->gsConfig->isGlobalScaleEnabled()) {
1017
-			return true;
1018
-		}
1019
-		$result = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no');
1020
-		return ($result === 'yes');
1021
-	}
1022
-
1023
-
1024
-	/**
1025
-	 * Check if it is allowed to publish user specific data to the lookup server
1026
-	 *
1027
-	 * @return bool
1028
-	 */
1029
-	public function isLookupServerUploadEnabled() {
1030
-		// in a global scale setup the admin is responsible to keep the lookup server up-to-date
1031
-		if ($this->gsConfig->isGlobalScaleEnabled()) {
1032
-			return false;
1033
-		}
1034
-		$result = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes');
1035
-		return ($result === 'yes');
1036
-	}
1037
-
1038
-	/**
1039
-	 * @inheritdoc
1040
-	 */
1041
-	public function getAccessList($nodes, $currentAccess) {
1042
-		$ids = [];
1043
-		foreach ($nodes as $node) {
1044
-			$ids[] = $node->getId();
1045
-		}
1046
-
1047
-		$qb = $this->dbConnection->getQueryBuilder();
1048
-		$qb->select('share_with', 'token', 'file_source')
1049
-			->from('share')
1050
-			->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE)))
1051
-			->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)))
1052
-			->andWhere($qb->expr()->orX(
1053
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
1054
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
1055
-			));
1056
-		$cursor = $qb->execute();
1057
-
1058
-		if ($currentAccess === false) {
1059
-			$remote = $cursor->fetch() !== false;
1060
-			$cursor->closeCursor();
1061
-
1062
-			return ['remote' => $remote];
1063
-		}
1064
-
1065
-		$remote = [];
1066
-		while ($row = $cursor->fetch()) {
1067
-			$remote[$row['share_with']] = [
1068
-				'node_id' => $row['file_source'],
1069
-				'token' => $row['token'],
1070
-			];
1071
-		}
1072
-		$cursor->closeCursor();
1073
-
1074
-		return ['remote' => $remote];
1075
-	}
485
+        return $share;
486
+    }
487
+
488
+    /**
489
+     * Get all children of this share
490
+     *
491
+     * @param IShare $parent
492
+     * @return IShare[]
493
+     */
494
+    public function getChildren(IShare $parent) {
495
+        $children = [];
496
+
497
+        $qb = $this->dbConnection->getQueryBuilder();
498
+        $qb->select('*')
499
+            ->from('share')
500
+            ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId())))
501
+            ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)))
502
+            ->orderBy('id');
503
+
504
+        $cursor = $qb->execute();
505
+        while($data = $cursor->fetch()) {
506
+            $children[] = $this->createShareObject($data);
507
+        }
508
+        $cursor->closeCursor();
509
+
510
+        return $children;
511
+    }
512
+
513
+    /**
514
+     * Delete a share (owner unShares the file)
515
+     *
516
+     * @param IShare $share
517
+     * @throws ShareNotFound
518
+     * @throws \OC\HintException
519
+     */
520
+    public function delete(IShare $share) {
521
+
522
+        list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedWith());
523
+
524
+        // if the local user is the owner we can send the unShare request directly...
525
+        if ($this->userManager->userExists($share->getShareOwner())) {
526
+            $this->notifications->sendRemoteUnShare($remote, $share->getId(), $share->getToken());
527
+            $this->revokeShare($share, true);
528
+        } else { // ... if not we need to correct ID for the unShare request
529
+            $remoteId = $this->getRemoteId($share);
530
+            $this->notifications->sendRemoteUnShare($remote, $remoteId, $share->getToken());
531
+            $this->revokeShare($share, false);
532
+        }
533
+
534
+        // only remove the share when all messages are send to not lose information
535
+        // about the share to early
536
+        $this->removeShareFromTable($share);
537
+    }
538
+
539
+    /**
540
+     * in case of a re-share we need to send the other use (initiator or owner)
541
+     * a message that the file was unshared
542
+     *
543
+     * @param IShare $share
544
+     * @param bool $isOwner the user can either be the owner or the user who re-sahred it
545
+     * @throws ShareNotFound
546
+     * @throws \OC\HintException
547
+     */
548
+    protected function revokeShare($share, $isOwner) {
549
+        // also send a unShare request to the initiator, if this is a different user than the owner
550
+        if ($share->getShareOwner() !== $share->getSharedBy()) {
551
+            if ($isOwner) {
552
+                list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
553
+            } else {
554
+                list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner());
555
+            }
556
+            $remoteId = $this->getRemoteId($share);
557
+            $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken());
558
+        }
559
+    }
560
+
561
+    /**
562
+     * remove share from table
563
+     *
564
+     * @param IShare $share
565
+     */
566
+    public function removeShareFromTable(IShare $share) {
567
+        $this->removeShareFromTableById($share->getId());
568
+    }
569
+
570
+    /**
571
+     * remove share from table
572
+     *
573
+     * @param string $shareId
574
+     */
575
+    private function removeShareFromTableById($shareId) {
576
+        $qb = $this->dbConnection->getQueryBuilder();
577
+        $qb->delete('share')
578
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId)));
579
+        $qb->execute();
580
+
581
+        $qb->delete('federated_reshares')
582
+            ->where($qb->expr()->eq('share_id', $qb->createNamedParameter($shareId)));
583
+        $qb->execute();
584
+    }
585
+
586
+    /**
587
+     * @inheritdoc
588
+     */
589
+    public function deleteFromSelf(IShare $share, $recipient) {
590
+        // nothing to do here. Technically deleteFromSelf in the context of federated
591
+        // shares is a umount of a external storage. This is handled here
592
+        // apps/files_sharing/lib/external/manager.php
593
+        // TODO move this code over to this app
594
+    }
595
+
596
+
597
+    public function getSharesInFolder($userId, Folder $node, $reshares) {
598
+        $qb = $this->dbConnection->getQueryBuilder();
599
+        $qb->select('*')
600
+            ->from('share', 's')
601
+            ->andWhere($qb->expr()->orX(
602
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
603
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
604
+            ))
605
+            ->andWhere(
606
+                $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE))
607
+            );
608
+
609
+        /**
610
+         * Reshares for this user are shares where they are the owner.
611
+         */
612
+        if ($reshares === false) {
613
+            $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
614
+        } else {
615
+            $qb->andWhere(
616
+                $qb->expr()->orX(
617
+                    $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
618
+                    $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
619
+                )
620
+            );
621
+        }
622
+
623
+        $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
624
+        $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
625
+
626
+        $qb->orderBy('id');
627
+
628
+        $cursor = $qb->execute();
629
+        $shares = [];
630
+        while ($data = $cursor->fetch()) {
631
+            $shares[$data['fileid']][] = $this->createShareObject($data);
632
+        }
633
+        $cursor->closeCursor();
634
+
635
+        return $shares;
636
+    }
637
+
638
+    /**
639
+     * @inheritdoc
640
+     */
641
+    public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) {
642
+        $qb = $this->dbConnection->getQueryBuilder();
643
+        $qb->select('*')
644
+            ->from('share');
645
+
646
+        $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)));
647
+
648
+        /**
649
+         * Reshares for this user are shares where they are the owner.
650
+         */
651
+        if ($reshares === false) {
652
+            //Special case for old shares created via the web UI
653
+            $or1 = $qb->expr()->andX(
654
+                $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
655
+                $qb->expr()->isNull('uid_initiator')
656
+            );
657
+
658
+            $qb->andWhere(
659
+                $qb->expr()->orX(
660
+                    $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)),
661
+                    $or1
662
+                )
663
+            );
664
+        } else {
665
+            $qb->andWhere(
666
+                $qb->expr()->orX(
667
+                    $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
668
+                    $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
669
+                )
670
+            );
671
+        }
672
+
673
+        if ($node !== null) {
674
+            $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
675
+        }
676
+
677
+        if ($limit !== -1) {
678
+            $qb->setMaxResults($limit);
679
+        }
680
+
681
+        $qb->setFirstResult($offset);
682
+        $qb->orderBy('id');
683
+
684
+        $cursor = $qb->execute();
685
+        $shares = [];
686
+        while($data = $cursor->fetch()) {
687
+            $shares[] = $this->createShareObject($data);
688
+        }
689
+        $cursor->closeCursor();
690
+
691
+        return $shares;
692
+    }
693
+
694
+    /**
695
+     * @inheritdoc
696
+     */
697
+    public function getShareById($id, $recipientId = null) {
698
+        $qb = $this->dbConnection->getQueryBuilder();
699
+
700
+        $qb->select('*')
701
+            ->from('share')
702
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
703
+            ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)));
704
+
705
+        $cursor = $qb->execute();
706
+        $data = $cursor->fetch();
707
+        $cursor->closeCursor();
708
+
709
+        if ($data === false) {
710
+            throw new ShareNotFound('Can not find share with ID: ' . $id);
711
+        }
712
+
713
+        try {
714
+            $share = $this->createShareObject($data);
715
+        } catch (InvalidShare $e) {
716
+            throw new ShareNotFound();
717
+        }
718
+
719
+        return $share;
720
+    }
721
+
722
+    /**
723
+     * Get shares for a given path
724
+     *
725
+     * @param \OCP\Files\Node $path
726
+     * @return IShare[]
727
+     */
728
+    public function getSharesByPath(Node $path) {
729
+        $qb = $this->dbConnection->getQueryBuilder();
730
+
731
+        $cursor = $qb->select('*')
732
+            ->from('share')
733
+            ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId())))
734
+            ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)))
735
+            ->execute();
736
+
737
+        $shares = [];
738
+        while($data = $cursor->fetch()) {
739
+            $shares[] = $this->createShareObject($data);
740
+        }
741
+        $cursor->closeCursor();
742
+
743
+        return $shares;
744
+    }
745
+
746
+    /**
747
+     * @inheritdoc
748
+     */
749
+    public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
750
+        /** @var IShare[] $shares */
751
+        $shares = [];
752
+
753
+        //Get shares directly with this user
754
+        $qb = $this->dbConnection->getQueryBuilder();
755
+        $qb->select('*')
756
+            ->from('share');
757
+
758
+        // Order by id
759
+        $qb->orderBy('id');
760
+
761
+        // Set limit and offset
762
+        if ($limit !== -1) {
763
+            $qb->setMaxResults($limit);
764
+        }
765
+        $qb->setFirstResult($offset);
766
+
767
+        $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)));
768
+        $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)));
769
+
770
+        // Filter by node if provided
771
+        if ($node !== null) {
772
+            $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
773
+        }
774
+
775
+        $cursor = $qb->execute();
776
+
777
+        while($data = $cursor->fetch()) {
778
+            $shares[] = $this->createShareObject($data);
779
+        }
780
+        $cursor->closeCursor();
781
+
782
+
783
+        return $shares;
784
+    }
785
+
786
+    /**
787
+     * Get a share by token
788
+     *
789
+     * @param string $token
790
+     * @return IShare
791
+     * @throws ShareNotFound
792
+     */
793
+    public function getShareByToken($token) {
794
+        $qb = $this->dbConnection->getQueryBuilder();
795
+
796
+        $cursor = $qb->select('*')
797
+            ->from('share')
798
+            ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)))
799
+            ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)))
800
+            ->execute();
801
+
802
+        $data = $cursor->fetch();
803
+
804
+        if ($data === false) {
805
+            throw new ShareNotFound('Share not found', $this->l->t('Could not find share'));
806
+        }
807
+
808
+        try {
809
+            $share = $this->createShareObject($data);
810
+        } catch (InvalidShare $e) {
811
+            throw new ShareNotFound('Share not found', $this->l->t('Could not find share'));
812
+        }
813
+
814
+        return $share;
815
+    }
816
+
817
+    /**
818
+     * get database row of a give share
819
+     *
820
+     * @param $id
821
+     * @return array
822
+     * @throws ShareNotFound
823
+     */
824
+    private function getRawShare($id) {
825
+
826
+        // Now fetch the inserted share and create a complete share object
827
+        $qb = $this->dbConnection->getQueryBuilder();
828
+        $qb->select('*')
829
+            ->from('share')
830
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
831
+
832
+        $cursor = $qb->execute();
833
+        $data = $cursor->fetch();
834
+        $cursor->closeCursor();
835
+
836
+        if ($data === false) {
837
+            throw new ShareNotFound;
838
+        }
839
+
840
+        return $data;
841
+    }
842
+
843
+    /**
844
+     * Create a share object from an database row
845
+     *
846
+     * @param array $data
847
+     * @return IShare
848
+     * @throws InvalidShare
849
+     * @throws ShareNotFound
850
+     */
851
+    private function createShareObject($data) {
852
+
853
+        $share = new Share($this->rootFolder, $this->userManager);
854
+        $share->setId((int)$data['id'])
855
+            ->setShareType((int)$data['share_type'])
856
+            ->setPermissions((int)$data['permissions'])
857
+            ->setTarget($data['file_target'])
858
+            ->setMailSend((bool)$data['mail_send'])
859
+            ->setToken($data['token']);
860
+
861
+        $shareTime = new \DateTime();
862
+        $shareTime->setTimestamp((int)$data['stime']);
863
+        $share->setShareTime($shareTime);
864
+        $share->setSharedWith($data['share_with']);
865
+
866
+        if ($data['uid_initiator'] !== null) {
867
+            $share->setShareOwner($data['uid_owner']);
868
+            $share->setSharedBy($data['uid_initiator']);
869
+        } else {
870
+            //OLD SHARE
871
+            $share->setSharedBy($data['uid_owner']);
872
+            $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']);
873
+
874
+            $owner = $path->getOwner();
875
+            $share->setShareOwner($owner->getUID());
876
+        }
877
+
878
+        $share->setNodeId((int)$data['file_source']);
879
+        $share->setNodeType($data['item_type']);
880
+
881
+        $share->setProviderId($this->identifier());
882
+
883
+        return $share;
884
+    }
885
+
886
+    /**
887
+     * Get the node with file $id for $user
888
+     *
889
+     * @param string $userId
890
+     * @param int $id
891
+     * @return \OCP\Files\File|\OCP\Files\Folder
892
+     * @throws InvalidShare
893
+     */
894
+    private function getNode($userId, $id) {
895
+        try {
896
+            $userFolder = $this->rootFolder->getUserFolder($userId);
897
+        } catch (NotFoundException $e) {
898
+            throw new InvalidShare();
899
+        }
900
+
901
+        $nodes = $userFolder->getById($id);
902
+
903
+        if (empty($nodes)) {
904
+            throw new InvalidShare();
905
+        }
906
+
907
+        return $nodes[0];
908
+    }
909
+
910
+    /**
911
+     * A user is deleted from the system
912
+     * So clean up the relevant shares.
913
+     *
914
+     * @param string $uid
915
+     * @param int $shareType
916
+     */
917
+    public function userDeleted($uid, $shareType) {
918
+        //TODO: probabaly a good idea to send unshare info to remote servers
919
+
920
+        $qb = $this->dbConnection->getQueryBuilder();
921
+
922
+        $qb->delete('share')
923
+            ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE)))
924
+            ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)))
925
+            ->execute();
926
+    }
927
+
928
+    /**
929
+     * This provider does not handle groups
930
+     *
931
+     * @param string $gid
932
+     */
933
+    public function groupDeleted($gid) {
934
+        // We don't handle groups here
935
+    }
936
+
937
+    /**
938
+     * This provider does not handle groups
939
+     *
940
+     * @param string $uid
941
+     * @param string $gid
942
+     */
943
+    public function userDeletedFromGroup($uid, $gid) {
944
+        // We don't handle groups here
945
+    }
946
+
947
+    /**
948
+     * check if users from other Nextcloud instances are allowed to mount public links share by this instance
949
+     *
950
+     * @return bool
951
+     */
952
+    public function isOutgoingServer2serverShareEnabled() {
953
+        if ($this->gsConfig->onlyInternalFederation()) {
954
+            return false;
955
+        }
956
+        $result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes');
957
+        return ($result === 'yes');
958
+    }
959
+
960
+    /**
961
+     * check if users are allowed to mount public links from other Nextclouds
962
+     *
963
+     * @return bool
964
+     */
965
+    public function isIncomingServer2serverShareEnabled() {
966
+        if ($this->gsConfig->onlyInternalFederation()) {
967
+            return false;
968
+        }
969
+        $result = $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes');
970
+        return ($result === 'yes');
971
+    }
972
+
973
+
974
+    /**
975
+     * check if users from other Nextcloud instances are allowed to send federated group shares
976
+     *
977
+     * @return bool
978
+     */
979
+    public function isOutgoingServer2serverGroupShareEnabled() {
980
+        if ($this->gsConfig->onlyInternalFederation()) {
981
+            return false;
982
+        }
983
+        $result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_group_share_enabled', 'no');
984
+        return ($result === 'yes');
985
+    }
986
+
987
+    /**
988
+     * check if users are allowed to receive federated group shares
989
+     *
990
+     * @return bool
991
+     */
992
+    public function isIncomingServer2serverGroupShareEnabled() {
993
+        if ($this->gsConfig->onlyInternalFederation()) {
994
+            return false;
995
+        }
996
+        $result = $this->config->getAppValue('files_sharing', 'incoming_server2server_group_share_enabled', 'no');
997
+        return ($result === 'yes');
998
+    }
999
+
1000
+    /**
1001
+     * check if federated group sharing is supported, therefore the OCM API need to be enabled
1002
+     *
1003
+     * @return bool
1004
+     */
1005
+    public function isFederatedGroupSharingSupported() {
1006
+        return $this->cloudFederationProviderManager->isReady();
1007
+    }
1008
+
1009
+    /**
1010
+     * Check if querying sharees on the lookup server is enabled
1011
+     *
1012
+     * @return bool
1013
+     */
1014
+    public function isLookupServerQueriesEnabled() {
1015
+        // in a global scale setup we should always query the lookup server
1016
+        if ($this->gsConfig->isGlobalScaleEnabled()) {
1017
+            return true;
1018
+        }
1019
+        $result = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no');
1020
+        return ($result === 'yes');
1021
+    }
1022
+
1023
+
1024
+    /**
1025
+     * Check if it is allowed to publish user specific data to the lookup server
1026
+     *
1027
+     * @return bool
1028
+     */
1029
+    public function isLookupServerUploadEnabled() {
1030
+        // in a global scale setup the admin is responsible to keep the lookup server up-to-date
1031
+        if ($this->gsConfig->isGlobalScaleEnabled()) {
1032
+            return false;
1033
+        }
1034
+        $result = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes');
1035
+        return ($result === 'yes');
1036
+    }
1037
+
1038
+    /**
1039
+     * @inheritdoc
1040
+     */
1041
+    public function getAccessList($nodes, $currentAccess) {
1042
+        $ids = [];
1043
+        foreach ($nodes as $node) {
1044
+            $ids[] = $node->getId();
1045
+        }
1046
+
1047
+        $qb = $this->dbConnection->getQueryBuilder();
1048
+        $qb->select('share_with', 'token', 'file_source')
1049
+            ->from('share')
1050
+            ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE)))
1051
+            ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)))
1052
+            ->andWhere($qb->expr()->orX(
1053
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
1054
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
1055
+            ));
1056
+        $cursor = $qb->execute();
1057
+
1058
+        if ($currentAccess === false) {
1059
+            $remote = $cursor->fetch() !== false;
1060
+            $cursor->closeCursor();
1061
+
1062
+            return ['remote' => $remote];
1063
+        }
1064
+
1065
+        $remote = [];
1066
+        while ($row = $cursor->fetch()) {
1067
+            $remote[$row['share_with']] = [
1068
+                'node_id' => $row['file_source'],
1069
+                'token' => $row['token'],
1070
+            ];
1071
+        }
1072
+        $cursor->closeCursor();
1073
+
1074
+        return ['remote' => $remote];
1075
+    }
1076 1076
 }
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/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/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/ICloudFederationFactory.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -30,33 +30,33 @@
 block discarded – undo
30 30
  */
31 31
 interface ICloudFederationFactory {
32 32
 
33
-	/**
34
-	 * get a CloudFederationShare Object to prepare a share you want to send
35
-	 *
36
-	 * @param string $shareWith
37
-	 * @param string $name resource name (e.g. document.odt)
38
-	 * @param string $description share description (optional)
39
-	 * @param string $providerId resource UID on the provider side
40
-	 * @param string $owner provider specific UID of the user who owns the resource
41
-	 * @param string $ownerDisplayName display name of the user who shared the item
42
-	 * @param string $sharedBy provider specific UID of the user who shared the resource
43
-	 * @param string $sharedByDisplayName display name of the user who shared the resource
44
-	 * @param string $sharedSecret used to authenticate requests across servers
45
-	 * @param string $shareType ('group' or 'user' share)
46
-	 * @param $resourceType ('file', 'calendar',...)
47
-	 * @return ICloudFederationShare
48
-	 *
49
-	 * @since 14.0.0
50
-	 */
51
-	public function getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $sharedSecret, $shareType, $resourceType);
33
+    /**
34
+     * get a CloudFederationShare Object to prepare a share you want to send
35
+     *
36
+     * @param string $shareWith
37
+     * @param string $name resource name (e.g. document.odt)
38
+     * @param string $description share description (optional)
39
+     * @param string $providerId resource UID on the provider side
40
+     * @param string $owner provider specific UID of the user who owns the resource
41
+     * @param string $ownerDisplayName display name of the user who shared the item
42
+     * @param string $sharedBy provider specific UID of the user who shared the resource
43
+     * @param string $sharedByDisplayName display name of the user who shared the resource
44
+     * @param string $sharedSecret used to authenticate requests across servers
45
+     * @param string $shareType ('group' or 'user' share)
46
+     * @param $resourceType ('file', 'calendar',...)
47
+     * @return ICloudFederationShare
48
+     *
49
+     * @since 14.0.0
50
+     */
51
+    public function getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $sharedSecret, $shareType, $resourceType);
52 52
 
53
-	/**
54
-	 * get a Cloud FederationNotification object to prepare a notification you
55
-	 * want to send
56
-	 *
57
-	 * @return ICloudFederationNotification
58
-	 *
59
-	 * @since 14.0.0
60
-	 */
61
-	public function getCloudFederationNotification();
53
+    /**
54
+     * get a Cloud FederationNotification object to prepare a notification you
55
+     * want to send
56
+     *
57
+     * @return ICloudFederationNotification
58
+     *
59
+     * @since 14.0.0
60
+     */
61
+    public function getCloudFederationNotification();
62 62
 }
Please login to merge, or discard this patch.
lib/public/IServerContainer.php 1 patch
Indentation   +506 added lines, -506 removed lines patch added patch discarded remove patch
@@ -60,510 +60,510 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.