问题
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.
回答1:
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:
- Remove all features
- Remove all views
- 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
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
来源:https://stackoverflow.com/questions/50480858/display-only-team-drives-in-drive-picker-widget