Completed
Push — master ( 394184...29f9dc )
by Julius
21s
created

BoardService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 29

Duplication

Lines 29
Ratio 100 %

Importance

Changes 0
Metric Value
dl 29
loc 29
rs 9.456
c 0
b 0
f 0
cc 1
nc 1
nop 13

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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\Db\Acl;
29
use OCA\Deck\Db\AclMapper;
30
use OCA\Deck\Db\AssignedUsersMapper;
31
use OCA\Deck\Db\ChangeHelper;
32
use OCA\Deck\Db\IPermissionMapper;
33
use OCA\Deck\Db\Label;
34
use OCA\Deck\Db\StackMapper;
35
use OCA\Deck\NoPermissionException;
36
use OCA\Deck\Notification\NotificationHelper;
37
use OCP\AppFramework\Db\DoesNotExistException;
38
use OCP\IGroupManager;
39
use OCP\IL10N;
40
use OCA\Deck\Db\Board;
41
use OCA\Deck\Db\BoardMapper;
42
use OCA\Deck\Db\LabelMapper;
43
use OCP\IUserManager;
44
use OCA\Deck\BadRequestException;
45
46
47
class BoardService {
48
49
	private $boardMapper;
50
	private $stackMapper;
51
	private $labelMapper;
52
	private $aclMapper;
53
	private $l10n;
54
	private $permissionService;
55
	private $notificationHelper;
56
	private $assignedUsersMapper;
57
	private $userManager;
58
	private $groupManager;
59
	private $userId;
60
	private $activityManager;
61
	private $changeHelper;
62
63 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...
64
		BoardMapper $boardMapper,
65
		StackMapper $stackMapper,
66
		IL10N $l10n,
67
		LabelMapper $labelMapper,
68
		AclMapper $aclMapper,
69
		PermissionService $permissionService,
70
		NotificationHelper $notificationHelper,
71
		AssignedUsersMapper $assignedUsersMapper,
72
		IUserManager $userManager,
73
		IGroupManager $groupManager,
74
		ActivityManager $activityManager,
75
		ChangeHelper $changeHelper,
76
		$userId
77
	) {
78
		$this->boardMapper = $boardMapper;
79
		$this->stackMapper = $stackMapper;
80
		$this->labelMapper = $labelMapper;
81
		$this->aclMapper = $aclMapper;
82
		$this->l10n = $l10n;
83
		$this->permissionService = $permissionService;
84
		$this->notificationHelper = $notificationHelper;
85
		$this->assignedUsersMapper = $assignedUsersMapper;
86
		$this->userManager = $userManager;
87
		$this->groupManager = $groupManager;
88
		$this->activityManager = $activityManager;
89
		$this->changeHelper = $changeHelper;
90
		$this->userId = $userId;
91
	}
92
93
	/**
94
	 * @return array
95
	 */
96
	public function findAll($since = 0) {
97
		$userInfo = $this->getBoardPrerequisites();
98
		$userBoards = $this->boardMapper->findAllByUser($userInfo['user'], null, null, $since);
99
		$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...
100
		$complete = array_merge($userBoards, $groupBoards);
101
		$result = [];
102
		/** @var Board $item */
103
		foreach ($complete as &$item) {
104
			if (!array_key_exists($item->getId(), $result)) {
105
				$this->boardMapper->mapOwner($item);
106
				if ($item->getAcl() !== null) {
107
					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...
108
						$this->boardMapper->mapAcl($acl);
109
					}
110
				}
111
				$this->enrichWithStacks($item);
112
				$permissions = $this->permissionService->matchPermissions($item);
113
				$item->setPermissions([
114
					'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ],
115
					'PERMISSION_EDIT' => $permissions[Acl::PERMISSION_EDIT],
116
					'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE],
117
					'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE]
118
				]);
119
				$result[$item->getId()] = $item;
120
			}
121
		}
122
		return array_values($result);
123
	}
124
125
	/**
126
	 * @param $boardId
127
	 * @return Board
128
	 * @throws DoesNotExistException
129
	 * @throws \OCA\Deck\NoPermissionException
130
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
131
	 * @throws BadRequestException
132
	 */
133
	public function find($boardId) {
134
135
		if ( is_numeric($boardId) === false ) {
136
			throw new BadRequestException('board id must be a number');
137
		}
138
139
		$this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_READ);
140
		/** @var Board $board */
141
		$board = $this->boardMapper->find($boardId, true, true);
142
		$this->boardMapper->mapOwner($board);
143
		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...
144
			if ($acl !== null) {
145
				$this->boardMapper->mapAcl($acl);
146
			}
147
		}
148
		$permissions = $this->permissionService->matchPermissions($board);
149
		$board->setPermissions([
150
			'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ],
151
			'PERMISSION_EDIT' => $permissions[Acl::PERMISSION_EDIT],
152
			'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE],
153
			'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE]
154
		]);
155
		$boardUsers = $this->permissionService->findUsers($boardId);
156
		$board->setUsers(array_values($boardUsers));
157
		return $board;
158
	}
159
160
	/**
161
	 * @return array
162
	 */
163
	private function getBoardPrerequisites() {
164
		$groups = $this->groupManager->getUserGroupIds(
165
			$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...
166
		);
167
		return [
168
			'user' => $this->userId,
169
			'groups' => $groups
170
		];
171
	}
172
173
	/**
174
	 * @param $mapper
175
	 * @param $id
176
	 * @return bool
177
	 * @throws DoesNotExistException
178
	 * @throws \OCA\Deck\NoPermissionException
179
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
180
	 * @throws BadRequestException
181
	 */
182
	public function isArchived($mapper, $id) {
183
184
		if (is_numeric($id) === false)  {
185
			throw new BadRequestException('id must be a number');
186
		}
187
188
		try {
189
			$boardId = $id;
190
			if ($mapper instanceof IPermissionMapper) {
191
				$boardId = $mapper->findBoardId($id);
192
			}
193
			if ($boardId === null) {
194
				return false;
195
			}
196
		} catch (DoesNotExistException $exception) {
197
			return false;
198
		}
199
		$board = $this->find($boardId);
200
		return $board->getArchived();
201
	}
202
203
	/**
204
	 * @param $mapper
205
	 * @param $id
206
	 * @return bool
207
	 * @throws DoesNotExistException
208
	 * @throws \OCA\Deck\NoPermissionException
209
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
210
	 * @throws BadRequestException
211
	 */
212
	public function isDeleted($mapper, $id) {
213
214
		if ($mapper === false || $mapper === null) {
215
			throw new BadRequestException('mapper must be provided');
216
		}
217
218
		if (is_numeric($id) === false)  {
219
			throw new BadRequestException('id must be a number');
220
		}
221
222
		try {
223
			$boardId = $id;
224
			if ($mapper instanceof IPermissionMapper) {
225
				$boardId = $mapper->findBoardId($id);
226
			}
227
			if ($boardId === null) {
228
				return false;
229
			}
230
		} catch (DoesNotExistException $exception) {
231
			return false;
232
		}
233
		$board = $this->find($boardId);
234
		return $board->getDeletedAt() > 0;
235
	}
236
237
238
	/**
239
	 * @param $title
240
	 * @param $userId
241
	 * @param $color
242
	 * @return \OCP\AppFramework\Db\Entity
243
	 * @throws BadRequestException
244
	 */
245
	public function create($title, $userId, $color) {
246
247
		if ($title === false || $title === null) {
248
			throw new BadRequestException('title must be provided');
249
		}
250
251
		if ($userId === false || $userId === null) {
252
			throw new BadRequestException('userId must be provided');
253
		}
254
255
		if ($color === false || $color === null) {
256
			throw new BadRequestException('color must be provided');
257
		}
258
259
		if (!$this->permissionService->canCreate()) {
260
			throw new NoPermissionException('Creating boards has been disabled for your account.');
261
		}
262
263
		$board = new Board();
264
		$board->setTitle($title);
265
		$board->setOwner($userId);
266
		$board->setColor($color);
267
		$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...
268
269
		// create new labels
270
		$default_labels = [
271
			'31CC7C' => $this->l10n->t('Finished'),
272
			'317CCC' => $this->l10n->t('To review'),
273
			'FF7A66' => $this->l10n->t('Action needed'),
274
			'F1DB50' => $this->l10n->t('Later')
275
		];
276
		$labels = [];
277
		foreach ($default_labels as $labelColor => $labelTitle) {
278
			$label = new Label();
279
			$label->setColor($labelColor);
280
			$label->setTitle($labelTitle);
281
			$label->setBoardId($new_board->getId());
282
			$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...
283
		}
284
		$new_board->setLabels($labels);
285
		$this->boardMapper->mapOwner($new_board);
286
		$permissions = $this->permissionService->matchPermissions($new_board);
287
		$new_board->setPermissions([
288
			'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ],
289
			'PERMISSION_EDIT' => $permissions[Acl::PERMISSION_EDIT],
290
			'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE],
291
			'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE]
292
		]);
293
		$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $new_board, ActivityManager::SUBJECT_BOARD_CREATE);
294
		$this->changeHelper->boardChanged($new_board->getId());
295
		return $new_board;
296
297
	}
298
299
	/**
300
	 * @param $id
301
	 * @return Board
302
	 * @throws DoesNotExistException
303
	 * @throws \OCA\Deck\NoPermissionException
304
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
305
	 * @throws BadRequestException
306
	 */
307
	public function delete($id) {
308
309
		if (is_numeric($id) === false) {
310
			throw new BadRequestException('board id must be a number');
311
		}
312
313
		$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_READ);
314
		$board = $this->find($id);
315
		if ($board->getDeletedAt() > 0) {
316
			throw new BadRequestException('This board has already been deleted');
317
		}
318
		$board->setDeletedAt(time());
319
		$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...
320
		$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $board, ActivityManager::SUBJECT_BOARD_DELETE);
321
		$this->changeHelper->boardChanged($board->getId());
322
		return $board;
323
	}
324
325
	/**
326
	 * @param $id
327
	 * @return \OCP\AppFramework\Db\Entity
328
	 * @throws DoesNotExistException
329
	 * @throws \OCA\Deck\NoPermissionException
330
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
331
	 */
332 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...
333
334
		if (is_numeric($id) === false) {
335
			throw new BadRequestException('board id must be a number');
336
		}
337
338
		$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_READ);
339
		$board = $this->find($id);
340
		$board->setDeletedAt(0);
341
		$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...
342
		$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $board, ActivityManager::SUBJECT_BOARD_RESTORE);
343
		$this->changeHelper->boardChanged($board->getId());
344
		return $board;
345
	}
346
347
	/**
348
	 * @param $id
349
	 * @return \OCP\AppFramework\Db\Entity
350
	 * @throws DoesNotExistException
351
	 * @throws \OCA\Deck\NoPermissionException
352
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
353
	 * @throws BadRequestException
354
	 */
355 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...
356
		if (is_numeric($id) === false)  {
357
			throw new BadRequestException('id must be a number');
358
		}
359
360
		$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_READ);
361
		$board = $this->find($id);
362
		return $this->boardMapper->delete($board);
363
	}
364
365
	/**
366
	 * @param $id
367
	 * @param $title
368
	 * @param $color
369
	 * @param $archived
370
	 * @return \OCP\AppFramework\Db\Entity
371
	 * @throws DoesNotExistException
372
	 * @throws \OCA\Deck\NoPermissionException
373
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
374
	 * @throws BadRequestException
375
	 */
376
	public function update($id, $title, $color, $archived) {
377
378
		if (is_numeric($id) === false) {
379
			throw new BadRequestException('board id must be a number');
380
		}
381
382
		if ($title === false || $title === null) {
383
			throw new BadRequestException('color must be provided');
384
		}
385
386
		if ($color === false || $color === null) {
387
			throw new BadRequestException('color must be provided');
388
		}
389
390
		if ( is_bool($archived) === false ) {
391
			throw new BadRequestException('archived must be a boolean');
392
		}
393
394
		$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_MANAGE);
395
		$board = $this->find($id);
396
		$changes = new ChangeSet($board);
397
		$board->setTitle($title);
398
		$board->setColor($color);
399
		$board->setArchived($archived);
400
		$changes->setAfter($board);
401
		$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...
402
		$this->boardMapper->mapOwner($board);
403
		$this->activityManager->triggerUpdateEvents(ActivityManager::DECK_OBJECT_BOARD, $changes, ActivityManager::SUBJECT_BOARD_UPDATE);
404
		$this->changeHelper->boardChanged($board->getId());
405
		return $board;
406
	}
407
408
409
	/**
410
	 * @param $boardId
411
	 * @param $type
412
	 * @param $participant
413
	 * @param $edit
414
	 * @param $share
415
	 * @param $manage
416
	 * @return \OCP\AppFramework\Db\Entity
417
	 * @throws BadRequestException
418
	 * @throws \OCA\Deck\NoPermissionException
419
	 */
420
	public function addAcl($boardId, $type, $participant, $edit, $share, $manage) {
421
422
		if (is_numeric($boardId) === false) {
423
			throw new BadRequestException('board id must be a number');
424
		}
425
426
		if ($type === false || $type === null) {
427
			throw new BadRequestException('type must be provided');
428
		}
429
430
		if ($participant === false || $participant === null) {
431
			throw new BadRequestException('participant must be provided');
432
		}
433
434
		if ($edit === null) {
435
			throw new BadRequestException('edit must be provided');
436
		}
437
438
		if ($share === null) {
439
			throw new BadRequestException('share must be provided');
440
		}
441
442
		if ($manage === null) {
443
			throw new BadRequestException('manage must be provided');
444
		}
445
446
		$this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_SHARE);
447
		$acl = new Acl();
448
		$acl->setBoardId($boardId);
449
		$acl->setType($type);
450
		$acl->setParticipant($participant);
451
		$acl->setPermissionEdit($edit);
452
		$acl->setPermissionShare($share);
453
		$acl->setPermissionManage($manage);
454
455
		/* Notify users about the shared board */
456
		$this->notificationHelper->sendBoardShared($boardId, $acl);
457
458
		$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...
459
		$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $newAcl, ActivityManager::SUBJECT_BOARD_SHARE);
460
		$this->boardMapper->mapAcl($newAcl);
461
		$this->changeHelper->boardChanged($boardId);
462
		return $newAcl;
463
	}
464
465
	/**
466
	 * @param $id
467
	 * @param $edit
468
	 * @param $share
469
	 * @param $manage
470
	 * @return \OCP\AppFramework\Db\Entity
471
	 * @throws DoesNotExistException
472
	 * @throws \OCA\Deck\NoPermissionException
473
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
474
	 * @throws BadRequestException
475
	 */
476
	public function updateAcl($id, $edit, $share, $manage) {
477
478
		if (is_numeric($id) === false) {
479
			throw new BadRequestException('id must be a number');
480
		}
481
482
		if ($edit === null) {
483
			throw new BadRequestException('edit must be provided');
484
		}
485
486
		if ($share === null) {
487
			throw new BadRequestException('share must be provided');
488
		}
489
490
		if ($manage === null) {
491
			throw new BadRequestException('manage must be provided');
492
		}
493
494
		$this->permissionService->checkPermission($this->aclMapper, $id, Acl::PERMISSION_SHARE);
495
		/** @var Acl $acl */
496
		$acl = $this->aclMapper->find($id);
497
		$acl->setPermissionEdit($edit);
498
		$acl->setPermissionShare($share);
499
		$acl->setPermissionManage($manage);
500
		$this->boardMapper->mapAcl($acl);
501
		$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...
502
		$this->changeHelper->boardChanged($acl->getBoardId());
503
		return $board;
504
	}
505
506
	/**
507
	 * @param $id
508
	 * @return \OCP\AppFramework\Db\Entity
509
	 * @throws DoesNotExistException
510
	 * @throws \OCA\Deck\NoPermissionException
511
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
512
	 * @throws BadRequestException
513
	 */
514
	public function deleteAcl($id) {
515
516
		if (is_numeric($id) === false) {
517
			throw new BadRequestException('id must be a number');
518
		}
519
520
		$this->permissionService->checkPermission($this->aclMapper, $id, Acl::PERMISSION_SHARE);
521
		/** @var Acl $acl */
522
		$acl = $this->aclMapper->find($id);
523
		$this->boardMapper->mapAcl($acl);
524
		if ($acl->getType() === Acl::PERMISSION_TYPE_USER) {
525
			$assignements = $this->assignedUsersMapper->findByUserId($acl->getParticipant());
526
			foreach ($assignements as $assignement) {
527
				$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...
528
			}
529
		}
530
		$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $acl, ActivityManager::SUBJECT_BOARD_UNSHARE);
531
		$this->changeHelper->boardChanged($acl->getBoardId());
532
		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...
533
	}
534
535
	private function enrichWithStacks($board, $since = -1) {
536
		$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...
537
538
		if(\count($stacks) === 0) {
539
			return;
540
		}
541
542
		$board->setStacks($stacks);
543
	}
544
545
}
546