Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TeamDrive functionality #67

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
The branch works for scripts sitting in a Team Drive by adding the parameter supportsTeamDrives to the upload request.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't say better than @lricoy comment about updating the README


* Moving the script to a team drive causes https://github.com/danthareja/node-google-apps-script to fail uploading
* This is because the update command wants a parameter `supportTeamDrives` set to true, see https://developers.google.com/apis-explorer/?hl=en_US#p/drive/v3/drive.files.update and https://developers.google.com/drive/v3/reference/files/update
* https://developers.google.com/drive/v3/web/enable-teamdrives : “If your application isn't affected by the behavioral differences, then you only need to include thesupportsTeamDrives=true query parameter in requests. This is an acknowledgement that the application is aware of behavioral differences of files contained in Team Drives.”
* Adding `supportsTeamDrives: true` to
```return authenticate()
.then(function(auth) {
var drive = google.drive({ version: 'v2', auth: auth });
var options = {
fileId: id,
supportsTeamDrives: true,
media: {
mimeType: 'application/vnd.google-apps.script+json',
body: JSON.stringify({ files: files })
}
}; ```
fixes the problem for a team drive



# gapps (Google Apps Script)
>The easiest way to develop Google Apps Script projects

Expand Down
1 change: 1 addition & 0 deletions bin/gapps
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ program

program
.command('upload')
.option('-t, --teamdrive')
.description('Upload back to an Apps Script project in Google Drive. Run from root of project directory')
.alias('push')
.action(require(commands + '/upload'));
Expand Down
14 changes: 10 additions & 4 deletions lib/commands/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ var defaults = require('../defaults');
var manifestor = require('../manifestor');
var authenticate = require('../authenticate');

module.exports = function upload() {
module.exports = function upload(options) {
// console.log(options)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean this ? :)

console.log('Pushing back up to Google Drive...');

var fileId; // Hold in closure to avoid promise nesting
Expand All @@ -21,7 +22,7 @@ module.exports = function upload() {
return manifestor.build(externalFiles);
})
.then(function(files) {
return sendToGoogle(files, fileId);
return sendToGoogle(files, fileId, options.teamdrive);
})
.then(function() {
console.log('The latest files were successfully uploaded to your Apps Script project.'.green);
Expand All @@ -31,15 +32,14 @@ module.exports = function upload() {
});
};

function sendToGoogle(files, id) {
function sendToGoogle(files, id, supportsTeamDrives) {
if (!files.length) {
console.log('No Files to upload.'.red);
throw 'manifest file length is 0';
}

return authenticate()
.then(function(auth) {
var drive = google.drive({ version: 'v2', auth: auth });
var options = {
fileId: id,
media: {
Expand All @@ -48,6 +48,12 @@ function sendToGoogle(files, id) {
}
};

if (supportsTeamDrives) {
console.log('teamdrive=true')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about editing the message that shows up when uploading (something like "Pushing back up to Google Drive (target project is inside a Team Drive)..."?

options.supportsTeamDrives = true;
}

var drive = google.drive({ version: 'v2', auth: auth });
return Promise.promisify(drive.files.update)(options)
.catch(function(err) {
console.log('An error occured while running upload command: '.red + err.message);
Expand Down