diff options
author | Joas Schilling <coding@schilljs.com> | 2021-03-31 13:00:47 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2021-03-31 14:19:05 +0300 |
commit | 44a7308254ab24de85aa4b9f63f496c53ece3a73 (patch) | |
tree | 3bda2c288abab6ae5c99fa657b57f0285709bbf2 /lib/Service | |
parent | 5730ef0a7805e4bb08a76a03e76a574de666adb6 (diff) |
Only remove users and not moderators when a group (membership) is removed
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Service')
-rw-r--r-- | lib/Service/ParticipantService.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php index 448740a3c..ae4527260 100644 --- a/lib/Service/ParticipantService.php +++ b/lib/Service/ParticipantService.php @@ -479,6 +479,43 @@ class ParticipantService { } else { $this->dispatcher->dispatch(Room::EVENT_AFTER_PARTICIPANT_REMOVE, $event); } + + if ($participant->getAttendee()->getActorType() === Attendee::ACTOR_GROUPS) { + $this->removeGroupMembers($room, $participant, $reason); + } + } + + public function removeGroupMembers(Room $room, Participant $removedGroupParticipant, string $reason): void { + $removedGroup = $this->groupManager->get($removedGroupParticipant->getAttendee()->getActorId()); + if (!$removedGroup instanceof IGroup) { + return; + } + + $attendeeGroups = $this->attendeeMapper->getActorsByType($room->getId(), Attendee::ACTOR_GROUPS); + + $groupsInRoom = []; + foreach ($attendeeGroups as $attendee) { + $groupsInRoom[] = $attendee->getActorId(); + } + + foreach ($removedGroup->getUsers() as $user) { + try { + $participant = $room->getParticipant($user->getUID()); + } catch (ParticipantNotFoundException $e) { + continue; + } + + $userGroups = $this->groupManager->getUserGroupIds($user); + $stillHasGroup = array_intersect($userGroups, $groupsInRoom); + if (!empty($stillHasGroup)) { + continue; + } + + if ($participant->getAttendee()->getParticipantType() === Participant::USER) { + // Only remove normal users, not moderators/admins + $this->removeAttendee($room, $participant, $reason); + } + } } public function removeUser(Room $room, IUser $user, string $reason): void { |