Skip to content

Commit

Permalink
Merge pull request #1 from arawa/task/2919/room_shared_list_for_moder…
Browse files Browse the repository at this point in the history
…ators_and_users

feat: list all shared rooms for users and moderators
  • Loading branch information
smarinier authored May 15, 2024
2 parents 5935c09 + 9538c35 commit 081d2b9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
3 changes: 3 additions & 0 deletions lib/Db/Room.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Room extends Entity implements JsonSerializable {
public $cleanLayout;
public $joinMuted;
public $running;
public $permission;

public function __construct() {
$this->addType('maxParticipants', 'integer');
Expand All @@ -86,6 +87,7 @@ public function __construct() {
$this->addType('cleanLayout', 'boolean');
$this->addType('joinMuted', 'boolean');
$this->addType('running', 'boolean');
$this->addType('permission', 'integer');
}

public function jsonSerialize(): array {
Expand All @@ -102,6 +104,7 @@ public function jsonSerialize(): array {
'everyoneIsModerator' => boolval($this->everyoneIsModerator),
'requireModerator' => boolval($this->requireModerator),
'shared' => boolval($this->shared),
'permission' => $this->permission,
'moderatorToken' => $this->moderatorToken,
'listenOnly' => boolval($this->listenOnly),
'mediaCheck' => boolval($this->mediaCheck),
Expand Down
31 changes: 15 additions & 16 deletions lib/Db/RoomMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,24 @@ public function __construct(IDBConnection $db) {
parent::__construct($db, 'bbb_rooms', Room::class);
}

private function joinShares(IQueryBuilder $qb): IQueryBuilder {
$qb->select('r.*')
->from($this->tableName, 'r')
->leftJoin('r', 'bbb_room_shares', 's', $qb->expr()->eq('r.id', 's.room_id'))
->addSelect($qb->createFunction('count(case when `s`.`permission` IN ('.
RoomShare::PERMISSION_ADMIN.','.RoomShare::PERMISSION_MODERATOR.','.RoomShare::PERMISSION_USER
.') then 1 else null end) as shared'));
return $qb;
}

/**
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws DoesNotExistException
*/
public function find(int $id): Room {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$qb->select('r.*')
->from($this->tableName, 'r')
->leftJoin('r', 'bbb_room_shares', 's', $qb->expr()->eq('r.id', 's.room_id'))
->addSelect($qb->createFunction('count(case when `s`.`permission` = 0 then 1 else null end) as shared'))
$this->joinShares($qb)
->where($qb->expr()->eq('r.id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
->groupBy('r.id');
;
Expand All @@ -38,10 +45,7 @@ public function find(int $id): Room {
public function findByUid(string $uid): Room {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$qb->select('r.*')
->from($this->tableName, 'r')
->leftJoin('r', 'bbb_room_shares', 's', $qb->expr()->eq('r.id', 's.room_id'))
->addSelect($qb->createFunction('count(case when `s`.`permission` = 0 then 1 else null end) as shared'))
$this->joinShares($qb)
->where($qb->expr()->eq('r.uid', $qb->createNamedParameter($uid)))
->groupBy('r.id');
;
Expand Down Expand Up @@ -70,25 +74,20 @@ public function findByUserId(string $userId): array {
public function findAll(string $userId, array $groupIds, array $circleIds): array {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$qb->select('r.*')
->from($this->tableName, 'r')
->leftJoin('r', 'bbb_room_shares', 's', $qb->expr()->eq('r.id', 's.room_id'))
->addSelect($qb->createFunction('count(case when `s`.`permission` = 0 then 1 else null end) as shared'))
$this->joinShares($qb)
->addSelect($qb->createFunction('min(case when '.$qb->expr()->eq('r.user_id', $qb->createNamedParameter($userId)).' then '.RoomShare::PERMISSION_ADMIN.' else `s`.`permission` end) as permission'))
->where(
$qb->expr()->orX(
$qb->expr()->eq('r.user_id', $qb->createNamedParameter($userId)),
$qb->expr()->andX(
$qb->expr()->eq('s.permission', $qb->createNamedParameter(RoomShare::PERMISSION_ADMIN, IQueryBuilder::PARAM_INT)),
$qb->expr()->eq('s.share_type', $qb->createNamedParameter(RoomShare::SHARE_TYPE_USER, IQueryBuilder::PARAM_INT)),
$qb->expr()->eq('s.share_with', $qb->createNamedParameter($userId))
),
$qb->expr()->andX(
$qb->expr()->eq('s.permission', $qb->createNamedParameter(RoomShare::PERMISSION_ADMIN, IQueryBuilder::PARAM_INT)),
$qb->expr()->eq('s.share_type', $qb->createNamedParameter(RoomShare::SHARE_TYPE_GROUP, IQueryBuilder::PARAM_INT)),
$qb->expr()->in('s.share_with', $qb->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY))
),
$qb->expr()->andX(
$qb->expr()->eq('s.permission', $qb->createNamedParameter(RoomShare::PERMISSION_ADMIN, IQueryBuilder::PARAM_INT)),
$qb->expr()->eq('s.share_type', $qb->createNamedParameter(RoomShare::SHARE_TYPE_CIRCLE, IQueryBuilder::PARAM_INT)),
$qb->expr()->in('s.share_with', $qb->createNamedParameter($circleIds, IQueryBuilder::PARAM_STR_ARRAY))
)
Expand All @@ -99,7 +98,7 @@ public function findAll(string $userId, array $groupIds, array $circleIds): arra
/** @var array<Room> */
return $this->findEntities($qb);
}

/**
* @return array<Room>
*/
Expand Down

0 comments on commit 081d2b9

Please sign in to comment.