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 new organization domain fields #376

Merged
merged 5 commits into from
Nov 11, 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
28 changes: 28 additions & 0 deletions pkg/organizations/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,41 @@ func (c *Client) init() {
}
}

type OrganizationDomainState string

const (
OrganizationDomainPending OrganizationDomainState = "pending"
OrganizationDomainVerified OrganizationDomainState = "verified"
OrganizationDomainFailed OrganizationDomainState = "failed"
OrganizationDomainLegacyVerified OrganizationDomainState = "legacy_verified"
)

type OrganizationDomainVerificationStrategy string

const (
Dns OrganizationDomainVerificationStrategy = "dns"
Manual OrganizationDomainVerificationStrategy = "manual"
)

// OrganizationDomain contains data about an Organization's Domains.
type OrganizationDomain struct {
// The Organization Domain's unique identifier.
ID string `json:"id"`

// The domain value
Domain string `json:"domain"`

// The Organization's unique identifier.
OrganizationID string `json:"organization_id"`

// Verification state of the domain.
State OrganizationDomainState `json:"state"`

// Strategy used to verify the domain.
VerificationStrategy OrganizationDomainVerificationStrategy `json:"verification_strategy,omitempty"`

// Token used for DNS verification.
VerificationToken string `json:"verification_token,omitempty"`
Comment on lines +93 to +97
Copy link
Contributor

@mattgd mattgd Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on your thread, is the ultimate goal to have the domain data on the organization_domain events only, but for now they also reside on the organization events?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh no, I meant that the OrganizationID specifically is mostly useful in the context of organization domain events (since in organization events or the organization API you have the ID already from the parent organization object). it's included by the API in all cases though.

for the other fields, i don't expect VerificationStrategy or VerificationToken to be widely used, but i'm including them for completeness. State on the other hand is generally useful in all cases where this struct would be used

}

// Organization contains data about a WorkOS Organization.
Expand Down
114 changes: 70 additions & 44 deletions pkg/organizations/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ func TestGetOrganization(t *testing.T) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
},
},
Expand Down Expand Up @@ -79,9 +81,11 @@ func getOrganizationTestHandler(w http.ResponseWriter, r *http.Request) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
},
})
Expand Down Expand Up @@ -118,14 +122,16 @@ func TestListOrganizations(t *testing.T) {

expected: ListOrganizationsResponse{
Data: []Organization{
Organization{
{
ID: "organization_id",
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
},
},
Expand Down Expand Up @@ -175,14 +181,16 @@ func listOrganizationsTestHandler(w http.ResponseWriter, r *http.Request) {
}{
ListOrganizationsResponse: ListOrganizationsResponse{
Data: []Organization{
Organization{
{
ID: "organization_id",
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
},
},
Expand Down Expand Up @@ -229,9 +237,11 @@ func TestCreateOrganization(t *testing.T) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
},
},
Expand All @@ -244,7 +254,7 @@ func TestCreateOrganization(t *testing.T) {
options: CreateOrganizationOpts{
Name: "Foo Corp",
DomainData: []OrganizationDomainData{
OrganizationDomainData{
{
Domain: "foo-corp.com",
State: "verified",
},
Expand All @@ -255,9 +265,11 @@ func TestCreateOrganization(t *testing.T) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
},
},
Expand Down Expand Up @@ -346,9 +358,11 @@ func createOrganizationTestHandler(w http.ResponseWriter, r *http.Request) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
},
})
Expand Down Expand Up @@ -390,13 +404,17 @@ func TestUpdateOrganization(t *testing.T) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
OrganizationDomain{
ID: "organization_domain_id_2",
Domain: "foo-corp.io",
{
ID: "organization_domain_id_2",
Domain: "foo-corp.io",
OrganizationID: "organization_id",
State: "verified",
},
},
},
Expand All @@ -410,11 +428,11 @@ func TestUpdateOrganization(t *testing.T) {
Organization: "organization_id",
Name: "Foo Corp",
DomainData: []OrganizationDomainData{
OrganizationDomainData{
{
Domain: "foo-corp.com",
State: "verified",
},
OrganizationDomainData{
{
Domain: "foo-corp.io",
State: "verified",
},
Expand All @@ -425,13 +443,17 @@ func TestUpdateOrganization(t *testing.T) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
OrganizationDomain{
ID: "organization_domain_id_2",
Domain: "foo-corp.io",
{
ID: "organization_domain_id_2",
Domain: "foo-corp.io",
OrganizationID: "organization_id",
State: "verified",
},
},
},
Expand Down Expand Up @@ -497,13 +519,17 @@ func updateOrganizationTestHandler(w http.ResponseWriter, r *http.Request) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
OrganizationDomain{
ID: "organization_domain_id_2",
Domain: "foo-corp.io",
{
ID: "organization_domain_id_2",
Domain: "foo-corp.io",
OrganizationID: "organization_id",
State: "verified",
},
},
})
Expand Down
42 changes: 26 additions & 16 deletions pkg/organizations/organizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ func TestOrganizationsGetOrganization(t *testing.T) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
},
}
Expand All @@ -51,14 +53,16 @@ func TestOrganizationsListOrganizations(t *testing.T) {

expectedResponse := ListOrganizationsResponse{
Data: []Organization{
Organization{
{
ID: "organization_id",
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
},
},
Expand Down Expand Up @@ -93,9 +97,11 @@ func TestOrganizationsCreateOrganization(t *testing.T) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
},
}
Expand Down Expand Up @@ -126,13 +132,17 @@ func TestOrganizationsUpdateOrganization(t *testing.T) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
OrganizationDomain{
ID: "organization_domain_id_2",
Domain: "foo-corp.io",
{
ID: "organization_domain_id_2",
Domain: "foo-corp.io",
OrganizationID: "organization_id",
State: "verified",
},
},
}
Expand Down
Loading