-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dm-4338 persistent file links pagebuilder (#742)
* remove old js handling async fetching of presigned url for file download links * remove `after_sign_in` method override * add shared `unauthorized_response` method to `ApplicationController` * edit `PracticeResourcesController` remove `download_and_redirect` action remove `unauthorized_response` helper method, now lives in `ApplicationController` remove set_download_session now returns unauthorized response when trying to access va-user-only resource * remove `download_and_redirect` view * add `PageResourceController` handles requests for downloadable resources found on page builder pages * edit routs removes `practice_resources` route adds route for `PageResourcesController#download` * edit file links on pagebuilder page views uses new path helper pointing to `PageResourcesController#download` * update / add factory_bot factories * update / add specs for static resource links
- Loading branch information
1 parent
f28dc1f
commit 5f363d2
Showing
15 changed files
with
185 additions
and
197 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
class PageResourcesController < ApplicationController | ||
before_action :authenticate_user!, except: [:download] | ||
before_action :set_page_resource | ||
|
||
def download | ||
if @page.published | ||
handle_published_page | ||
elsif current_user | ||
handle_user_with_unpublished_practice | ||
else | ||
unauthorized_response | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_page_resource | ||
@page = Page.find_by(id: resource_params[:page_id]) | ||
|
||
if @page | ||
@page_resource = @page.page_components.find_by(component_id: resource_params[:id]).component | ||
else | ||
render plain: "Page not found", status: :not_found and return | ||
end | ||
end | ||
|
||
def resource_params | ||
params.permit(:page_id, :id) | ||
end | ||
|
||
def handle_published_page | ||
if @page.is_public || current_user | ||
redirect_to @page_resource.attachment_s3_presigned_url | ||
else | ||
unauthorized_response | ||
end | ||
end | ||
|
||
def handle_user_with_unpublished_practice | ||
if current_user&.has_role?(:admin) | ||
redirect_to @page_resource.attachment_s3_presigned_url | ||
else | ||
unauthorized_response | ||
end | ||
end | ||
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
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
38 changes: 0 additions & 38 deletions
38
app/views/practice_resources/download_and_redirect.html.erb
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
FactoryBot.define do | ||
factory :page_downloadable_file_component do | ||
display_name { "Sample File" } | ||
description { "This is a sample file for download." } | ||
|
||
transient do | ||
file_type { "pdf" } | ||
end | ||
|
||
attachment_file_name do | ||
if file_type == "docx" | ||
"dummy.docx" | ||
else | ||
"dummy.pdf" | ||
end | ||
end | ||
|
||
attachment_content_type do | ||
if file_type == "pdf" | ||
"application/pdf" | ||
elsif file_type == "docx" | ||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document" | ||
else | ||
"application/pdf" | ||
end | ||
end | ||
|
||
attachment_file_size { File.size(Rails.root.join('spec', 'assets', attachment_file_name)) } | ||
attachment_updated_at { Time.current } | ||
|
||
after(:build) do |page_downloadable_file_component| | ||
file_name = page_downloadable_file_component.attachment_file_name | ||
page_downloadable_file_component.attachment = File.new(Rails.root.join('spec', 'assets', file_name)) | ||
end | ||
end | ||
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
Oops, something went wrong.