committed by
Julius Härtl
parent
b7f3c2d140
commit
981fc8e16f
@@ -154,19 +154,17 @@ class AssignmentMapper extends QBMapper implements IPermissionMapper {
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function transferOwnership(string $ownerId, string $newOwnerId) {
|
public function transferOwnership(string $ownerId, string $newOwnerId) {
|
||||||
$params = [
|
|
||||||
'newOwner' => $newOwnerId,
|
|
||||||
'type' => Assignment::TYPE_USER
|
|
||||||
];
|
|
||||||
$qb = $this->db->getQueryBuilder();
|
|
||||||
$sql = "DELETE FROM `*PREFIX*{$this->tableName}` WHERE `participant` = :newOwner AND `type`= :type";
|
|
||||||
$stmt = $this->db->executeQuery($sql, $params);
|
|
||||||
$stmt->closeCursor();
|
|
||||||
$params = [
|
$params = [
|
||||||
'owner' => $ownerId,
|
'owner' => $ownerId,
|
||||||
'newOwner' => $newOwnerId,
|
'newOwner' => $newOwnerId,
|
||||||
'type' => Assignment::TYPE_USER
|
'type' => Assignment::TYPE_USER
|
||||||
];
|
];
|
||||||
|
$qb = $this->db->getQueryBuilder();
|
||||||
|
$sql = "DELETE FROM `*PREFIX*{$this->tableName}` WHERE `participant` = :newOwner AND `type`= :type AND id IN
|
||||||
|
(SELECT id FROM `*PREFIX*{$this->tableName}` WHERE `participant` = :owner)";
|
||||||
|
$stmt = $this->db->executeQuery($sql, $params);
|
||||||
|
$stmt->closeCursor();
|
||||||
|
|
||||||
$sql = "UPDATE `*PREFIX*{$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->db->executeQuery($sql, $params);
|
$stmt = $this->db->executeQuery($sql, $params);
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ class BoardMapper extends QBMapper implements IPermissionMapper {
|
|||||||
|
|
||||||
// shared with user
|
// shared with user
|
||||||
$qb->resetQueryParts();
|
$qb->resetQueryParts();
|
||||||
$qb->select('b.id', 'title', 'owner', 'color', 'archived', 'deleted_at', 'last_modified')
|
$qb->selectDistinct('b.id', 'title', 'owner', 'color', 'archived', 'deleted_at', 'last_modified')
|
||||||
//->selectAlias('1', 'shared')
|
//->selectAlias('1', 'shared')
|
||||||
->from('deck_boards', 'b')
|
->from('deck_boards', 'b')
|
||||||
->innerJoin('b', 'deck_board_acl', 'acl', $qb->expr()->eq('b.id', 'acl.board_id'))
|
->innerJoin('b', 'deck_board_acl', 'acl', $qb->expr()->eq('b.id', 'acl.board_id'))
|
||||||
@@ -490,4 +490,25 @@ class BoardMapper extends QBMapper implements IPermissionMapper {
|
|||||||
$stmt = $this->db->executeQuery($sql, $params);
|
$stmt = $this->db->executeQuery($sql, $params);
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset Cache for a
|
||||||
|
* given board or a given user
|
||||||
|
*
|
||||||
|
* @param int|null $boardId
|
||||||
|
* @param int|null $userId
|
||||||
|
*/
|
||||||
|
public function flushCache(?int $boardId = null, ?string $userId = null)
|
||||||
|
{
|
||||||
|
if ($boardId) {
|
||||||
|
unset($this->boardCache[$boardId]);
|
||||||
|
} else {
|
||||||
|
$this->boardCache = null;
|
||||||
|
}
|
||||||
|
if ($userId) {
|
||||||
|
unset($this->userBoardCache[$userId]);
|
||||||
|
} else {
|
||||||
|
$this->userBoardCache = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -528,6 +528,9 @@ class BoardService {
|
|||||||
$this->boardMapper->mapAcl($newAcl);
|
$this->boardMapper->mapAcl($newAcl);
|
||||||
$this->changeHelper->boardChanged($boardId);
|
$this->changeHelper->boardChanged($boardId);
|
||||||
|
|
||||||
|
$board = $this->find($boardId);
|
||||||
|
$this->clearBoardFromCache($board);
|
||||||
|
|
||||||
// TODO: use the dispatched event for this
|
// TODO: use the dispatched event for this
|
||||||
try {
|
try {
|
||||||
$resourceProvider = \OC::$server->query(\OCA\Deck\Collaboration\Resources\ResourceProvider::class);
|
$resourceProvider = \OC::$server->query(\OCA\Deck\Collaboration\Resources\ResourceProvider::class);
|
||||||
@@ -681,6 +684,7 @@ class BoardService {
|
|||||||
public function transferOwnership(string $owner, string $newOwner): void {
|
public function transferOwnership(string $owner, string $newOwner): void {
|
||||||
$boards = $this->boardMapper->findAllByUser($owner);
|
$boards = $this->boardMapper->findAllByUser($owner);
|
||||||
foreach ($boards as $board) {
|
foreach ($boards as $board) {
|
||||||
|
$this->clearBoardFromCache($board);
|
||||||
$this->aclMapper->transferOwnership($board->getId(), $owner, $newOwner);
|
$this->aclMapper->transferOwnership($board->getId(), $owner, $newOwner);
|
||||||
}
|
}
|
||||||
$this->boardMapper->transferOwnership($owner, $newOwner);
|
$this->boardMapper->transferOwnership($owner, $newOwner);
|
||||||
@@ -723,4 +727,18 @@ class BoardService {
|
|||||||
private function clearBoardsCache() {
|
private function clearBoardsCache() {
|
||||||
$this->boardsCache = null;
|
$this->boardsCache = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean a given board data
|
||||||
|
* from the Cache
|
||||||
|
*
|
||||||
|
* @param OCA\Deck\Db\Board $board
|
||||||
|
*/
|
||||||
|
private function clearBoardFromCache(Board $board) {
|
||||||
|
$boardId = $board->getId();
|
||||||
|
$boardOwnerId = $board->getOwner();
|
||||||
|
|
||||||
|
$this->boardMapper->flushCache($boardId, $boardOwnerId);
|
||||||
|
unset($this->boardsCache[$boardId]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +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');
|
/* $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);
|
||||||
|
|||||||
Reference in New Issue
Block a user