mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 05:19:22 +00:00
Add access level for group pages
This commit is contained in:
parent
015cf1e0d7
commit
90d81c1d7a
@ -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
|
||||
*
|
||||
|
@ -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!");
|
||||
|
Loading…
Reference in New Issue
Block a user