For users without product management perms, show a cut-down admin dashboard

This commit is contained in:
Rohan Mitchell
2014-08-19 16:02:11 +10:00
parent 9451f3659c
commit 5dc7d1ee11
5 changed files with 99 additions and 53 deletions

View File

@@ -30,17 +30,6 @@ class AbilityDecorator
can [:admin, :index], :overview
# Enterprise User can only access payment methods for their distributors
can [:index, :create], Spree::PaymentMethod
can [:admin, :read, :update, :fire, :resend, :destroy, :show_provider_preferences], Spree::PaymentMethod do |payment_method|
(user.enterprises & payment_method.distributors).any?
end
can [:index, :create], Spree::ShippingMethod
can [:admin, :read, :update, :destroy], Spree::ShippingMethod do |shipping_method|
(user.enterprises & shipping_method.distributors).any?
end
can [:admin, :index, :read, :create, :edit, :update_positions, :destroy], ProducerProperty
can [:admin, :index, :create], Enterprise
@@ -97,6 +86,17 @@ class AbilityDecorator
can [:admin, :index, :read, :create, :edit, :update], Exchange
can [:admin, :index, :read, :create, :edit, :update], ExchangeFee
# Enterprise user can only access payment and shipping methods for their distributors
can [:index, :create], Spree::PaymentMethod
can [:admin, :read, :update, :fire, :resend, :destroy, :show_provider_preferences], Spree::PaymentMethod do |payment_method|
(user.enterprises & payment_method.distributors).any?
end
can [:index, :create], Spree::ShippingMethod
can [:admin, :read, :update, :destroy], Spree::ShippingMethod do |shipping_method|
(user.enterprises & shipping_method.distributors).any?
end
# Reports page
can [:admin, :index, :customers, :orders_and_distributors, :group_buys, :bulk_coop, :payments, :orders_and_fulfillment, :products_and_inventory], :report
end

View File

@@ -1,35 +1,41 @@
%div.hubs_tab{ ng: { show: "activeTab == 'hubs'"} }
%div.sixteen.columns.alpha.list-title
%span.five.columns.alpha Name
%span.centered.three.columns Payment Methods
%span.centered.three.columns Shipping Methods
%span.centered.three.columns Enterprise Fees
- if can? :admin, Spree::PaymentMethod
%span.centered.three.columns Payment Methods
- if can? :admin, Spree::ShippingMethod
%span.centered.three.columns Shipping Methods
- if can? :admin, EnterpriseFee
%span.centered.three.columns Enterprise Fees
%div.sixteen.columns.alpha.list
- @enterprises.is_distributor.each do |enterprise|
%a.sixteen.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{main_app.edit_admin_enterprise_path(enterprise)}" }
%span.five.columns.alpha
= enterprise.name
%span.symbol.three.columns.centered
- payment_method_count = enterprise.payment_methods.count
- if payment_method_count < 1 && enterprise.is_distributor
%span.icon-remove-sign.with-tip{ title: "#{enterprise.name} has no payment methods" }
- elsif enterprise.is_primary_producer
%span.icon-ok-sign.with-tip{ title: "Producers (like #{enterprise.name}) do not require payment methods." }
- else
%span.icon-ok-sign.with-tip{ title: "#{pluralize payment_method_count, 'payment method'}" }
- if can? :admin, Spree::PaymentMethod
- payment_method_count = enterprise.payment_methods.count
- if payment_method_count < 1 && enterprise.is_distributor
%span.icon-remove-sign.with-tip{ title: "#{enterprise.name} has no payment methods" }
- elsif enterprise.is_primary_producer
%span.icon-ok-sign.with-tip{ title: "Producers (like #{enterprise.name}) do not require payment methods." }
- else
%span.icon-ok-sign.with-tip{ title: "#{pluralize payment_method_count, 'payment method'}" }
%span.symbol.three.columns.centered
- shipping_method_count = enterprise.shipping_methods.count
- if shipping_method_count < 1 && enterprise.is_distributor
%span.icon-remove-sign.with-tip{ title: "#{enterprise.name} has no shipping methods" }
- elsif enterprise.is_primary_producer
%span.icon-ok-sign.with-tip{ title: "Producers (like #{enterprise.name}) do not require shipping methods." }
-else
%span.icon-ok-sign.with-tip{ title: "#{pluralize shipping_method_count, 'shipping method'}" }
- if can? :admin, Spree::ShippingMethod
- shipping_method_count = enterprise.shipping_methods.count
- if shipping_method_count < 1 && enterprise.is_distributor
%span.icon-remove-sign.with-tip{ title: "#{enterprise.name} has no shipping methods" }
- elsif enterprise.is_primary_producer
%span.icon-ok-sign.with-tip{ title: "Producers (like #{enterprise.name}) do not require shipping methods." }
- else
%span.icon-ok-sign.with-tip{ title: "#{pluralize shipping_method_count, 'shipping method'}" }
%span.symbol.three.columns.centered
- fee_count = enterprise.enterprise_fees.count
- if fee_count > 0
%span.icon-ok-sign.with-tip{ title: "#{pluralize fee_count, 'fee'}" }
- else
%span.icon-warning-sign.with-tip{ title: "#{enterprise.name} has no enterprise fees" }
- if can? :admin, EnterpriseFee
- fee_count = enterprise.enterprise_fees.count
- if fee_count > 0
%span.icon-ok-sign.with-tip{ title: "#{pluralize fee_count, 'fee'}" }
- else
%span.icon-warning-sign.with-tip{ title: "#{enterprise.name} has no enterprise fees" }
%span.two.columns.omega.right
%span.icon-arrow-right

View File

@@ -1,28 +1,37 @@
%div.producers_tab{ ng: { show: "activeTab == 'producers'"} }
%div.list-title.sixteen.columns.alpha
%span.five.columns.alpha Name
%span.centered.three.columns Total Products
%span.centered.three.columns Active Products
%span.centered.three.columns Products in OCs
- if can? :admin, Spree::Product
%span.centered.three.columns Total Products
%span.centered.three.columns Active Products
- if can? :admin, OrderCycle
%span.centered.three.columns Products in OCs
%div.sixteen.columns.alpha.list
- @enterprises.is_primary_producer.each do |enterprise|
%a.sixteen.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{main_app.edit_admin_enterprise_path(enterprise)}" }
%span.five.columns.alpha
= enterprise.name
%span.symbol.three.columns.centered
%span.one.column.alpha &nbsp;
%span.text-icon.one.column.centered{ class: "#{enterprise.supplied_products.not_deleted.any? ? "green" : "red" }" }
= enterprise.supplied_products.not_deleted.count
%span.one.column.omega &nbsp;
- if can? :admin, Spree::Product
%span.one.column.alpha &nbsp;
%span.text-icon.one.column.centered{ class: "#{enterprise.supplied_products.not_deleted.any? ? "green" : "red" }" }
= enterprise.supplied_products.not_deleted.count
%span.one.column.omega &nbsp;
%span.symbol.three.columns.centered
%span.one.column.alpha &nbsp;
%span.text-icon.one.column.centered{ class: "#{enterprise.supplied_and_active_products_on_hand.any? ? "green" : "red" }" }
= enterprise.supplied_and_active_products_on_hand.count
%span.one.column.omega &nbsp;
- if can? :admin, Spree::Product
%span.one.column.alpha &nbsp;
%span.text-icon.one.column.centered{ class: "#{enterprise.supplied_and_active_products_on_hand.any? ? "green" : "red" }" }
= enterprise.supplied_and_active_products_on_hand.count
%span.one.column.omega &nbsp;
%span.symbol.three.columns.centered
%span.one.column.alpha &nbsp;
%span.text-icon.one.column.centered{ class: "#{enterprise.active_products_in_order_cycles.any? ? "green" : "orange" }" }
= enterprise.active_products_in_order_cycles.count
%span.one.column.omega &nbsp;
- if can? :admin, OrderCycle
%span.one.column.alpha &nbsp;
%span.text-icon.one.column.centered{ class: "#{enterprise.active_products_in_order_cycles.any? ? "green" : "orange" }" }
= enterprise.active_products_in_order_cycles.count
%span.one.column.omega &nbsp;
%span.two.columns.omega.right
%span.icon-arrow-right

View File

@@ -5,11 +5,13 @@
= render partial: "spree/admin/overview/enterprises"
- else
= render partial: "spree/admin/overview/products"
- if can? :admin, Spree::Product
= render partial: "spree/admin/overview/products"
%div.two.columns
&nbsp;
%div.two.columns
&nbsp;
= render partial: "spree/admin/overview/order_cycles"
- if can? :admin, OrderCycle
= render partial: "spree/admin/overview/order_cycles"
= render partial: "spree/admin/overview/enterprises"

View File

@@ -14,6 +14,7 @@ feature %q{
let(:supplier_profile) { create(:supplier_enterprise, name: 'Supplier profile', type: 'profile') }
let!(:distributor1) { create(:distributor_enterprise, name: 'Distributor 3') }
let!(:distributor2) { create(:distributor_enterprise, name: 'Distributor 4') }
let(:distributor_profile) { create(:distributor_enterprise, name: 'Distributor profile', type: 'profile') }
describe "creating an enterprise user" do
context "with no enterprises managed" do
@@ -79,6 +80,7 @@ feature %q{
describe "with only a profile-level enterprise" do
before do
user.enterprise_roles.create! enterprise: supplier_profile
user.enterprise_roles.create! enterprise: distributor_profile
login_to_admin_as user
end
@@ -91,7 +93,34 @@ feature %q{
end
end
it "shows me a cut-down dashboard"
describe "dashboard" do
it "shows me enterprise management controls" do
within('#enterprises') do
page.should have_selector 'h3', text: 'My Enterprises'
page.should have_link 'CREATE NEW'
page.should have_link supplier_profile.name
page.should have_link 'MANAGE MY ENTERPRISES'
end
end
it "does not show me product management controls" do
page.should_not have_selector '#products'
page.should_not have_selector '#order_cycles'
end
it "does not show me enterprise product info, payment methods, shipping methods or enterprise fees" do
# Producer product info
page.should_not have_selector '.producers_tab span', text: 'Total Products'
page.should_not have_selector '.producers_tab span', text: 'Active Products'
page.should_not have_selector '.producers_tab span', text: 'Products in OCs'
# Payment methods, shipping methods, enterprise fees
page.should_not have_selector '.hubs_tab span', text: 'Payment Methods'
page.should_not have_selector '.hubs_tab span', text: 'Shipping Methods'
page.should_not have_selector '.hubs_tab span', text: 'Enterprise Fees'
end
end
it "shows me only profile options on the enterprises page"
end