diff options
author | Joas Schilling <coding@schilljs.com> | 2023-04-24 16:17:11 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2023-04-25 12:12:19 +0200 |
commit | f39a4299ab8334247b50f0cd42c7e24fe4e184f7 (patch) | |
tree | 52252411a28895247c07f9b9b5289679f0f9897c | |
parent | b2b0bdfba9635ffea0e46b689f5a6f417ae23172 (diff) |
techdebt(controllers): Migrate Talk annotations to attributes
Signed-off-by: Joas Schilling <coding@schilljs.com>
20 files changed, 449 insertions, 304 deletions
diff --git a/lib/Controller/AvatarController.php b/lib/Controller/AvatarController.php index 84a9080d8..d908b6b19 100644 --- a/lib/Controller/AvatarController.php +++ b/lib/Controller/AvatarController.php @@ -27,6 +27,8 @@ declare(strict_types=1); namespace OCA\Talk\Controller; use InvalidArgumentException; +use OCA\Talk\Middleware\Attribute\RequireModeratorParticipant; +use OCA\Talk\Middleware\Attribute\RequireParticipant; use OCA\Talk\Service\AvatarService; use OCA\Talk\Service\RoomFormatter; use OCP\AppFramework\Http; @@ -53,8 +55,8 @@ class AvatarController extends AEnvironmentAwareController { /** * @PublicPage - * @RequireModeratorParticipant */ + #[RequireModeratorParticipant] public function uploadAvatar(): DataResponse { try { $file = $this->request->getUploadedFile('file'); @@ -79,8 +81,8 @@ class AvatarController extends AEnvironmentAwareController { /** * @PublicPage * @NoCSRFRequired - * @RequireParticipant */ + #[RequireParticipant] public function getAvatar(bool $darkTheme = false): Response { $file = $this->avatarService->getAvatar($this->getRoom(), $this->userSession->getUser(), $darkTheme); @@ -94,16 +96,16 @@ class AvatarController extends AEnvironmentAwareController { /** * @PublicPage * @NoCSRFRequired - * @RequireParticipant */ + #[RequireParticipant] public function getAvatarDark(): Response { return $this->getAvatar(true); } /** * @PublicPage - * @RequireModeratorParticipant */ + #[RequireModeratorParticipant] public function deleteAvatar(): DataResponse { $this->avatarService->deleteAvatar($this->getRoom()); return new DataResponse($this->roomFormatter->formatRoom( diff --git a/lib/Controller/BreakoutRoomController.php b/lib/Controller/BreakoutRoomController.php index d35f5143b..459993007 100644 --- a/lib/Controller/BreakoutRoomController.php +++ b/lib/Controller/BreakoutRoomController.php @@ -27,6 +27,8 @@ namespace OCA\Talk\Controller; use InvalidArgumentException; use OCA\Talk\Exceptions\ParticipantNotFoundException; +use OCA\Talk\Middleware\Attribute\RequireLoggedInModeratorParticipant; +use OCA\Talk\Middleware\Attribute\RequireLoggedInParticipant; use OCA\Talk\Service\BreakoutRoomService; use OCA\Talk\Service\ParticipantService; use OCA\Talk\Service\RoomFormatter; @@ -49,13 +51,8 @@ class BreakoutRoomController extends AEnvironmentAwareController { /** * @NoAdminRequired - * @RequireLoggedInModeratorParticipant - * - * @param int $mode - * @param int $amount - * @param string $attendeeMap - * @return DataResponse */ + #[RequireLoggedInModeratorParticipant] public function configureBreakoutRooms(int $mode, int $amount, string $attendeeMap = '[]'): DataResponse { try { $rooms = $this->breakoutRoomService->setupBreakoutRooms($this->room, $mode, $amount, $attendeeMap); @@ -69,8 +66,8 @@ class BreakoutRoomController extends AEnvironmentAwareController { /** * @NoAdminRequired - * @RequireLoggedInModeratorParticipant */ + #[RequireLoggedInModeratorParticipant] public function removeBreakoutRooms(): DataResponse { $this->breakoutRoomService->removeBreakoutRooms($this->room); @@ -84,8 +81,8 @@ class BreakoutRoomController extends AEnvironmentAwareController { /** * @NoAdminRequired - * @RequireLoggedInModeratorParticipant */ + #[RequireLoggedInModeratorParticipant] public function broadcastChatMessage(string $message): DataResponse { try { $rooms = $this->breakoutRoomService->broadcastChatMessage($this->room, $this->participant, $message); @@ -100,8 +97,8 @@ class BreakoutRoomController extends AEnvironmentAwareController { /** * @NoAdminRequired - * @RequireLoggedInModeratorParticipant */ + #[RequireLoggedInModeratorParticipant] public function applyAttendeeMap(string $attendeeMap): DataResponse { try { $rooms = $this->breakoutRoomService->applyAttendeeMap($this->room, $attendeeMap); @@ -114,8 +111,8 @@ class BreakoutRoomController extends AEnvironmentAwareController { /** * @NoAdminRequired - * @RequireLoggedInParticipant */ + #[RequireLoggedInParticipant] public function requestAssistance(): DataResponse { try { $this->breakoutRoomService->requestAssistance($this->room); @@ -133,8 +130,8 @@ class BreakoutRoomController extends AEnvironmentAwareController { /** * @NoAdminRequired - * @RequireLoggedInParticipant */ + #[RequireLoggedInParticipant] public function resetRequestForAssistance(): DataResponse { try { $this->breakoutRoomService->resetRequestForAssistance($this->room); @@ -152,8 +149,8 @@ class BreakoutRoomController extends AEnvironmentAwareController { /** * @NoAdminRequired - * @RequireLoggedInModeratorParticipant */ + #[RequireLoggedInModeratorParticipant] public function startBreakoutRooms(): DataResponse { try { $rooms = $this->breakoutRoomService->startBreakoutRooms($this->room); @@ -167,8 +164,8 @@ class BreakoutRoomController extends AEnvironmentAwareController { /** * @NoAdminRequired - * @RequireLoggedInModeratorParticipant */ + #[RequireLoggedInModeratorParticipant] public function stopBreakoutRooms(): DataResponse { try { $rooms = $this->breakoutRoomService->stopBreakoutRooms($this->room); @@ -182,8 +179,8 @@ class BreakoutRoomController extends AEnvironmentAwareController { /** * @NoAdminRequired - * @RequireLoggedInParticipant */ + #[RequireLoggedInParticipant] public function switchBreakoutRoom(string $target): DataResponse { try { $room = $this->breakoutRoomService->switchBreakoutRoom($this->room, $this->participant, $target); diff --git a/lib/Controller/CallController.php b/lib/Controller/CallController.php index c214d321a..9df7a6a9d 100644 --- a/lib/Controller/CallController.php +++ b/lib/Controller/CallController.php @@ -28,6 +28,10 @@ declare(strict_types=1); namespace OCA\Talk\Controller; use OCA\Talk\Middleware\Attribute\RequireCallEnabled; +use OCA\Talk\Middleware\Attribute\RequireModeratorOrNoLobby; +use OCA\Talk\Middleware\Attribute\RequireParticipant; +use OCA\Talk\Middleware\Attribute\RequirePermission; +use OCA\Talk\Middleware\Attribute\RequireReadWriteConversation; use OCA\Talk\Model\Attendee; use OCA\Talk\Model\Session; use OCA\Talk\Participant; @@ -62,13 +66,11 @@ class CallController extends AEnvironmentAwareController { /** * @PublicPage - * @RequireParticipant - * @RequireReadWriteConversation - * @RequireModeratorOrNoLobby - * - * @return DataResponse */ #[RequireCallEnabled] + #[RequireModeratorOrNoLobby] + #[RequireParticipant] + #[RequireReadWriteConversation] public function getPeersForCall(): DataResponse { $timeout = $this->timeFactory->getTime() - Session::SESSION_TIMEOUT; $result = []; @@ -104,15 +106,11 @@ class CallController extends AEnvironmentAwareController { /** * @PublicPage - * @RequireParticipant - * @RequireReadWriteConversation - * @RequireModeratorOrNoLobby - * - * @param int|null $flags - * @param int|null $forcePermissions - * @return DataResponse */ #[RequireCallEnabled] + #[RequireModeratorOrNoLobby] + #[RequireParticipant] + #[RequireReadWriteConversation] public function joinCall(?int $flags = null, ?int $forcePermissions = null, bool $silent = false): DataResponse { $this->participantService->ensureOneToOneRoomIsFilled($this->room); @@ -137,13 +135,10 @@ class CallController extends AEnvironmentAwareController { /** * @PublicPage - * @RequireParticipant - * @RequirePermissions(permissions=call-start) - * - * @param int $attendeeId - * @return DataResponse */ #[RequireCallEnabled] + #[RequireParticipant] + #[RequirePermission(permission: RequirePermission::START_CALL)] public function ringAttendee(int $attendeeId): DataResponse { if ($this->room->getCallFlag() === Participant::FLAG_DISCONNECTED) { return new DataResponse([], Http::STATUS_BAD_REQUEST); @@ -162,11 +157,8 @@ class CallController extends AEnvironmentAwareController { /** * @PublicPage - * @RequireParticipant - * - * @param int flags - * @return DataResponse */ + #[RequireParticipant] public function updateCallFlags(int $flags): DataResponse { $session = $this->participant->getSession(); if (!$session instanceof Session) { @@ -184,11 +176,11 @@ class CallController extends AEnvironmentAwareController { /** * @PublicPage - * @RequireParticipant * * @param bool $all whether to also terminate the call for all participants * @return DataResponse */ + #[RequireParticipant] public function leaveCall(bool $all = false): DataResponse { $session = $this->participant->getSession(); if (!$session instanceof Session) { diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php index 14e8f0e05..d9ea5131b 100644 --- a/lib/Controller/ChatController.php +++ b/lib/Controller/ChatController.php @@ -31,6 +31,11 @@ use OCA\Talk\Chat\MessageParser; use OCA\Talk\Chat\ReactionManager; use OCA\Talk\GuestManager; use OCA\Talk\MatterbridgeManager; +use OCA\Talk\Middleware\Attribute\RequireModeratorOrNoLobby; +use OCA\Talk\Middleware\Attribute\RequireModeratorParticipant; +use OCA\Talk\Middleware\Attribute\RequireParticipant; +use OCA\Talk\Middleware\Attribute\RequirePermission; +use OCA\Talk\Middleware\Attribute\RequireReadWriteConversation; use OCA\Talk\Model\Attachment; use OCA\Talk\Model\Attendee; use OCA\Talk\Model\Message; @@ -188,10 +193,6 @@ class ChatController extends AEnvironmentAwareController { /** * @PublicPage - * @RequireParticipant - * @RequireReadWriteConversation - * @RequirePermissions(permissions=chat) - * @RequireModeratorOrNoLobby * * Sends a new chat message to the given room. * @@ -207,6 +208,10 @@ class ChatController extends AEnvironmentAwareController { * "404 Not found" if the room or session for a guest user was not * found". */ + #[RequireModeratorOrNoLobby] + #[RequireParticipant] + #[RequirePermission(permission: RequirePermission::CHAT)] + #[RequireReadWriteConversation] public function sendMessage(string $message, string $actorDisplayName = '', string $referenceId = '', int $replyTo = 0, bool $silent = false): DataResponse { [$actorType, $actorId] = $this->getActorInfo($actorDisplayName); if (!$actorId) { @@ -245,10 +250,6 @@ class ChatController extends AEnvironmentAwareController { /** * @PublicPage - * @RequireParticipant - * @RequireReadWriteConversation - * @RequirePermissions(permissions=chat) - * @RequireModeratorOrNoLobby * * Sends a rich-object to the given room. * @@ -264,6 +265,10 @@ class ChatController extends AEnvironmentAwareController { * "404 Not found" if the room or session for a guest user was not * found". */ + #[RequireModeratorOrNoLobby] + #[RequireParticipant] + #[RequirePermission(permission: RequirePermission::CHAT)] + #[RequireReadWriteConversation] public function shareObjectToChat(string $objectType, string $objectId, string $metaData = '', string $actorDisplayName = '', string $referenceId = ''): DataResponse { [$actorType, $actorId] = $this->getActorInfo($actorDisplayName); if (!$actorId) { @@ -345,8 +350,6 @@ class ChatController extends AEnvironmentAwareController { /** * @PublicPage - * @RequireParticipant - * @RequireModeratorOrNoLobby * * Receives chat messages from the given room. * @@ -374,7 +377,7 @@ class ChatController extends AEnvironmentAwareController { * will be 0, yet the status will still be 200. Also note that * `X-Chat-Last-Given` may reference a message not visible and thus not * returned, but it should be used nevertheless as the $lastKnownMessageId - * for the follow up query. + * for the follow-up query. * * @param int $lookIntoFuture Polling for new messages (1) or getting the history of the chat (0) * @param int $limit Number of chat messages to receive (100 by default, 200 at most) @@ -395,6 +398,8 @@ class ChatController extends AEnvironmentAwareController { * 'actorDisplayName', 'timestamp' (in seconds and UTC timezone) and * 'message'. */ + #[RequireModeratorOrNoLobby] + #[RequireParticipant] public function receiveMessages(int $lookIntoFuture, int $limit = 100, int $lastKnownMessageId = 0, @@ -591,13 +596,13 @@ class ChatController extends AEnvironmentAwareController { /** * @PublicPage - * @RequireParticipant - * @RequireModeratorOrNoLobby * * @param int $messageId The focused message which should be in the "middle" of the returned context * @param int $limit Number of chat messages to receive in both directions (50 by default, 100 at most, might return 201 messages) * @return DataResponse */ + #[RequireModeratorOrNoLobby] + #[RequireParticipant] public function getMessageContext( int $messageId, int $limit = 50): DataResponse { @@ -657,14 +662,11 @@ class ChatController extends AEnvironmentAwareController { /** * @NoAdminRequired - * @RequireParticipant - * @RequireReadWriteConversation - * @RequirePermissions(permissions=chat) - * @RequireModeratorOrNoLobby - * - * @param int $messageId - * @return DataResponse */ + #[RequireModeratorOrNoLobby] + #[RequireParticipant] + #[RequirePermission(permission: RequirePermission::CHAT)] + #[RequireReadWriteConversation] public function deleteMessage(int $messageId): DataResponse { try { $message = $this->chatManager->getComment($this->room, (string) $messageId); @@ -730,11 +732,9 @@ class ChatController extends AEnvironmentAwareController { /** * @NoAdminRequired - * @RequireModeratorParticipant - * @RequireReadWriteConversation - * - * @return DataResponse */ + #[RequireModeratorParticipant] + #[RequireReadWriteConversation] public function clearHistory(): DataResponse { $attendee = $this->participant->getAttendee(); if (!$this->participant->hasModeratorPermissions(false) @@ -767,11 +767,8 @@ class ChatController extends AEnvironmentAwareController { /** * @NoAdminRequired - * @RequireParticipant - * - * @param int $lastReadMessage - * @return DataResponse */ + #[RequireParticipant] public function setReadMarker(int $lastReadMessage): DataResponse { $this->participantService->updateLastReadMessage($this->participant, $lastReadMessage); $response = new DataResponse(); @@ -783,10 +780,8 @@ class ChatController extends AEnvironmentAwareController { /** * @NoAdminRequired - * @RequireParticipant - * - * @return DataResponse */ + #[RequireParticipant] public function markUnread(): DataResponse { $message = $this->room->getLastMessage(); $unreadId = 0; @@ -811,12 +806,9 @@ class ChatController extends AEnvironmentAwareController { /** * @PublicPage - * @RequireParticipant - * @RequireModeratorOrNoLobby - * - * @param int $limit - * @return DataResponse */ + #[RequireModeratorOrNoLobby] + #[RequireParticipant] public function getObjectsSharedInRoomOverview(int $limit = 7): DataResponse { $limit = min(20, $limit); @@ -859,14 +851,9 @@ class ChatController extends AEnvir |