Module: Auth0::Api::V2::Roles
Overview
Methods to use the Roles endpoints
Instance Method Summary collapse
-
#add_role_permissions(role_id, permissions) ⇒ Object
Associate permissions with a Role.
-
#add_role_users(role_id, users = []) ⇒ Object
Add one or more Users to a Role.
-
#create_role(role_name, data = {}) ⇒ Object
Create a new Role.
-
#delete_role(role_id) ⇒ Object
Delete a single Role by ID.
-
#get_role(role_id) ⇒ json
(also: #role)
Get a single Role by ID.
-
#get_role_permissions(role_id, options = {}) ⇒ json
Get the permissions associated to a Role.
-
#get_role_users(role_id, options = {}) ⇒ Object
Get Users assigned to a specific Role.
-
#get_roles(options = {}) ⇒ json
(also: #roles)
Get all Roles Required scope: “read:roles”.
-
#remove_role_permissions(role_id, permissions) ⇒ Object
Remove permissions from a Role.
-
#update_role(role_id, data = {}) ⇒ Object
Update a Role by ID.
Methods included from Mixins::Validation
#validate_permissions_array, #validate_strings_array
Instance Method Details
#add_role_permissions(role_id, permissions) ⇒ Object
Associate permissions with a Role. Required scope: “update:roles”
147 148 149 150 151 152 |
# File 'lib/auth0/api/v2/roles.rb', line 147 def (role_id, ) raise Auth0::MissingParameter, 'Must supply a valid role_id' if role_id.to_s.empty? = () post "#{roles_path}/#{role_id}/permissions", permissions: end |
#add_role_users(role_id, users = []) ⇒ Object
Add one or more Users to a Role. Required scopes: “update:roles”
112 113 114 115 116 117 |
# File 'lib/auth0/api/v2/roles.rb', line 112 def add_role_users(role_id, users = []) raise Auth0::MissingParameter, 'Must supply a valid role_id' if role_id.to_s.empty? validate_strings_array(users) post "#{roles_path}/#{role_id}/users", users: users end |
#create_role(role_name, data = {}) ⇒ Object
Create a new Role. Required scope: “create:roles”
50 51 52 53 54 55 |
# File 'lib/auth0/api/v2/roles.rb', line 50 def create_role(role_name, data = {}) raise Auth0::MissingParameter, 'Must supply a valid role_name' if role_name.to_s.empty? data[:name] = role_name post roles_path.to_s, data end |
#delete_role(role_id) ⇒ Object
Delete a single Role by ID. Required scope: “delete:roles”
74 75 76 77 78 |
# File 'lib/auth0/api/v2/roles.rb', line 74 def delete_role(role_id) raise Auth0::MissingParameter, 'Must supply a valid role_id' if role_id.to_s.empty? delete "#{roles_path}/#{role_id}" end |
#get_role(role_id) ⇒ json Also known as: role
Get a single Role by ID. Required scope: “read:roles”
37 38 39 40 41 |
# File 'lib/auth0/api/v2/roles.rb', line 37 def get_role(role_id) raise Auth0::MissingParameter, 'Must supply a valid role_id' if role_id.to_s.empty? get "#{roles_path}/#{role_id}" end |
#get_role_permissions(role_id, options = {}) ⇒ json
Get the permissions associated to a Role. Required scope: “read:roles”
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/auth0/api/v2/roles.rb', line 130 def (role_id, = {}) raise Auth0::MissingParameter, 'Must supply a valid role_id' if role_id.to_s.empty? request_params = { per_page: .fetch(:per_page, nil), page: .fetch(:page, nil), include_totals: .fetch(:include_totals, nil) } get "#{roles_path}/#{role_id}/permissions", request_params end |
#get_role_users(role_id, options = {}) ⇒ Object
Get Users assigned to a specific Role. Required scopes:
- "read:roles"
- "read:users"
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/auth0/api/v2/roles.rb', line 93 def get_role_users(role_id, = {}) raise Auth0::MissingParameter, 'Must supply a valid role_id' if role_id.to_s.empty? request_params = { per_page: .fetch(:per_page, nil), page: .fetch(:page, nil), from: .fetch(:from, nil), take: .fetch(:take, nil), include_totals: .fetch(:include_totals, nil) } get "#{roles_path}/#{role_id}/users", request_params end |
#get_roles(options = {}) ⇒ json Also known as: roles
Get all Roles Required scope: “read:roles”
19 20 21 22 23 24 25 26 27 |
# File 'lib/auth0/api/v2/roles.rb', line 19 def get_roles( = {}) request_params = { per_page: .fetch(:per_page, nil), page: .fetch(:page, nil), include_totals: .fetch(:include_totals, nil), name_filter: .fetch(:name_filter, nil) } get roles_path, request_params end |
#remove_role_permissions(role_id, permissions) ⇒ Object
Remove permissions from a Role. Required scope: “update:roles”
160 161 162 163 164 165 |
# File 'lib/auth0/api/v2/roles.rb', line 160 def (role_id, ) raise Auth0::MissingParameter, 'Must supply a valid role_id' if role_id.to_s.empty? = () delete_with_body("#{roles_path}/#{role_id}/permissions", permissions: ) end |
#update_role(role_id, data = {}) ⇒ Object
Update a Role by ID. Required scope: “update:roles”
63 64 65 66 67 |
# File 'lib/auth0/api/v2/roles.rb', line 63 def update_role(role_id, data = {}) raise Auth0::MissingParameter, 'Must supply a valid role_id' if role_id.to_s.empty? patch "#{roles_path}/#{role_id}", data end |