From abe76ccf0f595cee6d76db17d09d800321f20bc5 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 22 Apr 2021 13:41:42 +1000 Subject: [PATCH] Add upload of Terms of Service files Admins can upload files and view the most recent (current) one. --- .../terms_of_service_files_controller.rb | 19 +++++++++++++++++++ .../terms_of_service_files/show.html.haml | 10 +++++++++- config/locales/en.yml | 2 ++ .../terms_of_service_files_spec.rb | 8 ++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/terms_of_service_files_controller.rb b/app/controllers/admin/terms_of_service_files_controller.rb index 1b649efabf..f7b2e728ab 100644 --- a/app/controllers/admin/terms_of_service_files_controller.rb +++ b/app/controllers/admin/terms_of_service_files_controller.rb @@ -3,6 +3,25 @@ module Admin class TermsOfServiceFilesController < Spree::Admin::BaseController def show + @current_file = TermsOfServiceFile.current + @new_file = TermsOfServiceFile.new + end + + def create + TermsOfServiceFile.create!(file_params) + redirect_to main_app.admin_terms_of_service_files_path + end + + private + + # Needed by Spree::Admin::BaseController#authorize_admin or it + # tries to find a Spree model. + def model_class + TermsOfServiceFile + end + + def file_params + params.require(:terms_of_service_file).permit(:attachment) end end end diff --git a/app/views/admin/terms_of_service_files/show.html.haml b/app/views/admin/terms_of_service_files/show.html.haml index db5da9ad9f..199abc49a1 100644 --- a/app/views/admin/terms_of_service_files/show.html.haml +++ b/app/views/admin/terms_of_service_files/show.html.haml @@ -1,4 +1,12 @@ - content_for :page_title do = t(".title") -= t(".no_files") +- if @current_file + = link_to t(".terms_of_service"), @current_file.attachment.url +- else + = t(".no_files") + += form_for [main_app, :admin, @new_file] do |f| + = f.label :attachment + = f.file_field :attachment + = f.submit diff --git a/config/locales/en.yml b/config/locales/en.yml index 6e316f5e65..f0a2a28379 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -450,7 +450,9 @@ en: terms_of_service_files: show: + title: "Terms of Service files" no_files: "No terms of services have been uploaded yet." + terms_of_service: "Terms of Service" number_localization: number_localization_settings: "Number Localization Settings" enable_localized_number: "Use the international thousand/decimal separator logic" diff --git a/spec/features/admin/configuration/terms_of_service_files_spec.rb b/spec/features/admin/configuration/terms_of_service_files_spec.rb index c40424d737..441fcfb802 100644 --- a/spec/features/admin/configuration/terms_of_service_files_spec.rb +++ b/spec/features/admin/configuration/terms_of_service_files_spec.rb @@ -13,5 +13,13 @@ describe "Terms of Service files" do click_link "Terms of Service" expect(page).to have_content "No terms of services have been uploaded yet." end + + it "can be uploaded" do + visit admin_terms_of_service_files_path + attach_file "Attachment", Rails.root.join("public/Terms-of-service.pdf") + click_button "Create Terms of service file" + + expect(page).to have_link "Terms of Service" + end end end