@Summary Update workspace automatic updates by ID @ID update-workspace-automatic-updates-by-id @Security CoderSessionToken @Accept json @Tags Workspaces @Param workspace path string true "Workspace ID" format(uuid) @Param request body codersdk.UpdateWorkspaceAutomaticUpdatesRequest true "Automatic u
(rw http.ResponseWriter, r *http.Request)
| 1932 | // @Success 204 |
| 1933 | // @Router /api/v2/workspaces/{workspace}/autoupdates [put] |
| 1934 | func (api *API) putWorkspaceAutoupdates(rw http.ResponseWriter, r *http.Request) { |
| 1935 | var ( |
| 1936 | ctx = r.Context() |
| 1937 | workspace = httpmw.WorkspaceParam(r) |
| 1938 | auditor = api.Auditor.Load() |
| 1939 | aReq, commitAudit = audit.InitRequest[database.WorkspaceTable](rw, &audit.RequestParams{ |
| 1940 | Audit: *auditor, |
| 1941 | Log: api.Logger, |
| 1942 | Request: r, |
| 1943 | Action: database.AuditActionWrite, |
| 1944 | OrganizationID: workspace.OrganizationID, |
| 1945 | }) |
| 1946 | ) |
| 1947 | defer commitAudit() |
| 1948 | aReq.Old = workspace.WorkspaceTable() |
| 1949 | |
| 1950 | var req codersdk.UpdateWorkspaceAutomaticUpdatesRequest |
| 1951 | if !httpapi.Read(ctx, rw, r, &req) { |
| 1952 | return |
| 1953 | } |
| 1954 | |
| 1955 | if !database.AutomaticUpdates(req.AutomaticUpdates).Valid() { |
| 1956 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 1957 | Message: "Invalid request", |
| 1958 | Validations: []codersdk.ValidationError{{Field: "automatic_updates", Detail: "must be always or never"}}, |
| 1959 | }) |
| 1960 | return |
| 1961 | } |
| 1962 | |
| 1963 | err := api.Database.UpdateWorkspaceAutomaticUpdates(ctx, database.UpdateWorkspaceAutomaticUpdatesParams{ |
| 1964 | ID: workspace.ID, |
| 1965 | AutomaticUpdates: database.AutomaticUpdates(req.AutomaticUpdates), |
| 1966 | }) |
| 1967 | if httpapi.Is404Error(err) { |
| 1968 | httpapi.ResourceNotFound(rw) |
| 1969 | return |
| 1970 | } |
| 1971 | if err != nil { |
| 1972 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 1973 | Message: "Internal error updating workspace automatic updates setting", |
| 1974 | Detail: err.Error(), |
| 1975 | }) |
| 1976 | return |
| 1977 | } |
| 1978 | |
| 1979 | newWorkspace := workspace |
| 1980 | newWorkspace.AutomaticUpdates = database.AutomaticUpdates(req.AutomaticUpdates) |
| 1981 | aReq.New = newWorkspace.WorkspaceTable() |
| 1982 | |
| 1983 | rw.WriteHeader(http.StatusNoContent) |
| 1984 | } |
| 1985 | |
| 1986 | // @Summary Resolve workspace autostart by id. |
| 1987 | // @ID resolve-workspace-autostart-by-id |
nothing calls this directly
no test coverage detected