From c31416c536495229286069dcb807bb97fc1da593 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 8 Aug 2024 15:47:08 +1000 Subject: [PATCH] Separate showing and rendering report --- app/controllers/admin/reports_controller.rb | 21 +++++++++---------- app/models/spree/ability.rb | 4 ++-- config/routes/admin.rb | 3 ++- .../admin/reports_controller_spec.rb | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rb index 699c326f3f..7027ea4746 100644 --- a/app/controllers/admin/reports_controller.rb +++ b/app/controllers/admin/reports_controller.rb @@ -6,7 +6,7 @@ module Admin include ReportsActions helper ReportsHelper - before_action :authorize_report, only: [:show] + before_action :authorize_report, only: [:show, :create] # Define model class for Can? permissions def model_class @@ -20,14 +20,17 @@ module Admin end def show - @report = report_class.new(spree_current_user, params, render: render_data?) + @report = report_class.new(spree_current_user, params, render: false) @rendering_options = rendering_options # also stores user preferences - if render_data? - render_in_background - else - show_report - end + show_report + end + + def create + @report = report_class.new(spree_current_user, params, render: true) + @rendering_options = rendering_options # also stores user preferences + + render_in_background end private @@ -54,10 +57,6 @@ module Admin @variant_serialized = Api::Admin::VariantSerializer.new(variant) end - def render_data? - request.post? - end - def render_in_background cable_ready[ScopedChannel.for_id(params[:uuid])] .inner_html( diff --git a/app/models/spree/ability.rb b/app/models/spree/ability.rb index 0de4b5abbd..e7c050aa24 100644 --- a/app/models/spree/ability.rb +++ b/app/models/spree/ability.rb @@ -244,7 +244,7 @@ module Spree # Reports page can [:admin, :index, :show], ::Admin::ReportsController - can [:admin, :show, :customers, :orders_and_distributors, :group_buys, :payments, + can [:admin, :show, :create, :customers, :orders_and_distributors, :group_buys, :payments, :orders_and_fulfillment, :products_and_inventory, :order_cycle_management, :packing, :enterprise_fee_summary, :bulk_coop], :report end @@ -324,7 +324,7 @@ module Spree end # Reports page - can [:admin, :index, :show], ::Admin::ReportsController + can [:admin, :index, :show, :create], ::Admin::ReportsController can [:admin, :customers, :group_buys, :sales_tax, :payments, :orders_and_distributors, :orders_and_fulfillment, :products_and_inventory, :order_cycle_management, :xero_invoices, :enterprise_fee_summary, :bulk_coop], :report diff --git a/config/routes/admin.rb b/config/routes/admin.rb index fe91db5633..2f6fa79d8b 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -135,6 +135,7 @@ Openfoodnetwork::Application.routes.draw do end get '/reports', to: 'reports#index', as: :reports - match '/reports/:report_type(/:report_subtype)', to: 'reports#show', via: [:get, :post], as: :report + match '/reports/:report_type(/:report_subtype)', to: 'reports#show', via: :get, as: :report + match '/reports/:report_type(/:report_subtype)', to: 'reports#create', via: :post end end diff --git a/spec/controllers/admin/reports_controller_spec.rb b/spec/controllers/admin/reports_controller_spec.rb index 4501adf433..0def47097f 100644 --- a/spec/controllers/admin/reports_controller_spec.rb +++ b/spec/controllers/admin/reports_controller_spec.rb @@ -310,7 +310,7 @@ RSpec.describe Admin::ReportsController, type: :controller do end it "triggers the delivery report" do - spree_post :show, { + spree_post :create, { q: { completed_at_lt: 1.day.ago }, shipping_method_in: ["123"], # We just need to search for shipping methods report_type: :order_cycle_management,