Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supplier ability to add products and be associated by shipping categories. #75

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/controllers/spree/admin/products_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Spree::Admin::ProductsController.class_eval do

belongs_to :supplier

before_filter :get_suppliers, only: [:edit, :update]
before_filter :supplier_collection, only: [:index]

Expand Down
14 changes: 9 additions & 5 deletions app/controllers/spree/base_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
Spree::BaseController.class_eval do

prepend_before_filter :redirect_supplier
before_action :authorize_supplier

private
protected

def redirect_supplier
if ['/admin', '/admin/authorization_failure'].include?(request.path) && try_spree_current_user.try(:supplier)
redirect_to '/admin/shipments' and return false
def authorize_supplier
if respond_to?(:model_class, true) && model_class

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the return of the conditional for variable assignment and comparison.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the return of the conditional for variable assignment and comparison.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the return of the conditional for variable assignment and comparison.

record = model_class
else
record = controller_name.to_sym
end
authorize! :supplier, record
authorize! action, record
end

end
2 changes: 1 addition & 1 deletion app/models/spree/supplier_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(user)
can [:admin, :read, :stock], Spree::Product do |product|
product.supplier_ids.include?(user.supplier_id)
end
can [:admin, :index], Spree::Product
can [:admin, :index, :manage, :create], Spree::Product
can [:admin, :manage, :read, :ready, :ship], Spree::Shipment, order: { state: 'complete' }, stock_location: { supplier_id: user.supplier_id }
can [:admin, :create, :update], :stock_items
can [:admin, :manage], Spree::StockItem, stock_location_id: user.supplier.stock_locations.pluck(:id)
Expand Down