1

I am creating an application where I need to provide Drive Picker widget so that users can upload some files. Now I want to restrict users so that they can only select files from their "Team Drives" and not from anywhere else.

I've tried adding method in onPickerInit event.

Here's my function which is getting called in onPickerInit event,

function fetchFolder(widget, pickerBuilder) {
  pickerBuilder.addView(new google.picker.DocsView()
                       .setParent('TeamDriveId')
                       .setIncludeFolders(true));
}

This method restricts users to select only from particular Team Drive, however my question is how can I give dynamic option so that users can select from any of their Team Drives and not limited to one Team Drive. Also they should not be able to select from their own Google Drives.

Pavel Shkleinik
  • 6,298
  • 2
  • 24
  • 36
Darpan Sanghavi
  • 1,443
  • 2
  • 17
  • 32

1 Answers1

4

It seems that this case requires low level Drive Picker tuning, so lets start from removing all settings that App Maker gives us out of the box:

  1. Remove all features
  2. Remove all views

Drive Picker settings

  1. Then add the following script to the onPickerInit event
// Enable Team Drives
pickerBuilder.enableFeature(google.picker.Feature.SUPPORT_TEAM_DRIVES);

// Let users to select files from any Team Drive
var multiTeamDrive = new google.picker.DocsView();
multiTeamDrive.setIncludeFolders(true)
              .setEnableTeamDrives(true);
pickerBuilder.addView(multiTeamDrive);


// This feature need to be set to force `setParent` work.
// Seems to be Drive Picker's bug
pickerBuilder.enableFeature(google.picker.Feature.MULTISELECT_ENABLED);

// Force users to upload files to a specific Team Drive
var uploadView = new google.picker.DocsUploadView();
uploadView.setParent('Fancy KEY from Team Drive folder URL')
          .setLabel('Upload to Team Drive XXX');
pickerBuilder.addView(uploadView);

Result Multi Team Drive

Notes

  • I didn't find a way to hide the tab for the Personal Drive upload. It is strange that App Maker adds it by default and there is no option to remove it.
  • I also recommend to add server side validation for the files selected by users to ensure that they originate from Team Drive.

Similar/related answer: https://stackoverflow.com/a/49677679/454137

Pavel Shkleinik
  • 6,298
  • 2
  • 24
  • 36
  • Thanks for detailed answer, but as you rightly pointed out Appmaker adds Person's My Drive by default, which is creating the issue for me. I've been able to achieve this much without removing these features as well, Just provide 'SUPPORT_TEAM_DRIVES' in "Features" and remove everything from "Views" and voila I can see My Drive and All Team Drives. But I want to remove "My Drive" as I can not put Server side validations, my requirement is somewhat different. – Darpan Sanghavi May 24 '18 at 04:21
  • FWIW, it looks like this is an option now. – xd1936 Sep 28 '18 at 17:46