Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Commit 3049c69

Browse files
GET /api/org/users (#31)
Returns all org users within the current organization. Accessible to users with org admin role. This is not an admin org endpoint so basic auth is not required.
1 parent e23a0e0 commit 3049c69

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

org_users.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ type OrgUser struct {
1515
Role string `json:"role"`
1616
}
1717

18+
// OrgUsersCurrent returns all org users within the current organization.
19+
// This endpoint is accessible to users with org admin role.
20+
func (c *Client) OrgUsersCurrent() ([]OrgUser, error) {
21+
users := make([]OrgUser, 0)
22+
err := c.request("GET", "/api/org/users", nil, nil, &users)
23+
if err != nil {
24+
return nil, err
25+
}
26+
return users, err
27+
}
28+
1829
// OrgUsers fetches and returns the users for the org whose ID it's passed.
1930
func (c *Client) OrgUsers(orgID int64) ([]OrgUser, error) {
2031
users := make([]OrgUser, 0)

org_users_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,28 @@ const (
1313
removeOrgUserJSON = `{"message":"User removed from organization"}`
1414
)
1515

16+
func TestOrgUsersCurrent(t *testing.T) {
17+
server, client := gapiTestTools(t, 200, getOrgUsersJSON)
18+
defer server.Close()
19+
20+
resp, err := client.OrgUsersCurrent()
21+
if err != nil {
22+
t.Fatal(err)
23+
}
24+
25+
user := OrgUser{
26+
OrgID: 1,
27+
UserID: 1,
28+
Email: "admin@localhost",
29+
Login: "admin",
30+
Role: "Admin",
31+
}
32+
33+
if resp[0] != user {
34+
t.Error("Not correctly parsing returned organization users.")
35+
}
36+
}
37+
1638
func TestOrgUsers(t *testing.T) {
1739
server, client := gapiTestTools(t, 200, getOrgUsersJSON)
1840
defer server.Close()

0 commit comments

Comments
 (0)