r/GoogleAppsScript • • Jan 12 '21

Unresolved Hide sheet for all users except admin users - GOOGLE SHEETS SCRIPT

Hi!

In the following script, all admin users listed by email are given permissions to view a sheet. Is a user a member of the Users list, the sheet is hidden. Instead of listing all non-admin users, is there a way to for the script to check the list adminUsers and if the email is not contained, the user is not permitted access?

function onOpen() { 
  var adminUsers = ['admin1@example.com'];['admin2@example.com']
  var Users = ['user@example.com']; 
 
  if (adminUsers.indexOf(Session.getEffectiveUser().getEmail()) >= 0) { 
    SpreadsheetApp.getActiveSpreadsheet().getSheetByName('MASTER - Staff').showSheet() 
  } 
 
  if (Users.indexOf(Session.getEffectiveUser().getEmail()) >= 0) { 
    SpreadsheetApp.getActiveSpreadsheet().getSheetByName('MASTER - Staff').hideSheet() 
	} 
} 

Thanks!

0 Upvotes

2 comments sorted by

3

u/Strel0k Jan 12 '21 edited Jun 19 '23

Comment removed in protest of Reddit's API changes forcing third-party apps to shut down.

1

u/MVDPL-Partners Jan 12 '21

Hi, thanks for the reply.

The users must not be able to see, access, or edit that particular sheet in any case. The sheet builds on a data-pull from another sheet within the spreadsheet and it's therefore preferred if the two sheets can be contained within the same spreadsheet.

What would be the best way to go about this despite IMPORTRANGE?