refactor: Add roles into the user response (#1347)

This commit is contained in:
Bruno Quaresma
2022-05-09 16:38:14 +00:00
committed by GitHub
parent ad8d9dd71a
commit e54324d880
10 changed files with 74 additions and 37 deletions
+6 -5
View File
@@ -45,6 +45,7 @@ type User struct {
Username string `json:"username" validate:"required"`
Status UserStatus `json:"status"`
OrganizationIDs []uuid.UUID `json:"organization_ids"`
Roles []Role `json:"roles"`
}
type CreateFirstUserRequest struct {
@@ -216,17 +217,17 @@ func (c *Client) UpdateUserRoles(ctx context.Context, userID uuid.UUID, req Upda
// UpdateOrganizationMemberRoles grants the userID the specified roles in an org.
// Include ALL roles the user has.
func (c *Client) UpdateOrganizationMemberRoles(ctx context.Context, organizationID, userID uuid.UUID, req UpdateRoles) (User, error) {
func (c *Client) UpdateOrganizationMemberRoles(ctx context.Context, organizationID, userID uuid.UUID, req UpdateRoles) (OrganizationMember, error) {
res, err := c.request(ctx, http.MethodPut, fmt.Sprintf("/api/v2/organizations/%s/members/%s/roles", organizationID, uuidOrMe(userID)), req)
if err != nil {
return User{}, err
return OrganizationMember{}, err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return User{}, readBodyAsError(res)
return OrganizationMember{}, readBodyAsError(res)
}
var user User
return user, json.NewDecoder(res.Body).Decode(&user)
var member OrganizationMember
return member, json.NewDecoder(res.Body).Decode(&member)
}
// GetUserRoles returns all roles the user has