feat(emails): Allow banning email guests

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2024-10-18 10:56:16 +02:00
parent 3ba5adfc4a
commit de5200a836
No known key found for this signature in database
GPG key ID: F72FA5B49FFA96B0
2 changed files with 13 additions and 9 deletions

View file

@ -37,7 +37,7 @@ class BanController extends AEnvironmentAwareController {
*
* 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{}>

View file

@ -49,7 +49,7 @@ class BanService {
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');
}
@ -81,7 +81,7 @@ class BanService {
/** @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();
@ -120,7 +120,7 @@ class BanService {
// No failure if the banned actor is not in the room yet/anymore
}
}
return $this->banMapper->insert($ban);
}
@ -156,14 +156,19 @@ class BanService {
$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');
@ -171,11 +176,10 @@ class BanService {
}
}
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)) {