From 7c3c262cef0618fb1fa35775efe1a55254222423 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 23 Oct 2026 11:45:17 +0000 Subject: [PATCH 1/2] wip(plugin-approvals): default the Delegator to the signed-in user Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_016g7nYP9wdNx1GDa5XDr7Uy --- ...proval-delegation-delegator-picker.test.ts | 23 +++++++++++++++++-- .../src/sys-approval-delegation.object.ts | 11 +++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/packages/plugins/plugin-approvals/src/sys-approval-delegation-delegator-picker.test.ts b/packages/plugins/plugin-approvals/src/sys-approval-delegation-delegator-picker.test.ts index d531e0c86d4..1907d2e910d 100644 --- a/packages/plugins/plugin-approvals/src/sys-approval-delegation-delegator-picker.test.ts +++ b/packages/plugins/plugin-approvals/src/sys-approval-delegation-delegator-picker.test.ts @@ -24,13 +24,21 @@ * 4. the guard is not widened: a create or an update naming anyone else is * still refused, `FORBIDDEN` / 403, and nothing is stored; * 5. `required` stays: a write with no acting user and no delegator is - * refused. + * refused; + * 6. the field defaults to the acting user with the spec's runtime token + * `current_user`, which the spec admits on a `sys_user` lookup, so a new + * delegation opens with its one admissible Delegator already filled. */ import { describe, it, expect, beforeAll, afterAll } from 'vitest'; import { ObjectQL } from '@objectstack/objectql'; import { SqlDriver } from '@objectstack/driver-sql'; -import type { EngineCountOptions, EngineQueryOptions } from '@objectstack/spec/data'; +import { + FieldSchema, + DEFAULT_VALUE_TOKEN_CURRENT_USER, + type EngineCountOptions, + type EngineQueryOptions, +} from '@objectstack/spec/data'; import { SysApprovalDelegation } from './sys-approval-delegation.object.js'; import { bindDelegationWriteGuard } from './lifecycle-hooks.js'; import { installDefaultOrganization } from './default-organization.testkit.js'; @@ -121,6 +129,17 @@ describe('sys_approval_delegation — the Delegator picker offers only what the expect(registered.lookupFilters).toEqual(ACTING_USER_ONLY); }); + it('defaults to the acting user with the spec\'s `current_user` token, and the spec admits it on this field', () => { + const field = delegatorField(); + expect(field.defaultValue).toBe(DEFAULT_VALUE_TOKEN_CURRENT_USER); + expect((engine.registry.getObject(OBJECT) as any).fields.delegator_id.defaultValue) + .toBe(DEFAULT_VALUE_TOKEN_CURRENT_USER); + // A token on a field it cannot default is refused at parse time; a full + // parse of this field must be green. + const parsed = FieldSchema.safeParse({ name: 'delegator_id', ...field }); + expect(parsed.success, JSON.stringify(parsed.error?.issues)).toBe(true); + }); + it.each(USERS.map((u) => [u.id]))('the picker offers %s themselves and nobody else', async (caller) => { const candidates = await engine.find('sys_user', pickerQuery(), asUser(caller)); expect(candidates.map((r: any) => r.id)).toEqual([caller]); diff --git a/packages/plugins/plugin-approvals/src/sys-approval-delegation.object.ts b/packages/plugins/plugin-approvals/src/sys-approval-delegation.object.ts index 7c1d42c3692..006498300f4 100644 --- a/packages/plugins/plugin-approvals/src/sys-approval-delegation.object.ts +++ b/packages/plugins/plugin-approvals/src/sys-approval-delegation.object.ts @@ -94,13 +94,20 @@ export const SysApprovalDelegation = ObjectSchema.create({ // `lookupFilters` is the picker's candidate query, and the engine resolves // `{current_user_id}` against the caller on every read. Presentation only // — the guard stays the enforcement, and what a write may store is - // unchanged. Pinned in `sys-approval-delegation-delegator-picker.test.ts`. + // unchanged. Since that one value is always the acting user, the field + // also defaults to it: `defaultValue: 'current_user'` is the spec's + // runtime token for a `sys_user` lookup (`DEFAULT_VALUE_TOKENS`), so a new + // delegation opens with the Delegator already filled instead of at an + // empty picker. Pinned in `sys-approval-delegation-delegator-picker.test.ts`. delegator_id: Field.lookup('sys_user', { label: 'Delegator', required: true, + defaultValue: 'current_user', lookupFilters: [{ field: 'id', operator: 'eq', value: '{current_user_id}' }], group: 'Delegation', - description: 'The user going out of office; their individually-routed approver slots are rerouted while active.', + description: + 'The user going out of office. You can delegate only your own approvals, so this is always you: ' + + 'it starts as you and offers no one else. Their individually-routed approver slots are rerouted while active.', }), delegate_id: Field.lookup('sys_user', { From 4194149960094594115e755890af323d69766d47 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 23 Oct 2026 11:55:32 +0000 Subject: [PATCH 2/2] fix(plugin-approvals): say why the Delegator is always you, in every locale; changeset Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_016g7nYP9wdNx1GDa5XDr7Uy --- .changeset/25342-delegator-prefill.md | 13 +++++++++++++ .../src/translations/en.objects.generated.ts | 2 +- .../src/translations/es-ES.objects.generated.ts | 2 +- .../translations/es-ES.source-hashes.generated.ts | 1 - .../src/translations/ja-JP.objects.generated.ts | 2 +- .../translations/ja-JP.source-hashes.generated.ts | 1 - .../src/translations/zh-CN.objects.generated.ts | 2 +- 7 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 .changeset/25342-delegator-prefill.md diff --git a/.changeset/25342-delegator-prefill.md b/.changeset/25342-delegator-prefill.md new file mode 100644 index 00000000000..14c8fb61997 --- /dev/null +++ b/.changeset/25342-delegator-prefill.md @@ -0,0 +1,13 @@ +--- +'@objectstack/plugin-approvals': patch +--- + +fix: a new out-of-office delegation opens with the Delegator already set to the signed-in user, and the field's help says why no one else can be chosen + +Clause-②: no +Metadata-protocol: none + +The Delegator of `sys_approval_delegation` (Setup → Delegations) only ever offers the signed-in user, because the delegation write guard admits nobody else. The field still opened empty, and a search for a colleague answered "No options found" with no reason. + +- `delegator_id` now declares `defaultValue: 'current_user'`, the spec's runtime token for a `sys_user` lookup, so the one admissible value is filled in from the start. The write guard is unchanged and stays the enforcement. +- The field's help now reads: "The user going out of office. You can delegate only your own approvals, so this is always you: it starts as you and offers no one else." The `es-ES`, `ja-JP` and `zh-CN` bundles carry the translated text. diff --git a/packages/plugins/plugin-approvals/src/translations/en.objects.generated.ts b/packages/plugins/plugin-approvals/src/translations/en.objects.generated.ts index ab7de8b4e72..06e96b8102a 100644 --- a/packages/plugins/plugin-approvals/src/translations/en.objects.generated.ts +++ b/packages/plugins/plugin-approvals/src/translations/en.objects.generated.ts @@ -354,7 +354,7 @@ export const enObjects: NonNullable = { }, delegator_id: { label: "Delegator", - help: "The user going out of office; their individually-routed approver slots are rerouted while active." + help: "The user going out of office. You can delegate only your own approvals, so this is always you: it starts as you and offers no one else. Their individually-routed approver slots are rerouted while active." }, delegate_id: { label: "Delegate", diff --git a/packages/plugins/plugin-approvals/src/translations/es-ES.objects.generated.ts b/packages/plugins/plugin-approvals/src/translations/es-ES.objects.generated.ts index 00792b3d56c..99e249999bf 100644 --- a/packages/plugins/plugin-approvals/src/translations/es-ES.objects.generated.ts +++ b/packages/plugins/plugin-approvals/src/translations/es-ES.objects.generated.ts @@ -354,7 +354,7 @@ export const esESObjects: NonNullable = { }, delegator_id: { label: "Delegator", - help: "The user going out of office; their individually-routed approver slots are rerouted while active." + help: "El usuario que se ausenta. Solo puedes delegar tus propias aprobaciones, así que siempre eres tú: el campo empieza contigo y no ofrece a nadie más. Mientras la delegación está activa, los puestos de aprobador asignados a esa persona se reenrutan." }, delegate_id: { label: "Delegate", diff --git a/packages/plugins/plugin-approvals/src/translations/es-ES.source-hashes.generated.ts b/packages/plugins/plugin-approvals/src/translations/es-ES.source-hashes.generated.ts index 37e6b847bc4..d51cd41dad7 100644 --- a/packages/plugins/plugin-approvals/src/translations/es-ES.source-hashes.generated.ts +++ b/packages/plugins/plugin-approvals/src/translations/es-ES.source-hashes.generated.ts @@ -26,7 +26,6 @@ export const esESGeneratedSourceHashes: Readonly> = { "objects.sys_approval_delegation.fields.created_at.label": "1f02d416befb595b", "objects.sys_approval_delegation.fields.delegate_id.help": "9cfc641f7b0b04f9", "objects.sys_approval_delegation.fields.delegate_id.label": "afd6d8733dc5bc14", - "objects.sys_approval_delegation.fields.delegator_id.help": "c4686c5c9f24e0be", "objects.sys_approval_delegation.fields.delegator_id.label": "f76b1f95f2fdabff", "objects.sys_approval_delegation.fields.display_title.help": "2831a1ffde72b425", "objects.sys_approval_delegation.fields.display_title.label": "70f7aadecce647a5", diff --git a/packages/plugins/plugin-approvals/src/translations/ja-JP.objects.generated.ts b/packages/plugins/plugin-approvals/src/translations/ja-JP.objects.generated.ts index 02141b6bbc6..1bab525a9a9 100644 --- a/packages/plugins/plugin-approvals/src/translations/ja-JP.objects.generated.ts +++ b/packages/plugins/plugin-approvals/src/translations/ja-JP.objects.generated.ts @@ -354,7 +354,7 @@ export const jaJPObjects: NonNullable = { }, delegator_id: { label: "Delegator", - help: "The user going out of office; their individually-routed approver slots are rerouted while active." + help: "不在になるユーザーです。委任できるのは自分の承認だけなので、常にあなた自身です。最初からあなたが設定され、ほかのユーザーは選べません。有効な間、その人に個別に割り当てられた承認者枠は振り替えられます。" }, delegate_id: { label: "Delegate", diff --git a/packages/plugins/plugin-approvals/src/translations/ja-JP.source-hashes.generated.ts b/packages/plugins/plugin-approvals/src/translations/ja-JP.source-hashes.generated.ts index 16edecc272a..47a94db873d 100644 --- a/packages/plugins/plugin-approvals/src/translations/ja-JP.source-hashes.generated.ts +++ b/packages/plugins/plugin-approvals/src/translations/ja-JP.source-hashes.generated.ts @@ -25,7 +25,6 @@ export const jaJPGeneratedSourceHashes: Readonly> = { "objects.sys_approval_delegation.fields.created_at.label": "1f02d416befb595b", "objects.sys_approval_delegation.fields.delegate_id.help": "9cfc641f7b0b04f9", "objects.sys_approval_delegation.fields.delegate_id.label": "afd6d8733dc5bc14", - "objects.sys_approval_delegation.fields.delegator_id.help": "c4686c5c9f24e0be", "objects.sys_approval_delegation.fields.delegator_id.label": "f76b1f95f2fdabff", "objects.sys_approval_delegation.fields.display_title.help": "2831a1ffde72b425", "objects.sys_approval_delegation.fields.display_title.label": "70f7aadecce647a5", diff --git a/packages/plugins/plugin-approvals/src/translations/zh-CN.objects.generated.ts b/packages/plugins/plugin-approvals/src/translations/zh-CN.objects.generated.ts index 2668a86fa1d..38e8859ca2b 100644 --- a/packages/plugins/plugin-approvals/src/translations/zh-CN.objects.generated.ts +++ b/packages/plugins/plugin-approvals/src/translations/zh-CN.objects.generated.ts @@ -354,7 +354,7 @@ export const zhCNObjects: NonNullable = { }, delegator_id: { label: "委派人", - help: "即将不在岗的用户;规则生效期间,路由到其个人的审批人槽位将被改派。" + help: "即将不在岗的用户。你只能委派自己的审批,所以这里始终是你:默认填入你本人,不提供其他人选。规则生效期间,路由到其个人的审批人槽位将被改派。" }, delegate_id: { label: "候补人",