Skip to content
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

Make trigger_id and action_name optional for actions index endpoint #478

Merged
merged 7 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions lib/auth0/api/v2/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ module Actions
# @param page [integer] The page number. Zero based.
# @param installed [boolean] When true, return only installed actions. When false, return only custom actions. Returns all actions by default.
# @return [json] Actions and pagination info
def actions(trigger_id, action_name, deployed: nil, per_page: nil, page: nil, installed: nil)
raise Auth0::MissingTriggerId, 'Must supply a valid trigger_id' if trigger_id.to_s.empty?
raise Auth0::MissingActionName, 'Must supply a valid action_name' if action_name.to_s.empty?

def actions(trigger_id: nil, action_name: nil, deployed: nil, per_page: nil, page: nil, installed: nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this is the ideal API for this method but I would prefer we implement it in a non-breaking way. How about we do optional position parameters instead of named ones for the first two? That way existing calls will continue to work while there is also the ability to optionally leave them out.

def actions(trigger_id = nil, action_name = nil, deployed: nil, per_page: nil, page: nil, installed: nil)

request_params = {
trigger_id: trigger_id,
action_name: action_name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately the original implementation looks broken here, as these should be (according to the API):

triggerId: trigger_id,
actionName: action_name,

I'm curious though, did you test this against the API? As I can't get your implementation to work, I get the "Query validation error: 'Additional properties not allowed: trigger_id'." error with the PR as it is now.

Copy link
Contributor Author

@rapito rapito Jun 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I just tested it and as long as trigger_id and action_name are not passed as parameters, it works.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I can see the same. If they are passed, however, we get an error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've provided a fix in cb1ade0 that makes these arguments optional positional for backwards compatibility.

Expand All @@ -38,7 +35,8 @@ def actions(trigger_id, action_name, deployed: nil, per_page: nil, page: nil, in
# @param body [hash] See https://auth0.com/docs/api/management/v2/#!/actions/post_action for available options
# @return [json] Returns the created action.
def create_action(body = {})
post(actions_path, body)
path = "#{actions_path}/actions"
post(path, body)
end

# Retrieve the set of triggers currently available within actions. A trigger is an extensibility point to which actions can be bound.
Expand Down
13 changes: 3 additions & 10 deletions spec/lib/auth0/api/v2/actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
})
expect do
@instance.actions(
'post-login',
'loginHandler',
trigger_id: 'post-login',
action_name: 'loginHandler',
deployed: true,
per_page: 10,
page: 1,
Expand All @@ -37,13 +37,6 @@
end.not_to raise_error
end

it 'is expected to raise an exception when the trigger id is empty' do
expect { @instance.actions(nil, nil) }.to raise_exception(Auth0::MissingTriggerId)
end

it 'is expected to raise an exception when the action name is empty' do
expect { @instance.actions(1, nil) }.to raise_exception(Auth0::MissingActionName)
end
end

context '.action' do
Expand Down Expand Up @@ -71,7 +64,7 @@

it 'is expected to post to /api/v2/actions' do
expect(@instance).to receive(:post).with(
'/api/v2/actions', {
'/api/v2/actions/actions', {
name: 'test_org'
})
expect do
Expand Down