-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1327 from DFE-Digital/upload-documents-to-gdrive-…
…rebased Upload documents to google drive (UD3, UD6.1, UD6.2)
- Loading branch information
Showing
31 changed files
with
525 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,43 @@ | ||
.upload-group .govuk-button { | ||
#file-upload { | ||
margin-bottom: 0; | ||
} | ||
|
||
.hidden-input { | ||
display: none; | ||
} | ||
|
||
.upload-progress { | ||
display: inline-block; | ||
position: relative; | ||
width: 18px; | ||
height: 18px; | ||
} | ||
.upload-progress div { | ||
box-sizing: border-box; | ||
display: block; | ||
position: absolute; | ||
width: 18px; | ||
height: 18px; | ||
margin: 0px; | ||
border: 3px solid green; | ||
border-radius: 50%; | ||
animation: spin 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite; | ||
border-color: green transparent transparent transparent; | ||
} | ||
.upload-progress div:nth-child(1) { | ||
animation-delay: -0.45s; | ||
} | ||
.upload-progress div:nth-child(2) { | ||
animation-delay: -0.3s; | ||
} | ||
.upload-progress div:nth-child(3) { | ||
animation-delay: -0.15s; | ||
} | ||
@keyframes spin { | ||
0% { | ||
transform: rotate(0deg); | ||
} | ||
100% { | ||
transform: rotate(360deg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Document < ApplicationRecord | ||
belongs_to :vacancy | ||
validates :name, :size, :content_type, :download_url, :google_drive_id, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require 'google/apis/drive_v3' | ||
|
||
class DocumentUpload | ||
class MissingUploadPath < StandardError; end | ||
attr_accessor :drive_service, :upload_path, :name, :uploaded, :safe_download | ||
|
||
def initialize(opts = {}) | ||
raise MissingUploadPath if opts[:upload_path].nil? | ||
self.upload_path = opts[:upload_path] | ||
self.name = opts[:name] | ||
self.drive_service = Google::Apis::DriveV3::DriveService.new | ||
end | ||
|
||
def upload | ||
upload_hiring_staff_document | ||
set_public_permission_on_document | ||
google_drive_virus_check | ||
end | ||
|
||
def upload_hiring_staff_document | ||
self.uploaded = drive_service.create_file( | ||
{ alt: 'media', name: name }, | ||
fields: 'id, web_view_link, web_content_link, mime_type', | ||
upload_source: upload_path | ||
) | ||
end | ||
|
||
def set_public_permission_on_document | ||
drive_service.create_permission( | ||
uploaded.id, | ||
Google::Apis::DriveV3::Permission.new(type: 'anyone', role: 'reader') | ||
) | ||
end | ||
|
||
def google_drive_virus_check | ||
download_path = "#{uploaded.id}" | ||
begin | ||
drive_service.get_file( | ||
uploaded.id, | ||
acknowledge_abuse: false, | ||
download_dest: download_path | ||
) | ||
rescue Google::Apis::ClientError | ||
drive_service.delete_file(uploaded.id) | ||
self.safe_download = false | ||
else | ||
self.safe_download = true | ||
ensure | ||
File.delete(download_path) if File.exist?(download_path) | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.