Passed
Push — master ( ccc0a5...5195be )
by Roeland
10:43 queued 11s
created

ShareAPIController::acceptShare()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 14
nc 6
nop 1
dl 0
loc 21
rs 9.2222
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright Copyright (c) 2016, ownCloud, Inc.
5
 *
6
 * @author Bjoern Schiessle <[email protected]>
7
 * @author Joas Schilling <[email protected]>
8
 * @author Lukas Reschke <[email protected]>
9
 * @author Maxence Lange <[email protected]>
10
 * @author Michael Jobst <[email protected]>
11
 * @author Robin Appelman <[email protected]>
12
 * @author Roeland Jago Douma <[email protected]>
13
 * @author Vincent Petry <[email protected]>
14
 * @author John Molakvoæ <[email protected]>
15
 *
16
 * @license AGPL-3.0
17
 *
18
 * This code is free software: you can redistribute it and/or modify
19
 * it under the terms of the GNU Affero General Public License, version 3,
20
 * as published by the Free Software Foundation.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
 * GNU Affero General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU Affero General Public License, version 3,
28
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
29
 *
30
 */
31
32
namespace OCA\Files_Sharing\Controller;
33
34
use OCA\Files\Helper;
35
use OCP\App\IAppManager;
36
use OCP\AppFramework\Http\DataResponse;
37
use OCP\AppFramework\OCS\OCSBadRequestException;
38
use OCP\AppFramework\OCS\OCSException;
39
use OCP\AppFramework\OCS\OCSForbiddenException;
40
use OCP\AppFramework\OCS\OCSNotFoundException;
41
use OCP\AppFramework\OCSController;
42
use OCP\AppFramework\QueryException;
43
use OCP\Constants;
44
use OCP\Files\Node;
45
use OCP\Files\NotFoundException;
46
use OCP\IConfig;
47
use OCP\IGroupManager;
48
use OCP\IL10N;
49
use OCP\IUserManager;
50
use OCP\IRequest;
51
use OCP\IServerContainer;
52
use OCP\IURLGenerator;
53
use OCP\Files\IRootFolder;
54
use OCP\Lock\LockedException;
55
use OCP\Share;
56
use OCP\Share\IManager;
57
use OCP\Share\Exceptions\ShareNotFound;
58
use OCP\Share\Exceptions\GenericShareException;
59
use OCP\Lock\ILockingProvider;
60
use OCP\Share\IShare;
61
use OCA\Files_Sharing\External\Storage;
62
63
/**
64
 * Class Share20OCS
65
 *
66
 * @package OCA\Files_Sharing\API
67
 */
68
class ShareAPIController extends OCSController {
69
70
	/** @var IManager */
71
	private $shareManager;
72
	/** @var IGroupManager */
73
	private $groupManager;
74
	/** @var IUserManager */
75
	private $userManager;
76
	/** @var IRootFolder */
77
	private $rootFolder;
78
	/** @var IURLGenerator */
79
	private $urlGenerator;
80
	/** @var string */
81
	private $currentUser;
82
	/** @var IL10N */
83
	private $l;
84
	/** @var \OCP\Files\Node */
85
	private $lockedNode;
86
	/** @var IConfig */
87
	private $config;
88
	/** @var IAppManager */
89
	private $appManager;
90
	/** @var IServerContainer */
91
	private $serverContainer;
92
93
	/**
94
	 * Share20OCS constructor.
95
	 *
96
	 * @param string $appName
97
	 * @param IRequest $request
98
	 * @param IManager $shareManager
99
	 * @param IGroupManager $groupManager
100
	 * @param IUserManager $userManager
101
	 * @param IRootFolder $rootFolder
102
	 * @param IURLGenerator $urlGenerator
103
	 * @param string $userId
104
	 * @param IL10N $l10n
105
	 * @param IConfig $config
106
	 * @param IAppManager $appManager
107
	 * @param IServerContainer $serverContainer
108
	 */
109
	public function __construct(
110
		string $appName,
111
		IRequest $request,
112
		IManager $shareManager,
113
		IGroupManager $groupManager,
114
		IUserManager $userManager,
115
		IRootFolder $rootFolder,
116
		IURLGenerator $urlGenerator,
117
		string $userId = null,
118
		IL10N $l10n,
119
		IConfig $config,
120
		IAppManager $appManager,
121
		IServerContainer $serverContainer
122
	) {
123
		parent::__construct($appName, $request);
124
125
		$this->shareManager = $shareManager;
126
		$this->userManager = $userManager;
127
		$this->groupManager = $groupManager;
128
		$this->request = $request;
129
		$this->rootFolder = $rootFolder;
130
		$this->urlGenerator = $urlGenerator;
131
		$this->currentUser = $userId;
132
		$this->l = $l10n;
133
		$this->config = $config;
134
		$this->appManager = $appManager;
135
		$this->serverContainer = $serverContainer;
136
	}
137
138
	/**
139
	 * Convert an IShare to an array for OCS output
140
	 *
141
	 * @param \OCP\Share\IShare $share
142
	 * @param Node|null $recipientNode
143
	 * @return array
144
	 * @throws NotFoundException In case the node can't be resolved.
145
	 *
146
	 * @suppress PhanUndeclaredClassMethod
147
	 */
148
	protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = null): array {
149
		$sharedBy = $this->userManager->get($share->getSharedBy());
150
		$shareOwner = $this->userManager->get($share->getShareOwner());
151
152
		$result = [
153
			'id' => $share->getId(),
154
			'share_type' => $share->getShareType(),
155
			'uid_owner' => $share->getSharedBy(),
156
			'displayname_owner' => $sharedBy !== null ? $sharedBy->getDisplayName() : $share->getSharedBy(),
157
			// recipient permissions
158
			'permissions' => $share->getPermissions(),
159
			// current user permissions on this share
160
			'can_edit' => $this->canEditShare($share),
161
			'can_delete' => $this->canDeleteShare($share),
162
			'stime' => $share->getShareTime()->getTimestamp(),
163
			'parent' => null,
164
			'expiration' => null,
165
			'token' => null,
166
			'uid_file_owner' => $share->getShareOwner(),
167
			'note' => $share->getNote(),
168
			'label' => $share->getLabel(),
169
			'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(),
170
		];
171
172
		$userFolder = $this->rootFolder->getUserFolder($this->currentUser);
173
		if ($recipientNode) {
174
			$node = $recipientNode;
175
		} else {
176
			$nodes = $userFolder->getById($share->getNodeId());
177
			if (empty($nodes)) {
178
				// fallback to guessing the path
179
				$node = $userFolder->get($share->getTarget());
180
				if ($node === null || $share->getTarget() === '') {
181
					throw new NotFoundException();
182
				}
183
			} else {
184
				$node = $nodes[0];
185
			}
186
		}
187
188
		$result['path'] = $userFolder->getRelativePath($node->getPath());
189
		if ($node instanceof \OCP\Files\Folder) {
190
			$result['item_type'] = 'folder';
191
		} else {
192
			$result['item_type'] = 'file';
193
		}
194
195
		$result['mimetype'] = $node->getMimetype();
196
		$result['storage_id'] = $node->getStorage()->getId();
197
		$result['storage'] = $node->getStorage()->getCache()->getNumericStorageId();
198
		$result['item_source'] = $node->getId();
199
		$result['file_source'] = $node->getId();
200
		$result['file_parent'] = $node->getParent()->getId();
201
		$result['file_target'] = $share->getTarget();
202
203
		$expiration = $share->getExpirationDate();
204
		if ($expiration !== null) {
205
			$result['expiration'] = $expiration->format('Y-m-d 00:00:00');
206
		}
207
208
		if ($share->getShareType() === Share::SHARE_TYPE_USER) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_USER has been deprecated: 17.0.0 - use IShare::TYPE_USER instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

208
		if ($share->getShareType() === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_USER) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
209
			$sharedWith = $this->userManager->get($share->getSharedWith());
210
			$result['share_with'] = $share->getSharedWith();
211
			$result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith();
212
		} else if ($share->getShareType() === Share::SHARE_TYPE_GROUP) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_GROUP has been deprecated: 17.0.0 - use IShare::TYPE_GROUP instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

212
		} else if ($share->getShareType() === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_GROUP) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
213
			$group = $this->groupManager->get($share->getSharedWith());
214
			$result['share_with'] = $share->getSharedWith();
215
			$result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith();
216
		} else if ($share->getShareType() === Share::SHARE_TYPE_LINK) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_LINK has been deprecated: 17.0.0 - use IShare::TYPE_LINK instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

216
		} else if ($share->getShareType() === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_LINK) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
217
218
			// "share_with" and "share_with_displayname" for passwords of link
219
			// shares was deprecated in Nextcloud 15, use "password" instead.
220
			$result['share_with'] = $share->getPassword();
221
			$result['share_with_displayname'] = $share->getPassword();
222
223
			$result['password'] = $share->getPassword();
224
225
			$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
226
227
			$result['token'] = $share->getToken();
228
			$result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]);
229
		} else if ($share->getShareType() === Share::SHARE_TYPE_REMOTE || $share->getShareType() === Share::SHARE_TYPE_REMOTE_GROUP) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_REMOTE has been deprecated: 17.0.0 - use IShare::TYPE_REMOTE instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

229
		} else if ($share->getShareType() === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_REMOTE || $share->getShareType() === Share::SHARE_TYPE_REMOTE_GROUP) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_REMOTE_GROUP has been deprecated: 17.0.0 - use IShare::REMOTE_GROUP instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

229
		} else if ($share->getShareType() === Share::SHARE_TYPE_REMOTE || $share->getShareType() === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_REMOTE_GROUP) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
230
			$result['share_with'] = $share->getSharedWith();
231
			$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD');
232
			$result['token'] = $share->getToken();
233
		} else if ($share->getShareType() === Share::SHARE_TYPE_EMAIL) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_EMAIL has been deprecated: 17.0.0 - use IShare::TYPE_EMAIL instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

233
		} else if ($share->getShareType() === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_EMAIL) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
234
			$result['share_with'] = $share->getSharedWith();
235
			$result['password'] = $share->getPassword();
236
			$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
237
			$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
238
			$result['token'] = $share->getToken();
239
		} else if ($share->getShareType() === Share::SHARE_TYPE_CIRCLE) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_CIRCLE has been deprecated: 17.0.0 - use IShare::TYPE_CIRCLE instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

239
		} else if ($share->getShareType() === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_CIRCLE) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
240
			// getSharedWith() returns either "name (type, owner)" or
241
			// "name (type, owner) [id]", depending on the Circles app version.
242
			$hasCircleId = (substr($share->getSharedWith(), -1) === ']');
243
244
			$result['share_with_displayname'] = $share->getSharedWithDisplayName();
245
			if (empty($result['share_with_displayname'])) {
246
				$displayNameLength = ($hasCircleId ? strrpos($share->getSharedWith(), ' ') : strlen($share->getSharedWith()));
247
				$result['share_with_displayname'] = substr($share->getSharedWith(), 0, $displayNameLength);
248
			}
249
250
			$result['share_with_avatar'] = $share->getSharedWithAvatar();
251
252
			$shareWithStart = ($hasCircleId ? strrpos($share->getSharedWith(), '[') + 1 : 0);
253
			$shareWithLength = ($hasCircleId ? -1 : strpos($share->getSharedWith(), ' '));
254
			if (is_bool($shareWithLength)) {
0 ignored issues
show
introduced by
The condition is_bool($shareWithLength) is always false.
Loading history...
255
				$shareWithLength = -1;
256
			}
257
			$result['share_with'] = substr($share->getSharedWith(), $shareWithStart, $shareWithLength);
258
		} else if ($share->getShareType() === Share::SHARE_TYPE_ROOM) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_ROOM has been deprecated: 17.0.0 - use IShare::TYPE_ROOM instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

258
		} else if ($share->getShareType() === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_ROOM) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
259
			$result['share_with'] = $share->getSharedWith();
260
			$result['share_with_displayname'] = '';
261
262
			try {
263
				$result = array_merge($result, $this->getRoomShareHelper()->formatShare($share));
264
			} catch (QueryException $e) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
265
		}
266
267
268
		$result['mail_send'] = $share->getMailSend() ? 1 : 0;
269
		$result['hide_download'] = $share->getHideDownload() ? 1 : 0;
270
271
		return $result;
272
	}
273
274
	/**
275
	 * Check if one of the users address books knows the exact property, if
276
	 * yes we return the full name.
277
	 *
278
	 * @param string $query
279
	 * @param string $property
280
	 * @return string
281
	 */
282
	private function getDisplayNameFromAddressBook(string $query, string $property): string {
283
		// FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered
284
		$result = \OC::$server->getContactsManager()->search($query, [$property]);
285
		foreach ($result as $r) {
286
			foreach ($r[$property] as $value) {
287
				if ($value === $query) {
288
					return $r['FN'];
289
				}
290
			}
291
		}
292
293
		return $query;
294
	}
295
296
	/**
297
	 * Get a specific share by id
298
	 *
299
	 * @NoAdminRequired
300
	 *
301
	 * @param string $id
302
	 * @return DataResponse
303
	 * @throws OCSNotFoundException
304
	 */
305
	public function getShare(string $id): DataResponse {
306
		try {
307
			$share = $this->getShareById($id);
308
		} catch (ShareNotFound $e) {
309
			throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
310
		}
311
312
		try {
313
			if ($this->canAccessShare($share)) {
314
				$share = $this->formatShare($share);
315
				return new DataResponse([$share]);
316
			}
317
		} catch (NotFoundException $e) {
318
			// Fall trough
319
		}
320
321
		throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
322
	}
323
324
	/**
325
	 * Delete a share
326
	 *
327
	 * @NoAdminRequired
328
	 *
329
	 * @param string $id
330
	 * @return DataResponse
331
	 * @throws OCSNotFoundException
332
	 */
333
	public function deleteShare(string $id): DataResponse {
334
		try {
335
			$share = $this->getShareById($id);
336
		} catch (ShareNotFound $e) {
337
			throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
338
		}
339
340
		try {
341
			$this->lock($share->getNode());
342
		} catch (LockedException $e) {
343
			throw new OCSNotFoundException($this->l->t('Could not delete share'));
344
		}
345
346
		if (!$this->canAccessShare($share)) {
347
			throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
348
		}
349
350
		// if it's a group share or a room share
351
		// we don't delete the share, but only the
352
		// mount point. Allowing it to be restored
353
		// from the deleted shares
354
		if ($this->canDeleteShareFromSelf($share)) {
355
			$this->shareManager->deleteFromSelf($share, $this->currentUser);
356
		} else {
357
			if (!$this->canDeleteShare($share)) {
358
				throw new OCSForbiddenException($this->l->t('Could not delete share'));
359
			}
360
361
			$this->shareManager->deleteShare($share);
362
		}
363
364
		return new DataResponse();
365
	}
366
367
	/**
368
	 * @NoAdminRequired
369
	 *
370
	 * @param string $path
371
	 * @param int $permissions
372
	 * @param int $shareType
373
	 * @param string $shareWith
374
	 * @param string $publicUpload
375
	 * @param string $password
376
	 * @param string $sendPasswordByTalk
377
	 * @param string $expireDate
378
	 * @param string $label
379
	 *
380
	 * @return DataResponse
381
	 * @throws NotFoundException
382
	 * @throws OCSBadRequestException
383
	 * @throws OCSException
384
	 * @throws OCSForbiddenException
385
	 * @throws OCSNotFoundException
386
	 * @throws \OCP\Files\InvalidPathException
387
	 * @suppress PhanUndeclaredClassMethod
388
	 */
389
	public function createShare(
390
		string $path = null,
391
		int $permissions = null,
392
		int $shareType = -1,
393
		string $shareWith = null,
394
		string $publicUpload = 'false',
395
		string $password = '',
396
		string $sendPasswordByTalk = null,
397
		string $expireDate = '',
398
		string $label = ''
399
	): DataResponse {
400
		$share = $this->shareManager->newShare();
401
402
		if ($permissions === null) {
403
			$permissions = $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL);
404
		}
405
406
		// Verify path
407
		if ($path === null) {
408
			throw new OCSNotFoundException($this->l->t('Please specify a file or folder path'));
409
		}
410
411
		$userFolder = $this->rootFolder->getUserFolder($this->currentUser);
412
		try {
413
			$path = $userFolder->get($path);
414
		} catch (NotFoundException $e) {
415
			throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist'));
416
		}
417
418
		$share->setNode($path);
419
420
		try {
421
			$this->lock($share->getNode());
422
		} catch (LockedException $e) {
423
			throw new OCSNotFoundException($this->l->t('Could not create share'));
424
		}
425
426
		if ($permissions < 0 || $permissions > Constants::PERMISSION_ALL) {
427
			throw new OCSNotFoundException($this->l->t('invalid permissions'));
428
		}
429
430
		// Shares always require read permissions
431
		$permissions |= Constants::PERMISSION_READ;
432
433
		if ($path instanceof \OCP\Files\File) {
434
			// Single file shares should never have delete or create permissions
435
			$permissions &= ~Constants::PERMISSION_DELETE;
436
			$permissions &= ~Constants::PERMISSION_CREATE;
437
		}
438
439
		/**
440
		 * Hack for https://github.com/owncloud/core/issues/22587
441
		 * We check the permissions via webdav. But the permissions of the mount point
442
		 * do not equal the share permissions. Here we fix that for federated mounts.
443
		 */
444
		if ($path->getStorage()->instanceOfStorage(Storage::class)) {
445
			$permissions &= ~($permissions & ~$path->getPermissions());
446
		}
447
448
		if ($shareType === Share::SHARE_TYPE_USER) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_USER has been deprecated: 17.0.0 - use IShare::TYPE_USER instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

448
		if ($shareType === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_USER) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
449
			// Valid user is required to share
450
			if ($shareWith === null || !$this->userManager->userExists($shareWith)) {
451
				throw new OCSNotFoundException($this->l->t('Please specify a valid user'));
452
			}
453
			$share->setSharedWith($shareWith);
454
			$share->setPermissions($permissions);
455
		} else if ($shareType === Share::SHARE_TYPE_GROUP) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_GROUP has been deprecated: 17.0.0 - use IShare::TYPE_GROUP instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

455
		} else if ($shareType === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_GROUP) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
456
			if (!$this->shareManager->allowGroupSharing()) {
457
				throw new OCSNotFoundException($this->l->t('Group sharing is disabled by the administrator'));
458
			}
459
460
			// Valid group is required to share
461
			if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) {
462
				throw new OCSNotFoundException($this->l->t('Please specify a valid group'));
463
			}
464
			$share->setSharedWith($shareWith);
465
			$share->setPermissions($permissions);
466
		} else if ($shareType === Share::SHARE_TYPE_LINK
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_LINK has been deprecated: 17.0.0 - use IShare::TYPE_LINK instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

466
		} else if ($shareType === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_LINK

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
467
			|| $shareType === Share::SHARE_TYPE_EMAIL) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_EMAIL has been deprecated: 17.0.0 - use IShare::TYPE_EMAIL instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

467
			|| $shareType === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_EMAIL) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
468
469
			// Can we even share links?
470
			if (!$this->shareManager->shareApiAllowLinks()) {
471
				throw new OCSNotFoundException($this->l->t('Public link sharing is disabled by the administrator'));
472
			}
473
474
			if ($publicUpload === 'true') {
475
				// Check if public upload is allowed
476
				if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
477
					throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator'));
478
				}
479
480
				// Public upload can only be set for folders
481
				if ($path instanceof \OCP\Files\File) {
482
					throw new OCSNotFoundException($this->l->t('Public upload is only possible for publicly shared folders'));
483
				}
484
485
				$share->setPermissions(
486
					Constants::PERMISSION_READ |
487
					Constants::PERMISSION_CREATE |
488
					Constants::PERMISSION_UPDATE |
489
					Constants::PERMISSION_DELETE
490
				);
491
			} else {
492
				$share->setPermissions(Constants::PERMISSION_READ);
493
			}
494
495
			// Set password
496
			if ($password !== '') {
497
				$share->setPassword($password);
498
			}
499
500
			// Only share by mail have a recipient
501
			if ($shareType === Share::SHARE_TYPE_EMAIL) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_EMAIL has been deprecated: 17.0.0 - use IShare::TYPE_EMAIL instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

501
			if ($shareType === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_EMAIL) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
502
				$share->setSharedWith($shareWith);
503
			} else {
504
				// Only link share have a label
505
				if (!empty($label)) {
506
					$share->setLabel($label);
507
				}
508
			}
509
510
			if ($sendPasswordByTalk === 'true') {
511
				if (!$this->appManager->isEnabledForUser('spreed')) {
512
					throw new OCSForbiddenException($this->l->t('Sharing %s sending the password by Nextcloud Talk failed because Nextcloud Talk is not enabled', [$path->getPath()]));
513
				}
514
515
				$share->setSendPasswordByTalk(true);
516
			}
517
518
			//Expire date
519
			if ($expireDate !== '') {
520
				try {
521
					$expireDate = $this->parseDate($expireDate);
522
					$share->setExpirationDate($expireDate);
523
				} catch (\Exception $e) {
524
					throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
525
				}
526
			}
527
		} else if ($shareType === Share::SHARE_TYPE_REMOTE) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_REMOTE has been deprecated: 17.0.0 - use IShare::TYPE_REMOTE instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

527
		} else if ($shareType === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_REMOTE) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
528
			if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
529
				throw new OCSForbiddenException($this->l->t('Sharing %1$s failed because the back end does not allow shares from type %2$s', [$path->getPath(), $shareType]));
530
			}
531
532
			$share->setSharedWith($shareWith);
533
			$share->setPermissions($permissions);
534
		} else if ($shareType === Share::SHARE_TYPE_REMOTE_GROUP) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_REMOTE_GROUP has been deprecated: 17.0.0 - use IShare::REMOTE_GROUP instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

534
		} else if ($shareType === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_REMOTE_GROUP) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
535
			if (!$this->shareManager->outgoingServer2ServerGroupSharesAllowed()) {
536
				throw new OCSForbiddenException($this->l->t('Sharing %1$s failed because the back end does not allow shares from type %2$s', [$path->getPath(), $shareType]));
537
			}
538
539
			$share->setSharedWith($shareWith);
540
			$share->setPermissions($permissions);
541
		} else if ($shareType === Share::SHARE_TYPE_CIRCLE) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_CIRCLE has been deprecated: 17.0.0 - use IShare::TYPE_CIRCLE instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

541
		} else if ($shareType === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_CIRCLE) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
542
			if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) {
543
				throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled'));
544
			}
545
546
			$circle = \OCA\Circles\Api\v1\Circles::detailsCircle($shareWith);
0 ignored issues
show
Bug introduced by
The type OCA\Circles\Api\v1\Circles was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
547
548
			// Valid circle is required to share
549
			if ($circle === null) {
550
				throw new OCSNotFoundException($this->l->t('Please specify a valid circle'));
551
			}
552
			$share->setSharedWith($shareWith);
553
			$share->setPermissions($permissions);
554
		} else if ($shareType === Share::SHARE_TYPE_ROOM) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_ROOM has been deprecated: 17.0.0 - use IShare::TYPE_ROOM instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

554
		} else if ($shareType === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_ROOM) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
555
			try {
556
				$this->getRoomShareHelper()->createShare($share, $shareWith, $permissions, $expireDate);
557
			} catch (QueryException $e) {
558
				throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not support room shares', [$path->getPath()]));
559
			}
560
		} else {
561
			throw new OCSBadRequestException($this->l->t('Unknown share type'));
562
		}
563
564
		$share->setShareType($shareType);
565
		$share->setSharedBy($this->currentUser);
566
567
		try {
568
			$share = $this->shareManager->createShare($share);
569
		} catch (GenericShareException $e) {
570
			$code = $e->getCode() === 0 ? 403 : $e->getCode();
571
			throw new OCSException($e->getHint(), $code);
572
		} catch (\Exception $e) {
573
			throw new OCSForbiddenException($e->getMessage(), $e);
574
		}
575
576
		$output = $this->formatShare($share);
577
578
		return new DataResponse($output);
579
	}
580
581
	/**
582
	 * @param \OCP\Files\File|\OCP\Files\Folder $node
583
	 * @param boolean $includeTags
584
	 * @return DataResponse
585
	 */
586
	private function getSharedWithMe($node = null, bool $includeTags): DataResponse {
587
588
		$userShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_USER, $node, -1, 0);
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_USER has been deprecated: 17.0.0 - use IShare::TYPE_USER instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

588
		$userShares = $this->shareManager->getSharedWith($this->currentUser, /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_USER, $node, -1, 0);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
589
		$groupShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_GROUP, $node, -1, 0);
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_GROUP has been deprecated: 17.0.0 - use IShare::TYPE_GROUP instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

589
		$groupShares = $this->shareManager->getSharedWith($this->currentUser, /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_GROUP, $node, -1, 0);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
590
		$circleShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_CIRCLE, $node, -1, 0);
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_CIRCLE has been deprecated: 17.0.0 - use IShare::TYPE_CIRCLE instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

590
		$circleShares = $this->shareManager->getSharedWith($this->currentUser, /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_CIRCLE, $node, -1, 0);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
591
		$roomShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_ROOM, $node, -1, 0);
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_ROOM has been deprecated: 17.0.0 - use IShare::TYPE_ROOM instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

591
		$roomShares = $this->shareManager->getSharedWith($this->currentUser, /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_ROOM, $node, -1, 0);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
592
593
		$shares = array_merge($userShares, $groupShares, $circleShares, $roomShares);
594
595
		$shares = array_filter($shares, function (IShare $share) {
596
			return $share->getShareOwner() !== $this->currentUser;
597
		});
598
599
		$formatted = [];
600
		foreach ($shares as $share) {
601
			if ($this->canAccessShare($share)) {
602
				try {
603
					$formatted[] = $this->formatShare($share);
604
				} catch (NotFoundException $e) {
605
					// Ignore this share
606
				}
607
			}
608
		}
609
610
		if ($includeTags) {
611
			$formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager());
612
		}
613
614
		return new DataResponse($formatted);
615
	}
616
617
	/**
618
	 * @param \OCP\Files\Folder $folder
619
	 * @return array
620
	 * @throws OCSBadRequestException
621
	 */
622
	private function getSharesInDir(Node $folder): array {
623
		if (!($folder instanceof \OCP\Files\Folder)) {
624
			throw new OCSBadRequestException($this->l->t('Not a directory'));
625
		}
626
627
		$nodes = $folder->getDirectoryListing();
628
629
		/** @var \OCP\Share\IShare[] $shares */
630
		$shares = array_reduce($nodes, function($carry, $node) {
631
			$carry = array_merge($carry, $this->getAllShares($node, true));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getAllShares($node, true) targeting OCA\Files_Sharing\Contro...troller::getAllShares() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
$this->getAllShares($node, true) of type void is incompatible with the type array|null expected by parameter $array2 of array_merge(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

631
			$carry = array_merge($carry, /** @scrutinizer ignore-type */ $this->getAllShares($node, true));
Loading history...
632
			return $carry;
633
		}, []);
634
635
		// filter out duplicate shares
636
		$known = [];
637
		return array_filter($shares, function($share) use (&$known) {
638
			if (in_array($share->getId(), $known)) {
639
				return false;
640
			}
641
			$known[] = $share->getId();
642
			return true;
643
		});
644
	}
645
646
	/**
647
	 * The getShares function.
648
	 *
649
	 * @NoAdminRequired
650
	 *
651
	 * @param string $shared_with_me
652
	 * @param string $reshares
653
	 * @param string $subfiles
654
	 * @param string $path
655
	 *
656
	 * - Get shares by the current user
657
	 * - Get shares by the current user and reshares (?reshares=true)
658
	 * - Get shares with the current user (?shared_with_me=true)
659
	 * - Get shares for a specific path (?path=...)
660
	 * - Get all shares in a folder (?subfiles=true&path=..)
661
	 *
662
	 * @return DataResponse
663
	 * @throws OCSNotFoundException
664
	 */
665
	public function getShares(
666
		string $shared_with_me = 'false',
667
		string $reshares = 'false',
668
		string $subfiles = 'false',
669
		string $path = null,
670
		string $include_tags = 'false'
671
	): DataResponse {
672
673
		if ($path !== null) {
674
			$userFolder = $this->rootFolder->getUserFolder($this->currentUser);
675
			try {
676
				$path = $userFolder->get($path);
677
				$this->lock($path);
678
			} catch (\OCP\Files\NotFoundException $e) {
679
				throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist'));
680
			} catch (LockedException $e) {
681
				throw new OCSNotFoundException($this->l->t('Could not lock path'));
682
			}
683
		}
684
685
		$include_tags = $include_tags === 'true';
686
687
		if ($shared_with_me === 'true') {
688
			$result = $this->getSharedWithMe($path, $include_tags);
689
			return $result;
690
		}
691
692
		if ($reshares === 'true') {
693
			$reshares = true;
694
		} else {
695
			$reshares = false;
696
		}
697
698
		if ($subfiles === 'true') {
699
			$shares = $this->getSharesInDir($path);
700
			$recipientNode = null;
701
		} else {
702
			// get all shares
703
			$shares = $this->getAllShares($path, $reshares);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $shares is correct as $this->getAllShares($path, $reshares) targeting OCA\Files_Sharing\Contro...troller::getAllShares() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
704
			$recipientNode = $path;
705
		}
706
707
		// process all shares
708
		$formatted = $miniFormatted = [];
709
		$resharingRight = false;
710
		foreach ($shares as $share) {
711
			/** @var IShare $share */
712
713
			// do not list the shares of the current user
714
			if ($share->getSharedWith() === $this->currentUser) {
715
				continue;
716
			}
717
718
			try {
719
				$format = $this->formatShare($share, $recipientNode);
720
				$formatted[] = $format;
721
722
				// let's also build a list of shares created
723
				// by the current user only, in case
724
				// there is no resharing rights
725
				if ($share->getSharedBy() === $this->currentUser) {
726
					$miniFormatted[] = $format;
727
				}
728
729
				// check if one of those share is shared with me
730
				// and if I have resharing rights on it
731
				if (!$resharingRight && $this->shareProviderResharingRights($this->currentUser, $share, $path)) {
732
					$resharingRight = true;
733
				}
734
			} catch (\Exception $e) {
735
				//Ignore share
736
			}
737
		}
738
739
		if (!$resharingRight) {
740
			$formatted = $miniFormatted;
741
		}
742
743
		if ($include_tags) {
744
			$formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager());
745
		}
746
747
		return new DataResponse($formatted);
748
	}
749
750
	/**
751
	 * @NoAdminRequired
752
	 *
753
	 * @param string $id
754
	 * @param int $permissions
755
	 * @param string $password
756
	 * @param string $sendPasswordByTalk
757
	 * @param string $publicUpload
758
	 * @param string $expireDate
759
	 * @param string $note
760
	 * @param string $label
761
	 * @param string $hideDownload
762
	 * @return DataResponse
763
	 * @throws LockedException
764
	 * @throws NotFoundException
765
	 * @throws OCSBadRequestException
766
	 * @throws OCSForbiddenException
767
	 * @throws OCSNotFoundException
768
	 */
769
	public function updateShare(
770
		string $id,
771
		int $permissions = null,
772
		string $password = null,
773
		string $sendPasswordByTalk = null,
774
		string $publicUpload = null,
775
		string $expireDate = null,
776
		string $note = null,
777
		string $label = null,
778
		string $hideDownload = null
779
	): DataResponse {
780
		try {
781
			$share = $this->getShareById($id);
782
		} catch (ShareNotFound $e) {
783
			throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
784
		}
785
786
		$this->lock($share->getNode());
787
788
		if (!$this->canAccessShare($share, false)) {
789
			throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
790
		}
791
792
		if (!$this->canEditShare($share)) {
793
			throw new OCSForbiddenException('You are not allowed to edit incoming shares');
794
		}
795
796
		if (
797
			$permissions === null &&
798
			$password === null &&
799
			$sendPasswordByTalk === null &&
800
			$publicUpload === null &&
801
			$expireDate === null &&
802
			$note === null &&
803
			$label === null &&
804
			$hideDownload === null
805
		) {
806
			throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given'));
807
		}
808
809
		if ($note !== null) {
810
			$share->setNote($note);
811
		}
812
813
		/**
814
		 * expirationdate, password and publicUpload only make sense for link shares
815
		 */
816
		if ($share->getShareType() === Share::SHARE_TYPE_LINK
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_LINK has been deprecated: 17.0.0 - use IShare::TYPE_LINK instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

816
		if ($share->getShareType() === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_LINK

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
817
			|| $share->getShareType() === Share::SHARE_TYPE_EMAIL) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_EMAIL has been deprecated: 17.0.0 - use IShare::TYPE_EMAIL instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

817
			|| $share->getShareType() === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_EMAIL) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
818
819
			/**
820
			 * We do not allow editing link shares that the current user
821
			 * doesn't own. This is confusing and lead to errors when
822
			 * someone else edit a password or expiration date without
823
			 * the share owner knowing about it.
824
			 * We only allow deletion
825
			 */
826
827
			if ($share->getSharedBy() !== $this->currentUser) {
828
				throw new OCSForbiddenException('You are not allowed to edit link shares that you don\'t own');
829
			}
830
831
			// Update hide download state
832
			if ($hideDownload === 'true') {
833
				$share->setHideDownload(true);
834
			} else if ($hideDownload === 'false') {
835
				$share->setHideDownload(false);
836
			}
837
838
			$newPermissions = null;
839
			if ($publicUpload === 'true') {
840
				$newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE;
841
			} else if ($publicUpload === 'false') {
842
				$newPermissions = Constants::PERMISSION_READ;
843
			}
844
845
			if ($permissions !== null) {
846
				$newPermissions = (int) $permissions;
847
				$newPermissions = $newPermissions & ~Constants::PERMISSION_SHARE;
848
			}
849
850
			if ($newPermissions !== null &&
851
				!in_array($newPermissions, [
852
					Constants::PERMISSION_READ,
853
					Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE, // legacy
854
					Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE, // correct
855
					Constants::PERMISSION_CREATE, // hidden file list
856
					Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE, // allow to edit single files
857
				], true)
858
			) {
859
				throw new OCSBadRequestException($this->l->t('Can\'t change permissions for public share links'));
860
			}
861
862
			if (
863
				// legacy
864
				$newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE) ||
865
				// correct
866
				$newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
867
			) {
868
				if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
869
					throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator'));
870
				}
871
872
				if (!($share->getNode() instanceof \OCP\Files\Folder)) {
873
					throw new OCSBadRequestException($this->l->t('Public upload is only possible for publicly shared folders'));
874
				}
875
876
				// normalize to correct public upload permissions
877
				$newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE;
878
			}
879
880
			if ($newPermissions !== null) {
881
				$share->setPermissions($newPermissions);
882
				$permissions = $newPermissions;
0 ignored issues
show
Unused Code introduced by
The assignment to $permissions is dead and can be removed.
Loading history...
883
			}
884
885
			if ($expireDate === '') {
886
				$share->setExpirationDate(null);
887
			} else if ($expireDate !== null) {
888
				try {
889
					$expireDate = $this->parseDate($expireDate);
890
				} catch (\Exception $e) {
891
					throw new OCSBadRequestException($e->getMessage(), $e);
892
				}
893
				$share->setExpirationDate($expireDate);
894
			}
895
896
			if ($password === '') {
897
				$share->setPassword(null);
898
			} else if ($password !== null) {
899
				$share->setPassword($password);
900
			}
901
902
			// only link shares have labels
903
			if ($share->getShareType() === Share::SHARE_TYPE_LINK && $label !== null) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_LINK has been deprecated: 17.0.0 - use IShare::TYPE_LINK instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

903
			if ($share->getShareType() === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_LINK && $label !== null) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
904
				$share->setLabel($label);
905
			}
906
907
			if ($sendPasswordByTalk === 'true') {
908
				if (!$this->appManager->isEnabledForUser('spreed')) {
909
					throw new OCSForbiddenException($this->l->t('Sharing sending the password by Nextcloud Talk failed because Nextcloud Talk is not enabled'));
910
				}
911
912
				$share->setSendPasswordByTalk(true);
913
			} else if ($sendPasswordByTalk !== null) {
914
				$share->setSendPasswordByTalk(false);
915
			}
916
		}
917
918
		// NOT A LINK SHARE
919
		else {
920
			if ($permissions !== null) {
921
				$permissions = (int) $permissions;
922
				$share->setPermissions($permissions);
923
			}
924
925
			if ($expireDate === '') {
926
				$share->setExpirationDate(null);
927
			} else if ($expireDate !== null) {
928
				try {
929
					$expireDate = $this->parseDate($expireDate);
930
				} catch (\Exception $e) {
931
					throw new OCSBadRequestException($e->getMessage(), $e);
932
				}
933
				$share->setExpirationDate($expireDate);
934
			}
935
		}
936
937
		try {
938
			$share = $this->shareManager->updateShare($share);
939
		} catch (GenericShareException $e) {
940
			$code = $e->getCode() === 0 ? 403 : $e->getCode();
941
			throw new OCSException($e->getHint(), $code);
942
		} catch (\Exception $e) {
943
			throw new OCSBadRequestException($e->getMessage(), $e);
944
		}
945
946
		return new DataResponse($this->formatShare($share));
947
	}
948
949
	/**
950
	 * @NoAdminRequired
951
	 *
952
	 * @param string $id
953
	 * @return DataResponse
954
	 * @throws OCSNotFoundException
955
	 * @throws OCSException
956
	 * @throws OCSBadRequestException
957
	 */
958
	public function acceptShare(string $id): DataResponse {
959
		try {
960
			$share = $this->getShareById($id);
961
		} catch (ShareNotFound $e) {
962
			throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
963
		}
964
965
		if (!$this->canAccessShare($share)) {
966
			throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
967
		}
968
969
		try {
970
			$this->shareManager->acceptShare($share, $this->currentUser);
971
		} catch (GenericShareException $e) {
972
			$code = $e->getCode() === 0 ? 403 : $e->getCode();
973
			throw new OCSException($e->getHint(), $code);
974
		} catch (\Exception $e) {
975
			throw new OCSBadRequestException($e->getMessage(), $e);
976
		}
977
978
		return new DataResponse();
979
	}
980
981
	/**
982
	 * Does the user have read permission on the share
983
	 *
984
	 * @param \OCP\Share\IShare $share the share to check
985
	 * @param boolean $checkGroups check groups as well?
986
	 * @return boolean
987
	 * @throws NotFoundException
988
	 *
989
	 * @suppress PhanUndeclaredClassMethod
990
	 */
991
	protected function canAccessShare(\OCP\Share\IShare $share, bool $checkGroups = true): bool {
992
		// A file with permissions 0 can't be accessed by us. So Don't show it
993
		if ($share->getPermissions() === 0) {
994
			return false;
995
		}
996
997
		// Owner of the file and the sharer of the file can always get share
998
		if ($share->getShareOwner() === $this->currentUser
999
			|| $share->getSharedBy() === $this->currentUser) {
1000
			return true;
1001
		}
1002
1003
		// If the share is shared with you, you can access it!
1004
		if ($share->getShareType() === Share::SHARE_TYPE_USER
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_USER has been deprecated: 17.0.0 - use IShare::TYPE_USER instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1004
		if ($share->getShareType() === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_USER

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1005
			&& $share->getSharedWith() === $this->currentUser) {
1006
			return true;
1007
		}
1008
1009
		// Have reshare rights on the shared file/folder ?
1010
		// Does the currentUser have access to the shared file?
1011
		$userFolder = $this->rootFolder->getUserFolder($this->currentUser);
1012
		$files = $userFolder->getById($share->getNodeId());
1013
		if (!empty($files) && $this->shareProviderResharingRights($this->currentUser, $share, $files[0])) {
1014
			return true;
1015
		}
1016
1017
		// If in the recipient group, you can see the share
1018
		if ($checkGroups && $share->getShareType() === Share::SHARE_TYPE_GROUP) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_GROUP has been deprecated: 17.0.0 - use IShare::TYPE_GROUP instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1018
		if ($checkGroups && $share->getShareType() === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_GROUP) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1019
			$sharedWith = $this->groupManager->get($share->getSharedWith());
1020
			$user = $this->userManager->get($this->currentUser);
1021
			if ($user !== null && $sharedWith !== null && $sharedWith->inGroup($user)) {
1022
				return true;
1023
			}
1024
		}
1025
1026
		if ($share->getShareType() === Share::SHARE_TYPE_CIRCLE) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_CIRCLE has been deprecated: 17.0.0 - use IShare::TYPE_CIRCLE instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1026
		if ($share->getShareType() === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_CIRCLE) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1027
			// TODO: have a sanity check like above?
1028
			return true;
1029
		}
1030
1031
		if ($share->getShareType() === Share::SHARE_TYPE_ROOM) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_ROOM has been deprecated: 17.0.0 - use IShare::TYPE_ROOM instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1031
		if ($share->getShareType() === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_ROOM) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1032
			try {
1033
				return $this->getRoomShareHelper()->canAccessShare($share, $this->currentUser);
1034
			} catch (QueryException $e) {
1035
				return false;
1036
			}
1037
		}
1038
1039
		return false;
1040
	}
1041
1042
	/**
1043
	 * Does the user have edit permission on the share
1044
	 *
1045
	 * @param \OCP\Share\IShare $share the share to check
1046
	 * @return boolean
1047
	 */
1048
	protected function canEditShare(\OCP\Share\IShare $share): bool {
1049
		// A file with permissions 0 can't be accessed by us. So Don't show it
1050
		if ($share->getPermissions() === 0) {
1051
			return false;
1052
		}
1053
1054
		// The owner of the file and the creator of the share
1055
		// can always edit the share
1056
		if ($share->getShareOwner() === $this->currentUser ||
1057
			$share->getSharedBy() === $this->currentUser
1058
		) {
1059
			return true;
1060
		}
1061
1062
		//! we do NOT support some kind of `admin` in groups.
1063
		//! You cannot edit shares shared to a group you're
1064
		//! a member of if you're not the share owner or the file owner!
1065
1066
		return false;
1067
	}
1068
1069
	/**
1070
	 * Does the user have delete permission on the share
1071
	 *
1072
	 * @param \OCP\Share\IShare $share the share to check
1073
	 * @return boolean
1074
	 */
1075
	protected function canDeleteShare(\OCP\Share\IShare $share): bool {
1076
		// A file with permissions 0 can't be accessed by us. So Don't show it
1077
		if ($share->getPermissions() === 0) {
1078
			return false;
1079
		}
1080
1081
		// if the user is the recipient, i can unshare
1082
		// the share with self
1083
		if ($share->getShareType() === Share::SHARE_TYPE_USER &&
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_USER has been deprecated: 17.0.0 - use IShare::TYPE_USER instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1083
		if ($share->getShareType() === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_USER &&

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1084
			$share->getSharedWith() === $this->currentUser
1085
		) {
1086
			return true;
1087
		}
1088
1089
		// The owner of the file and the creator of the share
1090
		// can always delete the share
1091
		if ($share->getShareOwner() === $this->currentUser ||
1092
			$share->getSharedBy() === $this->currentUser
1093
		) {
1094
			return true;
1095
		}
1096
1097
		return false;
1098
	}
1099
1100
	/**
1101
	 * Does the user have delete permission on the share
1102
	 * This differs from the canDeleteShare function as it only
1103
	 * remove the share for the current user. It does NOT
1104
	 * completely delete the share but only the mount point.
1105
	 * It can then be restored from the deleted shares section.
1106
	 *
1107
	 * @param \OCP\Share\IShare $share the share to check
1108
	 * @return boolean
1109
	 *
1110
	 * @suppress PhanUndeclaredClassMethod
1111
	 */
1112
	protected function canDeleteShareFromSelf(\OCP\Share\IShare $share): bool {
1113
		if ($share->getShareType() !== IShare::TYPE_GROUP &&
1114
			$share->getShareType() !== IShare::TYPE_ROOM
1115
		) {
1116
			return false;
1117
		}
1118
1119
		if ($share->getShareOwner() === $this->currentUser ||
1120
			$share->getSharedBy() === $this->currentUser
1121
		) {
1122
			// Delete the whole share, not just for self
1123
			return false;
1124
		}
1125
1126
		// If in the recipient group, you can delete the share from self
1127
		if ($share->getShareType() === Share::SHARE_TYPE_GROUP) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_GROUP has been deprecated: 17.0.0 - use IShare::TYPE_GROUP instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1127
		if ($share->getShareType() === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_GROUP) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1128
			$sharedWith = $this->groupManager->get($share->getSharedWith());
1129
			$user = $this->userManager->get($this->currentUser);
1130
			if ($user !== null && $sharedWith !== null && $sharedWith->inGroup($user)) {
1131
				return true;
1132
			}
1133
		}
1134
1135
		if ($share->getShareType() === Share::SHARE_TYPE_ROOM) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_ROOM has been deprecated: 17.0.0 - use IShare::TYPE_ROOM instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1135
		if ($share->getShareType() === /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_ROOM) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1136
			try {
1137
				return $this->getRoomShareHelper()->canAccessShare($share, $this->currentUser);
1138
			} catch (QueryException $e) {
1139
				return false;
1140
			}
1141
		}
1142
1143
		return false;
1144
	}
1145
1146
	/**
1147
	 * Make sure that the passed date is valid ISO 8601
1148
	 * So YYYY-MM-DD
1149
	 * If not throw an exception
1150
	 *
1151
	 * @param string $expireDate
1152
	 *
1153
	 * @throws \Exception
1154
	 * @return \DateTime
1155
	 */
1156
	private function parseDate(string $expireDate): \DateTime {
1157
		try {
1158
			$date = new \DateTime($expireDate);
1159
		} catch (\Exception $e) {
1160
			throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
1161
		}
1162
1163
		if ($date === false) {
0 ignored issues
show
introduced by
The condition $date === false is always false.
Loading history...
1164
			throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
1165
		}
1166
1167
		$date->setTime(0, 0, 0);
1168
1169
		return $date;
1170
	}
1171
1172
	/**
1173
	 * Since we have multiple providers but the OCS Share API v1 does
1174
	 * not support this we need to check all backends.
1175
	 *
1176
	 * @param string $id
1177
	 * @return \OCP\Share\IShare
1178
	 * @throws ShareNotFound
1179
	 */
1180
	private function getShareById(string $id): IShare {
1181
		$share = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $share is dead and can be removed.
Loading history...
1182
1183
		// First check if it is an internal share.
1184
		try {
1185
			$share = $this->shareManager->getShareById('ocinternal:' . $id, $this->currentUser);
1186
			return $share;
1187
		} catch (ShareNotFound $e) {
1188
			// Do nothing, just try the other share type
1189
		}
1190
1191
1192
		try {
1193
			if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_CIRCLE)) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_CIRCLE has been deprecated: 17.0.0 - use IShare::TYPE_CIRCLE instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1193
			if ($this->shareManager->shareProviderExists(/** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_CIRCLE)) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1194
				$share = $this->shareManager->getShareById('ocCircleShare:' . $id, $this->currentUser);
1195
				return $share;
1196
			}
1197
		} catch (ShareNotFound $e) {
1198
			// Do nothing, just try the other share type
1199
		}
1200
1201
		try {
1202
			if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_EMAIL has been deprecated: 17.0.0 - use IShare::TYPE_EMAIL instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1202
			if ($this->shareManager->shareProviderExists(/** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_EMAIL)) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1203
				$share = $this->shareManager->getShareById('ocMailShare:' . $id, $this->currentUser);
1204
				return $share;
1205
			}
1206
		} catch (ShareNotFound $e) {
1207
			// Do nothing, just try the other share type
1208
		}
1209
1210
		try {
1211
			$share = $this->shareManager->getShareById('ocRoomShare:' . $id, $this->currentUser);
1212
			return $share;
1213
		} catch (ShareNotFound $e) {
1214
			// Do nothing, just try the other share type
1215
		}
1216
1217
		if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
1218
			throw new ShareNotFound();
1219
		}
1220
		$share = $this->shareManager->getShareById('ocFederatedSharing:' . $id, $this->currentUser);
1221
1222
		return $share;
1223
	}
1224
1225
	/**
1226
	 * Lock a Node
1227
	 *
1228
	 * @param \OCP\Files\Node $node
1229
	 * @throws LockedException
1230
	 */
1231
	private function lock(\OCP\Files\Node $node) {
1232
		$node->lock(ILockingProvider::LOCK_SHARED);
1233
		$this->lockedNode = $node;
1234
	}
1235
1236
	/**
1237
	 * Cleanup the remaining locks
1238
	 * @throws @LockedException
1239
	 */
1240
	public function cleanup() {
1241
		if ($this->lockedNode !== null) {
1242
			$this->lockedNode->unlock(ILockingProvider::LOCK_SHARED);
1243
		}
1244
	}
1245
1246
	/**
1247
	 * Returns the helper of ShareAPIController for room shares.
1248
	 *
1249
	 * If the Talk application is not enabled or the helper is not available
1250
	 * a QueryException is thrown instead.
1251
	 *
1252
	 * @return \OCA\Talk\Share\Helper\ShareAPIController
0 ignored issues
show
Bug introduced by
The type OCA\Talk\Share\Helper\ShareAPIController was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
1253
	 * @throws QueryException
1254
	 */
1255
	private function getRoomShareHelper() {
1256
		if (!$this->appManager->isEnabledForUser('spreed')) {
1257
			throw new QueryException();
1258
		}
1259
1260
		return $this->serverContainer->query('\OCA\Talk\Share\Helper\ShareAPIController');
1261
	}
1262
1263
1264
	/**
1265
	 * Returns if we can find resharing rights in an IShare object for a specific user.
1266
	 *
1267
	 * @suppress PhanUndeclaredClassMethod
1268
	 *
1269
	 * @param string $userId
1270
	 * @param IShare $share
1271
	 * @param Node $node
1272
	 * @return bool
1273
	 * @throws NotFoundException
1274
	 * @throws \OCP\Files\InvalidPathException
1275
	 */
1276
	private function shareProviderResharingRights(string $userId, IShare $share, $node): bool {
1277
1278
		if ($share->getShareOwner() === $userId) {
1279
			return true;
1280
		}
1281
1282
		// we check that current user have parent resharing rights on the current file
1283
		if ($node !== null && ($node->getPermissions() & \OCP\Constants::PERMISSION_SHARE) !== 0) {
1284
			return true;
1285
		}
1286
1287
		if ((\OCP\Constants::PERMISSION_SHARE & $share->getPermissions()) === 0) {
1288
			return false;
1289
		}
1290
1291
		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() === $userId) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_USER has been deprecated: 17.0.0 - use IShare::TYPE_USER instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1291
		if ($share->getShareType() === /** @scrutinizer ignore-deprecated */ \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() === $userId) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1292
			return true;
1293
		}
1294
1295
		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && $this->groupManager->isInGroup($userId, $share->getSharedWith())) {
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_GROUP has been deprecated: 17.0.0 - use IShare::TYPE_GROUP instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1295
		if ($share->getShareType() === /** @scrutinizer ignore-deprecated */ \OCP\Share::SHARE_TYPE_GROUP && $this->groupManager->isInGroup($userId, $share->getSharedWith())) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1296
			return true;
1297
		}
1298
1299
		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE && \OC::$server->getAppManager()->isEnabledForUser('circles')
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_CIRCLE has been deprecated: 17.0.0 - use IShare::TYPE_CIRCLE instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1299
		if ($share->getShareType() === /** @scrutinizer ignore-deprecated */ \OCP\Share::SHARE_TYPE_CIRCLE && \OC::$server->getAppManager()->isEnabledForUser('circles')

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1300
			&& class_exists('\OCA\Circles\Api\v1\Circles')) {
1301
1302
			$hasCircleId = (substr($share->getSharedWith(), -1) === ']');
1303
			$shareWithStart = ($hasCircleId ? strrpos($share->getSharedWith(), '[') + 1 : 0);
1304
			$shareWithLength = ($hasCircleId ? -1 : strpos($share->getSharedWith(), ' '));
1305
			if (is_bool($shareWithLength)) {
0 ignored issues
show
introduced by
The condition is_bool($shareWithLength) is always false.
Loading history...
1306
				$shareWithLength = -1;
1307
			}
1308
			$sharedWith = substr($share->getSharedWith(), $shareWithStart, $shareWithLength);
1309
			try {
1310
				$member = \OCA\Circles\Api\v1\Circles::getMember($sharedWith, $userId, 1);
1311
				if ($member->getLevel() >= 4) {
1312
					return true;
1313
				}
1314
				return false;
1315
			} catch (QueryException $e) {
1316
				return false;
1317
			}
1318
		}
1319
1320
		return false;
1321
	}
1322
1323
	/**
1324
	 * Get all the shares for the current user
1325
	 *
1326
	 * @param Node|null $path
1327
	 * @param boolean $reshares
1328
	 * @return void
1329
	 */
1330
	private function getAllShares(?Node $path = null, bool $reshares = false) {
1331
		// Get all shares
1332
		$userShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_USER, $path, $reshares, -1, 0);
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_USER has been deprecated: 17.0.0 - use IShare::TYPE_USER instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1332
		$userShares = $this->shareManager->getSharesBy($this->currentUser, /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_USER, $path, $reshares, -1, 0);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1333
		$groupShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0);
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_GROUP has been deprecated: 17.0.0 - use IShare::TYPE_GROUP instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1333
		$groupShares = $this->shareManager->getSharesBy($this->currentUser, /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1334
		$linkShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0);
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_LINK has been deprecated: 17.0.0 - use IShare::TYPE_LINK instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1334
		$linkShares = $this->shareManager->getSharesBy($this->currentUser, /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1335
1336
		// EMAIL SHARES
1337
		$mailShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0);
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_EMAIL has been deprecated: 17.0.0 - use IShare::TYPE_EMAIL instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1337
		$mailShares = $this->shareManager->getSharesBy($this->currentUser, /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1338
1339
		// CIRCLE SHARES
1340
		$circleShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0);
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_CIRCLE has been deprecated: 17.0.0 - use IShare::TYPE_CIRCLE instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1340
		$circleShares = $this->shareManager->getSharesBy($this->currentUser, /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1341
1342
		// TALK SHARES
1343
		$roomShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_ROOM, $path, $reshares, -1, 0);
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_ROOM has been deprecated: 17.0.0 - use IShare::TYPE_ROOM instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1343
		$roomShares = $this->shareManager->getSharesBy($this->currentUser, /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_ROOM, $path, $reshares, -1, 0);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1344
1345
		// FEDERATION
1346
		if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
1347
			$federatedShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0);
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_REMOTE has been deprecated: 17.0.0 - use IShare::TYPE_REMOTE instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1347
			$federatedShares = $this->shareManager->getSharesBy($this->currentUser, /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1348
		} else {
1349
			$federatedShares = [];
1350
		}
1351
		if ($this->shareManager->outgoingServer2ServerGroupSharesAllowed()) {
1352
			$federatedGroupShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE_GROUP, $path, $reshares, -1, 0);
0 ignored issues
show
Deprecated Code introduced by
The constant OC\Share\Constants::SHARE_TYPE_REMOTE_GROUP has been deprecated: 17.0.0 - use IShare::REMOTE_GROUP instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1352
			$federatedGroupShares = $this->shareManager->getSharesBy($this->currentUser, /** @scrutinizer ignore-deprecated */ Share::SHARE_TYPE_REMOTE_GROUP, $path, $reshares, -1, 0);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1353
		} else {
1354
			$federatedGroupShares = [];
1355
		}
1356
1357
		return array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares, $roomShares, $federatedShares, $federatedGroupShares);
0 ignored issues
show
Bug Best Practice introduced by
The expression return array_merge($user... $federatedGroupShares) returns the type array which is incompatible with the documented return type void.
Loading history...
1358
	}
1359
1360
}
1361