Skip to content

Commit 22abeec

Browse files
committed
Support a notion of an associated assignment.
Resolves the shortcoming of 17aec5c. When a user navigates to a `#template=GDRIVE` URL, we search their gdrive for a file with the property `assignment` equal to `GDRIVE`. If such a file exists, we load it. Otherwise, the file named `template.arr` is selected from the folder of id `GDRIVE`. We copy it to the user's gdrive, set the property `assignment` of the copied file equal to `GDRIVE`, and share the copied file with a course staff google account.
1 parent 17aec5c commit 22abeec

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

src/web/js/google-apis/drive.js

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ window.createProgramCollectionAPI = function createProgramCollectionAPI(collecti
66
var drive;
77
var SCOPE = "https://www.googleapis.com/auth/drive.file "
88
+ "https://spreadsheets.google.com/feeds "
9+
+ "https://www.googleapis.com/auth/drive.appdata "
910
+ "https://www.googleapis.com/auth/drive.install";
10-
var FOLDER_MIME = "application/vnd.google-apps.folder";
11+
var FOLDER_MIME = "application/vnd.google-apps.folder";
1112
var BACKREF_KEY = "originalProgram";
1213
var PUBLIC_LINK = "pubLink";
1314

@@ -218,9 +219,43 @@ window.createProgramCollectionAPI = function createProgramCollectionAPI(collecti
218219
return ret.promise;
219220
}
220221

221-
var fromDrive = ls("'"+ id + "' in parents and title = 'template.arr'").then(function(results) {
222-
return makeSharedFile(results[0], true);
223-
});
222+
var fromDrive = ls("properties has { key='assignment' and value='" + id + "' and visibility='PRIVATE' }")
223+
.then(function(results) {
224+
if (results[0]) {
225+
// load the student's work
226+
return drive.files.get({"fileId": results[0].id});
227+
} else {
228+
// copy the template
229+
return ls("'"+ id + "' in parents and title = 'template.arr'").then(function(results) {
230+
let template = results[0];
231+
return drive.files.copy({
232+
"fileId": template.id,
233+
"keepRevisionForever": "true",
234+
}).then(function(file) {
235+
return drive.properties.insert({
236+
"fileId": file.id,
237+
"resource": {
238+
"key": "assignment",
239+
"value": id
240+
}
241+
}).then(function(_) {
242+
return drive.permissions.insert({
243+
"fileId": file.id,
244+
"emailMessage": "TEST MESSAGE",
245+
"sendNotificationEmails": "true",
246+
"resource": {
247+
"role": "reader",
248+
"type": "user",
249+
"value": "[email protected]"
250+
}
251+
});
252+
}).then(function(_) {
253+
return file;
254+
});
255+
});
256+
});
257+
}
258+
}).then(fileBuilder);
224259

225260
var fromServer = fromDrive.fail(function() {
226261
return Q($.get("/shared-file", {

0 commit comments

Comments
 (0)