Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/28833-condition-builder-admin-subject.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@object-ui/app-shell': patch
---

fix(app-shell): the condition builder offers `user.isPlatformAdmin` instead of `user.isAdmin` and `user.role`

Clause-②: no
Metadata-protocol: none

The no-code condition builder's subject list offered `user.isAdmin` and `user.role`. Neither builds an admin gate. `user.isAdmin` is not a member of the identity the browser evaluates against, so a row on it faults: a field or action `visible` gate then shows the item to everyone, and a navigation gate hides it from everyone. `user.role` is better-auth's legacy scalar, which ObjectStack never writes and which reads `user` for a signed-in platform admin too.

The list now offers `user.isPlatformAdmin`, the platform-admin flag the identity carries on every branch (`false` when signed out), and no longer offers `user.role`. The raw editor's example placeholder teaches `user.isPlatformAdmin` as well. A stored condition on either old subject still opens in row mode with its subject intact and is never rewritten. A new test evaluates every offered `user.*` subject against the real expression scope, so the list cannot drift from it again.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function Harness({ context }: { context?: WidgetContext }) {
);
}

/** The root of a subject spelling — `user` for `user.isAdmin`. */
/** The root of a subject spelling — `user` for `user.isPlatformAdmin`. */
const rootOf = (subject: string) => subject.split('.')[0];

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ describe('the default subject vocabulary ↔ the engine (objectui#9855)', () =>
// narrows it by DECLARING a `context` instead. Both legs are asserted so
// this cannot be satisfied by an empty dropdown.
const subjects = contextSubjectsOf(await defaultSubjects());
expect(subjects).toContain('user.isAdmin');
expect(subjects).toContain('user.isPlatformAdmin');
expect(subjects).toContain('record.id');
expect(await errorsFor('user.isAdmin')).toEqual([]);
expect(await errorsFor('user.isPlatformAdmin')).toEqual([]);
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* The row builder's `user.*` subjects are members of the bag the browser
* really evaluates against (objectstack#28833).
*
* `CONTEXT_SUBJECTS` offered `user.isAdmin`, which `buildExpressionUser` never
* put on the bound `user` object, and `user.role`, the legacy better-auth
* scalar. The engine's LINT cannot see either problem: it accepts any member of
* an accepted root, so `ConditionBuilder.contextSubjects.test.tsx` stayed green
* on `user.isAdmin`. What can see it is the bag, so these cases read the member
* list off `buildExpressionUser` on both branches and evaluate every offered
* subject against `buildExpressionScope`, the one scope the app-shell binds.
*
* Derived, not retyped (ui AGENTS.md #9): a member renamed or dropped in
* `expressionUser.ts` reddens here, and so does a subject added to the list
* that the bag does not carry.
*/

import { describe, it, expect } from 'vitest';

import { CEL_EXAMPLE_CLAUSES, CONTEXT_SUBJECTS, celRootsMentioned } from './ConditionBuilder';
import { buildExpressionUser } from '../../../providers/expressionUser';
import { createExpressionEvaluator } from '../../../providers/ExpressionProvider';

const ADMIN = { id: 'u-admin', name: 'Ada', email: 'ada@example.com', isPlatformAdmin: true };
const MEMBER = { id: 'u-member', name: 'Bo', email: 'bo@example.com' };

/** The three identities a client gate meets: admin, ordinary member, signed out. */
const BRANCHES = [
['platform admin', buildExpressionUser(ADMIN)],
['member', buildExpressionUser(MEMBER)],
['anonymous', buildExpressionUser(null)],
] as const;

const USER_SUBJECTS = CONTEXT_SUBJECTS.map((s) => s.value).filter((v) => v.startsWith('user.'));

/** Evaluate on the evaluator's fail-closed seam: a fault throws instead of answering `true`. */
function evaluate(expr: string, user: Record<string, unknown>): boolean {
return createExpressionEvaluator({ user }).evaluateCondition(expr, { throwOnError: true });
}

/* ── control — the instrument can FAIL ─────────────────────────────────── */

describe('the bag refuses the members this card removed (objectstack#28833)', () => {
it('`user.isAdmin` faults on every branch: it is not a member of the bag', () => {
// Run first: every case below is worthless if a missing member does not
// fault. If `buildExpressionUser` ever grows an `isAdmin`, this reddens and
// the removal gets re-read instead of outliving its reason.
for (const [branch, user] of BRANCHES) {
expect(Object.keys(user), branch).not.toContain('isAdmin');
expect(() => evaluate('user.isAdmin', user), branch).toThrow();
}
});

it('`user.role` is in the bag but answers no admin question: a signed-in admin reads `user`', () => {
// Why it was dropped rather than kept: the member resolves, so the bag pin
// alone would admit it. It is the legacy scalar, defaulted to `user` for
// every session, platform admins included.
expect(evaluate("user.role == 'user'", buildExpressionUser(ADMIN))).toBe(true);
expect(USER_SUBJECTS).not.toContain('user.role');
});
});

/* ── subject — every offered `user.*` member is in the bag ─────────────── */

describe('every `user.*` subject the dropdown offers is a member of the bag (objectstack#28833)', () => {
it('offers some `user.*` subject at all — an empty list would satisfy the cases below', () => {
expect(USER_SUBJECTS).toContain('user.isPlatformAdmin');
});

it.each(BRANCHES)('each subject is an own key of the %s identity and evaluates without a fault', (_branch, user) => {
for (const subject of USER_SUBJECTS) {
const member = subject.slice('user.'.length);
expect(Object.keys(user), subject).toContain(member);
expect(() => evaluate(`${subject} != null`, user), subject).not.toThrow();
}
});

it('a row "user.isPlatformAdmin is true" opens for the platform admin and no one else', () => {
// The row builder compiles a value-less truthy row on a context subject to
// the bare subject; this is the gate the card's author was trying to build.
expect(evaluate('user.isPlatformAdmin', buildExpressionUser(ADMIN))).toBe(true);
expect(evaluate('user.isPlatformAdmin', buildExpressionUser(MEMBER))).toBe(false);
expect(evaluate('user.isPlatformAdmin', buildExpressionUser(null))).toBe(false);
});
});

/* ── the raw editor's worked example teaches the same members ──────────── */

describe('the placeholder example names only members the bag carries (objectstack#28833)', () => {
it('teaches a `user` clause, and that clause evaluates on every branch', () => {
const userClauses = CEL_EXAMPLE_CLAUSES.filter((c) => celRootsMentioned(c).includes('user'));
expect(userClauses.length, 'the example teaches no `user` clause: dead instrument').toBeGreaterThan(0);
for (const clause of userClauses) {
for (const [branch, user] of BRANCHES) {
expect(() => evaluate(clause, user), `${clause} (${branch})`).not.toThrow();
}
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,10 @@ describe('#6296 DEFAULT-PATH INVARIANCE — the record-scoped consumers are unto
'record.id',
'user.id',
'user.email',
'user.role',
'user.isAdmin',
'user.isPlatformAdmin',
// ⛔ no `user.role` (the legacy better-auth scalar) and no `user.isAdmin`
// (a member the bag never carried); the bag half is pinned in
// `ConditionBuilder.contextSubjectsBag.test.ts`.
// ⛔ no `org.id`: objectui#9855 withdrew it — no host binds an `org` root
// and the engine refuses the spelling. The verdict behind that removal is
// re-derived from the engine in `ConditionBuilder.contextSubjects.test.tsx`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,35 @@ function declaredSubjectValues(
* raw editor's SUGGESTIONS, so a mount that loses one loses an offer and keeps
* the spelling; this list is the row builder's ONLY subject control, so
* dropping an entry drops the author's ability to build that row at all.
*
* ## Every `user.*` member is a key the bag really carries (objectstack#28833)
*
* The `user` object `buildExpressionScope` binds is `buildExpressionUser`'s
* output (`providers/expressionUser.ts`), and a member it does not put there
* is not `false`: the predicate FAULTS, which a fail-open gate (an action's or
* a field's `visible`) answers by showing the item to everyone and a
* withholding gate (navigation) answers by showing it to no one. Either way an
* admin gate built on such a member never means "admins only".
*
* - `user.isPlatformAdmin` is the platform-admin signal, carried on both the
* signed-in and the anonymous branch (anonymous: `false`). It replaces an
* `isAdmin` member no producer ever set.
* - ⛔ No `user.role`. The bag does carry it, but it is better-auth's legacy
* `sys_user.role` scalar: ObjectStack never writes it (ADR-0068 D2), it
* reads `user` for a signed-in platform admin too, and offering it beside
* the other identity members reads as "the platform role". A stored
* `user.role` row still opens in row mode, because an out-of-vocabulary
* subject is appended as its own option.
*
* `ConditionBuilder.contextSubjectsBag.test.ts` re-derives the member list
* from `buildExpressionUser` on both branches and evaluates each subject
* against the real bag, so a member renamed or dropped there reddens here.
*/
const CONTEXT_SUBJECTS = [
export const CONTEXT_SUBJECTS: ReadonlyArray<{ value: string; label?: string }> = [
{ value: 'record.id', label: 'record.id' },
{ value: 'user.id', label: 'user.id' },
{ value: 'user.email', label: 'user.email' },
{ value: 'user.role', label: 'user.role' },
{ value: 'user.isAdmin', label: 'user.isAdmin' },
{ value: 'user.isPlatformAdmin', label: 'user.isPlatformAdmin' },
];

const norm = (s: string) => s.replace(/\s+/g, ' ').trim();
Expand Down Expand Up @@ -471,8 +493,11 @@ export function celRootsMentioned(expr: string): string[] {
* Each clause carries its own roots in its own text, and {@link
* celExampleForRoots} reads them back out with {@link celRootsMentioned}, so a
* clause cannot claim a root it does not spell.
*
* A `user.*` clause names a member the bag carries, the rule
* {@link CONTEXT_SUBJECTS} states, pinned by the same test.
*/
const CEL_EXAMPLE_CLAUSES = ["record.status != 'done'", 'user.isAdmin'] as const;
export const CEL_EXAMPLE_CLAUSES = ["record.status != 'done'", 'user.isPlatformAdmin'] as const;

/**
* The placeholder example for a mount that offers `offered` — every clause
Expand Down
Loading