|DataResponse * * 200: Ban successfully * 400: Actor information is invalid */ #[PublicPage] #[RequireModeratorParticipant] #[ApiRoute(verb: 'POST', url: '/api/{apiVersion}/ban/{token}', requirements: [ 'apiVersion' => '(v1)', 'token' => '[a-z0-9]{4,30}', ])] public function banActor(string $actorType, string $actorId, string $internalNote = ''): DataResponse { try { $moderator = $this->participant->getAttendee(); $ban = $this->banService->createBan( $this->room, $moderator->getActorType(), $moderator->getActorId(), $moderator->getDisplayName(), $actorType, $actorId, $this->timeFactory->getDateTime(), $internalNote ); return new DataResponse($ban->jsonSerialize(), Http::STATUS_OK); } catch (\InvalidArgumentException $e) { /** @var 'bannedActor'|'internalNote'|'moderator'|'self' $message */ $message = $e->getMessage(); return new DataResponse([ 'error' => $message, ], Http::STATUS_BAD_REQUEST); } } /** * List the bans of a conversation * * Required capability: `ban-v1` * * @return DataResponse, array{}> * * 200: List all bans */ #[PublicPage] #[RequireModeratorParticipant] #[ApiRoute(verb: 'GET', url: '/api/{apiVersion}/ban/{token}', requirements: [ 'apiVersion' => '(v1)', 'token' => '[a-z0-9]{4,30}', ])] public function listBans(): DataResponse { $bans = $this->banService->getBansForRoom($this->room->getId()); $result = array_map(static fn (Ban $ban): array => $ban->jsonSerialize(), $bans); return new DataResponse($result, Http::STATUS_OK); } /** * Unban an actor or IP address * * Required capability: `ban-v1` * * @param int $banId ID of the ban to be removed * @return DataResponse * * 200: Unban successfully or not found */ #[PublicPage] #[RequireModeratorParticipant] #[ApiRoute(verb: 'DELETE', url: '/api/{apiVersion}/ban/{token}/{banId}', requirements: [ 'apiVersion' => '(v1)', 'token' => '[a-z0-9]{4,30}', 'banId' => '[0-9]{1,64}', ])] public function unbanActor(int $banId): DataResponse { $this->banService->findAndDeleteBanByIdForRoom($banId, $this->room->getId()); return new DataResponse(null, Http::STATUS_OK); } }