Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 4x 56x 36x 33x | import type { CoreUser } from "@/objects/CoreUser";
/**
* Platform roles: what a person may do on CHAIN-R itself, assigned in Auth0
* and kept on their user by svc-core (`app/services/platform_roles.py`,
* docs/system/security/auth-flow.md#platform-roles). Membership roles say
* what they may do in an organisation or project; these say what they may
* do on the platform.
*
* A page that needs one shows itself only to those who hold it; svc-core's
* `require_role` refuses everyone else regardless.
*/
export const PLATFORM_ROLES = ["superuser", "developer"] as const;
export type PlatformRole = (typeof PLATFORM_ROLES)[number];
/** Whether `user` holds `role`: their own roles, or every one for a superuser. */
export function hasPlatformRole(
user: Pick<CoreUser, "is_superuser" | "platform_roles"> | null | undefined,
role: PlatformRole,
): boolean {
if (!user) return false;
if (user.is_superuser) return true;
return (user.platform_roles ?? []).includes(role);
}
|