Move to OCS routes for new comments api
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
@@ -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'],
|
||||
]
|
||||
];
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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']);
|
||||
|
||||
Reference in New Issue
Block a user