1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 13:29:22 +00:00

Add access level for group pages

This commit is contained in:
Pierre HUBERT 2020-01-03 16:49:11 +01:00
parent 015cf1e0d7
commit 90d81c1d7a
2 changed files with 29 additions and 0 deletions

View File

@ -158,6 +158,15 @@ export class GroupsHelper {
return result.visibility;
}
/**
* Convenience function to check whether a group is open or not
*
* @param groupID Target group ID
*/
public static async IsOpen(groupID: number) : Promise<boolean> {
return (await this.GetVisibility(groupID)) == GroupVisibilityLevel.OPEN_GROUP;
}
/**
* Invite a user to join a group
*

View File

@ -2,6 +2,8 @@ import { PostKind, PostVisibilityLevel, Post, PostPageKind, PostFile, PostLink,
import { FriendsHelper } from "./FriendsHelper";
import { DatabaseHelper } from "./DatabaseHelper";
import { UserHelper } from "./UserHelper";
import { GroupsHelper } from "./GroupsHelper";
import { GroupMembershipLevels } from "../entities/GroupMember";
/**
* Posts helper
@ -155,7 +157,25 @@ export class PostsHelper {
// Group page
else if(post.kindPage == PostPageKind.PAGE_KIND_GROUP) {
// TODO : check this code
const accessLevel = await GroupsHelper.GetMembershipLevel(userID, post.groupID);
// Moderator & admin = intermediate access
if(accessLevel < GroupMembershipLevels.MEMBER)
return PostAccessLevel.INTERMEDIATE_ACCESS;
// Members can see all the posts of a group
if(accessLevel == GroupMembershipLevels.MEMBER)
return PostAccessLevel.BASIC_ACCESS;
// Now we check if the post is public & the group is open
if(post.visibilityLevel != PostVisibilityLevel.VISIBILITY_PUBLIC
|| !await GroupsHelper.IsOpen(post.groupID))
return PostAccessLevel.NO_ACCESS;
// Public post + open group = basic access
return PostAccessLevel.BASIC_ACCESS;
}
throw Error("GetAccessLevel reached an unimplemented status!");