-
Notifications
You must be signed in to change notification settings - Fork 875
feat: Allow user to cancel workspace jobs #5115
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
Conversation
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.
The code looks good. Just a few things:
- I think you could use the field helper
{...getFieldHelpers("name")}
if it makes sense and works just to keep consistency - Would be nice to add this field to the form schema in line
47
I just commented on a few things but it is up to you.
Thank you for the review, Bruno.
Checkbox doesn't have property For reference:
Good catch! Fixed. |
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.
Backend looks good 👍, a few minor suggestions.
coderd/database/migrations/000081_template_allow_user_cancel_workspace_jobs.up.sql
Show resolved
Hide resolved
@@ -599,6 +604,21 @@ func (api *API) patchCancelWorkspaceBuild(rw http.ResponseWriter, r *http.Reques | |||
return | |||
} | |||
|
|||
valid, err := api.verifyUserCanCancelWorkspaceBuilds(ctx, httpmw.APIKey(r).UserID, workspace.TemplateID) | |||
if err != nil { | |||
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
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.
Suggestion: Both errors returned by verify seem like known states and caused by a user doing a nonsense request (vs. server making a mistake), maybe unauthorized would be a good response?
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.
Unauthorized might be misleading while debugging potential customer issues. In theory, we don't expect an invalid user or an invalid template, and it doesn't look possible that the user passes it, hence an internal error.
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.
Good points. After a second look I agree, didn't look closely enough at the inputs at first. 👍🏻
codersdk/templates.go
Outdated
Description string `json:"description,omitempty"` | ||
Icon string `json:"icon,omitempty"` | ||
DefaultTTLMillis int64 `json:"default_ttl_ms,omitempty"` | ||
AllowUserCancelWorkspaceJobs bool `json:"allow_user_cancel_workspace_jobs"` |
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.
Should this be *bool
as well so the value doesn’t need to be provided every request?
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.
Frankly speaking, I would leave it as is and fix it as part of #5066. This is the outcome of API design. If I fix it here, it will be confusing for customers (optional params vs ""
).
Fixes: #5035
This PR adds a condition to
workspacebuilds
to allow/block cancel requests to workspace jobs. If the flagallow_user_cancel_workspace_jobs
is disabled, only users with the "owner" role can cancel jobs.Detailed changes:
allow_user_cancel_workspace_jobs
(default: true)workspacebuilds
Screenshots: