Handle board exceptions more gracefully

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2022-03-22 08:21:18 +01:00
parent 3f29cd97db
commit 23f0b16a5a
4 changed files with 32 additions and 12 deletions

View File

@@ -2,7 +2,9 @@
namespace OCA\Deck\Command;
use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Service\BoardService;
use OCA\Deck\Service\PermissionService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
@@ -13,12 +15,16 @@ use Symfony\Component\Console\Question\ConfirmationQuestion;
final class TransferOwnership extends Command {
protected $boardService;
protected $boardMapper;
protected $permissionService;
protected $questionHelper;
public function __construct(BoardService $boardService, QuestionHelper $questionHelper) {
public function __construct(BoardService $boardService, BoardMapper $boardMapper, PermissionService $permissionService, QuestionHelper $questionHelper) {
parent::__construct();
$this->boardService = $boardService;
$this->boardMapper = $boardMapper;
$this->permissionService = $permissionService;
$this->questionHelper = $questionHelper;
}
@@ -57,7 +63,15 @@ final class TransferOwnership extends Command {
$remapAssignment = $input->getOption('remap');
$board = $boardId ? $this->boardService->find($boardId) : null;
$this->boardService->setUserId($owner);
$this->permissionService->setUserId($owner);
try {
$board = $boardId ? $this->boardMapper->find($boardId) : null;
} catch (\Exception $e) {
$output->writeln("Could not find a board for the provided id.");
return 1;
}
if ($boardId !== null && $board->getOwner() !== $owner) {
$output->writeln("$owner is not the owner of the board $boardId (" . $board->getTitle() . ")");

View File

@@ -161,10 +161,6 @@ class BoardController extends ApiController {
/**
* @NoAdminRequired
* @param $boardId
* @param $owner
* @param $newOwner
* * @return null|void
*/
public function transferOwner(int $boardId, string $newOwner): DataResponse {
if ($this->permissionService->userIsBoardOwner($boardId, $this->userId)) {

View File

@@ -524,7 +524,7 @@ class BoardService {
$acl->setPermissionManage($manage);
$newAcl = $this->aclMapper->insert($acl);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $newAcl, ActivityManager::SUBJECT_BOARD_SHARE);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $newAcl, ActivityManager::SUBJECT_BOARD_SHARE, [], $this->userId);
$this->notificationHelper->sendBoardShared((int)$boardId, $acl);
$this->boardMapper->mapAcl($newAcl);
$this->changeHelper->boardChanged($boardId);
@@ -689,17 +689,18 @@ class BoardService {
$previousOwner = $board->getOwner();
$this->clearBoardFromCache($board);
$this->aclMapper->deleteParticipantFromBoard($boardId, Acl::PERMISSION_TYPE_USER, $newOwner);
if (!$changeContent) {
try {
$this->addAcl($boardId, Acl::PERMISSION_TYPE_USER, $previousOwner, true, true, true);
} catch (UniqueConstraintViolationException $e) {
}
}
$this->boardMapper->transferOwnership($previousOwner, $newOwner, $boardId);
// Optionally also change user assignments and card owner information
if ($changeContent) {
$this->assignedUsersMapper->remapAssignedUser($boardId, $previousOwner, $newOwner);
$this->cardMapper->remapCardOwner($boardId, $previousOwner, $newOwner);
} else {
try {
$this->addAcl($boardId, Acl::PERMISSION_TYPE_USER, $previousOwner, true, true, true);
} catch (UniqueConstraintViolationException $e) {
}
}
\OC::$server->getDatabaseConnection()->commit();
return $this->boardMapper->find($boardId);

View File

@@ -333,4 +333,13 @@ class PermissionService {
}
return $groups;
}
/**
* Set a different user than the current one, e.g. when no user is available in occ
*
* @param string $userId
*/
public function setUserId(string $userId): void {
$this->userId = $userId;
}
}