Move working documents to its own area, rename dashboard

This commit is contained in:
2026-04-29 01:21:16 +12:00
parent 7e9663fa06
commit 761ebb050d
32 changed files with 1779 additions and 526 deletions
+28
View File
@@ -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;