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