From fb06cac246865d83bcd67e2695a02ec12520cba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 6 Mar 2020 16:10:07 +0100 Subject: [PATCH] Move to OCS routes for new comments api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- appinfo/routes.php | 11 +++++++---- lib/Controller/CommentsApiController.php | 9 ++++----- lib/Middleware/ExceptionMiddleware.php | 7 +++++++ lib/Service/CommentService.php | 1 + 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index 2b04971c5..0c247b642 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -122,11 +122,14 @@ return [ ['name' => 'attachment_api#delete', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}/attachments/{attachmentId}', 'verb' => 'DELETE'], ['name' => 'attachment_api#restore', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}/attachments/{attachmentId}/restore', 'verb' => 'PUT'], - ['name' => 'comments_api#list', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}/comments', 'verb' => 'GET'], - ['name' => 'comments_api#create', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}/comments', 'verb' => 'POST'], - ['name' => 'comments_api#update', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}/comments/{commentId}', 'verb' => 'PUT'], - ['name' => 'comments_api#delete', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}/comments/{commentId}', 'verb' => 'DELETE'], + ['name' => 'board_api#preflighted_cors', 'url' => '/api/v1.0/{path}','verb' => 'OPTIONS', 'requirements' => ['path' => '.+']], + ], + 'ocs' => [ + ['name' => 'comments_api#list', 'url' => '/api/v1.0/cards/{cardId}/comments', 'verb' => 'GET'], + ['name' => 'comments_api#create', 'url' => '/api/v1.0/cards/{cardId}/comments', 'verb' => 'POST'], + ['name' => 'comments_api#update', 'url' => '/api/v1.0/cards/{cardId}/comments/{commentId}', 'verb' => 'PUT'], + ['name' => 'comments_api#delete', 'url' => '/api/v1.0/cards/{cardId}/comments/{commentId}', 'verb' => 'DELETE'], ] ]; diff --git a/lib/Controller/CommentsApiController.php b/lib/Controller/CommentsApiController.php index 6a16629c3..8f38ddf53 100644 --- a/lib/Controller/CommentsApiController.php +++ b/lib/Controller/CommentsApiController.php @@ -23,14 +23,17 @@ namespace OCA\Deck\Controller; +use OCA\Deck\BadRequestException; use OCA\Deck\Service\CommentService; use OCA\Deck\StatusException; use OCP\AppFramework\ApiController; use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\OCS\OCSException; +use OCP\AppFramework\OCSController; use OCP\IRequest; -class CommentsApiController extends ApiController { +class CommentsApiController extends OCSController { /** @var CommentService */ private $commentService; @@ -45,7 +48,6 @@ class CommentsApiController extends ApiController { /** * @NoAdminRequired - * @NoCSRFRequired * @throws StatusException */ public function list(string $cardId, int $limit = 20, int $offset = 0): DataResponse { @@ -54,7 +56,6 @@ class CommentsApiController extends ApiController { /** * @NoAdminRequired - * @NoCSRFRequired * @throws StatusException */ public function create(string $cardId, string $message, string $parentId = '0'): DataResponse { @@ -63,7 +64,6 @@ class CommentsApiController extends ApiController { /** * @NoAdminRequired - * @NoCSRFRequired * @throws StatusException */ public function update(string $cardId, string $commentId, string $message): DataResponse { @@ -72,7 +72,6 @@ class CommentsApiController extends ApiController { /** * @NoAdminRequired - * @NoCSRFRequired * @throws StatusException */ public function delete(string $cardId, string $commentId): DataResponse { diff --git a/lib/Middleware/ExceptionMiddleware.php b/lib/Middleware/ExceptionMiddleware.php index 96d2a1b65..a4f0610ee 100644 --- a/lib/Middleware/ExceptionMiddleware.php +++ b/lib/Middleware/ExceptionMiddleware.php @@ -28,6 +28,8 @@ use OCA\Deck\StatusException; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Middleware; use OCP\AppFramework\Http\JSONResponse; +use OCP\AppFramework\OCS\OCSException; +use OCP\AppFramework\OCSController; use OCP\ILogger; use OCP\Util; use OCP\IConfig; @@ -65,6 +67,11 @@ class ExceptionMiddleware extends Middleware { if ($this->config->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { $this->logger->logException($exception); } + + if ($controller instanceof OCSController) { + $exception = new OCSException($exception->getMessage(), $exception->getStatus(), $exception); + throw $exception; + } return new JSONResponse([ 'status' => $exception->getStatus(), 'message' => $exception->getMessage() diff --git a/lib/Service/CommentService.php b/lib/Service/CommentService.php index 03b0532b5..b492f99a7 100644 --- a/lib/Service/CommentService.php +++ b/lib/Service/CommentService.php @@ -151,6 +151,7 @@ class CommentService { 'actorId' => $comment->getActorId(), 'actorType' => $comment->getActorType(), 'actorDisplayName' => $actorDisplayName, + 'creationDateTime' => $comment->getCreationDateTime()->format(\DateTime::ATOM), 'mentions' => array_map(function($mention) { try { $displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']);