Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add role to directory sync user #339

Merged
merged 5 commits into from
May 28, 2024
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
6 changes: 6 additions & 0 deletions pkg/common/role.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package common

type RoleResponse struct {
// The slug of the role
Slug string `json:"slug"`
}
3 changes: 3 additions & 0 deletions pkg/directorysync/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ type User struct {

// The User's updated at date
UpdatedAt string `json:"updated_at"`

// The role given to this Directory User
Role common.RoleResponse `json:"role,omitempty"`
}

// ListUsersOpts contains the options to request provisioned Directory Users.
Expand Down
6 changes: 6 additions & 0 deletions pkg/directorysync/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func TestListUsers(t *testing.T) {
State: Active,
RawAttributes: json.RawMessage(`{"foo":"bar"}`),
CustomAttributes: json.RawMessage(`{"foo":"bar"}`),
Role: common.RoleResponse{
Slug: "member",
},
},
},
ListMetadata: common.ListMetadata{
Expand Down Expand Up @@ -126,6 +129,7 @@ func listUsersTestHandler(w http.ResponseWriter, r *http.Request) {
State: Active,
RawAttributes: json.RawMessage(`{"foo":"bar"}`),
CustomAttributes: json.RawMessage(`{"foo":"bar"}`),
Role: common.RoleResponse{Slug: "member"},
},
},
ListMetadata: common.ListMetadata{
Expand Down Expand Up @@ -291,6 +295,7 @@ func TestGetUser(t *testing.T) {
State: Active,
RawAttributes: json.RawMessage(`{"foo":"bar"}`),
CustomAttributes: json.RawMessage(`{"foo":"bar"}`),
Role: common.RoleResponse{Slug: "member"},
},
},
}
Expand Down Expand Up @@ -349,6 +354,7 @@ func getUserTestHandler(w http.ResponseWriter, r *http.Request) {
State: Active,
RawAttributes: json.RawMessage(`{"foo":"bar"}`),
CustomAttributes: json.RawMessage(`{"foo":"bar"}`),
Role: common.RoleResponse{Slug: "member"},
})
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
Expand Down
10 changes: 10 additions & 0 deletions pkg/directorysync/directorysync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func TestDirectorySyncListUsers(t *testing.T) {
}
SetAPIKey("test")

expectedRole := common.RoleResponse{
Slug: "member",
}

expectedResponse := ListUsersResponse{
Data: []User{
User{
Expand All @@ -45,6 +49,7 @@ func TestDirectorySyncListUsers(t *testing.T) {
State: Active,
RawAttributes: json.RawMessage(`{"foo":"bar"}`),
CustomAttributes: json.RawMessage(`{"foo":"bar"}`),
Role: expectedRole,
},
},
ListMetadata: common.ListMetadata{
Expand Down Expand Up @@ -109,6 +114,10 @@ func TestDirectorySyncGetUser(t *testing.T) {
}
SetAPIKey("test")

expectedRole := common.RoleResponse{
Slug: "member",
}

expectedResponse := User{
ID: "directory_user_id",
FirstName: "Rick",
Expand All @@ -131,6 +140,7 @@ func TestDirectorySyncGetUser(t *testing.T) {
State: Active,
RawAttributes: json.RawMessage(`{"foo":"bar"}`),
CustomAttributes: json.RawMessage(`{"foo":"bar"}`),
Role: expectedRole,
}
directoryUserResponse, err := GetUser(context.Background(), GetUserOpts{
User: "directory_user_id",
Expand Down
7 changes: 1 addition & 6 deletions pkg/usermanagement/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ const (
PendingOrganizationMembership OrganizationMembershipStatus = "pending"
)

type RoleResponse struct {
// The slug of the role
Slug string `json:"slug"`
}

// OrganizationMembership contains data about a particular OrganizationMembership.
type OrganizationMembership struct {
// The Organization Membership's unique identifier.
Expand All @@ -109,7 +104,7 @@ type OrganizationMembership struct {
OrganizationID string `json:"organization_id"`

// The role given to this Organization Membership
Role RoleResponse `json:"role"`
Role common.RoleResponse `json:"role"`

// The Status of the Organization.
Status OrganizationMembershipStatus `json:"status"`
Expand Down
8 changes: 4 additions & 4 deletions pkg/usermanagement/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2068,7 +2068,7 @@ func TestCreateOrganizationMembership(t *testing.T) {
UserID: "user_01E4ZCR3C5A4QZ2Z2JQXGKZJ9E",
OrganizationID: "org_01E4ZCR3C56J083X43JQXF3JK5",
Status: Active,
Role: RoleResponse{
Role: common.RoleResponse{
Slug: "member",
},
CreatedAt: "2021-06-25T19:07:33.155Z",
Expand Down Expand Up @@ -2113,7 +2113,7 @@ func createOrganizationMembershipTestHandler(w http.ResponseWriter, r *http.Requ
UserID: "user_01E4ZCR3C5A4QZ2Z2JQXGKZJ9E",
OrganizationID: "org_01E4ZCR3C56J083X43JQXF3JK5",
Status: Active,
Role: RoleResponse{
Role: common.RoleResponse{
Slug: "member",
},
CreatedAt: "2021-06-25T19:07:33.155Z",
Expand Down Expand Up @@ -2156,7 +2156,7 @@ func TestUpdateOrganizationMembership(t *testing.T) {
UserID: "user_01E4ZCR3C5A4QZ2Z2JQXGKZJ9E",
OrganizationID: "org_01E4ZCR3C56J083X43JQXF3JK5",
Status: Active,
Role: RoleResponse{
Role: common.RoleResponse{
Slug: "member",
},
CreatedAt: "2021-06-25T19:07:33.155Z",
Expand Down Expand Up @@ -2201,7 +2201,7 @@ func updateOrganizationMembershipTestHandler(w http.ResponseWriter, r *http.Requ
UserID: "user_01E4ZCR3C5A4QZ2Z2JQXGKZJ9E",
OrganizationID: "org_01E4ZCR3C56J083X43JQXF3JK5",
Status: Active,
Role: RoleResponse{
Role: common.RoleResponse{
Slug: "member",
},
CreatedAt: "2021-06-25T19:07:33.155Z",
Expand Down
4 changes: 2 additions & 2 deletions pkg/usermanagement/usermanagement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ func TestUserManagementCreateOrganizationMembership(t *testing.T) {

SetAPIKey("test")

expectedRole := RoleResponse{
expectedRole := common.RoleResponse{
Slug: "member",
}

Expand Down Expand Up @@ -737,7 +737,7 @@ func TestUsersUpdateOrganizationMembership(t *testing.T) {

SetAPIKey("test")

expectedRole := RoleResponse{
expectedRole := common.RoleResponse{
Slug: "member",
}

Expand Down
Loading