2021-01-06 09:47:55 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2021-01-12 11:59:51 +00:00
|
|
|
caos_errs "github.com/caos/zitadel/internal/errors"
|
2021-01-06 09:47:55 +00:00
|
|
|
"github.com/caos/zitadel/internal/v2/domain"
|
2021-01-12 11:59:51 +00:00
|
|
|
"github.com/caos/zitadel/internal/v2/repository/iam"
|
2021-01-06 09:47:55 +00:00
|
|
|
)
|
|
|
|
|
2021-01-08 10:33:45 +00:00
|
|
|
//TODO: private
|
2021-01-12 11:59:51 +00:00
|
|
|
func (r *CommandSide) GetIAM(ctx context.Context) (*domain.IAM, error) {
|
|
|
|
iamWriteModel := NewIAMWriteModel()
|
2021-01-06 09:47:55 +00:00
|
|
|
err := r.eventstore.FilterToQueryReducer(ctx, iamWriteModel)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return writeModelToIAM(iamWriteModel), nil
|
|
|
|
}
|
2021-01-12 11:59:51 +00:00
|
|
|
|
|
|
|
func (r *CommandSide) setGlobalOrg(ctx context.Context, iamAgg *iam.Aggregate, iamWriteModel *IAMWriteModel, orgID string) error {
|
|
|
|
err := r.eventstore.FilterToQueryReducer(ctx, iamWriteModel)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if iamWriteModel.GlobalOrgID != "" {
|
|
|
|
return caos_errs.ThrowPreconditionFailed(nil, "IAM-HGG24", "Errors.IAM.GlobalOrgAlreadySet")
|
|
|
|
}
|
|
|
|
iamAgg.PushEvents(iam.NewGlobalOrgSetEventEvent(ctx, orgID))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *CommandSide) setIAMProject(ctx context.Context, iamAgg *iam.Aggregate, iamWriteModel *IAMWriteModel, projectID string) error {
|
|
|
|
err := r.eventstore.FilterToQueryReducer(ctx, iamWriteModel)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if iamWriteModel.ProjectID != "" {
|
|
|
|
return caos_errs.ThrowPreconditionFailed(nil, "IAM-EGbw2", "Errors.IAM.IAMProjectAlreadySet")
|
|
|
|
}
|
|
|
|
iamAgg.PushEvents(iam.NewIAMProjectSetEvent(ctx, projectID))
|
|
|
|
return nil
|
|
|
|
}
|