diff --git a/.changeset/36017-show-user-manager.md b/.changeset/36017-show-user-manager.md new file mode 100644 index 00000000000..4c4a9572e29 --- /dev/null +++ b/.changeset/36017-show-user-manager.md @@ -0,0 +1,15 @@ +--- +'@objectstack/platform-objects': patch +--- + +fix(platform-objects): Setup → Users shows who a user's manager is, who reports to them, and can remove a manager + +Clause-②: no +Metadata-protocol: none + +An administrator who set a user's manager could not read it back anywhere in Setup: the record page's Details tab named no section holding `manager_id`, no list showed the people reporting to a user, and the Set Manager dialog opened on an empty picker. The value was stored correctly; only the reading back was missing. + +- **Details → Reporting Line** shows the user's manager (`sys_user.manager_id`, still read-only on the record; it is written only through the admin endpoint). +- **Details → Direct Reports** lists the users whose manager is this user. It is read-only: a report's manager is changed on that report's record. +- **Set Manager** now opens on the current manager (the param is field-backed on `manager_id` with `defaultFromRow`), so an admin sees what a re-point replaces. The request body is unchanged: `{ userId, managerId }`. +- **Remove Manager** (new `sys_user` action `remove_user_manager`, on the row menu and the record header) clears the link by posting `managerId: null` to `POST /api/v1/auth/admin/set-user-manager`. It carries the same platform-admin gate as Set Manager, is offered only while the user has a manager, asks for confirmation, and is not exposed to AI agents. The endpoint's refusals are unchanged and apply to the clear too: an identity a SCIM directory holds is refused there. diff --git a/packages/platform-objects/src/apps/translations/ar.objects.generated.ts b/packages/platform-objects/src/apps/translations/ar.objects.generated.ts index 8921dc0efe6..13dcacc4ce0 100644 --- a/packages/platform-objects/src/apps/translations/ar.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/ar.objects.generated.ts @@ -328,6 +328,11 @@ export const arObjects: NonNullable = { } } }, + remove_user_manager: { + label: "إزالة المدير", + confirmText: "هل تريد إزالة مدير هذا المستخدم؟ لن يتبع أحدًا حتى يُعيَّن مدير من جديد، ويتبع توجيه الموافقات ونطاق السجلات own_and_reports هذا التغيير.", + successMessage: "تمت إزالة المدير" + }, list_platform_admins: { label: "مسؤولو المنصة", resultDialog: { diff --git a/packages/platform-objects/src/apps/translations/de.objects.generated.ts b/packages/platform-objects/src/apps/translations/de.objects.generated.ts index ae79ce9f681..8e0a89d2540 100644 --- a/packages/platform-objects/src/apps/translations/de.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/de.objects.generated.ts @@ -328,6 +328,11 @@ export const deObjects: NonNullable = { } } }, + remove_user_manager: { + label: "Vorgesetzten entfernen", + confirmText: "Den Vorgesetzten dieses Benutzers entfernen? Bis erneut ein Vorgesetzter festgelegt wird, berichtet er an niemanden; das Genehmigungsrouting und der Datensatzbereich own_and_reports folgen der Änderung.", + successMessage: "Vorgesetzter entfernt" + }, list_platform_admins: { label: "Plattformadministratoren", resultDialog: { diff --git a/packages/platform-objects/src/apps/translations/en.objects.generated.ts b/packages/platform-objects/src/apps/translations/en.objects.generated.ts index e5165598536..c9a117735ba 100644 --- a/packages/platform-objects/src/apps/translations/en.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/en.objects.generated.ts @@ -328,6 +328,11 @@ export const enObjects: NonNullable = { } } }, + remove_user_manager: { + label: "Remove Manager", + confirmText: "Remove this user's manager? They will report to no one until a manager is set again; approval routing and the own_and_reports record scope follow the change.", + successMessage: "Manager removed" + }, list_platform_admins: { label: "Platform Administrators", resultDialog: { diff --git a/packages/platform-objects/src/apps/translations/es-ES.objects.generated.ts b/packages/platform-objects/src/apps/translations/es-ES.objects.generated.ts index 922c98c2e1b..63122d81f38 100644 --- a/packages/platform-objects/src/apps/translations/es-ES.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/es-ES.objects.generated.ts @@ -328,6 +328,11 @@ export const esESObjects: NonNullable = { } } }, + remove_user_manager: { + label: "Quitar gerente", + confirmText: "¿Quitar el gerente de este usuario? No reportará a nadie hasta que se vuelva a asignar un gerente; el enrutamiento de aprobaciones y el ámbito de registros own_and_reports siguen el cambio.", + successMessage: "Gerente quitado" + }, list_platform_admins: { label: "Administradores de la plataforma", resultDialog: { diff --git a/packages/platform-objects/src/apps/translations/fr.objects.generated.ts b/packages/platform-objects/src/apps/translations/fr.objects.generated.ts index b83c9c39094..1c2806acb2e 100644 --- a/packages/platform-objects/src/apps/translations/fr.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/fr.objects.generated.ts @@ -328,6 +328,11 @@ export const frObjects: NonNullable = { } } }, + remove_user_manager: { + label: "Retirer le responsable", + confirmText: "Retirer le responsable de cet utilisateur ? Il ne rendra compte à personne tant qu’un responsable n’est pas de nouveau défini ; le routage des approbations et la portée d’enregistrements own_and_reports suivent ce changement.", + successMessage: "Responsable retiré" + }, list_platform_admins: { label: "Administrateurs de la plateforme", resultDialog: { diff --git a/packages/platform-objects/src/apps/translations/ja-JP.objects.generated.ts b/packages/platform-objects/src/apps/translations/ja-JP.objects.generated.ts index 1fe0d29c16c..73746d28ff4 100644 --- a/packages/platform-objects/src/apps/translations/ja-JP.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/ja-JP.objects.generated.ts @@ -328,6 +328,11 @@ export const jaJPObjects: NonNullable = { } } }, + remove_user_manager: { + label: "マネージャーを解除", + confirmText: "このユーザーのマネージャーを解除しますか?マネージャーを再設定するまで、このユーザーには報告先がありません。承認ルーティングと own_and_reports レコードスコープもこの変更に従います。", + successMessage: "マネージャーを解除しました" + }, list_platform_admins: { label: "プラットフォーム管理者", resultDialog: { diff --git a/packages/platform-objects/src/apps/translations/ko.objects.generated.ts b/packages/platform-objects/src/apps/translations/ko.objects.generated.ts index ffd7da58376..4c6b7017036 100644 --- a/packages/platform-objects/src/apps/translations/ko.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/ko.objects.generated.ts @@ -328,6 +328,11 @@ export const koObjects: NonNullable = { } } }, + remove_user_manager: { + label: "상사 제거", + confirmText: "이 사용자의 상사를 제거하시겠습니까? 상사를 다시 지정할 때까지 이 사용자는 아무에게도 보고하지 않으며, 승인 라우팅과 own_and_reports 레코드 범위도 이 변경을 따릅니다.", + successMessage: "상사가 제거되었습니다" + }, list_platform_admins: { label: "플랫폼 관리자", resultDialog: { diff --git a/packages/platform-objects/src/apps/translations/pt-BR.objects.generated.ts b/packages/platform-objects/src/apps/translations/pt-BR.objects.generated.ts index 1e9eb992859..8b7cfd2891c 100644 --- a/packages/platform-objects/src/apps/translations/pt-BR.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/pt-BR.objects.generated.ts @@ -328,6 +328,11 @@ export const ptBRObjects: NonNullable = { } } }, + remove_user_manager: { + label: "Remover gestor", + confirmText: "Remover o gestor deste usuário? Ele não se reportará a ninguém até que um gestor seja definido novamente; o roteamento de aprovações e o escopo de registros own_and_reports acompanham a mudança.", + successMessage: "Gestor removido" + }, list_platform_admins: { label: "Administradores da plataforma", resultDialog: { diff --git a/packages/platform-objects/src/apps/translations/ru.objects.generated.ts b/packages/platform-objects/src/apps/translations/ru.objects.generated.ts index d78bbd61631..88a0086565b 100644 --- a/packages/platform-objects/src/apps/translations/ru.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/ru.objects.generated.ts @@ -328,6 +328,11 @@ export const ruObjects: NonNullable = { } } }, + remove_user_manager: { + label: "Удалить руководителя", + confirmText: "Удалить руководителя этого пользователя? Пока руководитель не будет назначен снова, пользователь никому не подчиняется; маршрутизация согласований и область записей own_and_reports следуют этому изменению.", + successMessage: "Руководитель удалён" + }, list_platform_admins: { label: "Администраторы платформы", resultDialog: { diff --git a/packages/platform-objects/src/apps/translations/zh-CN.objects.generated.ts b/packages/platform-objects/src/apps/translations/zh-CN.objects.generated.ts index ea97d7ed86c..ad3f43a1564 100644 --- a/packages/platform-objects/src/apps/translations/zh-CN.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/zh-CN.objects.generated.ts @@ -328,6 +328,11 @@ export const zhCNObjects: NonNullable = { } } }, + remove_user_manager: { + label: "移除经理", + confirmText: "要移除该用户的经理吗?在重新设置经理之前,该用户不向任何人汇报;审批路由与 own_and_reports 记录范围会随之变化。", + successMessage: "已移除经理" + }, list_platform_admins: { label: "平台管理员", resultDialog: { diff --git a/packages/platform-objects/src/apps/translations/zh-Hant.objects.generated.ts b/packages/platform-objects/src/apps/translations/zh-Hant.objects.generated.ts index fd9801bbbfa..8d004d05eb3 100644 --- a/packages/platform-objects/src/apps/translations/zh-Hant.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/zh-Hant.objects.generated.ts @@ -328,6 +328,11 @@ export const zhHantObjects: NonNullable = { } } }, + remove_user_manager: { + label: "移除經理", + confirmText: "要移除此使用者的經理嗎?在重新設定經理之前,此使用者不向任何人匯報;審批路由與 own_and_reports 記錄範圍會隨之變更。", + successMessage: "已移除經理" + }, list_platform_admins: { label: "平台管理員", resultDialog: { diff --git a/packages/platform-objects/src/identity/sys-user-set-manager-action.test.ts b/packages/platform-objects/src/identity/sys-user-set-manager-action.test.ts index 651c18f2b75..ddc4e7f4e33 100644 --- a/packages/platform-objects/src/identity/sys-user-set-manager-action.test.ts +++ b/packages/platform-objects/src/identity/sys-user-set-manager-action.test.ts @@ -113,21 +113,27 @@ describe('#19249 — sys_user.set_user_manager posts the admin endpoint', () => expect(ACTION.locations).toContain('record_header'); }); - it('collects the manager as an inline sys_user lookup under the body key the endpoint reads', () => { + it('collects the manager on `manager_id`, seeded from the row, under the body key the endpoint reads', () => { const params = (ACTION.params ?? []) as AnyParam[]; expect(params).toHaveLength(1); const [p] = params; expect(p.name).toBe('managerId'); - expect(p.type).toBe('lookup'); - expect(p.reference).toBe('sys_user'); - // INLINE, not field-backed: `{ field: 'manager_id' }` would inherit the - // referenced field's metadata, and that field is `readonly: true` - // (ADR-0092 D4 keeps it non-editable in the standard edit form). - expect(p.field).toBeUndefined(); + // FIELD-BACKED and seeded from the row, so the dialog opens on the + // CURRENT manager: before, it opened empty and an admin re-pointing a + // manager could not see what the click would replace. The console's param + // resolver inherits the field's type and target, never its `readonly` + // (ADR-0092 D4 keeps the column locked in the edit form, not here). + expect(p.field).toBe('manager_id'); + expect(p.defaultFromRow).toBe(true); + expect(SysUser.fields.manager_id.type).toBe('lookup'); + expect((SysUser.fields.manager_id as { reference?: string }).reference).toBe('sys_user'); + // Seeded, not carried: the admin picks the new manager, so the control + // stays editable. + expect(p.carryOver).toBeUndefined(); // Required, because the endpoint refuses an ABSENT or empty key by design // ("managerId is required — send null to clear the link, never omit the // key"). A dialog that could submit nothing would turn an ordinary click - // into a 400 about a key the user never saw. + // into a 400 about a key the user never saw; the clear is its own action. expect(p.required).toBe(true); }); @@ -213,3 +219,77 @@ describe('the visible predicate: offered on every row, the SCIM-held refusal is expect(visible()).not.toContain('features.'); }); }); + +/** + * `remove_user_manager` — the clear the required picker above cannot send. + * The endpoint clears the link on `managerId: null` ("send null to clear the + * link, never omit the key"); the action sends that null as its static body + * and asks a confirm question instead of collecting anything. The forward + * itself — the null arriving at the target — is pinned at the door, in + * `@objectstack/runtime`'s `platform-admin-action-gate.test.ts`. + */ +describe('sys_user.remove_user_manager clears the link through the same endpoint', () => { + const REMOVE = (() => { + const found = actionsOf().find((a) => a.name === 'remove_user_manager'); + if (!found) throw new Error('sys_user declares no remove_user_manager action'); + return found; + })(); + + it('posts the set-user-manager endpoint with `managerId: null` and collects nothing', () => { + expect(REMOVE.type).toBe('api'); + expect(REMOVE.target).toBe(ACTION.target); + expect(REMOVE.recordIdParam).toBe(ACTION.recordIdParam); + expect(REMOVE.method === undefined || REMOVE.method === 'POST').toBe(true); + // The key PRESENT and null: an absent key is the endpoint's 400. + expect(REMOVE.bodyExtra).toEqual({ managerId: null }); + expect(Object.prototype.hasOwnProperty.call(REMOVE.bodyExtra, 'managerId')).toBe(true); + expect(REMOVE.params ?? []).toEqual([]); + // Nothing collected, so the question rides `confirmText`, not + // `description` (the param-collecting set action's carrier). + expect(REMOVE.confirmText).toBeTruthy(); + expect(REMOVE.description).toBeUndefined(); + }); + + it('⛔ does NOT write manager_id through the generic data API', () => { + expect(String(REMOVE.target)).not.toContain('/data/'); + expect(REMOVE.operation).toBeUndefined(); + expect(REMOVE.patch).toBeUndefined(); + }); + + it('is gated exactly like set_user_manager: the same capability gate, the same standing term first', () => { + expect(REMOVE.requiredPermissions).toEqual(ACTION.requiredPermissions); + expect(REMOVE.requiresFeature).toBeUndefined(); + expect(REMOVE.locations).toEqual(ACTION.locations); + const standing = sourceOf(ACTION.visible)!; + expect(sourceOf(REMOVE.visible)!.startsWith(`${standing} && `)).toBe(true); + }); + + it('reads only the row\'s `manager_id`, never a copy of a server refusal', () => { + const visible = sourceOf(REMOVE.visible)!; + const columns = new Set([...visible.matchAll(/record\.([a-z_][a-z0-9_]*)/gi)].map((m) => m[1])); + expect([...columns]).toEqual(['manager_id']); + expect(visible).not.toContain('record.source'); + expect(visible).not.toContain('ctx.user.id'); + }); + + it('is offered only while the row has a manager, and only to the standing the door admits', () => { + const visible = sourceOf(REMOVE.visible)!; + expect(evaluate(visible, { id: 'someone_else', manager_id: 'u_mgr' })).toBe(true); + // An SSO-only person's manager is cleared here too; a SCIM-held row is the + // endpoint's refusal, as for the set. + expect(evaluate(visible, { id: 'someone_else', manager_id: 'u_mgr', source: 'idp_provisioned' })).toBe(true); + expect(evaluate(visible, { id: 'someone_else', manager_id: null })).toBe(false); + // The sparse face (no column projected) is not a fault, just not offered. + expect(evaluate(visible, { id: 'someone_else' })).toBe(false); + const member = { id: 'm_1', isPlatformAdmin: false, positions: [] as string[] }; + const r = celEngine.evaluate( + { dialect: 'cel', source: visible }, + { record: { id: 'someone_else', manager_id: 'u_mgr' }, extra: { current_user: member, user: member, ctx: { user: member }, os: { user: member }, features: {} } }, + ); + expect(r.ok && r.value).toBe(false); + }); + + it('stays human-only: no `ai` block, like every action after the ADR-0011 assessment', () => { + expect(REMOVE.ai).toBeUndefined(); + }); +}); diff --git a/packages/platform-objects/src/identity/sys-user.object.ts b/packages/platform-objects/src/identity/sys-user.object.ts index f058d18c77a..1845ce6f59f 100644 --- a/packages/platform-objects/src/identity/sys-user.object.ts +++ b/packages/platform-objects/src/identity/sys-user.object.ts @@ -774,26 +774,27 @@ export const SysUser = ObjectSchema.create({ description: "Set this user's manager. The reporting chain drives approval routing and the own_and_reports record scope.", params: [ { - // INLINE, not field-backed. A field-backed `{ field: 'manager_id' }` - // param inherits the referenced field's metadata, and that field is - // `readonly: true` (ADR-0092 D4 — it must stay non-editable in the - // standard edit form), so inheriting it here is a picker that may - // render read-only. `name` is the request-body key, and it is the - // camelCase spelling the endpoint reads first (`readId(body, - // 'managerId', 'manager_id')`). + // FIELD-BACKED on `manager_id` and seeded from the row + // (`defaultFromRow`), so the dialog opens on the CURRENT manager and + // an admin sees what a re-point would replace. Both doors that draw + // this dialog pass the row: the record header stamps its record and a + // list row is projected with every field a `defaultFromRow` param + // seeds from. The field's `readonly: true` (ADR-0092 D4) is not + // inherited: the console's param resolver carries the field's type, + // target and label onto the param and never its `readonly`, so the + // picker stays editable while the edit form keeps the column locked. + // `name` is the request-body key, the camelCase spelling the endpoint + // reads first (`readId(body, 'managerId', 'manager_id')`). name: 'managerId', + field: 'manager_id', + defaultFromRow: true, label: 'Manager', - type: 'lookup', - reference: 'sys_user', // Required, because the endpoint refuses an ABSENT or empty key by // design — "managerId is required — send null to clear the link, // never omit the key" — so a dialog that could submit nothing would // turn a normal click into a 400 about a key the user never saw. - // Required means a value is collected before anything is POSTed. - // ⚠️ Clearing the link (`managerId: null`) is a real endpoint - // capability that this action therefore does not reach; it is - // recorded in the PR's acceptance notes rather than half-declared - // here. + // Required means a value is collected before anything is POSTed; + // clearing is `remove_user_manager` below. required: true, helpText: 'The user this person reports to. The server refuses a manager outside their organization, a self-assignment, and a link that would close or over-deepen the reporting chain.', }, @@ -807,6 +808,42 @@ export const SysUser = ObjectSchema.create({ requiresConfirmation: true, }, }, + { + // The clear half of the same endpoint: `managerId: null` unsets the + // link ("send null to clear the link, never omit the key"), which the + // required picker above cannot send. The null rides `bodyExtra`, the + // action's static request body, merged last at both doors + // (`buildApiActionRequest`), so the action collects nothing and asks a + // confirm question instead. Same door, same gate, same refusals as + // `set_user_manager` — the SCIM-held one included, which the endpoint + // applies to the clear as well — and ⛔ no client-side copy of any of + // them (maintainer ruling record 6895645364, option A). + // + // `visible` is `set_user_manager`'s standing term, then the row's state, + // in the form of Ban / Unban above: it is offered only while the row + // HAS a manager, so it never reports success for removing nothing. The + // `has()` guard because a CEL read of an absent key faults; a list row + // carries `manager_id` because the console projects every column an + // action predicate reads. + // + // No `ai` block: this action postdates the ADR-0011 identity-actions + // assessment, and an unassessed action stays human-only. + name: 'remove_user_manager', + label: 'Remove Manager', + icon: 'user-minus', + variant: 'secondary', + locations: ['list_item', 'record_header'], + type: 'api', + target: '/api/v1/auth/admin/set-user-manager', + // The door's platform-admin gate, declared where both action doors read it (#30771). + requiredPermissions: [...PLATFORM_ADMIN_USERS_GATE], + visible: 'current_user.isPlatformAdmin == true && has(record.manager_id) && record.manager_id != null', + recordIdParam: 'userId', + bodyExtra: { managerId: null }, + confirmText: "Remove this user's manager? They will report to no one until a manager is set again; approval routing and the own_and_reports record scope follow the change.", + successMessage: 'Manager removed', + refreshAfter: true, + }, { // ADR-0095 D3 — who holds platform-admin standing. Standing is derived // per user, never stored on this object, so the Users list carries no diff --git a/packages/platform-objects/src/pages/sys-user-details-tab.test.ts b/packages/platform-objects/src/pages/sys-user-details-tab.test.ts index 72484ce1018..feb41f65c49 100644 --- a/packages/platform-objects/src/pages/sys-user-details-tab.test.ts +++ b/packages/platform-objects/src/pages/sys-user-details-tab.test.ts @@ -18,7 +18,7 @@ */ import { describe, expect, it } from 'vitest'; -import { PageSchema } from '@objectstack/spec/ui'; +import { PageSchema, RecordRelatedListProps } from '@objectstack/spec/ui'; import { SysUserDetailPage } from './sys-user.page.js'; type Rec = Record; @@ -38,6 +38,11 @@ const SECTIONS = [ // #27859: a saved Locale is shown; the renderer draws only authored sections. fields: ['name', 'image', 'locale'], }, + { + // The reporting line: who this person reports to (see the describe below). + label: { en: 'Reporting Line', 'zh-CN': '汇报关系', 'ja-JP': 'レポートライン', 'es-ES': 'Línea de reporte', 'zh-Hant': '匯報關係', ar: 'التسلسل الإداري', fr: 'Ligne hiérarchique', 'pt-BR': 'Linha de reporte', ru: 'Подчинённость', de: 'Berichtslinie', ko: '보고 라인' }, + fields: ['manager_id'], + }, { // #27859: a banned user reads as banned, with the reason, not as active. label: { en: 'Account Status', 'zh-CN': '账号状态', 'ja-JP': 'アカウントの状態', 'es-ES': 'Estado de la cuenta', 'zh-Hant': '帳號狀態', ar: 'حالة الحساب', fr: 'État du compte', 'pt-BR': 'Status da conta', ru: 'Статус учётной записи', de: 'Kontostatus', ko: '계정 상태' }, @@ -65,11 +70,12 @@ describe('sys_user_detail — the details body lives in the first tab', () => { expect(tabs.type).toBe('page:tabs'); }); - it('carries the `record:details` as the only child of the FIRST tab item, sections and hidden fields intact', () => { + it('carries the `record:details` as the FIRST child of the FIRST tab item, sections and hidden fields intact', () => { const first = items[0]!; expect((first.label as Rec).en).toBe('Details'); const children = first.children as Rec[]; - expect(children.map((c) => c.type)).toEqual(['record:details']); + // The details grid, then the Direct Reports list (pinned below). + expect(children.map((c) => c.type)).toEqual(['record:details', 'record:related_list']); const props = children[0]!.properties as Rec; expect(props.hideFields).toEqual(HIDE_FIELDS); expect(props.sections).toEqual(SECTIONS); @@ -96,3 +102,59 @@ describe('sys_user_detail — the details body lives in the first tab', () => { expect(found).toHaveLength(1); }); }); + +/** + * The reporting line is read back on the record: who this person reports to, + * and who reports to them. + * + * `sys_user.manager_id` is `readonly` (ADR-0092 D4) and written only by the + * admin endpoint behind Set Manager / Remove Manager, and the renderer draws + * only the sections a page names. Before, no section named it and no list + * showed its reverse, so an admin who had set a manager could not see it + * anywhere in Setup. Decision batch #127 item 1: the manager is this explicit + * link alone; a business unit's head is not read here. + */ +describe('sys_user_detail — the reporting line is shown in the Details tab', () => { + const parsed = PageSchema.parse(SysUserDetailPage); + const strip = (parsed.regions![0]!.components as Rec[]).find((c) => c.type === 'page:tabs') as Rec; + const details = ((strip.properties as Rec).items as Rec[])[0]!; + const children = details.children as Rec[]; + + it('a Details section names `manager_id`, and nothing hides it', () => { + const props = children.find((c) => c.type === 'record:details')!.properties as Rec; + const sections = props.sections as { label: Rec; fields: string[] }[]; + const holding = sections.filter((s) => s.fields.includes('manager_id')); + expect(holding.map((s) => s.label.en)).toEqual(['Reporting Line']); + expect(props.hideFields).not.toContain('manager_id'); + }); + + it('the Direct Reports list reads `sys_user` rows whose `manager_id` is this record\'s id', () => { + const lists = children.filter((c) => c.type === 'record:related_list'); + expect(lists).toHaveLength(1); + const props = lists[0]!.properties as Rec; + expect((props.title as Rec).en).toBe('Direct Reports'); + expect(props.objectName).toBe('sys_user'); + expect(props.relationshipField).toBe('manager_id'); + // The parent value the relationship field is matched against is the + // record's id: nothing is authored, and the props contract's default is + // `id` (the page envelope serves `properties` verbatim, so the default is + // read through the block's own schema). + expect(props).not.toHaveProperty('relationshipValueField'); + const contract = RecordRelatedListProps.safeParse(props); + expect(contract.success, JSON.stringify(contract.error?.issues ?? [])).toBe(true); + expect(contract.data!.relationshipValueField).toBe('id'); + // No authored filter narrows it, and no `add` picker: the link is the + // admin endpoint's to write, never a related-list insert. + expect(props.filter).toBeUndefined(); + expect(props.add).toBeUndefined(); + }); + + it('both labels carry the same locales as the tab they sit in', () => { + const tabLocales = Object.keys(details.label as Rec).sort(); + const props = children.find((c) => c.type === 'record:details')!.properties as Rec; + const section = (props.sections as { label: Rec; fields: string[] }[]).find((s) => s.fields.includes('manager_id'))!; + const list = children.find((c) => c.type === 'record:related_list')!.properties as Rec; + expect(Object.keys(section.label).sort()).toEqual(tabLocales); + expect(Object.keys(list.title as Rec).sort()).toEqual(tabLocales); + }); +}); diff --git a/packages/platform-objects/src/pages/sys-user.page.ts b/packages/platform-objects/src/pages/sys-user.page.ts index 6672ef51589..884a277e187 100644 --- a/packages/platform-objects/src/pages/sys-user.page.ts +++ b/packages/platform-objects/src/pages/sys-user.page.ts @@ -239,6 +239,21 @@ export const SysUserDetailPage: Page = { label: { en: 'Identity', 'zh-CN': '身份', 'ja-JP': 'アイデンティティ', 'es-ES': 'Identidad', 'zh-Hant': '身分', ar: 'الهوية', fr: 'Identité', 'pt-BR': 'Identidade', ru: 'Идентификация', de: 'Identität', ko: 'ID 정보' }, fields: ['name', 'image', 'locale'], }, + { + // Who this person reports to (`manager_id`, readonly + // on the object: ADR-0092 D4). Shown here, not edited: + // Set Manager / Remove Manager in the header write it + // through the admin endpoint. Decision batch #127 + // item 1: the manager is this explicit link only, never + // derived from a business unit's head. Not named + // "Organization": the Organizations tab is membership, + // not the reporting line. `primary_business_unit_id` + // (same field group) stays off: it is plugin-sharing's + // projection of the Business Units tab, which shows + // the source rows and their primary flag. + label: { en: 'Reporting Line', 'zh-CN': '汇报关系', 'ja-JP': 'レポートライン', 'es-ES': 'Línea de reporte', 'zh-Hant': '匯報關係', ar: 'التسلسل الإداري', fr: 'Ligne hiérarchique', 'pt-BR': 'Linha de reporte', ru: 'Подчинённость', de: 'Berichtslinie', ko: '보고 라인' }, + fields: ['manager_id'], + }, { label: { en: 'Account Status', 'zh-CN': '账号状态', 'ja-JP': 'アカウントの状態', 'es-ES': 'Estado de la cuenta', 'zh-Hant': '帳號狀態', ar: 'حالة الحساب', fr: 'État du compte', 'pt-BR': 'Status da conta', ru: 'Статус учётной записи', de: 'Kontostatus', ko: '계정 상태' }, fields: ['banned', 'ban_reason', 'ban_expires'], @@ -250,6 +265,23 @@ export const SysUserDetailPage: Page = { ], }, }, + { + // The other half of the reporting line: the people whose + // `manager_id` is this user. Read-only by construction: + // `sys_user` opens no create or delete (`userActions`, + // `apiMethods`), so the list offers neither New nor Remove; + // a report's manager is changed on that report's record. + type: 'record:related_list', + properties: { + objectName: 'sys_user', + relationshipField: 'manager_id', + columns: ['name', 'email'], + sort: [{ field: 'name', order: 'asc' }], + limit: 25, + showViewAll: true, + title: { en: 'Direct Reports', 'zh-CN': '直接下属', 'ja-JP': '直属の部下', 'es-ES': 'Subordinados directos', 'zh-Hant': '直屬部屬', ar: 'المرؤوسون المباشرون', fr: 'Collaborateurs directs', 'pt-BR': 'Subordinados diretos', ru: 'Прямые подчинённые', de: 'Direkte Mitarbeiter', ko: '직속 팀원' }, + }, + }, ], }, { diff --git a/packages/runtime/src/platform-admin-action-gate.test.ts b/packages/runtime/src/platform-admin-action-gate.test.ts index 8c02de395f0..0dcc98fb6b7 100644 --- a/packages/runtime/src/platform-admin-action-gate.test.ts +++ b/packages/runtime/src/platform-admin-action-gate.test.ts @@ -165,6 +165,39 @@ describe('[#30771] a hidden action is still refused when called', () => { } }); +describe('sys_user.remove_user_manager: the clear reaches the endpoint as `managerId: null`', () => { + // The endpoint clears the link on `managerId: null` and refuses an ABSENT + // key, so the null has to survive the door's body assembly: the declared + // `bodyExtra` is merged last, after the row id. Driven over the real + // declaration; the target is faked so the forwarded body can be read. + const forwardOf = (request: ReturnType['request']) => + (request.mock.calls as unknown as Array<[string, RequestInit]>)[0]!; + + it('the admin\'s click is forwarded to set-user-manager with the row id and the key present and null', async () => { + const { dispatcher, request } = boot(); + const res = await dispatcher.handleActions(`/${OBJECT}/remove_user_manager`, 'POST', { recordId: 'u_target', params: {} }, ADMIN()); + expect(res?.response?.status).toBe(200); + expect(request).toHaveBeenCalledTimes(1); + const [url, init] = forwardOf(request); + expect(new URL(url).pathname).toBe('/api/v1/auth/admin/set-user-manager'); + expect(String(init.method).toUpperCase()).toBe('POST'); + const body = JSON.parse(String(init.body)); + expect(body.userId).toBe('u_target'); + expect(Object.prototype.hasOwnProperty.call(body, 'managerId')).toBe(true); + expect(body.managerId).toBeNull(); + }); + + it('a plain member is refused 403 at the door with the set action\'s gate, nothing forwarded', async () => { + const { dispatcher, request } = boot(); + const refused = await dispatcher.handleActions(`/${OBJECT}/remove_user_manager`, 'POST', { recordId: 'u_target', params: {} }, MEMBER()); + expect(refused?.response?.status).toBe(403); + // The ADR-0112 envelope code, the one the MCP twin above pins for this gate. + expect(refused?.response?.body?.error?.code).toBe('PERMISSION_DENIED'); + expect(String(refused?.response?.body?.error?.message)).toContain('requires capability [manage_users]'); + expect(request).not.toHaveBeenCalled(); + }); +}); + describe('[#30771] capabilityRefusal: why the scoped MCP pre-screen finds an action missing', () => { it('answers the gate\'s refusal for an exposed action the member cannot run — the one run_action throws by name', async () => { const { dispatcher, request } = boot();