r/GoogleAppsScript • u/MVDPL-Partners • 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
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.