Skip to content

Commit 05b9c36

Browse files
authored
Add role to directory sync user (#339)
Add role to directory sync user
1 parent 35ebb01 commit 05b9c36

File tree

7 files changed

+32
-12
lines changed

7 files changed

+32
-12
lines changed

pkg/common/role.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package common
2+
3+
type RoleResponse struct {
4+
// The slug of the role
5+
Slug string `json:"slug"`
6+
}

pkg/directorysync/client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ type User struct {
131131

132132
// The User's updated at date
133133
UpdatedAt string `json:"updated_at"`
134+
135+
// The role given to this Directory User
136+
Role common.RoleResponse `json:"role,omitempty"`
134137
}
135138

136139
// ListUsersOpts contains the options to request provisioned Directory Users.

pkg/directorysync/client_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ func TestListUsers(t *testing.T) {
5757
State: Active,
5858
RawAttributes: json.RawMessage(`{"foo":"bar"}`),
5959
CustomAttributes: json.RawMessage(`{"foo":"bar"}`),
60+
Role: common.RoleResponse{
61+
Slug: "member",
62+
},
6063
},
6164
},
6265
ListMetadata: common.ListMetadata{
@@ -126,6 +129,7 @@ func listUsersTestHandler(w http.ResponseWriter, r *http.Request) {
126129
State: Active,
127130
RawAttributes: json.RawMessage(`{"foo":"bar"}`),
128131
CustomAttributes: json.RawMessage(`{"foo":"bar"}`),
132+
Role: common.RoleResponse{Slug: "member"},
129133
},
130134
},
131135
ListMetadata: common.ListMetadata{
@@ -291,6 +295,7 @@ func TestGetUser(t *testing.T) {
291295
State: Active,
292296
RawAttributes: json.RawMessage(`{"foo":"bar"}`),
293297
CustomAttributes: json.RawMessage(`{"foo":"bar"}`),
298+
Role: common.RoleResponse{Slug: "member"},
294299
},
295300
},
296301
}
@@ -349,6 +354,7 @@ func getUserTestHandler(w http.ResponseWriter, r *http.Request) {
349354
State: Active,
350355
RawAttributes: json.RawMessage(`{"foo":"bar"}`),
351356
CustomAttributes: json.RawMessage(`{"foo":"bar"}`),
357+
Role: common.RoleResponse{Slug: "member"},
352358
})
353359
if err != nil {
354360
w.WriteHeader(http.StatusInternalServerError)

pkg/directorysync/directorysync_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ func TestDirectorySyncListUsers(t *testing.T) {
2121
}
2222
SetAPIKey("test")
2323

24+
expectedRole := common.RoleResponse{
25+
Slug: "member",
26+
}
27+
2428
expectedResponse := ListUsersResponse{
2529
Data: []User{
2630
User{
@@ -45,6 +49,7 @@ func TestDirectorySyncListUsers(t *testing.T) {
4549
State: Active,
4650
RawAttributes: json.RawMessage(`{"foo":"bar"}`),
4751
CustomAttributes: json.RawMessage(`{"foo":"bar"}`),
52+
Role: expectedRole,
4853
},
4954
},
5055
ListMetadata: common.ListMetadata{
@@ -109,6 +114,10 @@ func TestDirectorySyncGetUser(t *testing.T) {
109114
}
110115
SetAPIKey("test")
111116

117+
expectedRole := common.RoleResponse{
118+
Slug: "member",
119+
}
120+
112121
expectedResponse := User{
113122
ID: "directory_user_id",
114123
FirstName: "Rick",
@@ -131,6 +140,7 @@ func TestDirectorySyncGetUser(t *testing.T) {
131140
State: Active,
132141
RawAttributes: json.RawMessage(`{"foo":"bar"}`),
133142
CustomAttributes: json.RawMessage(`{"foo":"bar"}`),
143+
Role: expectedRole,
134144
}
135145
directoryUserResponse, err := GetUser(context.Background(), GetUserOpts{
136146
User: "directory_user_id",

pkg/usermanagement/client.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,6 @@ const (
113113
PendingOrganizationMembership OrganizationMembershipStatus = "pending"
114114
)
115115

116-
type RoleResponse struct {
117-
// The slug of the role
118-
Slug string `json:"slug"`
119-
}
120-
121116
// OrganizationMembership contains data about a particular OrganizationMembership.
122117
type OrganizationMembership struct {
123118
// The Organization Membership's unique identifier.
@@ -130,7 +125,7 @@ type OrganizationMembership struct {
130125
OrganizationID string `json:"organization_id"`
131126

132127
// The role given to this Organization Membership
133-
Role RoleResponse `json:"role"`
128+
Role common.RoleResponse `json:"role"`
134129

135130
// The Status of the Organization.
136131
Status OrganizationMembershipStatus `json:"status"`

pkg/usermanagement/client_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,7 +2313,7 @@ func TestCreateOrganizationMembership(t *testing.T) {
23132313
UserID: "user_01E4ZCR3C5A4QZ2Z2JQXGKZJ9E",
23142314
OrganizationID: "org_01E4ZCR3C56J083X43JQXF3JK5",
23152315
Status: Active,
2316-
Role: RoleResponse{
2316+
Role: common.RoleResponse{
23172317
Slug: "member",
23182318
},
23192319
CreatedAt: "2021-06-25T19:07:33.155Z",
@@ -2358,7 +2358,7 @@ func createOrganizationMembershipTestHandler(w http.ResponseWriter, r *http.Requ
23582358
UserID: "user_01E4ZCR3C5A4QZ2Z2JQXGKZJ9E",
23592359
OrganizationID: "org_01E4ZCR3C56J083X43JQXF3JK5",
23602360
Status: Active,
2361-
Role: RoleResponse{
2361+
Role: common.RoleResponse{
23622362
Slug: "member",
23632363
},
23642364
CreatedAt: "2021-06-25T19:07:33.155Z",
@@ -2401,7 +2401,7 @@ func TestUpdateOrganizationMembership(t *testing.T) {
24012401
UserID: "user_01E4ZCR3C5A4QZ2Z2JQXGKZJ9E",
24022402
OrganizationID: "org_01E4ZCR3C56J083X43JQXF3JK5",
24032403
Status: Active,
2404-
Role: RoleResponse{
2404+
Role: common.RoleResponse{
24052405
Slug: "member",
24062406
},
24072407
CreatedAt: "2021-06-25T19:07:33.155Z",
@@ -2446,7 +2446,7 @@ func updateOrganizationMembershipTestHandler(w http.ResponseWriter, r *http.Requ
24462446
UserID: "user_01E4ZCR3C5A4QZ2Z2JQXGKZJ9E",
24472447
OrganizationID: "org_01E4ZCR3C56J083X43JQXF3JK5",
24482448
Status: Active,
2449-
Role: RoleResponse{
2449+
Role: common.RoleResponse{
24502450
Slug: "member",
24512451
},
24522452
CreatedAt: "2021-06-25T19:07:33.155Z",

pkg/usermanagement/usermanagement_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ func TestUserManagementCreateOrganizationMembership(t *testing.T) {
767767

768768
SetAPIKey("test")
769769

770-
expectedRole := RoleResponse{
770+
expectedRole := common.RoleResponse{
771771
Slug: "member",
772772
}
773773

@@ -814,7 +814,7 @@ func TestUsersUpdateOrganizationMembership(t *testing.T) {
814814

815815
SetAPIKey("test")
816816

817-
expectedRole := RoleResponse{
817+
expectedRole := common.RoleResponse{
818818
Slug: "member",
819819
}
820820

0 commit comments

Comments
 (0)