mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 11:04:25 +00:00
c740ee5d81
* fix: add events for domain * fix: add/remove domain command side * fix: add/remove domain command side * fix: add/remove domain query side * fix: create instance * fix: merge v2 * fix: instance domain * fix: instance domain * fix: instance domain * fix: instance domain * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from api * fix: remove domain.IAMID * fix: remove domain.IAMID * fix: add instance domain queries * fix: fix after merge * Update auth_request.go * fix keypair * remove unused code * feat: read instance id from context * feat: remove unused code * feat: use instance id from context * some fixes Co-authored-by: Livio Amstutz <livio.a@gmail.com>
51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/caos/zitadel/internal/api/authz"
|
|
"github.com/caos/zitadel/internal/command"
|
|
"github.com/caos/zitadel/internal/command/v2/preparation"
|
|
"github.com/caos/zitadel/internal/errors"
|
|
)
|
|
|
|
func domainPolicyWriteModel(ctx context.Context, filter preparation.FilterToQueryReducer) (*command.PolicyDomainWriteModel, error) {
|
|
wm, err := orgDomainPolicy(ctx, filter)
|
|
if err != nil || wm != nil && wm.State.Exists() {
|
|
return wm, err
|
|
}
|
|
wm, err = instanceDomainPolicy(ctx, filter)
|
|
if err != nil || wm != nil {
|
|
return wm, err
|
|
}
|
|
return nil, errors.ThrowInternal(nil, "USER-Ggk9n", "Errors.Internal")
|
|
}
|
|
|
|
func orgDomainPolicy(ctx context.Context, filter preparation.FilterToQueryReducer) (*command.PolicyDomainWriteModel, error) {
|
|
policy := command.NewOrgDomainPolicyWriteModel(authz.GetCtxData(ctx).OrgID)
|
|
events, err := filter(ctx, policy.Query())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(events) == 0 {
|
|
return nil, nil
|
|
}
|
|
policy.AppendEvents(events...)
|
|
err = policy.Reduce()
|
|
return &policy.PolicyDomainWriteModel, err
|
|
}
|
|
|
|
func instanceDomainPolicy(ctx context.Context, filter preparation.FilterToQueryReducer) (*command.PolicyDomainWriteModel, error) {
|
|
policy := command.NewInstanceDomainPolicyWriteModel(ctx)
|
|
events, err := filter(ctx, policy.Query())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(events) == 0 {
|
|
return nil, nil
|
|
}
|
|
policy.AppendEvents(events...)
|
|
err = policy.Reduce()
|
|
return &policy.PolicyDomainWriteModel, err
|
|
}
|