Module: Sunrise::Models::User::InstanceMethods
- Defined in:
- lib/sunrise/models/user.rb
Instance Method Summary collapse
- #admin? ⇒ Boolean
- #avatar_small_url ⇒ Object
- #current_role ⇒ Object
- #default? ⇒ Boolean
- #events_for_current_state ⇒ Object
- #has_login? ⇒ Boolean
- #has_role?(role_name) ⇒ Boolean
- #moderator? ⇒ Boolean
- #role_symbols ⇒ Object
- #role_type_id ⇒ Object
- #role_type_id=(value) ⇒ Object
- #roles_attributes=(value) ⇒ Object
- #roles_empty? ⇒ Boolean
- #state ⇒ Object
Instance Method Details
#admin? ⇒ Boolean
56 57 58 |
# File 'lib/sunrise/models/user.rb', line 56 def admin? has_role?(:admin) end |
#avatar_small_url ⇒ Object
119 120 121 122 123 124 125 |
# File 'lib/sunrise/models/user.rb', line 119 def avatar_small_url if self.avatar self.avatar.url(:small) else "/images/manage/user_pic_small.gif" end end |
#current_role ⇒ Object
83 84 85 |
# File 'lib/sunrise/models/user.rb', line 83 def current_role self.roles.first end |
#default? ⇒ Boolean
48 49 50 |
# File 'lib/sunrise/models/user.rb', line 48 def default? has_role?(:default) end |
#events_for_current_state ⇒ Object
110 111 112 113 114 115 116 117 |
# File 'lib/sunrise/models/user.rb', line 110 def events_for_current_state events = [] events << 'activate' unless confirmed? events << 'unlock' if access_locked? # TODO: ban access for active users # events << 'suspend' if active_for_authentication? events end |
#has_login? ⇒ Boolean
68 69 70 |
# File 'lib/sunrise/models/user.rb', line 68 def has_login? respond_to?(:login) end |
#has_role?(role_name) ⇒ Boolean
60 61 62 |
# File 'lib/sunrise/models/user.rb', line 60 def has_role?(role_name) role_symbols.include?(role_name.to_sym) end |
#moderator? ⇒ Boolean
52 53 54 |
# File 'lib/sunrise/models/user.rb', line 52 def moderator? has_role?(:moderator) end |
#role_symbols ⇒ Object
79 80 81 |
# File 'lib/sunrise/models/user.rb', line 79 def role_symbols (roles || []).map {|r| r.to_sym} end |
#role_type_id ⇒ Object
87 88 89 90 91 |
# File 'lib/sunrise/models/user.rb', line 87 def role_type_id if current_role current_role.role_type.id end end |
#role_type_id=(value) ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/sunrise/models/user.rb', line 93 def role_type_id=(value) role_id = value.blank? ? nil : value.to_i if ::RoleType.legal?(role_id) ::RoleType.all.each do |role_type| create_or_destroy_role(role_type.id, role_type.id == role_id) end end end |
#roles_attributes=(value) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/sunrise/models/user.rb', line 72 def roles_attributes=(value) = value || {} .each do |k, v| create_or_destroy_role(k.to_i, v.to_i == 1) end end |
#roles_empty? ⇒ Boolean
64 65 66 |
# File 'lib/sunrise/models/user.rb', line 64 def roles_empty? self.roles.empty? end |
#state ⇒ Object
103 104 105 106 107 108 |
# File 'lib/sunrise/models/user.rb', line 103 def state return 'active' if active_for_authentication? return 'register' unless confirmed? return 'suspend' if access_locked? return 'pending' end |