-
-
Save landsurveyorsunited/e4ccd34d822ad0b15b54 to your computer and use it in GitHub Desktop.
Google Apps Script snippet which uses viewer settings on Google Sheet to control who views
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var DOC_ID = '1K5IJLwK7qBUfLAG-tic9hOK3L8x4qUIQgd3gryHNE6Y'; | |
function doGet() { | |
var doc =SpreadsheetApp.openById(DOC_ID); | |
var auth_user = doc.getViewers(); | |
var auth = auth_user.map(function(user) { | |
return String(user); | |
}); | |
var user = Session.getActiveUser().getEmail(); | |
if (auth.indexOf(user) > -1){ | |
return HtmlService.createHtmlOutput("you are allowed to view this").setSandboxMode(HtmlService.SandboxMode.IFRAME); | |
} else { | |
return HtmlService.createHtmlOutput(user+"you are <b>not</b> allowed to view this").setSandboxMode(HtmlService.SandboxMode.IFRAME); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment