mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 19:14:23 +00:00
fa9f581d56
* chore: move to new org * logging * fix: org rename caos -> zitadel Co-authored-by: adlerhurst <silvan.reusser@gmail.com>
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
"github.com/zitadel/zitadel/internal/command/preparation"
|
|
"github.com/zitadel/zitadel/internal/errors"
|
|
)
|
|
|
|
func domainPolicyWriteModel(ctx context.Context, filter preparation.FilterToQueryReducer) (*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) (*PolicyDomainWriteModel, error) {
|
|
policy := 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) (*PolicyDomainWriteModel, error) {
|
|
policy := 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
|
|
}
|