2020-05-13 12:22:29 +00:00
|
|
|
package eventstore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-07-08 11:56:37 +00:00
|
|
|
|
|
|
|
"github.com/caos/zitadel/internal/api/authz"
|
2020-06-16 09:40:18 +00:00
|
|
|
org_event "github.com/caos/zitadel/internal/org/repository/eventsourcing"
|
2020-05-29 06:44:01 +00:00
|
|
|
policy_event "github.com/caos/zitadel/internal/policy/repository/eventsourcing"
|
2020-05-13 12:22:29 +00:00
|
|
|
usr_model "github.com/caos/zitadel/internal/user/model"
|
|
|
|
usr_event "github.com/caos/zitadel/internal/user/repository/eventsourcing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type UserRepo struct {
|
2020-05-29 06:44:01 +00:00
|
|
|
UserEvents *usr_event.UserEventstore
|
|
|
|
PolicyEvents *policy_event.PolicyEventstore
|
2020-06-16 09:40:18 +00:00
|
|
|
OrgEvents *org_event.OrgEventstore
|
2020-05-13 12:22:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *UserRepo) UserByID(ctx context.Context, id string) (project *usr_model.User, err error) {
|
|
|
|
return repo.UserEvents.UserByID(ctx, id)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *UserRepo) CreateUser(ctx context.Context, user *usr_model.User) (*usr_model.User, error) {
|
2020-07-08 11:56:37 +00:00
|
|
|
pwPolicy, err := repo.PolicyEvents.GetPasswordComplexityPolicy(ctx, authz.GetCtxData(ctx).OrgID)
|
2020-05-29 06:44:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-08-26 07:56:23 +00:00
|
|
|
orgPolicy, err := repo.OrgEvents.GetOrgIAMPolicy(ctx, authz.GetCtxData(ctx).OrgID)
|
2020-06-16 09:40:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return repo.UserEvents.CreateUser(ctx, user, pwPolicy, orgPolicy)
|
2020-05-13 12:22:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *UserRepo) RegisterUser(ctx context.Context, user *usr_model.User, resourceOwner string) (*usr_model.User, error) {
|
2020-07-08 11:56:37 +00:00
|
|
|
policyResourceOwner := authz.GetCtxData(ctx).OrgID
|
2020-05-29 06:44:01 +00:00
|
|
|
if resourceOwner != "" {
|
|
|
|
policyResourceOwner = resourceOwner
|
|
|
|
}
|
2020-06-16 09:40:18 +00:00
|
|
|
pwPolicy, err := repo.PolicyEvents.GetPasswordComplexityPolicy(ctx, policyResourceOwner)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-08-26 07:56:23 +00:00
|
|
|
orgPolicy, err := repo.OrgEvents.GetOrgIAMPolicy(ctx, policyResourceOwner)
|
2020-05-29 06:44:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-06-16 09:40:18 +00:00
|
|
|
return repo.UserEvents.RegisterUser(ctx, user, pwPolicy, orgPolicy, resourceOwner)
|
2020-05-13 12:22:29 +00:00
|
|
|
}
|