From 14125b9b972a9244fca2d9110fc850e6f54f5c2d Mon Sep 17 00:00:00 2001 From: George Gevoian Date: Thu, 7 Mar 2024 23:43:46 -0500 Subject: [PATCH] (core) Use document access for showing form buttons Summary: Site access was being used to show or hide form widget buttons. This meant that users granted owner access to a document couldn't see buttons to publish/unpublish or share a form. Now, document access is used instead. Test Plan: Manual. Reviewers: paulfitz Reviewed By: paulfitz Subscribers: paulfitz Differential Revision: https://phab.getgrist.com/D4207 --- app/client/components/Forms/FormView.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/client/components/Forms/FormView.ts b/app/client/components/Forms/FormView.ts index dbbd5aca..a76f1ec6 100644 --- a/app/client/components/Forms/FormView.ts +++ b/app/client/components/Forms/FormView.ts @@ -24,6 +24,7 @@ import {cssButton} from 'app/client/ui2018/buttons'; import {icon} from 'app/client/ui2018/icons'; import {confirmModal} from 'app/client/ui2018/modals'; import {INITIAL_FIELDS_COUNT} from 'app/common/Forms'; +import {isOwner} from 'app/common/roles'; import {Events as BackboneEvents} from 'backbone'; import {Computed, dom, Holder, IDomArgs, MultiHolder, Observable} from 'grainjs'; import defaults from 'lodash/defaults'; @@ -58,6 +59,7 @@ export class FormView extends Disposable { private _remoteShare: AsyncComputed<{key: string}|null>; private _published: Computed; private _showPublishedMessage: Observable; + private _isOwner: boolean; public create(gristDoc: GristDoc, viewSectionModel: ViewSectionRec) { BaseView.call(this as any, gristDoc, viewSectionModel, {'addNewRow': false}); @@ -380,6 +382,8 @@ export class FormView extends Disposable { true )); + this._isOwner = isOwner(this.gristDoc.docPageModel.currentDoc.get()); + // Last line, build the dom. this.viewPane = this.autoDispose(this.buildDom()); } @@ -640,7 +644,7 @@ export class FormView extends Disposable { testId('link'), dom('div', 'Copy Link'), dom.prop('disabled', this._copyingLink), - dom.show(use => this.gristDoc.appModel.isOwner() && use(this._published)), + dom.show(use => this._isOwner && use(this._published)), dom.on('click', async (_event, element) => { try { this._copyingLink.set(true); @@ -662,14 +666,14 @@ export class FormView extends Disposable { return published ? style.cssIconButton( dom('div', 'Unpublish'), - dom.show(this.gristDoc.appModel.isOwner()), + dom.show(this._isOwner), style.cssIconButton.cls('-warning'), dom.on('click', () => this._handleClickUnpublish()), testId('unpublish'), ) : style.cssIconButton( dom('div', 'Publish'), - dom.show(this.gristDoc.appModel.isOwner()), + dom.show(this._isOwner), cssButton.cls('-primary'), dom.on('click', () => this._handleClickPublish()), testId('publish'), @@ -714,7 +718,7 @@ export class FormView extends Disposable { this._showPublishedMessage.set(false); }), ), - dom.show(this.gristDoc.appModel.isOwner()), + dom.show(this._isOwner), ); }); }