fix(ban): Ensure the ban is from the current room

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2024-07-10 12:29:02 +02:00
parent ec399445f2
commit a24bb4c188
No known key found for this signature in database
GPG key ID: 74434EFE0D2E2205
3 changed files with 7 additions and 6 deletions

View file

@ -104,7 +104,7 @@ class BanController extends AEnvironmentAwareController {
#[PublicPage]
#[RequireModeratorParticipant]
public function unbanActor(int $banId): DataResponse {
$this->banService->findAndDeleteBanById($banId);
$this->banService->findAndDeleteBanByIdForRoom($banId, $this->room->getId());
return new DataResponse([], Http::STATUS_OK);
}

View file

@ -52,11 +52,12 @@ class BanMapper extends QBMapper {
/**
* @throws DoesNotExistException
*/
public function findByBanId(int $banId): Ban {
public function findByBanIdAndRoom(int $banId, int $roomId): Ban {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from($this->getTableName())
->where($query->expr()->eq('id', $query->createNamedParameter($banId, IQueryBuilder::PARAM_INT)));
->where($query->expr()->eq('id', $query->createNamedParameter($banId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('room_id', $query->createNamedParameter($roomId, IQueryBuilder::PARAM_INT)));
return $this->findEntity($query);
}

View file

@ -37,7 +37,7 @@ class BanService {
if (empty($internalNote)) {
throw new \InvalidArgumentException("invalid_internalNote.");
}
if ($bannedTime !== null && !$bannedTime instanceof DateTime) {
throw new \InvalidArgumentException("invalid_bannedTime.");
}
@ -97,9 +97,9 @@ class BanService {
/**
* Retrieve a ban by its ID and delete it.
*/
public function findAndDeleteBanById(int $banId): void {
public function findAndDeleteBanByIdForRoom(int $banId, int $roomId): void {
try {
$ban = $this->banMapper->findByBanId($banId);
$ban = $this->banMapper->findByBanIdAndRoom($banId, $roomId);
$this->banMapper->delete($ban);
} catch (DoesNotExistException $e) {
// Ban does not exist