1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-21 00:55:17 +00:00

Implement groups visibility system

This commit is contained in:
2019-12-13 18:30:08 +01:00
parent ee6579efa0
commit af9e95a914
6 changed files with 187 additions and 0 deletions

26
src/entities/Group.ts Normal file
View File

@ -0,0 +1,26 @@
/**
* Single group information
*
* @author Pierre HUBERT
*/
/**
* Group visibility level
*/
export enum GroupVisibilityLevel {
OPEN_GROUP = 0,
PRIVATE_GROUP = 1,
SECRETE_GROUP = 2
}
/**
* Access level of a user to a group
*/
export enum GroupsAccessLevel {
NO_ACCESS = 0, //Can not even know if the group exists or not
LIMITED_ACCESS = 1, //Access to the name of the group only
VIEW_ACCESS = 2, //Can see the posts of the group, but not a member of the group
MEMBER_ACCESS = 3, //Member access (same as view access but as member)
MODERATOR_ACCESS = 4, //Can create posts, even if posts creation is restricted
ADMIN_ACCESS = 5, //Can do everything
}

View File

@ -0,0 +1,14 @@
/**
* Group membership information
*
* @author Pierre HUBERT
*/
export enum GroupMembershipLevels {
ADMINISTRATOR = 0,
MODERATOR = 1,
MEMBER = 2,
INVITED = 3,
PENDING = 4, //When the group membership has not been approved yet
VISITOR = 5, //Simple visitor
}

View File

@ -7,6 +7,8 @@ import { UploadedFile } from "express-fileupload";
import { prepareFileCreation, generateNewUserDataFileName, pathUserData } from "../utils/UserDataUtils";
import * as sharp from 'sharp';
import { UserHelper } from "../helpers/UserHelper";
import { GroupsAccessLevel } from "./Group";
import { GroupsHelper } from "../helpers/GroupsHelper";
/**
* Response to a request
@ -196,6 +198,41 @@ export class RequestHandler {
return userID;
}
/**
* Get a POST group ID
*
* @param name The name of the POST field
*/
public async postGroupID(name: string) : Promise<number> {
const groupID = this.postInt(name);
if(!await GroupsHelper.Exists(groupID))
this.error(404, "Specified group not found!");
return groupID;
}
/**
* Get a POST group ID with a check for access level of current user
*
* @param name The name of the POST field containing group ID
* @param minVisibility Minimum visiblity requested to the group
* @returns The ID of the group (throws in case of failure)
*/
public async postGroupIDWithAccess(name: string, minVisibility : GroupsAccessLevel) : Promise<number> {
const groupID = await this.postGroupID(name);
const access = await GroupsHelper.GetAccessLevel(groupID, this.getUserId());
if(access == GroupsAccessLevel.NO_ACCESS)
this.error(404, "Specified group not found!");
if(access < minVisibility)
this.error(401, "You do not have enough rights to perform what you intend to do on this group!");
return groupID;
}
/**
* Get information about an uploaded file
*