Class: Caboose::User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Caboose::User
- Defined in:
- app/models/caboose/user.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_to_role(role_id) ⇒ Object
- #add_to_role_with_name(role_name) ⇒ Object
- #is_allowed(resource, action) ⇒ Object
- #is_member?(role_id) ⇒ Boolean
Class Method Details
.logged_out_user ⇒ Object
7 8 9 |
# File 'app/models/caboose/user.rb', line 7 def self.logged_out_user return self.where('username' => 'elo').first end |
.logged_out_user_id ⇒ Object
11 12 13 |
# File 'app/models/caboose/user.rb', line 11 def self.logged_out_user_id return self.where('username' => 'elo').limit(1).pluck(:id)[0] end |
.validate_token(token) ⇒ Object
24 25 26 27 |
# File 'app/models/caboose/user.rb', line 24 def self.validate_token(token) user = User.where('token' => token).first return user end |
Instance Method Details
#add_to_role(role_id) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/caboose/user.rb', line 35 def add_to_role(role_id) r = Role.find(role_id) return false if r.nil? if (!is_member?(r.id)) roles.push r save end return true end |
#add_to_role_with_name(role_name) ⇒ Object
29 30 31 32 33 |
# File 'app/models/caboose/user.rb', line 29 def add_to_role_with_name(role_name) r = Role.where(:name => role_name).first return false if r.nil? return add_to_role(r.id) end |
#is_allowed(resource, action) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'app/models/caboose/user.rb', line 15 def is_allowed(resource, action) for role in roles if role.is_allowed(resource, action) return true end end return false; end |
#is_member?(role_id) ⇒ Boolean
46 47 48 49 50 51 |
# File 'app/models/caboose/user.rb', line 46 def is_member?(role_id) roles.each do |r| return true if (r.id == role_id) end return false end |