@@ -3,20 +3,47 @@ package coder
3
3
import (
4
4
"context"
5
5
"net/http"
6
+ "time"
6
7
)
7
8
8
- // Org describes an Organization in Coder
9
- type Org struct {
10
- ID string `json:"id"`
11
- Name string `json:"name"`
12
- Members []User `json:"members"`
9
+ // Organization describes an Organization in Coder
10
+ type Organization struct {
11
+ ID string `json:"id"`
12
+ Name string `json:"name"`
13
+ Members []OrganizationUser `json:"members"`
13
14
}
14
15
15
- // Orgs gets all Organizations
16
- func (c Client ) Orgs (ctx context.Context ) ([]Org , error ) {
17
- var orgs []Org
16
+ // OrganizationUser user wraps the basic User type and adds data specific to the user's membership of an organization
17
+ type OrganizationUser struct {
18
+ User
19
+ OrganizationRoles []OrganizationRole `json:"organization_roles"`
20
+ RolesUpdatedAt time.Time `json:"roles_updated_at"`
21
+ }
22
+
23
+ // OrganizationRole defines an organization OrganizationRole
24
+ type OrganizationRole string
25
+
26
+ // The OrganizationRole enum values
27
+ const (
28
+ RoleOrgMember OrganizationRole = "organization-member"
29
+ RoleOrgAdmin OrganizationRole = "organization-admin"
30
+ RoleOrgManager OrganizationRole = "organization-manager"
31
+ )
32
+
33
+ // Organizations gets all Organizations
34
+ func (c Client ) Organizations (ctx context.Context ) ([]Organization , error ) {
35
+ var orgs []Organization
18
36
if err := c .requestBody (ctx , http .MethodGet , "/api/orgs" , nil , & orgs ); err != nil {
19
37
return nil , err
20
38
}
21
39
return orgs , nil
22
40
}
41
+
42
+ // OrgMembers get all members of the given organization
43
+ func (c Client ) OrgMembers (ctx context.Context , orgID string ) ([]OrganizationUser , error ) {
44
+ var members []OrganizationUser
45
+ if err := c .requestBody (ctx , http .MethodGet , "/api/orgs/" + orgID + "/members" , nil , & members ); err != nil {
46
+ return nil , err
47
+ }
48
+ return members , nil
49
+ }
0 commit comments