mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
feat(coderd): notify when workspace is marked as dormant (#13868)
This commit is contained in:
@ -23,6 +23,7 @@ import (
|
||||
"github.com/coder/coder/v2/coderd/database/dbauthz"
|
||||
"github.com/coder/coder/v2/coderd/database/dbtime"
|
||||
"github.com/coder/coder/v2/coderd/database/provisionerjobs"
|
||||
"github.com/coder/coder/v2/coderd/dormancy"
|
||||
"github.com/coder/coder/v2/coderd/httpapi"
|
||||
"github.com/coder/coder/v2/coderd/httpmw"
|
||||
"github.com/coder/coder/v2/coderd/rbac"
|
||||
@ -950,6 +951,34 @@ func (api *API) putWorkspaceDormant(rw http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// We don't need to notify the owner if they are the one making the request.
|
||||
if req.Dormant && apiKey.UserID != workspace.OwnerID {
|
||||
initiator, err := api.Database.GetUserByID(ctx, apiKey.UserID)
|
||||
if err != nil {
|
||||
api.Logger.Warn(
|
||||
ctx,
|
||||
"failed to fetch the user that marked the workspace",
|
||||
slog.Error(err),
|
||||
slog.F("workspace_id", workspace.ID),
|
||||
slog.F("user_id", apiKey.UserID),
|
||||
)
|
||||
} else {
|
||||
_, err = dormancy.NotifyWorkspaceDormant(
|
||||
ctx,
|
||||
api.NotificationsEnqueuer,
|
||||
dormancy.WorkspaceDormantNotification{
|
||||
Workspace: workspace,
|
||||
Initiator: initiator.Username,
|
||||
Reason: "requested by user",
|
||||
CreatedBy: "api",
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
api.Logger.Warn(ctx, "failed to notify of workspace marked as dormant", slog.Error(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data, err := api.workspaceData(ctx, []database.Workspace{workspace})
|
||||
if err != nil {
|
||||
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
|
||||
|
Reference in New Issue
Block a user