Fix coding styles
Signed-off-by: Julius Härtl <jus@bitgrid.net> Signed-off-by: Max <max@nextcloud.com>
This commit is contained in:
committed by
Julius Härtl
parent
7df4b7c4bf
commit
6106066460
@@ -64,33 +64,33 @@ class AclMapper extends DeckMapper implements IPermissionMapper {
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function transferOwnership($ownerId, $newOwnerId) {
|
public function transferOwnership($ownerId, $newOwnerId) {
|
||||||
$params = [
|
$params = [
|
||||||
'owner' => $ownerId,
|
'owner' => $ownerId,
|
||||||
'newOwner' => $newOwnerId,
|
'newOwner' => $newOwnerId,
|
||||||
'type' => Acl::PERMISSION_TYPE_USER
|
'type' => Acl::PERMISSION_TYPE_USER
|
||||||
];
|
];
|
||||||
//We want preserve permissions from both users
|
//We want preserve permissions from both users
|
||||||
$sql = "UPDATE `{$this->tableName}` AS `source`
|
$sql = "UPDATE `{$this->tableName}` AS `source`
|
||||||
LEFT JOIN `{$this->tableName}` AS `target`
|
LEFT JOIN `{$this->tableName}` AS `target`
|
||||||
ON `target`.`participant` = :newOwner AND `target`.`type` = :type
|
ON `target`.`participant` = :newOwner AND `target`.`type` = :type
|
||||||
SET `source`.`permission_edit` =(`source`.`permission_edit` || `target`.`permission_edit`),
|
SET `source`.`permission_edit` =(`source`.`permission_edit` || `target`.`permission_edit`),
|
||||||
`source`.`permission_share` =(`source`.`permission_share` || `target`.`permission_share`),
|
`source`.`permission_share` =(`source`.`permission_share` || `target`.`permission_share`),
|
||||||
`source`.`permission_manage` =(`source`.`permission_manage` || `target`.`permission_manage`)
|
`source`.`permission_manage` =(`source`.`permission_manage` || `target`.`permission_manage`)
|
||||||
WHERE `source`.`participant` = :owner AND `source`.`type` = :type";
|
WHERE `source`.`participant` = :owner AND `source`.`type` = :type";
|
||||||
$stmt = $this->execute($sql, $params);
|
$stmt = $this->execute($sql, $params);
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
//We can't transfer acl if target already in acl
|
//We can't transfer acl if target already in acl
|
||||||
$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 EXISTS (SELECT `id` FROM (SELECT `id` FROM `{$this->tableName}`
|
||||||
WHERE `participant` = :owner AND `type` = :type) as tmp)";
|
WHERE `participant` = :owner AND `type` = :type) as tmp)";
|
||||||
$stmt = $this->execute($sql, $params);
|
$stmt = $this->execute($sql, $params);
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
//Now we can transfer without errors
|
//Now we can transfer without errors
|
||||||
$sqlUpdate = "UPDATE `{$this->tableName}`
|
$sqlUpdate = "UPDATE `{$this->tableName}`
|
||||||
SET `participant` = :newOwner WHERE `participant` = :owner AND `type` = :type";
|
SET `participant` = :newOwner WHERE `participant` = :owner AND `type` = :type";
|
||||||
$stmt = $this->execute($sqlUpdate, $params);
|
$stmt = $this->execute($sqlUpdate, $params);
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,16 +155,16 @@ class AssignmentMapper extends QBMapper implements IPermissionMapper {
|
|||||||
public function transferOwnership($ownerId, $newOwnerId) {
|
public function transferOwnership($ownerId, $newOwnerId) {
|
||||||
$params = [
|
$params = [
|
||||||
'newOwner' => $newOwnerId,
|
'newOwner' => $newOwnerId,
|
||||||
'type' => AssignedUsers::TYPE_USER
|
'type' => AssignedUsers::TYPE_USER
|
||||||
|
];
|
||||||
|
$sql = "DELETE FROM `{$this->tableName}` WHERE `participant` = :newOwner AND `type`= :type";
|
||||||
|
$stmt = $this->execute($sql, $params);
|
||||||
|
$stmt->closeCursor();
|
||||||
|
$params = [
|
||||||
|
'owner' => $ownerId,
|
||||||
|
'newOwner' => $newOwnerId,
|
||||||
|
'type' => AssignedUsers::TYPE_USER
|
||||||
];
|
];
|
||||||
$sql = "DELETE FROM `{$this->tableName}` WHERE `participant` = :newOwner AND `type`= :type";
|
|
||||||
$stmt = $this->execute($sql, $params);
|
|
||||||
$stmt->closeCursor();
|
|
||||||
$params = [
|
|
||||||
'owner' => $ownerId,
|
|
||||||
'newOwner' => $newOwnerId,
|
|
||||||
'type' => AssignedUsers::TYPE_USER
|
|
||||||
];
|
|
||||||
$sql = "UPDATE `{$this->tableName}` SET `participant` = :newOwner WHERE `participant` = :owner AND `type`= :type";
|
$sql = "UPDATE `{$this->tableName}` SET `participant` = :newOwner WHERE `participant` = :owner AND `type`= :type";
|
||||||
$stmt = $this->execute($sql, $params);
|
$stmt = $this->execute($sql, $params);
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
|||||||
@@ -685,9 +685,9 @@ class BoardService {
|
|||||||
*/
|
*/
|
||||||
public function transferOwnership($owner, $newOwner) {
|
public function transferOwnership($owner, $newOwner) {
|
||||||
$this->boardMapper->transferOwnership($owner, $newOwner);
|
$this->boardMapper->transferOwnership($owner, $newOwner);
|
||||||
$this->aclMapper->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);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function enrichWithStacks($board, $since = -1) {
|
private function enrichWithStacks($board, $since = -1) {
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ class TransferOwnershipTest extends \Test\TestCase {
|
|||||||
$this->boardService->addAcl($id, Acl::PERMISSION_TYPE_USER, self::TEST_USER_1, true, true, true);
|
$this->boardService->addAcl($id, Acl::PERMISSION_TYPE_USER, self::TEST_USER_1, true, true, true);
|
||||||
$this->boardService->addAcl($id, Acl::PERMISSION_TYPE_GROUP, self::TEST_GROUP, true, true, true);
|
$this->boardService->addAcl($id, Acl::PERMISSION_TYPE_GROUP, self::TEST_GROUP, true, true, true);
|
||||||
$this->boardService->addAcl($id, Acl::PERMISSION_TYPE_USER, self::TEST_USER_3, false, true, false);
|
$this->boardService->addAcl($id, Acl::PERMISSION_TYPE_USER, self::TEST_USER_3, false, true, false);
|
||||||
$stacks[] = $this->stackService->create('Stack A', $id, 1);
|
$stacks[] = $this->stackService->create('Stack A', $id, 1);
|
||||||
$stacks[] = $this->stackService->create('Stack B', $id, 1);
|
$stacks[] = $this->stackService->create('Stack B', $id, 1);
|
||||||
$stacks[] = $this->stackService->create('Stack C', $id, 1);
|
$stacks[] = $this->stackService->create('Stack C', $id, 1);
|
||||||
$cards[] = $this->cardService->create('Card 1', $stacks[0]->getId(), 'text', 0, self::TEST_USER_1);
|
$cards[] = $this->cardService->create('Card 1', $stacks[0]->getId(), 'text', 0, self::TEST_USER_1);
|
||||||
@@ -136,68 +136,68 @@ class TransferOwnershipTest extends \Test\TestCase {
|
|||||||
$this->assertNotContains(self::TEST_USER_1, $participantsUIDs);
|
$this->assertNotContains(self::TEST_USER_1, $participantsUIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::transferOwnership
|
* @covers ::transferOwnership
|
||||||
*/
|
*/
|
||||||
public function testReassignCardToNewParticipantOnlyIfParticipantHasUserType() {
|
public function testReassignCardToNewParticipantOnlyIfParticipantHasUserType() {
|
||||||
$this->assignmentService->assignUser($this->cards[1]->getId(), self::TEST_USER_1, AssignedUsers::TYPE_GROUP);
|
$this->assignmentService->assignUser($this->cards[1]->getId(), self::TEST_USER_1, AssignedUsers::TYPE_GROUP);
|
||||||
$this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_2);
|
$this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_2);
|
||||||
$assignedUsers = $this->assignedUsersMapper->find($this->cards[1]->getId());
|
$assignedUsers = $this->assignedUsersMapper->find($this->cards[1]->getId());
|
||||||
$participantsUIDs = [];
|
$participantsUIDs = [];
|
||||||
foreach ($assignedUsers as $user) {
|
foreach ($assignedUsers as $user) {
|
||||||
$participantsUIDs[] = $user->getParticipant();
|
$participantsUIDs[] = $user->getParticipant();
|
||||||
}
|
}
|
||||||
$this->assertContains(self::TEST_USER_1, $participantsUIDs);
|
$this->assertContains(self::TEST_USER_1, $participantsUIDs);
|
||||||
$this->assertNotContains(self::TEST_USER_2, $participantsUIDs);
|
$this->assertNotContains(self::TEST_USER_2, $participantsUIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::transferOwnership
|
* @covers ::transferOwnership
|
||||||
*/
|
*/
|
||||||
public function testTargetAlreadyParticipantOfBoard() {
|
public function testTargetAlreadyParticipantOfBoard() {
|
||||||
$this->expectNotToPerformAssertions();
|
$this->expectNotToPerformAssertions();
|
||||||
$this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_3);
|
$this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_3);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::transferOwnership
|
* @covers ::transferOwnership
|
||||||
*/
|
*/
|
||||||
public function testDontRemoveTargetFromAcl() {
|
public function testDontRemoveTargetFromAcl() {
|
||||||
$this->boardService->transferOwnership(self::TEST_USER_2, self::TEST_USER_3);
|
$this->boardService->transferOwnership(self::TEST_USER_2, self::TEST_USER_3);
|
||||||
$board = $this->boardService->find($this->board->getId());
|
$board = $this->boardService->find($this->board->getId());
|
||||||
$acl = $board->getAcl();
|
$acl = $board->getAcl();
|
||||||
$isOwnerInAcl = (bool)array_filter($acl, function ($item) {
|
$isOwnerInAcl = (bool)array_filter($acl, function ($item) {
|
||||||
return $item->getParticipant() === self::TEST_USER_3 && $item->getType() === Acl::PERMISSION_TYPE_USER;
|
return $item->getParticipant() === self::TEST_USER_3 && $item->getType() === Acl::PERMISSION_TYPE_USER;
|
||||||
});
|
});
|
||||||
$this->assertTrue($isOwnerInAcl);
|
$this->assertTrue($isOwnerInAcl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::transferOwnership
|
* @covers ::transferOwnership
|
||||||
*/
|
*/
|
||||||
public function testMergePermissions() {
|
public function testMergePermissions() {
|
||||||
$this->boardService->addAcl($this->board->getId(), Acl::PERMISSION_TYPE_USER, self::TEST_USER_2, true, false, true);
|
$this->boardService->addAcl($this->board->getId(), Acl::PERMISSION_TYPE_USER, self::TEST_USER_2, true, false, true);
|
||||||
$this->boardService->transferOwnership(self::TEST_USER_2, self::TEST_USER_3);
|
$this->boardService->transferOwnership(self::TEST_USER_2, self::TEST_USER_3);
|
||||||
$board = $this->boardService->find($this->board->getId());
|
$board = $this->boardService->find($this->board->getId());
|
||||||
$acl = $board->getAcl();
|
$acl = $board->getAcl();
|
||||||
$isMerged = (bool)array_filter($acl, function ($item) {
|
$isMerged = (bool)array_filter($acl, function ($item) {
|
||||||
return $item->getParticipant() === self::TEST_USER_1
|
return $item->getParticipant() === self::TEST_USER_1
|
||||||
&& $item->getType() === Acl::PERMISSION_TYPE_USER
|
&& $item->getType() === Acl::PERMISSION_TYPE_USER
|
||||||
&& $item->getPermission(Acl::PERMISSION_EDIT)
|
&& $item->getPermission(Acl::PERMISSION_EDIT)
|
||||||
&& $item->getPermission(Acl::PERMISSION_SHARE)
|
&& $item->getPermission(Acl::PERMISSION_SHARE)
|
||||||
&& $item->getPermission(Acl::PERMISSION_MANAGE);
|
&& $item->getPermission(Acl::PERMISSION_MANAGE);
|
||||||
});
|
});
|
||||||
$this->assertTrue($isMerged);
|
$this->assertTrue($isMerged);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::transferOwnership
|
* @covers ::transferOwnership
|
||||||
*/
|
*/
|
||||||
public function testTargetAlreadyParticipantOfCard() {
|
public function testTargetAlreadyParticipantOfCard() {
|
||||||
$this->expectNotToPerformAssertions();
|
$this->expectNotToPerformAssertions();
|
||||||
$this->assignmentService->assignUser($this->cards[0]->getId(), self::TEST_USER_3, AssignedUsers::TYPE_USER);
|
$this->assignmentService->assignUser($this->cards[0]->getId(), self::TEST_USER_3, AssignedUsers::TYPE_USER);
|
||||||
$this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_3);
|
$this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown(): void {
|
public function tearDown(): void {
|
||||||
$this->boardService->deleteForce($this->board->getId());
|
$this->boardService->deleteForce($this->board->getId());
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ class BoardServiceTest extends TestCase {
|
|||||||
private $boardMapper;
|
private $boardMapper;
|
||||||
/** @var StackMapper */
|
/** @var StackMapper */
|
||||||
private $stackMapper;
|
private $stackMapper;
|
||||||
/** @var CardMapper */
|
/** @var CardMapper */
|
||||||
private $cardMapper;
|
private $cardMapper;
|
||||||
/** @var PermissionService */
|
/** @var PermissionService */
|
||||||
private $permissionService;
|
private $permissionService;
|
||||||
/** @var NotificationHelper */
|
/** @var NotificationHelper */
|
||||||
|
|||||||
Reference in New Issue
Block a user