Passed
Push — master ( 80e12c...127af0 )
by Julius
15:15 queued 16s
created
apps/files_sharing/lib/Controller/ShareesAPIController.php 1 patch
Indentation   +379 added lines, -379 removed lines patch added patch discarded remove patch
@@ -58,383 +58,383 @@
 block discarded – undo
58 58
 
59 59
 class ShareesAPIController extends OCSController {
60 60
 
61
-	/** @var string */
62
-	protected $userId;
63
-
64
-	/** @var IConfig */
65
-	protected $config;
66
-
67
-	/** @var IURLGenerator */
68
-	protected $urlGenerator;
69
-
70
-	/** @var IManager */
71
-	protected $shareManager;
72
-
73
-	/** @var int */
74
-	protected $offset = 0;
75
-
76
-	/** @var int */
77
-	protected $limit = 10;
78
-
79
-	/** @var array */
80
-	protected $result = [
81
-		'exact' => [
82
-			'users' => [],
83
-			'groups' => [],
84
-			'remotes' => [],
85
-			'remote_groups' => [],
86
-			'emails' => [],
87
-			'circles' => [],
88
-			'rooms' => [],
89
-		],
90
-		'users' => [],
91
-		'groups' => [],
92
-		'remotes' => [],
93
-		'remote_groups' => [],
94
-		'emails' => [],
95
-		'lookup' => [],
96
-		'circles' => [],
97
-		'rooms' => [],
98
-		'lookupEnabled' => false,
99
-	];
100
-
101
-	protected $reachedEndFor = [];
102
-	/** @var ISearch */
103
-	private $collaboratorSearch;
104
-
105
-	/**
106
-	 * @param string $UserId
107
-	 * @param string $appName
108
-	 * @param IRequest $request
109
-	 * @param IConfig $config
110
-	 * @param IURLGenerator $urlGenerator
111
-	 * @param IManager $shareManager
112
-	 * @param ISearch $collaboratorSearch
113
-	 */
114
-	public function __construct(
115
-		$UserId,
116
-		string $appName,
117
-		IRequest $request,
118
-		IConfig $config,
119
-		IURLGenerator $urlGenerator,
120
-		IManager $shareManager,
121
-		ISearch $collaboratorSearch
122
-	) {
123
-		parent::__construct($appName, $request);
124
-		$this->userId = $UserId;
125
-		$this->config = $config;
126
-		$this->urlGenerator = $urlGenerator;
127
-		$this->shareManager = $shareManager;
128
-		$this->collaboratorSearch = $collaboratorSearch;
129
-	}
130
-
131
-	/**
132
-	 * @NoAdminRequired
133
-	 *
134
-	 * @param string $search
135
-	 * @param string $itemType
136
-	 * @param int $page
137
-	 * @param int $perPage
138
-	 * @param int|int[] $shareType
139
-	 * @param bool $lookup
140
-	 * @return DataResponse
141
-	 * @throws OCSBadRequestException
142
-	 */
143
-	public function search(string $search = '', string $itemType = null, int $page = 1, int $perPage = 200, $shareType = null, bool $lookup = false): DataResponse {
144
-
145
-		// only search for string larger than a given threshold
146
-		$threshold = $this->config->getSystemValueInt('sharing.minSearchStringLength', 0);
147
-		if (strlen($search) < $threshold) {
148
-			return new DataResponse($this->result);
149
-		}
150
-
151
-		// never return more than the max. number of results configured in the config.php
152
-		$maxResults = $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT);
153
-		if ($maxResults > 0) {
154
-			$perPage = min($perPage, $maxResults);
155
-		}
156
-		if ($perPage <= 0) {
157
-			throw new OCSBadRequestException('Invalid perPage argument');
158
-		}
159
-		if ($page <= 0) {
160
-			throw new OCSBadRequestException('Invalid page');
161
-		}
162
-
163
-		$shareTypes = [
164
-			IShare::TYPE_USER,
165
-		];
166
-
167
-		if ($itemType === null) {
168
-			throw new OCSBadRequestException('Missing itemType');
169
-		} elseif ($itemType === 'file' || $itemType === 'folder') {
170
-			if ($this->shareManager->allowGroupSharing()) {
171
-				$shareTypes[] = IShare::TYPE_GROUP;
172
-			}
173
-
174
-			if ($this->isRemoteSharingAllowed($itemType)) {
175
-				$shareTypes[] = IShare::TYPE_REMOTE;
176
-			}
177
-
178
-			if ($this->isRemoteGroupSharingAllowed($itemType)) {
179
-				$shareTypes[] = IShare::TYPE_REMOTE_GROUP;
180
-			}
181
-
182
-			if ($this->shareManager->shareProviderExists(IShare::TYPE_EMAIL)) {
183
-				$shareTypes[] = IShare::TYPE_EMAIL;
184
-			}
185
-
186
-			if ($this->shareManager->shareProviderExists(IShare::TYPE_ROOM)) {
187
-				$shareTypes[] = IShare::TYPE_ROOM;
188
-			}
189
-
190
-			if ($this->shareManager->shareProviderExists(IShare::TYPE_SCIENCEMESH)) {
191
-				$shareTypes[] = IShare::TYPE_SCIENCEMESH;
192
-			}
193
-		} else {
194
-			if ($this->shareManager->allowGroupSharing()) {
195
-				$shareTypes[] = IShare::TYPE_GROUP;
196
-			}
197
-			$shareTypes[] = IShare::TYPE_EMAIL;
198
-		}
199
-
200
-		// FIXME: DI
201
-		if (\OC::$server->getAppManager()->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) {
202
-			$shareTypes[] = IShare::TYPE_CIRCLE;
203
-		}
204
-
205
-		if ($this->shareManager->shareProviderExists(IShare::TYPE_SCIENCEMESH)) {
206
-			$shareTypes[] = IShare::TYPE_SCIENCEMESH;
207
-		}
208
-
209
-		if ($shareType !== null && is_array($shareType)) {
210
-			$shareTypes = array_intersect($shareTypes, $shareType);
211
-		} elseif (is_numeric($shareType)) {
212
-			$shareTypes = array_intersect($shareTypes, [(int) $shareType]);
213
-		}
214
-		sort($shareTypes);
215
-
216
-		$this->limit = $perPage;
217
-		$this->offset = $perPage * ($page - 1);
218
-
219
-		// In global scale mode we always search the loogup server
220
-		if ($this->config->getSystemValueBool('gs.enabled', false)) {
221
-			$lookup = true;
222
-			$this->result['lookupEnabled'] = true;
223
-		} else {
224
-			$this->result['lookupEnabled'] = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'yes') === 'yes';
225
-		}
226
-
227
-		[$result, $hasMoreResults] = $this->collaboratorSearch->search($search, $shareTypes, $lookup, $this->limit, $this->offset);
228
-
229
-		// extra treatment for 'exact' subarray, with a single merge expected keys might be lost
230
-		if (isset($result['exact'])) {
231
-			$result['exact'] = array_merge($this->result['exact'], $result['exact']);
232
-		}
233
-		$this->result = array_merge($this->result, $result);
234
-		$response = new DataResponse($this->result);
235
-
236
-		if ($hasMoreResults) {
237
-			$response->addHeader('Link', $this->getPaginationLink($page, [
238
-				'search' => $search,
239
-				'itemType' => $itemType,
240
-				'shareType' => $shareTypes,
241
-				'perPage' => $perPage,
242
-			]));
243
-		}
244
-
245
-		return $response;
246
-	}
247
-
248
-	/**
249
-	 * @param string $user
250
-	 * @param int $shareType
251
-	 *
252
-	 * @return Generator<array<string>>
253
-	 */
254
-	private function getAllShareesByType(string $user, int $shareType): Generator {
255
-		$offset = 0;
256
-		$pageSize = 50;
257
-
258
-		while (count($page = $this->shareManager->getSharesBy(
259
-			$user,
260
-			$shareType,
261
-			null,
262
-			false,
263
-			$pageSize,
264
-			$offset
265
-		))) {
266
-			foreach ($page as $share) {
267
-				yield [$share->getSharedWith(), $share->getSharedWithDisplayName() ?? $share->getSharedWith()];
268
-			}
269
-
270
-			$offset += $pageSize;
271
-		}
272
-	}
273
-
274
-	private function sortShareesByFrequency(array $sharees): array {
275
-		usort($sharees, function (array $s1, array $s2): int {
276
-			return $s2['count'] - $s1['count'];
277
-		});
278
-		return $sharees;
279
-	}
280
-
281
-	private $searchResultTypeMap = [
282
-		IShare::TYPE_USER => 'users',
283
-		IShare::TYPE_GROUP => 'groups',
284
-		IShare::TYPE_REMOTE => 'remotes',
285
-		IShare::TYPE_REMOTE_GROUP => 'remote_groups',
286
-		IShare::TYPE_EMAIL => 'emails',
287
-	];
288
-
289
-	private function getAllSharees(string $user, array $shareTypes): ISearchResult {
290
-		$result = [];
291
-		foreach ($shareTypes as $shareType) {
292
-			$sharees = $this->getAllShareesByType($user, $shareType);
293
-			$shareTypeResults = [];
294
-			foreach ($sharees as [$sharee, $displayname]) {
295
-				if (!isset($this->searchResultTypeMap[$shareType])) {
296
-					continue;
297
-				}
298
-
299
-				if (!isset($shareTypeResults[$sharee])) {
300
-					$shareTypeResults[$sharee] = [
301
-						'count' => 1,
302
-						'label' => $displayname,
303
-						'value' => [
304
-							'shareType' => $shareType,
305
-							'shareWith' => $sharee,
306
-						],
307
-					];
308
-				} else {
309
-					$shareTypeResults[$sharee]['count']++;
310
-				}
311
-			}
312
-			$result = array_merge($result, array_values($shareTypeResults));
313
-		}
314
-
315
-		$top5 = array_slice(
316
-			$this->sortShareesByFrequency($result),
317
-			0,
318
-			5
319
-		);
320
-
321
-		$searchResult = new SearchResult();
322
-		foreach ($this->searchResultTypeMap as $int => $str) {
323
-			$searchResult->addResultSet(new SearchResultType($str), [], []);
324
-			foreach ($top5 as $x) {
325
-				if ($x['value']['shareType'] === $int) {
326
-					$searchResult->addResultSet(new SearchResultType($str), [], [$x]);
327
-				}
328
-			}
329
-		}
330
-		return $searchResult;
331
-	}
332
-
333
-	/**
334
-	 * @NoAdminRequired
335
-	 *
336
-	 * @param string $itemType
337
-	 * @return DataResponse
338
-	 * @throws OCSBadRequestException
339
-	 */
340
-	public function findRecommended(string $itemType = null, $shareType = null): DataResponse {
341
-		$shareTypes = [
342
-			IShare::TYPE_USER,
343
-		];
344
-
345
-		if ($itemType === null) {
346
-			throw new OCSBadRequestException('Missing itemType');
347
-		} elseif ($itemType === 'file' || $itemType === 'folder') {
348
-			if ($this->shareManager->allowGroupSharing()) {
349
-				$shareTypes[] = IShare::TYPE_GROUP;
350
-			}
351
-
352
-			if ($this->isRemoteSharingAllowed($itemType)) {
353
-				$shareTypes[] = IShare::TYPE_REMOTE;
354
-			}
355
-
356
-			if ($this->isRemoteGroupSharingAllowed($itemType)) {
357
-				$shareTypes[] = IShare::TYPE_REMOTE_GROUP;
358
-			}
359
-
360
-			if ($this->shareManager->shareProviderExists(IShare::TYPE_EMAIL)) {
361
-				$shareTypes[] = IShare::TYPE_EMAIL;
362
-			}
363
-
364
-			if ($this->shareManager->shareProviderExists(IShare::TYPE_ROOM)) {
365
-				$shareTypes[] = IShare::TYPE_ROOM;
366
-			}
367
-		} else {
368
-			$shareTypes[] = IShare::TYPE_GROUP;
369
-			$shareTypes[] = IShare::TYPE_EMAIL;
370
-		}
371
-
372
-		// FIXME: DI
373
-		if (\OC::$server->getAppManager()->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) {
374
-			$shareTypes[] = IShare::TYPE_CIRCLE;
375
-		}
376
-
377
-		if (isset($_GET['shareType']) && is_array($_GET['shareType'])) {
378
-			$shareTypes = array_intersect($shareTypes, $_GET['shareType']);
379
-			sort($shareTypes);
380
-		} elseif (is_numeric($shareType)) {
381
-			$shareTypes = array_intersect($shareTypes, [(int) $shareType]);
382
-			sort($shareTypes);
383
-		}
384
-
385
-		return new DataResponse(
386
-			$this->getAllSharees($this->userId, $shareTypes)->asArray()
387
-		);
388
-	}
389
-
390
-	/**
391
-	 * Method to get out the static call for better testing
392
-	 *
393
-	 * @param string $itemType
394
-	 * @return bool
395
-	 */
396
-	protected function isRemoteSharingAllowed(string $itemType): bool {
397
-		try {
398
-			// FIXME: static foo makes unit testing unnecessarily difficult
399
-			$backend = \OC\Share\Share::getBackend($itemType);
400
-			return $backend->isShareTypeAllowed(IShare::TYPE_REMOTE);
401
-		} catch (\Exception $e) {
402
-			return false;
403
-		}
404
-	}
405
-
406
-	protected function isRemoteGroupSharingAllowed(string $itemType): bool {
407
-		try {
408
-			// FIXME: static foo makes unit testing unnecessarily difficult
409
-			$backend = \OC\Share\Share::getBackend($itemType);
410
-			return $backend->isShareTypeAllowed(IShare::TYPE_REMOTE_GROUP);
411
-		} catch (\Exception $e) {
412
-			return false;
413
-		}
414
-	}
415
-
416
-
417
-	/**
418
-	 * Generates a bunch of pagination links for the current page
419
-	 *
420
-	 * @param int $page Current page
421
-	 * @param array $params Parameters for the URL
422
-	 * @return string
423
-	 */
424
-	protected function getPaginationLink(int $page, array $params): string {
425
-		if ($this->isV2()) {
426
-			$url = $this->urlGenerator->getAbsoluteURL('/ocs/v2.php/apps/files_sharing/api/v1/sharees') . '?';
427
-		} else {
428
-			$url = $this->urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/sharees') . '?';
429
-		}
430
-		$params['page'] = $page + 1;
431
-		return '<' . $url . http_build_query($params) . '>; rel="next"';
432
-	}
433
-
434
-	/**
435
-	 * @return bool
436
-	 */
437
-	protected function isV2(): bool {
438
-		return $this->request->getScriptName() === '/ocs/v2.php';
439
-	}
61
+    /** @var string */
62
+    protected $userId;
63
+
64
+    /** @var IConfig */
65
+    protected $config;
66
+
67
+    /** @var IURLGenerator */
68
+    protected $urlGenerator;
69
+
70
+    /** @var IManager */
71
+    protected $shareManager;
72
+
73
+    /** @var int */
74
+    protected $offset = 0;
75
+
76
+    /** @var int */
77
+    protected $limit = 10;
78
+
79
+    /** @var array */
80
+    protected $result = [
81
+        'exact' => [
82
+            'users' => [],
83
+            'groups' => [],
84
+            'remotes' => [],
85
+            'remote_groups' => [],
86
+            'emails' => [],
87
+            'circles' => [],
88
+            'rooms' => [],
89
+        ],
90
+        'users' => [],
91
+        'groups' => [],
92
+        'remotes' => [],
93
+        'remote_groups' => [],
94
+        'emails' => [],
95
+        'lookup' => [],
96
+        'circles' => [],
97
+        'rooms' => [],
98
+        'lookupEnabled' => false,
99
+    ];
100
+
101
+    protected $reachedEndFor = [];
102
+    /** @var ISearch */
103
+    private $collaboratorSearch;
104
+
105
+    /**
106
+     * @param string $UserId
107
+     * @param string $appName
108
+     * @param IRequest $request
109
+     * @param IConfig $config
110
+     * @param IURLGenerator $urlGenerator
111
+     * @param IManager $shareManager
112
+     * @param ISearch $collaboratorSearch
113
+     */
114
+    public function __construct(
115
+        $UserId,
116
+        string $appName,
117
+        IRequest $request,
118
+        IConfig $config,
119
+        IURLGenerator $urlGenerator,
120
+        IManager $shareManager,
121
+        ISearch $collaboratorSearch
122
+    ) {
123
+        parent::__construct($appName, $request);
124
+        $this->userId = $UserId;
125
+        $this->config = $config;
126
+        $this->urlGenerator = $urlGenerator;
127
+        $this->shareManager = $shareManager;
128
+        $this->collaboratorSearch = $collaboratorSearch;
129
+    }
130
+
131
+    /**
132
+     * @NoAdminRequired
133
+     *
134
+     * @param string $search
135
+     * @param string $itemType
136
+     * @param int $page
137
+     * @param int $perPage
138
+     * @param int|int[] $shareType
139
+     * @param bool $lookup
140
+     * @return DataResponse
141
+     * @throws OCSBadRequestException
142
+     */
143
+    public function search(string $search = '', string $itemType = null, int $page = 1, int $perPage = 200, $shareType = null, bool $lookup = false): DataResponse {
144
+
145
+        // only search for string larger than a given threshold
146
+        $threshold = $this->config->getSystemValueInt('sharing.minSearchStringLength', 0);
147
+        if (strlen($search) < $threshold) {
148
+            return new DataResponse($this->result);
149
+        }
150
+
151
+        // never return more than the max. number of results configured in the config.php
152
+        $maxResults = $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT);
153
+        if ($maxResults > 0) {
154
+            $perPage = min($perPage, $maxResults);
155
+        }
156
+        if ($perPage <= 0) {
157
+            throw new OCSBadRequestException('Invalid perPage argument');
158
+        }
159
+        if ($page <= 0) {
160
+            throw new OCSBadRequestException('Invalid page');
161
+        }
162
+
163
+        $shareTypes = [
164
+            IShare::TYPE_USER,
165
+        ];
166
+
167
+        if ($itemType === null) {
168
+            throw new OCSBadRequestException('Missing itemType');
169
+        } elseif ($itemType === 'file' || $itemType === 'folder') {
170
+            if ($this->shareManager->allowGroupSharing()) {
171
+                $shareTypes[] = IShare::TYPE_GROUP;
172
+            }
173
+
174
+            if ($this->isRemoteSharingAllowed($itemType)) {
175
+                $shareTypes[] = IShare::TYPE_REMOTE;
176
+            }
177
+
178
+            if ($this->isRemoteGroupSharingAllowed($itemType)) {
179
+                $shareTypes[] = IShare::TYPE_REMOTE_GROUP;
180
+            }
181
+
182
+            if ($this->shareManager->shareProviderExists(IShare::TYPE_EMAIL)) {
183
+                $shareTypes[] = IShare::TYPE_EMAIL;
184
+            }
185
+
186
+            if ($this->shareManager->shareProviderExists(IShare::TYPE_ROOM)) {
187
+                $shareTypes[] = IShare::TYPE_ROOM;
188
+            }
189
+
190
+            if ($this->shareManager->shareProviderExists(IShare::TYPE_SCIENCEMESH)) {
191
+                $shareTypes[] = IShare::TYPE_SCIENCEMESH;
192
+            }
193
+        } else {
194
+            if ($this->shareManager->allowGroupSharing()) {
195
+                $shareTypes[] = IShare::TYPE_GROUP;
196
+            }
197
+            $shareTypes[] = IShare::TYPE_EMAIL;
198
+        }
199
+
200
+        // FIXME: DI
201
+        if (\OC::$server->getAppManager()->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) {
202
+            $shareTypes[] = IShare::TYPE_CIRCLE;
203
+        }
204
+
205
+        if ($this->shareManager->shareProviderExists(IShare::TYPE_SCIENCEMESH)) {
206
+            $shareTypes[] = IShare::TYPE_SCIENCEMESH;
207
+        }
208
+
209
+        if ($shareType !== null && is_array($shareType)) {
210
+            $shareTypes = array_intersect($shareTypes, $shareType);
211
+        } elseif (is_numeric($shareType)) {
212
+            $shareTypes = array_intersect($shareTypes, [(int) $shareType]);
213
+        }
214
+        sort($shareTypes);
215
+
216
+        $this->limit = $perPage;
217
+        $this->offset = $perPage * ($page - 1);
218
+
219
+        // In global scale mode we always search the loogup server
220
+        if ($this->config->getSystemValueBool('gs.enabled', false)) {
221
+            $lookup = true;
222
+            $this->result['lookupEnabled'] = true;
223
+        } else {
224
+            $this->result['lookupEnabled'] = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'yes') === 'yes';
225
+        }
226
+
227
+        [$result, $hasMoreResults] = $this->collaboratorSearch->search($search, $shareTypes, $lookup, $this->limit, $this->offset);
228
+
229
+        // extra treatment for 'exact' subarray, with a single merge expected keys might be lost
230
+        if (isset($result['exact'])) {
231
+            $result['exact'] = array_merge($this->result['exact'], $result['exact']);
232
+        }
233
+        $this->result = array_merge($this->result, $result);
234
+        $response = new DataResponse($this->result);
235
+
236
+        if ($hasMoreResults) {
237
+            $response->addHeader('Link', $this->getPaginationLink($page, [
238
+                'search' => $search,
239
+                'itemType' => $itemType,
240
+                'shareType' => $shareTypes,
241
+                'perPage' => $perPage,
242
+            ]));
243
+        }
244
+
245
+        return $response;
246
+    }
247
+
248
+    /**
249
+     * @param string $user
250
+     * @param int $shareType
251
+     *
252
+     * @return Generator<array<string>>
253
+     */
254
+    private function getAllShareesByType(string $user, int $shareType): Generator {
255
+        $offset = 0;
256
+        $pageSize = 50;
257
+
258
+        while (count($page = $this->shareManager->getSharesBy(
259
+            $user,
260
+            $shareType,
261
+            null,
262
+            false,
263
+            $pageSize,
264
+            $offset
265
+        ))) {
266
+            foreach ($page as $share) {
267
+                yield [$share->getSharedWith(), $share->getSharedWithDisplayName() ?? $share->getSharedWith()];
268
+            }
269
+
270
+            $offset += $pageSize;
271
+        }
272
+    }
273
+
274
+    private function sortShareesByFrequency(array $sharees): array {
275
+        usort($sharees, function (array $s1, array $s2): int {
276
+            return $s2['count'] - $s1['count'];
277
+        });
278
+        return $sharees;
279
+    }
280
+
281
+    private $searchResultTypeMap = [
282
+        IShare::TYPE_USER => 'users',
283
+        IShare::TYPE_GROUP => 'groups',
284
+        IShare::TYPE_REMOTE => 'remotes',
285
+        IShare::TYPE_REMOTE_GROUP => 'remote_groups',
286
+        IShare::TYPE_EMAIL => 'emails',
287
+    ];
288
+
289
+    private function getAllSharees(string $user, array $shareTypes): ISearchResult {
290
+        $result = [];
291
+        foreach ($shareTypes as $shareType) {
292
+            $sharees = $this->getAllShareesByType($user, $shareType);
293
+            $shareTypeResults = [];
294
+            foreach ($sharees as [$sharee, $displayname]) {
295
+                if (!isset($this->searchResultTypeMap[$shareType])) {
296
+                    continue;
297
+                }
298
+
299
+                if (!isset($shareTypeResults[$sharee])) {
300
+                    $shareTypeResults[$sharee] = [
301
+                        'count' => 1,
302
+                        'label' => $displayname,
303
+                        'value' => [
304
+                            'shareType' => $shareType,
305
+                            'shareWith' => $sharee,
306
+                        ],
307
+                    ];
308
+                } else {
309
+                    $shareTypeResults[$sharee]['count']++;
310
+                }
311
+            }
312
+            $result = array_merge($result, array_values($shareTypeResults));
313
+        }
314
+
315
+        $top5 = array_slice(
316
+            $this->sortShareesByFrequency($result),
317
+            0,
318
+            5
319
+        );
320
+
321
+        $searchResult = new SearchResult();
322
+        foreach ($this->searchResultTypeMap as $int => $str) {
323
+            $searchResult->addResultSet(new SearchResultType($str), [], []);
324
+            foreach ($top5 as $x) {
325
+                if ($x['value']['shareType'] === $int) {
326
+                    $searchResult->addResultSet(new SearchResultType($str), [], [$x]);
327
+                }
328
+            }
329
+        }
330
+        return $searchResult;
331
+    }
332
+
333
+    /**
334
+     * @NoAdminRequired
335
+     *
336
+     * @param string $itemType
337
+     * @return DataResponse
338
+     * @throws OCSBadRequestException
339
+     */
340
+    public function findRecommended(string $itemType = null, $shareType = null): DataResponse {
341
+        $shareTypes = [
342
+            IShare::TYPE_USER,
343
+        ];
344
+
345
+        if ($itemType === null) {
346
+            throw new OCSBadRequestException('Missing itemType');
347
+        } elseif ($itemType === 'file' || $itemType === 'folder') {
348
+            if ($this->shareManager->allowGroupSharing()) {
349
+                $shareTypes[] = IShare::TYPE_GROUP;
350
+            }
351
+
352
+            if ($this->isRemoteSharingAllowed($itemType)) {
353
+                $shareTypes[] = IShare::TYPE_REMOTE;
354
+            }
355
+
356
+            if ($this->isRemoteGroupSharingAllowed($itemType)) {
357
+                $shareTypes[] = IShare::TYPE_REMOTE_GROUP;
358
+            }
359
+
360
+            if ($this->shareManager->shareProviderExists(IShare::TYPE_EMAIL)) {
361
+                $shareTypes[] = IShare::TYPE_EMAIL;
362
+            }
363
+
364
+            if ($this->shareManager->shareProviderExists(IShare::TYPE_ROOM)) {
365
+                $shareTypes[] = IShare::TYPE_ROOM;
366
+            }
367
+        } else {
368
+            $shareTypes[] = IShare::TYPE_GROUP;
369
+            $shareTypes[] = IShare::TYPE_EMAIL;
370
+        }
371
+
372
+        // FIXME: DI
373
+        if (\OC::$server->getAppManager()->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) {
374
+            $shareTypes[] = IShare::TYPE_CIRCLE;
375
+        }
376
+
377
+        if (isset($_GET['shareType']) && is_array($_GET['shareType'])) {
378
+            $shareTypes = array_intersect($shareTypes, $_GET['shareType']);
379
+            sort($shareTypes);
380
+        } elseif (is_numeric($shareType)) {
381
+            $shareTypes = array_intersect($shareTypes, [(int) $shareType]);
382
+            sort($shareTypes);
383
+        }
384
+
385
+        return new DataResponse(
386
+            $this->getAllSharees($this->userId, $shareTypes)->asArray()
387
+        );
388
+    }
389
+
390
+    /**
391
+     * Method to get out the static call for better testing
392
+     *
393
+     * @param string $itemType
394
+     * @return bool
395
+     */
396
+    protected function isRemoteSharingAllowed(string $itemType): bool {
397
+        try {
398
+            // FIXME: static foo makes unit testing unnecessarily difficult
399
+            $backend = \OC\Share\Share::getBackend($itemType);
400
+            return $backend->isShareTypeAllowed(IShare::TYPE_REMOTE);
401
+        } catch (\Exception $e) {
402
+            return false;
403
+        }
404
+    }
405
+
406
+    protected function isRemoteGroupSharingAllowed(string $itemType): bool {
407
+        try {
408
+            // FIXME: static foo makes unit testing unnecessarily difficult
409
+            $backend = \OC\Share\Share::getBackend($itemType);
410
+            return $backend->isShareTypeAllowed(IShare::TYPE_REMOTE_GROUP);
411
+        } catch (\Exception $e) {
412
+            return false;
413
+        }
414
+    }
415
+
416
+
417
+    /**
418
+     * Generates a bunch of pagination links for the current page
419
+     *
420
+     * @param int $page Current page
421
+     * @param array $params Parameters for the URL
422
+     * @return string
423
+     */
424
+    protected function getPaginationLink(int $page, array $params): string {
425
+        if ($this->isV2()) {
426
+            $url = $this->urlGenerator->getAbsoluteURL('/ocs/v2.php/apps/files_sharing/api/v1/sharees') . '?';
427
+        } else {
428
+            $url = $this->urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/sharees') . '?';
429
+        }
430
+        $params['page'] = $page + 1;
431
+        return '<' . $url . http_build_query($params) . '>; rel="next"';
432
+    }
433
+
434
+    /**
435
+     * @return bool
436
+     */
437
+    protected function isV2(): bool {
438
+        return $this->request->getScriptName() === '/ocs/v2.php';
439
+    }
440 440
 }
Please login to merge, or discard this patch.
apps/admin_audit/lib/Actions/Sharing.php 1 patch
Indentation   +340 added lines, -340 removed lines patch added patch discarded remove patch
@@ -38,349 +38,349 @@
 block discarded – undo
38 38
  * @package OCA\AdminAudit\Actions
39 39
  */
40 40
 class Sharing extends Action {
41
-	/**
42
-	 * Logs sharing of data
43
-	 *
44
-	 * @param array $params
45
-	 */
46
-	public function shared(array $params): void {
47
-		if ($params['shareType'] === IShare::TYPE_LINK) {
48
-			$this->log(
49
-				'The %s "%s" with ID "%s" has been shared via link with permissions "%s" (Share ID: %s)',
50
-				$params,
51
-				[
52
-					'itemType',
53
-					'path',
54
-					'itemSource',
55
-					'permissions',
56
-					'id',
57
-				]
58
-			);
59
-		} elseif ($params['shareType'] === IShare::TYPE_USER) {
60
-			$this->log(
61
-				'The %s "%s" with ID "%s" has been shared to the user "%s" with permissions "%s"  (Share ID: %s)',
62
-				$params,
63
-				[
64
-					'itemType',
65
-					'path',
66
-					'itemSource',
67
-					'shareWith',
68
-					'permissions',
69
-					'id',
70
-				]
71
-			);
72
-		} elseif ($params['shareType'] === IShare::TYPE_GROUP) {
73
-			$this->log(
74
-				'The %s "%s" with ID "%s" has been shared to the group "%s" with permissions "%s"  (Share ID: %s)',
75
-				$params,
76
-				[
77
-					'itemType',
78
-					'path',
79
-					'itemSource',
80
-					'shareWith',
81
-					'permissions',
82
-					'id',
83
-				]
84
-			);
85
-		} elseif ($params['shareType'] === IShare::TYPE_ROOM) {
86
-			$this->log(
87
-				'The %s "%s" with ID "%s" has been shared to the room "%s" with permissions "%s" (Share ID: %s)',
88
-				$params,
89
-				[
90
-					'itemType',
91
-					'path',
92
-					'itemSource',
93
-					'shareWith',
94
-					'permissions',
95
-					'id',
96
-				]
97
-			);
98
-		} elseif ($params['shareType'] === IShare::TYPE_EMAIL) {
99
-			$this->log(
100
-				'The %s "%s" with ID "%s" has been shared to the email recipient "%s" with permissions "%s" (Share ID: %s)',
101
-				$params,
102
-				[
103
-					'itemType',
104
-					'path',
105
-					'itemSource',
106
-					'shareWith',
107
-					'permissions',
108
-					'id',
109
-				]
110
-			);
111
-		} elseif ($params['shareType'] === IShare::TYPE_CIRCLE) {
112
-			$this->log(
113
-				'The %s "%s" with ID "%s" has been shared to the circle "%s" with permissions "%s" (Share ID: %s)',
114
-				$params,
115
-				[
116
-					'itemType',
117
-					'path',
118
-					'itemSource',
119
-					'shareWith',
120
-					'permissions',
121
-					'id',
122
-				]
123
-			);
124
-		} elseif ($params['shareType'] === IShare::TYPE_REMOTE) {
125
-			$this->log(
126
-				'The %s "%s" with ID "%s" has been shared to the remote user "%s" with permissions "%s" (Share ID: %s)',
127
-				$params,
128
-				[
129
-					'itemType',
130
-					'path',
131
-					'itemSource',
132
-					'shareWith',
133
-					'permissions',
134
-					'id',
135
-				]
136
-			);
137
-		} elseif ($params['shareType'] === IShare::TYPE_REMOTE_GROUP) {
138
-			$this->log(
139
-				'The %s "%s" with ID "%s" has been shared to the remote group "%s" with permissions "%s" (Share ID: %s)',
140
-				$params,
141
-				[
142
-					'itemType',
143
-					'path',
144
-					'itemSource',
145
-					'shareWith',
146
-					'permissions',
147
-					'id',
148
-				]
149
-			);
150
-		} elseif ($params['shareType'] === IShare::TYPE_DECK) {
151
-			$this->log(
152
-				'The %s "%s" with ID "%s" has been shared to the deck card "%s" with permissions "%s" (Share ID: %s)',
153
-				$params,
154
-				[
155
-					'itemType',
156
-					'path',
157
-					'itemSource',
158
-					'shareWith',
159
-					'permissions',
160
-					'id',
161
-				]
162
-			);
163
-		} elseif ($params['shareType'] === IShare::TYPE_SCIENCEMESH) {
164
-			$this->log(
165
-				'The %s "%s" with ID "%s" has been shared to the sciencemesh user "%s" with permissions "%s" (Share ID: %s)',
166
-				$params,
167
-				[
168
-					'itemType',
169
-					'path',
170
-					'itemSource',
171
-					'shareWith',
172
-					'permissions',
173
-					'id',
174
-				]
175
-			);
176
-		}
177
-	}
41
+    /**
42
+     * Logs sharing of data
43
+     *
44
+     * @param array $params
45
+     */
46
+    public function shared(array $params): void {
47
+        if ($params['shareType'] === IShare::TYPE_LINK) {
48
+            $this->log(
49
+                'The %s "%s" with ID "%s" has been shared via link with permissions "%s" (Share ID: %s)',
50
+                $params,
51
+                [
52
+                    'itemType',
53
+                    'path',
54
+                    'itemSource',
55
+                    'permissions',
56
+                    'id',
57
+                ]
58
+            );
59
+        } elseif ($params['shareType'] === IShare::TYPE_USER) {
60
+            $this->log(
61
+                'The %s "%s" with ID "%s" has been shared to the user "%s" with permissions "%s"  (Share ID: %s)',
62
+                $params,
63
+                [
64
+                    'itemType',
65
+                    'path',
66
+                    'itemSource',
67
+                    'shareWith',
68
+                    'permissions',
69
+                    'id',
70
+                ]
71
+            );
72
+        } elseif ($params['shareType'] === IShare::TYPE_GROUP) {
73
+            $this->log(
74
+                'The %s "%s" with ID "%s" has been shared to the group "%s" with permissions "%s"  (Share ID: %s)',
75
+                $params,
76
+                [
77
+                    'itemType',
78
+                    'path',
79
+                    'itemSource',
80
+                    'shareWith',
81
+                    'permissions',
82
+                    'id',
83
+                ]
84
+            );
85
+        } elseif ($params['shareType'] === IShare::TYPE_ROOM) {
86
+            $this->log(
87
+                'The %s "%s" with ID "%s" has been shared to the room "%s" with permissions "%s" (Share ID: %s)',
88
+                $params,
89
+                [
90
+                    'itemType',
91
+                    'path',
92
+                    'itemSource',
93
+                    'shareWith',
94
+                    'permissions',
95
+                    'id',
96
+                ]
97
+            );
98
+        } elseif ($params['shareType'] === IShare::TYPE_EMAIL) {
99
+            $this->log(
100
+                'The %s "%s" with ID "%s" has been shared to the email recipient "%s" with permissions "%s" (Share ID: %s)',
101
+                $params,
102
+                [
103
+                    'itemType',
104
+                    'path',
105
+                    'itemSource',
106
+                    'shareWith',
107
+                    'permissions',
108
+                    'id',
109
+                ]
110
+            );
111
+        } elseif ($params['shareType'] === IShare::TYPE_CIRCLE) {
112
+            $this->log(
113
+                'The %s "%s" with ID "%s" has been shared to the circle "%s" with permissions "%s" (Share ID: %s)',
114
+                $params,
115
+                [
116
+                    'itemType',
117
+                    'path',
118
+                    'itemSource',
119
+                    'shareWith',
120
+                    'permissions',
121
+                    'id',
122
+                ]
123
+            );
124
+        } elseif ($params['shareType'] === IShare::TYPE_REMOTE) {
125
+            $this->log(
126
+                'The %s "%s" with ID "%s" has been shared to the remote user "%s" with permissions "%s" (Share ID: %s)',
127
+                $params,
128
+                [
129
+                    'itemType',
130
+                    'path',
131
+                    'itemSource',
132
+                    'shareWith',
133
+                    'permissions',
134
+                    'id',
135
+                ]
136
+            );
137
+        } elseif ($params['shareType'] === IShare::TYPE_REMOTE_GROUP) {
138
+            $this->log(
139
+                'The %s "%s" with ID "%s" has been shared to the remote group "%s" with permissions "%s" (Share ID: %s)',
140
+                $params,
141
+                [
142
+                    'itemType',
143
+                    'path',
144
+                    'itemSource',
145
+                    'shareWith',
146
+                    'permissions',
147
+                    'id',
148
+                ]
149
+            );
150
+        } elseif ($params['shareType'] === IShare::TYPE_DECK) {
151
+            $this->log(
152
+                'The %s "%s" with ID "%s" has been shared to the deck card "%s" with permissions "%s" (Share ID: %s)',
153
+                $params,
154
+                [
155
+                    'itemType',
156
+                    'path',
157
+                    'itemSource',
158
+                    'shareWith',
159
+                    'permissions',
160
+                    'id',
161
+                ]
162
+            );
163
+        } elseif ($params['shareType'] === IShare::TYPE_SCIENCEMESH) {
164
+            $this->log(
165
+                'The %s "%s" with ID "%s" has been shared to the sciencemesh user "%s" with permissions "%s" (Share ID: %s)',
166
+                $params,
167
+                [
168
+                    'itemType',
169
+                    'path',
170
+                    'itemSource',
171
+                    'shareWith',
172
+                    'permissions',
173
+                    'id',
174
+                ]
175
+            );
176
+        }
177
+    }
178 178
 
179
-	/**
180
-	 * Logs unsharing of data
181
-	 *
182
-	 * @param array $params
183
-	 */
184
-	public function unshare(array $params): void {
185
-		if ($params['shareType'] === IShare::TYPE_LINK) {
186
-			$this->log(
187
-				'The %s "%s" with ID "%s" has been unshared (Share ID: %s)',
188
-				$params,
189
-				[
190
-					'itemType',
191
-					'fileTarget',
192
-					'itemSource',
193
-					'id',
194
-				]
195
-			);
196
-		} elseif ($params['shareType'] === IShare::TYPE_USER) {
197
-			$this->log(
198
-				'The %s "%s" with ID "%s" has been unshared from the user "%s" (Share ID: %s)',
199
-				$params,
200
-				[
201
-					'itemType',
202
-					'fileTarget',
203
-					'itemSource',
204
-					'shareWith',
205
-					'id',
206
-				]
207
-			);
208
-		} elseif ($params['shareType'] === IShare::TYPE_GROUP) {
209
-			$this->log(
210
-				'The %s "%s" with ID "%s" has been unshared from the group "%s" (Share ID: %s)',
211
-				$params,
212
-				[
213
-					'itemType',
214
-					'fileTarget',
215
-					'itemSource',
216
-					'shareWith',
217
-					'id',
218
-				]
219
-			);
220
-		} elseif ($params['shareType'] === IShare::TYPE_ROOM) {
221
-			$this->log(
222
-				'The %s "%s" with ID "%s" has been unshared from the room "%s" (Share ID: %s)',
223
-				$params,
224
-				[
225
-					'itemType',
226
-					'fileTarget',
227
-					'itemSource',
228
-					'shareWith',
229
-					'id',
230
-				]
231
-			);
232
-		} elseif ($params['shareType'] === IShare::TYPE_EMAIL) {
233
-			$this->log(
234
-				'The %s "%s" with ID "%s" has been unshared from the email recipient "%s" (Share ID: %s)',
235
-				$params,
236
-				[
237
-					'itemType',
238
-					'fileTarget',
239
-					'itemSource',
240
-					'shareWith',
241
-					'id',
242
-				]
243
-			);
244
-		} elseif ($params['shareType'] === IShare::TYPE_CIRCLE) {
245
-			$this->log(
246
-				'The %s "%s" with ID "%s" has been unshared from the circle "%s" (Share ID: %s)',
247
-				$params,
248
-				[
249
-					'itemType',
250
-					'fileTarget',
251
-					'itemSource',
252
-					'shareWith',
253
-					'id',
254
-				]
255
-			);
256
-		} elseif ($params['shareType'] === IShare::TYPE_REMOTE) {
257
-			$this->log(
258
-				'The %s "%s" with ID "%s" has been unshared from the remote user "%s" (Share ID: %s)',
259
-				$params,
260
-				[
261
-					'itemType',
262
-					'fileTarget',
263
-					'itemSource',
264
-					'shareWith',
265
-					'id',
266
-				]
267
-			);
268
-		} elseif ($params['shareType'] === IShare::TYPE_REMOTE_GROUP) {
269
-			$this->log(
270
-				'The %s "%s" with ID "%s" has been unshared from the remote group "%s" (Share ID: %s)',
271
-				$params,
272
-				[
273
-					'itemType',
274
-					'fileTarget',
275
-					'itemSource',
276
-					'shareWith',
277
-					'id',
278
-				]
279
-			);
280
-		} elseif ($params['shareType'] === IShare::TYPE_DECK) {
281
-			$this->log(
282
-				'The %s "%s" with ID "%s" has been unshared from the deck card "%s" (Share ID: %s)',
283
-				$params,
284
-				[
285
-					'itemType',
286
-					'fileTarget',
287
-					'itemSource',
288
-					'shareWith',
289
-					'id',
290
-				]
291
-			);
292
-		} elseif ($params['shareType'] === IShare::TYPE_SCIENCEMESH) {
293
-			$this->log(
294
-				'The %s "%s" with ID "%s" has been unshared from the sciencemesh user "%s" (Share ID: %s)',
295
-				$params,
296
-				[
297
-					'itemType',
298
-					'fileTarget',
299
-					'itemSource',
300
-					'shareWith',
301
-					'id',
302
-				]
303
-			);
304
-		}
305
-	}
179
+    /**
180
+     * Logs unsharing of data
181
+     *
182
+     * @param array $params
183
+     */
184
+    public function unshare(array $params): void {
185
+        if ($params['shareType'] === IShare::TYPE_LINK) {
186
+            $this->log(
187
+                'The %s "%s" with ID "%s" has been unshared (Share ID: %s)',
188
+                $params,
189
+                [
190
+                    'itemType',
191
+                    'fileTarget',
192
+                    'itemSource',
193
+                    'id',
194
+                ]
195
+            );
196
+        } elseif ($params['shareType'] === IShare::TYPE_USER) {
197
+            $this->log(
198
+                'The %s "%s" with ID "%s" has been unshared from the user "%s" (Share ID: %s)',
199
+                $params,
200
+                [
201
+                    'itemType',
202
+                    'fileTarget',
203
+                    'itemSource',
204
+                    'shareWith',
205
+                    'id',
206
+                ]
207
+            );
208
+        } elseif ($params['shareType'] === IShare::TYPE_GROUP) {
209
+            $this->log(
210
+                'The %s "%s" with ID "%s" has been unshared from the group "%s" (Share ID: %s)',
211
+                $params,
212
+                [
213
+                    'itemType',
214
+                    'fileTarget',
215
+                    'itemSource',
216
+                    'shareWith',
217
+                    'id',
218
+                ]
219
+            );
220
+        } elseif ($params['shareType'] === IShare::TYPE_ROOM) {
221
+            $this->log(
222
+                'The %s "%s" with ID "%s" has been unshared from the room "%s" (Share ID: %s)',
223
+                $params,
224
+                [
225
+                    'itemType',
226
+                    'fileTarget',
227
+                    'itemSource',
228
+                    'shareWith',
229
+                    'id',
230
+                ]
231
+            );
232
+        } elseif ($params['shareType'] === IShare::TYPE_EMAIL) {
233
+            $this->log(
234
+                'The %s "%s" with ID "%s" has been unshared from the email recipient "%s" (Share ID: %s)',
235
+                $params,
236
+                [
237
+                    'itemType',
238
+                    'fileTarget',
239
+                    'itemSource',
240
+                    'shareWith',
241
+                    'id',
242
+                ]
243
+            );
244
+        } elseif ($params['shareType'] === IShare::TYPE_CIRCLE) {
245
+            $this->log(
246
+                'The %s "%s" with ID "%s" has been unshared from the circle "%s" (Share ID: %s)',
247
+                $params,
248
+                [
249
+                    'itemType',
250
+                    'fileTarget',
251
+                    'itemSource',
252
+                    'shareWith',
253
+                    'id',
254
+                ]
255
+            );
256
+        } elseif ($params['shareType'] === IShare::TYPE_REMOTE) {
257
+            $this->log(
258
+                'The %s "%s" with ID "%s" has been unshared from the remote user "%s" (Share ID: %s)',
259
+                $params,
260
+                [
261
+                    'itemType',
262
+                    'fileTarget',
263
+                    'itemSource',
264
+                    'shareWith',
265
+                    'id',
266
+                ]
267
+            );
268
+        } elseif ($params['shareType'] === IShare::TYPE_REMOTE_GROUP) {
269
+            $this->log(
270
+                'The %s "%s" with ID "%s" has been unshared from the remote group "%s" (Share ID: %s)',
271
+                $params,
272
+                [
273
+                    'itemType',
274
+                    'fileTarget',
275
+                    'itemSource',
276
+                    'shareWith',
277
+                    'id',
278
+                ]
279
+            );
280
+        } elseif ($params['shareType'] === IShare::TYPE_DECK) {
281
+            $this->log(
282
+                'The %s "%s" with ID "%s" has been unshared from the deck card "%s" (Share ID: %s)',
283
+                $params,
284
+                [
285
+                    'itemType',
286
+                    'fileTarget',
287
+                    'itemSource',
288
+                    'shareWith',
289
+                    'id',
290
+                ]
291
+            );
292
+        } elseif ($params['shareType'] === IShare::TYPE_SCIENCEMESH) {
293
+            $this->log(
294
+                'The %s "%s" with ID "%s" has been unshared from the sciencemesh user "%s" (Share ID: %s)',
295
+                $params,
296
+                [
297
+                    'itemType',
298
+                    'fileTarget',
299
+                    'itemSource',
300
+                    'shareWith',
301
+                    'id',
302
+                ]
303
+            );
304
+        }
305
+    }
306 306
 
307
-	/**
308
-	 * Logs the updating of permission changes for shares
309
-	 *
310
-	 * @param array $params
311
-	 */
312
-	public function updatePermissions(array $params): void {
313
-		$this->log(
314
-			'The permissions of the shared %s "%s" with ID "%s" have been changed to "%s"',
315
-			$params,
316
-			[
317
-				'itemType',
318
-				'path',
319
-				'itemSource',
320
-				'permissions',
321
-			]
322
-		);
323
-	}
307
+    /**
308
+     * Logs the updating of permission changes for shares
309
+     *
310
+     * @param array $params
311
+     */
312
+    public function updatePermissions(array $params): void {
313
+        $this->log(
314
+            'The permissions of the shared %s "%s" with ID "%s" have been changed to "%s"',
315
+            $params,
316
+            [
317
+                'itemType',
318
+                'path',
319
+                'itemSource',
320
+                'permissions',
321
+            ]
322
+        );
323
+    }
324 324
 
325
-	/**
326
-	 * Logs the password changes for a share
327
-	 *
328
-	 * @param array $params
329
-	 */
330
-	public function updatePassword(array $params): void {
331
-		$this->log(
332
-			'The password of the publicly shared %s "%s" with ID "%s" has been changed',
333
-			$params,
334
-			[
335
-				'itemType',
336
-				'token',
337
-				'itemSource',
338
-			]
339
-		);
340
-	}
325
+    /**
326
+     * Logs the password changes for a share
327
+     *
328
+     * @param array $params
329
+     */
330
+    public function updatePassword(array $params): void {
331
+        $this->log(
332
+            'The password of the publicly shared %s "%s" with ID "%s" has been changed',
333
+            $params,
334
+            [
335
+                'itemType',
336
+                'token',
337
+                'itemSource',
338
+            ]
339
+        );
340
+    }
341 341
 
342
-	/**
343
-	 * Logs the expiration date changes for a share
344
-	 *
345
-	 * @param array $params
346
-	 */
347
-	public function updateExpirationDate(array $params): void {
348
-		if ($params['date'] === null) {
349
-			$this->log(
350
-				'The expiration date of the publicly shared %s with ID "%s" has been removed',
351
-				$params,
352
-				[
353
-					'itemType',
354
-					'itemSource',
355
-				]
356
-			);
357
-		} else {
358
-			$this->log(
359
-				'The expiration date of the publicly shared %s with ID "%s" has been changed to "%s"',
360
-				$params,
361
-				[
362
-					'itemType',
363
-					'itemSource',
364
-					'date',
365
-				]
366
-			);
367
-		}
368
-	}
342
+    /**
343
+     * Logs the expiration date changes for a share
344
+     *
345
+     * @param array $params
346
+     */
347
+    public function updateExpirationDate(array $params): void {
348
+        if ($params['date'] === null) {
349
+            $this->log(
350
+                'The expiration date of the publicly shared %s with ID "%s" has been removed',
351
+                $params,
352
+                [
353
+                    'itemType',
354
+                    'itemSource',
355
+                ]
356
+            );
357
+        } else {
358
+            $this->log(
359
+                'The expiration date of the publicly shared %s with ID "%s" has been changed to "%s"',
360
+                $params,
361
+                [
362
+                    'itemType',
363
+                    'itemSource',
364
+                    'date',
365
+                ]
366
+            );
367
+        }
368
+    }
369 369
 
370
-	/**
371
-	 * Logs access of shared files
372
-	 *
373
-	 * @param array $params
374
-	 */
375
-	public function shareAccessed(array $params): void {
376
-		$this->log(
377
-			'The shared %s with the token "%s" by "%s" has been accessed.',
378
-			$params,
379
-			[
380
-				'itemType',
381
-				'token',
382
-				'uidOwner',
383
-			]
384
-		);
385
-	}
370
+    /**
371
+     * Logs access of shared files
372
+     *
373
+     * @param array $params
374
+     */
375
+    public function shareAccessed(array $params): void {
376
+        $this->log(
377
+            'The shared %s with the token "%s" by "%s" has been accessed.',
378
+            $params,
379
+            [
380
+                'itemType',
381
+                'token',
382
+                'uidOwner',
383
+            ]
384
+        );
385
+    }
386 386
 }
Please login to merge, or discard this patch.