mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Allow user to upload terms and conditions PDF file to an enterprise
This commit is contained in:
@@ -74,10 +74,16 @@ class Enterprise < ActiveRecord::Base
|
||||
},
|
||||
url: '/images/enterprises/promo_images/:id/:style/:basename.:extension',
|
||||
path: 'public/images/enterprises/promo_images/:id/:style/:basename.:extension'
|
||||
|
||||
validates_attachment_content_type :logo, content_type: %r{\Aimage/.*\Z}
|
||||
validates_attachment_content_type :promo_image, content_type: %r{\Aimage/.*\Z}
|
||||
|
||||
has_attached_file :terms_and_conditions,
|
||||
url: '/files/enterprises/terms_and_conditions/:id/:basename.:extension',
|
||||
path: 'public/files/enterprises/terms_and_conditions/:id/:basename.:extension'
|
||||
validates_attachment_content_type :terms_and_conditions,
|
||||
content_type: "application/pdf",
|
||||
message: I18n.t(:enterprise_terms_and_conditions_type_error)
|
||||
|
||||
include Spree::Core::S3Support
|
||||
supports_s3 :logo
|
||||
supports_s3 :promo_image
|
||||
|
||||
@@ -6,7 +6,7 @@ class Api::Admin::EnterpriseSerializer < ActiveModel::Serializer
|
||||
:preferred_product_selection_from_inventory_only,
|
||||
:preferred_show_customer_names_to_suppliers, :owner, :contact, :users, :tag_groups,
|
||||
:default_tag_group, :require_login, :allow_guest_orders, :allow_order_changes,
|
||||
:logo, :promo_image
|
||||
:logo, :promo_image, :terms_and_conditions, :terms_and_conditions_file_name
|
||||
|
||||
has_one :owner, serializer: Api::Admin::UserSerializer
|
||||
has_many :users, serializer: Api::Admin::UserSerializer
|
||||
|
||||
@@ -25,7 +25,7 @@ module PermittedAttributes
|
||||
[
|
||||
:id, :name, :visible, :permalink, :owner_id, :contact_name, :email_address, :phone,
|
||||
:is_primary_producer, :sells, :website, :facebook, :instagram, :linkedin, :twitter,
|
||||
:description, :long_description, :logo, :promo_image,
|
||||
:description, :long_description, :logo, :promo_image, :terms_and_conditions,
|
||||
:allow_guest_orders, :allow_order_changes, :require_login, :enable_subscriptions,
|
||||
:abn, :acn, :charges_sales_tax, :display_invoice_logo, :invoice_text,
|
||||
:preferred_product_selection_from_inventory_only, :preferred_shopfront_message,
|
||||
|
||||
@@ -31,3 +31,13 @@
|
||||
= f.label :invoice_text, t('.invoice_text')
|
||||
.omega.eight.columns
|
||||
= f.text_area :invoice_text, style: "width: 100%; height: 100px;"
|
||||
|
||||
.row
|
||||
.alpha.three.columns
|
||||
= f.label :terms_and_conditions, t('.terms_and_conditions')
|
||||
|
||||
.omega.eight.columns
|
||||
%a{ href: '{{ Enterprise.terms_and_conditions }}', ng: { if: 'Enterprise.terms_and_conditions' } }
|
||||
= '{{ Enterprise.terms_and_conditions_file_name }}'
|
||||
%p
|
||||
= f.file_field :terms_and_conditions
|
||||
|
||||
@@ -690,6 +690,7 @@ en:
|
||||
acn_placeholder: eg. 123 456 789
|
||||
display_invoice_logo: Display logo in invoices
|
||||
invoice_text: Add customized text at the end of invoices
|
||||
terms_and_conditions: "Terms and Conditions"
|
||||
contact:
|
||||
name: Name
|
||||
name_placeholder: eg. Gustav Plum
|
||||
@@ -2433,6 +2434,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
enterprise_name_error: "has already been taken. If this is your enterprise and you would like to claim ownership, or if you would like to trade with this enterprise please contact the current manager of this profile at %{email}."
|
||||
enterprise_owner_error: "^%{email} is not permitted to own any more enterprises (limit is %{enterprise_limit})."
|
||||
enterprise_role_uniqueness_error: "^That role is already present."
|
||||
enterprise_terms_and_conditions_type_error: "Only PDFs are allowed"
|
||||
inventory_item_visibility_error: must be true or false
|
||||
product_importer_file_error: "error: no file uploaded"
|
||||
product_importer_spreadsheet_error: "could not process file: invalid filetype"
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddTermsAndConditionsToEnterprises < ActiveRecord::Migration
|
||||
def change
|
||||
add_attachment :enterprises, :terms_and_conditions
|
||||
end
|
||||
end
|
||||
32
db/schema.rb
32
db/schema.rb
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20200721135726) do
|
||||
ActiveRecord::Schema.define(version: 20200817150002) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -190,8 +190,8 @@ ActiveRecord::Schema.define(version: 20200721135726) do
|
||||
t.integer "address_id"
|
||||
t.text "pickup_times"
|
||||
t.string "next_collection_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.text "distributor_info"
|
||||
t.string "logo_file_name"
|
||||
t.string "logo_content_type"
|
||||
@@ -201,22 +201,26 @@ ActiveRecord::Schema.define(version: 20200721135726) do
|
||||
t.string "promo_image_content_type"
|
||||
t.integer "promo_image_file_size"
|
||||
t.datetime "promo_image_updated_at"
|
||||
t.boolean "visible", default: true
|
||||
t.boolean "visible", default: true
|
||||
t.string "facebook"
|
||||
t.string "instagram"
|
||||
t.string "linkedin"
|
||||
t.integer "owner_id", null: false
|
||||
t.string "sells", default: "none", null: false
|
||||
t.boolean "producer_profile_only", default: false
|
||||
t.string "permalink", null: false
|
||||
t.boolean "charges_sales_tax", default: false, null: false
|
||||
t.integer "owner_id", null: false
|
||||
t.string "sells", default: "none", null: false
|
||||
t.boolean "producer_profile_only", default: false
|
||||
t.string "permalink", null: false
|
||||
t.boolean "charges_sales_tax", default: false, null: false
|
||||
t.string "email_address"
|
||||
t.boolean "require_login", default: false, null: false
|
||||
t.boolean "allow_guest_orders", default: true, null: false
|
||||
t.boolean "require_login", default: false, null: false
|
||||
t.boolean "allow_guest_orders", default: true, null: false
|
||||
t.text "invoice_text"
|
||||
t.boolean "display_invoice_logo", default: false
|
||||
t.boolean "allow_order_changes", default: false, null: false
|
||||
t.boolean "enable_subscriptions", default: false, null: false
|
||||
t.boolean "display_invoice_logo", default: false
|
||||
t.boolean "allow_order_changes", default: false, null: false
|
||||
t.boolean "enable_subscriptions", default: false, null: false
|
||||
t.string "terms_and_conditions_file_name"
|
||||
t.string "terms_and_conditions_content_type"
|
||||
t.integer "terms_and_conditions_file_size"
|
||||
t.datetime "terms_and_conditions_updated_at"
|
||||
end
|
||||
|
||||
add_index "enterprises", ["address_id"], name: "index_enterprises_on_address_id", using: :btree
|
||||
|
||||
@@ -15,7 +15,7 @@ feature "Managing enterprise images" do
|
||||
visit edit_admin_enterprise_path(distributor)
|
||||
end
|
||||
|
||||
describe "images for an enterprise", js: true do
|
||||
describe "images for an enterprise" do
|
||||
def go_to_images
|
||||
within(".side_menu") do
|
||||
click_link "Images"
|
||||
|
||||
61
spec/features/admin/enterprises/terms_and_conditions_spec.rb
Normal file
61
spec/features/admin/enterprises/terms_and_conditions_spec.rb
Normal file
@@ -0,0 +1,61 @@
|
||||
require "spec_helper"
|
||||
|
||||
feature "Uploading Terms and Conditions PDF" do
|
||||
include WebHelper
|
||||
include AuthenticationHelper
|
||||
|
||||
context "as an Enterprise user", js: true do
|
||||
let(:enterprise_user) { create(:user, enterprise_limit: 1) }
|
||||
let(:distributor) { create(:distributor_enterprise, name: "First Distributor") }
|
||||
|
||||
before do
|
||||
enterprise_user.enterprise_roles.build(enterprise: distributor).save!
|
||||
|
||||
login_as enterprise_user
|
||||
visit edit_admin_enterprise_path(distributor)
|
||||
end
|
||||
|
||||
describe "images for an enterprise" do
|
||||
def go_to_business_details
|
||||
within(".side_menu") do
|
||||
click_link "Business Details"
|
||||
end
|
||||
end
|
||||
|
||||
let(:white_pdf_file_name) { Rails.root.join("app", "assets", "images", "logo-white.pdf") }
|
||||
let(:black_pdf_file_name) { Rails.root.join("app", "assets", "images", "logo-black.pdf") }
|
||||
|
||||
before do
|
||||
# Create fake PDFs from PNG images
|
||||
FileUtils.cp(Rails.root.join("app", "assets", "images", "logo-white.png"), white_pdf_file_name)
|
||||
FileUtils.cp(Rails.root.join("app", "assets", "images", "logo-black.png"), black_pdf_file_name)
|
||||
|
||||
go_to_business_details
|
||||
end
|
||||
|
||||
scenario "uploading terms and conditions" do
|
||||
# Add PDF
|
||||
attach_file "enterprise[terms_and_conditions]", white_pdf_file_name
|
||||
click_button "Update"
|
||||
expect(page).to have_content("Enterprise \"#{distributor.name}\" has been successfully updated!")
|
||||
|
||||
go_to_business_details
|
||||
expect(page).to have_selector("a[href*='logo-white.pdf']")
|
||||
|
||||
# Replace PDF
|
||||
attach_file "enterprise[terms_and_conditions]", black_pdf_file_name
|
||||
click_button "Update"
|
||||
expect(page).to have_content("Enterprise \"#{distributor.name}\" has been successfully updated!")
|
||||
|
||||
go_to_business_details
|
||||
expect(page).to have_selector("a[href*='logo-black.pdf']")
|
||||
end
|
||||
|
||||
after do
|
||||
# Delete fake PDFs
|
||||
FileUtils.rm_f(white_pdf_file_name)
|
||||
FileUtils.rm_f(black_pdf_file_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user