Skip to content

Commit

Permalink
feat: allow setting the org ID on creation (#4306)
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl authored Feb 13, 2025
1 parent e2f878a commit bccd2fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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

0 comments on commit bccd2fb

Please sign in to comment.