Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: Extract method to get the base query for setting permissions
Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu committed Aug 17, 2024
commit a974742ec69cde24fbe64f129d5387421e1007bd
20 changes: 13 additions & 7 deletions lib/Model/AttendeeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,7 @@ public function deleteByIds(array $ids): int {
}

public function modifyPermissions(int $roomId, string $mode, int $newState): void {
$query = $this->db->getQueryBuilder();
$query->update($this->getTableName())
->where($query->expr()->eq('room_id', $query->createNamedParameter($roomId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->notIn('actor_type', $query->createNamedParameter([
Attendee::ACTOR_CIRCLES,
Attendee::ACTOR_GROUPS,
], IQueryBuilder::PARAM_STR_ARRAY)));
$query = $this->getModifyPermissionsBaseQuery($roomId);

if ($mode === Attendee::PERMISSIONS_MODIFY_SET) {
if ($newState !== Attendee::PERMISSIONS_DEFAULT) {
Expand Down Expand Up @@ -237,6 +231,18 @@ public function modifyPermissions(int $roomId, string $mode, int $newState): voi
}
}

protected function getModifyPermissionsBaseQuery(int $roomId): IQueryBuilder {
$query = $this->db->getQueryBuilder();
$query->update($this->getTableName())
->where($query->expr()->eq('room_id', $query->createNamedParameter($roomId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->notIn('actor_type', $query->createNamedParameter([
Attendee::ACTOR_CIRCLES,
Attendee::ACTOR_GROUPS,
], IQueryBuilder::PARAM_STR_ARRAY)));

return $query;
}

protected function addSinglePermission(IQueryBuilder $query, int $permission): void {
$query->set('permissions', $query->func()->add(
'permissions',
Expand Down