feat: delete metadata on SetOrganizationMetadata api (#11790)

# Which Problems Are Solved

Currently, to delete an Organization metadata key, callers must use a
separate
[DeleteMetadata](https://zitadel.com/docs/reference/api/org/zitadel.org.v2.OrganizationService.DeleteOrganizationMetadata)
API. This increases the complexity on client-side for operations where
metadata need to be synchronized.

# How the Problems Are Solved

Introduce deletion behavior to
[SetOrganizationMetadata](https://zitadel.com/docs/reference/api/org/zitadel.org.v2.OrganizationService.SetOrganizationMetadata):

When a metadata entry is passed with an empty value ("" / empty bytes):

- If the key exists → delete the key
- If the key does not exist → no-op (idempotent, no error)

# Additional Changes

n/a

# Additional Context

Relates to #11776

---------

Co-authored-by: Gayathri Vijayan <[email protected]>
Co-authored-by: Gayathri Vijayan <[email protected]>
This commit is contained in:
Vitor Bari Buccianti
2026-03-10 10:09:51 +00:00
committed by GitHub
co-authored by Gayathri Vijayan Gayathri Vijayan
parent 8b90ddb0b5
commit 62cb5bbb83
9 changed files with 267 additions and 142 deletions
+71 -26
View File
@@ -196,32 +196,6 @@ func TestCommandSide_BulkSetOrgMetadata(t *testing.T) {
err: zerrors.IsPreconditionFailed,
},
},
{
name: "invalid metadata, pre condition error",
fields: fields{
eventstore: expectEventstore(
expectFilter(
eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"ZITADEL",
),
),
),
),
},
args: args{
ctx: context.Background(),
orgID: "org1",
metadataList: []*domain.Metadata{
{Key: "key"},
{Key: "key1"},
},
},
res: res{
err: zerrors.IsErrorInvalidArgument,
},
},
{
name: "add metadata, ok",
fields: fields{
@@ -234,6 +208,7 @@ func TestCommandSide_BulkSetOrgMetadata(t *testing.T) {
),
),
),
expectFilter(),
expectPush(
org.NewMetadataSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
@@ -274,6 +249,7 @@ func TestCommandSide_BulkSetOrgMetadata(t *testing.T) {
),
),
),
expectFilter(),
expectPush(
org.NewMetadataSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
@@ -303,6 +279,75 @@ func TestCommandSide_BulkSetOrgMetadata(t *testing.T) {
},
},
},
{
name: "update and delete metadata, ok",
fields: fields{
eventstore: expectEventstore(
expectFilter(
eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"ZITADEL",
),
),
),
expectFilter(
eventFromEventPusher(
org.NewMetadataSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key",
[]byte("value"),
),
),
eventFromEventPusher(
org.NewMetadataSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key1",
[]byte("value1"),
),
),
eventFromEventPusher(
org.NewMetadataSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key2",
[]byte("value2"),
),
)),
expectPush(
org.NewMetadataSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key",
[]byte("updated_value"),
),
org.NewMetadataRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key1",
),
org.NewMetadataSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key3",
[]byte("value3"),
),
),
),
},
args: args{
ctx: context.Background(),
orgID: "org1",
metadataList: []*domain.Metadata{
{Key: "key", Value: []byte("updated_value")}, // update an existing key
{Key: "key1"}, // delete an existing key
{Key: "key2", Value: []byte("value2")}, // unchanged value
{Key: "key3", Value: []byte("value3")}, // add a new key
{Key: "key4"}, // delete a non-existing key
},
},
res: res{
want: &domain.ObjectDetails{
ResourceOwner: "org1",
},
},
},
{
name: "add metadata (no permission), error",
fields: fields{