diff options
author | Joas Schilling <coding@schilljs.com> | 2021-09-29 11:54:44 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2021-10-07 19:18:31 +0300 |
commit | 984c8bd0f1365430464b835d708892a787742999 (patch) | |
tree | 6e4f741aac1ad254f9824ad3905b9319b45ab9c4 /lib/Service | |
parent | 118a6d2ded963942baee339d24b67dd3506ed12e (diff) |
Unify the endpoints and permissions update handling
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Service')
-rw-r--r-- | lib/Service/ParticipantService.php | 41 | ||||
-rw-r--r-- | lib/Service/RoomService.php | 41 |
2 files changed, 49 insertions, 33 deletions
diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php index bd7f09f07..4492f75d7 100644 --- a/lib/Service/ParticipantService.php +++ b/lib/Service/ParticipantService.php @@ -139,38 +139,45 @@ class ParticipantService { $this->dispatcher->dispatch(Room::EVENT_AFTER_PARTICIPANT_TYPE_SET, $event); } - public function updatePermissions(Room $room, Participant $participant, int $newState): void { + public function updatePermissions(Room $room, Participant $participant, string $method, int $newPermissions): bool { + if ($room->getType() === Room::TYPE_ONE_TO_ONE) { + return false; + } + $attendee = $participant->getAttendee(); if ($attendee->getActorType() === Attendee::ACTOR_GROUPS || $attendee->getActorType() === Attendee::ACTOR_CIRCLES) { // Can not set publishing permissions for those actor types - return; + return false; } - $oldState = $participant->getPermissions(); - if ($newState !== Attendee::PERMISSIONS_DEFAULT) { - // Make sure the custom flag is set when not setting to default permissions - $newState |= Attendee::PERMISSIONS_CUSTOM; + $oldPermissions = $participant->getPermissions(); + if ($method === Participant::PERMISSIONS_MODIFY_SET) { + if ($newPermissions !== Attendee::PERMISSIONS_DEFAULT) { + // Make sure the custom flag is set when not setting to default permissions + $newPermissions |= Attendee::PERMISSIONS_CUSTOM; + } + } elseif ($method === Participant::PERMISSIONS_MODIFY_ADD) { + $newPermissions = $oldPermissions | $newPermissions; + } elseif ($method === Participant::PERMISSIONS_MODIFY_REMOVE) { + $newPermissions = $oldPermissions & ~$newPermissions; + } else { + return false; } - $event = new ModifyParticipantEvent($room, $participant, 'permissions', $newState, $oldState); + $event = new ModifyParticipantEvent($room, $participant, 'permissions', $newPermissions, $oldPermissions); $this->dispatcher->dispatch(Room::EVENT_BEFORE_PARTICIPANT_PERMISSIONS_SET, $event); - $attendee->setPermissions($newState); + $attendee->setPermissions($newPermissions); $this->attendeeMapper->update($attendee); $this->dispatcher->dispatch(Room::EVENT_AFTER_PARTICIPANT_PERMISSIONS_SET, $event); - } - public function updateAllPermissions(Room $room, string $mode, int $newState): void { - // FIXME Add events after checking what should be sent to the HPB - // $event = new ModifyParticipantEvent($room, $participant, 'permissions', $newState, $oldState); - // $this->dispatcher->dispatch(Room::EVENT_BEFORE_PARTICIPANT_PERMISSIONS_SET, $event); - - $this->attendeeMapper->modifyPermissions($room->getId(), $mode, $newState); + return true; + } - // FIXME Add events after checking what should be sent to the HPB - // $this->dispatcher->dispatch(Room::EVENT_AFTER_PARTICIPANT_PERMISSIONS_SET, $event); + public function updateAllPermissions(Room $room, string $method, int $newState): void { + $this->attendeeMapper->modifyPermissions($room->getId(), $method, $newState); } public function updateLastReadMessage(Participant $participant, int $lastReadMessage): void { diff --git a/lib/Service/RoomService.php b/lib/Service/RoomService.php index 6a1fbf57f..f00e83ad5 100644 --- a/lib/Service/RoomService.php +++ b/lib/Service/RoomService.php @@ -146,34 +146,43 @@ class RoomService { return rtrim(mb_substr(ltrim($objectName), 0, 64)); } - public function setPermissions(Room $room, string $mode, int $newPermissions): bool { - if ($mode === 'default') { - $oldPermissions = $room->getDefaultPermissions(); - } elseif ($mode === 'call') { - $oldPermissions = $room->getCallPermissions(); - } else { + public function setPermissions(Room $room, string $level, string $method, int $permissions, bool $resetCustomPermissions): bool { + if ($room->getType() === Room::TYPE_ONE_TO_ONE) { return false; } - if ($newPermissions < Attendee::PERMISSIONS_DEFAULT || $newPermissions > Attendee::PERMISSIONS_MAX_CUSTOM) { + if ($level === 'default') { + $oldPermissions = $room->getDefaultPermissions(); + } elseif ($level === 'call') { + $oldPermissions = $room->getCallPermissions(); + } else { return false; } - if (!in_array($room->getType(), [Room::TYPE_GROUP, Room::TYPE_PUBLIC], true)) { + $newPermissions = $permissions; + if ($method === Participant::PERMISSIONS_MODIFY_SET) { + if ($newPermissions !== Attendee::PERMISSIONS_DEFAULT) { + // Make sure the custom flag is set when not setting to default permissions + $newPermissions |= Attendee::PERMISSIONS_CUSTOM; + } + } elseif ($method === Participant::PERMISSIONS_MODIFY_ADD) { + $newPermissions = $oldPermissions | $newPermissions; + } elseif ($method === Participant::PERMISSIONS_MODIFY_REMOVE) { + $newPermissions = $oldPermissions & ~$newPermissions; + } else { return false; } - if ($newPermissions === $oldPermissions) { - return true; - } - - $event = new ModifyRoomEvent($room, $mode . 'Permissions', $newPermissions, $oldPermissions); + $event = new ModifyRoomEvent($room, $level . 'Permissions', $newPermissions, $oldPermissions); $this->dispatcher->dispatch(Room::EVENT_BEFORE_PERMISSIONS_SET, $event); - // FIXME Make sure participant service is not sending another set of permissions and events - $this->participantService->updateAllPermissions($room, Participant::PERMISSIONS_MODIFY_SET, Attendee::PERMISSIONS_DEFAULT); + if ($resetCustomPermissions) { + $this->participantService->updateAllPermissions($room, Participant::PERMISSIONS_MODIFY_SET, Attendee::PERMISSIONS_DEFAULT); + } else { + $this->participantService->updateAllPermissions($room, $method, $permissions); + } - $room->setPermissions($mode, $newPermissions); + $room->setPermissions($level, $newPermissions); $this->dispatcher->dispatch(Room::EVENT_AFTER_PERMISSIONS_SET, $event); |