Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions org_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ type OrgUser struct {
Role string `json:"role"`
}

// OrgUsersCurrent returns all org users within the current organization.
// This endpoint is accessible to users with org admin role.
func (c *Client) OrgUsersCurrent() ([]OrgUser, error) {
users := make([]OrgUser, 0)
err := c.request("GET", "/api/org/users", nil, nil, &users)
if err != nil {
return nil, err
}
return users, err
}

// OrgUsers fetches and returns the users for the org whose ID it's passed.
func (c *Client) OrgUsers(orgID int64) ([]OrgUser, error) {
users := make([]OrgUser, 0)
Expand Down
22 changes: 22 additions & 0 deletions org_users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,28 @@ const (
removeOrgUserJSON = `{"message":"User removed from organization"}`
)

func TestOrgUsersCurrent(t *testing.T) {
server, client := gapiTestTools(t, 200, getOrgUsersJSON)
defer server.Close()

resp, err := client.OrgUsersCurrent()
if err != nil {
t.Fatal(err)
}

user := OrgUser{
OrgID: 1,
UserID: 1,
Email: "admin@localhost",
Login: "admin",
Role: "Admin",
}

if resp[0] != user {
t.Error("Not correctly parsing returned organization users.")
}
}

func TestOrgUsers(t *testing.T) {
server, client := gapiTestTools(t, 200, getOrgUsersJSON)
defer server.Close()
Expand Down