mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-06 02:51:34 +00:00
Separate enterprise fee summary action
Split the previous "index" action into "new" and "create" actions.
This commit is contained in:
@@ -10,14 +10,15 @@ module Spree
|
||||
module Admin
|
||||
module Reports
|
||||
class EnterpriseFeeSummariesController < BaseController
|
||||
before_filter :load_report_parameters, only: [:index]
|
||||
before_filter :load_permissions, only: [:index]
|
||||
before_filter :load_authorizer, only: [:index]
|
||||
before_filter :load_report_parameters
|
||||
before_filter :load_permissions
|
||||
|
||||
def index
|
||||
return render_report_form if params[:report].blank?
|
||||
def new; end
|
||||
|
||||
def create
|
||||
return respond_to_invalid_parameters unless @report_parameters.valid?
|
||||
|
||||
@authorizer = report_klass::Authorizer.new(@report_parameters, @permissions)
|
||||
@authorizer.authorize!
|
||||
@report = report_klass::ReportService.new(@permissions, @report_parameters,
|
||||
report_renderer_klass)
|
||||
@@ -39,7 +40,7 @@ module Spree
|
||||
end
|
||||
|
||||
def render_report_form
|
||||
render action: :index
|
||||
render action: :new
|
||||
end
|
||||
|
||||
def report_klass
|
||||
@@ -54,10 +55,6 @@ module Spree
|
||||
@permissions = report_klass::Permissions.new(spree_current_user)
|
||||
end
|
||||
|
||||
def load_authorizer
|
||||
@authorizer = report_klass::Authorizer.new(@report_parameters, @permissions)
|
||||
end
|
||||
|
||||
def render_report
|
||||
return render_html_report unless @report.renderer.independent_file?
|
||||
send_data(@report.render, filename: @report.filename)
|
||||
|
||||
@@ -270,7 +270,13 @@ Spree::Admin::ReportsController.class_eval do
|
||||
locals: { report_types: report_types[report] }
|
||||
).html_safe
|
||||
end
|
||||
{ name: name, description: description }
|
||||
{ name: name, url: url_for_report(report), description: description }
|
||||
end
|
||||
|
||||
def url_for_report(report)
|
||||
public_send("#{report}_admin_reports_url".to_sym)
|
||||
rescue NoMethodError
|
||||
url_for([:new, :admin, :reports, report.to_s.singularize])
|
||||
end
|
||||
|
||||
def timestamp
|
||||
|
||||
@@ -187,7 +187,7 @@ class AbilityDecorator
|
||||
can [:admin, :index, :customers, :orders_and_distributors, :group_buys, :bulk_coop, :payments,
|
||||
:orders_and_fulfillment, :products_and_inventory, :order_cycle_management, :packing,
|
||||
:enterprise_fee_summary], :report
|
||||
can [:admin, :index], :enterprise_fee_summary
|
||||
can [:admin, :new, :create], :enterprise_fee_summary
|
||||
end
|
||||
|
||||
def add_order_cycle_management_abilities(user)
|
||||
@@ -263,7 +263,7 @@ class AbilityDecorator
|
||||
can [:admin, :index, :customers, :group_buys, :bulk_coop, :sales_tax, :payments,
|
||||
:orders_and_distributors, :orders_and_fulfillment, :products_and_inventory,
|
||||
:order_cycle_management, :xero_invoices, :enterprise_fee_summary], :report
|
||||
can [:admin, :index], :enterprise_fee_summary
|
||||
can [:admin, :new, :create], :enterprise_fee_summary
|
||||
|
||||
can [:create], Customer
|
||||
can [:admin, :index, :update, :destroy, :show], Customer, enterprise_id: Enterprise.managed_by(user).pluck(:id)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
= form_for @report_parameters, as: :report, url: spree.enterprise_fee_summary_admin_reports_path, method: :get do |f|
|
||||
= form_for @report_parameters, as: :report, url: spree.admin_reports_enterprise_fee_summary_path, method: :post do |f|
|
||||
.row.date-range-filter
|
||||
.sixteen.columns.alpha
|
||||
= label_tag nil, t(".date_range")
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
= render "filters"
|
||||
@@ -12,7 +12,7 @@
|
||||
<tbody>
|
||||
<% @reports.each do |key, value| %>
|
||||
<tr data-hook="reports_row">
|
||||
<td><%= link_to value[:name], send("#{key}_admin_reports_url".to_sym) %></td>
|
||||
<td><%= link_to value[:name], value[:url] %></td>
|
||||
<td><%= value[:description] %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -25,13 +25,17 @@ Spree::Core::Engine.routes.prepend do
|
||||
match '/admin/reports/products_and_inventory' => 'admin/reports#products_and_inventory', :as => "products_and_inventory_admin_reports", :via => [:get, :post]
|
||||
match '/admin/reports/customers' => 'admin/reports#customers', :as => "customers_admin_reports", :via => [:get, :post]
|
||||
match '/admin/reports/xero_invoices' => 'admin/reports#xero_invoices', :as => "xero_invoices_admin_reports", :via => [:get, :post]
|
||||
get "/admin/reports/enterprise_fee_summary", to: "admin/reports/enterprise_fee_summaries#index", as: :enterprise_fee_summary_admin_reports
|
||||
match '/admin', :to => 'admin/overview#index', :as => :admin
|
||||
match '/admin/payment_methods/show_provider_preferences' => 'admin/payment_methods#show_provider_preferences', :via => :get
|
||||
put 'credit_cards/new_from_token', to: 'credit_cards#new_from_token'
|
||||
|
||||
resources :credit_cards
|
||||
namespace :admin do
|
||||
namespace :reports do
|
||||
resource :enterprise_fee_summary, only: [:new, :create]
|
||||
end
|
||||
end
|
||||
|
||||
resources :credit_cards
|
||||
|
||||
namespace :api, :defaults => { :format => 'json' } do
|
||||
resources :users do
|
||||
|
||||
@@ -11,19 +11,19 @@ describe Spree::Admin::Reports::EnterpriseFeeSummariesController, type: :control
|
||||
allow(controller).to receive(:spree_current_user) { current_user }
|
||||
end
|
||||
|
||||
describe "#index" do
|
||||
context "when there are no parameters" do
|
||||
it "renders the report form" do
|
||||
get :index
|
||||
describe "#new" do
|
||||
it "renders the report form" do
|
||||
get :new
|
||||
|
||||
expect(response).to be_success
|
||||
expect(response).to render_template(view_template_path)
|
||||
end
|
||||
expect(response).to be_success
|
||||
expect(response).to render_template(new_template_path)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#create" do
|
||||
context "when the parameters are valid" do
|
||||
it "sends the generated report in the correct format" do
|
||||
get :index, report: { start_at: "2018-10-09 07:30:00" }, report_format: "csv"
|
||||
post :create, report: { start_at: "2018-10-09 07:30:00" }, report_format: "csv"
|
||||
|
||||
expect(response).to be_success
|
||||
expect(response.body).not_to be_blank
|
||||
@@ -33,10 +33,10 @@ describe Spree::Admin::Reports::EnterpriseFeeSummariesController, type: :control
|
||||
|
||||
context "when the parameters are invalid" do
|
||||
it "renders the report form with an error" do
|
||||
get :index, report: { start_at: "invalid date" }, report_format: "csv"
|
||||
post :create, report: { start_at: "invalid date" }, report_format: "csv"
|
||||
|
||||
expect(flash[:error]).to eq(I18n.t("invalid_filter_parameters", scope: i18n_scope))
|
||||
expect(response).to render_template(view_template_path)
|
||||
expect(response).to render_template(new_template_path)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -47,11 +47,10 @@ describe Spree::Admin::Reports::EnterpriseFeeSummariesController, type: :control
|
||||
let(:current_user) { distributor.owner }
|
||||
|
||||
it "renders the report form with an error" do
|
||||
get :index, report: { distributor_ids: [other_distributor.id] }, report_format: "csv"
|
||||
post :create, report: { distributor_ids: [other_distributor.id] }, report_format: "csv"
|
||||
|
||||
expect(flash[:error]).to eq(report_klass::Authorizer::PARAMETER_NOT_ALLOWED_ERROR)
|
||||
expect(response)
|
||||
.to render_template("spree/admin/reports/enterprise_fee_summaries/index")
|
||||
expect(response).to render_template(new_template_path)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -65,7 +64,7 @@ describe Spree::Admin::Reports::EnterpriseFeeSummariesController, type: :control
|
||||
let(:current_user) { distributor.owner }
|
||||
|
||||
it "applies permissions to report" do
|
||||
get :index, report: {}, report_format: "csv"
|
||||
post :create, report: {}, report_format: "csv"
|
||||
|
||||
expect(assigns(:permissions).allowed_order_cycles.to_a).to eq([order_cycle])
|
||||
end
|
||||
@@ -76,7 +75,7 @@ describe Spree::Admin::Reports::EnterpriseFeeSummariesController, type: :control
|
||||
"order_management.reports.enterprise_fee_summary"
|
||||
end
|
||||
|
||||
def view_template_path
|
||||
"spree/admin/reports/enterprise_fee_summaries/index"
|
||||
def new_template_path
|
||||
"spree/admin/reports/enterprise_fee_summaries/new"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,7 +31,7 @@ feature "enterprise fee summaries" do
|
||||
it "does not allow access to the report" do
|
||||
visit spree.admin_reports_path
|
||||
expect(page).to have_no_link(I18n.t("admin.reports.enterprise_fee_summary.name"))
|
||||
visit spree.enterprise_fee_summary_admin_reports_path
|
||||
visit spree.new_admin_reports_enterprise_fee_summary_path
|
||||
expect(page).to have_content(I18n.t("unauthorized"))
|
||||
end
|
||||
end
|
||||
@@ -39,7 +39,7 @@ feature "enterprise fee summaries" do
|
||||
|
||||
describe "smoke test for filters" do
|
||||
before do
|
||||
visit spree.enterprise_fee_summary_admin_reports_path
|
||||
visit spree.new_admin_reports_enterprise_fee_summary_path
|
||||
end
|
||||
|
||||
context "when logged in as admin" do
|
||||
@@ -63,7 +63,7 @@ feature "enterprise fee summaries" do
|
||||
|
||||
describe "smoke test for generation of report based on permissions" do
|
||||
before do
|
||||
visit spree.enterprise_fee_summary_admin_reports_path
|
||||
visit spree.new_admin_reports_enterprise_fee_summary_path
|
||||
end
|
||||
|
||||
context "when logged in as admin" do
|
||||
@@ -105,7 +105,7 @@ feature "enterprise fee summaries" do
|
||||
let(:current_user) { create(:admin_user) }
|
||||
|
||||
before do
|
||||
visit spree.enterprise_fee_summary_admin_reports_path
|
||||
visit spree.new_admin_reports_enterprise_fee_summary_path
|
||||
end
|
||||
|
||||
it "generates file with data for selected order cycle" do
|
||||
|
||||
Reference in New Issue
Block a user