Browse Source

fix(api): Properly typed recordingConsent update

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/13167/head
Joas Schilling 1 year ago
parent
commit
3e761acdf2
No known key found for this signature in database GPG Key ID: 74434EFE0D2E2205
  1. 7
      lib/Controller/RoomController.php
  2. 31
      lib/Exceptions/RoomProperty/RecordingConsentException.php
  3. 15
      lib/Service/RoomService.php

7
lib/Controller/RoomController.php

@ -18,6 +18,7 @@ use OCA\Talk\Exceptions\InvalidPasswordException;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Exceptions\RoomProperty\DefaultPermissionsException;
use OCA\Talk\Exceptions\RoomProperty\RecordingConsentException;
use OCA\Talk\Exceptions\RoomProperty\SipConfigurationException;
use OCA\Talk\Exceptions\UnauthorizedException;
use OCA\Talk\Federation\Authenticator;
@ -2284,7 +2285,7 @@ class RoomController extends AEnvironmentAwareController {
* @param int $recordingConsent New consent setting for the conversation
* (Only {@see RecordingService::CONSENT_REQUIRED_NO} and {@see RecordingService::CONSENT_REQUIRED_YES} are allowed here.)
* @psalm-param RecordingService::CONSENT_REQUIRED_NO|RecordingService::CONSENT_REQUIRED_YES $recordingConsent
* @return DataResponse<Http::STATUS_OK, TalkRoom, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: string}, array{}>|DataResponse<Http::STATUS_PRECONDITION_FAILED, array<empty>, array{}>
* @return DataResponse<Http::STATUS_OK, TalkRoom, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: 'breakout-room'|'call'|'value'}, array{}>|DataResponse<Http::STATUS_PRECONDITION_FAILED, array<empty>, array{}>
*
* 200: Recording consent requirement set successfully
* 400: Setting recording consent requirement is not possible
@ -2299,8 +2300,8 @@ class RoomController extends AEnvironmentAwareController {
try {
$this->roomService->setRecordingConsent($this->room, $recordingConsent);
} catch (\InvalidArgumentException $exception) {
return new DataResponse(['error' => $exception->getMessage()], Http::STATUS_BAD_REQUEST);
} catch (RecordingConsentException $e) {
return new DataResponse(['error' => $e->getReason()], Http::STATUS_BAD_REQUEST);
}
return new DataResponse($this->formatRoom($this->room, $this->participant));

31
lib/Exceptions/RoomProperty/RecordingConsentException.php

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Talk\Exceptions\RoomProperty;
class RecordingConsentException extends \InvalidArgumentException {
public const REASON_BREAKOUT_ROOM = 'breakout-room';
public const REASON_CALL = 'call';
public const REASON_VALUE = 'value';
/**
* @param self::REASON_* $reason
*/
public function __construct(
protected string $reason,
) {
parent::__construct($reason);
}
/**
* @return self::REASON_*
*/
public function getReason(): string {
return $this->reason;
}
}

15
lib/Service/RoomService.php

@ -28,6 +28,7 @@ use OCA\Talk\Events\RoomPasswordVerifyEvent;
use OCA\Talk\Events\RoomSyncedEvent;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Exceptions\RoomProperty\DefaultPermissionsException;
use OCA\Talk\Exceptions\RoomProperty\RecordingConsentException;
use OCA\Talk\Exceptions\RoomProperty\SipConfigurationException;
use OCA\Talk\Manager;
use OCA\Talk\Model\Attendee;
@ -275,7 +276,7 @@ class RoomService {
/**
* @psalm-param RecordingService::CONSENT_REQUIRED_* $recordingConsent
* @throws InvalidArgumentException When the room has an active call or the value is invalid
* @throws RecordingConsentException When the room has an active call or the value is invalid
*/
public function setRecordingConsent(Room $room, int $recordingConsent, bool $allowUpdatingBreakoutRooms = false): void {
$oldRecordingConsent = $room->getRecordingConsent();
@ -285,19 +286,19 @@ class RoomService {
}
if (!in_array($recordingConsent, [RecordingService::CONSENT_REQUIRED_NO, RecordingService::CONSENT_REQUIRED_YES], true)) {
throw new InvalidArgumentException('value');
throw new RecordingConsentException(RecordingConsentException::REASON_VALUE);
}
if ($recordingConsent !== RecordingService::CONSENT_REQUIRED_NO && $room->getCallFlag() !== Participant::FLAG_DISCONNECTED) {
throw new InvalidArgumentException('call');
throw new RecordingConsentException(RecordingConsentException::REASON_CALL);
}
if (!$allowUpdatingBreakoutRooms && $room->getObjectType() === BreakoutRoom::PARENT_OBJECT_TYPE) {
throw new InvalidArgumentException('breakout-room');
throw new RecordingConsentException(RecordingConsentException::REASON_BREAKOUT_ROOM);
}
if ($room->getBreakoutRoomStatus() !== BreakoutRoom::STATUS_STOPPED) {
throw new InvalidArgumentException('breakout-room');
throw new RecordingConsentException(RecordingConsentException::REASON_BREAKOUT_ROOM);
}
$event = new BeforeRoomModifiedEvent($room, ARoomModifiedEvent::PROPERTY_RECORDING_CONSENT, $recordingConsent, $oldRecordingConsent);
@ -1119,8 +1120,8 @@ class RoomService {
try {
$this->setRecordingConsent($local, $host['recordingConsent'], true);
$changed[] = ARoomModifiedEvent::PROPERTY_RECORDING_CONSENT;
} catch (\InvalidArgumentException $e) {
$this->logger->error('An error (' . $e->getMessage() . ') occurred while trying to sync recordingConsent of ' . $local->getId() . ' to ' . $host['recordingConsent'], ['exception' => $e]);
} catch (RecordingConsentException $e) {
$this->logger->error('An error (' . $e->getReason() . ') occurred while trying to sync recordingConsent of ' . $local->getId() . ' to ' . $host['recordingConsent'], ['exception' => $e]);
}
}
if (isset($host['sipEnabled']) && $host['sipEnabled'] !== $local->getSIPEnabled()) {

Loading…
Cancel
Save