Class: Hotify::Role
- Inherits:
-
Object
- Object
- Hotify::Role
- Defined in:
- lib/hotify.rb
Instance Method Summary collapse
- #add_role(user_email, role_ids) ⇒ Object
- #all_roles ⇒ Object
- #all_users ⇒ Object
- #all_users_and_roles ⇒ Object
- #dump_role ⇒ Object
- #find_by(id) ⇒ Object
- #find_by_name(name) ⇒ Object
- #leave_role(user_email, role_ids) ⇒ Object
- #role_ids_from(user:) ⇒ Object
- #role_in_user ⇒ Object
- #roles_from(user:) ⇒ Object
- #users ⇒ Object
Instance Method Details
#add_role(user_email, role_ids) ⇒ Object
72 73 74 75 |
# File 'lib/hotify.rb', line 72 def add_role(user_email, role_ids) user = Hotify::Users.find_by(email: user_email) client.assign_role_to_user(user.id, role_ids) end |
#all_roles ⇒ Object
23 24 25 |
# File 'lib/hotify.rb', line 23 def all_roles @_all_roles ||= client.get_roles.to_a end |
#all_users ⇒ Object
42 43 44 |
# File 'lib/hotify.rb', line 42 def all_users @_all_users ||= users.all_users end |
#all_users_and_roles ⇒ Object
46 47 48 49 50 |
# File 'lib/hotify.rb', line 46 def all_users_and_roles @_all_users_and_roles ||= all_users.map do | user | { user: user, role_ids: role_ids_from(user: user) } end end |
#dump_role ⇒ Object
19 20 21 |
# File 'lib/hotify.rb', line 19 def dump_role client.get_roles.to_a.each{ |role| p role } end |
#find_by(id) ⇒ Object
87 88 89 |
# File 'lib/hotify.rb', line 87 def find_by(id) client.get_role(id) end |
#find_by_name(name) ⇒ Object
82 83 84 85 |
# File 'lib/hotify.rb', line 82 def find_by_name(name) name = "?name=#{name}" client.get_role(name) end |
#leave_role(user_email, role_ids) ⇒ Object
77 78 79 80 |
# File 'lib/hotify.rb', line 77 def leave_role(user_email, role_ids) user = Hotify::Users.find_by(email: user_email) client.remove_role_from_user(user.id, role_ids) end |
#role_ids_from(user:) ⇒ Object
34 35 36 |
# File 'lib/hotify.rb', line 34 def role_ids_from(user: ) client.get_user_roles(user.id) end |
#role_in_user ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/hotify.rb', line 52 def role_in_user role_user = Hash.new { |h,k| h[k] = [] } all_roles.each do | role | all_users_and_roles.each do | user_and_role_ids | user_and_role_ids[:role_ids].each do | role_id | if role.id == role_id role_user[role.name].push(user_and_role_ids[:user]) end end end end role_user.each do | role_name , users | users.uniq! end role_user end |
#roles_from(user:) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/hotify.rb', line 27 def roles_from(user: ) role_ids = client.get_user_roles(user.id) role_ids.map do | role_id | client.get_role(role_id) end end |