Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
18bc3f29
Unverified
Commit
18bc3f29
authored
2 years ago
by
Tim Macdonald
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add action/:id/execute endpoint (#28335)
parent
084416f1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/metabase/api/action.clj
+12
-0
12 additions, 0 deletions
src/metabase/api/action.clj
src/metabase/api/public.clj
+2
-4
2 additions, 4 deletions
src/metabase/api/public.clj
test/metabase/api/action_test.clj
+34
-2
34 additions, 2 deletions
test/metabase/api/action_test.clj
with
48 additions
and
6 deletions
src/metabase/api/action.clj
+
12
−
0
View file @
18bc3f29
...
...
@@ -3,6 +3,7 @@
(
:require
[
compojure.core
:as
compojure
:refer
[
POST
]]
[
metabase.actions
:as
actions
]
[
metabase.actions.execution
:as
actions.execution
]
[
metabase.actions.http-action
:as
http-action
]
[
metabase.api.common
:as
api
]
[
metabase.api.common.validation
:as
validation
]
...
...
@@ -163,4 +164,15 @@
(
db/update!
Action
id
:public_uuid
nil,
:made_public_by_id
nil
)
{
:status
204
,
:body
nil
})
(
api/defendpoint
POST
"/:id/execute"
"Execute the Action.
`parameters` should be the mapped dashboard parameters with values."
[
id
:as
{{
:keys
[
parameters
]
,
:as
_body
}
:body
}]
{
id
pos-int?
parameters
[
:maybe
[
:map-of
:keyword
any?
]]}
(
->
(
action/select-action
:id
id
:archived
false
)
(
api/check-404
)
(
actions.execution/execute-action!
(
update-keys
parameters
name
))))
(
api/define-routes
)
This diff is collapsed.
Click to expand it.
src/metabase/api/public.clj
+
2
−
4
View file @
18bc3f29
...
...
@@ -264,8 +264,7 @@
(
api/defendpoint-schema
POST
"/dashboard/:uuid/dashcard/:dashcard-id/execute"
"Execute the associated Action in the context of a `Dashboard` and `DashboardCard` that includes it.
`parameters` should be the mapped dashboard parameters with values.
`extra_parameters` should be the extra, user entered parameter values."
`parameters` should be the mapped dashboard parameters with values."
[
uuid
dashcard-id
:as
{{
:keys
[
parameters
]
,
:as
_body
}
:body
}]
{
dashcard-id
su/IntGreaterThanZero
parameters
(
s/maybe
{
s/Keyword
s/Any
})}
...
...
@@ -564,8 +563,7 @@
(
api/defendpoint
POST
"/action/:uuid/execute"
"Execute the Action.
`parameters` should be the mapped dashboard parameters with values.
`extra_parameters` should be the extra, user entered parameter values."
`parameters` should be the mapped dashboard parameters with values."
[
uuid
:as
{{
:keys
[
parameters
]
,
:as
_body
}
:body
}]
{
uuid
ms/UUIDString
parameters
[
:maybe
[
:map-of
:keyword
any?
]]}
...
...
This diff is collapsed.
Click to expand it.
test/metabase/api/action_test.clj
+
34
−
2
View file @
18bc3f29
...
...
@@ -2,8 +2,7 @@
(
:require
[
clojure.test
:refer
:all
]
[
metabase.api.action
:as
api.action
]
[
metabase.models
:refer
[
Card
]]
[
metabase.models.action
:refer
[
Action
]]
[
metabase.models
:refer
[
Action
Card
Database
]]
[
metabase.models.user
:as
user
]
[
metabase.test
:as
mt
]
[
metabase.util
:as
u
]
...
...
@@ -364,3 +363,36 @@
(
testing
"Test that we get a 404 if Action doesn't exist"
(
is
(
=
"Not found."
(
mt/user-http-request
:crowberto
:delete
404
(
format
"action/%d/public_link"
Integer/MAX_VALUE
)))))))))
(
deftest
execute-action-test
(
mt/with-actions-test-data-and-actions-enabled
(
mt/with-actions
[{
:keys
[
action-id
]}
unshared-action-opts
]
(
testing
"Action execution"
(
is
(
=?
{
:rows-affected
1
}
(
mt/user-http-request
:crowberto
:post
200
(
format
"action/%s/execute"
action-id
)
{
:parameters
{
:id
1
:name
"European"
}})))))
(
mt/with-actions
[{
:keys
[
action-id
]}
(
assoc
unshared-action-opts
:archived
true
)]
(
testing
"Check that we get a 404 if the action is archived"
(
is
(
=
"Not found."
(
mt/user-http-request
:crowberto
:post
404
(
format
"action/%s/execute"
action-id
)
{
:parameters
{
:id
1
:name
"European"
}})))))
(
mt/with-actions
[{
:keys
[
action-id
]}
unshared-action-opts
]
(
let
[
nonexistent-id
(
inc
(
db/select-one-id
Action
{
:order-by
[[
:id
:desc
]]}))]
(
testing
"Check that we get a 404 if the action doesn't exist"
(
is
(
=
"Not found."
(
mt/user-http-request
:crowberto
:post
404
(
format
"action/%s/execute"
nonexistent-id
)
{
:parameters
{
:id
1
:name
"European"
}})))))
(
testing
"Check that we get a 400 if actions are disabled for the database."
(
mt/with-temp-vals-in-db
Database
(
mt/id
)
{
:settings
{
:database-enable-actions
false
}}
(
is
(
=
"Actions are not enabled."
(
:cause
(
mt/user-http-request
:crowberto
:post
400
(
format
"action/%s/execute"
action-id
)
{
:parameters
{
:id
1
:name
"European"
}})))))))))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment