mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-18 03:15:11 +00:00
chore: forward port organization v2 API changes (#11207)
# Which Problems Are Solved Recent changes to the v2beta and v2 API of the organization service were directly merged to the `next` branch and release on v4.x, since the ongoing move to the relation table, blocked it from being merged into main. # How the Problems Are Solved This PR ports the following changes into main: - fix(api): correct permission check in organization v2beta service: https://github.com/zitadel/zitadel/commit/8dcfff97ed52a8b9fc77ecb1f972744f42cff3ed - fix(actions v1): return org metadata again (https://github.com/zitadel/zitadel/pull/11040) - feat(api): move organization api (https://github.com/zitadel/zitadel/pull/11045) # Additional Changes None # Additional Context relates to #10772 --------- Co-authored-by: Gayathri Vijayan <[email protected]>
This commit is contained in:
co-authored by
Gayathri Vijayan
parent
4c8a668585
commit
5f34d1af8f
@@ -55,7 +55,7 @@ func NewOrgDomainVerifiedSearchQuery(verified bool) (SearchQuery, error) {
|
||||
return NewBoolQuery(OrgDomainIsVerifiedCol, verified)
|
||||
}
|
||||
|
||||
func (q *Queries) SearchOrgDomains(ctx context.Context, queries *OrgDomainSearchQueries, withOwnerRemoved bool) (domains *Domains, err error) {
|
||||
func (q *Queries) SearchOrgDomains(ctx context.Context, queries *OrgDomainSearchQueries, withOwnerRemoved, withPermissionCheck bool) (domains *Domains, err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
@@ -64,6 +64,11 @@ func (q *Queries) SearchOrgDomains(ctx context.Context, queries *OrgDomainSearch
|
||||
if !withOwnerRemoved {
|
||||
eq[OrgDomainOwnerRemovedCol.identifier()] = false
|
||||
}
|
||||
if withPermissionCheck {
|
||||
// We always use the permission v2 check and don't check the feature flag, since it's stable enough to work
|
||||
// in this case and using the old checks only adds more latency, but no benefit.
|
||||
query = orgDomainPermissionCheckV2(ctx, query, queries)
|
||||
}
|
||||
stmt, args, err := queries.toQuery(query).Where(eq).ToSql()
|
||||
if err != nil {
|
||||
return nil, zerrors.ThrowInvalidArgument(err, "QUERY-ZRfj1", "Errors.Query.SQLStatement")
|
||||
@@ -176,3 +181,13 @@ var (
|
||||
table: orgDomainsTable,
|
||||
}
|
||||
)
|
||||
|
||||
func orgDomainPermissionCheckV2(ctx context.Context, query sq.SelectBuilder, queries *OrgDomainSearchQueries) sq.SelectBuilder {
|
||||
join, args := PermissionClause(
|
||||
ctx,
|
||||
OrgDomainOrgIDCol,
|
||||
domain.PermissionOrgRead,
|
||||
SingleOrgPermissionOption(queries.Queries),
|
||||
)
|
||||
return query.JoinClause(join, args...)
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/zitadel/logging"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/api/authz"
|
||||
domain_pkg "github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/query/projection"
|
||||
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
||||
@@ -113,7 +114,7 @@ func (q *Queries) GetOrgMetadataByKey(ctx context.Context, shouldTriggerBulk boo
|
||||
return metadata, err
|
||||
}
|
||||
|
||||
func (q *Queries) SearchOrgMetadata(ctx context.Context, shouldTriggerBulk bool, orgID string, queries *OrgMetadataSearchQueries, withOwnerRemoved bool) (metadata *OrgMetadataList, err error) {
|
||||
func (q *Queries) SearchOrgMetadata(ctx context.Context, shouldTriggerBulk bool, orgID string, queries *OrgMetadataSearchQueries, withOwnerRemoved, withPermissionCheck bool) (metadata *OrgMetadataList, err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
@@ -131,6 +132,11 @@ func (q *Queries) SearchOrgMetadata(ctx context.Context, shouldTriggerBulk bool,
|
||||
eq[OrgMetadataOwnerRemovedCol.identifier()] = false
|
||||
}
|
||||
query, scan := prepareOrgMetadataListQuery()
|
||||
if withPermissionCheck {
|
||||
// We always use the permission v2 check and don't check the feature flag, since it's stable enough to work
|
||||
// in this case and using the old checks only adds more latency, but no benefit.
|
||||
query = orgMetadataPermissionCheckV2(ctx, query, queries)
|
||||
}
|
||||
stmt, args, err := queries.toQuery(query).Where(eq).ToSql()
|
||||
if err != nil {
|
||||
return nil, zerrors.ThrowInternal(err, "QUERY-Egbld", "Errors.Query.SQLStatement")
|
||||
@@ -248,3 +254,13 @@ func prepareOrgMetadataListQuery() (sq.SelectBuilder, func(*sql.Rows) (*OrgMetad
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func orgMetadataPermissionCheckV2(ctx context.Context, query sq.SelectBuilder, queries *OrgMetadataSearchQueries) sq.SelectBuilder {
|
||||
join, args := PermissionClause(
|
||||
ctx,
|
||||
OrgMetadataOrgIDCol,
|
||||
domain_pkg.PermissionOrgRead,
|
||||
SingleOrgPermissionOption(queries.Queries),
|
||||
)
|
||||
return query.JoinClause(join, args...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user