Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / frontend/src/lib/can.ts |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 |
| Branch | feature/aioe-upgrade |
| Path or archive member | frontend/src/lib/can.ts |
| Original SHA-256 | 85dbff8c787d2ad76551e1e5f49eec923ff5c13f408a5ae8afe45ea2c57e94f5 |
| Git blob SHA | 1702763bb9d8efb7636d3c3ac3be97b80d8186ca |
| Reading-copy SHA-256 | 85dbff8c787d2ad76551e1e5f49eec923ff5c13f408a5ae8afe45ea2c57e94f5 |
Recovered source transcript
Download complete source text ↓43 lines · 1.7 KB
import type { SessionPrincipal } from './auth'
// Capability names, mirrored from internal/platform/security. Only the ones the interface actually
// gates on are listed: an unused constant here would imply a permission the UI respects when it does not.
export const CAP = {
candidateWrite: 'candidate.write',
requirementEdit: 'requirement.write',
exportRun: 'export.run',
deskReassign: 'desk.reassign',
userInvite: 'user.invite',
userRoleChange: 'user.role.change',
userDisable: 'user.disable',
orgSettings: 'org.settings.write',
auditRead: 'audit.read',
privacyErase: 'privacy.erase',
} as const
// can reports whether the signed in user holds a capability.
//
// Fails closed: no session, or a session from a server that does not send the list, grants nothing. That
// is the safe direction, and it means an older client against a newer server simply offers less rather
// than offering something that will 403.
export function can(principal: SessionPrincipal | null, cap: string): boolean {
return !!principal?.capabilities?.includes(cap)
}
// Tool names, mirrored from internal/platform/security. The vocabulary is closed on both sides.
export const TOOL = {
missionmatch: 'missionmatch',
screenmatch: 'screenmatch',
slatematch: 'slatematch',
recruitmatch: 'recruitmatch',
} as const
// hasTool reports whether the signed in user was granted a product.
//
// Fails closed for the same reason can() does: no session, or a session from a server that does not send
// the list, shows nothing. An older client against a newer server offers less rather than offering a tool
// whose every endpoint will 404.
export function hasTool(principal: SessionPrincipal | null, tool: string): boolean {
return !!principal?.tools?.includes(tool)
}