mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Move admin remove terms and condition logic to enterprise controller
This commit is contained in:
@@ -13,7 +13,9 @@ module Admin
|
||||
prepend_before_action :override_owner, only: :create
|
||||
prepend_before_action :override_sells, only: :create
|
||||
|
||||
before_action :load_countries, except: [:index, :register, :check_permalink, :remove_logo]
|
||||
before_action :load_countries,
|
||||
except: [:index, :register, :check_permalink, :remove_logo,
|
||||
:remove_terms_and_conditions]
|
||||
before_action :load_methods_and_fees, only: [:edit, :update]
|
||||
before_action :load_groups, only: [:new, :edit, :update, :create]
|
||||
before_action :load_taxons, only: [:new, :edit, :update, :create]
|
||||
@@ -151,7 +153,7 @@ module Admin
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
flash[:success] = I18n.t("admin.enterprises.form.white_label.remove_logo_success")
|
||||
redirect_to edit_admin_enterprise_path
|
||||
redirect_to main_app.edit_admin_enterprise_path(@enterprise)
|
||||
end
|
||||
format.turbo_stream do
|
||||
flash.now[:success] = I18n.t("admin.enterprises.form.white_label.remove_logo_success")
|
||||
@@ -169,6 +171,13 @@ module Admin
|
||||
end
|
||||
end
|
||||
|
||||
def remove_terms_and_conditions
|
||||
authorize! :remove_terms_and_conditions, @object
|
||||
|
||||
@object.terms_and_conditions.purge_later
|
||||
redirect_to edit_admin_enterprise_path(@object)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def delete_custom_tab
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
# frozen_string_literal: false
|
||||
|
||||
class EnterpriseEditReflex < ApplicationReflex
|
||||
def remove_terms_and_conditions
|
||||
@enterprise = Enterprise.find(element.dataset['enterprise-id'])
|
||||
throw :forbidden unless can?(:remove_terms_and_conditions, @enterprise)
|
||||
|
||||
@enterprise.terms_and_conditions.purge_later
|
||||
end
|
||||
end
|
||||
@@ -40,8 +40,7 @@
|
||||
- if @enterprise.terms_and_conditions.attached?
|
||||
= link_to "#{@enterprise.terms_and_conditions.blob.filename} #{ t('.uploaded_on') } #{@enterprise.terms_and_conditions.blob.created_at}", url_for(@enterprise.terms_and_conditions), target: '_blank'
|
||||
%div
|
||||
%a.icon-trash{ href: '#', data: { action: 'click->terms-and-conditions#remove', "terms-and-conditions-message-value": t('js.admin.enterprises.form.images.immediate_terms_and_conditions_removal_warning'), 'enterprise-id': @enterprise.id}}
|
||||
= t('.remove_terms_and_conditions')
|
||||
= link_to t('.remove_terms_and_conditions'), remove_terms_and_conditions_admin_enterprise_path(@enterprise), class: 'icon-trash', data: { method: :delete, confirm: t('js.admin.enterprises.form.images.immediate_terms_and_conditions_removal_warning') }
|
||||
.pad-top
|
||||
%div
|
||||
.button.small{ data: { controller: 'help-modal-link', action: 'click->help-modal-link#open', "help-modal-link-target-value": "terms_and_conditions_warning_modal" } }
|
||||
|
||||
@@ -13,17 +13,6 @@ export default class extends ApplicationController {
|
||||
});
|
||||
}
|
||||
|
||||
remove(event) {
|
||||
let confirmation = confirm(this.messageValue);
|
||||
if (confirmation) {
|
||||
location.hash = "";
|
||||
this.stimulate(
|
||||
"EnterpriseEdit#remove_terms_and_conditions",
|
||||
event.target
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
add() {
|
||||
this.fileinputTarget.click();
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ Openfoodnetwork::Application.routes.draw do
|
||||
get :welcome
|
||||
patch :register
|
||||
patch :remove_logo
|
||||
delete :remove_terms_and_conditions
|
||||
end
|
||||
|
||||
resources :connected_apps, only: [:create, :destroy]
|
||||
|
||||
@@ -55,6 +55,33 @@ RSpec.describe "Uploading Terms and Conditions PDF" do
|
||||
go_to_business_details
|
||||
expect(page).to have_selector "a[href*='Terms-of-ServiceUK.pdf']"
|
||||
end
|
||||
|
||||
it "uploading terms and conditions" do
|
||||
go_to_business_details
|
||||
|
||||
# Add PDF
|
||||
attach_file "enterprise[terms_and_conditions]", original_terms, make_visible: true
|
||||
|
||||
time = Time.zone.local(2002, 4, 13, 0, 0, 0)
|
||||
Timecop.freeze(run_time = time) do
|
||||
click_button "Update"
|
||||
expect(distributor.reload.terms_and_conditions_blob.created_at).to eq run_time
|
||||
end
|
||||
expect(page).
|
||||
to have_content "Enterprise \"#{distributor.name}\" has been successfully updated!"
|
||||
|
||||
go_to_business_details
|
||||
expect(page).to have_selector "a[href*='Terms-of-service.pdf'][target=\"_blank\"]"
|
||||
expect(page).to have_content 'Remove File'
|
||||
|
||||
# Remove PDF
|
||||
accept_confirm "The Terms and Conditions file will be removed immediately after you confirm." do
|
||||
click_on "Remove File"
|
||||
end
|
||||
go_to_business_details
|
||||
expect(page).not_to have_selector "a[href*='Terms-of-service.pdf'][target=\"_blank\"]"
|
||||
expect(page).not_to have_content 'Remove File'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user