Add per-document control over who can see viewer insights (#5594)

This commit is contained in:
Tom Moor
2023-07-23 12:01:36 -04:00
committed by GitHub
parent caf7333682
commit 479b805613
14 changed files with 192 additions and 73 deletions

View File

@@ -892,18 +892,8 @@ router.post(
auth(),
validate(T.DocumentsUpdateSchema),
async (ctx: APIContext<T.DocumentsUpdateReq>) => {
const {
id,
title,
text,
fullWidth,
publish,
templateId,
collectionId,
append,
apiVersion,
done,
} = ctx.input.body;
const { id, apiVersion, insightsEnabled, publish, collectionId, ...input } =
ctx.input.body;
const editorVersion = ctx.headers["x-editor-version"] as string | undefined;
const { user } = ctx.state.auth;
let collection: Collection | null | undefined;
@@ -915,6 +905,10 @@ router.post(
collection = document?.collection;
authorize(user, "update", document);
if (collection && insightsEnabled !== undefined) {
authorize(user, "updateInsights", document);
}
if (publish) {
if (!document.collectionId) {
assertPresent(
@@ -932,16 +926,12 @@ router.post(
await documentUpdater({
document,
user,
title,
text,
fullWidth,
...input,
publish,
collectionId,
append,
templateId,
insightsEnabled,
editorVersion,
transaction,
done,
ip: ctx.request.ip,
});

View File

@@ -189,6 +189,9 @@ export const DocumentsUpdateSchema = BaseSchema.extend({
/** Boolean to denote if the doc should occupy full width */
fullWidth: z.boolean().optional(),
/** Boolean to denote if insights should be visible on the doc */
insightsEnabled: z.boolean().optional(),
/** Boolean to denote if the doc should be published */
publish: z.boolean().optional(),