mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-20 20:08:46 +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
@@ -20,7 +20,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
func (c *Commands) prepareAddOrgDomain(a *org.Aggregate, addDomain string, userIDs []string) preparation.Validation {
|
||||
//nolint:gocognit
|
||||
func (c *Commands) prepareAddOrgDomain(a *org.Aggregate, addDomain string, userIDs []string, permissionCheck OrganizationPermissionCheck) preparation.Validation {
|
||||
return func() (preparation.CreateCommands, error) {
|
||||
if addDomain = strings.TrimSpace(addDomain); addDomain == "" {
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "ORG-r3h4J", "Errors.Invalid.Argument")
|
||||
@@ -29,6 +30,15 @@ func (c *Commands) prepareAddOrgDomain(a *org.Aggregate, addDomain string, userI
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
if permissionCheck != nil {
|
||||
if err := permissionCheck(ctx, a.ID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err := c.checkOrgExists(ctx, a.ID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
existing, err := orgDomain(ctx, filter, a.ID, addDomain)
|
||||
if err != nil && !errors.Is(err, zerrors.ThrowNotFound(nil, "", "")) {
|
||||
return nil, err
|
||||
@@ -123,12 +133,13 @@ func (c *Commands) VerifyOrgDomain(ctx context.Context, orgID, domain string) (_
|
||||
return pushedEventsToObjectDetails(pushedEvents), nil
|
||||
}
|
||||
|
||||
func (c *Commands) AddOrgDomain(ctx context.Context, orgID, domain string, claimedUserIDs []string) (_ *domain.ObjectDetails, err error) {
|
||||
func (c *Commands) AddOrgDomain(ctx context.Context, orgID, domain string, claimedUserIDs []string, permissionCheck OrganizationPermissionCheck) (_ *domain.ObjectDetails, err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
orgAgg := org.NewAggregate(orgID)
|
||||
cmds, err := preparation.PrepareCommands(ctx, c.eventstore.Filter, c.prepareAddOrgDomain(orgAgg, domain, claimedUserIDs))
|
||||
//nolint:staticcheck
|
||||
cmds, err := preparation.PrepareCommands(ctx, c.eventstore.Filter, c.prepareAddOrgDomain(orgAgg, domain, claimedUserIDs, permissionCheck))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -139,7 +150,7 @@ func (c *Commands) AddOrgDomain(ctx context.Context, orgID, domain string, claim
|
||||
return pushedEventsToObjectDetails(pushedEvents), nil
|
||||
}
|
||||
|
||||
func (c *Commands) GenerateOrgDomainValidation(ctx context.Context, orgDomain *domain.OrgDomain) (token, url string, err error) {
|
||||
func (c *Commands) GenerateOrgDomainValidation(ctx context.Context, orgDomain *domain.OrgDomain, permissionCheck OrganizationPermissionCheck) (token, url string, err error) {
|
||||
if orgDomain == nil || !orgDomain.IsValid() || orgDomain.AggregateID == "" {
|
||||
return "", "", zerrors.ThrowInvalidArgument(nil, "ORG-R24hb", "Errors.Org.InvalidDomain")
|
||||
}
|
||||
@@ -147,6 +158,11 @@ func (c *Commands) GenerateOrgDomainValidation(ctx context.Context, orgDomain *d
|
||||
if !ok {
|
||||
return "", "", zerrors.ThrowInvalidArgument(nil, "ORG-Gsw31", "Errors.Org.DomainVerificationTypeInvalid")
|
||||
}
|
||||
if permissionCheck != nil {
|
||||
if err := permissionCheck(ctx, orgDomain.AggregateID); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
}
|
||||
domainWriteModel, err := c.getOrgDomainWriteModel(ctx, orgDomain.AggregateID, orgDomain.Domain)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
@@ -177,10 +193,15 @@ func (c *Commands) GenerateOrgDomainValidation(ctx context.Context, orgDomain *d
|
||||
return token, url, nil
|
||||
}
|
||||
|
||||
func (c *Commands) ValidateOrgDomain(ctx context.Context, orgDomain *domain.OrgDomain, claimedUserIDs []string) (*domain.ObjectDetails, error) {
|
||||
func (c *Commands) ValidateOrgDomain(ctx context.Context, orgDomain *domain.OrgDomain, claimedUserIDs []string, permissionCheck OrganizationPermissionCheck) (*domain.ObjectDetails, error) {
|
||||
if orgDomain == nil || !orgDomain.IsValid() || orgDomain.AggregateID == "" {
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "ORG-R24hb", "Errors.Org.InvalidDomain")
|
||||
}
|
||||
if permissionCheck != nil {
|
||||
if err := permissionCheck(ctx, orgDomain.AggregateID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
domainWriteModel, err := c.getOrgDomainWriteModel(ctx, orgDomain.AggregateID, orgDomain.Domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -261,10 +282,15 @@ func (c *Commands) SetPrimaryOrgDomain(ctx context.Context, orgDomain *domain.Or
|
||||
return writeModelToObjectDetails(&domainWriteModel.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) RemoveOrgDomain(ctx context.Context, orgDomain *domain.OrgDomain) (*domain.ObjectDetails, error) {
|
||||
func (c *Commands) RemoveOrgDomain(ctx context.Context, orgDomain *domain.OrgDomain, permissionCheck OrganizationPermissionCheck) (*domain.ObjectDetails, error) {
|
||||
if orgDomain == nil || !orgDomain.IsValid() || orgDomain.AggregateID == "" {
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "ORG-SJsK3", "Errors.Org.InvalidDomain")
|
||||
}
|
||||
if permissionCheck != nil {
|
||||
if err := permissionCheck(ctx, orgDomain.AggregateID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
domainWriteModel, err := c.getOrgDomainWriteModel(ctx, orgDomain.AggregateID, orgDomain.Domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user