-
Notifications
You must be signed in to change notification settings - Fork 46
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
Add workflows API to create, get, update and list #2792
Conversation
4adef60
to
d1cda5c
Compare
3a78e2c
to
4830973
Compare
f2d6262
to
bf7cc45
Compare
7dfbc4b
to
85550ce
Compare
0aa06ac
to
8db3687
Compare
8db3687
to
53795a2
Compare
Sorry Joe, previously it was implemented only on the get workflow, now it's done for the index
The reason it's returning 401 Unauthorized it's because the project id is used for ACL. The user could check the project id on 401 but if 404 is really helpful for the user we can add a query or subquery for all operations. In any case I've added the 401 on the spec with a description "User not allowed to access the project" for existing projects.
The arbitrary ids are supported only on the POST because the triggers cannot be replaced. If arbitrary ids are allowed only for jobs we could have a single rule for POST and PUT. However the PUT we need to be aware that all jobs would be replaced and I need to check what is behaviour of the edges on this jobs full update.
On PUT everything is expected to have an id for being an update. It's doable however. |
Take aways from our meeting:
|
According to Stu, the Workflows Policy are prone to be rewriting. This reverts commit 8f2e5b7.
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.
Hey @jyeshe , this looks really great.
There's a comment I've left regarding using if..else
instead of cond
.
Also, there's a conflict on the CHANGELOG
.
defp save_workflow(%{"project_id" => project_id} = params, user) do | ||
active_triggers_count = count_enabled_triggers(params) | ||
|
||
cond do |
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.
Shouldn't we just use if..else
here?
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.
Great work @jyeshe, left some comments; I think at least we need to add the other condition_...
fields to the Edge @derive
property.
lib/lightning/workflows/edge.ex
Outdated
@derive {Jason.Encoder, | ||
only: [ | ||
:id, | ||
:condition_type, | ||
:enabled, | ||
:source_job_id, | ||
:source_trigger_id, | ||
:target_job_id | ||
]} |
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 we also need condition_expression
and condition_label
to allow for JS based conditions no?
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.
Done
msgid "has already been taken" | ||
msgstr "This email address already exists." | ||
msgstr "This value should be unique." |
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.
Is there not a way to make the distinction between emails (in this case) and other uniqueness violations?
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.
It's possible but we gonna need to call a different translation. Opened an issue for identifying and changing on all places of the app to have a specific message for email: #2824
Description
This PR adds an API that allows to create, update, get and list workflows. The authentication uses a Bearer token and the user of the Personal Access Token must belong to the project related to the workflow.
For POST and PUT the body should be a JSON encoded workflow having {name, project_id, edges, jobs, triggers}.
A PATCH can be also used to update a workflow passing only a difference of the fields that needs to be changed.
When certain workflow preconditions are not met, it returns 422 (Unprocessable Entity) with an error message describing the violation:
A POST or PUT or PATCH might also fail if the outcome would be having more active workflows than the limit (when running on the billing app). For this case it also returns a 422 with the message:
"Your plan has reached the limit of active workflows."
Some additional information on protocol syntax in regards to paths and responses:
workflow
workflows
Closes #1887
Validation steps
Create a Personal Access Token (PAT) on Lightning user profile menu and make these curl requests with
authorization: Bearer <the_PAT>
,accept: application/json
andcontent-type: application/json
Example of POST to create using $token and project_id 86a7888e-8a07-4673-9dbf-43ba016dc790
it shall return a JSON in this format: {"error":null,"id":"2eed727b-99a1-4bf8-8312-1ab460f4fd47"}
After that execute curl commands for:
GET /api/projects/:projectId/workflows
GET /api/projects/:projectId/workflows/:workflowId
PUT /api/projects/:projectId/workflows/:workflowId
PATCH /api/projects/:projectId/workflows/:workflowId
Additional notes for the reviewer
Currently PUT and PATCH are handled by the same
update
function so can be used interchangeably until a final validation is added.AI Usage
Please disclose how you've used AI in this work (it's cool, we just want to know!):
You can read more details in our Responsible AI Policy
Pre-submission checklist
:owner
,:admin
,:editor
,:viewer
)