mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-20 16:45:16 +00:00
Can check the right to access a comment
This commit is contained in:
@ -14,6 +14,7 @@ import { FriendsHelper } from "../helpers/FriendsHelper";
|
||||
import { PostsHelper } from "../helpers/PostsHelper";
|
||||
import { PostAccessLevel } from "./Post";
|
||||
import { writeFileSync } from "fs";
|
||||
import { CommentsHelper } from "../helpers/CommentsHelper";
|
||||
|
||||
/**
|
||||
* Response to a request
|
||||
@ -323,6 +324,26 @@ export class RequestHandler {
|
||||
return postID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID of a comment that the user is allowed to access
|
||||
*
|
||||
* @param name The name of the comment field
|
||||
*/
|
||||
public async postCommentIDWithAccess(name: string) : Promise<number> {
|
||||
const commentID = this.postInt(name);
|
||||
|
||||
if(!await CommentsHelper.Exists(commentID))
|
||||
this.error(404, "Specified comment not found!");
|
||||
|
||||
const postID = await CommentsHelper.GetAssociatedPost(commentID);
|
||||
const post = await PostsHelper.GetSingle(postID);
|
||||
|
||||
if(await PostsHelper.GetAccessLevel(this.getUserId(), post) == PostAccessLevel.NO_ACCESS)
|
||||
this.error(401, "You are not allowed to acess this post information!");
|
||||
|
||||
return commentID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a virtual directory included in a POST request
|
||||
*
|
||||
|
Reference in New Issue
Block a user