chore: implement api layer for listing organization members (#13546)

This commit is contained in:
Steven Masley
2024-06-12 09:52:18 -10:00
committed by GitHub
parent de9e6889bb
commit bbe23edc7d
10 changed files with 353 additions and 0 deletions
+5
View File
@@ -58,6 +58,11 @@ type OrganizationMember struct {
Roles []SlimRole `db:"roles" json:"roles"`
}
type OrganizationMemberWithName struct {
Username string `table:"username,default_sort" json:"username"`
OrganizationMember `table:"m,recursive_inline"`
}
type CreateOrganizationRequest struct {
Name string `json:"name" validate:"required,organization_name"`
// DisplayName will default to the same value as `Name` if not provided.
+14
View File
@@ -379,6 +379,20 @@ func (c *Client) UpdateUserPassword(ctx context.Context, user string, req Update
return nil
}
// OrganizationMembers lists all members in an organization
func (c *Client) OrganizationMembers(ctx context.Context, organizationID uuid.UUID) ([]OrganizationMemberWithName, error) {
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/organizations/%s/members/", organizationID), nil)
if err != nil {
return nil, err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return nil, ReadBodyAsError(res)
}
var members []OrganizationMemberWithName
return members, json.NewDecoder(res.Body).Decode(&members)
}
// UpdateUserRoles grants the userID the specified roles.
// Include ALL roles the user has.
func (c *Client) UpdateUserRoles(ctx context.Context, user string, req UpdateRoles) (User, error) {