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

Move uploaded references to Google Drive #123

Merged
merged 4 commits into from
Apr 4, 2019

Conversation

ollietreend
Copy link
Contributor

Closes #117

This PR adds a Cloud Function which is triggered when reference files are uploaded to the Cloud Storage bucket.

Files uploaded to the default Cloud Storage bucket, assuming a file path of: references/{referenceId}/{fileName}, are processed by the Cloud Function processReferenceUpload.

Steps taken when a new file is uploaded

  1. Find the associated reference in Firestore, given {referenceId} from the file upload path
  2. If the reference is in state 'pending', upload the file to Google Drive. It'll be uploaded to the Team Drive denoted by references.team_drive_id Functions config variable, into the directory structure {vacancyTitle}/{applicantName}/{assessorName} ({assessorType}).{ext}
  3. If the reference has already been marked as 'received', and this is therefore a duplicate upload, ignore the file and emit a log message.
  4. Delete the file from Cloud Storage

Cloud Functions configuration

references.team_drive_id

Files are moved into the Google Team Drive with this ID.

This variable has already been set in production project.

When files are uploaded to the Storage bucket path `independent-assessments/*`, a Cloud Function will move them into Google Drive.
For now, the runtime variables at `src/moveIndependentAssessmentToGoogleDrive.js:10` are hardcoded. Eventually these will be driven by metadata that comes with the upload.
This commit refactors the functionality initially spiked in 6079a59.

Files uploaded to the default Cloud Storage bucket, assuming a file path of: `references/{referenceId}/{fileName}`, are processed by the Cloud Function `processReferenceUpload`.

The following steps are taken:

- Find the associated reference in Firestore, given `{referenceId}` from the file upload path
- If the reference is in state 'pending', upload the file to Google Drive. It'll be uploaded to the Team Drive denoted by `teamDriveId` (currently hardcoded in `functions/src/references/moveToGoogleDrive.js`), into the directory structure `{vacancyTitle}/{applicantName}/{assessorName} ({assessorType}).{ext}`
- If the reference has already been marked as 'received', and this is therefore a duplicate upload, ignore the file and emit a log message.
- Delete the file from Cloud Storage
Replace the hardcoded `teamDriveId` variable in `functions/src/references/moveToGoogleDrive.js` with Cloud Functions config.

This is the variable used to determine which Google Team Drive to store received reference files in. Whilst this value doesn't need to be kept secret, it is configuration and so doesn't really belong in the codebase.
@ollietreend ollietreend requested a review from tatyree April 4, 2019 12:37
@ollietreend ollietreend force-pushed the 117-move-to-google-drive branch from 1719630 to 84a4317 Compare April 4, 2019 12:38
@ollietreend ollietreend force-pushed the 117-move-to-google-drive branch from 84a4317 to b77617e Compare April 4, 2019 12:40
Update the npm packages used by Cloud Functions. Additionally, fix a linting error which seems to have cropped up with the upgrade of `eslint`.
@ollietreend ollietreend force-pushed the 117-move-to-google-drive branch from b77617e to b67b737 Compare April 4, 2019 12:41
@ollietreend ollietreend merged commit 8666165 into master Apr 4, 2019
@ollietreend ollietreend deleted the 117-move-to-google-drive branch April 4, 2019 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants