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

Method AssignableSiteRoles

coderd/roles.go:26–50  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

24// @Success 200 {array} codersdk.AssignableRoles
25// @Router /api/v2/users/roles [get]
26func (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//

Callers

nothing calls this directly

Calls 9

AuthorizeMethod · 0.95
UserAuthorizationFunction · 0.92
ForbiddenFunction · 0.92
InternalServerErrorFunction · 0.92
SiteBuiltInRolesFunction · 0.92
WriteFunction · 0.92
assignableRolesFunction · 0.85
ContextMethod · 0.65
CustomRolesMethod · 0.65

Tested by

no test coverage detected