This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * @copyright Copyright (c) 2016 Julius Härtl <[email protected]> |
||
4 | * |
||
5 | * @author Julius Härtl <[email protected]> |
||
6 | * @author Maxence Lange <[email protected]> |
||
7 | * |
||
8 | * @license GNU AGPL version 3 or any later version |
||
9 | * |
||
10 | * This program is free software: you can redistribute it and/or modify |
||
11 | * it under the terms of the GNU Affero General Public License as |
||
12 | * published by the Free Software Foundation, either version 3 of the |
||
13 | * License, or (at your option) any later version. |
||
14 | * |
||
15 | * This program is distributed in the hope that it will be useful, |
||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
18 | * GNU Affero General Public License for more details. |
||
19 | * |
||
20 | * You should have received a copy of the GNU Affero General Public License |
||
21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
22 | * |
||
23 | */ |
||
24 | |||
25 | namespace OCA\Deck\Service; |
||
26 | |||
27 | use OCA\Deck\Activity\ActivityManager; |
||
28 | use OCA\Deck\Activity\ChangeSet; |
||
29 | use OCA\Deck\Collaboration\Resources\ResourceProvider; |
||
30 | use OCA\Deck\Db\Acl; |
||
31 | use OCA\Deck\Db\AclMapper; |
||
32 | use OCA\Deck\Db\AssignedUsersMapper; |
||
33 | use OCA\Deck\Db\ChangeHelper; |
||
34 | use OCA\Deck\Db\IPermissionMapper; |
||
35 | use OCA\Deck\Db\Label; |
||
36 | use OCA\Deck\Db\Stack; |
||
37 | use OCA\Deck\Db\StackMapper; |
||
38 | use OCA\Deck\NoPermissionException; |
||
39 | use OCA\Deck\Notification\NotificationHelper; |
||
40 | use OCP\AppFramework\Db\DoesNotExistException; |
||
41 | use OCP\IGroupManager; |
||
42 | use OCP\IL10N; |
||
43 | use OCA\Deck\Db\Board; |
||
44 | use OCA\Deck\Db\BoardMapper; |
||
45 | use OCA\Deck\Db\LabelMapper; |
||
46 | use OCP\IUserManager; |
||
47 | use OCA\Deck\BadRequestException; |
||
48 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
||
49 | use Symfony\Component\EventDispatcher\GenericEvent; |
||
50 | |||
51 | |||
52 | class BoardService { |
||
53 | |||
54 | private $boardMapper; |
||
55 | private $stackMapper; |
||
56 | private $labelMapper; |
||
57 | private $aclMapper; |
||
58 | private $l10n; |
||
59 | private $permissionService; |
||
60 | private $notificationHelper; |
||
61 | private $assignedUsersMapper; |
||
62 | private $userManager; |
||
63 | private $groupManager; |
||
64 | private $userId; |
||
65 | private $activityManager; |
||
66 | /** @var EventDispatcherInterface */ |
||
67 | private $eventDispatcher; |
||
68 | private $changeHelper; |
||
69 | |||
70 | View Code Duplication | public function __construct( |
|
0 ignored issues
–
show
|
|||
71 | BoardMapper $boardMapper, |
||
72 | StackMapper $stackMapper, |
||
73 | IL10N $l10n, |
||
74 | LabelMapper $labelMapper, |
||
75 | AclMapper $aclMapper, |
||
76 | PermissionService $permissionService, |
||
77 | NotificationHelper $notificationHelper, |
||
78 | AssignedUsersMapper $assignedUsersMapper, |
||
79 | IUserManager $userManager, |
||
80 | IGroupManager $groupManager, |
||
81 | ActivityManager $activityManager, |
||
82 | EventDispatcherInterface $eventDispatcher, |
||
83 | ChangeHelper $changeHelper, |
||
84 | $userId |
||
85 | ) { |
||
86 | $this->boardMapper = $boardMapper; |
||
87 | $this->stackMapper = $stackMapper; |
||
88 | $this->labelMapper = $labelMapper; |
||
89 | $this->aclMapper = $aclMapper; |
||
90 | $this->l10n = $l10n; |
||
91 | $this->permissionService = $permissionService; |
||
92 | $this->notificationHelper = $notificationHelper; |
||
93 | $this->assignedUsersMapper = $assignedUsersMapper; |
||
94 | $this->userManager = $userManager; |
||
95 | $this->groupManager = $groupManager; |
||
96 | $this->activityManager = $activityManager; |
||
97 | $this->eventDispatcher = $eventDispatcher; |
||
98 | $this->changeHelper = $changeHelper; |
||
99 | $this->userId = $userId; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Set a different user than the current one, e.g. when no user is available in occ |
||
104 | * |
||
105 | * @param string $userId |
||
106 | */ |
||
107 | public function setUserId(string $userId): void { |
||
108 | $this->userId = $userId; |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * @return array |
||
113 | */ |
||
114 | public function findAll($since = -1, $details = null) { |
||
115 | $userInfo = $this->getBoardPrerequisites(); |
||
116 | $userBoards = $this->boardMapper->findAllByUser($userInfo['user'], null, null, $since); |
||
117 | $groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups'],null, null, $since); |
||
0 ignored issues
–
show
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 ![]() |
|||
118 | $circleBoards = $this->boardMapper->findAllByCircles($userInfo['user'], null, null, $since); |
||
0 ignored issues
–
show
The call to
BoardMapper::findAllByCircles() 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 ![]() |
|||
119 | $complete = array_merge($userBoards, $groupBoards, $circleBoards); |
||
120 | $result = []; |
||
121 | /** @var Board $item */ |
||
122 | foreach ($complete as &$item) { |
||
123 | if (!array_key_exists($item->getId(), $result)) { |
||
124 | $this->boardMapper->mapOwner($item); |
||
125 | if ($item->getAcl() !== null) { |
||
126 | foreach ($item->getAcl() as &$acl) { |
||
0 ignored issues
–
show
The expression
$item->getAcl() cannot be used as a reference.
Let?s assume that you have the following foreach ($array as &$itemValue) { }
However, if we were to replace foreach (getArray() as &$itemValue) { }
then assigning by reference is not possible anymore as there is no target that could be modified. Available Fixes1. Do not assign by referenceforeach (getArray() as $itemValue) { }
2. Assign to a local variable first$array = getArray();
foreach ($array as &$itemValue) {}
3. Return a referencefunction &getArray() { $array = array(); return $array; }
foreach (getArray() as &$itemValue) { }
![]() |
|||
127 | $this->boardMapper->mapAcl($acl); |
||
128 | } |
||
129 | } |
||
130 | if ($details !== null) { |
||
131 | $this->enrichWithStacks($item); |
||
132 | $this->enrichWithLabels($item); |
||
133 | $this->enrichWithUsers($item); |
||
134 | } |
||
135 | $permissions = $this->permissionService->matchPermissions($item); |
||
136 | $item->setPermissions([ |
||
137 | 'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ] ?? false, |
||
138 | 'PERMISSION_EDIT' => $permissions[Acl::PERMISSION_EDIT] ?? false, |
||
139 | 'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE] ?? false, |
||
140 | 'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE] ?? false |
||
141 | ]); |
||
142 | $result[$item->getId()] = $item; |
||
143 | } |
||
144 | } |
||
145 | return array_values($result); |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * @param $boardId |
||
150 | * @return Board |
||
151 | * @throws DoesNotExistException |
||
152 | * @throws \OCA\Deck\NoPermissionException |
||
153 | * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException |
||
154 | * @throws BadRequestException |
||
155 | */ |
||
156 | public function find($boardId) { |
||
157 | |||
158 | if ( is_numeric($boardId) === false ) { |
||
159 | throw new BadRequestException('board id must be a number'); |
||
160 | } |
||
161 | |||
162 | $this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_READ); |
||
163 | /** @var Board $board */ |
||
164 | $board = $this->boardMapper->find($boardId, true, true); |
||
165 | $this->boardMapper->mapOwner($board); |
||
166 | foreach ($board->getAcl() as &$acl) { |
||
0 ignored issues
–
show
The expression
$board->getAcl() cannot be used as a reference.
Let?s assume that you have the following foreach ($array as &$itemValue) { }
However, if we were to replace foreach (getArray() as &$itemValue) { }
then assigning by reference is not possible anymore as there is no target that could be modified. Available Fixes1. Do not assign by referenceforeach (getArray() as $itemValue) { }
2. Assign to a local variable first$array = getArray();
foreach ($array as &$itemValue) {}
3. Return a referencefunction &getArray() { $array = array(); return $array; }
foreach (getArray() as &$itemValue) { }
![]() |
|||
167 | if ($acl !== null) { |
||
168 | $this->boardMapper->mapAcl($acl); |
||
169 | } |
||
170 | } |
||
171 | $permissions = $this->permissionService->matchPermissions($board); |
||
172 | $board->setPermissions([ |
||
173 | 'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ] ?? false, |
||
174 | 'PERMISSION_EDIT' => $permissions[Acl::PERMISSION_EDIT] ?? false, |
||
175 | 'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE] ?? false, |
||
176 | 'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE] ?? false |
||
177 | ]); |
||
178 | $this->enrichWithUsers($board); |
||
179 | return $board; |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * @return array |
||
184 | */ |
||
185 | private function getBoardPrerequisites() { |
||
186 | $groups = $this->groupManager->getUserGroupIds( |
||
187 | $this->userManager->get($this->userId) |
||
0 ignored issues
–
show
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);
}
}
![]() |
|||
188 | ); |
||
189 | return [ |
||
190 | 'user' => $this->userId, |
||
191 | 'groups' => $groups |
||
192 | ]; |
||
193 | } |
||
194 | |||
195 | /** |
||
196 | * @param $mapper |
||
197 | * @param $id |
||
198 | * @return bool |
||
199 | * @throws DoesNotExistException |
||
200 | * @throws \OCA\Deck\NoPermissionException |
||
201 | * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException |
||
202 | * @throws BadRequestException |
||
203 | */ |
||
204 | public function isArchived($mapper, $id) { |
||
205 | |||
206 | if (is_numeric($id) === false) { |
||
207 | throw new BadRequestException('id must be a number'); |
||
208 | } |
||
209 | |||
210 | try { |
||
211 | $boardId = $id; |
||
212 | if ($mapper instanceof IPermissionMapper) { |
||
213 | $boardId = $mapper->findBoardId($id); |
||
214 | } |
||
215 | if ($boardId === null) { |
||
216 | return false; |
||
217 | } |
||
218 | } catch (DoesNotExistException $exception) { |
||
219 | return false; |
||
220 | } |
||
221 | $board = $this->find($boardId); |
||
222 | return $board->getArchived(); |
||
223 | } |
||
224 | |||
225 | /** |
||
226 | * @param $mapper |
||
227 | * @param $id |
||
228 | * @return bool |
||
229 | * @throws DoesNotExistException |
||
230 | * @throws \OCA\Deck\NoPermissionException |
||
231 | * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException |
||
232 | * @throws BadRequestException |
||
233 | */ |
||
234 | public function isDeleted($mapper, $id) { |
||
235 | |||
236 | if ($mapper === false || $mapper === null) { |
||
237 | throw new BadRequestException('mapper must be provided'); |
||
238 | } |
||
239 | |||
240 | if (is_numeric($id) === false) { |
||
241 | throw new BadRequestException('id must be a number'); |
||
242 | } |
||
243 | |||
244 | try { |
||
245 | $boardId = $id; |
||
246 | if ($mapper instanceof IPermissionMapper) { |
||
247 | $boardId = $mapper->findBoardId($id); |
||
248 | } |
||
249 | if ($boardId === null) { |
||
250 | return false; |
||
251 | } |
||
252 | } catch (DoesNotExistException $exception) { |
||
253 | return false; |
||
254 | } |
||
255 | $board = $this->find($boardId); |
||
256 | return $board->getDeletedAt() > 0; |
||
257 | } |
||
258 | |||
259 | |||
260 | /** |
||
261 | * @param $title |
||
262 | * @param $userId |
||
263 | * @param $color |
||
264 | * @return \OCP\AppFramework\Db\Entity |
||
265 | * @throws BadRequestException |
||
266 | */ |
||
267 | public function create($title, $userId, $color) { |
||
268 | |||
269 | if ($title === false || $title === null) { |
||
270 | throw new BadRequestException('title must be provided'); |
||
271 | } |
||
272 | |||
273 | if ($userId === false || $userId === null) { |
||
274 | throw new BadRequestException('userId must be provided'); |
||
275 | } |
||
276 | |||
277 | if ($color === false || $color === null) { |
||
278 | throw new BadRequestException('color must be provided'); |
||
279 | } |
||
280 | |||
281 | if (!$this->permissionService->canCreate()) { |
||
282 | throw new NoPermissionException('Creating boards has been disabled for your account.'); |
||
283 | } |
||
284 | |||
285 | $board = new Board(); |
||
286 | $board->setTitle($title); |
||
287 | $board->setOwner($userId); |
||
288 | $board->setColor($color); |
||
289 | $new_board = $this->boardMapper->insert($board); |
||
0 ignored issues
–
show
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. ![]() |
|||
290 | |||
291 | // create new labels |
||
292 | $default_labels = [ |
||
293 | '31CC7C' => $this->l10n->t('Finished'), |
||
294 | '317CCC' => $this->l10n->t('To review'), |
||
295 | 'FF7A66' => $this->l10n->t('Action needed'), |
||
296 | 'F1DB50' => $this->l10n->t('Later') |
||
297 | ]; |
||
298 | $labels = []; |
||
299 | foreach ($default_labels as $labelColor => $labelTitle) { |
||
300 | $label = new Label(); |
||
301 | $label->setColor($labelColor); |
||
302 | $label->setTitle($labelTitle); |
||
303 | $label->setBoardId($new_board->getId()); |
||
304 | $labels[] = $this->labelMapper->insert($label); |
||
305 | } |
||
306 | $new_board->setLabels($labels); |
||
307 | $this->boardMapper->mapOwner($new_board); |
||
308 | $permissions = $this->permissionService->matchPermissions($new_board); |
||
309 | $new_board->setPermissions([ |
||
310 | 'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ] ?? false, |
||
311 | 'PERMISSION_EDIT' => $permissions[Acl::PERMISSION_EDIT] ?? false, |
||
312 | 'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE] ?? false, |
||
313 | 'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE] ?? false |
||
314 | ]); |
||
315 | $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $new_board, ActivityManager::SUBJECT_BOARD_CREATE); |
||
316 | $this->changeHelper->boardChanged($new_board->getId()); |
||
317 | |||
318 | $this->eventDispatcher->dispatch( |
||
319 | '\OCA\Deck\Board::onCreate', |
||
320 | new GenericEvent( |
||
321 | null, ['id' => $new_board->getId(), 'userId' => $userId, 'board' => $new_board] |
||
322 | ) |
||
323 | ); |
||
324 | |||
325 | return $new_board; |
||
326 | } |
||
327 | |||
328 | /** |
||
329 | * @param $id |
||
330 | * @return Board |
||
331 | * @throws DoesNotExistException |
||
332 | * @throws \OCA\Deck\NoPermissionException |
||
333 | * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException |
||
334 | * @throws BadRequestException |
||
335 | */ |
||
336 | public function delete($id) { |
||
337 | |||
338 | if (is_numeric($id) === false) { |
||
339 | throw new BadRequestException('board id must be a number'); |
||
340 | } |
||
341 | |||
342 | $this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_READ); |
||
343 | $board = $this->find($id); |
||
344 | if ($board->getDeletedAt() > 0) { |
||
345 | throw new BadRequestException('This board has already been deleted'); |
||
346 | } |
||
347 | $board->setDeletedAt(time()); |
||
348 | $board = $this->boardMapper->update($board); |
||
0 ignored issues
–
show
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. ![]() |
|||
349 | $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $board, ActivityManager::SUBJECT_BOARD_DELETE); |
||
350 | $this->changeHelper->boardChanged($board->getId()); |
||
351 | |||
352 | $this->eventDispatcher->dispatch( |
||
353 | '\OCA\Deck\Board::onDelete', new GenericEvent(null, ['id' => $id]) |
||
354 | ); |
||
355 | |||
356 | return $board; |
||
357 | } |
||
358 | |||
359 | /** |
||
360 | * @param $id |
||
361 | * @return \OCP\AppFramework\Db\Entity |
||
362 | * @throws DoesNotExistException |
||
363 | * @throws \OCA\Deck\NoPermissionException |
||
364 | * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException |
||
365 | */ |
||
366 | View Code Duplication | public function deleteUndo($id) { |
|
0 ignored issues
–
show
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. ![]() |
|||
367 | |||
368 | if (is_numeric($id) === false) { |
||
369 | throw new BadRequestException('board id must be a number'); |
||
370 | } |
||
371 | |||
372 | $this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_READ); |
||
373 | $board = $this->find($id); |
||
374 | $board->setDeletedAt(0); |
||
375 | $board = $this->boardMapper->update($board); |
||
0 ignored issues
–
show
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. ![]() |
|||
376 | $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $board, ActivityManager::SUBJECT_BOARD_RESTORE); |
||
377 | $this->changeHelper->boardChanged($board->getId()); |
||
378 | |||
379 | $this->eventDispatcher->dispatch( |
||
380 | '\OCA\Deck\Board::onUpdate', new GenericEvent(null, ['id' => $id, 'board' => $board]) |
||
381 | ); |
||
382 | |||
383 | return $board; |
||
384 | } |
||
385 | |||
386 | /** |
||
387 | * @param $id |
||
388 | * @return \OCP\AppFramework\Db\Entity |
||
389 | * @throws DoesNotExistException |
||
390 | * @throws \OCA\Deck\NoPermissionException |
||
391 | * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException |
||
392 | * @throws BadRequestException |
||
393 | */ |
||
394 | public function deleteForce($id) { |
||
395 | if (is_numeric($id) === false) { |
||
396 | throw new BadRequestException('id must be a number'); |
||
397 | } |
||
398 | |||
399 | $this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_READ); |
||
400 | $board = $this->find($id); |
||
401 | $delete = $this->boardMapper->delete($board); |
||
402 | |||
403 | $this->eventDispatcher->dispatch( |
||
404 | '\OCA\Deck\Board::onDelete', new GenericEvent(null, ['id' => $id]) |
||
405 | ); |
||
406 | |||
407 | return $delete; |
||
408 | } |
||
409 | |||
410 | /** |
||
411 | * @param $id |
||
412 | * @param $title |
||
413 | * @param $color |
||
414 | * @param $archived |
||
415 | * @return \OCP\AppFramework\Db\Entity |
||
416 | * @throws DoesNotExistException |
||
417 | * @throws \OCA\Deck\NoPermissionException |
||
418 | * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException |
||
419 | * @throws BadRequestException |
||
420 | */ |
||
421 | public function update($id, $title, $color, $archived) { |
||
422 | |||
423 | if (is_numeric($id) === false) { |
||
424 | throw new BadRequestException('board id must be a number'); |
||
425 | } |
||
426 | |||
427 | if ($title === false || $title === null) { |
||
428 | throw new BadRequestException('color must be provided'); |
||
429 | } |
||
430 | |||
431 | if ($color === false || $color === null) { |
||
432 | throw new BadRequestException('color must be provided'); |
||
433 | } |
||
434 | |||
435 | if ( is_bool($archived) === false ) { |
||
436 | throw new BadRequestException('archived must be a boolean'); |
||
437 | } |
||
438 | |||
439 | $this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_MANAGE); |
||
440 | $board = $this->find($id); |
||
441 | $changes = new ChangeSet($board); |
||
442 | $board->setTitle($title); |
||
443 | $board->setColor($color); |
||
444 | $board->setArchived($archived); |
||
445 | $changes->setAfter($board); |
||
446 | $this->boardMapper->update($board); // operate on clone so we can check for updated fields |
||
0 ignored issues
–
show
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. ![]() |
|||
447 | $this->boardMapper->mapOwner($board); |
||
448 | $this->activityManager->triggerUpdateEvents(ActivityManager::DECK_OBJECT_BOARD, $changes, ActivityManager::SUBJECT_BOARD_UPDATE); |
||
449 | $this->changeHelper->boardChanged($board->getId()); |
||
450 | |||
451 | $this->eventDispatcher->dispatch( |
||
452 | '\OCA\Deck\Board::onUpdate', new GenericEvent(null, ['id' => $id, 'board' => $board]) |
||
453 | ); |
||
454 | |||
455 | return $board; |
||
456 | } |
||
457 | |||
458 | |||
459 | /** |
||
460 | * @param $boardId |
||
461 | * @param $type |
||
462 | * @param $participant |
||
463 | * @param $edit |
||
464 | * @param $share |
||
465 | * @param $manage |
||
466 | * @return \OCP\AppFramework\Db\Entity |
||
467 | * @throws BadRequestException |
||
468 | * @throws \OCA\Deck\NoPermissionException |
||
469 | */ |
||
470 | public function addAcl($boardId, $type, $participant, $edit, $share, $manage) { |
||
471 | |||
472 | if (is_numeric($boardId) === false) { |
||
473 | throw new BadRequestException('board id must be a number'); |
||
474 | } |
||
475 | |||
476 | if ($type === false || $type === null) { |
||
477 | throw new BadRequestException('type must be provided'); |
||
478 | } |
||
479 | |||
480 | if ($participant === false || $participant === null) { |
||
481 | throw new BadRequestException('participant must be provided'); |
||
482 | } |
||
483 | |||
484 | if ($edit === null) { |
||
485 | throw new BadRequestException('edit must be provided'); |
||
486 | } |
||
487 | |||
488 | if ($share === null) { |
||
489 | throw new BadRequestException('share must be provided'); |
||
490 | } |
||
491 | |||
492 | if ($manage === null) { |
||
493 | throw new BadRequestException('manage must be provided'); |
||
494 | } |
||
495 | |||
496 | $this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_SHARE); |
||
497 | $acl = new Acl(); |
||
498 | $acl->setBoardId($boardId); |
||
499 | $acl->setType($type); |
||
500 | $acl->setParticipant($participant); |
||
501 | $acl->setPermissionEdit($edit); |
||
502 | $acl->setPermissionShare($share); |
||
503 | $acl->setPermissionManage($manage); |
||
504 | |||
505 | /* Notify users about the shared board */ |
||
506 | $this->notificationHelper->sendBoardShared($boardId, $acl); |
||
507 | |||
508 | $newAcl = $this->aclMapper->insert($acl); |
||
0 ignored issues
–
show
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. ![]() |
|||
509 | $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $newAcl, ActivityManager::SUBJECT_BOARD_SHARE); |
||
510 | $this->boardMapper->mapAcl($newAcl); |
||
511 | $this->changeHelper->boardChanged($boardId); |
||
512 | |||
513 | // TODO: use the dispatched event for this |
||
514 | $version = \OC_Util::getVersion()[0]; |
||
515 | View Code Duplication | if ($version >= 16) { |
|
0 ignored issues
–
show
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. ![]() |
|||
516 | try { |
||
517 | $resourceProvider = \OC::$server->query(\OCA\Deck\Collaboration\Resources\ResourceProvider::class); |
||
518 | $resourceProvider->invalidateAccessCache($boardId); |
||
519 | } catch (\Exception $e) {} |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
|
|||
520 | } |
||
521 | |||
522 | $this->eventDispatcher->dispatch( |
||
523 | '\OCA\Deck\Board::onShareNew', new GenericEvent(null, ['id' => $newAcl->getId(), 'acl' => $newAcl, 'boardId' => $boardId]) |
||
524 | ); |
||
525 | |||
526 | return $newAcl; |
||
527 | } |
||
528 | |||
529 | /** |
||
530 | * @param $id |
||
531 | * @param $edit |
||
532 | * @param $share |
||
533 | * @param $manage |
||
534 | * @return \OCP\AppFramework\Db\Entity |
||
535 | * @throws DoesNotExistException |
||
536 | * @throws \OCA\Deck\NoPermissionException |
||
537 | * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException |
||
538 | * @throws BadRequestException |
||
539 | */ |
||
540 | public function updateAcl($id, $edit, $share, $manage) { |
||
541 | |||
542 | if (is_numeric($id) === false) { |
||
543 | throw new BadRequestException('id must be a number'); |
||
544 | } |
||
545 | |||
546 | if ($edit === null) { |
||
547 | throw new BadRequestException('edit must be provided'); |
||
548 | } |
||
549 | |||
550 | if ($share === null) { |
||
551 | throw new BadRequestException('share must be provided'); |
||
552 | } |
||
553 | |||
554 | if ($manage === null) { |
||
555 | throw new BadRequestException('manage must be provided'); |
||
556 | } |
||
557 | |||
558 | $this->permissionService->checkPermission($this->aclMapper, $id, Acl::PERMISSION_SHARE); |
||
559 | /** @var Acl $acl */ |
||
560 | $acl = $this->aclMapper->find($id); |
||
561 | $acl->setPermissionEdit($edit); |
||
562 | $acl->setPermissionShare($share); |
||
563 | $acl->setPermissionManage($manage); |
||
564 | $this->boardMapper->mapAcl($acl); |
||
565 | $board = $this->aclMapper->update($acl); |
||
0 ignored issues
–
show
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. ![]() |
|||
566 | $this->changeHelper->boardChanged($acl->getBoardId()); |
||
567 | |||
568 | $this->eventDispatcher->dispatch( |
||
569 | '\OCA\Deck\Board::onShareEdit', new GenericEvent(null, ['id' => $id, 'boardId' => $acl->getBoardId(), 'acl' => $acl]) |
||
570 | ); |
||
571 | |||
572 | return $board; |
||
573 | } |
||
574 | |||
575 | /** |
||
576 | * @param $id |
||
577 | * @return \OCP\AppFramework\Db\Entity |
||
578 | * @throws DoesNotExistException |
||
579 | * @throws \OCA\Deck\NoPermissionException |
||
580 | * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException |
||
581 | * @throws BadRequestException |
||
582 | */ |
||
583 | public function deleteAcl($id) { |
||
584 | |||
585 | if (is_numeric($id) === false) { |
||
586 | throw new BadRequestException('id must be a number'); |
||
587 | } |
||
588 | |||
589 | $this->permissionService->checkPermission($this->aclMapper, $id, Acl::PERMISSION_SHARE); |
||
590 | /** @var Acl $acl */ |
||
591 | $acl = $this->aclMapper->find($id); |
||
592 | $this->boardMapper->mapAcl($acl); |
||
593 | if ($acl->getType() === Acl::PERMISSION_TYPE_USER) { |
||
594 | $assignements = $this->assignedUsersMapper->findByUserId($acl->getParticipant()); |
||
595 | foreach ($assignements as $assignement) { |
||
596 | $this->assignedUsersMapper->delete($assignement); |
||
0 ignored issues
–
show
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. ![]() |
|||
597 | } |
||
598 | } |
||
599 | $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $acl, ActivityManager::SUBJECT_BOARD_UNSHARE); |
||
600 | $this->changeHelper->boardChanged($acl->getBoardId()); |
||
601 | |||
602 | $version = \OC_Util::getVersion()[0]; |
||
603 | View Code Duplication | if ($version >= 16) { |
|
0 ignored issues
–
show
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. ![]() |
|||
604 | try { |
||
605 | $resourceProvider = \OC::$server->query(\OCA\Deck\Collaboration\Resources\ResourceProvider::class); |
||
606 | $resourceProvider->invalidateAccessCache($acl->getBoardId()); |
||
607 | } catch (\Exception $e) {} |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
|
|||
608 | } |
||
609 | $delete = $this->aclMapper->delete($acl); |
||
0 ignored issues
–
show
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. ![]() |
|||
610 | |||
611 | $this->eventDispatcher->dispatch( |
||
612 | '\OCA\Deck\Board::onShareDelete', new GenericEvent(null, ['id' => $id, 'boardId' => $acl->getBoardId(), 'acl' => $acl]) |
||
613 | ); |
||
614 | |||
615 | return $delete; |
||
616 | } |
||
617 | |||
618 | /** |
||
619 | * @param $id |
||
620 | * @return Board |
||
621 | * @throws DoesNotExistException |
||
622 | * @throws \OCA\Deck\NoPermissionException |
||
623 | * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException |
||
624 | * @throws BadRequestException |
||
625 | */ |
||
626 | public function clone($id) { |
||
627 | |||
628 | if (is_numeric($id) === false) { |
||
629 | throw new BadRequestException('board id must be a number'); |
||
630 | } |
||
631 | |||
632 | $this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_READ); |
||
633 | |||
634 | $board = $this->boardMapper->find($id); |
||
635 | $newBoard = new Board(); |
||
636 | $newBoard->setTitle($board->getTitle() . ' (' . $this->l10n->t('copy') . ')'); |
||
637 | $newBoard->setOwner($board->getOwner()); |
||
638 | $newBoard->setColor($board->getColor()); |
||
639 | $this->boardMapper->insert($newBoard); |
||
0 ignored issues
–
show
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. ![]() |
|||
640 | |||
641 | $labels = $this->labelMapper->findAll($id); |
||
642 | foreach ($labels as $label) { |
||
643 | $newLabel = new Label(); |
||
644 | $newLabel->setTitle($label->getTitle()); |
||
645 | $newLabel->setColor($label->getColor()); |
||
646 | $newLabel->setBoardId($newBoard->getId()); |
||
647 | $this->labelMapper->insert($newLabel); |
||
648 | } |
||
649 | |||
650 | $stacks = $this->stackMapper->findAll($id); |
||
651 | foreach ($stacks as $stack) { |
||
652 | $newStack = new Stack(); |
||
653 | $newStack->setTitle($stack->getTitle()); |
||
654 | $newStack->setBoardId($newBoard->getId()); |
||
655 | $this->stackMapper->insert($newStack); |
||
0 ignored issues
–
show
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. ![]() |
|||
656 | } |
||
657 | |||
658 | return $newBoard; |
||
659 | } |
||
660 | |||
661 | private function enrichWithStacks($board, $since = -1) { |
||
662 | $stacks = $this->stackMapper->findAll($board->getId(), null, null, $since); |
||
0 ignored issues
–
show
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 ![]() |
|||
663 | |||
664 | if(\count($stacks) === 0) { |
||
665 | return; |
||
666 | } |
||
667 | |||
668 | $board->setStacks($stacks); |
||
669 | } |
||
670 | |||
671 | private function enrichWithLabels($board, $since = -1) { |
||
672 | $labels = $this->labelMapper->findAll($board->getId(), null, null, $since); |
||
0 ignored issues
–
show
The call to
LabelMapper::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 ![]() |
|||
673 | |||
674 | if(\count($labels) === 0) { |
||
675 | return; |
||
676 | } |
||
677 | |||
678 | $board->setLabels($labels); |
||
679 | } |
||
680 | |||
681 | private function enrichWithUsers($board, $since = -1) { |
||
0 ignored issues
–
show
|
|||
682 | $boardUsers = $this->permissionService->findUsers($board->getId()); |
||
683 | if(\count($boardUsers) === 0) { |
||
684 | return; |
||
685 | } |
||
686 | $board->setUsers(array_values($boardUsers)); |
||
687 | } |
||
688 | |||
689 | } |
||
690 |
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.