Skip to content

Commit cf2908d

Browse files
committed
refactor(console): keep the effective-access widget module to components only
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5kxrRdCiSKcPqREG4w
1 parent 3555fac commit cf2908d

3 files changed

Lines changed: 69 additions & 51 deletions

File tree

‎ui/packages/app-shell/src/console/security/UserEffectiveAccess.test.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ import {
5454
SchemaRenderer,
5555
type MetadataContextValue,
5656
} from '@object-ui/react';
57-
import { describeOrigin, type EffectiveAccessAnswer } from './UserEffectiveAccess';
57+
import './UserEffectiveAccess';
58+
import { describeOrigin, type EffectiveAccessAnswer } from './effectiveAccess';
5859

5960
const NODE = { type: 'security:effective-access', properties: {} };
6061

‎ui/packages/app-shell/src/console/security/UserEffectiveAccess.tsx‎

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,14 @@ import { useAdapter, useDataInvalidation, useMetadata, useRecordContext } from '
3636
import type { ObjectStackAdapter } from '@object-ui/data-objectstack';
3737
import { AlertCircle, ShieldCheck } from 'lucide-react';
3838
import { catalogEntries } from '../../views/setup/peopleAssignments.js';
39-
40-
type Translate = (key: string, options?: Record<string, unknown>) => string;
41-
42-
type DescribeEffectiveAccess = ReturnType<ObjectStackAdapter['getClient']>['security']['describeEffectiveAccess'];
43-
/** The answer (`EffectiveAccess` of `@objectstack/spec/contracts`, through the client). */
44-
export type EffectiveAccessAnswer = Awaited<ReturnType<DescribeEffectiveAccess>>;
45-
/** One way a set reaches the person (`EffectivePermissionSetOrigin`). */
46-
export type EffectiveAccessOrigin = EffectiveAccessAnswer['permissionSets'][number]['origins'][number];
47-
48-
/** The object whose record pages this widget belongs on. */
49-
export const EFFECTIVE_ACCESS_OBJECT = 'sys_user';
39+
import {
40+
EFFECTIVE_ACCESS_OBJECT,
41+
describeOrigin,
42+
failureText,
43+
httpStatusOf,
44+
originKey,
45+
type EffectiveAccessAnswer,
46+
} from './effectiveAccess.js';
5047

5148
/** The registry type the set labels are read from. */
5249
const PERMISSION_SET_TYPE = 'permission';
@@ -58,45 +55,6 @@ type Read =
5855
| { state: 'unserved' }
5956
| { state: 'failed'; message: string };
6057

61-
/** The status the client stamps on a refused call (`httpStatus`, from `res.status`). */
62-
function httpStatusOf(err: unknown): number | undefined {
63-
const status = (err as { httpStatus?: unknown } | null | undefined)?.httpStatus;
64-
return typeof status === 'number' ? status : undefined;
65-
}
66-
67-
function failureText(err: unknown): string {
68-
const message = (err as { message?: unknown } | null | undefined)?.message;
69-
return typeof message === 'string' && message ? message : String(err);
70-
}
71-
72-
/** Where one origin says the set comes from. */
73-
export function describeOrigin(origin: EffectiveAccessOrigin, t: Translate): string {
74-
switch (origin.kind) {
75-
case 'direct':
76-
return t('effectiveAccess.origin.direct');
77-
case 'position':
78-
return t('effectiveAccess.origin.position', { position: origin.position });
79-
case 'default':
80-
return t('effectiveAccess.origin.default');
81-
case 'derived':
82-
return origin.source === 'platform_admin_config'
83-
? t('effectiveAccess.origin.derivedPlatformAdmin')
84-
: t('effectiveAccess.origin.derivedAiAccess');
85-
}
86-
}
87-
88-
/** A stable key for one origin of a row. */
89-
function originKey(origin: EffectiveAccessOrigin): string {
90-
switch (origin.kind) {
91-
case 'position':
92-
return `position-${origin.position}`;
93-
case 'derived':
94-
return `derived-${origin.source}`;
95-
default:
96-
return origin.kind;
97-
}
98-
}
99-
10058
export interface UserEffectiveAccessProps {
10159
/** Carries the scope class of the node's `responsiveStyles`. */
10260
className?: string;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The `security:effective-access` widget's vocabulary: the client's answer,
5+
* typed off the adapter's own client, and the words each origin is shown in.
6+
*/
7+
8+
import type { ObjectStackAdapter } from '@object-ui/data-objectstack';
9+
10+
type Translate = (key: string, options?: Record<string, unknown>) => string;
11+
12+
type DescribeEffectiveAccess = ReturnType<ObjectStackAdapter['getClient']>['security']['describeEffectiveAccess'];
13+
/** The answer (`EffectiveAccess` of `@objectstack/spec/contracts`, through the client). */
14+
export type EffectiveAccessAnswer = Awaited<ReturnType<DescribeEffectiveAccess>>;
15+
/** One way a set reaches the person (`EffectivePermissionSetOrigin`). */
16+
export type EffectiveAccessOrigin = EffectiveAccessAnswer['permissionSets'][number]['origins'][number];
17+
18+
/** The object whose record pages the widget belongs on. */
19+
export const EFFECTIVE_ACCESS_OBJECT = 'sys_user';
20+
21+
/** The status the client stamps on a refused call (`httpStatus`, from `res.status`). */
22+
export function httpStatusOf(err: unknown): number | undefined {
23+
const status = (err as { httpStatus?: unknown } | null | undefined)?.httpStatus;
24+
return typeof status === 'number' ? status : undefined;
25+
}
26+
27+
/** A failed call's words: the client throws an `Error` carrying the server's message. */
28+
export function failureText(err: unknown): string {
29+
const message = (err as { message?: unknown } | null | undefined)?.message;
30+
return typeof message === 'string' && message ? message : String(err);
31+
}
32+
33+
/** Where one origin says the set comes from. */
34+
export function describeOrigin(origin: EffectiveAccessOrigin, t: Translate): string {
35+
switch (origin.kind) {
36+
case 'direct':
37+
return t('effectiveAccess.origin.direct');
38+
case 'position':
39+
return t('effectiveAccess.origin.position', { position: origin.position });
40+
case 'default':
41+
return t('effectiveAccess.origin.default');
42+
case 'derived':
43+
return origin.source === 'platform_admin_config'
44+
? t('effectiveAccess.origin.derivedPlatformAdmin')
45+
: t('effectiveAccess.origin.derivedAiAccess');
46+
}
47+
}
48+
49+
/** A stable key for one origin of a row. */
50+
export function originKey(origin: EffectiveAccessOrigin): string {
51+
switch (origin.kind) {
52+
case 'position':
53+
return `position-${origin.position}`;
54+
case 'derived':
55+
return `derived-${origin.source}`;
56+
default:
57+
return origin.kind;
58+
}
59+
}

0 commit comments

Comments
 (0)