Class: Yao::Resources::Role

Inherits:
Base
  • Object
show all
Defined in:
lib/yao/resources/role.rb

Instance Attribute Summary

Attributes included from RestfullyAccessible

#api_version, #service

Class Method Summary collapse

Methods inherited from Base

#[], #[]=, #created, friendly_attributes, #id, #initialize, map_attribute_to_attribute, map_attribute_to_resource, map_attribute_to_resources, #updated

Methods included from RestfullyAccessible

#admin=, #as_member, #client, #create, #destroy, extended, #get, #list, #list_detail, #resources_path, #resources_path=, #return_single_on_querying=, #update, #with_resources_path

Constructor Details

This class inherits a constructor from Yao::Resources::Base

Class Method Details

.get_by_name(name) ⇒ Object Also known as: find_by_name



12
13
14
# File 'lib/yao/resources/role.rb', line 12

def get_by_name(name)
  self.list.find {|role| role.name == name }
end

.grant(role_name, to:, on:) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/yao/resources/role.rb', line 25

def grant(role_name, to:, on:)
  role   = Yao::Role.get_by_name(role_name)
  user   = Yao::User.get_by_name(to)
  tenant = Yao::Tenant.get_by_name(on)

  PUT path_for_grant_revoke(tenant, user, role)
end

.list_for_user(user_name, on:) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/yao/resources/role.rb', line 17

def list_for_user(user_name, on:)
  user   = Yao::User.get_by_name(user_name)
  tenant = Yao::Tenant.get_by_name(on)
  path = ["tenants", tenant.id, "users", user.id, "roles"].join("/")

  with_resources_path(path) { self.list }
end

.revoke(role_name, from:, on:) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/yao/resources/role.rb', line 33

def revoke(role_name, from:, on:)
  role   = Yao::Role.get_by_name(role_name)
  user   = Yao::User.get_by_name(from)
  tenant = Yao::Tenant.get_by_name(on)

  DELETE path_for_grant_revoke(tenant, user, role)
end