Skip to content

Commit a8614e4

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/issue-24512-conditional-when-hydration
2 parents 9b80c99 + 14ccb1d commit a8614e4

14 files changed

Lines changed: 894 additions & 45 deletions
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@objectstack/spec': minor
3+
---
4+
5+
feat(spec/ui): `navItemVisibleDataNeedsDataSource` is exported from `@objectstack/spec/ui`, so a mirror of `NavigationItemSchema` attaches the spec's own rule by identifier
6+
7+
Clause-②: yes (widening)
8+
9+
- **What is added.** One function export, `navItemVisibleDataNeedsDataSource(item, ctx)`: the refinement `NavigationItemSchema` already runs, which refuses a navigation entry with no `dataSource` whose `visible` reads `data`. It is exported the way `objectNavTargetExclusivity`, `checkPageRegionPlacement` and `checkPageMainRegionWidth` are, so a hand-written mirror of the navigation item can chain the same function in its own `superRefine` instead of restating the rule.
10+
- **What does not change.** No schema accepts or refuses anything new. The issue is the same: one `custom` issue at `visible`, with the same message. `NavigationItemSchema` still attaches the same function, once, by name.
11+
- **What the function reads.** Both spellings of `visible`, so it answers the same on an entry as authored and as parsed:
12+
- the authored bare string (`'data.total == 1'`), normalised by `EvaluatedExpressionInputSchema`, the slot's own schema, exactly as the spec's parse normalises it;
13+
- the parsed `{ dialect: 'cel', source }` envelope.
14+
15+
A boolean or absent `visible` judges nothing. So a mirror whose own `visible` stays the authored string chains the function as it is and refuses what the spec refuses.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
'@objectstack/service-automation': minor
3+
'@objectstack/spec': minor
4+
---
5+
6+
fix(service-automation): a `runAs: 'user'` flow now carries its user's email, so a row policy on `current_user.email` admits the run on the rows it admits for the same user's own request
7+
8+
Clause-②: yes (widening)
9+
10+
A `runAs: 'user'` flow's data nodes ran without the acting user's email, which the request path resolves for every user. The row-level security compiler reads `current_user.email` from the execution context's `email` and nothing else, so every owner policy keyed on it (such as `assignee == current_user.email`) dropped out inside the run. A record-change flow triggered by a member whose only access to a row is such a policy was refused on the row the member had just written, and could read and update with their own request.
11+
12+
Run setup now seeds the email through the resolver the request path uses (`resolveUserAuthzGrants` from `@objectstack/core`, the user's stored `sys_user` email), and every data node passes it on:
13+
14+
- It is seeded for every trigger shape that names a user and carries no email: the record-change shape (`userId` and `tenantId` only) and the REST and action doors' shape (positions and permission sets already resolved). Only the missing facts are taken from the resolver; forwarded positions and permission sets stay exactly as they were.
15+
- A context that already carries an email keeps it verbatim, as a request's session email wins over the stored one. A `subflow` or `map` child and a suspended run keep the email their run was seeded with.
16+
- After an approval decision, the nodes that run as the decider carry the decider's own email, resolved for them. The submitter's email is removed with the rest of the submitter's grants, on both `runAs` postures.
17+
- A user with no stored email, or a resolver failure, leaves the run without one: policies that read it drop out, and the run sees less, never more. The `[runAs]` warning on a resolver failure now names the email beside the peer list.
18+
- A run suspended before this release resumes without the email until it ends.
19+
20+
A `runAs: 'system'` flow is unchanged. The flow CEL scope's `current_user` is unchanged too: it still binds no email.
21+
22+
Published types: `AutomationContext` (`@objectstack/spec/contracts`) gains an optional `email` member, and `RunIdentityContext` / `RunDataContext` and `FlowUserGrants` (`@objectstack/service-automation`) each gain an optional `email` member.

‎packages/services/service-automation/src/builtin/crud-runas.test.ts‎

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ describe("runAs:'user' resolves the triggering user's grants at run setup (#3356
449449
const seen: Array<{ userId: string; tenantId?: string }> = [];
450450
engine.setUserGrantsResolver((userId, tenantId) => {
451451
seen.push({ userId, tenantId });
452-
return { positions: ['SHOULD_NOT_APPLY'], permissions: ['SHOULD_NOT_APPLY'], org_user_ids: ['u1', 'u2'] };
452+
return { positions: ['SHOULD_NOT_APPLY'], permissions: ['SHOULD_NOT_APPLY'], org_user_ids: ['u1', 'u2'], email: 'u1@example.test' };
453453
});
454454

455455
// An already-resolved envelope — e.g. an ADR-0090 agent ceiling acting
@@ -463,10 +463,11 @@ describe("runAs:'user' resolves the triggering user's grants at run setup (#3356
463463
expect(c.ctx.permissions).toEqual(['mcp_agent_read']);
464464
expect(c.ctx.positions).toEqual(['agent']);
465465
expect(c.ctx.org_user_ids, `${c.op} lost the seeded peer list`).toEqual(['u1', 'u2']);
466+
expect(c.ctx.email, `${c.op} lost the seeded email`).toBe('u1@example.test');
466467
}
467468
});
468469

469-
it('resolves nothing when the trigger already carried permissions AND a peer list (a subflow child, a resumed leg)', async () => {
470+
it('resolves nothing when the trigger already carried permissions, a peer list AND an email (a subflow child, a resumed leg)', async () => {
470471
const engine = new AutomationEngine(makeLogger());
471472
const { data, calls } = fakeData();
472473
registerCrudNodes(engine, ctxWith(data));
@@ -475,20 +476,93 @@ describe("runAs:'user' resolves the triggering user's grants at run setup (#3356
475476
let called = 0;
476477
engine.setUserGrantsResolver(() => {
477478
called++;
478-
return { positions: ['SHOULD_NOT_APPLY'], permissions: ['SHOULD_NOT_APPLY'], org_user_ids: ['SHOULD_NOT_APPLY'] };
479+
return { positions: ['SHOULD_NOT_APPLY'], permissions: ['SHOULD_NOT_APPLY'], org_user_ids: ['SHOULD_NOT_APPLY'], email: 'SHOULD_NOT_APPLY' };
479480
});
480481

481482
await engine.execute('usr', {
482-
userId: 'u1', positions: ['member'], permissions: ['member_default'], tenantId: 't1', org_user_ids: ['u1', 'u3'],
483+
userId: 'u1', positions: ['member'], permissions: ['member_default'], tenantId: 't1', org_user_ids: ['u1', 'u3'], email: 'u1@example.test',
483484
} as SeededRunContext);
484485
expect(called).toBe(0);
485486
expect(calls.length).toBeGreaterThan(0);
486487
for (const c of calls) {
487488
expect(c.ctx.permissions).toEqual(['member_default']);
488489
expect(c.ctx.org_user_ids).toEqual(['u1', 'u3']);
490+
expect(c.ctx.email).toBe('u1@example.test');
491+
}
492+
});
493+
494+
it('a context carrying permissions and a peer list but no email resolves the email alone, and keeps the rest verbatim', async () => {
495+
const engine = new AutomationEngine(makeLogger());
496+
const { data, calls } = fakeData();
497+
registerCrudNodes(engine, ctxWith(data));
498+
engine.registerFlow('usr', allOpsFlow('usr', 'user'));
499+
500+
const seen: Array<{ userId: string; tenantId?: string }> = [];
501+
engine.setUserGrantsResolver((userId, tenantId) => {
502+
seen.push({ userId, tenantId });
503+
return { positions: ['SHOULD_NOT_APPLY'], permissions: ['SHOULD_NOT_APPLY'], org_user_ids: ['SHOULD_NOT_APPLY'], email: 'u1@example.test' };
504+
});
505+
506+
await engine.execute('usr', {
507+
userId: 'u1', positions: ['member'], permissions: ['member_default'], tenantId: 't1', org_user_ids: ['u1', 'u3'],
508+
} as SeededRunContext);
509+
expect(seen).toEqual([{ userId: 'u1', tenantId: 't1' }]);
510+
expect(calls.length).toBeGreaterThan(0);
511+
for (const c of calls) {
512+
expect(c.ctx.positions).toEqual(['member']);
513+
expect(c.ctx.permissions).toEqual(['member_default']);
514+
expect(c.ctx.org_user_ids).toEqual(['u1', 'u3']);
515+
expect(c.ctx.email, `${c.op} lost the seeded email`).toBe('u1@example.test');
516+
}
517+
});
518+
519+
it('seeds the email beside the resolved grants and threads it to EVERY data op', async () => {
520+
const engine = new AutomationEngine(makeLogger());
521+
const { data, calls } = fakeData();
522+
registerCrudNodes(engine, ctxWith(data));
523+
engine.registerFlow('usr', allOpsFlow('usr', 'user'));
524+
engine.setUserGrantsResolver(() => ({ positions: ['org_member'], permissions: ['member_default'], org_user_ids: ['u1'], email: 'u1@example.test' }));
525+
526+
// The record-change trigger's shape: a user id and an organization, no email.
527+
const res = await engine.execute('usr', { userId: 'u1', tenantId: 't1' });
528+
expect(res.success).toBe(true);
529+
expect(calls.length).toBeGreaterThan(0);
530+
for (const c of calls) expect(c.ctx.email, `${c.op} lost the seeded email`).toBe('u1@example.test');
531+
});
532+
533+
it('a context that already carries an email keeps it verbatim; the resolver\'s stored one is not applied', async () => {
534+
const engine = new AutomationEngine(makeLogger());
535+
const { data, calls } = fakeData();
536+
registerCrudNodes(engine, ctxWith(data));
537+
engine.registerFlow('usr', allOpsFlow('usr', 'user'));
538+
let called = 0;
539+
engine.setUserGrantsResolver(() => {
540+
called++;
541+
return { positions: ['org_member'], permissions: ['member_default'], org_user_ids: ['u1'], email: 'SHOULD_NOT_APPLY' };
542+
});
543+
544+
// A door that forwards the request's own (session) email.
545+
await engine.execute('usr', { userId: 'u1', tenantId: 't1', email: 'u1.session@example.test' });
546+
expect(called, 'the other facts are still resolved').toBe(1);
547+
expect(calls.length).toBeGreaterThan(0);
548+
for (const c of calls) {
549+
expect(c.ctx.email).toBe('u1.session@example.test');
550+
expect(c.ctx.permissions).toEqual(['member_default']);
489551
}
490552
});
491553

554+
it('a resolver that answers no email seeds none — the data context carries no email, never a made-up one', async () => {
555+
const engine = new AutomationEngine(makeLogger());
556+
const { data, calls } = fakeData();
557+
registerCrudNodes(engine, ctxWith(data));
558+
engine.registerFlow('usr', allOpsFlow('usr', 'user'));
559+
engine.setUserGrantsResolver(() => ({ positions: ['org_member'], permissions: ['member_default'], org_user_ids: ['u1'] }));
560+
561+
await engine.execute('usr', { userId: 'u1', tenantId: 't1' });
562+
expect(calls.length).toBeGreaterThan(0);
563+
for (const c of calls) expect('email' in c.ctx, `${c.op} carried an invented email`).toBe(false);
564+
});
565+
492566
it('seeds the peer list beside the resolved grants and threads it to EVERY data op', async () => {
493567
const engine = new AutomationEngine(makeLogger());
494568
const { data, calls } = fakeData();
@@ -529,6 +603,7 @@ describe("runAs:'user' resolves the triggering user's grants at run setup (#3356
529603
expect(c.ctx.isSystem).toBe(false);
530604
expect(c.ctx.permissions).toEqual(['member_default']);
531605
expect('org_user_ids' in c.ctx).toBe(false);
606+
expect('email' in c.ctx).toBe(false);
532607
}
533608
});
534609

0 commit comments

Comments
 (0)