diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index f510d8b65e..554b186a3e 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -500,7 +500,7 @@ class RoomController extends AEnvironmentAwareController { * @param string $objectType Type of the object * @param string $objectId ID of the object * @param string $password The room password - * @return DataResponse|DataResponse|DataResponse|DataResponse, array{}> + * @return DataResponse|DataResponse|DataResponse, array{}> * * 200: Room already existed * 201: Room created successfully @@ -651,7 +651,7 @@ class RoomController extends AEnvironmentAwareController { } /** - * @return DataResponse|DataResponse|DataResponse|DataResponse, array{}> + * @return DataResponse|DataResponse|DataResponse, array{}> */ #[NoAdminRequired] protected function createEmptyRoom(string $roomName, bool $public = true, string $objectType = '', string $objectId = '', string $password = ''): DataResponse { @@ -694,7 +694,7 @@ class RoomController extends AEnvironmentAwareController { try { $room = $this->roomService->createConversation($roomType, $roomName, $currentUser, $objectType, $objectId, $password); } catch (PasswordException $e) { - return new DataResponse(['reason' => $e->getReason(), 'hint' => $e->getHint()], Http::STATUS_FORBIDDEN); + return new DataResponse(['error' => 'password', 'hint' => $e->getHint()], Http::STATUS_BAD_REQUEST); } catch (\InvalidArgumentException $e) { return new DataResponse([], Http::STATUS_BAD_REQUEST); } diff --git a/lib/Service/RoomService.php b/lib/Service/RoomService.php index f52f92c0f8..b6c6a914ac 100644 --- a/lib/Service/RoomService.php +++ b/lib/Service/RoomService.php @@ -57,6 +57,7 @@ use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\EventDispatcher\IEventDispatcher; use OCP\HintException; use OCP\IDBConnection; +use OCP\IL10N; use OCP\IUser; use OCP\Log\Audit\CriticalActionPerformedEvent; use OCP\Security\Events\ValidatePasswordPolicyEvent; @@ -80,6 +81,7 @@ class RoomService { protected IEventDispatcher $dispatcher, protected IJobList $jobList, protected LoggerInterface $logger, + protected IL10N $l10n, ) { } @@ -172,7 +174,7 @@ class RoomService { if ($type !== Room::TYPE_PUBLIC || !$this->config->isPasswordEnforced()) { $room = $this->manager->createRoom($type, $name, $objectType, $objectId); } elseif ($password === '') { - throw new PasswordException(PasswordException::REASON_VALUE, 'Password needs to be set'); + throw new PasswordException(PasswordException::REASON_VALUE, $this->l10n->t('Password needs to be set')); } else { $event = new ValidatePasswordPolicyEvent($password); try { diff --git a/tests/php/Service/RoomServiceTest.php b/tests/php/Service/RoomServiceTest.php index 8696ea30ff..0093b2c6fb 100644 --- a/tests/php/Service/RoomServiceTest.php +++ b/tests/php/Service/RoomServiceTest.php @@ -26,6 +26,7 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; use OCP\EventDispatcher\IEventDispatcher; use OCP\IDBConnection; +use OCP\IL10N; use OCP\IUser; use OCP\Security\IHasher; use OCP\Share\IManager as IShareManager; @@ -46,6 +47,7 @@ class RoomServiceTest extends TestCase { protected IEventDispatcher&MockObject $dispatcher; protected IJobList&MockObject $jobList; protected LoggerInterface&MockObject $logger; + private IL10N&MockObject $l10n; protected ?RoomService $service = null; public function setUp(): void { @@ -60,6 +62,7 @@ class RoomServiceTest extends TestCase { $this->dispatcher = $this->createMock(IEventDispatcher::class); $this->jobList = $this->createMock(IJobList::class); $this->logger = $this->createMock(LoggerInterface::class); + $this->l10n = $this->createMock(IL10N::class); $this->service = new RoomService( $this->manager, $this->participantService, @@ -71,6 +74,7 @@ class RoomServiceTest extends TestCase { $this->dispatcher, $this->jobList, $this->logger, + $this->l10n, ); } @@ -332,6 +336,7 @@ class RoomServiceTest extends TestCase { $dispatcher, $this->jobList, $this->logger, + $this->l10n, ); $room = new Room(