Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Service/BoardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public function delete(int $id): Board {
public function deleteUndo(int $id): Board {
$this->boardServiceValidator->check(compact('id'));

$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_MANAGE);
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_MANAGE, allowDeletedBoard: true);
$board = $this->find($id, allowDeleted: true);
$board->setDeletedAt(0);
$board = $this->boardMapper->update($board);
Expand All @@ -265,7 +265,7 @@ public function deleteUndo(int $id): Board {
public function deleteForce(int $id): Board {
$this->boardServiceValidator->check(compact('id'));

$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_MANAGE);
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_MANAGE, allowDeletedBoard: true);
$board = $this->find($id, allowDeleted: true);
$delete = $this->boardMapper->delete($board);

Expand Down
18 changes: 9 additions & 9 deletions lib/Service/PermissionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct(
*
* @return array<Acl::PERMISSION_*, bool>
*/
public function getPermissions(int $boardId, ?string $userId = null): array {
public function getPermissions(int $boardId, ?string $userId = null, bool $allowDeleted = false): array {
if ($userId === null) {
$userId = $this->userId;
}
Expand All @@ -64,8 +64,8 @@ public function getPermissions(int $boardId, ?string $userId = null): array {
}

try {
$board = $this->getBoard($boardId);
$owner = $this->userIsBoardOwner($boardId, $userId);
$board = $this->getBoard($boardId, $allowDeleted);
$owner = $this->userIsBoardOwner($boardId, $userId, $allowDeleted);
$acls = $board->getDeletedAt() === 0 ? $this->aclMapper->findAll($boardId) : [];
} catch (MultipleObjectsReturnedException|DoesNotExistException $e) {
$owner = false;
Expand Down Expand Up @@ -107,7 +107,7 @@ public function matchPermissions(Board $board) {
*
* @throws NoPermissionException
*/
public function checkPermission(?IPermissionMapper $mapper, $id, int $permission, $userId = null, bool $allowDeletedCard = false): bool {
public function checkPermission(?IPermissionMapper $mapper, $id, int $permission, $userId = null, bool $allowDeletedCard = false, bool $allowDeletedBoard = false): bool {
$boardId = (int)$id;
if ($mapper instanceof IPermissionMapper && !($mapper instanceof BoardMapper)) {
$boardId = $mapper->findBoardId($id);
Expand All @@ -117,7 +117,7 @@ public function checkPermission(?IPermissionMapper $mapper, $id, int $permission
throw new NoPermissionException('Permission denied');
}

$permissions = $this->getPermissions($boardId, $userId);
$permissions = $this->getPermissions($boardId, $userId, $allowDeletedBoard);
if ($permissions[$permission] === true) {

if (!$allowDeletedCard && $mapper instanceof CardMapper) {
Expand All @@ -142,12 +142,12 @@ public function checkPermission(?IPermissionMapper $mapper, $id, int $permission
* @param $boardId
* @return bool
*/
public function userIsBoardOwner($boardId, $userId = null) {
public function userIsBoardOwner($boardId, $userId = null, bool $allowDeleted = false) {
if ($userId === null) {
$userId = $this->userId;
}
try {
$board = $this->getBoard($boardId);
$board = $this->getBoard($boardId, $allowDeleted);
return $userId === $board->getOwner();
} catch (DoesNotExistException|MultipleObjectsReturnedException $e) {
}
Expand All @@ -158,9 +158,9 @@ public function userIsBoardOwner($boardId, $userId = null) {
* @throws MultipleObjectsReturnedException
* @throws DoesNotExistException
*/
private function getBoard(int $boardId): Board {
private function getBoard(int $boardId, bool $allowDeleted = false): Board {
if (!isset($this->boardCache[(string)$boardId])) {
$this->boardCache[(string)$boardId] = $this->boardMapper->find($boardId, false, true);
$this->boardCache[(string)$boardId] = $this->boardMapper->find($boardId, false, true, $allowDeleted);
}
return $this->boardCache[(string)$boardId];
}
Expand Down
Loading