Per review, move logic to display ToS banner to a helper

It easier to understand when we can see the logic to display the banner
in the view.
This commit is contained in:
Gaetan Craig-Riou
2023-11-23 14:56:13 +11:00
committed by Konrad
parent d0ba881aa2
commit aaa8f3f572
4 changed files with 31 additions and 29 deletions

View File

@@ -9,6 +9,7 @@ module Spree
helper 'admin/injection'
helper 'admin/orders'
helper 'admin/enterprises'
helper 'admin/terms_of_service'
helper 'enterprise_fees'
helper 'angular_form'
@@ -19,7 +20,6 @@ module Spree
before_action :authorize_admin
before_action :set_locale
before_action :warn_invalid_order_cycles, if: :html_request?
before_action :check_updated_tos_accepted, if: :html_request?
# Warn the user when they have an active order cycle with hubs that are not ready
# for checkout (ie. does not have valid shipping and payment methods).
@@ -111,26 +111,6 @@ module Spree
name = controller_name.classify
"::Api::Admin::#{prefix}#{name}Serializer".constantize
end
def check_updated_tos_accepted
@terms_of_service_banner = false
return unless spree_user_signed_in?
return if Spree::Config.enterprises_require_tos == false
return if accepted_tos?
@terms_of_service_banner = true
end
def accepted_tos?
file_uploaded_at = TermsOfServiceFile.updated_at
current_spree_user.terms_of_service_accepted_at.present? &&
current_spree_user.terms_of_service_accepted_at > file_uploaded_at &&
current_spree_user.terms_of_service_accepted_at < DateTime.now
end
end
end
end

View File

@@ -0,0 +1,23 @@
# frozen_string_literal: true
module Admin
module TermsOfServiceHelper
def tos_need_accepting?
return false unless spree_user_signed_in?
return false if Spree::Config.enterprises_require_tos == false
!accepted_tos?
end
private
def accepted_tos?
file_uploaded_at = TermsOfServiceFile.updated_at
current_spree_user.terms_of_service_accepted_at.present? &&
current_spree_user.terms_of_service_accepted_at > file_uploaded_at &&
current_spree_user.terms_of_service_accepted_at < DateTime.now
end
end
end

View File

@@ -1,9 +1,8 @@
.banner-container#banner-container
- if @terms_of_service_banner == true
.terms-of-service-banner
.column-left
%p= t("admin.terms_of_service_have_been_updated_html", tos_link: link_to(t("admin.terms_of_service"), TermsOfServiceFile.current_url, target: "_blank"))
.column-right
%button{ data: { reflex: "click->Enterprise::User#accept_terms_of_services", id: current_spree_user&.id } }
= t("admin.accept_terms_of_service")
.terms-of-service-banner
.column-left
%p= t("admin.terms_of_service_have_been_updated_html", tos_link: link_to(t("admin.terms_of_service"), TermsOfServiceFile.current_url, target: "_blank"))
.column-right
%button{ data: { reflex: "click->Enterprise::User#accept_terms_of_services", id: current_spree_user&.id } }
= t("admin.accept_terms_of_service")

View File

@@ -59,7 +59,7 @@
%span= yield :sidebar_title
= yield :sidebar
= render partial: "admin/terms_of_service_banner"
= render "admin/terms_of_service_banner" if tos_need_accepting?
%script
= raw "Spree.api_key = \"#{spree_current_user.try(:spree_api_key).to_s}\";"