Completed
Push — master ( 3d31b2...c9ad65 )
by Sander
8s
created

ShareController   C

Complexity

Total Complexity 61

Size/Duplication

Total Lines 497
Duplicated Lines 0.6 %

Coupling/Cohesion

Components 1
Dependencies 12

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 61
lcom 1
cbo 12
dl 3
loc 497
ccs 0
cts 258
cp 0
rs 6.018
c 1
b 0
f 0

18 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 26 1
B unshareCredentialFromUser() 0 28 5
A search() 0 4 1
A getVaultsByUser() 0 14 2
B savePendingRequest() 0 28 2
A getPendingRequests() 0 15 3
A getRevisions() 0 7 2
A isSharingEnabled() 3 5 3
B createPublicShare() 0 34 4
C applyIntermediateShare() 0 67 8
A searchUsers() 0 15 4
A unshareCredential() 0 18 3
A getVaultItems() 0 9 2
B deleteShareRequest() 0 28 2
B getPublicCredentialData() 0 26 6
A getItemAcl() 0 18 4
A getFile() 0 14 4
B updateSharedCredentialACL() 0 22 5

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like ShareController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ShareController, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * Nextcloud - passman
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Sander Brand <[email protected]>
9
 * @copyright Sander Brand 2016
10
 */
11
12
namespace OCA\Passman\Controller;
13
14
use OCA\Passman\Db\SharingACL;
15
use OCA\Passman\Db\Vault;
16
use OCA\Passman\Service\CredentialService;
17
use OCA\Passman\Service\FileService;
18
use OCA\Passman\Service\NotificationService;
19
use OCA\Passman\Service\ShareService;
20
use OCA\Passman\Utility\NotFoundJSONResponse;
21
use OCA\Passman\Utility\Utils;
22
use OCP\AppFramework\Db\DoesNotExistException;
23
use OCP\AppFramework\Http\NotFoundResponse;
24
use OCP\IConfig;
25
use OCP\IRequest;
26
use OCP\AppFramework\Http\JSONResponse;
27
use OCP\AppFramework\ApiController;
28
29
use OCP\IGroupManager;
30
use OCP\IUserManager;
31
32
use OCA\Passman\Service\VaultService;
33
use OCA\Passman\Service\ActivityService;
34
use OCA\Passman\Activity;
35
36
37
class ShareController extends ApiController {
38
	private $userId;
39
	private $activityService;
40
	private $groupManager;
41
	private $userManager;
42
	private $vaultService;
43
	private $shareService;
44
	private $credentialService;
45
	private $notificationService;
46
	private $fileService;
47
	private $config;
48
49
	private $limit = 50;
50
	private $offset = 0;
51
52
	public function __construct($AppName,
53
								IRequest $request,
54
								$UserId,
55
								IGroupManager $groupManager,
56
								IUserManager $userManager,
57
								ActivityService $activityService,
58
								VaultService $vaultService,
59
								ShareService $shareService,
60
								CredentialService $credentialService,
61
								NotificationService $notificationService,
62
								FileService $fileService,
63
								IConfig $config
64
	) {
65
		parent::__construct($AppName, $request);
66
67
		$this->userId = $UserId;
68
		$this->userManager = $userManager;
69
		$this->groupManager = $groupManager;
70
		$this->activityService = $activityService;
71
		$this->vaultService = $vaultService;
72
		$this->shareService = $shareService;
73
		$this->credentialService = $credentialService;
74
		$this->notificationService = $notificationService;
75
		$this->fileService = $fileService;
76
		$this->config = $config;
77
	}
78
79
	private function isSharingEnabled() {
80 View Code Duplication
		if ($this->config->getAppValue('passman', 'link_sharing_enabled', 1) === 0 || $this->config->getAppValue('passman', 'link_sharing_enabled', 1) === '0') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
81
			return new JSONResponse(array());
82
		}
83
	}
84
85
	/**
86
	 * @param $item_id
87
	 * @param $item_guid
88
	 * @param $permissions
89
	 * @param $expire_timestamp
90
	 * @NoAdminRequired
91
	 * @NoCSRFRequired
92
	 */
93
	public function createPublicShare($item_id, $item_guid, $permissions, $expire_timestamp, $expire_views) {
94
		$this->isSharingEnabled();
95
96
97
		try {
98
			$credential = $this->credentialService->getCredentialByGUID($item_guid);
99
		} catch (DoesNotExistException $exception) {
0 ignored issues
show
Bug introduced by
The class OCP\AppFramework\Db\DoesNotExistException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
100
			return new NotFoundResponse();
101
		}
102
103
		try {
104
			$acl = $this->shareService->getACL(null, $item_guid);
105
		} catch (DoesNotExistException $exception) {
0 ignored issues
show
Bug introduced by
The class OCP\AppFramework\Db\DoesNotExistException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
106
			$acl = new SharingACL();
107
		}
108
109
110
		$acl->setItemId($item_id);
111
		$acl->setItemGuid($item_guid);
112
		$acl->setPermissions($permissions);
113
		$acl->setExpire($expire_timestamp);
114
		$acl->setExpireViews($expire_views);
115
		if (!$acl->getId()) {
116
			$this->shareService->createACLEntry($acl);
117
118
			$this->activityService->add(
119
				'item_shared_publicly', [$credential->getLabel()],
120
				'', array(),
121
				'', $this->userId->getUID(), Activity::TYPE_ITEM_SHARED);
122
		} else {
123
			$this->shareService->updateCredentialACL($acl);
124
		}
125
126
	}
127
128
	/**
129
	 * @NoAdminRequired
130
	 * @NoCSRFRequired
131
	 */
132
	public function applyIntermediateShare($item_id, $item_guid, $vaults, $permissions) {
133
		$this->isSharingEnabled();
134
		/**
135
		 * Assemble notification
136
		 */
137
		//@TODO add expire_time
138
		//@TODO add expire_views
139
		$credential = $this->credentialService->getCredentialById($item_id, $this->userId->getUID());
140
		$credential_owner = $credential->getUserId();
141
142
		$first_vault = $vaults[0];
143
		try {
144
			$shareRequests = $this->shareService->getPendingShareRequestsForCredential($item_guid, $first_vault['user_id']);
145
			if (count($shareRequests) > 0) {
146
				return new JSONResponse(array('error' => 'User got already pending requests'));
147
			}
148
		} catch (DoesNotExistException $exception) {
0 ignored issues
show
Bug introduced by
The class OCP\AppFramework\Db\DoesNotExistException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
149
			// no need to catch this
150
		}
151
152
		$acl = null;
153
		try {
154
			$acl = $this->shareService->getCredentialAclForUser($first_vault['user_id'], $item_guid);
155
		} catch (DoesNotExistException $exception) {
0 ignored issues
show
Bug introduced by
The class OCP\AppFramework\Db\DoesNotExistException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
156
			// no need to catch this
157
		}
158
159
		if ($acl) {
160
			return new JSONResponse(array('error' => 'User got already this credential'));
161
		}
162
163
		$result = $this->shareService->createBulkRequests($item_id, $item_guid, $vaults, $permissions, $credential_owner);
164
		if ($credential) {
165
			$processed_users = array();
166
			foreach ($result as $vault) {
167
				if (!in_array($vault->getTargetUserId(), $processed_users)) {
168
					$target_user = $vault->getTargetUserId();
169
					$notification = array(
170
						'from_user' => ucfirst($this->userId->getDisplayName()),
171
						'credential_label' => $credential->getLabel(),
172
						'credential_id' => $credential->getId(),
173
						'item_id' => $credential->getId(),
174
						'target_user' => $target_user,
175
						'req_id' => $vault->getId()
176
					);
177
					$this->notificationService->credentialSharedNotification(
178
						$notification
179
					);
180
					array_push($processed_users, $target_user);
181
182
					$this->activityService->add(
183
						'item_shared', [$credential->getLabel(), $target_user],
184
						'', array(),
185
						'', $this->userId->getUID(), Activity::TYPE_ITEM_SHARED);
186
187
188
					$this->activityService->add(
189
						'item_share_received', [$credential->getLabel(), $this->userId->getUID()],
190
						'', array(),
191
						'', $target_user, Activity::TYPE_ITEM_SHARED);
192
				}
193
			}
194
		}
195
196
197
		return new JSONResponse($result);
198
	}
199
200
	/**
201
	 * @NoAdminRequired
202
	 * @NoCSRFRequired
203
	 */
204
	public function searchUsers($search) {
205
		$users = array();
206
		$usersTmp = $this->userManager->searchDisplayName($search, $this->limit, $this->offset);
207
208
		foreach ($usersTmp as $user) {
209
			if ($this->userId->getUID() !== $user->getUID() && count($this->vaultService->getByUser($user->getUID())) >= 1) {
210
				$users[] = array(
211
					'text' => $user->getDisplayName(),
212
					'uid' => $user->getUID(),
213
					'type' => 'user'
214
				);
215
			}
216
		}
217
		return $users;
218
	}
219
220
221
	/**
222
	 * @NoAdminRequired
223
	 * @NoCSRFRequired
224
	 */
225
	public function unshareCredential($item_guid) {
226
		$this->isSharingEnabled();
227
		$acl_list = $this->shareService->getCredentialAclList($item_guid);
228
		$request_list = $this->shareService->getShareRequestsByGuid($item_guid);
229
		foreach ($acl_list as $ACL) {
230
			$this->shareService->deleteShareACL($ACL);
231
		}
232
		foreach ($request_list as $request) {
233
			$this->shareService->deleteShareRequest($request);
234
			$manager = \OC::$server->getNotificationManager();
235
			$notification = $manager->createNotification();
236
			$notification->setApp('passman')
237
				->setObject('passman_share_request', $request->getId())
238
				->setUser($request->getTargetUserId());
239
			$manager->markProcessed($notification);
240
		}
241
		return new JSONResponse(array('result' => true));
242
	}
243
244
245
	public function unshareCredentialFromUser($item_guid, $user_id) {
246
		$acl = null;
247
		$sr = null;
248
		try {
249
			$acl = $this->shareService->getCredentialAclForUser($user_id, $item_guid);
250
		} catch (DoesNotExistException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
Bug introduced by
The class OCP\AppFramework\Db\DoesNotExistException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
251
252
		}
253
		try {
254
			$sr = array_pop($this->shareService->getPendingShareRequestsForCredential($item_guid, $user_id));
0 ignored issues
show
Bug introduced by
$this->shareService->get...l($item_guid, $user_id) cannot be passed to array_pop() as the parameter $array expects a reference.
Loading history...
255
		} catch (DoesNotExistException $e) {
0 ignored issues
show
Bug introduced by
The class OCP\AppFramework\Db\DoesNotExistException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
256
			// no need to catch this
257
		}
258
259
		if ($sr) {
260
			$this->shareService->cleanItemRequestsForUser($sr);
261
			$manager = \OC::$server->getNotificationManager();
262
			$notification = $manager->createNotification();
263
			$notification->setApp('passman')
264
				->setObject('passman_share_request', $sr->getId())
265
				->setUser($user_id);
266
			$manager->markProcessed($notification);
267
		}
268
		if ($acl) {
269
			$this->shareService->deleteShareACL($acl);
270
		}
271
		return new JSONResponse(array('result' => true));
272
	}
273
274
	/**
275
	 * @NoAdminRequired
276
	 * @NoCSRFRequired
277
	 */
278
	public function search($search) {
279
		$user_search = $this->searchUsers($search);
280
		return new JSONResponse($user_search);
281
	}
282
283
284
	/**
285
	 * @NoAdminRequired
286
	 * @NoCSRFRequired
287
	 */
288
	public function getVaultsByUser($user_id) {
289
		$user_vaults = $this->vaultService->getByUser($user_id);
290
		$result = array();
291
		foreach ($user_vaults as $vault) {
292
			array_push($result,
293
				array(
294
					'vault_id' => $vault->getId(),
295
					'guid' => $vault->getGuid(),
296
					'public_sharing_key' => $vault->getPublicSharingKey(),
297
					'user_id' => $user_id,
298
				));
299
		}
300
		return new JSONResponse($result);
301
	}
302
303
	/**
304
	 * @NoAdminRequired
305
	 * @NoCSRFRequired
306
	 */
307
	public function savePendingRequest($item_guid, $target_vault_guid, $final_shared_key) {
308
		try {
309
			$sr = $this->shareService->getRequestByGuid($item_guid, $target_vault_guid);
310
		} catch (DoesNotExistException $ex) {
0 ignored issues
show
Bug introduced by
The class OCP\AppFramework\Db\DoesNotExistException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
311
			return new NotFoundResponse();
312
		}
313
314
		$manager = \OC::$server->getNotificationManager();
315
		$notification = $manager->createNotification();
316
		$notification->setApp('passman')
317
			->setObject('passman_share_request', $sr->getId())
318
			->setUser($this->userId->getUID());
319
		$manager->markProcessed($notification);
320
321
		$notification = array(
322
			'from_user' => ucfirst($this->userId->getDisplayName()),
323
			'credential_label' => $this->credentialService->getCredentialLabelById($sr->getItemId())->getLabel(),
324
			'target_user' => $sr->getFromUserId(),
325
			'req_id' => $sr->getId()
326
		);
327
328
		$this->notificationService->credentialAcceptedSharedNotification(
329
			$notification
330
		);
331
332
333
		$this->shareService->applyShare($item_guid, $target_vault_guid, $final_shared_key);
334
	}
335
336
	/**
337
	 * @NoAdminRequired
338
	 * @NoCSRFRequired
339
	 */
340
	public function getPendingRequests() {
341
		try {
342
			$requests = $this->shareService->getUserPendingRequests($this->userId->getUID());
343
			$results = array();
344
			foreach ($requests as $request) {
345
				$result = $request->jsonSerialize();
346
				$c = $this->credentialService->getCredentialLabelById($request->getItemId());
347
				$result['credential_label'] = $c->getLabel();
348
				array_push($results, $result);
349
			}
350
			return new JSONResponse($results);
351
		} catch (DoesNotExistException $ex) {
0 ignored issues
show
Bug introduced by
The class OCP\AppFramework\Db\DoesNotExistException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
352
			return new NotFoundResponse();
353
		}
354
	}
355
356
	/**
357
	 * @param $item_guid
358
	 * @return JSONResponse
359
	 * @NoAdminRequired
360
	 * @NoCSRFRequired
361
	 */
362
	public function getRevisions($item_guid) {
363
		try {
364
			return new JSONResponse($this->shareService->getItemHistory($this->userId, $item_guid));
365
		} catch (DoesNotExistException $ex) {
0 ignored issues
show
Bug introduced by
The class OCP\AppFramework\Db\DoesNotExistException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
366
			return new NotFoundJSONResponse();
367
		}
368
	}
369
370
	/**
371
	 * Obtains the list of credentials shared with this vault
372
	 *
373
	 * @NoAdminRequired
374
	 * @NoCSRFRequired
375
	 */
376
	public function getVaultItems($vault_guid) {
377
		$this->isSharingEnabled();
378
379
		try {
380
			return new JSONResponse($this->shareService->getSharedItems($this->userId->getUID(), $vault_guid));
381
		} catch (DoesNotExistException $ex) {
0 ignored issues
show
Bug introduced by
The class OCP\AppFramework\Db\DoesNotExistException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
382
			return new NotFoundResponse();
383
		}
384
	}
385
386
	/**
387
	 * @param $share_request_id
388
	 * @return JSONResponse
389
	 * @NoAdminRequired
390
	 * @NoCSRFRequired
391
	 */
392
	public function deleteShareRequest($share_request_id) {
393
		try {
394
395
			$sr = $this->shareService->getShareRequestById($share_request_id);
396
			$notification = array(
397
				'from_user' => ucfirst($this->userId->getDisplayName()),
398
				'credential_label' => $this->credentialService->getCredentialLabelById($sr->getItemId())->getLabel(),
399
				'target_user' => $sr->getFromUserId(),
400
				'req_id' => $sr->getId()
401
			);
402
			$this->notificationService->credentialDeclinedSharedNotification(
403
				$notification
404
			);
405
406
407
			$manager = \OC::$server->getNotificationManager();
408
			$notification = $manager->createNotification();
409
			$notification->setApp('passman')
410
				->setObject('passman_share_request', $share_request_id)
411
				->setUser($this->userId->getUID());
412
			$manager->markProcessed($notification);
413
414
			$this->shareService->cleanItemRequestsForUser($sr);
415
			return new JSONResponse(array('result' => true));
416
		} catch (DoesNotExistException $ex) {
0 ignored issues
show
Bug introduced by
The class OCP\AppFramework\Db\DoesNotExistException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
417
			return new NotFoundJSONResponse();
418
		}
419
	}
420
421
	/**
422
	 * @param $credential_guid
423
	 * @return JSONResponse
424
	 * @NoAdminRequired
425
	 * @NoCSRFRequired
426
	 * @PublicPage
427
	 */
428
	public function getPublicCredentialData($credential_guid) {
429
		$this->isSharingEnabled();
430
		//@TODO Check expire date
431
		$acl = $this->shareService->getACL(null, $credential_guid);
432
433
		if ($acl->getExpire() > 0 && Utils::getTime() > $acl->getExpire()) {
434
			return new NotFoundJSONResponse();
435
		}
436
437
		$views = $acl->getExpireViews();
438
		if ($views === 0) {
439
			return new NotFoundJSONResponse();
440
		} else if ($views !== -1) {
441
			$views--;
442
			$acl->setExpireViews($views);
443
			$this->shareService->updateCredentialACL($acl);
444
		}
445
446
447
		try {
448
			$credential = $this->shareService->getSharedItem(null, $credential_guid);
449
			return new JSONResponse($credential);
450
		} catch (DoesNotExistException $ex) {
0 ignored issues
show
Bug introduced by
The class OCP\AppFramework\Db\DoesNotExistException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
451
			return new NotFoundJSONResponse();
452
		}
453
	}
454
455
	/**
456
	 * @param $item_guid
457
	 * @return JSONResponse
458
	 * @NoAdminRequired
459
	 * @NoCSRFRequired
460
	 */
461
	public function getItemAcl($item_guid) {
462
		$acl = $this->shareService->getCredentialAclList($item_guid);
463
		$pending = $this->shareService->getCredentialPendingAclList($item_guid);
464
		try {
465
			$credential = $this->credentialService->getCredentialByGUID($item_guid);
466
			if ($credential->getUserId() === $this->userId->getUID()) {
467
				foreach ($pending as &$item) {
468
					$item = $item->asACLJson();
469
				}
470
				$acl = array_merge($acl, $pending);
471
				return new JSONResponse($acl);
472
			} else {
473
				return new NotFoundResponse();
474
			}
475
		} catch (DoesNotExistException $ex) {
0 ignored issues
show
Bug introduced by
The class OCP\AppFramework\Db\DoesNotExistException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
476
			return new JSONResponse(array());
477
		}
478
	}
479
480
	/**
481
	 * @param $credential_guid
482
	 * @param $file_guid
483
	 * @NoAdminRequired
484
	 * @PublicPage
485
	 * @return JSONResponse
486
	 * @return NotFoundResponse
487
	 */
488
	public function getFile($item_guid, $file_guid) {
489
		try {
490
			$credential = $this->credentialService->getCredentialByGUID($item_guid);
491
		} catch (DoesNotExistException $e) {
0 ignored issues
show
Bug introduced by
The class OCP\AppFramework\Db\DoesNotExistException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
492
			return new NotFoundJSONResponse();
493
		}
494
		$userId = ($this->userId) ? $this->userId->getUID() : null;
495
		$acl = $this->shareService->getACL($userId, $credential->getGuid());
496
		if (!$acl->hasPermission(SharingACL::FILES)) {
497
			return new NotFoundJSONResponse();
498
		} else {
499
			return $this->fileService->getFileByGuid($file_guid);
500
		}
501
	}
502
503
	/**
504
	 * @param $item_guid
505
	 * @param  $user_id
506
	 * @param $permission
507
	 * @return JSONResponse
508
	 * @NoAdminRequired
509
	 * @NoCSRFRequired
510
	 */
511
	public function updateSharedCredentialACL($item_guid, $user_id, $permission) {
512
		try {
513
			$credential = $this->credentialService->getCredentialByGUID($item_guid);
514
		} catch (DoesNotExistException $exception) {
0 ignored issues
show
Bug introduced by
The class OCP\AppFramework\Db\DoesNotExistException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
515
			return new NotFoundJSONResponse();
516
		}
517
		if ($this->userId->getUID() === $credential->getUserId()) {
518
			$acl = null;
519
			try {
520
				$acl = $this->shareService->getACL($user_id, $item_guid);
521
				$acl->setPermissions($permission);
522
				return $this->shareService->updateCredentialACL($acl);
523
			} catch (DoesNotExistException $exception) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
Bug introduced by
The class OCP\AppFramework\Db\DoesNotExistException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
524
525
			}
526
527
			if ($acl === null) {
528
				$this->shareService->updatePendingShareRequestsForCredential($item_guid, $user_id, $permission);
529
			}
530
531
		}
532
	}
533
}