@Summary Get workspace quota by user @ID get-workspace-quota-by-user @Security CoderSessionToken @Produce json @Tags Enterprise @Param user path string true "User ID, name, or me" @Param organization path string true "Organization ID" format(uuid) @Success 200 {object} codersdk.WorkspaceQuota @Route
(rw http.ResponseWriter, r *http.Request)
| 152 | // @Success 200 {object} codersdk.WorkspaceQuota |
| 153 | // @Router /api/v2/organizations/{organization}/members/{user}/workspace-quota [get] |
| 154 | func (api *API) workspaceQuota(rw http.ResponseWriter, r *http.Request) { |
| 155 | var ( |
| 156 | organization = httpmw.OrganizationParam(r) |
| 157 | user = httpmw.UserParam(r) |
| 158 | ) |
| 159 | |
| 160 | licensed := api.Entitlements.Enabled(codersdk.FeatureTemplateRBAC) |
| 161 | |
| 162 | // There are no groups and thus no allowance if RBAC isn't licensed. |
| 163 | var quotaAllowance int64 = -1 |
| 164 | if licensed { |
| 165 | var err error |
| 166 | quotaAllowance, err = api.Database.GetQuotaAllowanceForUser(r.Context(), database.GetQuotaAllowanceForUserParams{ |
| 167 | UserID: user.ID, |
| 168 | OrganizationID: organization.ID, |
| 169 | }) |
| 170 | if err != nil { |
| 171 | httpapi.Write(r.Context(), rw, http.StatusInternalServerError, codersdk.Response{ |
| 172 | Message: "Failed to get allowance", |
| 173 | Detail: err.Error(), |
| 174 | }) |
| 175 | return |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | quotaConsumed, err := api.Database.GetQuotaConsumedForUser(r.Context(), database.GetQuotaConsumedForUserParams{ |
| 180 | OwnerID: user.ID, |
| 181 | OrganizationID: organization.ID, |
| 182 | }) |
| 183 | if err != nil { |
| 184 | httpapi.Write(r.Context(), rw, http.StatusInternalServerError, codersdk.Response{ |
| 185 | Message: "Failed to get consumed", |
| 186 | Detail: err.Error(), |
| 187 | }) |
| 188 | return |
| 189 | } |
| 190 | |
| 191 | httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.WorkspaceQuota{ |
| 192 | CreditsConsumed: int(quotaConsumed), |
| 193 | Budget: int(quotaAllowance), |
| 194 | }) |
| 195 | } |
nothing calls this directly
no test coverage detected