Class: Roleable::RoleValidator
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- Roleable::RoleValidator
- Defined in:
- app/models/concerns/roleable.rb
Overview
role management
enum listing possible roles max_role setting the model max role to that of the current user - you never can promote anyone above your own level set_default_role sets the role of a new user
Instance Attribute Summary collapse
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
Instance Attribute Details
#user ⇒ Object
Returns the value of attribute user.
32 33 34 |
# File 'app/models/concerns/roleable.rb', line 32 def user @user end |
Instance Method Details
#max_role_exhausted ⇒ Object
47 48 49 50 51 |
# File 'app/models/concerns/roleable.rb', line 47 def max_role_exhausted User.roles[user.role] > User.roles[user.max_role] rescue false end |
#old_role_less_than_new ⇒ Object
41 42 43 44 45 |
# File 'app/models/concerns/roleable.rb', line 41 def old_role_less_than_new User.roles[user.previous_version.role] < User.roles[user.role] rescue false end |
#validate(record) ⇒ Object
33 34 35 36 37 38 39 |
# File 'app/models/concerns/roleable.rb', line 33 def validate(record) @user = record Rails.logger.info ("roles: old %s new %s" % [ User.roles[record.previous_version.role], User.roles[record.role] ] ) rescue "no previous role" if max_role_exhausted and old_role_less_than_new record.errors[:role] << I18n.t('.assigned_role_not_allowed') end end |