Home > Software design >  Share the Drive file with extra permissions
Share the Drive file with extra permissions

Time:12-01

I have a drive file where I need to restrict the users from these (I mean ticks for both needs to be removed and shared using apps script/drive api)

enter image description here enter image description here

I need to accomplish using Google Apps Script Advanced Drive service or regular apps script. I am unsure what is the exact method. I have tried with

function shareit() {
  DriveApp.getFileById(id).setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.EDIT);
}

CodePudding user response:

Drive Sharing Permissions with App Script

I manage to make both changes by using Advance Services from App Script. I was able to use part of your code to first remove the "Editors can change permissions and share" by using the:

setShareableByEditors(false)

Code Sample:

function shareit() {
      DriveApp.getFileById(id).setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.EDIT).setShareableByEditors(false);

// Add advance service to be able to run a files patch and update the permissions of the ID to require writters permisions to copy, print and download. 

     Drive.Files.patch({copyRequiresWriterPermission:true}, id);
      }

As presented in the comments you would need run a patch update to the File ID to change the permissions.

References:

  • Related