Skip to content

Commit

Permalink
Move common Spree.user_class role decorations into core
Browse files Browse the repository at this point in the history
As per BDQ's comment here: spree#1512 (comment)
  • Loading branch information
radar committed Jun 20, 2012
1 parent 3fe34d6 commit bd52468
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
7 changes: 0 additions & 7 deletions api/app/models/spree/user_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
if Spree.user_class
Spree.user_class.class_eval do
has_and_belongs_to_many :roles, :join_table => 'spree_roles_users'

def generate_api_key!
self.api_key = SecureRandom.hex(24)
save!
Expand All @@ -11,10 +9,5 @@ def clear_api_key!
self.api_key = nil
save!
end

# has_spree_role? simply needs to return true or false whether a user has a role or not.
def has_spree_role?(role_in_question)
roles.any? { |role| role.name == role_in_question.to_s }
end
end
end
11 changes: 11 additions & 0 deletions core/config/initializers/user_class_extensions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if Spree.user_class
Spree.user_class.class_eval do
has_and_belongs_to_many :roles, :join_table => 'spree_roles_users'

# has_spree_role? simply needs to return true or false whether a user has a role or not.
def has_spree_role?(role_in_question)
roles.any? { |role| role.name == role_in_question.to_s }
end
end
end

5 changes: 0 additions & 5 deletions dash/app/models/spree/user_decorator.rb

This file was deleted.

5 changes: 0 additions & 5 deletions promo/app/models/spree/user_decorator.rb

This file was deleted.

0 comments on commit bd52468

Please sign in to comment.