1

How can I allow users with permissions of "View Only" the ability to execute an apps script in a spreadsheet?

I've created a custom menu choice triggered by onOpen() that launches the script fine for anyone with edit permissions. However, onOpen() does not run for anyone with only view/comment permissions (consistent with the documentation) and thus the menu is not created and there is no way to launch the script.

Ideally, I would like view only users to view and execute the script, but not modify it.

Seanny123
  • 8,776
  • 13
  • 68
  • 124
Max
  • 43
  • 1
  • 9
  • 2
    The first thing that you need to know about "View Only" is that if you do not explicitly check the box to prevent the viewer from copying the file, then there is no real security for your code. The viewer can just make a copy of the file, and then they can view the code in the copy. Because you are using the reserved function name `onOpen()` that is a *simple* trigger versus an "Installed" trigger. But even an "installed" trigger will not run when the file is in "View Only" mode. So, if you want to prevent the user from seeing the code, you must use an Add-on. You can publish it unlisted. – Alan Wells Mar 14 '17 at 01:32
  • I don't mind if they view the code. I want to keep them from modifying it. – Max Mar 14 '17 at 03:52
  • You could try a "library", which is just a reference to another Apps Script file. That will keep people from seeing or modifying the code. It may run slower, and you'll still have the problem with the trigger not running. – Alan Wells Mar 14 '17 at 12:45

3 Answers3

0

If executing the script results in modifying any content of the sheet then I think it's reasonable to expect only those users with edit rights will be able to run the script. In view of this I am not sure I understand the question at all.

  • I totally disagree with @Vivekananda L Baindoor Rao. The concept of running a script is vastly different from editing it, and a sheet is different from a program that runs under the owners account and can access all sort of things other than just the sheet. This concept was worked out a long time ago with Read, Modify, Execute privileges. Google's approach to running web app scripts is vastly flawed. I suspect they want to do away with anonymous users and in their view, everyone has to get a google account. – stanely Apr 06 '21 at 16:06
0

Ideally, I would like view only users to view and execute the script, but not modify it.

Simple triggers and installable triggers that are able to use SpreadsheetApp.getUi like onOpen and onEdit are executed only for users with edit permissions.

Instead of using a custom menu you could add a link to script published as web app allowed to be accessed by anyone and run. The link could be added to a cell or to an image.

Related

Threads with answers with score > 0

Threads with one answer with 0 score

Rubén
  • 34,714
  • 9
  • 70
  • 166
0

I just spend a few days on this and don't believe you can! In order to let an anonymous user execute a web app google app script, you have to set it to "Anyone on the internet with this link can edit" in the app script sharing options. Plus you have to make the sheets the script touches editable by anyone. Plus you have to deploy it as executed by you and everyone has access.

No sir, I don't like it. The app script should be executable without being editable. Google's choice makes no sense, especially considering how difficult they've made it to share content with anonymous users. You'd think they would allow an execute privilege without a modify privilege. (Are opinions allowed in answers?)

stanely
  • 342
  • 1
  • 8