diff options
author | Joas Schilling <coding@schilljs.com> | 2021-09-27 17:54:29 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2021-10-07 19:18:31 +0300 |
commit | e115e96d7daa11b70fb270f59825894535f10c7c (patch) | |
tree | 6b9c78e0325c0a33106ea2b3cc1aa6b5e20697fa /lib/Service | |
parent | 1c641f8c64a80753fc46ec27e622c696f1f93fc8 (diff) |
Remove moderator option and clear custom permissions when setting the conversation permissions
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Service')
-rw-r--r-- | lib/Service/ParticipantService.php | 4 | ||||
-rw-r--r-- | lib/Service/RoomService.php | 42 |
2 files changed, 43 insertions, 3 deletions
diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php index 12dcad0f8..bd7f09f07 100644 --- a/lib/Service/ParticipantService.php +++ b/lib/Service/ParticipantService.php @@ -162,12 +162,12 @@ class ParticipantService { $this->dispatcher->dispatch(Room::EVENT_AFTER_PARTICIPANT_PERMISSIONS_SET, $event); } - public function updateAllPermissions(Room $room, string $mode, int $newState, bool $includeModerators): void { + 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, $includeModerators); + $this->attendeeMapper->modifyPermissions($room->getId(), $mode, $newState); // FIXME Add events after checking what should be sent to the HPB // $this->dispatcher->dispatch(Room::EVENT_AFTER_PARTICIPANT_PERMISSIONS_SET, $event); diff --git a/lib/Service/RoomService.php b/lib/Service/RoomService.php index 9667f7193..6a1fbf57f 100644 --- a/lib/Service/RoomService.php +++ b/lib/Service/RoomService.php @@ -24,11 +24,13 @@ declare(strict_types=1); namespace OCA\Talk\Service; use InvalidArgumentException; +use OCA\Talk\Events\ModifyRoomEvent; use OCA\Talk\Exceptions\RoomNotFoundException; use OCA\Talk\Manager; use OCA\Talk\Model\Attendee; use OCA\Talk\Participant; use OCA\Talk\Room; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IUser; class RoomService { @@ -37,11 +39,15 @@ class RoomService { protected $manager; /** @var ParticipantService */ protected $participantService; + /** @var IEventDispatcher */ + private $dispatcher; public function __construct(Manager $manager, - ParticipantService $participantService) { + ParticipantService $participantService, + IEventDispatcher $dispatcher) { $this->manager = $manager; $this->participantService = $participantService; + $this->dispatcher = $dispatcher; } /** @@ -139,4 +145,38 @@ class RoomService { public function prepareConversationName(string $objectName): string { 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 { + return false; + } + + if ($newPermissions < Attendee::PERMISSIONS_DEFAULT || $newPermissions > Attendee::PERMISSIONS_MAX_CUSTOM) { + return false; + } + + if (!in_array($room->getType(), [Room::TYPE_GROUP, Room::TYPE_PUBLIC], true)) { + return false; + } + + if ($newPermissions === $oldPermissions) { + return true; + } + + $event = new ModifyRoomEvent($room, $mode . '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); + + $room->setPermissions($mode, $newPermissions); + + $this->dispatcher->dispatch(Room::EVENT_AFTER_PERMISSIONS_SET, $event); + + return true; + } } |