mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { TeamMemberRole } from '@documenso/prisma/client';
|
|
|
|
export const TEAM_MEMBER_ROLE_MAP: Record<keyof typeof TeamMemberRole, string> = {
|
|
ADMIN: 'Admin',
|
|
MANAGER: 'Manager',
|
|
MEMBER: 'Member',
|
|
};
|
|
|
|
export const TEAM_MEMBER_ROLE_PERMISSIONS_MAP = {
|
|
/**
|
|
* Includes updating team name, url, logo, emails.
|
|
*
|
|
* Todo: Teams - Clean this up, merge etc.
|
|
*/
|
|
MANAGE_TEAM: [TeamMemberRole.ADMIN, TeamMemberRole.MANAGER],
|
|
DELETE_INVITATIONS: [TeamMemberRole.ADMIN, TeamMemberRole.MANAGER],
|
|
DELETE_TEAM_MEMBERS: [TeamMemberRole.ADMIN, TeamMemberRole.MANAGER],
|
|
DELETE_TEAM_TRANSFER_REQUEST: [TeamMemberRole.ADMIN],
|
|
UPDATE_TEAM_MEMBERS: [TeamMemberRole.ADMIN, TeamMemberRole.MANAGER],
|
|
} satisfies Record<string, TeamMemberRole[]>;
|
|
|
|
/**
|
|
* Determines whether a team member can execute a given action.
|
|
*
|
|
* @param action The action the user is trying to execute.
|
|
* @param role The current role of the user.
|
|
* @returns Whether the user can execute the action.
|
|
*/
|
|
export const canExecuteTeamAction = (
|
|
action: keyof typeof TEAM_MEMBER_ROLE_PERMISSIONS_MAP,
|
|
role: keyof typeof TEAM_MEMBER_ROLE_MAP,
|
|
) => {
|
|
return TEAM_MEMBER_ROLE_PERMISSIONS_MAP[action].some((i) => i === role);
|
|
};
|