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
59 60 61 |
# File 'lib/sunrise/models/user.rb', line 59 def admin? has_role?(:admin) end |
#avatar_small_url ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/sunrise/models/user.rb', line 122 def avatar_small_url if self.avatar self.avatar.data.small.url else "/images/manage/user_pic_small.gif" end end |
#current_role ⇒ Object
86 87 88 |
# File 'lib/sunrise/models/user.rb', line 86 def current_role self.roles.first end |
#default? ⇒ Boolean
51 52 53 |
# File 'lib/sunrise/models/user.rb', line 51 def default? has_role?(:default) end |
#events_for_current_state ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/sunrise/models/user.rb', line 113 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
71 72 73 |
# File 'lib/sunrise/models/user.rb', line 71 def has_login? respond_to?(:login) end |
#has_role?(role_name) ⇒ Boolean
63 64 65 |
# File 'lib/sunrise/models/user.rb', line 63 def has_role?(role_name) role_symbols.include?(role_name.to_sym) end |
#moderator? ⇒ Boolean
55 56 57 |
# File 'lib/sunrise/models/user.rb', line 55 def moderator? has_role?(:moderator) end |
#role_symbols ⇒ Object
82 83 84 |
# File 'lib/sunrise/models/user.rb', line 82 def role_symbols (roles || []).map {|r| r.to_sym} end |
#role_type_id ⇒ Object
90 91 92 93 94 |
# File 'lib/sunrise/models/user.rb', line 90 def role_type_id if current_role current_role.role_type.id end end |
#role_type_id=(value) ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/sunrise/models/user.rb', line 96 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
75 76 77 78 79 80 |
# File 'lib/sunrise/models/user.rb', line 75 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
67 68 69 |
# File 'lib/sunrise/models/user.rb', line 67 def roles_empty? self.roles.empty? end |
#state ⇒ Object
106 107 108 109 110 111 |
# File 'lib/sunrise/models/user.rb', line 106 def state return 'active' if active_for_authentication? return 'register' unless confirmed? return 'suspend' if access_locked? return 'pending' end |