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
13 changes: 13 additions & 0 deletions .changeset/25342-delegator-prefill.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export const enObjects: NonNullable<TranslationData['objects']> = {
},
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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export const esESObjects: NonNullable<TranslationData['objects']> = {
},
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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export const esESGeneratedSourceHashes: Readonly<Record<string, string>> = {
"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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export const jaJPObjects: NonNullable<TranslationData['objects']> = {
},
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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const jaJPGeneratedSourceHashes: Readonly<Record<string, string>> = {
"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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export const zhCNObjects: NonNullable<TranslationData['objects']> = {
},
delegator_id: {
label: "委派人",
help: "即将不在岗的用户;规则生效期间,路由到其个人的审批人槽位将被改派。"
help: "即将不在岗的用户。你只能委派自己的审批,所以这里始终是你:默认填入你本人,不提供其他人选。规则生效期间,路由到其个人的审批人槽位将被改派。"
},
delegate_id: {
label: "候补人",
Expand Down
Loading