Add upload of Terms of Service files

Admins can upload files and view the most recent (current) one.
This commit is contained in:
Maikel Linke
2021-04-22 13:41:42 +10:00
parent ed4f61acd7
commit abe76ccf0f
4 changed files with 38 additions and 1 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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