Merge pull request #4949 from nextcloud/backport/4906/stable27

This commit is contained in:
Julius Härtl
2023-07-24 18:12:53 +02:00
committed by GitHub

View File

@@ -106,28 +106,36 @@ class BoardMapper extends QBMapper implements IPermissionMapper {
} }
public function findBoardIds(string $userId): array { public function findBoardIds(string $userId): array {
// Owned by the user
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
$qb->selectDistinct('b.id') $qb->selectDistinct('b.id')
->from($this->getTableName(), 'b') ->from($this->getTableName(), 'b')
->leftJoin('b', 'deck_board_acl', 'acl', $qb->expr()->eq('b.id', 'acl.board_id')); ->where($qb->expr()->andX(
// Owned by the user
$qb->where($qb->expr()->andX(
$qb->expr()->eq('owner', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)), $qb->expr()->eq('owner', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)),
)); ));
$result = $qb->executeQuery();
$ownerBoards = array_map(function (string $id) {
return (int)$id;
}, $result->fetchAll(\PDO::FETCH_COLUMN));
$result->closeCursor();
$qb = $this->db->getQueryBuilder();
$qb->selectDistinct('b.id')
->from($this->getTableName(), 'b')
->innerJoin('b', 'deck_board_acl', 'acl', $qb->expr()->eq('b.id', 'acl.board_id'));
// Shared to the user // Shared to the user
$qb->orWhere($qb->expr()->andX( $qb->where($qb->expr()->andX(
$qb->expr()->eq('acl.participant', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('acl.type', $qb->createNamedParameter(Acl::PERMISSION_TYPE_USER, IQueryBuilder::PARAM_INT)), $qb->expr()->eq('acl.type', $qb->createNamedParameter(Acl::PERMISSION_TYPE_USER, IQueryBuilder::PARAM_INT)),
$qb->expr()->eq('acl.participant', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)),
)); ));
// Shared to user groups of the user // Shared to user groups of the user
$groupIds = $this->groupManager->getUserGroupIds($this->userManager->get($userId)); $groupIds = $this->groupManager->getUserGroupIds($this->userManager->get($userId));
if (count($groupIds) !== 0) { if (count($groupIds) !== 0) {
$qb->orWhere($qb->expr()->andX( $qb->orWhere($qb->expr()->andX(
$qb->expr()->in('acl.participant', $qb->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY)),
$qb->expr()->eq('acl.type', $qb->createNamedParameter(Acl::PERMISSION_TYPE_GROUP, IQueryBuilder::PARAM_INT)), $qb->expr()->eq('acl.type', $qb->createNamedParameter(Acl::PERMISSION_TYPE_GROUP, IQueryBuilder::PARAM_INT)),
$qb->expr()->in('acl.participant', $qb->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY)),
)); ));
} }
@@ -135,15 +143,17 @@ class BoardMapper extends QBMapper implements IPermissionMapper {
$circles = $this->circlesService->getUserCircles($userId); $circles = $this->circlesService->getUserCircles($userId);
if (count($circles) !== 0) { if (count($circles) !== 0) {
$qb->orWhere($qb->expr()->andX( $qb->orWhere($qb->expr()->andX(
$qb->expr()->in('acl.participant', $qb->createNamedParameter($circles, IQueryBuilder::PARAM_STR_ARRAY)),
$qb->expr()->eq('acl.type', $qb->createNamedParameter(Acl::PERMISSION_TYPE_CIRCLE, IQueryBuilder::PARAM_INT)), $qb->expr()->eq('acl.type', $qb->createNamedParameter(Acl::PERMISSION_TYPE_CIRCLE, IQueryBuilder::PARAM_INT)),
$qb->expr()->in('acl.participant', $qb->createNamedParameter($circles, IQueryBuilder::PARAM_STR_ARRAY)),
)); ));
} }
$result = $qb->executeQuery(); $result = $qb->executeQuery();
return array_map(function (string $id) { $sharedBoards = array_map(function (string $id) {
return (int)$id; return (int)$id;
}, $result->fetchAll(\PDO::FETCH_COLUMN)); }, $result->fetchAll(\PDO::FETCH_COLUMN));
$result->closeCursor();
return array_unique(array_merge($ownerBoards, $sharedBoards));
} }
public function findAllForUser(string $userId, ?int $since = null, bool $includeArchived = true, ?int $before = null, public function findAllForUser(string $userId, ?int $since = null, bool $includeArchived = true, ?int $before = null,