Staff / Owner
Merged staff and owner settings
This commit is contained in:
23 files changed
+693
-236
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { cache } from "react";
|
||||
import { prisma } from "@/lib/db/prisma";
|
||||
import type { Permission } from "@/generated/prisma/enums";
|
||||
import { Permission } from "@/generated/prisma/enums";
|
||||
import type { NavRole } from "@/lib/navigation/nav-config";
|
||||
|
||||
/**
|
||||
* Foundation for Phase 3+ role gating — not exercised by any UI yet.
|
||||
@@ -50,3 +51,19 @@ export async function hasPermission(userId: string, permission: Permission): Pro
|
||||
const permissions = await getStaffPermissions(userId);
|
||||
return permissions.has(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* The single role classification behind the merged nav (see
|
||||
* lib/navigation/nav-config.ts) — "staff" vs "owner" is just whether the
|
||||
* account's Role grants MANAGE_STAFF, and "superadmin" short-circuits both
|
||||
* (a Super Administrator has no StaffProfile at all, see isSuperAdmin).
|
||||
* Returns null for a signed-in user who is neither staff nor a super
|
||||
* admin — callers should redirect those away, same as today.
|
||||
*/
|
||||
export const getNavRole = cache(async (userId: string): Promise<NavRole | null> => {
|
||||
if (await isSuperAdmin(userId)) return "superadmin";
|
||||
const staffProfile = await prisma.staffProfile.findUnique({ where: { userId }, select: { id: true } });
|
||||
if (!staffProfile) return null;
|
||||
const permissions = await getStaffPermissions(userId);
|
||||
return permissions.has(Permission.MANAGE_STAFF) ? "owner" : "staff";
|
||||
});
|
||||
Reference in new issue
Block a user