UNPKG

@gsb-core/core

Version:

GSB core services and classes for platform-independent web applications

88 lines (87 loc) 3.26 kB
import { GsbPermission, GsbPermissionType } from '../models/gsb-user.model'; /** * Service for managing Permissions (Policies) in the application */ export declare class PermissionService { private entityService; private ENTITY_NAME; private static instance; constructor(); /** * Get the singleton instance of PermissionService * @returns The PermissionService instance */ static getInstance(): PermissionService; /** * Check if the current user is authorized to perform an action on an entity * @param entityDef The entity definition name or ID * @param permissionType The type of permission to check * @param userId Optional user ID to check for (defaults to current user) * @returns Promise resolving to a boolean indicating if the user is authorized */ isAuthorized(entityDef: string, permissionType: GsbPermissionType, userId?: string): Promise<boolean>; /** * Get permission by ID * @param id The permission ID * @returns The permission or null if not found */ getPermissionById(id: string): Promise<GsbPermission | null>; /** * Get all permissions with pagination * @param page The page number (starting from 1) * @param pageSize The number of items per page * @returns An array of permissions and the total count */ getPermissions(page?: number, pageSize?: number): Promise<{ permissions: GsbPermission[]; totalCount: number; }>; /** * Search for permissions * @param searchTerm The search term * @param page The page number (starting from 1) * @param pageSize The number of items per page * @returns An array of permissions and the total count */ searchPermissions(searchTerm: string, page?: number, pageSize?: number): Promise<{ permissions: GsbPermission[]; totalCount: number; }>; /** * Create a new permission * @param permission The permission to create * @returns The created permission ID or null if failed */ createPermission(permission: GsbPermission): Promise<string | null>; /** * Update an existing permission * @param permission The permission to update * @returns True if updated successfully, false otherwise */ updatePermission(permission: GsbPermission): Promise<boolean>; /** * Delete a permission * @param id The permission ID to delete * @returns True if deleted successfully, false otherwise */ deletePermission(id: string): Promise<boolean>; /** * Get entity permissions * @param entityDefId The entity definition ID or name * @returns The entity permissions */ getEntityPermissions(entityDefId: string): Promise<GsbPermission[]>; /** * Get user permissions * @param userId The user ID * @returns The user permissions */ getUserPermissions(userId: string): Promise<GsbPermission[]>; /** * Get user's effective permissions * This combines permissions from user directly, roles and groups * @param userId The user ID * @returns All effective permissions for the user */ getUserEffectivePermissions(userId: string): Promise<GsbPermission[]>; }