Passed
Push — master ( a842fd...195d63 )
by Julius
03:43 queued 51s
created

BoardService::deleteAcl()   B

Complexity

Conditions 6
Paths 9

Size

Total Lines 27

Duplication

Lines 6
Ratio 22.22 %

Importance

Changes 0
Metric Value
dl 6
loc 27
rs 8.8657
c 0
b 0
f 0
cc 6
nc 9
nop 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016 Julius Härtl <[email protected]>
4
 *
5
 * @author Julius Härtl <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Deck\Service;
25
26
use OCA\Deck\Activity\ActivityManager;
27
use OCA\Deck\Activity\ChangeSet;
28
use OCA\Deck\Collaboration\Resources\ResourceProvider;
29
use OCA\Deck\Db\Acl;
30
use OCA\Deck\Db\AclMapper;
31
use OCA\Deck\Db\AssignedUsersMapper;
32
use OCA\Deck\Db\ChangeHelper;
33
use OCA\Deck\Db\IPermissionMapper;
34
use OCA\Deck\Db\Label;
35
use OCA\Deck\Db\StackMapper;
36
use OCA\Deck\NoPermissionException;
37
use OCA\Deck\Notification\NotificationHelper;
38
use OCP\AppFramework\Db\DoesNotExistException;
39
use OCP\IGroupManager;
40
use OCP\IL10N;
41
use OCA\Deck\Db\Board;
42
use OCA\Deck\Db\BoardMapper;
43
use OCA\Deck\Db\LabelMapper;
44
use OCP\IUserManager;
45
use OCA\Deck\BadRequestException;
46
47
48
class BoardService {
49
50
	private $boardMapper;
51
	private $stackMapper;
52
	private $labelMapper;
53
	private $aclMapper;
54
	private $l10n;
55
	private $permissionService;
56
	private $notificationHelper;
57
	private $assignedUsersMapper;
58
	private $userManager;
59
	private $groupManager;
60
	private $userId;
61
	private $activityManager;
62
	private $changeHelper;
63
64 View Code Duplication
	public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
65
		BoardMapper $boardMapper,
66
		StackMapper $stackMapper,
67
		IL10N $l10n,
68
		LabelMapper $labelMapper,
69
		AclMapper $aclMapper,
70
		PermissionService $permissionService,
71
		NotificationHelper $notificationHelper,
72
		AssignedUsersMapper $assignedUsersMapper,
73
		IUserManager $userManager,
74
		IGroupManager $groupManager,
75
		ActivityManager $activityManager,
76
		ChangeHelper $changeHelper,
77
		$userId
78
	) {
79
		$this->boardMapper = $boardMapper;
80
		$this->stackMapper = $stackMapper;
81
		$this->labelMapper = $labelMapper;
82
		$this->aclMapper = $aclMapper;
83
		$this->l10n = $l10n;
84
		$this->permissionService = $permissionService;
85
		$this->notificationHelper = $notificationHelper;
86
		$this->assignedUsersMapper = $assignedUsersMapper;
87
		$this->userManager = $userManager;
88
		$this->groupManager = $groupManager;
89
		$this->activityManager = $activityManager;
90
		$this->changeHelper = $changeHelper;
91
		$this->userId = $userId;
92
	}
93
94
	/**
95
	 * @return array
96
	 */
97
	public function findAll($since = 0) {
98
		$userInfo = $this->getBoardPrerequisites();
99
		$userBoards = $this->boardMapper->findAllByUser($userInfo['user'], null, null, $since);
100
		$groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups'],null, null,  $since);
0 ignored issues
show
Unused Code introduced by
The call to BoardMapper::findAllByGroups() has too many arguments starting with $since.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
101
		$complete = array_merge($userBoards, $groupBoards);
102
		$result = [];
103
		/** @var Board $item */
104
		foreach ($complete as &$item) {
105
			if (!array_key_exists($item->getId(), $result)) {
106
				$this->boardMapper->mapOwner($item);
107
				if ($item->getAcl() !== null) {
108
					foreach ($item->getAcl() as &$acl) {
0 ignored issues
show
Bug introduced by
The expression $item->getAcl() cannot be used as a reference.

Let?s assume that you have the following foreach statement:

foreach ($array as &$itemValue) { }

$itemValue is assigned by reference. This is possible because the expression (in the example $array) can be used as a reference target.

However, if we were to replace $array with something different like the result of a function call as in

foreach (getArray() as &$itemValue) { }

then assigning by reference is not possible anymore as there is no target that could be modified.

Available Fixes

1. Do not assign by reference
foreach (getArray() as $itemValue) { }
2. Assign to a local variable first
$array = getArray();
foreach ($array as &$itemValue) {}
3. Return a reference
function &getArray() { $array = array(); return $array; }

foreach (getArray() as &$itemValue) { }
Loading history...
109
						$this->boardMapper->mapAcl($acl);
110
					}
111
				}
112
				$this->enrichWithStacks($item);
113
				$permissions = $this->permissionService->matchPermissions($item);
114
				$item->setPermissions([
115
					'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ],
116
					'PERMISSION_EDIT' => $permissions[Acl::PERMISSION_EDIT],
117
					'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE],
118
					'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE]
119
				]);
120
				$result[$item->getId()] = $item;
121
			}
122
		}
123
		return array_values($result);
124
	}
125
126
	/**
127
	 * @param $boardId
128
	 * @return Board
129
	 * @throws DoesNotExistException
130
	 * @throws \OCA\Deck\NoPermissionException
131
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
132
	 * @throws BadRequestException
133
	 */
134
	public function find($boardId) {
135
136
		if ( is_numeric($boardId) === false ) {
137
			throw new BadRequestException('board id must be a number');
138
		}
139
140
		$this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_READ);
141
		/** @var Board $board */
142
		$board = $this->boardMapper->find($boardId, true, true);
143
		$this->boardMapper->mapOwner($board);
144
		foreach ($board->getAcl() as &$acl) {
0 ignored issues
show
Bug introduced by
The expression $board->getAcl() cannot be used as a reference.

Let?s assume that you have the following foreach statement:

foreach ($array as &$itemValue) { }

$itemValue is assigned by reference. This is possible because the expression (in the example $array) can be used as a reference target.

However, if we were to replace $array with something different like the result of a function call as in

foreach (getArray() as &$itemValue) { }

then assigning by reference is not possible anymore as there is no target that could be modified.

Available Fixes

1. Do not assign by reference
foreach (getArray() as $itemValue) { }
2. Assign to a local variable first
$array = getArray();
foreach ($array as &$itemValue) {}
3. Return a reference
function &getArray() { $array = array(); return $array; }

foreach (getArray() as &$itemValue) { }
Loading history...
145
			if ($acl !== null) {
146
				$this->boardMapper->mapAcl($acl);
147
			}
148
		}
149
		$permissions = $this->permissionService->matchPermissions($board);
150
		$board->setPermissions([
151
			'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ],
152
			'PERMISSION_EDIT' => $permissions[Acl::PERMISSION_EDIT],
153
			'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE],
154
			'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE]
155
		]);
156
		$boardUsers = $this->permissionService->findUsers($boardId);
157
		$board->setUsers(array_values($boardUsers));
158
		return $board;
159
	}
160
161
	/**
162
	 * @return array
163
	 */
164
	private function getBoardPrerequisites() {
165
		$groups = $this->groupManager->getUserGroupIds(
166
			$this->userManager->get($this->userId)
0 ignored issues
show
Bug introduced by
It seems like $this->userManager->get($this->userId) can be null; however, getUserGroupIds() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
167
		);
168
		return [
169
			'user' => $this->userId,
170
			'groups' => $groups
171
		];
172
	}
173
174
	/**
175
	 * @param $mapper
176
	 * @param $id
177
	 * @return bool
178
	 * @throws DoesNotExistException
179
	 * @throws \OCA\Deck\NoPermissionException
180
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
181
	 * @throws BadRequestException
182
	 */
183
	public function isArchived($mapper, $id) {
184
185
		if (is_numeric($id) === false)  {
186
			throw new BadRequestException('id must be a number');
187
		}
188
189
		try {
190
			$boardId = $id;
191
			if ($mapper instanceof IPermissionMapper) {
192
				$boardId = $mapper->findBoardId($id);
193
			}
194
			if ($boardId === null) {
195
				return false;
196
			}
197
		} catch (DoesNotExistException $exception) {
198
			return false;
199
		}
200
		$board = $this->find($boardId);
201
		return $board->getArchived();
202
	}
203
204
	/**
205
	 * @param $mapper
206
	 * @param $id
207
	 * @return bool
208
	 * @throws DoesNotExistException
209
	 * @throws \OCA\Deck\NoPermissionException
210
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
211
	 * @throws BadRequestException
212
	 */
213
	public function isDeleted($mapper, $id) {
214
215
		if ($mapper === false || $mapper === null) {
216
			throw new BadRequestException('mapper must be provided');
217
		}
218
219
		if (is_numeric($id) === false)  {
220
			throw new BadRequestException('id must be a number');
221
		}
222
223
		try {
224
			$boardId = $id;
225
			if ($mapper instanceof IPermissionMapper) {
226
				$boardId = $mapper->findBoardId($id);
227
			}
228
			if ($boardId === null) {
229
				return false;
230
			}
231
		} catch (DoesNotExistException $exception) {
232
			return false;
233
		}
234
		$board = $this->find($boardId);
235
		return $board->getDeletedAt() > 0;
236
	}
237
238
239
	/**
240
	 * @param $title
241
	 * @param $userId
242
	 * @param $color
243
	 * @return \OCP\AppFramework\Db\Entity
244
	 * @throws BadRequestException
245
	 */
246
	public function create($title, $userId, $color) {
247
248
		if ($title === false || $title === null) {
249
			throw new BadRequestException('title must be provided');
250
		}
251
252
		if ($userId === false || $userId === null) {
253
			throw new BadRequestException('userId must be provided');
254
		}
255
256
		if ($color === false || $color === null) {
257
			throw new BadRequestException('color must be provided');
258
		}
259
260
		if (!$this->permissionService->canCreate()) {
261
			throw new NoPermissionException('Creating boards has been disabled for your account.');
262
		}
263
264
		$board = new Board();
265
		$board->setTitle($title);
266
		$board->setOwner($userId);
267
		$board->setColor($color);
268
		$new_board = $this->boardMapper->insert($board);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::insert() has been deprecated with message: 14.0.0 Move over to QBMapper

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
269
270
		// create new labels
271
		$default_labels = [
272
			'31CC7C' => $this->l10n->t('Finished'),
273
			'317CCC' => $this->l10n->t('To review'),
274
			'FF7A66' => $this->l10n->t('Action needed'),
275
			'F1DB50' => $this->l10n->t('Later')
276
		];
277
		$labels = [];
278
		foreach ($default_labels as $labelColor => $labelTitle) {
279
			$label = new Label();
280
			$label->setColor($labelColor);
281
			$label->setTitle($labelTitle);
282
			$label->setBoardId($new_board->getId());
283
			$labels[] = $this->labelMapper->insert($label);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::insert() has been deprecated with message: 14.0.0 Move over to QBMapper

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
284
		}
285
		$new_board->setLabels($labels);
286
		$this->boardMapper->mapOwner($new_board);
287
		$permissions = $this->permissionService->matchPermissions($new_board);
288
		$new_board->setPermissions([
289
			'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ],
290
			'PERMISSION_EDIT' => $permissions[Acl::PERMISSION_EDIT],
291
			'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE],
292
			'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE]
293
		]);
294
		$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $new_board, ActivityManager::SUBJECT_BOARD_CREATE);
295
		$this->changeHelper->boardChanged($new_board->getId());
296
		return $new_board;
297
298
	}
299
300
	/**
301
	 * @param $id
302
	 * @return Board
303
	 * @throws DoesNotExistException
304
	 * @throws \OCA\Deck\NoPermissionException
305
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
306
	 * @throws BadRequestException
307
	 */
308
	public function delete($id) {
309
310
		if (is_numeric($id) === false) {
311
			throw new BadRequestException('board id must be a number');
312
		}
313
314
		$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_READ);
315
		$board = $this->find($id);
316
		if ($board->getDeletedAt() > 0) {
317
			throw new BadRequestException('This board has already been deleted');
318
		}
319
		$board->setDeletedAt(time());
320
		$board = $this->boardMapper->update($board);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::update() has been deprecated with message: 14.0.0 Move over to QBMapper

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
321
		$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $board, ActivityManager::SUBJECT_BOARD_DELETE);
322
		$this->changeHelper->boardChanged($board->getId());
323
		return $board;
324
	}
325
326
	/**
327
	 * @param $id
328
	 * @return \OCP\AppFramework\Db\Entity
329
	 * @throws DoesNotExistException
330
	 * @throws \OCA\Deck\NoPermissionException
331
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
332
	 */
333 View Code Duplication
	public function deleteUndo($id) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
334
335
		if (is_numeric($id) === false) {
336
			throw new BadRequestException('board id must be a number');
337
		}
338
339
		$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_READ);
340
		$board = $this->find($id);
341
		$board->setDeletedAt(0);
342
		$board = $this->boardMapper->update($board);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::update() has been deprecated with message: 14.0.0 Move over to QBMapper

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
343
		$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $board, ActivityManager::SUBJECT_BOARD_RESTORE);
344
		$this->changeHelper->boardChanged($board->getId());
345
		return $board;
346
	}
347
348
	/**
349
	 * @param $id
350
	 * @return \OCP\AppFramework\Db\Entity
351
	 * @throws DoesNotExistException
352
	 * @throws \OCA\Deck\NoPermissionException
353
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
354
	 * @throws BadRequestException
355
	 */
356 View Code Duplication
	public function deleteForce($id) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
357
		if (is_numeric($id) === false)  {
358
			throw new BadRequestException('id must be a number');
359
		}
360
361
		$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_READ);
362
		$board = $this->find($id);
363
		return $this->boardMapper->delete($board);
364
	}
365
366
	/**
367
	 * @param $id
368
	 * @param $title
369
	 * @param $color
370
	 * @param $archived
371
	 * @return \OCP\AppFramework\Db\Entity
372
	 * @throws DoesNotExistException
373
	 * @throws \OCA\Deck\NoPermissionException
374
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
375
	 * @throws BadRequestException
376
	 */
377
	public function update($id, $title, $color, $archived) {
378
379
		if (is_numeric($id) === false) {
380
			throw new BadRequestException('board id must be a number');
381
		}
382
383
		if ($title === false || $title === null) {
384
			throw new BadRequestException('color must be provided');
385
		}
386
387
		if ($color === false || $color === null) {
388
			throw new BadRequestException('color must be provided');
389
		}
390
391
		if ( is_bool($archived) === false ) {
392
			throw new BadRequestException('archived must be a boolean');
393
		}
394
395
		$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_MANAGE);
396
		$board = $this->find($id);
397
		$changes = new ChangeSet($board);
398
		$board->setTitle($title);
399
		$board->setColor($color);
400
		$board->setArchived($archived);
401
		$changes->setAfter($board);
402
		$this->boardMapper->update($board); // operate on clone so we can check for updated fields
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::update() has been deprecated with message: 14.0.0 Move over to QBMapper

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
403
		$this->boardMapper->mapOwner($board);
404
		$this->activityManager->triggerUpdateEvents(ActivityManager::DECK_OBJECT_BOARD, $changes, ActivityManager::SUBJECT_BOARD_UPDATE);
405
		$this->changeHelper->boardChanged($board->getId());
406
		return $board;
407
	}
408
409
410
	/**
411
	 * @param $boardId
412
	 * @param $type
413
	 * @param $participant
414
	 * @param $edit
415
	 * @param $share
416
	 * @param $manage
417
	 * @return \OCP\AppFramework\Db\Entity
418
	 * @throws BadRequestException
419
	 * @throws \OCA\Deck\NoPermissionException
420
	 */
421
	public function addAcl($boardId, $type, $participant, $edit, $share, $manage) {
422
423
		if (is_numeric($boardId) === false) {
424
			throw new BadRequestException('board id must be a number');
425
		}
426
427
		if ($type === false || $type === null) {
428
			throw new BadRequestException('type must be provided');
429
		}
430
431
		if ($participant === false || $participant === null) {
432
			throw new BadRequestException('participant must be provided');
433
		}
434
435
		if ($edit === null) {
436
			throw new BadRequestException('edit must be provided');
437
		}
438
439
		if ($share === null) {
440
			throw new BadRequestException('share must be provided');
441
		}
442
443
		if ($manage === null) {
444
			throw new BadRequestException('manage must be provided');
445
		}
446
447
		$this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_SHARE);
448
		$acl = new Acl();
449
		$acl->setBoardId($boardId);
450
		$acl->setType($type);
451
		$acl->setParticipant($participant);
452
		$acl->setPermissionEdit($edit);
453
		$acl->setPermissionShare($share);
454
		$acl->setPermissionManage($manage);
455
456
		/* Notify users about the shared board */
457
		$this->notificationHelper->sendBoardShared($boardId, $acl);
458
459
		$newAcl = $this->aclMapper->insert($acl);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::insert() has been deprecated with message: 14.0.0 Move over to QBMapper

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
460
		$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $newAcl, ActivityManager::SUBJECT_BOARD_SHARE);
461
		$this->boardMapper->mapAcl($newAcl);
462
		$this->changeHelper->boardChanged($boardId);
463
		$version = \OC_Util::getVersion()[0];
464 View Code Duplication
		if ($version >= 16) {
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...
465
			try {
466
				$resourceProvider = \OC::$server->query(\OCA\Deck\Collaboration\Resources\ResourceProvider::class);
467
				$resourceProvider->invalidateAccessCache($boardId);
468
			} catch (\Exception $e) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
469
		}
470
		return $newAcl;
471
	}
472
473
	/**
474
	 * @param $id
475
	 * @param $edit
476
	 * @param $share
477
	 * @param $manage
478
	 * @return \OCP\AppFramework\Db\Entity
479
	 * @throws DoesNotExistException
480
	 * @throws \OCA\Deck\NoPermissionException
481
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
482
	 * @throws BadRequestException
483
	 */
484
	public function updateAcl($id, $edit, $share, $manage) {
485
486
		if (is_numeric($id) === false) {
487
			throw new BadRequestException('id must be a number');
488
		}
489
490
		if ($edit === null) {
491
			throw new BadRequestException('edit must be provided');
492
		}
493
494
		if ($share === null) {
495
			throw new BadRequestException('share must be provided');
496
		}
497
498
		if ($manage === null) {
499
			throw new BadRequestException('manage must be provided');
500
		}
501
502
		$this->permissionService->checkPermission($this->aclMapper, $id, Acl::PERMISSION_SHARE);
503
		/** @var Acl $acl */
504
		$acl = $this->aclMapper->find($id);
505
		$acl->setPermissionEdit($edit);
506
		$acl->setPermissionShare($share);
507
		$acl->setPermissionManage($manage);
508
		$this->boardMapper->mapAcl($acl);
509
		$board = $this->aclMapper->update($acl);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::update() has been deprecated with message: 14.0.0 Move over to QBMapper

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
510
		$this->changeHelper->boardChanged($acl->getBoardId());
511
		return $board;
512
	}
513
514
	/**
515
	 * @param $id
516
	 * @return \OCP\AppFramework\Db\Entity
517
	 * @throws DoesNotExistException
518
	 * @throws \OCA\Deck\NoPermissionException
519
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
520
	 * @throws BadRequestException
521
	 */
522
	public function deleteAcl($id) {
523
524
		if (is_numeric($id) === false) {
525
			throw new BadRequestException('id must be a number');
526
		}
527
528
		$this->permissionService->checkPermission($this->aclMapper, $id, Acl::PERMISSION_SHARE);
529
		/** @var Acl $acl */
530
		$acl = $this->aclMapper->find($id);
531
		$this->boardMapper->mapAcl($acl);
532
		if ($acl->getType() === Acl::PERMISSION_TYPE_USER) {
533
			$assignements = $this->assignedUsersMapper->findByUserId($acl->getParticipant());
534
			foreach ($assignements as $assignement) {
535
				$this->assignedUsersMapper->delete($assignement);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::delete() has been deprecated with message: 14.0.0 Move over to QBMapper

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
536
			}
537
		}
538
		$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $acl, ActivityManager::SUBJECT_BOARD_UNSHARE);
539
		$this->changeHelper->boardChanged($acl->getBoardId());
540
		$version = \OC_Util::getVersion()[0];
541 View Code Duplication
		if ($version >= 16) {
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...
542
			try {
543
				$resourceProvider = \OC::$server->query(\OCA\Deck\Collaboration\Resources\ResourceProvider::class);
544
				$resourceProvider->invalidateAccessCache($acl->getBoardId());
545
			} catch (\Exception $e) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
546
		}
547
		return $this->aclMapper->delete($acl);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::delete() has been deprecated with message: 14.0.0 Move over to QBMapper

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
548
	}
549
550
	private function enrichWithStacks($board, $since = -1) {
551
		$stacks = $this->stackMapper->findAll($board->getId(), null, null, $since);
0 ignored issues
show
Unused Code introduced by
The call to StackMapper::findAll() has too many arguments starting with $since.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
552
553
		if(\count($stacks) === 0) {
554
			return;
555
		}
556
557
		$board->setStacks($stacks);
558
	}
559
560
}
561