Move working documents to its own area, rename dashboard
This commit is contained in:
@@ -7,6 +7,17 @@ export type AppSession = {
|
||||
role: string;
|
||||
token: string;
|
||||
tenant_id?: string | null;
|
||||
client_role?: string | null;
|
||||
user_id?: number | null;
|
||||
client_account_id?: number | null;
|
||||
module_permissions?: Record<string, string>;
|
||||
};
|
||||
|
||||
const ACCESS_LEVEL_ORDER: Record<string, number> = {
|
||||
none: 0,
|
||||
view: 1,
|
||||
edit: 2,
|
||||
manage: 3
|
||||
};
|
||||
|
||||
const CLIENT_STORAGE_KEY = 'data-entry-app-client-session';
|
||||
@@ -74,6 +85,23 @@ export function hasStoredAdminSession() {
|
||||
return getStoredAdminSession() !== null;
|
||||
}
|
||||
|
||||
export function hasModuleAccess(
|
||||
session: AppSession | null | undefined,
|
||||
moduleKey: string,
|
||||
minimumLevel: 'view' | 'edit' | 'manage' = 'view'
|
||||
) {
|
||||
if (!session) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (session.role === 'admin') {
|
||||
return true;
|
||||
}
|
||||
|
||||
const currentLevel = session.module_permissions?.[moduleKey] ?? 'none';
|
||||
return (ACCESS_LEVEL_ORDER[currentLevel] ?? 0) >= ACCESS_LEVEL_ORDER[minimumLevel];
|
||||
}
|
||||
|
||||
export const sessionHydrated = readable(false, (set) => {
|
||||
if (!browser) {
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user