mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-20 08:35:17 +00:00
Check user authorization to create posts
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import { DatabaseHelper } from "./DatabaseHelper";
|
||||
import { GroupsAccessLevel, GroupVisibilityLevel, GroupInfo } from "../entities/Group";
|
||||
import { GroupsAccessLevel, GroupVisibilityLevel, GroupInfo, GroupPostsCreationLevel } from "../entities/Group";
|
||||
import { GroupMembershipLevels, GroupMember } from "../entities/GroupMember";
|
||||
import { NewGroup } from "../entities/NewGroup";
|
||||
import { time } from "../utils/DateUtils";
|
||||
@ -480,6 +480,29 @@ export class GroupsHelper {
|
||||
return groupID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check out whether a user can create posts on a group or not
|
||||
*
|
||||
* @param groupID Target group ID
|
||||
* @param userID Target user ID
|
||||
*/
|
||||
public static async CanUserCreatePosts(groupID: number, userID: number) : Promise<boolean> {
|
||||
const membershipLevel = await this.GetMembershipLevel(groupID, userID);
|
||||
|
||||
// Moderators + administrators => can always create posts
|
||||
if(membershipLevel == GroupMembershipLevels.MODERATOR ||
|
||||
membershipLevel == GroupMembershipLevels.ADMINISTRATOR)
|
||||
return true;
|
||||
|
||||
// Simple members => check authorization
|
||||
if(membershipLevel == GroupMembershipLevels.MEMBER) {
|
||||
return (await this.GetInfo(groupID)).postsCreationLevel
|
||||
== GroupPostsCreationLevel.POSTS_LEVEL_ALL_MEMBERS;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a database row into a {GroupInfo} object
|
||||
*
|
||||
|
Reference in New Issue
Block a user