From d5a228bb4b893e4b48bfaebbeacd39b5ae1ad3fb Mon Sep 17 00:00:00 2001 From: Iraq Jaber Date: Tue, 22 Jul 2025 14:51:14 +0100 Subject: [PATCH] changed idp repo interface to use a pointer for orgID --- backend/v3/domain/id_provider.go | 6 +++--- .../migration/003_identity_providers_table/up.sql | 8 ++++---- .../v3/storage/database/repository/id_provider.go | 12 ++++++------ .../database/repository/id_provider_test.go | 14 +++++++------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/backend/v3/domain/id_provider.go b/backend/v3/domain/id_provider.go index 05dfe9b9e5..04c4d89af6 100644 --- a/backend/v3/domain/id_provider.go +++ b/backend/v3/domain/id_provider.go @@ -101,10 +101,10 @@ type IDProviderRepository interface { idProviderConditions idProviderChanges - Get(ctx context.Context, id IDPIdentifierCondition, instnaceID string, orgID string) (*IdentityProvider, error) + Get(ctx context.Context, id IDPIdentifierCondition, instnaceID string, orgID *string) (*IdentityProvider, error) List(ctx context.Context, conditions ...database.Condition) ([]*IdentityProvider, error) Create(ctx context.Context, idp *IdentityProvider) error - Update(ctx context.Context, id IDPIdentifierCondition, instnaceID string, orgID string, changes ...database.Change) (int64, error) - Delete(ctx context.Context, id IDPIdentifierCondition, instnaceID string, orgID string) (int64, error) + Update(ctx context.Context, id IDPIdentifierCondition, instnaceID string, orgID *string, changes ...database.Change) (int64, error) + Delete(ctx context.Context, id IDPIdentifierCondition, instnaceID string, orgID *string) (int64, error) } diff --git a/backend/v3/storage/database/dialect/postgres/migration/003_identity_providers_table/up.sql b/backend/v3/storage/database/dialect/postgres/migration/003_identity_providers_table/up.sql index c1bddccb64..a21ba939de 100644 --- a/backend/v3/storage/database/dialect/postgres/migration/003_identity_providers_table/up.sql +++ b/backend/v3/storage/database/dialect/postgres/migration/003_identity_providers_table/up.sql @@ -1,9 +1,9 @@ -CREATE TYPE idp_state AS ENUM ( +CREATE TYPE zitadel.idp_state AS ENUM ( 'active', 'inactive' ); -CREATE TYPE idp_type AS ENUM ( +CREATE TYPE zitadel.idp_type AS ENUM ( 'oidc', 'oauth', 'saml', @@ -18,9 +18,9 @@ CREATE TABLE zitadel.identity_providers ( instance_id TEXT NOT NULL , org_id TEXT , id TEXT NOT NULL CHECK (id <> '') - , state idp_state NOT NULL DEFAULT 'active' + , state zitadel.idp_state NOT NULL DEFAULT 'active' , name TEXT NOT NULL CHECK (name <> '') - , type idp_type NOT NULL + , type zitadel.idp_type NOT NULL , allow_creation BOOLEAN NOT NULL DEFAULT TRUE , allow_auto_creation BOOLEAN NOT NULL DEFAULT TRUE , allow_auto_update BOOLEAN NOT NULL DEFAULT TRUE diff --git a/backend/v3/storage/database/repository/id_provider.go b/backend/v3/storage/database/repository/id_provider.go index 9b0f82d6e3..23317b8810 100644 --- a/backend/v3/storage/database/repository/id_provider.go +++ b/backend/v3/storage/database/repository/id_provider.go @@ -26,12 +26,12 @@ const queryIDProviderStmt = `SELECT instance_id, org_id, id, state, name, type, ` allow_auto_update, allow_linking, styling_type, payload, created_at, updated_at` + ` FROM zitadel.identity_providers` -func (i *idProvider) Get(ctx context.Context, id domain.IDPIdentifierCondition, instnaceID string, orgID string) (*domain.IdentityProvider, error) { +func (i *idProvider) Get(ctx context.Context, id domain.IDPIdentifierCondition, instnaceID string, orgID *string) (*domain.IdentityProvider, error) { builder := database.StatementBuilder{} builder.WriteString(queryIDProviderStmt) - conditions := []database.Condition{id, i.InstanceIDCondition(instnaceID), i.OrgIDCondition(orgID)} + conditions := []database.Condition{id, i.InstanceIDCondition(instnaceID), i.OrgIDCondition(*orgID)} writeCondition(&builder, database.And(conditions...)) @@ -83,7 +83,7 @@ func (i *idProvider) Create(ctx context.Context, idp *domain.IdentityProvider) e return nil } -func (i *idProvider) Update(ctx context.Context, id domain.IDPIdentifierCondition, instnaceID string, orgID string, changes ...database.Change) (int64, error) { +func (i *idProvider) Update(ctx context.Context, id domain.IDPIdentifierCondition, instnaceID string, orgID *string, changes ...database.Change) (int64, error) { if changes == nil { return 0, errors.New("Update must contain at least one change") } @@ -93,7 +93,7 @@ func (i *idProvider) Update(ctx context.Context, id domain.IDPIdentifierConditio conditions := []database.Condition{ id, i.InstanceIDCondition(instnaceID), - i.OrgIDCondition(orgID), + i.OrgIDCondition(*orgID), } database.Changes(changes).Write(&builder) writeCondition(&builder, database.And(conditions...)) @@ -103,7 +103,7 @@ func (i *idProvider) Update(ctx context.Context, id domain.IDPIdentifierConditio return i.client.Exec(ctx, stmt, builder.Args()...) } -func (i *idProvider) Delete(ctx context.Context, id domain.IDPIdentifierCondition, instnaceID string, orgID string) (int64, error) { +func (i *idProvider) Delete(ctx context.Context, id domain.IDPIdentifierCondition, instnaceID string, orgID *string) (int64, error) { builder := database.StatementBuilder{} builder.WriteString(`DELETE FROM zitadel.identity_providers`) @@ -111,7 +111,7 @@ func (i *idProvider) Delete(ctx context.Context, id domain.IDPIdentifierConditio conditions := []database.Condition{ id, i.InstanceIDCondition(instnaceID), - i.OrgIDCondition(orgID), + i.OrgIDCondition(*orgID), } writeCondition(&builder, database.And(conditions...)) diff --git a/backend/v3/storage/database/repository/id_provider_test.go b/backend/v3/storage/database/repository/id_provider_test.go index d438af1614..8e704a47e0 100644 --- a/backend/v3/storage/database/repository/id_provider_test.go +++ b/backend/v3/storage/database/repository/id_provider_test.go @@ -330,7 +330,7 @@ func TestCreateIDProvider(t *testing.T) { idp, err = idpRepo.Get(ctx, idpRepo.IDCondition(idp.ID), idp.InstanceID, - idp.OrgID, + &idp.OrgID, ) require.NoError(t, err) @@ -585,7 +585,7 @@ func TestUpdateIDProvider(t *testing.T) { rowsAffected, err := idpRepo.Update(ctx, idpRepo.IDCondition(createdIDP.ID), createdIDP.InstanceID, - createdIDP.OrgID, + &createdIDP.OrgID, tt.update..., ) afterUpdate := time.Now() @@ -601,7 +601,7 @@ func TestUpdateIDProvider(t *testing.T) { idp, err := idpRepo.Get(ctx, organizationRepo.IDCondition(createdIDP.ID), createdIDP.InstanceID, - createdIDP.OrgID, + &createdIDP.OrgID, ) require.NoError(t, err) @@ -848,7 +848,7 @@ func TestGetIDProvider(t *testing.T) { returnedIDP, err := idpRepo.Get(ctx, tt.idpIdentifierCondition, idp.InstanceID, - idp.OrgID, + &idp.OrgID, ) if err != nil { require.ErrorIs(t, tt.err, err) @@ -1830,7 +1830,7 @@ func TestDeleteIDProvider(t *testing.T) { affectedRows, err := idpRepo.Delete(ctx, idpRepo.NameCondition(name), instanceId, - orgId, + &orgId, ) assert.Equal(t, int64(1), affectedRows) require.NoError(t, err) @@ -1853,7 +1853,7 @@ func TestDeleteIDProvider(t *testing.T) { noOfDeletedRows, err := idpRepo.Delete(ctx, tt.idpIdentifierCondition, instanceId, - orgId, + &orgId, ) require.NoError(t, err) assert.Equal(t, noOfDeletedRows, tt.noOfDeletedRows) @@ -1862,7 +1862,7 @@ func TestDeleteIDProvider(t *testing.T) { organization, err := idpRepo.Get(ctx, tt.idpIdentifierCondition, instanceId, - orgId, + &orgId, ) require.ErrorIs(t, err, new(database.NoRowFoundError)) assert.Nil(t, organization)