class Datacentred::Model::Role
A role on your DataCentred account.
Roles allow simple setup of user permissions via the creation of roles, then assigning those roles to users.
@attr [String] id @attr [String] name @attr [Boolean] admin @attr [[String]] permissions @attr_reader [Time] created_at @attr_reader [Time] updated_at
Public Class Methods
Add new user to this role, giving them the associated permissions.
@param [String] role_id The unique identifier for this role. @param [String] user_id The unique identifier for this user. @raise [Errors::NotFound] Raised if the role or user couldn't be found. @raise [Errors::Unauthorized] Raised if credentials aren't valid. @return [Boolean] Confirms that user was added (or is already present).
# File lib/datacentred/model/role.rb, line 83 def add_user(role_id:, user_id:) Request::Roles.add_user role_id, user_id true end
List all available roles.
@raise [Errors::Unauthorized] Raised if credentials aren't valid. @return [[Role]] A collection of all roles on this account.
# File lib/datacentred/model/role.rb, line 29 def all Request::Roles.list.map{|role| new role } end
Create a new role.
@param [Hash] params Role
attributes. @raise [Errors::UnprocessableEntity] Raised if validations fail for the supplied attributes. @raise [Errors::Unauthorized] Raised if credentials aren't valid. @return [Role] New role.
# File lib/datacentred/model/role.rb, line 21 def create(params) new Request::Roles.create params end
Permanently remove the specified role.
@param [String] id The unique identifier for this role. @raise [Errors::NotFound] Raised if the role couldn't be found. @raise [Errors::UnprocessableEntity] Raised if validations fail for the specifed role. @raise [Errors::Unauthorized] Raised if credentials aren't valid. @return [Boolean] Confirms the role was destroyed.
# File lib/datacentred/model/role.rb, line 62 def destroy(id) Request::Roles.destroy id true end
Find a role by unique ID.
@param [String] id The unique identifier for this role. @raise [Errors::NotFound] Raised if the role couldn't be found. @raise [Errors::Unauthorized] Raised if credentials aren't valid. @return [Role] The role, if it exists.
# File lib/datacentred/model/role.rb, line 39 def find(id) new Request::Roles.show id end
Remove user from this role, revoking the associated permissions.
@param [String] role_id The unique identifier for this role. @param [String] user_id The unique identifier for this user. @raise [Errors::NotFound] Raised if the role or user coundn't be found. @raise [Errors::Unauthorized] Raised if credentials aren't valid. @return [Boolean] Confirms that user was removed (or is already absent).
# File lib/datacentred/model/role.rb, line 95 def remove_user(role_id:, user_id:) Request::Roles.remove_user role_id, user_id true end
Update a role by unique ID.
@param [String] id The unique identifier for this role. @param [Hash] params Role
attributes. @raise [Errors::UnprocessableEntity] Raised if validations fail for the supplied attributes. @raise [Errors::NotFound] Raised if the role doesn't exist. @raise [Errors::Unauthorized] Raised if credentials aren't valid. @return [Role] The updated role.
# File lib/datacentred/model/role.rb, line 51 def update(id, params) new Request::Roles.update id, params end
List all users assigned to this role.
@param [String] id The unique identifier for this role. @raise [Errors::Unauthorized] Raised if credentials aren't valid. @return [[User]] A collection of the role's users.
# File lib/datacentred/model/role.rb, line 72 def users(id) Request::Roles.list_users(id).map{|user| new user } end