diff --git a/src/lib/server/authorization.ts b/src/lib/server/authorization.ts index ccfaea6..76e718b 100644 --- a/src/lib/server/authorization.ts +++ b/src/lib/server/authorization.ts @@ -38,12 +38,15 @@ export function hasRole(roles: CompanyRole[], target: CompanyRole): boolean { return roles.includes(target); } -/** Does any hierarchical role in the set meet or exceed the minimum rank? `hr` does not count. */ -export function meetsMinRole(roles: CompanyRole[], min: Exclude): boolean { +/** Does any hierarchical role in the set meet or exceed the minimum rank? `hr` and `accountant` do not count. */ +export function meetsMinRole( + roles: CompanyRole[], + min: Exclude +): boolean { const minRank = ROLE_HIERARCHY[min]; for (const r of roles) { - if (r === 'hr') continue; - const rank = ROLE_HIERARCHY[r as Exclude]; + if (r === 'hr' || r === 'accountant') continue; + const rank = ROLE_HIERARCHY[r as Exclude]; if (rank >= minRank) return true; } return false; @@ -56,7 +59,7 @@ export function meetsMinRole(roles: CompanyRole[], min: Exclude + minRole: Exclude ): Promise<{ user: NonNullable; roles: CompanyRole[] }> { const user = requireAuth(locals); diff --git a/src/lib/server/db/schema.ts b/src/lib/server/db/schema.ts index aa966a3..642e305 100644 --- a/src/lib/server/db/schema.ts +++ b/src/lib/server/db/schema.ts @@ -15,7 +15,7 @@ import { // ── Enums ────────────────────────────────────────────── -export const companyRoleEnum = pgEnum('company_role', ['admin', 'manager', 'user', 'viewer', 'hr']); +export const companyRoleEnum = pgEnum('company_role', ['admin', 'manager', 'user', 'viewer', 'hr', 'accountant']); export const expenseStatusEnum = pgEnum('expense_status', ['pending', 'approved', 'rejected']); // ── Users ────────────────────────────────────────────── @@ -697,7 +697,8 @@ export const companyLogEventEnum = pgEnum('company_log_event', [ 'package_delivered', 'package_status_refreshed', 'shipping_account_added', - 'shipping_account_removed' + 'shipping_account_removed', + 'financial_exported' ]); export const companyLog = pgTable( diff --git a/src/lib/types/index.ts b/src/lib/types/index.ts index f679cd6..4c822df 100644 --- a/src/lib/types/index.ts +++ b/src/lib/types/index.ts @@ -1,4 +1,4 @@ -export type CompanyRole = 'admin' | 'manager' | 'user' | 'viewer' | 'hr'; +export type CompanyRole = 'admin' | 'manager' | 'user' | 'viewer' | 'hr' | 'accountant'; export type ExpenseStatus = 'pending' | 'approved' | 'rejected'; export type LeaveStatus = 'pending' | 'approved' | 'rejected'; export type PartyType = 'customer' | 'supplier' | 'both'; @@ -16,13 +16,13 @@ export type FeatureRequestStatus = | 'closed'; /** - * Hierarchical roles — only these ranks. `hr` is orthogonal and excluded. + * Hierarchical roles only. `hr` and `accountant` are orthogonal flags excluded from this map. */ -export const ROLE_HIERARCHY: Record, number> = { +export const ROLE_HIERARCHY: Record, number> = { admin: 4, manager: 3, user: 2, viewer: 1 }; -export const ALL_ROLES: CompanyRole[] = ['admin', 'manager', 'hr', 'user', 'viewer']; +export const ALL_ROLES: CompanyRole[] = ['admin', 'manager', 'hr', 'accountant', 'user', 'viewer']; diff --git a/src/routes/(app)/companies/[companyId]/settings/+page.svelte b/src/routes/(app)/companies/[companyId]/settings/+page.svelte index 61ced6d..44fb882 100644 --- a/src/routes/(app)/companies/[companyId]/settings/+page.svelte +++ b/src/routes/(app)/companies/[companyId]/settings/+page.svelte @@ -105,7 +105,7 @@
Roles (one or more)
- {#each ['admin', 'manager', 'hr', 'user', 'viewer'] as role} + {#each ['admin', 'manager', 'hr', 'accountant', 'user', 'viewer'] as role}