AssignableSiteRoles returns all site wide roles that can be assigned. @Summary Get site member roles @ID get-site-member-roles @Security CoderSessionToken @Produce json @Tags Members @Success 200 {array} codersdk.AssignableRoles @Router /api/v2/users/roles [get]
(rw http.ResponseWriter, r *http.Request)
| 24 | // @Success 200 {array} codersdk.AssignableRoles |
| 25 | // @Router /api/v2/users/roles [get] |
| 26 | func (api *API) AssignableSiteRoles(rw http.ResponseWriter, r *http.Request) { |
| 27 | ctx := r.Context() |
| 28 | actorRoles := httpmw.UserAuthorization(r.Context()) |
| 29 | if !api.Authorize(r, policy.ActionRead, rbac.ResourceAssignRole) { |
| 30 | httpapi.Forbidden(rw) |
| 31 | return |
| 32 | } |
| 33 | |
| 34 | dbCustomRoles, err := api.Database.CustomRoles(ctx, database.CustomRolesParams{ |
| 35 | LookupRoles: nil, |
| 36 | // Only site wide custom roles to be included |
| 37 | ExcludeOrgRoles: true, |
| 38 | OrganizationID: uuid.Nil, |
| 39 | IncludeSystemRoles: false, |
| 40 | }) |
| 41 | if err != nil { |
| 42 | httpapi.InternalServerError(rw, err) |
| 43 | return |
| 44 | } |
| 45 | |
| 46 | siteRoles := rbac.SiteBuiltInRoles() |
| 47 | |
| 48 | httpapi.Write(ctx, rw, http.StatusOK, |
| 49 | assignableRoles(actorRoles.Roles, siteRoles, dbCustomRoles)) |
| 50 | } |
| 51 | |
| 52 | // assignableOrgRoles returns all org wide roles that can be assigned. |
| 53 | // |
nothing calls this directly
no test coverage detected