Shah Rukh
Shah Rukh

Reputation: 3156

How To set permissions to Google Drive files/folder while adding from Google Site

I am new to Google Sites, I have created a test google site, and add some pages files from google drive to the pages.

My Question is: Is it possible to set permissions from a Google Site while adding a file/folder from Google Drive via any Google Apps Script or Google Drive SDK?

I also did some overview about Google Apps Script for adding UI elements/ html elements, and perform some basic authentication using Google Drive SDK. Given this:

  1. Is possible to perform permission actions.

  2. If we upload a file in a file cabinet template can we set any kind of permissions or remove download link button of that file?

Upvotes: 0

Views: 1929

Answers (2)

Shah Rukh
Shah Rukh

Reputation: 3156

Thanks to Your Answer @Sandy Good from you suggestion/idea I able to create a simple script and after creating this script I am sure I will be able to create a complicated script also. I have created a script that will create a form in in google site's page. this form contain a dropdown list of my google drive files and an input filed in which i will add an email address. and in the last a submit button.

after pressing submit button , the script work as it will grant permission on a selected to the email given as viewer of the file if he has link.

create a blank script in the Google Site's Apps Script Section.

Add some UI via UI Service

function doGet() {
 // create ui element
 var app = UiApp.createApplication();
 // create form 
 var form = app.createFormPanel();
 // create area or panel
 var flow = app.createFlowPanel();
 // create list box for files
 var element_file = app.createListBox().setId('file_name').setName('file_name');
// add first elemnt
element_file.addItem('Please Select','');
// get drive files
var files = DriveApp.getFiles();
while (files.hasNext()) {
var file = files.next();

  element_file.addItem(file.getName(),file.getId());
 }
  flow.add(element_file); 
  var element_text=app.createTextBox().setId('email').setName('email');
  flow.add(element_text); 
 flow.add(app.createSubmitButton("Submit"));
  form.add(flow);
 app.add(form);  
  return app;
 }

after this I handle the data submitted via post

 function doPost(e) {
   var app = UiApp.getActiveApplication();
   var email = e.parameter.email;
   var file_name = e.parameter.file_name;
   var public_file = DriveApp.getFileById(file_name);
   public_file.addViewer(email);
   return app;
}

after this you can check the permissions of the specific file in the google drive. you may also add a success message. after this go to publish menu of the file select deploy as web app then select the required things. remember please select execute scripts only as me option because you are listing all your files. then go to the page in which you want to add script just edit/add new page from editor of the page just insert Apps Script.

apologies , its my first time to work in google apps script , if I miss anything or i did not follow any rule etc.

Thanks,

Upvotes: 1

Alan Wells
Alan Wells

Reputation: 31310

Apps Script has a service called Drive. Drive has a class named: DriveApp. DriveApp can create, save and retrieve files. Once you have a reference to a file, you can use other Classes, Properties and Methods.

setSharing method - Google Documentation

Upvotes: 1

Related Questions