diff --git a/src/helpers/GroupsHelper.ts b/src/helpers/GroupsHelper.ts index 797ee1a..143a9d5 100644 --- a/src/helpers/GroupsHelper.ts +++ b/src/helpers/GroupsHelper.ts @@ -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 { + return (await this.GetVisibility(groupID)) == GroupVisibilityLevel.OPEN_GROUP; + } + /** * Invite a user to join a group * diff --git a/src/helpers/PostsHelper.ts b/src/helpers/PostsHelper.ts index 28db429..e52f22d 100644 --- a/src/helpers/PostsHelper.ts +++ b/src/helpers/PostsHelper.ts @@ -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!");