[WEB-3964] refactor: permission layer (#7094)

* refactor: permission layer

* refactor: add original_role to project member serializer

* chore: minor fixes related to permission layer

* fix: strict type checking while checking user permissions
This commit is contained in:
Prateek Shourya 2025-05-30 19:57:07 +05:30 committed by GitHub
parent 322af8c436
commit 67cbe94d4a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
64 changed files with 719 additions and 428 deletions

View file

@ -0,0 +1,43 @@
import { computedFn } from "mobx-utils";
// plane imports
import { EUserProjectRoles } from "@plane/constants";
// plane web imports
import { RootStore } from "@/plane-web/store/root.store";
// store
import { IMemberRootStore } from "@/store/member";
import { BaseProjectMemberStore, IBaseProjectMemberStore } from "@/store/member/base-project-member.store";
export type IProjectMemberStore = IBaseProjectMemberStore;
export class ProjectMemberStore extends BaseProjectMemberStore implements IProjectMemberStore {
constructor(_memberRoot: IMemberRootStore, rootStore: RootStore) {
super(_memberRoot, rootStore);
}
/**
* @description Returns the highest role from the project membership
* @param { string } userId
* @param { string } projectId
* @returns { EUserProjectRoles | undefined }
*/
getUserProjectRole = computedFn((userId: string, projectId: string): EUserProjectRoles | undefined =>
this.getRoleFromProjectMembership(userId, projectId)
);
/**
* @description Returns the role from the project membership
* @param projectId
* @param userId
* @param role
*/
getProjectMemberRoleForUpdate = (_projectId: string, _userId: string, role: EUserProjectRoles): EUserProjectRoles =>
role;
/**
* @description Processes the removal of a member from a project
* This method handles the cleanup of member data from the project member map
* @param projectId - The ID of the project to remove the member from
* @param userId - The ID of the user to remove from the project
*/
processMemberRemoval = (projectId: string, userId: string) => this.handleMemberRemoval(projectId, userId);
}

View file

@ -0,0 +1,23 @@
import { computedFn } from "mobx-utils";
import { EUserPermissions } from "@plane/constants";
import { RootStore } from "@/plane-web/store/root.store";
import { BaseUserPermissionStore, IBaseUserPermissionStore } from "@/store/user/base-permissions.store";
export type IUserPermissionStore = IBaseUserPermissionStore;
export class UserPermissionStore extends BaseUserPermissionStore implements IUserPermissionStore {
constructor(store: RootStore) {
super(store);
}
/**
* @description Returns the project role from the workspace
* @param { string } workspaceSlug
* @param { string } projectId
* @returns { EUserPermissions | undefined }
*/
getProjectRoleByWorkspaceSlugAndProjectId = computedFn(
(workspaceSlug: string, projectId: string): EUserPermissions | undefined =>
this.getProjectRole(workspaceSlug, projectId)
);
}