Skip to content
Merged
Show file tree
Hide file tree
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
feat(emails): Allow banning email guests
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen authored and backportbot[bot] committed Oct 23, 2024
commit b67d2f1bf8959dcca56da95f5aedb7c2b148f9eb
2 changes: 1 addition & 1 deletion lib/Controller/BanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(
*
* Required capability: `ban-v1`
*
* @param 'users'|'guests'|'ip' $actorType Type of actor to ban, or `ip` when banning a clients remote address
* @param 'users'|'guests'|'emails'|'ip' $actorType Type of actor to ban, or `ip` when banning a clients remote address
* @param string $actorId Actor ID or the IP address or range in case of type `ip`
* @param string $internalNote Optional internal note (max. 4000 characters)
* @return DataResponse<Http::STATUS_OK, TalkBan, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: 'bannedActor'|'internalNote'|'moderator'|'self'|'room'}, array{}>
Expand Down
20 changes: 12 additions & 8 deletions lib/Service/BanService.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function createBan(Room $room, string $moderatorActorType, string $modera
throw new \InvalidArgumentException('room');
}

if (!in_array($bannedActorType, [Attendee::ACTOR_USERS, Attendee::ACTOR_GUESTS, 'ip'], true)) {
if (!in_array($bannedActorType, [Attendee::ACTOR_USERS, Attendee::ACTOR_GUESTS, Attendee::ACTOR_EMAILS, 'ip'], true)) {
throw new \InvalidArgumentException('bannedActor');
}

Expand Down Expand Up @@ -81,7 +81,7 @@ public function createBan(Room $room, string $moderatorActorType, string $modera

/** @var ?string $displayname */
$displayname = null;
if (in_array($bannedActorType, [Attendee::ACTOR_USERS, Attendee::ACTOR_GUESTS], true)) {
if (in_array($bannedActorType, [Attendee::ACTOR_USERS, Attendee::ACTOR_EMAILS, Attendee::ACTOR_GUESTS], true)) {
try {
$bannedParticipant = $this->participantService->getParticipantByActor($room, $bannedActorType, $bannedActorId);
$displayname = $bannedParticipant->getAttendee()->getDisplayName();
Expand Down Expand Up @@ -120,7 +120,7 @@ public function createBan(Room $room, string $moderatorActorType, string $modera
// No failure if the banned actor is not in the room yet/anymore
}
}

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

Expand Down Expand Up @@ -156,26 +156,30 @@ public function throwIfActorIsBanned(Room $room, ?string $userId): void {
$actorType = Attendee::ACTOR_USERS;
$actorId = $userId;
} else {
$actorType = Attendee::ACTOR_GUESTS;
$actorId = $this->talkSession->getGuestActorIdForRoom($room->getToken());
$actorId = $this->talkSession->getAuthedEmailActorIdForRoom($room->getToken());
if ($actorId !== null) {
$actorType = Attendee::ACTOR_EMAILS;
} else {
$actorId = $this->talkSession->getGuestActorIdForRoom($room->getToken());
$actorType = Attendee::ACTOR_GUESTS;
}
}

if ($actorId !== null) {
try {
$ban = $this->banMapper->findForBannedActorAndRoom($actorType, $actorId, $room->getId());
if ($actorType === Attendee::ACTOR_GUESTS) {
if (in_array($actorType, [Attendee::ACTOR_GUESTS, Attendee::ACTOR_EMAILS], true)) {
$this->copyBanForRemoteAddress($ban, $this->request->getRemoteAddress());
}
throw new ForbiddenException('actor');
} catch (DoesNotExistException) {
}
}

if ($actorType !== Attendee::ACTOR_GUESTS) {
if (!in_array($actorType, [Attendee::ACTOR_GUESTS, Attendee::ACTOR_EMAILS], true)) {
return;
}


$ipBans = $this->banMapper->findByRoomId($room->getId(), 'ip');

if (empty($ipBans)) {
Expand Down