@Summary Get user roles @ID get-user-roles @Security CoderSessionToken @Produce json @Tags Users @Param user path string true "User ID, name, or me" @Success 200 {object} codersdk.User @Router /api/v2/users/{user}/roles [get]
(rw http.ResponseWriter, r *http.Request)
| 1728 | // @Success 200 {object} codersdk.User |
| 1729 | // @Router /api/v2/users/{user}/roles [get] |
| 1730 | func (api *API) userRoles(rw http.ResponseWriter, r *http.Request) { |
| 1731 | ctx := r.Context() |
| 1732 | user := httpmw.UserParam(r) |
| 1733 | |
| 1734 | if !api.Authorize(r, policy.ActionReadPersonal, user) { |
| 1735 | httpapi.ResourceNotFound(rw) |
| 1736 | return |
| 1737 | } |
| 1738 | |
| 1739 | // TODO: Replace this with "GetAuthorizationUserRoles" |
| 1740 | resp := codersdk.UserRoles{ |
| 1741 | Roles: user.RBACRoles, |
| 1742 | OrganizationRoles: make(map[uuid.UUID][]string), |
| 1743 | } |
| 1744 | |
| 1745 | memberships, err := api.Database.OrganizationMembers(ctx, database.OrganizationMembersParams{ |
| 1746 | UserID: user.ID, |
| 1747 | OrganizationID: uuid.Nil, |
| 1748 | IncludeSystem: false, |
| 1749 | GithubUserID: 0, |
| 1750 | }) |
| 1751 | if err != nil { |
| 1752 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 1753 | Message: "Internal error fetching user's organization memberships.", |
| 1754 | Detail: err.Error(), |
| 1755 | }) |
| 1756 | return |
| 1757 | } |
| 1758 | |
| 1759 | for _, mem := range memberships { |
| 1760 | resp.OrganizationRoles[mem.OrganizationMember.OrganizationID] = mem.OrganizationMember.Roles |
| 1761 | } |
| 1762 | |
| 1763 | httpapi.Write(ctx, rw, http.StatusOK, resp) |
| 1764 | } |
| 1765 | |
| 1766 | // @Summary Assign role to user |
| 1767 | // @ID assign-role-to-user |
nothing calls this directly
no test coverage detected