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
15 changes: 15 additions & 0 deletions .changeset/36017-show-user-manager.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ export const arObjects: NonNullable<TranslationData['objects']> = {
}
}
},
remove_user_manager: {
label: "إزالة المدير",
confirmText: "هل تريد إزالة مدير هذا المستخدم؟ لن يتبع أحدًا حتى يُعيَّن مدير من جديد، ويتبع توجيه الموافقات ونطاق السجلات own_and_reports هذا التغيير.",
successMessage: "تمت إزالة المدير"
},
list_platform_admins: {
label: "مسؤولو المنصة",
resultDialog: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ export const deObjects: NonNullable<TranslationData['objects']> = {
}
}
},
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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ export const enObjects: NonNullable<TranslationData['objects']> = {
}
}
},
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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ export const esESObjects: NonNullable<TranslationData['objects']> = {
}
}
},
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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ export const frObjects: NonNullable<TranslationData['objects']> = {
}
}
},
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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ export const jaJPObjects: NonNullable<TranslationData['objects']> = {
}
}
},
remove_user_manager: {
label: "マネージャーを解除",
confirmText: "このユーザーのマネージャーを解除しますか?マネージャーを再設定するまで、このユーザーには報告先がありません。承認ルーティングと own_and_reports レコードスコープもこの変更に従います。",
successMessage: "マネージャーを解除しました"
},
list_platform_admins: {
label: "プラットフォーム管理者",
resultDialog: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ export const koObjects: NonNullable<TranslationData['objects']> = {
}
}
},
remove_user_manager: {
label: "상사 제거",
confirmText: "이 사용자의 상사를 제거하시겠습니까? 상사를 다시 지정할 때까지 이 사용자는 아무에게도 보고하지 않으며, 승인 라우팅과 own_and_reports 레코드 범위도 이 변경을 따릅니다.",
successMessage: "상사가 제거되었습니다"
},
list_platform_admins: {
label: "플랫폼 관리자",
resultDialog: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ export const ptBRObjects: NonNullable<TranslationData['objects']> = {
}
}
},
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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ export const ruObjects: NonNullable<TranslationData['objects']> = {
}
}
},
remove_user_manager: {
label: "Удалить руководителя",
confirmText: "Удалить руководителя этого пользователя? Пока руководитель не будет назначен снова, пользователь никому не подчиняется; маршрутизация согласований и область записей own_and_reports следуют этому изменению.",
successMessage: "Руководитель удалён"
},
list_platform_admins: {
label: "Администраторы платформы",
resultDialog: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ export const zhCNObjects: NonNullable<TranslationData['objects']> = {
}
}
},
remove_user_manager: {
label: "移除经理",
confirmText: "要移除该用户的经理吗?在重新设置经理之前,该用户不向任何人汇报;审批路由与 own_and_reports 记录范围会随之变化。",
successMessage: "已移除经理"
},
list_platform_admins: {
label: "平台管理员",
resultDialog: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ export const zhHantObjects: NonNullable<TranslationData['objects']> = {
}
}
},
remove_user_manager: {
label: "移除經理",
confirmText: "要移除此使用者的經理嗎?在重新設定經理之前,此使用者不向任何人匯報;審批路由與 own_and_reports 記錄範圍會隨之變更。",
successMessage: "已移除經理"
},
list_platform_admins: {
label: "平台管理員",
resultDialog: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down Expand Up @@ -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();
});
});
65 changes: 51 additions & 14 deletions packages/platform-objects/src/identity/sys-user.object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
},
Expand All @@ -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
Expand Down
Loading
Loading