@@ -113,21 +113,27 @@ describe('#19249 — sys_user.set_user_manager posts the admin endpoint', () =>
113113 expect ( ACTION . locations ) . toContain ( 'record_header' ) ;
114114 } ) ;
115115
116- it ( 'collects the manager as an inline sys_user lookup under the body key the endpoint reads' , ( ) => {
116+ it ( 'collects the manager on `manager_id`, seeded from the row, under the body key the endpoint reads' , ( ) => {
117117 const params = ( ACTION . params ?? [ ] ) as AnyParam [ ] ;
118118 expect ( params ) . toHaveLength ( 1 ) ;
119119 const [ p ] = params ;
120120 expect ( p . name ) . toBe ( 'managerId' ) ;
121- expect ( p . type ) . toBe ( 'lookup' ) ;
122- expect ( p . reference ) . toBe ( 'sys_user' ) ;
123- // INLINE, not field-backed: `{ field: 'manager_id' }` would inherit the
124- // referenced field's metadata, and that field is `readonly: true`
125- // (ADR-0092 D4 keeps it non-editable in the standard edit form).
126- expect ( p . field ) . toBeUndefined ( ) ;
121+ // FIELD-BACKED and seeded from the row, so the dialog opens on the
122+ // CURRENT manager: before, it opened empty and an admin re-pointing a
123+ // manager could not see what the click would replace. The console's param
124+ // resolver inherits the field's type and target, never its `readonly`
125+ // (ADR-0092 D4 keeps the column locked in the edit form, not here).
126+ expect ( p . field ) . toBe ( 'manager_id' ) ;
127+ expect ( p . defaultFromRow ) . toBe ( true ) ;
128+ expect ( SysUser . fields . manager_id . type ) . toBe ( 'lookup' ) ;
129+ expect ( ( SysUser . fields . manager_id as { reference ?: string } ) . reference ) . toBe ( 'sys_user' ) ;
130+ // Seeded, not carried: the admin picks the new manager, so the control
131+ // stays editable.
132+ expect ( p . carryOver ) . toBeUndefined ( ) ;
127133 // Required, because the endpoint refuses an ABSENT or empty key by design
128134 // ("managerId is required — send null to clear the link, never omit the
129135 // key"). A dialog that could submit nothing would turn an ordinary click
130- // into a 400 about a key the user never saw.
136+ // into a 400 about a key the user never saw; the clear is its own action .
131137 expect ( p . required ) . toBe ( true ) ;
132138 } ) ;
133139
@@ -213,3 +219,77 @@ describe('the visible predicate: offered on every row, the SCIM-held refusal is
213219 expect ( visible ( ) ) . not . toContain ( 'features.' ) ;
214220 } ) ;
215221} ) ;
222+
223+ /**
224+ * `remove_user_manager` — the clear the required picker above cannot send.
225+ * The endpoint clears the link on `managerId: null` ("send null to clear the
226+ * link, never omit the key"); the action sends that null as its static body
227+ * and asks a confirm question instead of collecting anything. The forward
228+ * itself — the null arriving at the target — is pinned at the door, in
229+ * `@objectstack/runtime`'s `platform-admin-action-gate.test.ts`.
230+ */
231+ describe ( 'sys_user.remove_user_manager clears the link through the same endpoint' , ( ) => {
232+ const REMOVE = ( ( ) => {
233+ const found = actionsOf ( ) . find ( ( a ) => a . name === 'remove_user_manager' ) ;
234+ if ( ! found ) throw new Error ( 'sys_user declares no remove_user_manager action' ) ;
235+ return found ;
236+ } ) ( ) ;
237+
238+ it ( 'posts the set-user-manager endpoint with `managerId: null` and collects nothing' , ( ) => {
239+ expect ( REMOVE . type ) . toBe ( 'api' ) ;
240+ expect ( REMOVE . target ) . toBe ( ACTION . target ) ;
241+ expect ( REMOVE . recordIdParam ) . toBe ( ACTION . recordIdParam ) ;
242+ expect ( REMOVE . method === undefined || REMOVE . method === 'POST' ) . toBe ( true ) ;
243+ // The key PRESENT and null: an absent key is the endpoint's 400.
244+ expect ( REMOVE . bodyExtra ) . toEqual ( { managerId : null } ) ;
245+ expect ( Object . prototype . hasOwnProperty . call ( REMOVE . bodyExtra , 'managerId' ) ) . toBe ( true ) ;
246+ expect ( REMOVE . params ?? [ ] ) . toEqual ( [ ] ) ;
247+ // Nothing collected, so the question rides `confirmText`, not
248+ // `description` (the param-collecting set action's carrier).
249+ expect ( REMOVE . confirmText ) . toBeTruthy ( ) ;
250+ expect ( REMOVE . description ) . toBeUndefined ( ) ;
251+ } ) ;
252+
253+ it ( '⛔ does NOT write manager_id through the generic data API' , ( ) => {
254+ expect ( String ( REMOVE . target ) ) . not . toContain ( '/data/' ) ;
255+ expect ( REMOVE . operation ) . toBeUndefined ( ) ;
256+ expect ( REMOVE . patch ) . toBeUndefined ( ) ;
257+ } ) ;
258+
259+ it ( 'is gated exactly like set_user_manager: the same capability gate, the same standing term first' , ( ) => {
260+ expect ( REMOVE . requiredPermissions ) . toEqual ( ACTION . requiredPermissions ) ;
261+ expect ( REMOVE . requiresFeature ) . toBeUndefined ( ) ;
262+ expect ( REMOVE . locations ) . toEqual ( ACTION . locations ) ;
263+ const standing = sourceOf ( ACTION . visible ) ! ;
264+ expect ( sourceOf ( REMOVE . visible ) ! . startsWith ( `${ standing } && ` ) ) . toBe ( true ) ;
265+ } ) ;
266+
267+ it ( 'reads only the row\'s `manager_id`, never a copy of a server refusal' , ( ) => {
268+ const visible = sourceOf ( REMOVE . visible ) ! ;
269+ const columns = new Set ( [ ...visible . matchAll ( / r e c o r d \. ( [ a - z _ ] [ a - z 0 - 9 _ ] * ) / gi) ] . map ( ( m ) => m [ 1 ] ) ) ;
270+ expect ( [ ...columns ] ) . toEqual ( [ 'manager_id' ] ) ;
271+ expect ( visible ) . not . toContain ( 'record.source' ) ;
272+ expect ( visible ) . not . toContain ( 'ctx.user.id' ) ;
273+ } ) ;
274+
275+ it ( 'is offered only while the row has a manager, and only to the standing the door admits' , ( ) => {
276+ const visible = sourceOf ( REMOVE . visible ) ! ;
277+ expect ( evaluate ( visible , { id : 'someone_else' , manager_id : 'u_mgr' } ) ) . toBe ( true ) ;
278+ // An SSO-only person's manager is cleared here too; a SCIM-held row is the
279+ // endpoint's refusal, as for the set.
280+ expect ( evaluate ( visible , { id : 'someone_else' , manager_id : 'u_mgr' , source : 'idp_provisioned' } ) ) . toBe ( true ) ;
281+ expect ( evaluate ( visible , { id : 'someone_else' , manager_id : null } ) ) . toBe ( false ) ;
282+ // The sparse face (no column projected) is not a fault, just not offered.
283+ expect ( evaluate ( visible , { id : 'someone_else' } ) ) . toBe ( false ) ;
284+ const member = { id : 'm_1' , isPlatformAdmin : false , positions : [ ] as string [ ] } ;
285+ const r = celEngine . evaluate (
286+ { dialect : 'cel' , source : visible } ,
287+ { record : { id : 'someone_else' , manager_id : 'u_mgr' } , extra : { current_user : member , user : member , ctx : { user : member } , os : { user : member } , features : { } } } ,
288+ ) ;
289+ expect ( r . ok && r . value ) . toBe ( false ) ;
290+ } ) ;
291+
292+ it ( 'stays human-only: no `ai` block, like every action after the ADR-0011 assessment' , ( ) => {
293+ expect ( REMOVE . ai ) . toBeUndefined ( ) ;
294+ } ) ;
295+ } ) ;
0 commit comments