Handle board exceptions more gracefully
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace OCA\Deck\Command;
|
namespace OCA\Deck\Command;
|
||||||
|
|
||||||
|
use OCA\Deck\Db\BoardMapper;
|
||||||
use OCA\Deck\Service\BoardService;
|
use OCA\Deck\Service\BoardService;
|
||||||
|
use OCA\Deck\Service\PermissionService;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
@@ -13,12 +15,16 @@ use Symfony\Component\Console\Question\ConfirmationQuestion;
|
|||||||
|
|
||||||
final class TransferOwnership extends Command {
|
final class TransferOwnership extends Command {
|
||||||
protected $boardService;
|
protected $boardService;
|
||||||
|
protected $boardMapper;
|
||||||
|
protected $permissionService;
|
||||||
protected $questionHelper;
|
protected $questionHelper;
|
||||||
|
|
||||||
public function __construct(BoardService $boardService, QuestionHelper $questionHelper) {
|
public function __construct(BoardService $boardService, BoardMapper $boardMapper, PermissionService $permissionService, QuestionHelper $questionHelper) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->boardService = $boardService;
|
$this->boardService = $boardService;
|
||||||
|
$this->boardMapper = $boardMapper;
|
||||||
|
$this->permissionService = $permissionService;
|
||||||
$this->questionHelper = $questionHelper;
|
$this->questionHelper = $questionHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +63,15 @@ final class TransferOwnership extends Command {
|
|||||||
|
|
||||||
$remapAssignment = $input->getOption('remap');
|
$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) {
|
if ($boardId !== null && $board->getOwner() !== $owner) {
|
||||||
$output->writeln("$owner is not the owner of the board $boardId (" . $board->getTitle() . ")");
|
$output->writeln("$owner is not the owner of the board $boardId (" . $board->getTitle() . ")");
|
||||||
|
|||||||
@@ -161,10 +161,6 @@ class BoardController extends ApiController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @param $boardId
|
|
||||||
* @param $owner
|
|
||||||
* @param $newOwner
|
|
||||||
* * @return null|void
|
|
||||||
*/
|
*/
|
||||||
public function transferOwner(int $boardId, string $newOwner): DataResponse {
|
public function transferOwner(int $boardId, string $newOwner): DataResponse {
|
||||||
if ($this->permissionService->userIsBoardOwner($boardId, $this->userId)) {
|
if ($this->permissionService->userIsBoardOwner($boardId, $this->userId)) {
|
||||||
|
|||||||
@@ -524,7 +524,7 @@ class BoardService {
|
|||||||
$acl->setPermissionManage($manage);
|
$acl->setPermissionManage($manage);
|
||||||
$newAcl = $this->aclMapper->insert($acl);
|
$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->notificationHelper->sendBoardShared((int)$boardId, $acl);
|
||||||
$this->boardMapper->mapAcl($newAcl);
|
$this->boardMapper->mapAcl($newAcl);
|
||||||
$this->changeHelper->boardChanged($boardId);
|
$this->changeHelper->boardChanged($boardId);
|
||||||
@@ -689,17 +689,18 @@ class BoardService {
|
|||||||
$previousOwner = $board->getOwner();
|
$previousOwner = $board->getOwner();
|
||||||
$this->clearBoardFromCache($board);
|
$this->clearBoardFromCache($board);
|
||||||
$this->aclMapper->deleteParticipantFromBoard($boardId, Acl::PERMISSION_TYPE_USER, $newOwner);
|
$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);
|
$this->boardMapper->transferOwnership($previousOwner, $newOwner, $boardId);
|
||||||
|
|
||||||
// Optionally also change user assignments and card owner information
|
// Optionally also change user assignments and card owner information
|
||||||
if ($changeContent) {
|
if ($changeContent) {
|
||||||
$this->assignedUsersMapper->remapAssignedUser($boardId, $previousOwner, $newOwner);
|
$this->assignedUsersMapper->remapAssignedUser($boardId, $previousOwner, $newOwner);
|
||||||
$this->cardMapper->remapCardOwner($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();
|
\OC::$server->getDatabaseConnection()->commit();
|
||||||
return $this->boardMapper->find($boardId);
|
return $this->boardMapper->find($boardId);
|
||||||
|
|||||||
@@ -333,4 +333,13 @@ class PermissionService {
|
|||||||
}
|
}
|
||||||
return $groups;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user