mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 00:50:56 +00:00
resolve confilict
This commit is contained in:
@@ -4,6 +4,7 @@ import type { TCurrentUser } from '@tria-plc/api-common/modules/auth/types/curre
|
||||
import { FREIGHT_PERMS } from '../seed/freight-permissions.registry';
|
||||
|
||||
const SUPER_ADMIN_ROLE = 'super_admin';
|
||||
const ORGANIZATION_ADMIN_ROLE = 'organization_admin';
|
||||
|
||||
type PermissionLike = { key?: string };
|
||||
type MeLikeUser = {
|
||||
@@ -25,6 +26,15 @@ export function isSuperAdmin(user: MeLikeUser | null | undefined): boolean {
|
||||
return user.roles.some((r) => r.key === SUPER_ADMIN_ROLE);
|
||||
}
|
||||
|
||||
export function isOrganizationAdmin(user: MeLikeUser | null | undefined): boolean {
|
||||
if (!user?.roles?.length) return false;
|
||||
return user.roles.some((r) => r.key === ORGANIZATION_ADMIN_ROLE);
|
||||
}
|
||||
|
||||
export function isFreightApprovalAdmin(user: MeLikeUser | null | undefined): boolean {
|
||||
return isSuperAdmin(user) || isOrganizationAdmin(user);
|
||||
}
|
||||
|
||||
/** Flat permission keys from JWT / session user (roles + position permissions). */
|
||||
export function collectPermissionKeys(user: MeLikeUser | null | undefined): string[] {
|
||||
if (!user) return [];
|
||||
@@ -90,7 +100,7 @@ export function assertCanApproveBookingStep(
|
||||
user: TCurrentUser | MeLikeUser | null | undefined,
|
||||
requiredRole: string,
|
||||
): void {
|
||||
if (isSuperAdmin(user)) return;
|
||||
if (isFreightApprovalAdmin(user)) return;
|
||||
const perm = APPROVE_ROLE_PERMISSION[requiredRole];
|
||||
if (!perm) {
|
||||
throw new ForbiddenException(`Unknown approval role: ${requiredRole}`);
|
||||
|
||||
Reference in New Issue
Block a user