fix: Enable toggling of insights while document is draft
This commit is contained in:
@@ -159,7 +159,7 @@ export const publishDocument = createAction({
|
||||
}
|
||||
|
||||
if (document?.collectionId) {
|
||||
await document.save({
|
||||
await document.save(undefined, {
|
||||
publish: true,
|
||||
});
|
||||
stores.toasts.showToast(t("Document published"), {
|
||||
|
||||
@@ -84,7 +84,6 @@ export default class Document extends ParanoidModel {
|
||||
/**
|
||||
* Whether team members can see who has viewed this document.
|
||||
*/
|
||||
@Field
|
||||
@observable
|
||||
insightsEnabled: boolean;
|
||||
|
||||
@@ -352,12 +351,18 @@ export default class Document extends ParanoidModel {
|
||||
templatize = () => this.store.templatize(this.id);
|
||||
|
||||
@action
|
||||
save = async (options?: SaveOptions | undefined) => {
|
||||
const params = this.toAPI();
|
||||
save = async (
|
||||
fields: Partial<Document> | undefined,
|
||||
options?: SaveOptions | undefined
|
||||
) => {
|
||||
const params = fields ?? this.toAPI();
|
||||
this.isSaving = true;
|
||||
|
||||
try {
|
||||
const model = await this.store.save({ ...params, id: this.id }, options);
|
||||
const model = await this.store.save(
|
||||
{ ...params, ...fields, id: this.id },
|
||||
options
|
||||
);
|
||||
|
||||
// if saving is successful set the new values on the model itself
|
||||
set(this, { ...params, ...model });
|
||||
|
||||
@@ -305,7 +305,7 @@ class DocumentScene extends React.Component<Props> {
|
||||
this.isPublishing = !!options.publish;
|
||||
|
||||
try {
|
||||
const savedDocument = await document.save(options);
|
||||
const savedDocument = await document.save(undefined, options);
|
||||
this.isEditorDirty = false;
|
||||
|
||||
if (options.done) {
|
||||
|
||||
@@ -160,8 +160,9 @@ function Insights() {
|
||||
<Switch
|
||||
checked={document.insightsEnabled}
|
||||
onChange={async (ev) => {
|
||||
document.insightsEnabled = ev.currentTarget.checked;
|
||||
await document.save();
|
||||
await document.save({
|
||||
insightsEnabled: ev.currentTarget.checked,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</Manage>
|
||||
|
||||
@@ -52,7 +52,7 @@ function DocumentPublish({ document }: Props) {
|
||||
}
|
||||
|
||||
document.collectionId = collectionId;
|
||||
await document.save({ publish: true });
|
||||
await document.save(undefined, { publish: true });
|
||||
|
||||
showToast(t("Document published"), {
|
||||
type: "success",
|
||||
|
||||
@@ -129,6 +129,23 @@ allow(User, "update", Document, (user, document) => {
|
||||
return user.teamId === document.teamId;
|
||||
});
|
||||
|
||||
allow(User, "updateInsights", Document, (user, document) => {
|
||||
if (!document || !document.isActive) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (document.collectionId) {
|
||||
invariant(
|
||||
document.collection,
|
||||
"collection is missing, did you forget to include in the query scope?"
|
||||
);
|
||||
if (cannot(user, "update", document.collection)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return user.teamId === document.teamId;
|
||||
});
|
||||
|
||||
allow(User, "createChildDocument", Document, (user, document) => {
|
||||
if (!document || !document.isActive || document.isDraft) {
|
||||
return false;
|
||||
@@ -277,20 +294,6 @@ allow(User, "archive", Document, (user, document) => {
|
||||
return user.teamId === document.teamId;
|
||||
});
|
||||
|
||||
allow(User, "updateInsights", Document, (user, document) => {
|
||||
if (!document || !document.isActive || document.isDraft) {
|
||||
return false;
|
||||
}
|
||||
invariant(
|
||||
document.collection,
|
||||
"collection is missing, did you forget to include in the query scope?"
|
||||
);
|
||||
if (cannot(user, "update", document.collection)) {
|
||||
return false;
|
||||
}
|
||||
return user.teamId === document.teamId;
|
||||
});
|
||||
|
||||
allow(User, "unarchive", Document, (user, document) => {
|
||||
if (!document) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user