Skip to content

Commit

Permalink
check user-permsisions when assigning to cloned card
Browse files Browse the repository at this point in the history
Signed-off-by: grnd-alt <salimbelakkaf@outlook.de>
  • Loading branch information
grnd-alt committed Nov 7, 2024
1 parent 4212c10 commit ef9358b
Showing 1 changed file with 32 additions and 60 deletions.
92 changes: 32 additions & 60 deletions lib/Service/CardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,70 +36,33 @@
use Psr\Log\LoggerInterface;

class CardService {
private CardMapper $cardMapper;
private StackMapper $stackMapper;
private BoardMapper $boardMapper;
private LabelMapper $labelMapper;
private LabelService $labelService;
private PermissionService $permissionService;
private BoardService $boardService;
private NotificationHelper $notificationHelper;
private AssignmentMapper $assignedUsersMapper;
private AttachmentService $attachmentService;
private ?string $currentUser;
private ActivityManager $activityManager;
private ICommentsManager $commentsManager;
private ChangeHelper $changeHelper;
private IEventDispatcher $eventDispatcher;
private IUserManager $userManager;
private IURLGenerator $urlGenerator;
private LoggerInterface $logger;
private IRequest $request;
private CardServiceValidator $cardServiceValidator;

private string $currentUser;

public function __construct(
CardMapper $cardMapper,
StackMapper $stackMapper,
BoardMapper $boardMapper,
LabelMapper $labelMapper,
LabelService $labelService,
PermissionService $permissionService,
BoardService $boardService,
NotificationHelper $notificationHelper,
AssignmentMapper $assignedUsersMapper,
AttachmentService $attachmentService,
ActivityManager $activityManager,
ICommentsManager $commentsManager,
IUserManager $userManager,
ChangeHelper $changeHelper,
IEventDispatcher $eventDispatcher,
IURLGenerator $urlGenerator,
LoggerInterface $logger,
IRequest $request,
CardServiceValidator $cardServiceValidator,
private CardMapper $cardMapper,
private StackMapper $stackMapper,
private BoardMapper $boardMapper,
private LabelMapper $labelMapper,
private LabelService $labelService,
private PermissionService $permissionService,
private BoardService $boardService,
private NotificationHelper $notificationHelper,
private AssignmentMapper $assignedUsersMapper,
private AttachmentService $attachmentService,
private ActivityManager $activityManager,
private ICommentsManager $commentsManager,
private IUserManager $userManager,
private ChangeHelper $changeHelper,
private IEventDispatcher $eventDispatcher,
private IURLGenerator $urlGenerator,
private LoggerInterface $logger,
private IRequest $request,
private CardServiceValidator $cardServiceValidator,
private AssignmentService $assignmentService,
?string $userId,
) {
$this->cardMapper = $cardMapper;
$this->stackMapper = $stackMapper;
$this->boardMapper = $boardMapper;
$this->labelMapper = $labelMapper;
$this->labelService = $labelService;
$this->permissionService = $permissionService;
$this->boardService = $boardService;
$this->notificationHelper = $notificationHelper;
$this->assignedUsersMapper = $assignedUsersMapper;
$this->attachmentService = $attachmentService;
$this->activityManager = $activityManager;
$this->commentsManager = $commentsManager;
$this->userManager = $userManager;
$this->changeHelper = $changeHelper;
$this->eventDispatcher = $eventDispatcher;
$this->currentUser = $userId;
$this->urlGenerator = $urlGenerator;
$this->logger = $logger;
$this->request = $request;
$this->cardServiceValidator = $cardServiceValidator;
}

public function enrichCards($cards) {
Expand Down Expand Up @@ -394,19 +357,28 @@ public function update($id, $title, $stackId, $type, $owner, $description = '',
public function cloneCard(int $id, ?int $targetStackId = null):Card {
$this->permissionService->checkPermission($this->cardMapper, $id, Acl::PERMISSION_READ);
$originCard = $this->cardMapper->find($id);
if ($targetStackId == null) {
if ($targetStackId === null) {
$targetStackId = $originCard->getStackId();
}
$this->permissionService->checkPermission($this->stackMapper, $targetStackId, Acl::PERMISSION_EDIT);
$newCard = $this->create($originCard->getTitle(), $targetStackId, $originCard->getType(), $originCard->getOrder(), $originCard->getOwner());
$boardId = $this->stackMapper->findBoardId($targetStackId);
foreach ($this->labelMapper->findAssignedLabelsForCard($id) as $label) {
if ($boardId != $this->stackMapper->findBoardId($originCard->getStackId())) {
$label = $this->labelService->cloneLabelIfNotExists($label->getId(), $boardId);
try {
$label = $this->labelService->cloneLabelIfNotExists($label->getId(), $boardId);
} catch (NoPermissionException $e) {
break;
}
}
$this->assignLabel($newCard->getId(), $label->getId());
}
foreach ($this->assignedUsersMapper->findAll($id) as $assignement) {
try {
$this->permissionService->checkPermission($this->cardMapper, $newCard->getId(), Acl::PERMISSION_READ, $assignement->getParticipant());
} catch (NoPermissionException $e) {
continue;
}
$this->assignmentService->assignUser($newCard->getId(), $assignement->getParticipant());
}
$newCard->setDescription($originCard->getDescription());
Expand Down

0 comments on commit ef9358b

Please sign in to comment.