Skip to content

Commit

Permalink
fix: When banning a user they are also removed from the room
Browse files Browse the repository at this point in the history
Signed-off-by: skalidindi53 <s.teja2004@gmail.com>
  • Loading branch information
skalidindi53 committed Aug 12, 2024
1 parent e3ce3b9 commit c0f36e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lib/Service/BanService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace OCA\Talk\Service;

use DateTime;
use OCA\Talk\Events\AAttendeeRemovedEvent;
use OCA\Talk\Exceptions\ForbiddenException;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Manager;
Expand Down Expand Up @@ -110,6 +111,14 @@ public function createBan(Room $room, string $moderatorActorType, string $modera
$ban->setBannedTime($bannedTime);
$ban->setInternalNote($internalNote);

//Remove the banned user from the room
try {
$bannedParticipant = $this->participantService->getParticipantByActor($room, $bannedActorType, $bannedActorId);
$this->participantService->removeAttendee($room, $bannedParticipant, AAttendeeRemovedEvent::REASON_REMOVED);
} catch (ParticipantNotFoundException) {
// No failure if the banned actor is not in the room yet/anymore
}

return $this->banMapper->insert($ban);
}

Expand Down
6 changes: 4 additions & 2 deletions tests/integration/features/conversation-1/ban.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Feature: conversation/ban
| users | participant1 | participant1-displayname | users | participant3 | participant3-displayname | BannedP3 |
And user "participant2" joins room "room" with 403 (v4)
And user "participant3" joins room "room" with 403 (v4)
And user "participant1" removes "participant2" from room "room" with 404 (v4)
And user "participant1" removes "participant3" from room "room" with 404 (v4)
And user "participant1" unbans user "participant2" from room "room" with 200 (v1)
And user "participant1" unbans user "participant3" from room "room" with 200 (v1)
And user "participant2" joins room "room" with 200 (v4)
Expand Down Expand Up @@ -110,8 +112,8 @@ Feature: conversation/ban
And user "participant2" sends message "Message 1" to room "room" with 201
When user "participant1" bans user "participant2" from room "room" with 200 (v1)
| internalNote | BannedP2 |
And user "participant2" sends message "Message 2" to room "room" with 403
And user "participant2" react with "👍" on message "Message 1" to room "room" with 403
And user "participant2" sends message "Message 2" to room "room" with 404
And user "participant2" react with "👍" on message "Message 1" to room "room" with 404

Scenario: Banning a guest bans their IP as well
Given user "participant1" creates room "room" (v4)
Expand Down

0 comments on commit c0f36e9

Please sign in to comment.