I made a script that receive a list of emails of users that need to be removed from accessing a given Google drive folder. Here is the snippet with the function that removes a user:
function remove_user(drive_folder,user_email){
if(drive_folder.getAccess(user_email) != "NONE"){
Logger.log("removing user: " user_email);
drive_folder.revokePermissions(user_email);
}
}
An exception is raised when the revokePermission method is called:
Exception: Access denied: DriveApp
Thing is, the script did ask the first time for a DriveApp permission to my email account and i gave it(Other DriveApp methods work pretty fine in the same script). Also, my email account has the permission to remove users from the google drive folder i'm targeting(I can manually remove users using my google account).
I appreciate any help.
CodePudding user response:
- The user you are logging in with needs to be owner of the file to remove others permissions.
- If this is a workspace account make sure the DriveApp is activated in the Admin Console for you or your domain.
CodePudding user response:
By design, you cannot remove the owner of the shared folder. If you try to do it as an editor, your exception will arise. If you try to remove yourself (being the owner) an Exception: Invalid argument: file.owner will arise.
This is how it is designed to work. A folder (or a file for that matter) always has an owner, regardless of how it is shared. You can read more about how permissions in Google Drive work here.
Naturally, using AppsScript you can remove other editors of the folder via DriveApp.revokePermissions() as you would do it manually.
