1616 *
1717 * - the composer: `feedComment`, the create grant on `sys_comment`;
1818 * - the reaction control: `feedReactionAdd`, the create grant on
19- * `sys_comment_reaction`, with a take-back asking `feedReactionRemove`, its
20- * delete grant, per click;
19+ * `sys_comment_reaction`, with a take-back asking `feedReactionRemove` per
20+ * click: the same create grant, since the take-back goes through the
21+ * unreact door (`DELETE /api/v1/comments/reactions/:id`), which removes the
22+ * caller's own row with no `delete` grant;
2123 * - on a deployment with no `sys_comment_reaction` (the column store), the
2224 * reaction control: `feedReactionColumn`, the update grant on `sys_comment`.
2325 *
@@ -36,10 +38,13 @@ import { MePermissionsProvider, type MePermissionsResponse } from '@object-ui/pe
3638import { DETAIL_DEFAULT_TRANSLATIONS } from '@object-ui/plugin-detail' ;
3739import { effectiveOperationsArray , resolveEffectiveApiMethods } from '@objectstack/spec/data' ;
3840
41+ /** The page's authenticated fetch: the unreact door is called through it. */
42+ const authFetch = vi . hoisted ( ( ) => vi . fn ( ) ) ;
43+
3944vi . mock ( '@object-ui/auth' , async ( importOriginal ) => ( {
4045 ...( await importOriginal < Record < string , unknown > > ( ) ) ,
4146 useAuth : ( ) => ( { user : { id : 'u1' , name : 'u1' , image : null } , activeOrganization : null } ) ,
42- createAuthenticatedFetch : ( ) => vi . fn ( ) ,
47+ createAuthenticatedFetch : ( ) => authFetch ,
4348} ) ) ;
4449
4550vi . mock ( '@object-ui/collaboration' , async ( importOriginal ) => ( {
@@ -69,6 +74,7 @@ vi.mock('./MetadataInspector', () => ({
6974} ) ) ;
7075
7176import { RecordDetailView } from './RecordDetailView' ;
77+ import { toast } from 'sonner' ;
7278
7379const COMMENT = 'sys_comment' ;
7480const REACTION = 'sys_comment_reaction' ;
@@ -127,18 +133,21 @@ function answer(feed: { [COMMENT]?: Bits; [REACTION]?: Bits }): MePermissionsRes
127133 } as MePermissionsResponse ;
128134}
129135
130- /** One comment by another member; the caller (`u1`) has already reacted 👍 on it. */
131- function makeDataSource ( ) {
136+ /**
137+ * One comment by another member; `reactor` (the caller `u1` unless named) has
138+ * already reacted 👍 on it.
139+ */
140+ function makeDataSource ( reactor = 'u1' ) {
132141 const comment = {
133142 id : COMMENT_ID ,
134143 thread_id : THREAD ,
135144 author_id : 'u3' ,
136145 author_name : 'u3' ,
137146 body : COMMENT_BODY ,
138147 created_at : '2026-10-10T08:00:00.000Z' ,
139- reactions : JSON . stringify ( { '👍' : [ 'u1' ] } ) ,
148+ reactions : JSON . stringify ( { '👍' : [ reactor ] } ) ,
140149 } ;
141- const ownReaction = { id : 'r1' , comment_id : COMMENT_ID , emoji : '👍' , user_id : 'u1' , created_at : '2026-10-10T09:00:00.000Z' } ;
150+ const ownReaction = { id : 'r1' , comment_id : COMMENT_ID , emoji : '👍' , user_id : reactor , created_at : '2026-10-10T09:00:00.000Z' } ;
142151 return {
143152 find : vi . fn ( async ( objectName : string ) => {
144153 if ( objectName === COMMENT ) return { data : [ { ...comment } ] } ;
@@ -210,7 +219,23 @@ const thumbsChip = (view: View) =>
210219 ( b ) => ! ! b . getAttribute ( 'aria-label' ) && b . children . length === 2 && b . children [ 0 ] . textContent === '👍' ,
211220 ) ;
212221
222+ /** The unreact door's answer to a removal of the caller's own row. */
223+ const unreacted = ( id : string ) =>
224+ new Response ( JSON . stringify ( { success : true , data : { id, deleted : true } } ) , {
225+ status : 200 ,
226+ headers : { 'content-type' : 'application/json' } ,
227+ } ) ;
228+
229+ /** The calls that reached the unreact door: `[url, init]`. */
230+ const unreactCalls = ( ) =>
231+ authFetch . mock . calls . filter ( ( [ url ] ) => String ( url ) . includes ( '/api/v1/comments/reactions/' ) ) ;
232+
213233beforeEach ( ( ) => {
234+ authFetch . mockImplementation ( async ( url : string ) =>
235+ String ( url ) . includes ( '/api/v1/comments/reactions/' )
236+ ? unreacted ( String ( url ) . split ( '/' ) . pop ( ) as string )
237+ : new Response ( JSON . stringify ( { data : [ ] } ) , { status : 200 , headers : { 'content-type' : 'application/json' } } ) ,
238+ ) ;
214239 vi . stubGlobal (
215240 'fetch' ,
216241 vi . fn ( async ( ) =>
@@ -267,19 +292,22 @@ describe("the record feed's reaction control reads feedReactionAdd / feedReactio
267292 expect ( ( thumbsChip ( view ) as HTMLButtonElement ) . disabled ) . toBe ( ! offered ) ;
268293 } ) ;
269294
270- it ( 'a take-back asks the delete grant: with create but not delete, clicking the own reaction writes nothing and keeps it shown ' , async ( ) => {
295+ it ( 'a take-back reads no delete grant: with create but not delete, clicking the own reaction removes it through the unreact door ' , async ( ) => {
271296 const { view, dataSource } = await mount ( answer ( { [ COMMENT ] : SHAPE . full , [ REACTION ] : SHAPE . createOnly } ) ) ;
272297 fireEvent . click ( thumbsChip ( view ) ! ) ;
273298 await act ( async ( ) => { } ) ;
299+ expect ( unreactCalls ( ) ) . toEqual ( [ [ '/api/v1/comments/reactions/r1' , { method : 'DELETE' , credentials : 'include' } ] ] ) ;
274300 expect ( dataSource . delete ) . not . toHaveBeenCalled ( ) ;
275- expect ( thumbsChip ( view ) ! . children [ 1 ] . textContent ) . toBe ( '1' ) ;
301+ expect ( thumbsChip ( view ) ) . toBeUndefined ( ) ;
276302 } ) ;
277303
278- it ( 'CONTROL — with the delete grant the same click takes the reaction back by deleting the own row ' , async ( ) => {
304+ it ( 'CONTROL — with the delete grant the same click takes the reaction back through the same door, never the data door ' , async ( ) => {
279305 const { view, dataSource } = await mount ( answer ( { [ COMMENT ] : SHAPE . full , [ REACTION ] : SHAPE . full } ) ) ;
280306 fireEvent . click ( thumbsChip ( view ) ! ) ;
281307 await act ( async ( ) => { } ) ;
282- expect ( dataSource . delete . mock . calls ) . toEqual ( [ [ REACTION , 'r1' ] ] ) ;
308+ expect ( unreactCalls ( ) ) . toEqual ( [ [ '/api/v1/comments/reactions/r1' , { method : 'DELETE' , credentials : 'include' } ] ] ) ;
309+ expect ( dataSource . delete ) . not . toHaveBeenCalled ( ) ;
310+ expect ( thumbsChip ( view ) ) . toBeUndefined ( ) ;
283311 } ) ;
284312
285313 it ( 'adding through the picker creates the own row where create is held' , async ( ) => {
@@ -291,6 +319,51 @@ describe("the record feed's reaction control reads feedReactionAdd / feedReactio
291319 } ) ;
292320} ) ;
293321
322+ describe ( "a take-back goes through the unreact door, and only on the caller's own reaction (objectstack#26346)" , ( ) => {
323+ it ( 'a member with no grant beyond create on sys_comment_reaction adds a reaction and takes it back' , async ( ) => {
324+ const { view, dataSource } = await mount ( answer ( { [ COMMENT ] : SHAPE . readOnly , [ REACTION ] : SHAPE . createOnly } ) ) ;
325+ fireEvent . click ( addReaction ( view ) ! ) ;
326+ fireEvent . click ( within ( screen . getByRole ( 'listbox' ) ) . getByRole ( 'option' , { name : '🎉' } ) ) ;
327+ await act ( async ( ) => { } ) ;
328+ const party = ( ) =>
329+ ( view . queryAllByRole ( 'button' ) as HTMLElement [ ] ) . find (
330+ ( b ) => ! ! b . getAttribute ( 'aria-label' ) && b . children . length === 2 && b . children [ 0 ] . textContent === '🎉' ,
331+ ) ;
332+ expect ( party ( ) ) . toBeDefined ( ) ;
333+ fireEvent . click ( party ( ) ! ) ;
334+ await act ( async ( ) => { } ) ;
335+ expect ( dataSource . create . mock . calls ) . toEqual ( [ [ REACTION , { comment_id : COMMENT_ID , emoji : '🎉' } ] ] ) ;
336+ expect ( unreactCalls ( ) ) . toEqual ( [ [ '/api/v1/comments/reactions/new-row' , { method : 'DELETE' , credentials : 'include' } ] ] ) ;
337+ expect ( dataSource . delete ) . not . toHaveBeenCalled ( ) ;
338+ expect ( party ( ) ) . toBeUndefined ( ) ;
339+ } ) ;
340+
341+ it ( "another member's reaction offers no take-back: a click on their chip adds the caller's own row and reaches no door that removes" , async ( ) => {
342+ const { view, dataSource } = await mount ( answer ( { [ COMMENT ] : SHAPE . full , [ REACTION ] : SHAPE . full } ) , makeDataSource ( 'u2' ) ) ;
343+ fireEvent . click ( thumbsChip ( view ) ! ) ;
344+ await act ( async ( ) => { } ) ;
345+ expect ( dataSource . create . mock . calls ) . toEqual ( [ [ REACTION , { comment_id : COMMENT_ID , emoji : '👍' } ] ] ) ;
346+ expect ( unreactCalls ( ) ) . toEqual ( [ ] ) ;
347+ expect ( dataSource . delete ) . not . toHaveBeenCalled ( ) ;
348+ expect ( thumbsChip ( view ) ! . children [ 1 ] . textContent ) . toBe ( '2' ) ;
349+ } ) ;
350+
351+ it ( 'a take-back the door refuses puts the reaction back and says it was not saved' , async ( ) => {
352+ authFetch . mockImplementation ( async ( ) =>
353+ new Response ( JSON . stringify ( { success : false , error : { code : 'PERMISSION_DENIED' } } ) , {
354+ status : 403 ,
355+ headers : { 'content-type' : 'application/json' } ,
356+ } ) ,
357+ ) ;
358+ const { view } = await mount ( answer ( { [ COMMENT ] : SHAPE . full , [ REACTION ] : SHAPE . createOnly } ) ) ;
359+ fireEvent . click ( thumbsChip ( view ) ! ) ;
360+ await act ( async ( ) => { } ) ;
361+ expect ( unreactCalls ( ) . map ( ( [ url ] ) => url ) ) . toEqual ( [ '/api/v1/comments/reactions/r1' ] ) ;
362+ expect ( thumbsChip ( view ) ! . children [ 1 ] . textContent ) . toBe ( '1' ) ;
363+ expect ( toast . error ) . toHaveBeenCalledTimes ( 1 ) ;
364+ } ) ;
365+ } ) ;
366+
294367/**
295368 * The two feed objects as objectstack registers them (`plugin-audit`): their
296369 * policy keys (`managedBy`, `userActions`) and the `enable` block the server
@@ -336,7 +409,8 @@ describe('against the registered feed schemas in the page objects (objectui#1208
336409 expect ( addReaction ( view ) ) . not . toBeNull ( ) ;
337410 fireEvent . click ( thumbsChip ( view ) ! ) ;
338411 await act ( async ( ) => { } ) ;
339- expect ( dataSource . delete . mock . calls ) . toEqual ( [ [ REACTION , 'r1' ] ] ) ;
412+ expect ( unreactCalls ( ) . map ( ( [ url ] ) => url ) ) . toEqual ( [ '/api/v1/comments/reactions/r1' ] ) ;
413+ expect ( dataSource . delete ) . not . toHaveBeenCalled ( ) ;
340414 } ) ;
341415} ) ;
342416
0 commit comments