feat: SPA Roles screens
This commit is contained in:
1 parent
907949aa12
commit
3db490a615
47 files changed
+6947
-9
No files matched your search
@@ -29,6 +29,18 @@ export interface ScopeOptions {
|
||||
|
||||
const TYPE_SEPARATOR = ':'
|
||||
|
||||
export function formatGrantKey(key: string, typeKey?: string) {
|
||||
return typeKey === undefined ? key : `${key}${TYPE_SEPARATOR}${typeKey}`
|
||||
}
|
||||
|
||||
export function parseGrantKey(key: string): { base: string; typeKey?: string } {
|
||||
const at = key.indexOf(TYPE_SEPARATOR)
|
||||
if (at === -1) {
|
||||
return { base: key }
|
||||
}
|
||||
return { base: key.slice(0, at), typeKey: key.slice(at + TYPE_SEPARATOR.length) }
|
||||
}
|
||||
|
||||
function scopeOfGrant(grants: readonly Grant[], key: string): Scope | undefined {
|
||||
return grants.find((grant) => grant.key === key)?.scope
|
||||
}
|
||||
@@ -39,7 +51,7 @@ export function effectiveScope(
|
||||
options: ScopeOptions = {},
|
||||
): Scope {
|
||||
if (options.typeKey) {
|
||||
const typed = scopeOfGrant(grants, `${key}${TYPE_SEPARATOR}${options.typeKey}`)
|
||||
const typed = scopeOfGrant(grants, formatGrantKey(key, options.typeKey))
|
||||
if (typed !== undefined) {
|
||||
return typed
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user