-
Notifications
You must be signed in to change notification settings - Fork 8
Add api token endpoints #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bea3e45
e816b5b
df0782c
8135426
c9d668b
1995772
4578274
0887495
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,16 @@ | |
| client = Mailtrap::Client.new(api_key: 'your-api-key') | ||
| permissions = Mailtrap::PermissionsAPI.new(account_id, client) | ||
|
|
||
| # Get the recursive tree of resources the current token can access | ||
| permissions.resources | ||
| # => [ | ||
| # #<struct Mailtrap::PermissionResource id=4001, name="My First Project", type="project", | ||
| # access_level=1, resources=[ | ||
| # #<struct Mailtrap::PermissionResource id=3816, name="My First Inbox", type="inbox", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as a suggestion, lets maybe not expose inboxes and choose another resource so its easier to later to remove all the mentions. |
||
| # access_level=100, resources=[]> | ||
| # ]> | ||
| # ] | ||
|
|
||
| # Bulk-update user/token permissions on an account access. Combine create/update with destroy: | ||
| permissions.bulk_update( | ||
| 5142, # account_access_id | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Mailtrap | ||
| # Data Transfer Object for a node in the Permissions resources tree | ||
| # @attr_reader id [Integer] Resource ID | ||
| # @attr_reader name [String] Resource name | ||
| # @attr_reader type [String] Resource type (account, project, inbox, sending_domain, ...) | ||
| # @attr_reader access_level [Integer] The access level the current token has on this resource | ||
| # @attr_reader resources [Array<PermissionResource>] Nested child resources | ||
| PermissionResource = Struct.new( | ||
| :id, | ||
| :name, | ||
| :type, | ||
| :access_level, | ||
| :resources, | ||
| keyword_init: true | ||
| ) | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative 'base_api' | ||
| require_relative 'permission_resource' | ||
|
|
||
| module Mailtrap | ||
| class PermissionsAPI | ||
|
|
@@ -20,10 +21,31 @@ def bulk_update(account_access_id, permissions) | |
| ) | ||
| end | ||
|
|
||
| # Returns the recursive tree of resources the current token can access. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if that information is crucial for customer, to know that its a recursive tree, everywhere else we just mention that its permissions.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather keep it |
||
| # Each node carries the token's access_level and any nested child resources. | ||
| # @return [Array<PermissionResource>] Top-level resources, each with nested children | ||
| # @!macro api_errors | ||
| def resources | ||
| response = client.get("#{base_path}/permissions/resources") | ||
| build_resource_tree(response) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def base_path | ||
| "/api/accounts/#{account_id}" | ||
| end | ||
|
|
||
| def build_resource_tree(items) | ||
| items.map do |item| | ||
| PermissionResource.new( | ||
| id: item[:id], | ||
| name: item[:name], | ||
| type: item[:type], | ||
| access_level: item[:access_level], | ||
| resources: build_resource_tree(Array(item[:resources])) | ||
| ) | ||
| end | ||
| end | ||
| end | ||
| end | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it would be nice quality of life improvement to have
api_tokens.reset(id: 12_345)so to explicitly define what is the route parameter.Very optional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that would not be aligned with the rest of the endpoints e.g. get, delete, ...