Reputation: 166
I am trying to check how permissions work in Google Apps Script
, so I am trying to create a File for each set of Permissions listed in https://developers.google.com/apps-script/reference/drive/permission?hl=en
function main () {
// CREATING A FILE WITH CERTAIN PERMISSIONS
// -------------------------------------------
var folderRef = DriveApp.getFolderById('root');
folderRef = folderRef.getFoldersByName('toarchive').next();
var fileRef = folderRef.createFile("NONE" , "Some text" , "text/plain");
fileRef.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.NONE);
//-------------------------------------------
// eof eof eof eof eof eof eof eof eof eof eof
// CREATING A FILE WITH CERTAIN PERMISSIONS
// -------------------------------------------
var folderRef = DriveApp.getFolderById('root');
folderRef = folderRef.getFoldersByName('toarchive').next();
var fileRef = folderRef.createFile("OWNER" , "Some text" , "text/plain");
fileRef.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.OWNER);
//-------------------------------------------
// eof eof eof eof eof eof eof eof eof eof eof
// CREATING A FILE WITH CERTAIN PERMISSIONS
// -------------------------------------------
var folderRef = DriveApp.getFolderById('root');
folderRef = folderRef.getFoldersByName('toarchive').next();
var fileRef = folderRef.createFile("ORGANIZER" , "Some text" , "text/plain");
fileRef.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.ORGANIZER);
//-------------------------------------------
// eof eof eof eof eof eof eof eof eof eof eof
(...)
}
The issue is that it gives me an Error when Running the Script
Error Exception: Invalid argument: OWNER
Upvotes: 2
Views: 359
Reputation: 2387
Based from the Enum Permission documentation, using the "OWNER" property (along with "ORGANIZER" and "FILE_ORGANIZER") will have its value returned but passing it to File.setSharing() is an exception and therefore cannot be used this way.
I have tried the other properties:
Here is the part of your script that I used to test the properties:
function permissionTest() {
// CREATING A FILE WITH CERTAIN PERMISSIONS
// -------------------------------------------
var folderRef = DriveApp.getFolderById('1ZKYjo70s51TANG9Zu3eojTkJpe3-SyOd'); //test folder ID
folderRef = folderRef.getFoldersByName('toArchive').next();
var fileRef = folderRef.createFile("EDITABLE", "Some text", "text/plain");
fileRef.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.EDIT); //changed "EDIT" to other properties to test
//-------------------------------------------
// eof eof eof eof eof eof eof eof eof eof eof
}
Here is the sample of your script being run in a google account without an admin role:
Here is the sample of your script being run in a google account with an admin role:
Upvotes: 2