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/33521-record-page-refused-reaction-column.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@object-ui/app-shell': patch
---

fix(app-shell): a record page offers the reactions column write only where `sys_comment` still declares the column

Clause-②: no
Metadata-protocol: none

A caller refused `sys_comment_reaction` (a permission set with no read on it, or an external user) was offered the reaction control on a record page's discussion, and every click answered `400 INVALID_FIELD`: the page fell back to writing the retired `sys_comment.reactions` column with `PATCH /api/v1/data/sys_comment/ID`, which the server refuses because the column left `sys_comment` in the release that added `sys_comment_reaction`.

The page took that fallback whenever it could not read `sys_comment_reaction`, and a refusal reads the same as an object the deployment does not have: the metadata door answers both as absent. It now tells them apart by `sys_comment`'s own definition, which the caller can read. Where `sys_comment` still declares `reactions` (a framework that predates `sys_comment_reaction`), the column path is used exactly as before. Anywhere else the caller is refused the reaction object: the page offers no reaction control, reads no reactions and sends no reaction request.

- A caller who holds read on `sys_comment_reaction` is unchanged: reactions are that object's records.
- `useObjectPresence` also returns the object's served `definition` when the object is present, so a reader can choose by what the object declares without a second registry read.
29 changes: 22 additions & 7 deletions ui/packages/app-shell/src/hooks/useObjectPresence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,14 @@ export interface ObjectPresenceReading {
* `presence`: `absent` skips the read, anything else performs it.
*/
settled: boolean;
/**
* The object's definition as the registry served it, when `presence` is
* `present`; otherwise `undefined`. A reader that chooses a path by what the
* deployment's object declares (the record chatter asks whether
* `sys_comment` still declares its retired `reactions` column) reads it here
* rather than asking the registry a second time.
*/
definition?: unknown;
}

/** @see ObjectPresenceReading.settled */
Expand Down Expand Up @@ -271,17 +279,24 @@ export function useObjectPresence(name: string): ObjectPresenceReading {
if (readObjectScope && getTypeStatus?.('object') === 'idle') {
const readNames = readObjectScope as ReadNamesWithoutViews;
const scope = readNames(packageId ? { packageId, names: [name], views: false } : { names: [name], views: false });
const presence: ObjectPresence = !scope.settled
? 'unknown'
: scope.objects.some((o) => (o as { name?: unknown } | null | undefined)?.name === name)
? 'present'
: 'absent';
return { presence, settled: scope.settled };
const definition = scope.settled ? definitionNamed(scope.objects, name) : undefined;
const presence: ObjectPresence = !scope.settled ? 'unknown' : definition !== undefined ? 'present' : 'absent';
return { presence, settled: scope.settled, definition };
}
// Reading the items is also what ENSURES the type is fetched (MetadataProvider
// `readType`), so a surface that only ever asks this question still gets an
// answer instead of waiting on somebody else to populate the cache.
const objects = getItemsByType('object');
const status = getTypeStatus?.('object');
return { presence: objectPresence(name, status, objects), settled: metadataTypeSettled(status) };
const presence = objectPresence(name, status, objects);
return {
presence,
settled: metadataTypeSettled(status),
definition: presence === 'present' ? definitionNamed(objects, name) : undefined,
};
}

/** The definition in `objects` named `name`, if one is. */
function definitionNamed(objects: readonly unknown[], name: string): unknown {
return objects.find((o) => (o as { name?: unknown } | null | undefined)?.name === name) ?? undefined;
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,27 @@ const PAGE = {
],
};

/** The object registry: with the reaction object (the records store), or without it (the column store). */
/**
* `sys_comment` as a framework without `sys_comment_reaction` serves it: it
* still declares the `reactions` column the column store writes.
*/
const COLUMN_ERA_COMMENT = {
name: COMMENT,
label: 'Comment',
fields: { body: { type: 'textarea', label: 'Body' }, reactions: { type: 'textarea', label: 'Reactions' } },
};
/** `sys_comment` as a framework with `sys_comment_reaction` serves it: the column is retired. */
const RECORDS_ERA_COMMENT = { name: COMMENT, label: 'Comment', fields: { body: { type: 'textarea', label: 'Body' } } };

/**
* The object registry: with the reaction object (the records store); without
* it, on a framework that predates it (the column store); or a framework that
* has it, as a caller refused it is served, without it (objectstack#33521).
*/
const REGISTRY = {
records: [...OBJECTS, { name: REACTION, label: 'Comment Reaction' }],
column: OBJECTS,
column: [...OBJECTS, COLUMN_ERA_COMMENT],
refused: [...OBJECTS, RECORDS_ERA_COMMENT],
};

/** The four grant shapes of the map's enumeration pin, as `/me/permissions` carries them. */
Expand Down Expand Up @@ -491,3 +508,63 @@ describe('the reaction store is asked of the registry only by a caller who may r
expect(asked).toContain(REACTION);
});
});

/**
* The column store is taken only where `sys_comment_reaction` is not deployed,
* never where the caller is refused it (objectstack#33521). Both answers read
* alike: the metadata door answers a refused caller's definition read as
* absent, and a caller's grants name neither. The column left `sys_comment` in
* the release that added the object, so `sys_comment`'s own served definition
* tells them apart. On a framework that has the object, a caller refused it was
* offered the column control, and its click was a
* `PATCH /api/v1/data/sys_comment/:id` naming the retired `reactions` column,
* which the data door answers `400 INVALID_FIELD`.
*/
describe('a caller refused sys_comment_reaction is offered no column write where the column is retired (objectstack#33521)', () => {
/** The writes that named the reactions column. */
const columnWrites = (dataSource: ReturnType<typeof makeDataSource>) =>
dataSource.update.mock.calls.filter(([o, , patch]: [string, string, any]) => o === COMMENT && 'reactions' in (patch ?? {}));
const reactionReads = (dataSource: ReturnType<typeof makeDataSource>) =>
dataSource.find.mock.calls.filter(([objectName]: [string]) => objectName === REACTION);

it('a caller whose grants hold no read on it is offered no reaction control and sends no reaction request', async () => {
const { view, dataSource } = await mount(answer({ [COMMENT]: SHAPE.full }), makeDataSource(), REGISTRY.refused);
expect(addReaction(view)).toBeNull();
// The stored chip is not read off the retired column either: a comment
// read on this framework never returns it.
expect(thumbsChip(view)).toBeUndefined();
expect(columnWrites(dataSource)).toEqual([]);
expect(reactionReads(dataSource)).toEqual([]);
expect(dataSource.create).not.toHaveBeenCalled();
});

it('with no permission provider, a registry that answers the object absent is read the same way: no control', async () => {
const { view, dataSource } = await mount(null, makeDataSource(), REGISTRY.refused);
expect(addReaction(view)).toBeNull();
expect(thumbsChip(view)).toBeUndefined();
expect(columnWrites(dataSource)).toEqual([]);
});

it('CONTROL — where the object is not deployed (sys_comment declares the column) the column path is still used', async () => {
const { view, dataSource } = await mount(answer({ [COMMENT]: SHAPE.full }), makeDataSource('u2'), REGISTRY.column);
expect(addReaction(view)).not.toBeNull();
expect(reactionReads(dataSource)).toEqual([]);
fireEvent.click(thumbsChip(view)!);
await act(async () => {});
expect(columnWrites(dataSource)).toHaveLength(1);
const [, id, patch] = columnWrites(dataSource)[0];
expect(id).toBe(COMMENT_ID);
expect(JSON.parse(patch.reactions)).toEqual({ '👍': ['u2', 'u1'] });
expect(dataSource.create).not.toHaveBeenCalled();
});

it('CONTROL — a caller who holds the grant takes the records store: its rows are read and a click creates its own row', async () => {
const { view, dataSource } = await mount(answer({ [COMMENT]: SHAPE.full, [REACTION]: SHAPE.full }), makeDataSource('u2'), REGISTRY.records);
expect(addReaction(view)).not.toBeNull();
expect(reactionReads(dataSource)).toHaveLength(1);
fireEvent.click(thumbsChip(view)!);
await act(async () => {});
expect(dataSource.create.mock.calls).toEqual([[REACTION, { comment_id: COMMENT_ID, emoji: '👍' }]]);
expect(columnWrites(dataSource)).toEqual([]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ const OBJECTS = [
},
];

/**
* The object registry of a framework without `sys_comment_reaction`: its
* `sys_comment` still declares the `reactions` column the column store writes
* (objectstack#33521).
*/
const REGISTRY = [
...OBJECTS,
{ name: 'sys_comment', label: 'Comment', fields: { reactions: { type: 'textarea', label: 'Reactions' } } },
];

const PAGE = {
name: 'customer_record_page',
type: 'record',
Expand Down Expand Up @@ -131,8 +141,9 @@ async function mountAs(userId: string, dataSource: any) {
getItem: async () => null,
// The registry lists this deployment's objects, and `sys_comment_reaction`
// is not one of them, so the page keeps reactions in the
// `sys_comment.reactions` column (objectui#12078).
getItemsByType: (type: string) => (type === 'page' ? pages : type === 'object' ? OBJECTS : []),
// `sys_comment.reactions` column (objectui#12078), which its `sys_comment`
// still declares (objectstack#33521).
getItemsByType: (type: string) => (type === 'page' ? pages : type === 'object' ? REGISTRY : []),
} as any;
render(
<MemoryRouter initialEntries={[`/app/demo/${OBJECT_NAME}/${RECORD_ID}`]}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,17 @@ const PAGE = {
],
};

/** The object registry each case serves: with the reaction object, without it, or listing nothing. */
/**
* The object registry each case serves: with the reaction object, without it
* (a framework that predates it, whose `sys_comment` still declares the
* `reactions` column, objectstack#33521), or listing nothing.
*/
const REGISTRY = {
present: [...OBJECTS, { name: REACTION, label: 'Comment Reaction' }],
absent: OBJECTS,
absent: [
...OBJECTS,
{ name: 'sys_comment', label: 'Comment', fields: { reactions: { type: 'textarea', label: 'Reactions' } } },
],
empty: [] as unknown[],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ const OBJECTS = [
},
];

/**
* The object registry of a framework without `sys_comment_reaction`: its
* `sys_comment` still declares the `reactions` column the column store writes
* (objectstack#33521).
*/
const REGISTRY = [
...OBJECTS,
{ name: 'sys_comment', label: 'Comment', fields: { reactions: { type: 'textarea', label: 'Reactions' } } },
];

const PAGE = {
name: 'customer_record_page',
type: 'record',
Expand Down Expand Up @@ -146,8 +156,9 @@ function mount(dataSource: any, wrap: (tree: React.ReactElement) => React.ReactE
getItem: async () => null,
// The registry lists this deployment's objects, and `sys_comment_reaction`
// is not one of them, so the page keeps reactions in the
// `sys_comment.reactions` column (objectui#12078).
getItemsByType: (type: string) => (type === 'page' ? pages : type === 'object' ? OBJECTS : []),
// `sys_comment.reactions` column (objectui#12078), which its `sys_comment`
// still declares (objectstack#33521).
getItemsByType: (type: string) => (type === 'page' ? pages : type === 'object' ? REGISTRY : []),
} as any;
return render(
wrap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ const OBJECTS = [
},
];

/**
* The object registry of a framework without `sys_comment_reaction`: its
* `sys_comment` still declares the `reactions` column the column store writes
* (objectstack#33521).
*/
const REGISTRY = [
...OBJECTS,
{ name: 'sys_comment', label: 'Comment', fields: { reactions: { type: 'textarea', label: 'Reactions' } } },
];

/**
* Hands the page's reaction handler an id directly, the way any consumer of
* `DiscussionContext` can: one button per feed id.
Expand Down Expand Up @@ -164,8 +174,9 @@ async function mount(dataSource: any, { withProbe = false } = {}) {
getItem: async () => null,
// The registry lists this deployment's objects, and `sys_comment_reaction`
// is not one of them, so the page keeps reactions in the
// `sys_comment.reactions` column (objectui#12078).
getItemsByType: (type: string) => (type === 'page' ? pages : type === 'object' ? OBJECTS : []),
// `sys_comment.reactions` column (objectui#12078), which its `sys_comment`
// still declares (objectstack#33521).
getItemsByType: (type: string) => (type === 'page' ? pages : type === 'object' ? REGISTRY : []),
} as any;
render(
<MemoryRouter initialEntries={[`/app/demo/${OBJECT_NAME}/${RECORD_ID}`]}>
Expand Down
45 changes: 39 additions & 6 deletions ui/packages/app-shell/src/views/RecordDetailView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,21 @@ const COMMENT_REACTION_REMOVE_PATH = '/api/v1/comments/reactions';
/** The object the record feed's comments and replies are rows of. */
const COMMENT_OBJECT = 'sys_comment';

/**
* Whether a served `sys_comment` definition still declares the retired
* `reactions` column: the one deployment the column store writes to. The
* column left `sys_comment` in the release that added
* {@link COMMENT_REACTION_OBJECT} (`sys-comment-reactions-column-retired`), so
* a definition that declares it is a framework without that object, and one
* that does not refuses a write naming it (`400 INVALID_FIELD`). No definition
* (none served, or not read yet) is not evidence of the column.
*/
function declaresReactionsColumn(definition: unknown): boolean {
const fields = (definition as { fields?: unknown } | null | undefined)?.fields;
if (Array.isArray(fields)) return fields.some((f) => (f as { name?: unknown } | null)?.name === 'reactions');
return !!fields && typeof fields === 'object' && Object.prototype.hasOwnProperty.call(fields, 'reactions');
}

/**
* `sys_approval_request`'s declared recall. While the decision bar draws it,
* the DetailView approval band yields its own Recall (objectstack#25877).
Expand Down Expand Up @@ -3183,15 +3198,31 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
// the object declares no `schemaReadDelegate`, so that read could only
// answer absent (a 404 on every record page). It takes the path that answer
// takes. With no permission provider every grant reads open, as before.
//
// Neither answer tells an undeployed object from a refused one: the door
// answers both as absent, and a caller's grants name neither. What does is
// `sys_comment`'s own definition, which this caller reads: the release that
// added `sys_comment_reaction` retired the `reactions` column in the same
// step (`sys-comment-reactions-column-retired`), so a framework without the
// object still declares the column, and one with it does not. So the column
// path is taken only where `sys_comment` declares `reactions`. Anywhere else
// the object is there and this caller may not read it: `none`, no reaction
// is read or offered. The column write there answered `400 INVALID_FIELD`
// on every click, and the caller's own reaction row is refused too.
const reactionReadRefused = perms.isLoaded && !perms.can(COMMENT_REACTION_OBJECT, 'read');
const reactionPresence = useObjectPresence(reactionReadRefused ? '' : COMMENT_REACTION_OBJECT);
const reactionStore: 'records' | 'column' | null = reactionReadRefused
? 'column'
: !reactionPresence.settled
const reactionObjectUnread =
reactionReadRefused || (reactionPresence.settled && reactionPresence.presence === 'absent');
const commentPresence = useObjectPresence(reactionObjectUnread ? COMMENT_OBJECT : '');
const reactionStore: 'records' | 'column' | 'none' | null = !reactionObjectUnread
? reactionPresence.settled
? 'records'
: null
: !commentPresence.settled
? null
: reactionPresence.presence === 'absent'
: declaresReactionsColumn(commentPresence.definition)
? 'column'
: 'records';
: 'none';
/**
* The signed-in user's own reaction rows, per comment (`[thread, comment]`)
* and emoji: the row id a click that takes the reaction back deletes. Filled
Expand Down Expand Up @@ -3383,7 +3414,9 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
reactions:
reactionStore === 'records'
? toReactions(records?.stored.get(String(c.id)))
: parseReactions(c.reactions),
: reactionStore === 'column'
? parseReactions(c.reactions)
: undefined,
}));
// Into THIS record's slice — `threadId` is the key the effect closed
// over, so a response that arrives after the user navigated away
Expand Down
Loading