Separate showing and rendering report

This commit is contained in:
Maikel Linke
2024-08-08 15:47:08 +10:00
parent 917079931e
commit c31416c536
4 changed files with 15 additions and 15 deletions

View File

@@ -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(

View File

@@ -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

View File

@@ -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

View File

@@ -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,