Permalink
Browse files

Changed admin tabs back to deface for retailers

Fixed CanCan Ability decorator for retailers
(Still need to get redirect location right)
  • Loading branch information...
1 parent 3707e8d commit 5d895ce761d1342c3154374bdb79163ab1079f8e @thms committed May 10, 2012
@@ -0,0 +1,21 @@
+Spree::Admin::BaseController.class_eval do
+ before_filter :authorize_admin
+
+ def authorize_admin
+ begin
+ model = model_class
+ rescue
+ #model = Object
+ # change the Object to controller_name.to_sym
+ # Reference here: https://github.com/ryanb/cancan/wiki/Non-RESTful-Controllers
+ model = controller_name.to_sym
+ end
+ authorize! :admin, model
+ authorize! params[:action].to_sym, model
+ end
+
+ protected
+ def model_class
+ "Spree::#{controller_name.classify}".constantize
+ end
+end
@@ -6,44 +6,40 @@ def initialize(user)
if user.has_role? 'retailer'
can :index, :overview
can :admin, :overview
-
+
can :manage, Spree::Order do |order|
(order.retailer_ids & user.retailer_ids).present?
end
+
+ can :manage, :customer_details
+
+ can :manage, Spree::Adjustment do |adjustment|
+ adjustment.order.retailer_id == user.retailer_id
+ end
-# can :manage, Spree::Adjustment do |adjustment|
-# adjustment.order.retailer_id == user.retailer_id
-# end
+ can :manage, Spree::Payment do |payment|
+ payment.order.retailer_id == user.retailer_id
+ end
-# can :manage, Spree::Payment do |payment|
-# payment.order.retailer_id == user.retailer_id
-# end
+ can :manage, Spree::Shipment do |shipment|
+ shipment.order.retailer_id == user.retailer_id
+ end
-# can :manage, Spree::Shipment do |shipment|
-# shipment.order.retailer_id == user.retailer_id
-# end
+ can :manage, Spree::ShipmentDetail do |shipment_detail|
+ shipment_detail.order.retailer_id == user.retailer_id
+ end
-# can :manage, Spree::ReturnAuthorization do |return_authorization|
-# return_authorization.order.retailer_id == user.retailer_id
-# end
-
- # TODO: Check if we want the retailer to do any of these:
- can :index, Spree::Product
- can :admin, Spree::Product
- can :index, Spree::OptionType
- can :admin, Spree::OptionType
- can :index, Spree::Prototype
- can :admin, Spree::Prototype
- can :index, Spree::Property
- can :admin, Spree::Property
- can :index, Spree::ProductGroup
- can :admin, Spree::ProductGroup
+ can :manage, Spree::ReturnAuthorization do |return_authorization|
+ return_authorization.order.retailer_id == user.retailer_id
+ end
# reference: https://github.com/ryanb/cancan/wiki/Non-RESTful-Controllers
can :index, :reports
can :sales_total, :reports
can :admin, :reports
+
+
end
# enable access to FedexLabels for non-logged until we figure out a way to
@@ -0,0 +1,7 @@
+# Limit admin tabs to orders and overview when the user is a retailer
+Deface::Override.new(:virtual_path => "spree/layouts/admin",
+ :name => "replace_admin_tabs_for_retailer",
+ :sequence => 1, # apply before all others
+ :replace => "[data-hook='admin_tabs']",
+ :partial => "spree/admin/shared/admin_tabs",
+ :disabled => false)
@@ -0,0 +1,11 @@
+<% if current_user.has_role? 'retailer' %>
+ <ul>
+ <%= tab :overview, :route => :admin %>
+ <%= tab :orders, :payments, :creditcard_payments, :shipments, :creditcards, :return_authorizations %>
+ <%= tab :reports %>
+ </ul>
+<% else %>
+ <ul data-hook="admin_tabs">
+ <%= render :partial => 'spree/admin/shared/tabs' %>
+ </ul>
+<% end %>
@@ -1,12 +0,0 @@
-<% if current_user.has_role? "admin" %>
-<%= tab :overview, :route => :admin %>
-<%= tab :orders, :payments, :creditcard_payments, :shipments, :creditcards, :return_authorizations %>
-<%= tab :products , :option_types, :properties, :prototypes, :variants, :product_properties, :product_groups, :taxons %>
-<%= tab :reports %>
-<%= tab :configurations, :general_settings, :mail_methods, :tax_categories, :zones, :states, :payment_methods, :inventory_settings, :taxonomies, :shipping_methods, :trackers, :label => 'configuration' %>
-<%= tab :users %>
-<% else %>
-<%= tab :overview, :route => :admin %>
-<%= tab :orders, :payments, :creditcard_payments, :shipments, :creditcards, :return_authorizations %>
-<%= tab :products , :option_types, :properties, :prototypes, :variants, :product_properties, :product_groups, :taxons %>
-<% end %>
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'spree_reservebar_core'
- s.version = '0.1.5'
+ s.version = '0.1.6'
s.summary = 'Spree Commerce Extensions for reservebar.com'
s.author = 'Thomas Boltze'

0 comments on commit 5d895ce

Please sign in to comment.