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

feat: allow setting the org ID on creation #4306

Merged
merged 1 commit into from
Feb 13, 2025
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 identity/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,11 @@ type CreateIdentityBody struct {
//
// required: false
State State `json:"state"`

// OrganizationID is the ID of the organization to which the identity belongs.
//
// required: false
OrganizationID uuid.NullUUID `json:"organization_id"`
}

// Create Identity and Import Credentials
Expand Down Expand Up @@ -576,6 +581,7 @@ func (h *Handler) identityFromCreateIdentityBody(ctx context.Context, cr *Create
RecoveryAddresses: cr.RecoveryAddresses,
MetadataAdmin: []byte(cr.MetadataAdmin),
MetadataPublic: []byte(cr.MetadataPublic),
OrganizationID: cr.OrganizationID,
}
// Lowercase all emails, because the schema extension will otherwise not find them.
for k := range i.VerifiableAddresses {
Expand Down
14 changes: 14 additions & 0 deletions identity/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,20 @@ func TestHandler(t *testing.T) {
}
})

t.Run("case=should create an identity with an organization ID", func(t *testing.T) {
for name, ts := range map[string]*httptest.Server{"public": publicTS, "admin": adminTS} {
t.Run("endpoint="+name, func(t *testing.T) {
orgID := uuid.NullUUID{x.NewUUID(), true}
i := identity.CreateIdentityBody{
Traits: []byte(`{"bar":"baz"}`),
OrganizationID: orgID,
}
res := send(t, ts, "POST", "/identities", http.StatusCreated, &i)
assert.EqualValues(t, orgID.UUID.String(), res.Get("organization_id").String(), "%s", res.Raw)
})
}
})

t.Run("case=should be able to import users", func(t *testing.T) {
ignoreDefault := []string{"id", "schema_url", "state_changed_at", "created_at", "updated_at"}
t.Run("without any credentials", func(t *testing.T) {
Expand Down
Loading