I am currently in the process of creating a script using Google Apps Script.
My goal is to verify whether a user with the email address [email protected] has viewing or editing privileges for a folder. If the user does not have either privilege, I want to add them as a viewer.
To retrieve an array of viewers, I am utilizing getViewers:
https://developers.google.com/apps-script/reference/drive/folder#getViewers()
Currently, it seems that there is no direct method to search for a user by their email address, only to retrieve the email address associated with a specific user:
https://developers.google.com/apps-script/reference/drive/user#getEmail()
To achieve this, I need to convert the array of viewers (users) into an array of email addresses. This will allow me to use indexOf to determine if [email protected] is included in that list.
How can I accomplish this task? Based on my understanding, it appears that I may need to utilize call or apply in order to apply a function to an array and obtain another array.
Furthermore, while I realize that the following solution works, I am curious if there is a more efficient or streamlined approach that doesn't require iterating through the entire array:
var vieweremails = new Array();
var viewers = folder.getViewers().concat(folder.getEditors()).concat(folder.getOwner());
for (var i = 0; i < viewers.length; i++) {
vieweremails[i] = viewers[i].getEmail()
}