(core) Preventing updates for widgets options when nothing has changed

Summary:
Custom widget was reseving its options, even though they haven't been changed. This
resulted with an ACL error and a popup message in readonly mode.

Test Plan:
Existing and manual.
To recreate:
1. Create a page with a calendar widget (don't change anything)
2. View this page as a Viewer (using ACL dropdown in tools)
3. The error should be shown.

Reviewers: georgegevoian

Reviewed By: georgegevoian

Subscribers: georgegevoian

Differential Revision: https://phab.getgrist.com/D4060
This commit is contained in:
Jarosław Sadziński 2023-09-27 23:00:33 +02:00
parent f38df564a9
commit 61023ecaa9

View File

@ -2,21 +2,36 @@ import {AccessLevel} from "app/common/CustomWidget";
import {ViewSectionRec} from "app/client/models/entities/ViewSectionRec"; import {ViewSectionRec} from "app/client/models/entities/ViewSectionRec";
import {CustomView} from "app/client/components/CustomView"; import {CustomView} from "app/client/components/CustomView";
import {GristDoc} from "app/client/components/GristDoc"; import {GristDoc} from "app/client/components/GristDoc";
import {reportError} from 'app/client/models/errors';
//Abstract class for more future inheritances //Abstract class for more future inheritances
abstract class CustomAttachedView extends CustomView { abstract class CustomAttachedView extends CustomView {
public override create(gristDoc: GristDoc, viewSectionModel: ViewSectionRec) { public override create(gristDoc: GristDoc, viewSectionModel: ViewSectionRec) {
super.create(gristDoc, viewSectionModel); super.create(gristDoc, viewSectionModel);
void viewSectionModel.customDef.access.setAndSave(AccessLevel.full); if (viewSectionModel.customDef.access.peek() !== AccessLevel.full) {
void viewSectionModel.customDef.access.setAndSave(AccessLevel.full).catch((err)=>{
if (err?.code === "ACL_DENY") {
// do nothing, we might be in a readonly mode.
return;
}
reportError(err);
});
}
const widgetsApi = this.gristDoc.app.topAppModel.api; const widgetsApi = this.gristDoc.app.topAppModel.api;
widgetsApi.getWidgets().then(async result=>{ widgetsApi.getWidgets().then(async result=>{
const widget = result.find(w=>w.name == this.getWidgetName()); const widget = result.find(w=>w.name == this.getWidgetName());
if(widget) { if (widget && this.customDef.url.peek() !== widget.url) {
await this.customDef.url.setAndSave(widget.url); await this.customDef.url.setAndSave(widget.url);
} }
}).catch(()=>{ }).catch((err)=>{
//do nothing if (err?.code !== "ACL_DENY") {
// TODO: revisit it later. getWidgets() is async call, and non of the code
// above is checking if we are still alive.
console.error(err);
} else {
// do nothing, we might be in a readonly mode.
}
}); });
} }