Skip to content

Commit

Permalink
Add checks for Spree.user_class to api, dash and promo user decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
radar committed May 10, 2012
1 parent b7cf532 commit e15009e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
28 changes: 15 additions & 13 deletions api/app/models/spree/user_decorator.rb
@@ -1,18 +1,20 @@
Spree.user_class.class_eval do
has_and_belongs_to_many :roles, :join_table => 'spree_roles_users'
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!
end
def generate_api_key!
self.api_key = SecureRandom.hex(24)
save!
end

def clear_api_key!
self.api_key = nil
save!
end
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 }
# 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
6 changes: 4 additions & 2 deletions dash/app/models/spree/user_decorator.rb
@@ -1,3 +1,5 @@
Spree.user_class.class_eval do
has_and_belongs_to_many :roles, :join_table => 'spree_roles_users'
if Spree.user_class
Spree.user_class.class_eval do
has_and_belongs_to_many :roles, :join_table => 'spree_roles_users'
end
end
6 changes: 4 additions & 2 deletions promo/app/models/spree/user_decorator.rb
@@ -1,3 +1,5 @@
Spree.user_class.class_eval do
has_and_belongs_to_many :roles, :join_table => 'spree_roles_users'
if Spree.user_class
Spree.user_class.class_eval do
has_and_belongs_to_many :roles, :join_table => 'spree_roles_users'
end
end

0 comments on commit e15009e

Please sign in to comment.