MCPcopy Index your code
hub / github.com/coder/coder / workspaceQuota

Method workspaceQuota

enterprise/coderd/workspacequota.go:154–195  ·  view source on GitHub ↗

@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)

Source from the content-addressed store, hash-verified

152// @Success 200 {object} codersdk.WorkspaceQuota
153// @Router /api/v2/organizations/{organization}/members/{user}/workspace-quota [get]
154func (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}

Callers

nothing calls this directly

Calls 8

OrganizationParamFunction · 0.92
UserParamFunction · 0.92
WriteFunction · 0.92
EnabledMethod · 0.65
ContextMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected