1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-20 08:35:17 +00:00

Can edit comment content

This commit is contained in:
2020-03-21 12:01:42 +01:00
parent 77695ac8f4
commit 9a0e746ebc
3 changed files with 64 additions and 0 deletions

View File

@ -62,6 +62,20 @@ export class CommentsController {
h.send(await this.CommentToAPI(h, comment))
}
/**
* Edit (update) a comment content
*
* @param h Request handler
*/
public static async Edit(h: RequestHandler) {
const commentID = await this.GetPostCommentIDWithFullAccess(h, "commentID");
const newContent = this.GetCommentContent(h, "content", true);
await CommentsHelper.Edit(commentID, newContent);
h.success()
}
/**
* Get the content of a comment included in a POST field
*
@ -78,6 +92,21 @@ export class CommentsController {
return content;
}
/**
* Get a comment ID on which current user has full access
*
* @param h Request handler
* @param name The name of the POST field containing the comment ID
*/
private static async GetPostCommentIDWithFullAccess(h: RequestHandler, name: string) : Promise<number> {
const commentID = h.postInt(name);
if(!await CommentsHelper.IsOwner(h.getUserId(), commentID))
h.error(401, "You are not the owner of this comment!");
return commentID;
}
/**
* Turn a list of comment object into API entries

View File

@ -209,6 +209,8 @@ export const Routes : Route[] = [
{path: "/comments/get_single", cb: (h) => CommentsController.GetSingle(h)},
{path: "/comments/edit", cb: (h) => CommentsController.Edit(h)},
// Notifications controller
{path: "/notifications/count_unread", cb: (h) => NotificationsController.CountUnread(h)},