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

Spree v4.0 #60

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion app/controllers/spree/admin/base_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Spree::Admin::BaseController.class_eval do
module Spree::Admin::BaseControllerDecorator
def authorize_admin
begin
if params[:id]
Expand All @@ -25,3 +25,5 @@ def new_action?
NEW_ACTIONS.include?(params[:action].to_sym)
end
end

::Spree::BaseController.prepend(Spree::BaseControllerDecorator)
5 changes: 3 additions & 2 deletions app/models/spree/ability_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Spree
Ability.class_eval do

module AbilityDecorator
def initialize(user)
self.clear_aliased_actions

Expand All @@ -26,3 +25,5 @@ def user_roles(user)
end
end
end

::Spree::Ability.prepend(Spree::AbilityDecorator)
23 changes: 13 additions & 10 deletions app/models/spree/role_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
Spree::Role.class_eval do
module Spree::RoleDecorator
def self.prepended(base)
base.has_many :roles_permission_sets, dependent: :destroy
base.has_many :permission_sets, through: :roles_permission_sets
base.has_many :permissions, through: :permission_sets

has_many :roles_permission_sets, dependent: :destroy
has_many :permission_sets, through: :roles_permission_sets
has_many :permissions, through: :permission_sets
# DEPRECATED: Use permission sets instead. Only here for aiding migration for existing users
base.has_and_belongs_to_many :legacy_permissions, join_table: 'spree_roles_permissions', class_name: 'Spree::Permission'

# DEPRECATED: Use permission sets instead. Only here for aiding migration for existing users
has_and_belongs_to_many :legacy_permissions, join_table: 'spree_roles_permissions', class_name: 'Spree::Permission'
base.validates :name, uniqueness: true, allow_blank: true
base.validates :permission_sets, length: { minimum: 1, too_short: :atleast_one_permission_set_is_required }, on: :update

validates :name, uniqueness: true, allow_blank: true
validates :permission_sets, length: { minimum: 1, too_short: :atleast_one_permission_set_is_required }, on: :update
base.scope :default_role, lambda { where(is_default: true) }
end

def has_permission?(permission_title)
permissions.pluck(:title).include?(permission_title)
end

scope :default_role, lambda { where(is_default: true) }
end

::Spree::Role.prepend(Spree::RoleDecorator)
8 changes: 6 additions & 2 deletions app/models/spree/user_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module Spree
Spree.user_class.class_eval do
alias_attribute :roles, :spree_roles
module UserDecorator
def self.prepended(base)
base.alias_attribute :roles, :spree_roles
end
end
end

::Spree.user_class.prepend(Spree::UserDecorator)
2 changes: 1 addition & 1 deletion spree_admin_roles_and_access.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.requirements << 'none'

spree_version = '>= 3.2.0', '< 4.0.0'
spree_version = '>= 3.2.0', '< 5.0'

s.add_dependency 'spree_core', spree_version
s.add_dependency 'spree_auth_devise'
Expand Down