Role default + user override with OR rules; covers customers, leads, sales, activities, notes, routines, projects, and tickets.
98 lines
1.8 KiB
TypeScript
98 lines
1.8 KiB
TypeScript
import { Type } from 'class-transformer';
|
|
import {
|
|
ArrayUnique,
|
|
IsArray,
|
|
IsIn,
|
|
IsObject,
|
|
IsOptional,
|
|
IsString,
|
|
MaxLength,
|
|
MinLength,
|
|
ValidateIf,
|
|
ValidateNested,
|
|
} from 'class-validator';
|
|
import { ROLE_PERMISSION_ITEMS, type RolePermissionKey } from '@mento/shared';
|
|
import { ROLE_COLORS } from './role-defaults';
|
|
|
|
const PERMISSION_KEYS = ROLE_PERMISSION_ITEMS.map((item) => item.key);
|
|
|
|
export class CreateOrgRoleDto {
|
|
@IsString()
|
|
@MinLength(2)
|
|
@MaxLength(80)
|
|
name!: string;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(280)
|
|
description?: string;
|
|
|
|
@IsOptional()
|
|
@IsIn([...ROLE_COLORS])
|
|
color?: (typeof ROLE_COLORS)[number];
|
|
|
|
@IsOptional()
|
|
@IsArray()
|
|
@ArrayUnique()
|
|
@IsIn(PERMISSION_KEYS, { each: true })
|
|
permissions?: RolePermissionKey[];
|
|
|
|
@IsOptional()
|
|
@IsObject()
|
|
dataAccessPolicy?: Record<string, unknown>;
|
|
|
|
@IsOptional()
|
|
@ValidateIf((_, v) => v !== null)
|
|
@IsString()
|
|
parentId?: string | null;
|
|
}
|
|
|
|
export class UpdateOrgRoleDto {
|
|
@IsOptional()
|
|
@IsString()
|
|
@MinLength(2)
|
|
@MaxLength(80)
|
|
name?: string;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(280)
|
|
description?: string;
|
|
|
|
@IsOptional()
|
|
@IsIn([...ROLE_COLORS])
|
|
color?: (typeof ROLE_COLORS)[number];
|
|
|
|
@IsOptional()
|
|
@IsArray()
|
|
@ArrayUnique()
|
|
@IsIn(PERMISSION_KEYS, { each: true })
|
|
permissions?: RolePermissionKey[];
|
|
|
|
@IsOptional()
|
|
@IsObject()
|
|
dataAccessPolicy?: Record<string, unknown>;
|
|
|
|
@IsOptional()
|
|
@ValidateIf((_, v) => v !== null)
|
|
@IsString()
|
|
parentId?: string | null;
|
|
}
|
|
|
|
export class RolePermissionPatchItemDto {
|
|
@IsString()
|
|
id!: string;
|
|
|
|
@IsArray()
|
|
@ArrayUnique()
|
|
@IsIn(PERMISSION_KEYS, { each: true })
|
|
permissions!: RolePermissionKey[];
|
|
}
|
|
|
|
export class BulkUpdatePermissionsDto {
|
|
@IsArray()
|
|
@ValidateNested({ each: true })
|
|
@Type(() => RolePermissionPatchItemDto)
|
|
items!: RolePermissionPatchItemDto[];
|
|
}
|