Skip to content

Commit 045616a

Browse files
committed
feat(platform-objects): read back a user's manager and direct reports; prefill and clear it
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5okniknzVVR3KTSVr1
1 parent 30b0987 commit 045616a

2 files changed

Lines changed: 83 additions & 14 deletions

File tree

‎packages/platform-objects/src/identity/sys-user.object.ts‎

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -774,26 +774,27 @@ export const SysUser = ObjectSchema.create({
774774
description: "Set this user's manager. The reporting chain drives approval routing and the own_and_reports record scope.",
775775
params: [
776776
{
777-
// INLINE, not field-backed. A field-backed `{ field: 'manager_id' }`
778-
// param inherits the referenced field's metadata, and that field is
779-
// `readonly: true` (ADR-0092 D4 — it must stay non-editable in the
780-
// standard edit form), so inheriting it here is a picker that may
781-
// render read-only. `name` is the request-body key, and it is the
782-
// camelCase spelling the endpoint reads first (`readId(body,
783-
// 'managerId', 'manager_id')`).
777+
// FIELD-BACKED on `manager_id` and seeded from the row
778+
// (`defaultFromRow`), so the dialog opens on the CURRENT manager and
779+
// an admin sees what a re-point would replace. Both doors that draw
780+
// this dialog pass the row: the record header stamps its record and a
781+
// list row is projected with every field a `defaultFromRow` param
782+
// seeds from. The field's `readonly: true` (ADR-0092 D4) is not
783+
// inherited: the console's param resolver carries the field's type,
784+
// target and label onto the param and never its `readonly`, so the
785+
// picker stays editable while the edit form keeps the column locked.
786+
// `name` is the request-body key, the camelCase spelling the endpoint
787+
// reads first (`readId(body, 'managerId', 'manager_id')`).
784788
name: 'managerId',
789+
field: 'manager_id',
790+
defaultFromRow: true,
785791
label: 'Manager',
786-
type: 'lookup',
787-
reference: 'sys_user',
788792
// Required, because the endpoint refuses an ABSENT or empty key by
789793
// design — "managerId is required — send null to clear the link,
790794
// never omit the key" — so a dialog that could submit nothing would
791795
// turn a normal click into a 400 about a key the user never saw.
792-
// Required means a value is collected before anything is POSTed.
793-
// ⚠️ Clearing the link (`managerId: null`) is a real endpoint
794-
// capability that this action therefore does not reach; it is
795-
// recorded in the PR's acceptance notes rather than half-declared
796-
// here.
796+
// Required means a value is collected before anything is POSTed;
797+
// clearing is `remove_user_manager` below.
797798
required: true,
798799
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.',
799800
},
@@ -807,6 +808,42 @@ export const SysUser = ObjectSchema.create({
807808
requiresConfirmation: true,
808809
},
809810
},
811+
{
812+
// The clear half of the same endpoint: `managerId: null` unsets the
813+
// link ("send null to clear the link, never omit the key"), which the
814+
// required picker above cannot send. The null rides `bodyExtra`, the
815+
// action's static request body, merged last at both doors
816+
// (`buildApiActionRequest`), so the action collects nothing and asks a
817+
// confirm question instead. Same door, same gate, same refusals as
818+
// `set_user_manager` — the SCIM-held one included, which the endpoint
819+
// applies to the clear as well — and ⛔ no client-side copy of any of
820+
// them (maintainer ruling record 6895645364, option A).
821+
//
822+
// `visible` is `set_user_manager`'s standing term, then the row's state,
823+
// in the form of Ban / Unban above: it is offered only while the row
824+
// HAS a manager, so it never reports success for removing nothing. The
825+
// `has()` guard because a CEL read of an absent key faults; a list row
826+
// carries `manager_id` because the console projects every column an
827+
// action predicate reads.
828+
//
829+
// No `ai` block: this action postdates the ADR-0011 identity-actions
830+
// assessment, and an unassessed action stays human-only.
831+
name: 'remove_user_manager',
832+
label: 'Remove Manager',
833+
icon: 'user-minus',
834+
variant: 'secondary',
835+
locations: ['list_item', 'record_header'],
836+
type: 'api',
837+
target: '/api/v1/auth/admin/set-user-manager',
838+
// The door's platform-admin gate, declared where both action doors read it (#30771).
839+
requiredPermissions: [...PLATFORM_ADMIN_USERS_GATE],
840+
visible: 'current_user.isPlatformAdmin == true && has(record.manager_id) && record.manager_id != null',
841+
recordIdParam: 'userId',
842+
bodyExtra: { managerId: null },
843+
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.",
844+
successMessage: 'Manager removed',
845+
refreshAfter: true,
846+
},
810847
{
811848
// ADR-0095 D3 — who holds platform-admin standing. Standing is derived
812849
// per user, never stored on this object, so the Users list carries no

‎packages/platform-objects/src/pages/sys-user.page.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,21 @@ export const SysUserDetailPage: Page = {
239239
label: { en: 'Identity', 'zh-CN': '身份', 'ja-JP': 'アイデンティティ', 'es-ES': 'Identidad', 'zh-Hant': '身分', ar: 'الهوية', fr: 'Identité', 'pt-BR': 'Identidade', ru: 'Идентификация', de: 'Identität', ko: 'ID 정보' },
240240
fields: ['name', 'image', 'locale'],
241241
},
242+
{
243+
// Who this person reports to (`manager_id`, readonly
244+
// on the object: ADR-0092 D4). Shown here, not edited:
245+
// Set Manager / Remove Manager in the header write it
246+
// through the admin endpoint. Decision batch #127
247+
// item 1: the manager is this explicit link only, never
248+
// derived from a business unit's head. Not named
249+
// "Organization": the Organizations tab is membership,
250+
// not the reporting line. `primary_business_unit_id`
251+
// (same field group) stays off: it is plugin-sharing's
252+
// projection of the Business Units tab, which shows
253+
// the source rows and their primary flag.
254+
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: '보고 라인' },
255+
fields: ['manager_id'],
256+
},
242257
{
243258
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: '계정 상태' },
244259
fields: ['banned', 'ban_reason', 'ban_expires'],
@@ -250,6 +265,23 @@ export const SysUserDetailPage: Page = {
250265
],
251266
},
252267
},
268+
{
269+
// The other half of the reporting line: the people whose
270+
// `manager_id` is this user. Read-only by construction:
271+
// `sys_user` opens no create or delete (`userActions`,
272+
// `apiMethods`), so the list offers neither New nor Remove;
273+
// a report's manager is changed on that report's record.
274+
type: 'record:related_list',
275+
properties: {
276+
objectName: 'sys_user',
277+
relationshipField: 'manager_id',
278+
columns: ['name', 'email'],
279+
sort: [{ field: 'name', order: 'asc' }],
280+
limit: 25,
281+
showViewAll: true,
282+
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: '직속 팀원' },
283+
},
284+
},
253285
],
254286
},
255287
{

0 commit comments

Comments
 (0)