Move User accept_terms_of_services action to admin user controller

This commit is contained in:
wandji20
2024-10-24 11:34:38 +01:00
parent 9ebbcfe138
commit a3c8ddb8bb
6 changed files with 26 additions and 33 deletions

View File

@@ -57,6 +57,15 @@ module Spree
end
end
def accept_terms_of_services
spree_current_user.update(terms_of_service_accepted_at: DateTime.now)
respond_to do |format|
format.html { redirect_back(fallback_location: spree.admin_dashboard_path) }
format.turbo_stream { render turbo_stream: turbo_stream.remove('banner-container') }
end
end
protected
def collection

View File

@@ -1,9 +0,0 @@
# frozen_string_literal: true
class UserReflex < ApplicationReflex
def accept_terms_of_services
current_user.update(terms_of_service_accepted_at: DateTime.now)
morph "#banner-container", ""
end
end

View File

@@ -3,6 +3,6 @@
.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->user#accept_terms_of_services" } }
= button_to admin_accept_terms_of_services_path, data: { turbo_method: :post }, form: { data: { turbo: true } } do
= t("admin.accept_terms_of_service")

View File

@@ -49,6 +49,7 @@ Spree::Core::Engine.routes.draw do
get '/search/customers' => 'search#customers', :as => :search_customers
resources :users
post 'accept_terms_of_services', to: 'users#accept_terms_of_services'
constraints FeatureToggleConstraint.new(:admin_style_v3, negate: true) do
# Show old bulk products screen

View File

@@ -38,4 +38,19 @@ RSpec.describe Spree::Admin::UsersController do
expect(response).to redirect_to('/unauthorized')
end
end
context '#accept_terms_of_services' do
before(:each) { controller_login_as_admin }
it "updates terms_of_service_accepted_at" do
expect {
spree_post :accept_terms_of_services, format: :turbo_stream
@admin_user.reload
}.to change{ @admin_user.terms_of_service_accepted_at }
end
it "removes banner from the page" do
spree_post :accept_terms_of_services, format: :turbo_stream
expect(response.body).not_to have_selector("#banner-container")
end
end
end

View File

@@ -1,23 +0,0 @@
# frozen_string_literal: true
require "reflex_helper"
RSpec.describe UserReflex, type: :reflex do
let(:current_user) { create(:user) }
let(:context) { { url: spree.admin_dashboard_url, connection: { current_user: } } }
describe "#accept_terms_of_services" do
subject(:reflex) { build_reflex(method_name: :accept_terms_of_services, **context) }
it "updates terms_of_service_accepted_at" do
expect {
reflex.run(:accept_terms_of_services)
current_user.reload
}.to change{ current_user.terms_of_service_accepted_at }
end
it "removes banner from the page" do
expect(reflex.run(:accept_terms_of_services)).to morph("#banner-container").with("")
end
end
end