Make queries work with the new base mapper

Signed-off-by: Julius Härtl <jus@bitgrid.net>

fix: conflicts
This commit is contained in:
Julius Härtl
2020-11-10 12:54:36 +01:00
parent c0886cfc7a
commit a8c22482f6
4 changed files with 23 additions and 20 deletions

View File

@@ -63,19 +63,18 @@ class AclMapper extends DeckMapper implements IPermissionMapper {
* @param $newOwnerId * @param $newOwnerId
* @return void * @return void
*/ */
public function transferOwnership($ownerId, $newOwnerId) { public function transferOwnership($boardId, $ownerId, $newOwnerId) {
$params = [ $params = [
'owner' => $ownerId,
'newOwner' => $newOwnerId, 'newOwner' => $newOwnerId,
'type' => Acl::PERMISSION_TYPE_USER 'type' => Acl::PERMISSION_TYPE_USER,
'boardId' => $boardId
]; ];
// Drop existing ACL rules for the new owner // Drop existing ACL rules for the new owner
$sql = "DELETE FROM `{$this->tableName}` $sql = "DELETE FROM `{$this->tableName}`
WHERE `participant` = :newOwner WHERE `participant` = :newOwner
AND `type` = :type AND `type` = :type
AND EXISTS (SELECT `id` FROM (SELECT `id` FROM `{$this->tableName}` AND `board_id` = :boardId";
WHERE `participant` = :newOwner AND `type` = :type) as tmp)";
$stmt = $this->execute($sql, $params); $stmt = $this->execute($sql, $params);
$stmt->closeCursor(); $stmt->closeCursor();
} }

View File

@@ -157,16 +157,17 @@ class AssignmentMapper extends QBMapper implements IPermissionMapper {
'newOwner' => $newOwnerId, 'newOwner' => $newOwnerId,
'type' => AssignedUsers::TYPE_USER 'type' => AssignedUsers::TYPE_USER
]; ];
$sql = "DELETE FROM `{$this->tableName}` WHERE `participant` = :newOwner AND `type`= :type"; $qb = $this->db->getQueryBuilder();
$stmt = $this->execute($sql, $params); $sql = "DELETE FROM `*PREFIX*{$this->tableName}` WHERE `participant` = :newOwner AND `type`= :type";
$stmt = $this->db->executeQuery($sql, $params);
$stmt->closeCursor(); $stmt->closeCursor();
$params = [ $params = [
'owner' => $ownerId, 'owner' => $ownerId,
'newOwner' => $newOwnerId, 'newOwner' => $newOwnerId,
'type' => AssignedUsers::TYPE_USER 'type' => AssignedUsers::TYPE_USER
]; ];
$sql = "UPDATE `{$this->tableName}` SET `participant` = :newOwner WHERE `participant` = :owner AND `type`= :type"; $sql = "UPDATE `*PREFIX*{$this->tableName}` SET `participant` = :newOwner WHERE `participant` = :owner AND `type`= :type";
$stmt = $this->execute($sql, $params); $stmt = $this->db->executeQuery($sql, $params);
$stmt->closeCursor(); $stmt->closeCursor();
} }
} }

View File

@@ -678,14 +678,12 @@ class BoardService {
return $newBoard; return $newBoard;
} }
/** public function transferOwnership(string $owner, string $newOwner): void {
* @param $ownerId $boards = $this->boardMapper->findAllByUser($owner);
* @param $newOwnerId foreach ($boards as $board) {
* @return void $this->aclMapper->transferOwnership($board->getId(), $owner, $newOwner);
*/ }
public function transferOwnership($owner, $newOwner) {
$this->boardMapper->transferOwnership($owner, $newOwner); $this->boardMapper->transferOwnership($owner, $newOwner);
$this->aclMapper->transferOwnership($owner, $newOwner);
$this->assignedUsersMapper->transferOwnership($owner, $newOwner); $this->assignedUsersMapper->transferOwnership($owner, $newOwner);
$this->cardMapper->transferOwnership($owner, $newOwner); $this->cardMapper->transferOwnership($owner, $newOwner);
} }
@@ -721,4 +719,8 @@ class BoardService {
public function getBoardUrl($endpoint) { public function getBoardUrl($endpoint) {
return $this->urlGenerator->linkToRouteAbsolute('deck.page.index') . '#' . $endpoint; return $this->urlGenerator->linkToRouteAbsolute('deck.page.index') . '#' . $endpoint;
} }
private function clearBoardsCache() {
$this->boardsCache = null;
}
} }

View File

@@ -82,6 +82,7 @@ class TransferOwnershipTest extends \Test\TestCase {
*/ */
public function testTransferBoardOwnership() { public function testTransferBoardOwnership() {
$this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_2); $this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_2);
$this->invokePrivate($this->boardService, 'clearBoardsCache');
$board = $this->boardService->find($this->board->getId()); $board = $this->boardService->find($this->board->getId());
$boardOwner = $board->getOwner(); $boardOwner = $board->getOwner();
$this->assertEquals(self::TEST_USER_2, $boardOwner); $this->assertEquals(self::TEST_USER_2, $boardOwner);
@@ -94,10 +95,10 @@ class TransferOwnershipTest extends \Test\TestCase {
$this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_2); $this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_2);
$board = $this->boardService->find($this->board->getId()); $board = $this->boardService->find($this->board->getId());
$acl = $board->getAcl(); $acl = $board->getAcl();
$isTargetInAcl = (bool)array_filter($acl, function ($item) { // Check if old owner is no longer in ACL
return $item->getParticipant() === self::TEST_USER_2 && $item->getType() === Acl::PERMISSION_TYPE_USER; $this->assertTrue((bool)array_filter($acl, function ($item) {
}); return $item->getParticipant() === self::TEST_USER_1 && $item->getType() === Acl::PERMISSION_TYPE_USER;
$this->assertTrue($isTargetInAcl); }));
} }
/** /**