From 3c07a186fc0c16d9ae5689b7dfa4f4552c8467ee Mon Sep 17 00:00:00 2001 From: Fabi <38692350+fgerschwiler@users.noreply.github.com> Date: Mon, 1 Mar 2021 08:48:50 +0100 Subject: [PATCH] fix: todos (#1346) * fix: pub sub in new eventstore * fix: todos * fix: todos * fix: todos * fix: todos * fix: todos --- cmd/zitadel/main.go | 7 ++-- .../api/grpc/admin/iam_member_converter.go | 15 ++++---- internal/api/grpc/admin/org_converter.go | 9 +++-- internal/api/grpc/auth/search_converter.go | 18 +++++----- internal/api/grpc/auth/user_converter.go | 34 +++++++++++++------ .../api/grpc/auth/user_human_converter.go | 23 ++++++------- .../grpc/management/application_converter.go | 7 ++-- .../grpc/management/org_member_converter.go | 15 ++++---- .../management/project_grant_converter.go | 3 +- .../project_grant_member_converter.go | 5 ++- .../api/grpc/management/search_converter.go | 24 ++++++------- .../api/grpc/management/user_converter.go | 16 +++++++-- .../grpc/management/user_human_converter.go | 23 ++++++------- .../grpc/management/user_machine_converter.go | 5 ++- .../eventsourcing/eventstore/user_grant.go | 18 +++++----- .../eventsourcing/view/application.go | 6 ++-- .../eventsourcing/eventstore/user_grant.go | 9 +++-- internal/command/command.go | 21 ++++++------ internal/command/iam.go | 2 +- internal/command/iam_converter.go | 1 - internal/command/iam_idp_config.go | 11 ++++++ internal/command/iam_member.go | 10 +++--- internal/command/idp_config_model.go | 17 ---------- internal/command/org_domain_model.go | 2 -- internal/command/org_idp_config.go | 11 ++++++ internal/command/org_member.go | 10 +++--- internal/command/project_grant_member.go | 5 +-- internal/command/project_member.go | 10 +++--- internal/command/user_human_externalidp.go | 12 +++++-- internal/command/user_human_phone.go | 11 +++--- internal/command/user_human_webauthn.go | 31 +++++++++++++++-- internal/command/user_machine.go | 1 - internal/domain/human_phone.go | 4 +++ internal/domain/human_web_auth_n.go | 2 -- internal/domain/idp_config.go | 8 +++-- internal/domain/mfa.go | 11 ++++++ internal/domain/roles.go | 28 +++++++++++++++ internal/{model => domain}/search_method.go | 2 +- internal/iam/model/iam_member_view.go | 5 ++- internal/iam/model/idp_config_view.go | 6 ++-- internal/iam/model/idp_provider_view.go | 5 ++- internal/iam/model/label_policy_view.go | 5 ++- internal/iam/model/login_policy_view.go | 3 +- internal/iam/model/mail_template_view.go | 5 ++- internal/iam/model/mail_text_view.go | 5 ++- internal/iam/model/mfa_view.go | 8 ++--- internal/iam/model/org_iam_policy_view.go | 4 +-- .../iam/model/password_age_policy_view.go | 4 +-- .../model/password_complexity_policy_view.go | 4 +-- .../iam/model/password_lockout_policy_view.go | 4 +-- .../iam/repository/view/iam_member_view.go | 8 ++--- .../iam/repository/view/idp_provider_view.go | 12 +++---- internal/iam/repository/view/idp_view.go | 6 ++-- .../iam/repository/view/label_policy_view.go | 4 +-- .../iam/repository/view/login_policy_view.go | 6 ++-- .../iam/repository/view/mail_template_view.go | 4 +-- .../iam/repository/view/mail_text_view.go | 10 +++--- .../repository/view/model/iam_member_query.go | 4 +-- .../repository/view/model/idp_config_query.go | 4 +-- .../view/model/idp_provider_query.go | 4 +-- .../view/model/label_policy_query.go | 4 +-- .../view/model/login_policy_query.go | 4 +-- .../view/model/mail_template_query.go | 4 +-- .../repository/view/model/mail_text_query.go | 4 +-- .../view/model/org_iam_policy_query.go | 4 +-- .../view/model/password_age_policy_query.go | 4 +-- .../model/password_complexity_policy_query.go | 4 +-- .../model/password_lockout_policy_query.go | 4 +-- .../repository/view/org_iam_policy_view.go | 4 +-- .../view/password_age_policy_view.go | 4 +-- .../view/password_complexity_policy_view.go | 4 +-- .../view/password_lockout_policy_view.go | 4 +-- internal/key/model/authn_key.go | 4 +-- internal/key/model/key_view.go | 4 +-- .../key/repository/view/authn_key_view.go | 10 +++--- internal/key/repository/view/key.go | 18 +++++----- .../repository/view/model/authn_key_query.go | 4 +-- .../key/repository/view/model/key_query.go | 4 +-- .../eventsourcing/eventstore/org.go | 5 ++- .../eventsourcing/eventstore/project.go | 5 ++- .../eventsourcing/eventstore/user.go | 8 ++--- .../eventsourcing/eventstore/user_grant.go | 4 +-- internal/model/enum.go | 6 ---- internal/model/mfa.go | 12 ------- internal/org/model/domain_view.go | 5 ++- internal/org/model/org_member_view.go | 5 ++- internal/org/model/org_view.go | 4 +-- .../repository/view/model/org_domain_query.go | 4 +-- .../repository/view/model/org_member_query.go | 4 +-- .../org/repository/view/model/org_query.go | 4 +-- .../org/repository/view/org_domain_view.go | 12 +++---- .../org/repository/view/org_member_view.go | 8 ++--- internal/project/model/application_view.go | 5 ++- .../model/project_grant_member_view.go | 5 ++- internal/project/model/project_grant_view.go | 10 +++--- internal/project/model/project_member_view.go | 7 ++-- internal/project/model/project_role_view.go | 9 +++-- internal/project/model/project_view.go | 7 ++-- .../repository/view/application_view.go | 14 ++++---- .../view/model/application_query.go | 4 +-- .../view/model/project_grant_member_query.go | 4 +-- .../view/model/project_grant_query.go | 4 +-- .../view/model/project_member_query.go | 4 +-- .../repository/view/model/project_query.go | 4 +-- .../view/model/project_role_query.go | 4 +-- .../view/project_grant_member_view.go | 10 +++--- .../repository/view/project_grant_view.go | 14 ++++---- .../repository/view/project_member_view.go | 10 +++--- .../repository/view/project_role_view.go | 20 +++++------ .../project/repository/view/project_view.go | 6 ++-- internal/query/converter.go | 15 +++----- internal/repository/org/eventstore.go | 1 - .../repository/user/human_mfa_passwordless.go | 12 +++++-- internal/repository/user/human_mfa_u2f.go | 12 +++++-- .../repository/user/human_mfa_web_auth_n.go | 22 ++++++------ internal/setup/setup.go | 5 --- internal/user/model/external_idp_view.go | 6 ++-- internal/user/model/notify_user.go | 4 +-- internal/user/model/token_view.go | 5 ++- internal/user/model/user_membership_view.go | 9 +++-- internal/user/model/user_session_view.go | 4 +-- internal/user/model/user_view.go | 5 ++- .../user/repository/view/external_idp_view.go | 24 ++++++------- .../view/model/external_idp_query.go | 4 +-- .../view/model/notify_user_query.go | 4 +-- .../user/repository/view/model/token_query.go | 4 +-- .../view/model/user_membership_query.go | 4 +-- .../user/repository/view/model/user_query.go | 4 +-- .../view/model/user_session_query.go | 4 +-- internal/user/repository/view/notify_user.go | 4 +-- internal/user/repository/view/token_view.go | 4 +-- .../user/repository/view/user_session_view.go | 12 +++---- internal/user/repository/view/user_view.go | 18 +++++----- .../repository/view/usermembership_view.go | 14 ++++---- internal/usergrant/model/user_grant_view.go | 9 +++-- .../repository/view/model/user_grant_query.go | 4 +-- .../repository/view/user_grant_view.go | 30 ++++++++-------- internal/view/model/general_query.go | 6 ++-- internal/view/repository/db_mock_test.go | 7 ++-- internal/view/repository/failed_events.go | 10 +++--- internal/view/repository/general_query.go | 4 +-- internal/view/repository/query.go | 32 ++++++++--------- internal/view/repository/query_test.go | 6 ++-- internal/view/repository/requests_test.go | 20 +++++------ internal/view/repository/sequence.go | 6 ++-- 145 files changed, 645 insertions(+), 575 deletions(-) rename internal/{model => domain}/search_method.go (96%) delete mode 100644 internal/model/enum.go delete mode 100644 internal/model/mfa.go diff --git a/cmd/zitadel/main.go b/cmd/zitadel/main.go index 3f0f52a49a..9b88f35289 100644 --- a/cmd/zitadel/main.go +++ b/cmd/zitadel/main.go @@ -61,11 +61,12 @@ type setupConfig struct { Eventstore types.SQL SystemDefaults sd.SystemDefaults SetUp setup.IAMSetUp + InternalAuthZ internal_authz.Config } var ( configPaths = config.NewArrayFlags("authz.yaml", "startup.yaml", "system-defaults.yaml") - setupPaths = config.NewArrayFlags("system-defaults.yaml", "setup.yaml") + setupPaths = config.NewArrayFlags("authz.yaml", "system-defaults.yaml", "setup.yaml") adminEnabled = flag.Bool("admin", true, "enable admin api") managementEnabled = flag.Bool("management", true, "enable management api") authEnabled = flag.Bool("auth", true, "enable auth api") @@ -106,7 +107,7 @@ func startZitadel(configPaths []string) { if err != nil { return } - commands, err := command.StartCommands(esCommands, conf.SystemDefaults) + commands, err := command.StartCommands(esCommands, conf.SystemDefaults, conf.InternalAuthZ) if err != nil { return } @@ -189,7 +190,7 @@ func startSetup(configPaths []string, localDevMode bool) { es, err := eventstore.Start(conf.Eventstore) logging.Log("MAIN-Ddt3").OnError(err).Fatal("cannot start eventstore") - commands, err := command.StartCommands(es, conf.SystemDefaults) + commands, err := command.StartCommands(es, conf.SystemDefaults, conf.InternalAuthZ) logging.Log("MAIN-dsjrr").OnError(err).Fatal("cannot start command side") err = setup.Execute(ctx, conf.SetUp, conf.SystemDefaults.IamID, commands) diff --git a/internal/api/grpc/admin/iam_member_converter.go b/internal/api/grpc/admin/iam_member_converter.go index bd4fac8b86..929230fa25 100644 --- a/internal/api/grpc/admin/iam_member_converter.go +++ b/internal/api/grpc/admin/iam_member_converter.go @@ -7,7 +7,6 @@ import ( "google.golang.org/protobuf/types/known/timestamppb" iam_model "github.com/caos/zitadel/internal/iam/model" - "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/pkg/grpc/admin" ) @@ -68,20 +67,20 @@ func iamMemberSearchKeyToModel(key admin.IamMemberSearchKey) iam_model.IAMMember } } -func searchMethodToModel(key admin.SearchMethod) model.SearchMethod { +func searchMethodToModel(key admin.SearchMethod) domain.SearchMethod { switch key { case admin.SearchMethod_SEARCHMETHOD_CONTAINS: - return model.SearchMethodContains + return domain.SearchMethodContains case admin.SearchMethod_SEARCHMETHOD_CONTAINS_IGNORE_CASE: - return model.SearchMethodContainsIgnoreCase + return domain.SearchMethodContainsIgnoreCase case admin.SearchMethod_SEARCHMETHOD_EQUALS: - return model.SearchMethodEquals + return domain.SearchMethodEquals case admin.SearchMethod_SEARCHMETHOD_EQUALS_IGNORE_CASE: - return model.SearchMethodEqualsIgnoreCase + return domain.SearchMethodEqualsIgnoreCase case admin.SearchMethod_SEARCHMETHOD_STARTS_WITH: - return model.SearchMethodStartsWith + return domain.SearchMethodStartsWith case admin.SearchMethod_SEARCHMETHOD_STARTS_WITH_IGNORE_CASE: - return model.SearchMethodStartsWithIgnoreCase + return domain.SearchMethodStartsWithIgnoreCase default: return -1 } diff --git a/internal/api/grpc/admin/org_converter.go b/internal/api/grpc/admin/org_converter.go index d9751e1849..0a8dcd42c2 100644 --- a/internal/api/grpc/admin/org_converter.go +++ b/internal/api/grpc/admin/org_converter.go @@ -9,7 +9,6 @@ import ( iam_model "github.com/caos/zitadel/internal/iam/model" "github.com/caos/zitadel/internal/eventstore/v1/models" - "github.com/caos/zitadel/internal/model" org_model "github.com/caos/zitadel/internal/org/model" usr_model "github.com/caos/zitadel/internal/user/model" "github.com/caos/zitadel/pkg/grpc/admin" @@ -164,14 +163,14 @@ func orgQueryKeyToModel(key admin.OrgSearchKey) org_model.OrgSearchKey { } } -func orgQueryMethodToModel(method admin.OrgSearchMethod) model.SearchMethod { +func orgQueryMethodToModel(method admin.OrgSearchMethod) domain.SearchMethod { switch method { case admin.OrgSearchMethod_ORGSEARCHMETHOD_CONTAINS: - return model.SearchMethodContains + return domain.SearchMethodContains case admin.OrgSearchMethod_ORGSEARCHMETHOD_EQUALS: - return model.SearchMethodEquals + return domain.SearchMethodEquals case admin.OrgSearchMethod_ORGSEARCHMETHOD_STARTS_WITH: - return model.SearchMethodStartsWith + return domain.SearchMethodStartsWith default: return 0 } diff --git a/internal/api/grpc/auth/search_converter.go b/internal/api/grpc/auth/search_converter.go index 3f6c9fab76..44b7f01c93 100644 --- a/internal/api/grpc/auth/search_converter.go +++ b/internal/api/grpc/auth/search_converter.go @@ -1,25 +1,25 @@ package auth import ( - "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/pkg/grpc/auth" ) -func searchMethodToModel(method auth.SearchMethod) model.SearchMethod { +func searchMethodToModel(method auth.SearchMethod) domain.SearchMethod { switch method { case auth.SearchMethod_SEARCHMETHOD_EQUALS: - return model.SearchMethodEquals + return domain.SearchMethodEquals case auth.SearchMethod_SEARCHMETHOD_CONTAINS: - return model.SearchMethodContains + return domain.SearchMethodContains case auth.SearchMethod_SEARCHMETHOD_STARTS_WITH: - return model.SearchMethodStartsWith + return domain.SearchMethodStartsWith case auth.SearchMethod_SEARCHMETHOD_EQUALS_IGNORE_CASE: - return model.SearchMethodEqualsIgnoreCase + return domain.SearchMethodEqualsIgnoreCase case auth.SearchMethod_SEARCHMETHOD_CONTAINS_IGNORE_CASE: - return model.SearchMethodContainsIgnoreCase + return domain.SearchMethodContainsIgnoreCase case auth.SearchMethod_SEARCHMETHOD_STARTS_WITH_IGNORE_CASE: - return model.SearchMethodStartsWithIgnoreCase + return domain.SearchMethodStartsWithIgnoreCase default: - return model.SearchMethodEquals + return domain.SearchMethodEquals } } diff --git a/internal/api/grpc/auth/user_converter.go b/internal/api/grpc/auth/user_converter.go index c206b6e097..85b803db20 100644 --- a/internal/api/grpc/auth/user_converter.go +++ b/internal/api/grpc/auth/user_converter.go @@ -81,17 +81,16 @@ func profileViewFromModel(profile *usr_model.Profile) *auth.UserProfileView { logging.Log("GRPC-9sujE").OnError(err).Debug("unable to parse timestamp") return &auth.UserProfileView{ - Id: profile.AggregateID, - CreationDate: creationDate, - ChangeDate: changeDate, - Sequence: profile.Sequence, - FirstName: profile.FirstName, - LastName: profile.LastName, - DisplayName: profile.DisplayName, - NickName: profile.NickName, - PreferredLanguage: profile.PreferredLanguage.String(), - //TODO: Use converter - Gender: auth.Gender(profile.Gender), + Id: profile.AggregateID, + CreationDate: creationDate, + ChangeDate: changeDate, + Sequence: profile.Sequence, + FirstName: profile.FirstName, + LastName: profile.LastName, + DisplayName: profile.DisplayName, + NickName: profile.NickName, + PreferredLanguage: profile.PreferredLanguage.String(), + Gender: genderFromModel(profile.Gender), LoginNames: profile.LoginNames, PreferredLoginName: profile.PreferredLoginName, } @@ -346,6 +345,19 @@ func genderFromDomain(gender domain.Gender) auth.Gender { } } +func genderFromModel(gender usr_model.Gender) auth.Gender { + switch gender { + case usr_model.GenderFemale: + return auth.Gender_GENDER_FEMALE + case usr_model.GenderMale: + return auth.Gender_GENDER_MALE + case usr_model.GenderDiverse: + return auth.Gender_GENDER_DIVERSE + default: + return auth.Gender_GENDER_UNSPECIFIED + } +} + func genderToDomain(gender auth.Gender) domain.Gender { switch gender { case auth.Gender_GENDER_FEMALE: diff --git a/internal/api/grpc/auth/user_human_converter.go b/internal/api/grpc/auth/user_human_converter.go index 7d292a9454..1b2a7bd72d 100644 --- a/internal/api/grpc/auth/user_human_converter.go +++ b/internal/api/grpc/auth/user_human_converter.go @@ -17,17 +17,16 @@ func humanViewFromModel(user *usr_model.HumanView) *auth.HumanView { DisplayName: user.DisplayName, NickName: user.NickName, PreferredLanguage: user.PreferredLanguage, - //TODO: add converter - Gender: auth.Gender(user.Gender), - Email: user.Email, - IsEmailVerified: user.IsEmailVerified, - Phone: user.Phone, - IsPhoneVerified: user.IsPhoneVerified, - Country: user.Country, - Locality: user.Locality, - PostalCode: user.PostalCode, - Region: user.Region, - StreetAddress: user.StreetAddress, - PasswordChanged: passwordChanged, + Gender: genderFromModel(user.Gender), + Email: user.Email, + IsEmailVerified: user.IsEmailVerified, + Phone: user.Phone, + IsPhoneVerified: user.IsPhoneVerified, + Country: user.Country, + Locality: user.Locality, + PostalCode: user.PostalCode, + Region: user.Region, + StreetAddress: user.StreetAddress, + PasswordChanged: passwordChanged, } } diff --git a/internal/api/grpc/management/application_converter.go b/internal/api/grpc/management/application_converter.go index ccaee66ab6..4627cb1a44 100644 --- a/internal/api/grpc/management/application_converter.go +++ b/internal/api/grpc/management/application_converter.go @@ -14,7 +14,6 @@ import ( "github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/eventstore/v1/models" key_model "github.com/caos/zitadel/internal/key/model" - "github.com/caos/zitadel/internal/model" proj_model "github.com/caos/zitadel/internal/project/model" "github.com/caos/zitadel/pkg/grpc/management" "github.com/caos/zitadel/pkg/grpc/message" @@ -271,7 +270,7 @@ func applicationSearchQueriesToModel(projectID string, queries []*management.App for i, q := range queries { converted[i] = applicationSearchQueryToModel(q) } - converted[len(queries)] = &proj_model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyProjectID, Method: model.SearchMethodEquals, Value: projectID} + converted[len(queries)] = &proj_model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyProjectID, Method: domain.SearchMethodEquals, Value: projectID} return converted } @@ -711,11 +710,11 @@ func clientKeySearchRequestToModel(req *management.ClientKeySearchRequest) *key_ Queries: []*key_model.AuthNKeySearchQuery{ { Key: key_model.AuthNKeyObjectType, - Method: model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: key_model.AuthNKeyObjectTypeApplication, }, { Key: key_model.AuthNKeyObjectID, - Method: model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: req.ApplicationId, }, }, diff --git a/internal/api/grpc/management/org_member_converter.go b/internal/api/grpc/management/org_member_converter.go index d39fe08e2b..0d85f1ea91 100644 --- a/internal/api/grpc/management/org_member_converter.go +++ b/internal/api/grpc/management/org_member_converter.go @@ -9,7 +9,6 @@ import ( "github.com/caos/zitadel/internal/api/authz" "github.com/caos/zitadel/internal/domain" - "github.com/caos/zitadel/internal/model" org_model "github.com/caos/zitadel/internal/org/model" "github.com/caos/zitadel/pkg/grpc/management" ) @@ -72,20 +71,20 @@ func orgMemberSearchKeyToModel(key management.OrgMemberSearchKey) org_model.OrgM } } -func orgMemberSearchMethodToModel(key management.SearchMethod) model.SearchMethod { +func orgMemberSearchMethodToModel(key management.SearchMethod) domain.SearchMethod { switch key { case management.SearchMethod_SEARCHMETHOD_CONTAINS: - return model.SearchMethodContains + return domain.SearchMethodContains case management.SearchMethod_SEARCHMETHOD_CONTAINS_IGNORE_CASE: - return model.SearchMethodContainsIgnoreCase + return domain.SearchMethodContainsIgnoreCase case management.SearchMethod_SEARCHMETHOD_EQUALS: - return model.SearchMethodEquals + return domain.SearchMethodEquals case management.SearchMethod_SEARCHMETHOD_EQUALS_IGNORE_CASE: - return model.SearchMethodEqualsIgnoreCase + return domain.SearchMethodEqualsIgnoreCase case management.SearchMethod_SEARCHMETHOD_STARTS_WITH: - return model.SearchMethodStartsWith + return domain.SearchMethodStartsWith case management.SearchMethod_SEARCHMETHOD_STARTS_WITH_IGNORE_CASE: - return model.SearchMethodStartsWithIgnoreCase + return domain.SearchMethodStartsWithIgnoreCase default: return -1 } diff --git a/internal/api/grpc/management/project_grant_converter.go b/internal/api/grpc/management/project_grant_converter.go index e43487d793..10f0f9db32 100644 --- a/internal/api/grpc/management/project_grant_converter.go +++ b/internal/api/grpc/management/project_grant_converter.go @@ -8,7 +8,6 @@ import ( "github.com/golang/protobuf/ptypes" "github.com/caos/zitadel/internal/eventstore/v1/models" - "github.com/caos/zitadel/internal/model" proj_model "github.com/caos/zitadel/internal/project/model" "github.com/caos/zitadel/pkg/grpc/management" ) @@ -77,7 +76,7 @@ func projectGrantSearchQueriesToModel(projectId string, queries []*management.Pr converted := make([]*proj_model.ProjectGrantViewSearchQuery, 0) converted = append(converted, &proj_model.ProjectGrantViewSearchQuery{ Key: proj_model.GrantedProjectSearchKeyProjectID, - Method: model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: projectId, }) for i, query := range queries { diff --git a/internal/api/grpc/management/project_grant_member_converter.go b/internal/api/grpc/management/project_grant_member_converter.go index a406947745..99db5ae4ab 100644 --- a/internal/api/grpc/management/project_grant_member_converter.go +++ b/internal/api/grpc/management/project_grant_member_converter.go @@ -3,7 +3,6 @@ package management import ( "github.com/caos/logging" "github.com/caos/zitadel/internal/domain" - "github.com/caos/zitadel/internal/model" "github.com/golang/protobuf/ptypes" "google.golang.org/protobuf/types/known/timestamppb" @@ -66,8 +65,8 @@ func projectGrantMemberSearchRequestsToModel(memberSearch *management.ProjectGra Limit: memberSearch.Limit, Queries: projectGrantMemberSearchQueriesToModel(memberSearch.Queries), } - request.Queries = append(request.Queries, &proj_model.ProjectGrantMemberSearchQuery{Key: proj_model.ProjectGrantMemberSearchKeyProjectID, Method: model.SearchMethodEquals, Value: memberSearch.ProjectId}) - request.Queries = append(request.Queries, &proj_model.ProjectGrantMemberSearchQuery{Key: proj_model.ProjectGrantMemberSearchKeyGrantID, Method: model.SearchMethodEquals, Value: memberSearch.GrantId}) + request.Queries = append(request.Queries, &proj_model.ProjectGrantMemberSearchQuery{Key: proj_model.ProjectGrantMemberSearchKeyProjectID, Method: domain.SearchMethodEquals, Value: memberSearch.ProjectId}) + request.Queries = append(request.Queries, &proj_model.ProjectGrantMemberSearchQuery{Key: proj_model.ProjectGrantMemberSearchKeyGrantID, Method: domain.SearchMethodEquals, Value: memberSearch.GrantId}) return request } diff --git a/internal/api/grpc/management/search_converter.go b/internal/api/grpc/management/search_converter.go index 1b3b2e2052..217b1b149f 100644 --- a/internal/api/grpc/management/search_converter.go +++ b/internal/api/grpc/management/search_converter.go @@ -1,31 +1,31 @@ package management import ( - "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/pkg/grpc/management" ) -func searchMethodToModel(method management.SearchMethod) model.SearchMethod { +func searchMethodToModel(method management.SearchMethod) domain.SearchMethod { switch method { case management.SearchMethod_SEARCHMETHOD_EQUALS: - return model.SearchMethodEquals + return domain.SearchMethodEquals case management.SearchMethod_SEARCHMETHOD_CONTAINS: - return model.SearchMethodContains + return domain.SearchMethodContains case management.SearchMethod_SEARCHMETHOD_STARTS_WITH: - return model.SearchMethodStartsWith + return domain.SearchMethodStartsWith case management.SearchMethod_SEARCHMETHOD_EQUALS_IGNORE_CASE: - return model.SearchMethodEqualsIgnoreCase + return domain.SearchMethodEqualsIgnoreCase case management.SearchMethod_SEARCHMETHOD_CONTAINS_IGNORE_CASE: - return model.SearchMethodContainsIgnoreCase + return domain.SearchMethodContainsIgnoreCase case management.SearchMethod_SEARCHMETHOD_STARTS_WITH_IGNORE_CASE: - return model.SearchMethodStartsWithIgnoreCase + return domain.SearchMethodStartsWithIgnoreCase case management.SearchMethod_SEARCHMETHOD_NOT_EQUALS: - return model.SearchMethodNotEquals + return domain.SearchMethodNotEquals case management.SearchMethod_SEARCHMETHOD_IS_ONE_OF: - return model.SearchMethodIsOneOf + return domain.SearchMethodIsOneOf case management.SearchMethod_SEARCHMETHOD_LIST_CONTAINS: - return model.SearchMethodListContains + return domain.SearchMethodListContains default: - return model.SearchMethodEquals + return domain.SearchMethodEquals } } diff --git a/internal/api/grpc/management/user_converter.go b/internal/api/grpc/management/user_converter.go index 7abffb66d8..bf31585ae1 100644 --- a/internal/api/grpc/management/user_converter.go +++ b/internal/api/grpc/management/user_converter.go @@ -13,7 +13,6 @@ import ( "github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/eventstore/v1/models" - "github.com/caos/zitadel/internal/model" usr_model "github.com/caos/zitadel/internal/user/model" "github.com/caos/zitadel/pkg/grpc/management" "github.com/caos/zitadel/pkg/grpc/message" @@ -74,7 +73,7 @@ func externalIDPSearchRequestToModel(request *management.ExternalIDPSearchReques return &usr_model.ExternalIDPSearchRequest{ Limit: request.Limit, Offset: request.Offset, - Queries: []*usr_model.ExternalIDPSearchQuery{{Key: usr_model.ExternalIDPSearchKeyUserID, Method: model.SearchMethodEquals, Value: request.UserId}}, + Queries: []*usr_model.ExternalIDPSearchQuery{{Key: usr_model.ExternalIDPSearchKeyUserID, Method: domain.SearchMethodEquals, Value: request.UserId}}, } } @@ -543,6 +542,19 @@ func genderFromDomain(gender domain.Gender) management.Gender { } } +func genderFromModel(gender usr_model.Gender) management.Gender { + switch gender { + case usr_model.GenderFemale: + return management.Gender_GENDER_FEMALE + case usr_model.GenderMale: + return management.Gender_GENDER_MALE + case usr_model.GenderDiverse: + return management.Gender_GENDER_DIVERSE + default: + return management.Gender_GENDER_UNSPECIFIED + } +} + func memberTypeFromModel(memberType usr_model.MemberType) management.MemberType { switch memberType { case usr_model.MemberTypeOrganisation: diff --git a/internal/api/grpc/management/user_human_converter.go b/internal/api/grpc/management/user_human_converter.go index 0bfad70425..315c68678e 100644 --- a/internal/api/grpc/management/user_human_converter.go +++ b/internal/api/grpc/management/user_human_converter.go @@ -47,18 +47,17 @@ func humanViewFromModel(user *usr_model.HumanView) *management.HumanView { DisplayName: user.DisplayName, NickName: user.NickName, PreferredLanguage: user.PreferredLanguage, - //TODO: User converter - Gender: management.Gender(user.Gender), - Email: user.Email, - IsEmailVerified: user.IsEmailVerified, - Phone: user.Phone, - IsPhoneVerified: user.IsPhoneVerified, - Country: user.Country, - Locality: user.Locality, - PostalCode: user.PostalCode, - Region: user.Region, - StreetAddress: user.StreetAddress, - PasswordChanged: passwordChanged, + Gender: genderFromModel(user.Gender), + Email: user.Email, + IsEmailVerified: user.IsEmailVerified, + Phone: user.Phone, + IsPhoneVerified: user.IsPhoneVerified, + Country: user.Country, + Locality: user.Locality, + PostalCode: user.PostalCode, + Region: user.Region, + StreetAddress: user.StreetAddress, + PasswordChanged: passwordChanged, } } diff --git a/internal/api/grpc/management/user_machine_converter.go b/internal/api/grpc/management/user_machine_converter.go index a03240ef09..278576d261 100644 --- a/internal/api/grpc/management/user_machine_converter.go +++ b/internal/api/grpc/management/user_machine_converter.go @@ -13,7 +13,6 @@ import ( "github.com/caos/zitadel/internal/eventstore/v1/models" key_model "github.com/caos/zitadel/internal/key/model" - "github.com/caos/zitadel/internal/model" usr_model "github.com/caos/zitadel/internal/user/model" "github.com/caos/zitadel/pkg/grpc/management" ) @@ -151,11 +150,11 @@ func machineKeySearchRequestToModel(req *management.MachineKeySearchRequest) *ke Queries: []*key_model.AuthNKeySearchQuery{ { Key: key_model.AuthNKeyObjectType, - Method: model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: key_model.AuthNKeyObjectTypeUser, }, { Key: key_model.AuthNKeyObjectID, - Method: model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: req.UserId, }, }, diff --git a/internal/auth/repository/eventsourcing/eventstore/user_grant.go b/internal/auth/repository/eventsourcing/eventstore/user_grant.go index e2bbd63703..27e19a75cc 100644 --- a/internal/auth/repository/eventsourcing/eventstore/user_grant.go +++ b/internal/auth/repository/eventsourcing/eventstore/user_grant.go @@ -3,12 +3,12 @@ package eventstore import ( "context" "github.com/caos/logging" + "github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/api/authz" "github.com/caos/zitadel/internal/auth/repository/eventsourcing/view" authz_repo "github.com/caos/zitadel/internal/authz/repository/eventsourcing" caos_errs "github.com/caos/zitadel/internal/errors" - global_model "github.com/caos/zitadel/internal/model" org_model "github.com/caos/zitadel/internal/org/model" org_view_model "github.com/caos/zitadel/internal/org/repository/view/model" "github.com/caos/zitadel/internal/telemetry/tracing" @@ -30,7 +30,7 @@ func (repo *UserGrantRepo) SearchMyUserGrants(ctx context.Context, request *gran request.EnsureLimit(repo.SearchLimit) sequence, err := repo.View.GetLatestUserGrantSequence() logging.Log("EVENT-Hd7s3").OnError(err).WithField("traceID", tracing.TraceIDFromCtx(ctx)).Warn("could not read latest user grant sequence") - request.Queries = append(request.Queries, &grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyUserID, Method: global_model.SearchMethodEquals, Value: authz.GetCtxData(ctx).UserID}) + request.Queries = append(request.Queries, &grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyUserID, Method: domain.SearchMethodEquals, Value: authz.GetCtxData(ctx).UserID}) grants, count, err := repo.View.SearchUserGrants(request) if err != nil { return nil, err @@ -68,7 +68,7 @@ func (repo *UserGrantRepo) SearchMyProjectOrgs(ctx context.Context, request *gra } return repo.searchZitadelOrgs(ctxData, request) } - request.Queries = append(request.Queries, &grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyProjectID, Method: global_model.SearchMethodEquals, Value: ctxData.ProjectID}) + request.Queries = append(request.Queries, &grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyProjectID, Method: domain.SearchMethodEquals, Value: ctxData.ProjectID}) grants, err := repo.SearchMyUserGrants(ctx, request) if err != nil { @@ -135,12 +135,12 @@ func (repo *UserGrantRepo) searchUserMemberships(ctx context.Context) ([]*user_v Queries: []*user_model.UserMembershipSearchQuery{ { Key: user_model.UserMembershipSearchKeyUserID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: ctxData.UserID, }, { Key: user_model.UserMembershipSearchKeyResourceOwner, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: ctxData.OrgID, }, }, @@ -152,12 +152,12 @@ func (repo *UserGrantRepo) searchUserMemberships(ctx context.Context) ([]*user_v Queries: []*user_model.UserMembershipSearchQuery{ { Key: user_model.UserMembershipSearchKeyUserID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: ctxData.UserID, }, { Key: user_model.UserMembershipSearchKeyAggregateID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: repo.IamID, }, }, @@ -203,7 +203,7 @@ func (repo *UserGrantRepo) SearchAdminOrgs(request *grant_model.UserGrantSearchR func (repo *UserGrantRepo) IsIamAdmin(ctx context.Context) (bool, error) { grantSearch := &grant_model.UserGrantSearchRequest{ Queries: []*grant_model.UserGrantSearchQuery{ - {Key: grant_model.UserGrantSearchKeyResourceOwner, Method: global_model.SearchMethodEquals, Value: repo.IamID}, + {Key: grant_model.UserGrantSearchKeyResourceOwner, Method: domain.SearchMethodEquals, Value: repo.IamID}, }} result, err := repo.SearchMyUserGrants(ctx, grantSearch) if err != nil { @@ -246,7 +246,7 @@ func (repo *UserGrantRepo) searchZitadelOrgs(ctxData authz.CtxData, request *gra Queries: []*user_model.UserMembershipSearchQuery{ { Key: user_model.UserMembershipSearchKeyUserID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: ctxData.UserID, }, }, diff --git a/internal/auth/repository/eventsourcing/view/application.go b/internal/auth/repository/eventsourcing/view/application.go index aaf1229def..bbfb6c0944 100644 --- a/internal/auth/repository/eventsourcing/view/application.go +++ b/internal/auth/repository/eventsourcing/view/application.go @@ -2,10 +2,10 @@ package view import ( "context" + "github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/errors" "github.com/caos/zitadel/internal/eventstore/v1/models" - global_model "github.com/caos/zitadel/internal/model" proj_model "github.com/caos/zitadel/internal/project/model" "github.com/caos/zitadel/internal/project/repository/view" "github.com/caos/zitadel/internal/project/repository/view/model" @@ -89,7 +89,7 @@ func (v *View) AppIDsFromProjectByClientID(ctx context.Context, clientID string) Queries: []*proj_model.ApplicationSearchQuery{ { Key: proj_model.AppSearchKeyProjectID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: app.ProjectID, }, }, @@ -113,7 +113,7 @@ func (v *View) AppIDsFromProjectID(ctx context.Context, projectID string) ([]str Queries: []*proj_model.ApplicationSearchQuery{ { Key: proj_model.AppSearchKeyProjectID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: projectID, }, }, diff --git a/internal/authz/repository/eventsourcing/eventstore/user_grant.go b/internal/authz/repository/eventsourcing/eventstore/user_grant.go index 81c8208fec..324da6df26 100644 --- a/internal/authz/repository/eventsourcing/eventstore/user_grant.go +++ b/internal/authz/repository/eventsourcing/eventstore/user_grant.go @@ -14,7 +14,6 @@ import ( "github.com/caos/zitadel/internal/authz/repository/eventsourcing/view" "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" - global_model "github.com/caos/zitadel/internal/model" user_model "github.com/caos/zitadel/internal/user/model" user_view_model "github.com/caos/zitadel/internal/user/repository/view/model" grant_model "github.com/caos/zitadel/internal/usergrant/model" @@ -60,12 +59,12 @@ func (repo *UserGrantRepo) searchUserMemberships(ctx context.Context) ([]*user_v Queries: []*user_model.UserMembershipSearchQuery{ { Key: user_model.UserMembershipSearchKeyUserID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: ctxData.UserID, }, { Key: user_model.UserMembershipSearchKeyResourceOwner, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: ctxData.OrgID, }, }, @@ -77,12 +76,12 @@ func (repo *UserGrantRepo) searchUserMemberships(ctx context.Context) ([]*user_v Queries: []*user_model.UserMembershipSearchQuery{ { Key: user_model.UserMembershipSearchKeyUserID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: ctxData.UserID, }, { Key: user_model.UserMembershipSearchKeyAggregateID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: repo.IamID, }, }, diff --git a/internal/command/command.go b/internal/command/command.go index 6dd646e0a0..10353945f1 100644 --- a/internal/command/command.go +++ b/internal/command/command.go @@ -2,7 +2,9 @@ package command import ( "context" + "github.com/caos/zitadel/internal/api/authz" "github.com/caos/zitadel/internal/config/types" + "github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/eventstore" "time" @@ -10,7 +12,6 @@ import ( sd "github.com/caos/zitadel/internal/config/systemdefaults" "github.com/caos/zitadel/internal/crypto" "github.com/caos/zitadel/internal/id" - global_model "github.com/caos/zitadel/internal/model" iam_repo "github.com/caos/zitadel/internal/repository/iam" keypair "github.com/caos/zitadel/internal/repository/keypair" "github.com/caos/zitadel/internal/repository/org" @@ -22,9 +23,10 @@ import ( ) type Commands struct { - eventstore *eventstore.Eventstore - idGenerator id.Generator - iamDomain string + eventstore *eventstore.Eventstore + idGenerator id.Generator + iamDomain string + zitadelRoles []authz.RoleMapping idpConfigSecretCrypto crypto.Crypto @@ -40,8 +42,7 @@ type Commands struct { domainVerificationAlg *crypto.AESCrypto domainVerificationGenerator crypto.Generator domainVerificationValidator func(domain, token, verifier string, checkType http.CheckType) error - //TODO: remove global model, or move to domain - multifactors global_model.Multifactors + multifactors domain.MultifactorConfigs webauthn *webauthn_helper.WebAuthN keySize int @@ -54,11 +55,12 @@ type Config struct { Eventstore types.SQLUser } -func StartCommands(eventstore *eventstore.Eventstore, defaults sd.SystemDefaults) (repo *Commands, err error) { +func StartCommands(eventstore *eventstore.Eventstore, defaults sd.SystemDefaults, authZConfig authz.Config) (repo *Commands, err error) { repo = &Commands{ eventstore: eventstore, idGenerator: id.SonyFlakeGenerator, iamDomain: defaults.Domain, + zitadelRoles: authZConfig.RolePermissionMappings, keySize: defaults.KeyConfig.Size, privateKeyLifetime: defaults.KeyConfig.PrivateKeyLifetime.Duration, publicKeyLifetime: defaults.KeyConfig.PublicKeyLifetime.Duration, @@ -70,7 +72,6 @@ func StartCommands(eventstore *eventstore.Eventstore, defaults sd.SystemDefaults proj_repo.RegisterEventMappers(repo.eventstore) keypair.RegisterEventMappers(repo.eventstore) - //TODO: simplify!!!! repo.idpConfigSecretCrypto, err = crypto.NewAESCrypto(defaults.IDPConfigVerificationKey) if err != nil { return nil, err @@ -92,8 +93,8 @@ func StartCommands(eventstore *eventstore.Eventstore, defaults sd.SystemDefaults if err != nil { return nil, err } - repo.multifactors = global_model.Multifactors{ - OTP: global_model.OTP{ + repo.multifactors = domain.MultifactorConfigs{ + OTP: domain.OTPConfig{ CryptoMFA: aesOTPCrypto, Issuer: defaults.Multifactors.OTP.Issuer, }, diff --git a/internal/command/iam.go b/internal/command/iam.go index 59bd733669..c0823254a3 100644 --- a/internal/command/iam.go +++ b/internal/command/iam.go @@ -8,7 +8,7 @@ import ( "github.com/caos/zitadel/internal/repository/iam" ) -//TODO: private +//TODO: private as soon as setup uses query func (c *Commands) GetIAM(ctx context.Context) (*domain.IAM, error) { iamWriteModel := NewIAMWriteModel() err := c.eventstore.FilterToQueryReducer(ctx, iamWriteModel) diff --git a/internal/command/iam_converter.go b/internal/command/iam_converter.go index a90904cc6e..d9e26f5b12 100644 --- a/internal/command/iam_converter.go +++ b/internal/command/iam_converter.go @@ -132,7 +132,6 @@ func writeModelToPasswordLockoutPolicy(wm *PasswordLockoutPolicyWriteModel) *dom func writeModelToIDPConfig(wm *IDPConfigWriteModel) *domain.IDPConfig { return &domain.IDPConfig{ ObjectRoot: writeModelToObjectRoot(wm.WriteModel), - OIDCConfig: writeModelToIDPOIDCConfig(wm.OIDCConfig), IDPConfigID: wm.ConfigID, Name: wm.Name, State: wm.State, diff --git a/internal/command/iam_idp_config.go b/internal/command/iam_idp_config.go index 22e44beaee..fc5d432de7 100644 --- a/internal/command/iam_idp_config.go +++ b/internal/command/iam_idp_config.go @@ -141,6 +141,17 @@ func (c *Commands) RemoveDefaultIDPConfig(ctx context.Context, idpID string, idp return err } +func (c *Commands) getIAMIDPConfigByID(ctx context.Context, idpID string) (*domain.IDPConfig, error) { + config, err := c.iamIDPConfigWriteModelByID(ctx, idpID) + if err != nil { + return nil, err + } + if !config.State.Exists() { + return nil, caos_errs.ThrowNotFound(nil, "IAM-4M9so", "Errors.IAM.IDPConfig.NotExisting") + } + return writeModelToIDPConfig(&config.IDPConfigWriteModel), nil +} + func (c *Commands) iamIDPConfigWriteModelByID(ctx context.Context, idpID string) (policy *IAMIDPConfigWriteModel, err error) { ctx, span := tracing.NewSpan(ctx) defer func() { span.EndWithError(err) }() diff --git a/internal/command/iam_member.go b/internal/command/iam_member.go index d5f0d2d762..5ab91bd275 100644 --- a/internal/command/iam_member.go +++ b/internal/command/iam_member.go @@ -32,11 +32,12 @@ func (c *Commands) AddIAMMember(ctx context.Context, member *domain.Member) (*do } func (c *Commands) addIAMMember(ctx context.Context, iamAgg *eventstore.Aggregate, addedMember *IAMMemberWriteModel, member *domain.Member) (eventstore.EventPusher, error) { - //TODO: check if roles valid - if !member.IsValid() { return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-GR34U", "Errors.IAM.MemberInvalid") } + if len(domain.CheckForInvalidRoles(member.Roles, domain.IAMRolePrefix, c.zitadelRoles)) > 0 { + return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-4m0fS", "Errors.IAM.MemberInvalid") + } err := c.eventstore.FilterToQueryReducer(ctx, addedMember) if err != nil { @@ -51,11 +52,12 @@ func (c *Commands) addIAMMember(ctx context.Context, iamAgg *eventstore.Aggregat //ChangeIAMMember updates an existing member func (c *Commands) ChangeIAMMember(ctx context.Context, member *domain.Member) (*domain.Member, error) { - //TODO: check if roles valid - if !member.IsValid() { return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-LiaZi", "Errors.IAM.MemberInvalid") } + if len(domain.CheckForInvalidRoles(member.Roles, domain.IAMRolePrefix, c.zitadelRoles)) > 0 { + return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-3m9fs", "Errors.IAM.MemberInvalid") + } existingMember, err := c.iamMemberWriteModelByID(ctx, member.UserID) if err != nil { diff --git a/internal/command/idp_config_model.go b/internal/command/idp_config_model.go index 93d0f370c8..133e12047c 100644 --- a/internal/command/idp_config_model.go +++ b/internal/command/idp_config_model.go @@ -14,22 +14,10 @@ type IDPConfigWriteModel struct { ConfigID string Name string StylingType domain.IDPConfigStylingType - - //TODO: sub writemodels not used anymore? - OIDCConfig *OIDCConfigWriteModel } func (rm *IDPConfigWriteModel) AppendEvents(events ...eventstore.EventReader) { rm.WriteModel.AppendEvents(events...) - for _, event := range events { - switch event.(type) { - case *idpconfig.OIDCConfigAddedEvent: - rm.OIDCConfig = new(OIDCConfigWriteModel) - rm.OIDCConfig.AppendEvents(event) - case *idpconfig.OIDCConfigChangedEvent: - rm.OIDCConfig.AppendEvents(event) - } - } } func (rm *IDPConfigWriteModel) Reduce() error { @@ -47,11 +35,6 @@ func (rm *IDPConfigWriteModel) Reduce() error { rm.reduceConfigStateChanged(e.ConfigID, domain.IDPConfigStateRemoved) } } - if rm.OIDCConfig != nil { - if err := rm.OIDCConfig.Reduce(); err != nil { - return err - } - } return rm.WriteModel.Reduce() } diff --git a/internal/command/org_domain_model.go b/internal/command/org_domain_model.go index e9a77b7a6c..e0101f7cd2 100644 --- a/internal/command/org_domain_model.go +++ b/internal/command/org_domain_model.go @@ -72,8 +72,6 @@ func (wm *OrgDomainWriteModel) Reduce() error { case *org.DomainVerificationAddedEvent: wm.ValidationType = e.ValidationType wm.ValidationCode = e.ValidationCode - case *org.DomainVerificationFailedEvent: - //TODO: not handled in v1 case *org.DomainVerifiedEvent: wm.Verified = true case *org.DomainPrimarySetEvent: diff --git a/internal/command/org_idp_config.go b/internal/command/org_idp_config.go index a2abde71fa..2fe4c7d837 100644 --- a/internal/command/org_idp_config.go +++ b/internal/command/org_idp_config.go @@ -143,6 +143,17 @@ func (c *Commands) RemoveIDPConfig(ctx context.Context, idpID, orgID string, cas return err } +func (c *Commands) getOrgIDPConfigByID(ctx context.Context, idpID, orgID string) (*domain.IDPConfig, error) { + config, err := c.orgIDPConfigWriteModelByID(ctx, idpID, orgID) + if err != nil { + return nil, err + } + if !config.State.Exists() { + return nil, caos_errs.ThrowNotFound(nil, "IAM-4M9so", "Errors.Org.IDPConfig.NotExisting") + } + return writeModelToIDPConfig(&config.IDPConfigWriteModel), nil +} + func (c *Commands) orgIDPConfigWriteModelByID(ctx context.Context, idpID, orgID string) (policy *OrgIDPConfigWriteModel, err error) { ctx, span := tracing.NewSpan(ctx) defer func() { span.EndWithError(err) }() diff --git a/internal/command/org_member.go b/internal/command/org_member.go index 4846a95dce..a99dbb78fd 100644 --- a/internal/command/org_member.go +++ b/internal/command/org_member.go @@ -32,11 +32,12 @@ func (c *Commands) AddOrgMember(ctx context.Context, member *domain.Member) (*do } func (c *Commands) addOrgMember(ctx context.Context, orgAgg *eventstore.Aggregate, addedMember *OrgMemberWriteModel, member *domain.Member) (eventstore.EventPusher, error) { - //TODO: check if roles valid - if !member.IsValid() { return nil, caos_errs.ThrowPreconditionFailed(nil, "Org-W8m4l", "Errors.Org.MemberInvalid") } + if len(domain.CheckForInvalidRoles(member.Roles, domain.OrgRolePrefix, c.zitadelRoles)) > 0 { + return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-3m9fs", "Errors.Org.MemberInvalid") + } err := c.eventstore.FilterToQueryReducer(ctx, addedMember) if err != nil { @@ -51,11 +52,12 @@ func (c *Commands) addOrgMember(ctx context.Context, orgAgg *eventstore.Aggregat //ChangeOrgMember updates an existing member func (c *Commands) ChangeOrgMember(ctx context.Context, member *domain.Member) (*domain.Member, error) { - //TODO: check if roles valid - if !member.IsValid() { return nil, caos_errs.ThrowPreconditionFailed(nil, "Org-LiaZi", "Errors.Org.MemberInvalid") } + if len(domain.CheckForInvalidRoles(member.Roles, domain.OrgRolePrefix, c.zitadelRoles)) > 0 { + return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-m9fG8", "Errors.Org.MemberInvalid") + } existingMember, err := c.orgMemberWriteModelByID(ctx, member.AggregateID, member.UserID) if err != nil { diff --git a/internal/command/project_grant_member.go b/internal/command/project_grant_member.go index c745e6e846..d0f3dcf95c 100644 --- a/internal/command/project_grant_member.go +++ b/internal/command/project_grant_member.go @@ -44,11 +44,12 @@ func (c *Commands) AddProjectGrantMember(ctx context.Context, member *domain.Pro //ChangeProjectGrantMember updates an existing member func (c *Commands) ChangeProjectGrantMember(ctx context.Context, member *domain.ProjectGrantMember, resourceOwner string) (*domain.ProjectGrantMember, error) { - //TODO: check if roles valid - if !member.IsValid() { return nil, caos_errs.ThrowPreconditionFailed(nil, "PROJECT-109fs", "Errors.Project.Member.Invalid") } + if len(domain.CheckForInvalidRoles(member.Roles, domain.ProjectGrantRolePrefix, c.zitadelRoles)) > 0 { + return nil, caos_errs.ThrowPreconditionFailed(nil, "PROJECT-m0sDf", "Errors.Project.Member.Invalid") + } existingMember, err := c.projectGrantMemberWriteModelByID(ctx, member.AggregateID, member.UserID, member.GrantID) if err != nil { diff --git a/internal/command/project_member.go b/internal/command/project_member.go index 4926f52f2d..321899dbc0 100644 --- a/internal/command/project_member.go +++ b/internal/command/project_member.go @@ -33,11 +33,12 @@ func (c *Commands) AddProjectMember(ctx context.Context, member *domain.Member, } func (c *Commands) addProjectMember(ctx context.Context, projectAgg *eventstore.Aggregate, addedMember *ProjectMemberWriteModel, member *domain.Member) (eventstore.EventPusher, error) { - //TODO: check if roles valid - if !member.IsValid() { return nil, caos_errs.ThrowPreconditionFailed(nil, "PROJECT-W8m4l", "Errors.Project.Member.Invalid") } + if len(domain.CheckForInvalidRoles(member.Roles, domain.ProjectRolePrefix, c.zitadelRoles)) > 0 { + return nil, caos_errs.ThrowPreconditionFailed(nil, "PROJECT-3m9ds", "Errors.Project.Member.Invalid") + } err := c.checkUserExists(ctx, addedMember.UserID, "") if err != nil { @@ -56,11 +57,12 @@ func (c *Commands) addProjectMember(ctx context.Context, projectAgg *eventstore. //ChangeProjectMember updates an existing member func (c *Commands) ChangeProjectMember(ctx context.Context, member *domain.Member, resourceOwner string) (*domain.Member, error) { - //TODO: check if roles valid - if !member.IsValid() { return nil, caos_errs.ThrowPreconditionFailed(nil, "PROJECT-LiaZi", "Errors.Project.Member.Invalid") } + if len(domain.CheckForInvalidRoles(member.Roles, domain.ProjectRolePrefix, c.zitadelRoles)) > 0 { + return nil, caos_errs.ThrowPreconditionFailed(nil, "PROJECT-3m9d", "Errors.Project.Member.Invalid") + } existingMember, err := c.projectMemberWriteModelByID(ctx, member.AggregateID, member.UserID, resourceOwner) if err != nil { diff --git a/internal/command/user_human_externalidp.go b/internal/command/user_human_externalidp.go index 8518ede69c..2e8f533df2 100644 --- a/internal/command/user_human_externalidp.go +++ b/internal/command/user_human_externalidp.go @@ -30,12 +30,18 @@ func (c *Commands) BulkAddedHumanExternalIDP(ctx context.Context, userID, resour return err } -func (c *Commands) addHumanExternalIDP(ctx context.Context, aggregate *eventstore.Aggregate, externalIDP *domain.ExternalIDP) (eventstore.EventPusher, error) { +func (c *Commands) addHumanExternalIDP(ctx context.Context, humanAgg *eventstore.Aggregate, externalIDP *domain.ExternalIDP) (eventstore.EventPusher, error) { if !externalIDP.IsValid() { return nil, caos_errs.ThrowPreconditionFailed(nil, "COMMAND-6m9Kd", "Errors.User.ExternalIDP.Invalid") } - //TODO: check if idpconfig exists - return user.NewHumanExternalIDPAddedEvent(ctx, aggregate, externalIDP.IDPConfigID, externalIDP.DisplayName, externalIDP.ExternalUserID), nil + _, err := c.getOrgIDPConfigByID(ctx, externalIDP.IDPConfigID, humanAgg.ResourceOwner) + if caos_errs.IsNotFound(err) { + _, err = c.getIAMIDPConfigByID(ctx, externalIDP.IDPConfigID) + } + if err != nil { + return nil, err + } + return user.NewHumanExternalIDPAddedEvent(ctx, humanAgg, externalIDP.IDPConfigID, externalIDP.DisplayName, externalIDP.ExternalUserID), nil } func (c *Commands) RemoveHumanExternalIDP(ctx context.Context, externalIDP *domain.ExternalIDP) error { diff --git a/internal/command/user_human_phone.go b/internal/command/user_human_phone.go index 835ecc2732..dbbfa45240 100644 --- a/internal/command/user_human_phone.go +++ b/internal/command/user_human_phone.go @@ -21,7 +21,7 @@ func (c *Commands) ChangeHumanPhone(ctx context.Context, phone *domain.Phone) (* if err != nil { return nil, err } - if existingPhone.State == domain.PhoneStateUnspecified || existingPhone.State == domain.PhoneStateRemoved { + if !existingPhone.State.Exists() { return nil, caos_errs.ThrowNotFound(nil, "COMMAND-aM9cs", "Errors.User.Phone.NotFound") } @@ -66,7 +66,7 @@ func (c *Commands) VerifyHumanPhone(ctx context.Context, userID, code, resourceo if err != nil { return err } - if existingCode.Code == nil || existingCode.State == domain.PhoneStateUnspecified || existingCode.State == domain.PhoneStateRemoved { + if !existingCode.State.Exists() { return caos_errs.ThrowNotFound(nil, "COMMAND-Rsj8c", "Errors.User.Code.NotFound") } @@ -92,8 +92,7 @@ func (c *Commands) CreateHumanPhoneVerificationCode(ctx context.Context, userID, return err } - //TODO: code like the following if is written many times find way to simplify - if existingPhone.State == domain.PhoneStateUnspecified || existingPhone.State == domain.PhoneStateRemoved { + if !existingPhone.State.Exists() { return caos_errs.ThrowNotFound(nil, "COMMAND-2b7Hf", "Errors.User.Phone.NotFound") } if existingPhone.IsPhoneVerified { @@ -115,7 +114,7 @@ func (c *Commands) HumanPhoneVerificationCodeSent(ctx context.Context, orgID, us if err != nil { return err } - if existingPhone.State == domain.PhoneStateUnspecified || existingPhone.State == domain.PhoneStateRemoved { + if !existingPhone.State.Exists() { return caos_errs.ThrowNotFound(nil, "COMMAND-66n8J", "Errors.User.Phone.NotFound") } @@ -133,7 +132,7 @@ func (c *Commands) RemoveHumanPhone(ctx context.Context, userID, resourceOwner s if err != nil { return err } - if existingPhone.State == domain.PhoneStateUnspecified || existingPhone.State == domain.PhoneStateRemoved { + if !existingPhone.State.Exists() { return caos_errs.ThrowNotFound(nil, "COMMAND-p6rsc", "Errors.User.Phone.NotFound") } diff --git a/internal/command/user_human_webauthn.go b/internal/command/user_human_webauthn.go index 1b8c4062bc..1cbf924b8e 100644 --- a/internal/command/user_human_webauthn.go +++ b/internal/command/user_human_webauthn.go @@ -2,6 +2,7 @@ package command import ( "context" + "github.com/caos/logging" "github.com/caos/zitadel/internal/eventstore" "github.com/caos/zitadel/internal/domain" @@ -165,7 +166,7 @@ func (c *Commands) HumanVerifyU2FSetup(ctx context.Context, userID, resourceowne usr_repo.NewHumanU2FVerifiedEvent( ctx, userAgg, - verifyWebAuthN.WebauthNTokenID, //TODO: webAuthN andverifyWebAuthN same TokenID? + verifyWebAuthN.WebauthNTokenID, webAuthN.WebAuthNTokenName, webAuthN.AttestationType, webAuthN.KeyID, @@ -191,7 +192,7 @@ func (c *Commands) HumanHumanPasswordlessSetup(ctx context.Context, userID, reso usr_repo.NewHumanPasswordlessVerifiedEvent( ctx, userAgg, - verifyWebAuthN.WebauthNTokenID, //TODO: webAuthN andverifyWebAuthN same TokenID? + verifyWebAuthN.WebauthNTokenID, webAuthN.WebAuthNTokenName, webAuthN.AttestationType, webAuthN.KeyID, @@ -305,10 +306,23 @@ func (c *Commands) HumanFinishU2FLogin(ctx context.Context, userID, resourceOwne userAgg, token, signCount, err := c.finishWebAuthNLogin(ctx, userID, resourceOwner, credentialData, webAuthNLogin, u2fTokens, isLoginUI) if err != nil { + _, pushErr := c.eventstore.PushEvents(ctx, + usr_repo.NewHumanU2FCheckFailedEvent( + ctx, + userAgg, + authRequestDomainToAuthRequestInfo(authRequest), + ), + ) + logging.Log("EVENT-33M9f").OnError(pushErr).WithField("userID", userID).Warn("could not push failed passwordless check event") return err } _, err = c.eventstore.PushEvents(ctx, + usr_repo.NewHumanU2FCheckSucceededEvent( + ctx, + userAgg, + authRequestDomainToAuthRequestInfo(authRequest), + ), usr_repo.NewHumanU2FSignCountChangedEvent( ctx, userAgg, @@ -333,10 +347,23 @@ func (c *Commands) HumanFinishPasswordlessLogin(ctx context.Context, userID, res userAgg, token, signCount, err := c.finishWebAuthNLogin(ctx, userID, resourceOwner, credentialData, webAuthNLogin, passwordlessTokens, isLoginUI) if err != nil { + _, pushErr := c.eventstore.PushEvents(ctx, + usr_repo.NewHumanPasswordlessCheckFailedEvent( + ctx, + userAgg, + authRequestDomainToAuthRequestInfo(authRequest), + ), + ) + logging.Log("EVENT-33M9f").OnError(pushErr).WithField("userID", userID).Warn("could not push failed passwordless check event") return err } _, err = c.eventstore.PushEvents(ctx, + usr_repo.NewHumanU2FCheckSucceededEvent( + ctx, + userAgg, + authRequestDomainToAuthRequestInfo(authRequest), + ), usr_repo.NewHumanPasswordlessSignCountChangedEvent( ctx, userAgg, diff --git a/internal/command/user_machine.go b/internal/command/user_machine.go index 13f5fbf652..0fda97c059 100644 --- a/internal/command/user_machine.go +++ b/internal/command/user_machine.go @@ -24,7 +24,6 @@ func (c *Commands) AddMachine(ctx context.Context, orgID string, machine *domain if err != nil { return nil, err } - //TODO: adlerhurst are no machines allowed in global org? or what if I create an org which allowes all suffixes? if !orgIAMPolicy.UserLoginMustBeDomain { return nil, caos_errs.ThrowInvalidArgument(nil, "COMMAND-6M0ds", "Errors.User.Invalid") } diff --git a/internal/domain/human_phone.go b/internal/domain/human_phone.go index 7b0cd3a9af..375718f3be 100644 --- a/internal/domain/human_phone.go +++ b/internal/domain/human_phone.go @@ -64,3 +64,7 @@ const ( func (s PhoneState) Valid() bool { return s >= 0 && s < phoneStateCount } + +func (s PhoneState) Exists() bool { + return s == PhoneStateActive +} diff --git a/internal/domain/human_web_auth_n.go b/internal/domain/human_web_auth_n.go index 96c6a293da..6c571e4388 100644 --- a/internal/domain/human_web_auth_n.go +++ b/internal/domain/human_web_auth_n.go @@ -29,8 +29,6 @@ type WebAuthNLogin struct { Challenge string AllowedCredentialIDs [][]byte UserVerification UserVerificationRequirement - //TODO: Add Auth Request - //*model.AuthRequest } type UserVerificationRequirement int32 diff --git a/internal/domain/idp_config.go b/internal/domain/idp_config.go index 8ef8084c60..3561345cf6 100644 --- a/internal/domain/idp_config.go +++ b/internal/domain/idp_config.go @@ -73,8 +73,12 @@ const ( idpConfigStateCount ) -func (f IDPConfigState) Valid() bool { - return f >= 0 && f < idpConfigStateCount +func (s IDPConfigState) Valid() bool { + return s >= 0 && s < idpConfigStateCount +} + +func (s IDPConfigState) Exists() bool { + return s != IDPConfigStateUnspecified || s == IDPConfigStateRemoved } type IDPConfigStylingType int32 diff --git a/internal/domain/mfa.go b/internal/domain/mfa.go index 3785e46f64..c60726f970 100644 --- a/internal/domain/mfa.go +++ b/internal/domain/mfa.go @@ -1,5 +1,7 @@ package domain +import "github.com/caos/zitadel/internal/crypto" + type MFAState int32 const ( @@ -14,3 +16,12 @@ const ( func (f MFAState) Valid() bool { return f >= 0 && f < stateCount } + +type MultifactorConfigs struct { + OTP OTPConfig +} + +type OTPConfig struct { + Issuer string + CryptoMFA crypto.EncryptionAlgorithm +} diff --git a/internal/domain/roles.go b/internal/domain/roles.go index ee87906520..c4dec8e7cc 100644 --- a/internal/domain/roles.go +++ b/internal/domain/roles.go @@ -1,9 +1,37 @@ package domain +import ( + "github.com/caos/zitadel/internal/api/authz" + "strings" +) + const ( + IAMRolePrefix = "IAM" + OrgRolePrefix = "ORG" + ProjectRolePrefix = "PROJECT" + ProjectGrantRolePrefix = "PROJECT_GRANT" RoleOrgOwner = "ORG_OWNER" RoleOrgProjectCreator = "ORG_PROJECT_CREATOR" RoleIAMOwner = "IAM_OWNER" RoleProjectOwner = "PROJECT_OWNER" RoleProjectOwnerGlobal = "PROJECT_OWNER_GLOBAL" ) + +func CheckForInvalidRoles(roles []string, rolePrefix string, validRoles []authz.RoleMapping) []string { + invalidRoles := make([]string, 0) + for _, role := range roles { + if !containsRole(role, rolePrefix, validRoles) { + invalidRoles = append(invalidRoles, role) + } + } + return invalidRoles +} + +func containsRole(role, rolePrefix string, validRoles []authz.RoleMapping) bool { + for _, validRole := range validRoles { + if role == validRole.Role && strings.HasPrefix(role, rolePrefix) { + return true + } + } + return false +} diff --git a/internal/model/search_method.go b/internal/domain/search_method.go similarity index 96% rename from internal/model/search_method.go rename to internal/domain/search_method.go index a8433304b7..8867af7e68 100644 --- a/internal/model/search_method.go +++ b/internal/domain/search_method.go @@ -1,4 +1,4 @@ -package model +package domain type SearchMethod int32 diff --git a/internal/iam/model/iam_member_view.go b/internal/iam/model/iam_member_view.go index e56409c03b..3f89ebe541 100644 --- a/internal/iam/model/iam_member_view.go +++ b/internal/iam/model/iam_member_view.go @@ -1,9 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" "time" - - "github.com/caos/zitadel/internal/model" ) type IAMMemberView struct { @@ -42,7 +41,7 @@ const ( type IAMMemberSearchQuery struct { Key IAMMemberSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } diff --git a/internal/iam/model/idp_config_view.go b/internal/iam/model/idp_config_view.go index 983e0bc5ab..8ef4875f75 100644 --- a/internal/iam/model/idp_config_view.go +++ b/internal/iam/model/idp_config_view.go @@ -2,7 +2,7 @@ package model import ( "github.com/caos/zitadel/internal/crypto" - "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" "time" ) @@ -46,7 +46,7 @@ const ( type IDPConfigSearchQuery struct { Key IDPConfigSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } @@ -66,5 +66,5 @@ func (r *IDPConfigSearchRequest) EnsureLimit(limit uint64) { } func (r *IDPConfigSearchRequest) AppendMyOrgQuery(orgID, iamID string) { - r.Queries = append(r.Queries, &IDPConfigSearchQuery{Key: IDPConfigSearchKeyAggregateID, Method: model.SearchMethodIsOneOf, Value: []string{orgID, iamID}}) + r.Queries = append(r.Queries, &IDPConfigSearchQuery{Key: IDPConfigSearchKeyAggregateID, Method: domain.SearchMethodIsOneOf, Value: []string{orgID, iamID}}) } diff --git a/internal/iam/model/idp_provider_view.go b/internal/iam/model/idp_provider_view.go index 7686f857f4..62ae100784 100644 --- a/internal/iam/model/idp_provider_view.go +++ b/internal/iam/model/idp_provider_view.go @@ -2,7 +2,6 @@ package model import ( "github.com/caos/zitadel/internal/domain" - "github.com/caos/zitadel/internal/model" "time" ) @@ -39,7 +38,7 @@ const ( type IDPProviderSearchQuery struct { Key IDPProviderSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } @@ -59,7 +58,7 @@ func (r *IDPProviderSearchRequest) EnsureLimit(limit uint64) { } func (r *IDPProviderSearchRequest) AppendAggregateIDQuery(aggregateID string) { - r.Queries = append(r.Queries, &IDPProviderSearchQuery{Key: IDPProviderSearchKeyAggregateID, Method: model.SearchMethodEquals, Value: aggregateID}) + r.Queries = append(r.Queries, &IDPProviderSearchQuery{Key: IDPProviderSearchKeyAggregateID, Method: domain.SearchMethodEquals, Value: aggregateID}) } func IdpProviderViewsToDomain(idpProviders []*IDPProviderView) []*domain.IDPProvider { diff --git a/internal/iam/model/label_policy_view.go b/internal/iam/model/label_policy_view.go index 9202680909..f4d715fcdc 100644 --- a/internal/iam/model/label_policy_view.go +++ b/internal/iam/model/label_policy_view.go @@ -1,9 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" "time" - - "github.com/caos/zitadel/internal/model" ) type LabelPolicyView struct { @@ -34,7 +33,7 @@ const ( type LabelPolicySearchQuery struct { Key LabelPolicySearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } diff --git a/internal/iam/model/login_policy_view.go b/internal/iam/model/login_policy_view.go index 43183eda66..b9e8f745e6 100644 --- a/internal/iam/model/login_policy_view.go +++ b/internal/iam/model/login_policy_view.go @@ -3,7 +3,6 @@ package model import ( "github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/eventstore/v1/models" - "github.com/caos/zitadel/internal/model" "time" ) @@ -41,7 +40,7 @@ const ( type LoginPolicySearchQuery struct { Key LoginPolicySearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } diff --git a/internal/iam/model/mail_template_view.go b/internal/iam/model/mail_template_view.go index 40e04ce413..b7a2532ab6 100644 --- a/internal/iam/model/mail_template_view.go +++ b/internal/iam/model/mail_template_view.go @@ -1,9 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" "time" - - "github.com/caos/zitadel/internal/model" ) type MailTemplateView struct { @@ -33,7 +32,7 @@ const ( type MailTemplateSearchQuery struct { Key MailTemplateSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } diff --git a/internal/iam/model/mail_text_view.go b/internal/iam/model/mail_text_view.go index 425c58eca6..ccc27e7522 100644 --- a/internal/iam/model/mail_text_view.go +++ b/internal/iam/model/mail_text_view.go @@ -1,9 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" "time" - - "github.com/caos/zitadel/internal/model" ) type MailTextsView struct { @@ -46,7 +45,7 @@ const ( type MailTextSearchQuery struct { Key MailTextSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } diff --git a/internal/iam/model/mfa_view.go b/internal/iam/model/mfa_view.go index 39df31e308..ca8e453449 100644 --- a/internal/iam/model/mfa_view.go +++ b/internal/iam/model/mfa_view.go @@ -1,7 +1,7 @@ package model import ( - "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" ) type SecondFactorsSearchRequest struct { @@ -17,7 +17,7 @@ type MultiFactorsSearchRequest struct { type MFASearchQuery struct { Key MFASearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } @@ -39,9 +39,9 @@ type MultiFactorsSearchResponse struct { } func (r *SecondFactorsSearchRequest) AppendAggregateIDQuery(aggregateID string) { - r.Queries = append(r.Queries, &MFASearchQuery{Key: MFASearchKeyAggregateID, Method: model.SearchMethodEquals, Value: aggregateID}) + r.Queries = append(r.Queries, &MFASearchQuery{Key: MFASearchKeyAggregateID, Method: domain.SearchMethodEquals, Value: aggregateID}) } func (r *MultiFactorsSearchRequest) AppendAggregateIDQuery(aggregateID string) { - r.Queries = append(r.Queries, &MFASearchQuery{Key: MFASearchKeyAggregateID, Method: model.SearchMethodEquals, Value: aggregateID}) + r.Queries = append(r.Queries, &MFASearchQuery{Key: MFASearchKeyAggregateID, Method: domain.SearchMethodEquals, Value: aggregateID}) } diff --git a/internal/iam/model/org_iam_policy_view.go b/internal/iam/model/org_iam_policy_view.go index e311aaecec..e944bc4ced 100644 --- a/internal/iam/model/org_iam_policy_view.go +++ b/internal/iam/model/org_iam_policy_view.go @@ -1,7 +1,7 @@ package model import ( - "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" "time" ) @@ -33,7 +33,7 @@ const ( type OrgIAMPolicySearchQuery struct { Key OrgIAMPolicySearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } diff --git a/internal/iam/model/password_age_policy_view.go b/internal/iam/model/password_age_policy_view.go index 5e94dd07df..cbb674813f 100644 --- a/internal/iam/model/password_age_policy_view.go +++ b/internal/iam/model/password_age_policy_view.go @@ -1,7 +1,7 @@ package model import ( - "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" "time" ) @@ -33,7 +33,7 @@ const ( type PasswordAgePolicySearchQuery struct { Key PasswordAgePolicySearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } diff --git a/internal/iam/model/password_complexity_policy_view.go b/internal/iam/model/password_complexity_policy_view.go index e206d2238b..1e720fbe3c 100644 --- a/internal/iam/model/password_complexity_policy_view.go +++ b/internal/iam/model/password_complexity_policy_view.go @@ -1,8 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" - "github.com/caos/zitadel/internal/model" "time" ) @@ -37,7 +37,7 @@ const ( type PasswordComplexityPolicySearchQuery struct { Key PasswordComplexityPolicySearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } diff --git a/internal/iam/model/password_lockout_policy_view.go b/internal/iam/model/password_lockout_policy_view.go index cf32e9a6e3..7414d75cfe 100644 --- a/internal/iam/model/password_lockout_policy_view.go +++ b/internal/iam/model/password_lockout_policy_view.go @@ -1,7 +1,7 @@ package model import ( - "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" "time" ) @@ -33,7 +33,7 @@ const ( type PasswordLockoutPolicySearchQuery struct { Key PasswordLockoutPolicySearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } diff --git a/internal/iam/repository/view/iam_member_view.go b/internal/iam/repository/view/iam_member_view.go index 711683b6cd..49932403f2 100644 --- a/internal/iam/repository/view/iam_member_view.go +++ b/internal/iam/repository/view/iam_member_view.go @@ -1,10 +1,10 @@ package view import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" iam_model "github.com/caos/zitadel/internal/iam/model" "github.com/caos/zitadel/internal/iam/repository/view/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" "github.com/jinzhu/gorm" ) @@ -12,8 +12,8 @@ import ( func IAMMemberByIDs(db *gorm.DB, table, orgID, userID string) (*model.IAMMemberView, error) { member := new(model.IAMMemberView) - iamIDQuery := &model.IAMMemberSearchQuery{Key: iam_model.IAMMemberSearchKeyIamID, Value: orgID, Method: global_model.SearchMethodEquals} - userIDQuery := &model.IAMMemberSearchQuery{Key: iam_model.IAMMemberSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals} + iamIDQuery := &model.IAMMemberSearchQuery{Key: iam_model.IAMMemberSearchKeyIamID, Value: orgID, Method: domain.SearchMethodEquals} + userIDQuery := &model.IAMMemberSearchQuery{Key: iam_model.IAMMemberSearchKeyUserID, Value: userID, Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, iamIDQuery, userIDQuery) err := query(db, member) if caos_errs.IsNotFound(err) { @@ -37,7 +37,7 @@ func IAMMembersByUserID(db *gorm.DB, table string, userID string) ([]*model.IAMM { Key: iam_model.IAMMemberSearchKeyUserID, Value: userID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, }, } query := repository.PrepareSearchQuery(table, model.IAMMemberSearchRequest{Queries: queries}) diff --git a/internal/iam/repository/view/idp_provider_view.go b/internal/iam/repository/view/idp_provider_view.go index 625280205f..a11d12fc00 100644 --- a/internal/iam/repository/view/idp_provider_view.go +++ b/internal/iam/repository/view/idp_provider_view.go @@ -1,18 +1,18 @@ package view import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" iam_model "github.com/caos/zitadel/internal/iam/model" "github.com/caos/zitadel/internal/iam/repository/view/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" "github.com/jinzhu/gorm" ) func GetIDPProviderByAggregateIDAndConfigID(db *gorm.DB, table, aggregateID, idpConfigID string) (*model.IDPProviderView, error) { policy := new(model.IDPProviderView) - aggIDQuery := &model.IDPProviderSearchQuery{Key: iam_model.IDPProviderSearchKeyAggregateID, Value: aggregateID, Method: global_model.SearchMethodEquals} - idpConfigIDQuery := &model.IDPProviderSearchQuery{Key: iam_model.IDPProviderSearchKeyIdpConfigID, Value: idpConfigID, Method: global_model.SearchMethodEquals} + aggIDQuery := &model.IDPProviderSearchQuery{Key: iam_model.IDPProviderSearchKeyAggregateID, Value: aggregateID, Method: domain.SearchMethodEquals} + idpConfigIDQuery := &model.IDPProviderSearchQuery{Key: iam_model.IDPProviderSearchKeyIdpConfigID, Value: idpConfigID, Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, aggIDQuery, idpConfigIDQuery) err := query(db, policy) if caos_errs.IsNotFound(err) { @@ -27,7 +27,7 @@ func IDPProvidersByIdpConfigID(db *gorm.DB, table string, idpConfigID string) ([ { Key: iam_model.IDPProviderSearchKeyIdpConfigID, Value: idpConfigID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, }, } query := repository.PrepareSearchQuery(table, model.IDPProviderSearchRequest{Queries: queries}) @@ -44,12 +44,12 @@ func IDPProvidersByAggregateIDAndState(db *gorm.DB, table string, aggregateID st { Key: iam_model.IDPProviderSearchKeyAggregateID, Value: aggregateID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, }, { Key: iam_model.IDPProviderSearchKeyState, Value: int(idpConfigState), - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, }, } query := repository.PrepareSearchQuery(table, model.IDPProviderSearchRequest{Queries: queries}) diff --git a/internal/iam/repository/view/idp_view.go b/internal/iam/repository/view/idp_view.go index d6505a2180..b4cd914a55 100644 --- a/internal/iam/repository/view/idp_view.go +++ b/internal/iam/repository/view/idp_view.go @@ -1,17 +1,17 @@ package view import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" iam_model "github.com/caos/zitadel/internal/iam/model" "github.com/caos/zitadel/internal/iam/repository/view/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" "github.com/jinzhu/gorm" ) func IDPByID(db *gorm.DB, table, idpID string) (*model.IDPConfigView, error) { idp := new(model.IDPConfigView) - idpIDQuery := &model.IDPConfigSearchQuery{Key: iam_model.IDPConfigSearchKeyIdpConfigID, Value: idpID, Method: global_model.SearchMethodEquals} + idpIDQuery := &model.IDPConfigSearchQuery{Key: iam_model.IDPConfigSearchKeyIdpConfigID, Value: idpID, Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, idpIDQuery) err := query(db, idp) if caos_errs.IsNotFound(err) { @@ -26,7 +26,7 @@ func GetIDPConfigsByAggregateID(db *gorm.DB, table string, aggregateID string) ( { Key: iam_model.IDPConfigSearchKeyAggregateID, Value: aggregateID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, }, } query := repository.PrepareSearchQuery(table, model.IDPConfigSearchRequest{Queries: queries}) diff --git a/internal/iam/repository/view/label_policy_view.go b/internal/iam/repository/view/label_policy_view.go index b294f44d42..d35150f199 100644 --- a/internal/iam/repository/view/label_policy_view.go +++ b/internal/iam/repository/view/label_policy_view.go @@ -1,17 +1,17 @@ package view import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" iam_model "github.com/caos/zitadel/internal/iam/model" "github.com/caos/zitadel/internal/iam/repository/view/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" "github.com/jinzhu/gorm" ) func GetLabelPolicyByAggregateID(db *gorm.DB, table, aggregateID string) (*model.LabelPolicyView, error) { policy := new(model.LabelPolicyView) - aggregateIDQuery := &model.LabelPolicySearchQuery{Key: iam_model.LabelPolicySearchKeyAggregateID, Value: aggregateID, Method: global_model.SearchMethodEquals} + aggregateIDQuery := &model.LabelPolicySearchQuery{Key: iam_model.LabelPolicySearchKeyAggregateID, Value: aggregateID, Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, aggregateIDQuery) err := query(db, policy) if caos_errs.IsNotFound(err) { diff --git a/internal/iam/repository/view/login_policy_view.go b/internal/iam/repository/view/login_policy_view.go index 0563f196a8..b1535a6567 100644 --- a/internal/iam/repository/view/login_policy_view.go +++ b/internal/iam/repository/view/login_policy_view.go @@ -1,10 +1,10 @@ package view import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" iam_model "github.com/caos/zitadel/internal/iam/model" "github.com/caos/zitadel/internal/iam/repository/view/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" "github.com/jinzhu/gorm" ) @@ -12,7 +12,7 @@ import ( func GetDefaultLoginPolicies(db *gorm.DB, table string) ([]*model.LoginPolicyView, error) { loginPolicies := make([]*model.LoginPolicyView, 0) queries := []*iam_model.LoginPolicySearchQuery{ - {Key: iam_model.LoginPolicySearchKeyDefault, Value: true, Method: global_model.SearchMethodEquals}, + {Key: iam_model.LoginPolicySearchKeyDefault, Value: true, Method: domain.SearchMethodEquals}, } query := repository.PrepareSearchQuery(table, model.LoginPolicySearchRequest{Queries: queries}) _, err := query(db, &loginPolicies) @@ -24,7 +24,7 @@ func GetDefaultLoginPolicies(db *gorm.DB, table string) ([]*model.LoginPolicyVie func GetLoginPolicyByAggregateID(db *gorm.DB, table, aggregateID string) (*model.LoginPolicyView, error) { policy := new(model.LoginPolicyView) - aggregateIDQuery := &model.LoginPolicySearchQuery{Key: iam_model.LoginPolicySearchKeyAggregateID, Value: aggregateID, Method: global_model.SearchMethodEquals} + aggregateIDQuery := &model.LoginPolicySearchQuery{Key: iam_model.LoginPolicySearchKeyAggregateID, Value: aggregateID, Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, aggregateIDQuery) err := query(db, policy) if caos_errs.IsNotFound(err) { diff --git a/internal/iam/repository/view/mail_template_view.go b/internal/iam/repository/view/mail_template_view.go index dab453cb3b..bf4f3a60e1 100644 --- a/internal/iam/repository/view/mail_template_view.go +++ b/internal/iam/repository/view/mail_template_view.go @@ -1,17 +1,17 @@ package view import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" iam_model "github.com/caos/zitadel/internal/iam/model" "github.com/caos/zitadel/internal/iam/repository/view/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" "github.com/jinzhu/gorm" ) func GetMailTemplateByAggregateID(db *gorm.DB, table, aggregateID string) (*model.MailTemplateView, error) { template := new(model.MailTemplateView) - aggregateIDQuery := &model.MailTemplateSearchQuery{Key: iam_model.MailTemplateSearchKeyAggregateID, Value: aggregateID, Method: global_model.SearchMethodEquals} + aggregateIDQuery := &model.MailTemplateSearchQuery{Key: iam_model.MailTemplateSearchKeyAggregateID, Value: aggregateID, Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, aggregateIDQuery) err := query(db, template) if caos_errs.IsNotFound(err) { diff --git a/internal/iam/repository/view/mail_text_view.go b/internal/iam/repository/view/mail_text_view.go index 31f440293a..ceb7ece1b6 100644 --- a/internal/iam/repository/view/mail_text_view.go +++ b/internal/iam/repository/view/mail_text_view.go @@ -1,10 +1,10 @@ package view import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" iam_model "github.com/caos/zitadel/internal/iam/model" "github.com/caos/zitadel/internal/iam/repository/view/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" "github.com/jinzhu/gorm" "strings" @@ -16,7 +16,7 @@ func GetMailTexts(db *gorm.DB, table string, aggregateID string) ([]*model.MailT { Key: iam_model.MailTextSearchKeyAggregateID, Value: aggregateID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, }, } query := repository.PrepareSearchQuery(table, model.MailTextSearchRequest{Queries: queries}) @@ -29,9 +29,9 @@ func GetMailTexts(db *gorm.DB, table string, aggregateID string) ([]*model.MailT func GetMailTextByIDs(db *gorm.DB, table, aggregateID string, textType string, language string) (*model.MailTextView, error) { mailText := new(model.MailTextView) - aggregateIDQuery := &model.MailTextSearchQuery{Key: iam_model.MailTextSearchKeyAggregateID, Value: aggregateID, Method: global_model.SearchMethodEquals} - textTypeQuery := &model.MailTextSearchQuery{Key: iam_model.MailTextSearchKeyMailTextType, Value: textType, Method: global_model.SearchMethodEquals} - languageQuery := &model.MailTextSearchQuery{Key: iam_model.MailTextSearchKeyLanguage, Value: strings.ToUpper(language), Method: global_model.SearchMethodEquals} + aggregateIDQuery := &model.MailTextSearchQuery{Key: iam_model.MailTextSearchKeyAggregateID, Value: aggregateID, Method: domain.SearchMethodEquals} + textTypeQuery := &model.MailTextSearchQuery{Key: iam_model.MailTextSearchKeyMailTextType, Value: textType, Method: domain.SearchMethodEquals} + languageQuery := &model.MailTextSearchQuery{Key: iam_model.MailTextSearchKeyLanguage, Value: strings.ToUpper(language), Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, aggregateIDQuery, textTypeQuery, languageQuery) err := query(db, mailText) if caos_errs.IsNotFound(err) { diff --git a/internal/iam/repository/view/model/iam_member_query.go b/internal/iam/repository/view/model/iam_member_query.go index 8a512f64de..369a2aa9a2 100644 --- a/internal/iam/repository/view/model/iam_member_query.go +++ b/internal/iam/repository/view/model/iam_member_query.go @@ -1,8 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" iam_model "github.com/caos/zitadel/internal/iam/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req IAMMemberSearchQuery) GetKey() repository.ColumnKey { return IAMMemberSearchKey(req.Key) } -func (req IAMMemberSearchQuery) GetMethod() global_model.SearchMethod { +func (req IAMMemberSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/iam/repository/view/model/idp_config_query.go b/internal/iam/repository/view/model/idp_config_query.go index 03c41b5552..e00680aef8 100644 --- a/internal/iam/repository/view/model/idp_config_query.go +++ b/internal/iam/repository/view/model/idp_config_query.go @@ -1,8 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" iam_model "github.com/caos/zitadel/internal/iam/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req IDPConfigSearchQuery) GetKey() repository.ColumnKey { return IDPConfigSearchKey(req.Key) } -func (req IDPConfigSearchQuery) GetMethod() global_model.SearchMethod { +func (req IDPConfigSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/iam/repository/view/model/idp_provider_query.go b/internal/iam/repository/view/model/idp_provider_query.go index 7661d9419c..9ff537dc44 100644 --- a/internal/iam/repository/view/model/idp_provider_query.go +++ b/internal/iam/repository/view/model/idp_provider_query.go @@ -1,8 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" iam_model "github.com/caos/zitadel/internal/iam/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req IDPProviderSearchQuery) GetKey() repository.ColumnKey { return IDPProviderSearchKey(req.Key) } -func (req IDPProviderSearchQuery) GetMethod() global_model.SearchMethod { +func (req IDPProviderSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/iam/repository/view/model/label_policy_query.go b/internal/iam/repository/view/model/label_policy_query.go index d12dcd2f78..e0940457fa 100644 --- a/internal/iam/repository/view/model/label_policy_query.go +++ b/internal/iam/repository/view/model/label_policy_query.go @@ -1,8 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" iam_model "github.com/caos/zitadel/internal/iam/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req LabelPolicySearchQuery) GetKey() repository.ColumnKey { return LabelPolicySearchKey(req.Key) } -func (req LabelPolicySearchQuery) GetMethod() global_model.SearchMethod { +func (req LabelPolicySearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/iam/repository/view/model/login_policy_query.go b/internal/iam/repository/view/model/login_policy_query.go index 5a4c8fff88..662284fa51 100644 --- a/internal/iam/repository/view/model/login_policy_query.go +++ b/internal/iam/repository/view/model/login_policy_query.go @@ -1,8 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" iam_model "github.com/caos/zitadel/internal/iam/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req LoginPolicySearchQuery) GetKey() repository.ColumnKey { return LoginPolicySearchKey(req.Key) } -func (req LoginPolicySearchQuery) GetMethod() global_model.SearchMethod { +func (req LoginPolicySearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/iam/repository/view/model/mail_template_query.go b/internal/iam/repository/view/model/mail_template_query.go index 60eb11049e..79b0838c85 100644 --- a/internal/iam/repository/view/model/mail_template_query.go +++ b/internal/iam/repository/view/model/mail_template_query.go @@ -1,8 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" iam_model "github.com/caos/zitadel/internal/iam/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req MailTemplateSearchQuery) GetKey() repository.ColumnKey { return MailTemplateSearchKey(req.Key) } -func (req MailTemplateSearchQuery) GetMethod() global_model.SearchMethod { +func (req MailTemplateSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/iam/repository/view/model/mail_text_query.go b/internal/iam/repository/view/model/mail_text_query.go index ed1d1a24aa..6f3da80765 100644 --- a/internal/iam/repository/view/model/mail_text_query.go +++ b/internal/iam/repository/view/model/mail_text_query.go @@ -1,8 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" iam_model "github.com/caos/zitadel/internal/iam/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req MailTextSearchQuery) GetKey() repository.ColumnKey { return MailTextSearchKey(req.Key) } -func (req MailTextSearchQuery) GetMethod() global_model.SearchMethod { +func (req MailTextSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/iam/repository/view/model/org_iam_policy_query.go b/internal/iam/repository/view/model/org_iam_policy_query.go index da2f508dbb..48fc0a3c4c 100644 --- a/internal/iam/repository/view/model/org_iam_policy_query.go +++ b/internal/iam/repository/view/model/org_iam_policy_query.go @@ -1,8 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" iam_model "github.com/caos/zitadel/internal/iam/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req OrgIAMPolicySearchQuery) GetKey() repository.ColumnKey { return OrgIAMPolicySearchKey(req.Key) } -func (req OrgIAMPolicySearchQuery) GetMethod() global_model.SearchMethod { +func (req OrgIAMPolicySearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/iam/repository/view/model/password_age_policy_query.go b/internal/iam/repository/view/model/password_age_policy_query.go index 41b160bab3..3bf51e273b 100644 --- a/internal/iam/repository/view/model/password_age_policy_query.go +++ b/internal/iam/repository/view/model/password_age_policy_query.go @@ -1,8 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" iam_model "github.com/caos/zitadel/internal/iam/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req PasswordAgePolicySearchQuery) GetKey() repository.ColumnKey { return PasswordAgePolicySearchKey(req.Key) } -func (req PasswordAgePolicySearchQuery) GetMethod() global_model.SearchMethod { +func (req PasswordAgePolicySearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/iam/repository/view/model/password_complexity_policy_query.go b/internal/iam/repository/view/model/password_complexity_policy_query.go index 74b50977d2..a775270c86 100644 --- a/internal/iam/repository/view/model/password_complexity_policy_query.go +++ b/internal/iam/repository/view/model/password_complexity_policy_query.go @@ -1,8 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" iam_model "github.com/caos/zitadel/internal/iam/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req PasswordComplexityPolicySearchQuery) GetKey() repository.ColumnKey { return PasswordComplexityPolicySearchKey(req.Key) } -func (req PasswordComplexityPolicySearchQuery) GetMethod() global_model.SearchMethod { +func (req PasswordComplexityPolicySearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/iam/repository/view/model/password_lockout_policy_query.go b/internal/iam/repository/view/model/password_lockout_policy_query.go index c0c769de95..4ec7145642 100644 --- a/internal/iam/repository/view/model/password_lockout_policy_query.go +++ b/internal/iam/repository/view/model/password_lockout_policy_query.go @@ -1,8 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" iam_model "github.com/caos/zitadel/internal/iam/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req PasswordLockoutPolicySearchQuery) GetKey() repository.ColumnKey { return PasswordLockoutPolicySearchKey(req.Key) } -func (req PasswordLockoutPolicySearchQuery) GetMethod() global_model.SearchMethod { +func (req PasswordLockoutPolicySearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/iam/repository/view/org_iam_policy_view.go b/internal/iam/repository/view/org_iam_policy_view.go index 574081bc40..64135173bb 100644 --- a/internal/iam/repository/view/org_iam_policy_view.go +++ b/internal/iam/repository/view/org_iam_policy_view.go @@ -1,17 +1,17 @@ package view import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" iam_model "github.com/caos/zitadel/internal/iam/model" "github.com/caos/zitadel/internal/iam/repository/view/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" "github.com/jinzhu/gorm" ) func GetOrgIAMPolicyByAggregateID(db *gorm.DB, table, aggregateID string) (*model.OrgIAMPolicyView, error) { policy := new(model.OrgIAMPolicyView) - aggregateIDQuery := &model.OrgIAMPolicySearchQuery{Key: iam_model.OrgIAMPolicySearchKeyAggregateID, Value: aggregateID, Method: global_model.SearchMethodEquals} + aggregateIDQuery := &model.OrgIAMPolicySearchQuery{Key: iam_model.OrgIAMPolicySearchKeyAggregateID, Value: aggregateID, Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, aggregateIDQuery) err := query(db, policy) if caos_errs.IsNotFound(err) { diff --git a/internal/iam/repository/view/password_age_policy_view.go b/internal/iam/repository/view/password_age_policy_view.go index eb85938edc..227b988fbf 100644 --- a/internal/iam/repository/view/password_age_policy_view.go +++ b/internal/iam/repository/view/password_age_policy_view.go @@ -1,17 +1,17 @@ package view import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" iam_model "github.com/caos/zitadel/internal/iam/model" "github.com/caos/zitadel/internal/iam/repository/view/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" "github.com/jinzhu/gorm" ) func GetPasswordAgePolicyByAggregateID(db *gorm.DB, table, aggregateID string) (*model.PasswordAgePolicyView, error) { policy := new(model.PasswordAgePolicyView) - aggregateIDQuery := &model.PasswordAgePolicySearchQuery{Key: iam_model.PasswordAgePolicySearchKeyAggregateID, Value: aggregateID, Method: global_model.SearchMethodEquals} + aggregateIDQuery := &model.PasswordAgePolicySearchQuery{Key: iam_model.PasswordAgePolicySearchKeyAggregateID, Value: aggregateID, Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, aggregateIDQuery) err := query(db, policy) if caos_errs.IsNotFound(err) { diff --git a/internal/iam/repository/view/password_complexity_policy_view.go b/internal/iam/repository/view/password_complexity_policy_view.go index 75713cead9..fdead126cc 100644 --- a/internal/iam/repository/view/password_complexity_policy_view.go +++ b/internal/iam/repository/view/password_complexity_policy_view.go @@ -1,17 +1,17 @@ package view import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" iam_model "github.com/caos/zitadel/internal/iam/model" "github.com/caos/zitadel/internal/iam/repository/view/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" "github.com/jinzhu/gorm" ) func GetPasswordComplexityPolicyByAggregateID(db *gorm.DB, table, aggregateID string) (*model.PasswordComplexityPolicyView, error) { policy := new(model.PasswordComplexityPolicyView) - aggregateIDQuery := &model.PasswordComplexityPolicySearchQuery{Key: iam_model.PasswordComplexityPolicySearchKeyAggregateID, Value: aggregateID, Method: global_model.SearchMethodEquals} + aggregateIDQuery := &model.PasswordComplexityPolicySearchQuery{Key: iam_model.PasswordComplexityPolicySearchKeyAggregateID, Value: aggregateID, Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, aggregateIDQuery) err := query(db, policy) if caos_errs.IsNotFound(err) { diff --git a/internal/iam/repository/view/password_lockout_policy_view.go b/internal/iam/repository/view/password_lockout_policy_view.go index e5bdc9922e..05a1d025d1 100644 --- a/internal/iam/repository/view/password_lockout_policy_view.go +++ b/internal/iam/repository/view/password_lockout_policy_view.go @@ -1,17 +1,17 @@ package view import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" iam_model "github.com/caos/zitadel/internal/iam/model" "github.com/caos/zitadel/internal/iam/repository/view/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" "github.com/jinzhu/gorm" ) func GetPasswordLockoutPolicyByAggregateID(db *gorm.DB, table, aggregateID string) (*model.PasswordLockoutPolicyView, error) { policy := new(model.PasswordLockoutPolicyView) - aggregateIDQuery := &model.PasswordLockoutPolicySearchQuery{Key: iam_model.PasswordLockoutPolicySearchKeyAggregateID, Value: aggregateID, Method: global_model.SearchMethodEquals} + aggregateIDQuery := &model.PasswordLockoutPolicySearchQuery{Key: iam_model.PasswordLockoutPolicySearchKeyAggregateID, Value: aggregateID, Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, aggregateIDQuery) err := query(db, policy) if caos_errs.IsNotFound(err) { diff --git a/internal/key/model/authn_key.go b/internal/key/model/authn_key.go index d0280e5b3a..1d279fc877 100644 --- a/internal/key/model/authn_key.go +++ b/internal/key/model/authn_key.go @@ -1,10 +1,10 @@ package model import ( + "github.com/caos/zitadel/internal/domain" "time" "github.com/caos/zitadel/internal/eventstore/v1/models" - "github.com/caos/zitadel/internal/model" ) const ( @@ -77,7 +77,7 @@ const ( type AuthNKeySearchQuery struct { Key AuthNKeySearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } diff --git a/internal/key/model/key_view.go b/internal/key/model/key_view.go index a6640354ad..0cc14c5fbd 100644 --- a/internal/key/model/key_view.go +++ b/internal/key/model/key_view.go @@ -1,11 +1,11 @@ package model import ( + "github.com/caos/zitadel/internal/domain" "time" "github.com/caos/zitadel/internal/crypto" "github.com/caos/zitadel/internal/errors" - "github.com/caos/zitadel/internal/model" ) type KeyView struct { @@ -52,7 +52,7 @@ const ( type KeySearchQuery struct { Key KeySearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } diff --git a/internal/key/repository/view/authn_key_view.go b/internal/key/repository/view/authn_key_view.go index 5bd299150e..cb024a9a42 100644 --- a/internal/key/repository/view/authn_key_view.go +++ b/internal/key/repository/view/authn_key_view.go @@ -1,10 +1,10 @@ package view import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" key_model "github.com/caos/zitadel/internal/key/model" "github.com/caos/zitadel/internal/key/repository/view/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" "github.com/jinzhu/gorm" ) @@ -12,8 +12,8 @@ import ( func AuthNKeyByIDs(db *gorm.DB, table, objectID, keyID string) (*model.AuthNKeyView, error) { key := new(model.AuthNKeyView) query := repository.PrepareGetByQuery(table, - model.AuthNKeySearchQuery{Key: key_model.AuthNKeyObjectID, Method: global_model.SearchMethodEquals, Value: objectID}, - model.AuthNKeySearchQuery{Key: key_model.AuthNKeyKeyID, Method: global_model.SearchMethodEquals, Value: keyID}, + model.AuthNKeySearchQuery{Key: key_model.AuthNKeyObjectID, Method: domain.SearchMethodEquals, Value: objectID}, + model.AuthNKeySearchQuery{Key: key_model.AuthNKeyKeyID, Method: domain.SearchMethodEquals, Value: keyID}, ) err := query(db, key) if caos_errs.IsNotFound(err) { @@ -38,7 +38,7 @@ func AuthNKeysByObjectID(db *gorm.DB, table string, objectID string) ([]*model.A { Key: key_model.AuthNKeyObjectID, Value: objectID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, }, } query := repository.PrepareSearchQuery(table, model.AuthNKeySearchRequest{Queries: queries}) @@ -52,7 +52,7 @@ func AuthNKeysByObjectID(db *gorm.DB, table string, objectID string) ([]*model.A func AuthNKeyByID(db *gorm.DB, table string, keyID string) (*model.AuthNKeyView, error) { key := new(model.AuthNKeyView) query := repository.PrepareGetByQuery(table, - model.AuthNKeySearchQuery{Key: key_model.AuthNKeyKeyID, Method: global_model.SearchMethodEquals, Value: keyID}, + model.AuthNKeySearchQuery{Key: key_model.AuthNKeyKeyID, Method: domain.SearchMethodEquals, Value: keyID}, ) err := query(db, key) if caos_errs.IsNotFound(err) { diff --git a/internal/key/repository/view/key.go b/internal/key/repository/view/key.go index dab41b0c86..521a4726ef 100644 --- a/internal/key/repository/view/key.go +++ b/internal/key/repository/view/key.go @@ -1,6 +1,7 @@ package view import ( + "github.com/caos/zitadel/internal/domain" "time" caos_errs "github.com/caos/zitadel/internal/errors" @@ -10,14 +11,13 @@ import ( key_model "github.com/caos/zitadel/internal/key/model" "github.com/caos/zitadel/internal/key/repository/view/model" - global_model "github.com/caos/zitadel/internal/model" ) func KeyByIDAndType(db *gorm.DB, table, keyID string, private bool) (*model.KeyView, error) { key := new(model.KeyView) query := repository.PrepareGetByQuery(table, - model.KeySearchQuery{Key: key_model.KeySearchKeyID, Method: global_model.SearchMethodEquals, Value: keyID}, - model.KeySearchQuery{Key: key_model.KeySearchKeyPrivate, Method: global_model.SearchMethodEquals, Value: private}, + model.KeySearchQuery{Key: key_model.KeySearchKeyID, Method: domain.SearchMethodEquals, Value: keyID}, + model.KeySearchQuery{Key: key_model.KeySearchKeyPrivate, Method: domain.SearchMethodEquals, Value: private}, ) err := query(db, key) return key, err @@ -31,9 +31,9 @@ func GetSigningKey(db *gorm.DB, table string, expiry time.Time) (*model.KeyView, query := repository.PrepareSearchQuery(table, model.KeySearchRequest{ Queries: []*key_model.KeySearchQuery{ - {Key: key_model.KeySearchKeyPrivate, Method: global_model.SearchMethodEquals, Value: true}, - {Key: key_model.KeySearchKeyUsage, Method: global_model.SearchMethodEquals, Value: key_model.KeyUsageSigning}, - {Key: key_model.KeySearchKeyExpiry, Method: global_model.SearchMethodGreaterThan, Value: time.Now().UTC()}, + {Key: key_model.KeySearchKeyPrivate, Method: domain.SearchMethodEquals, Value: true}, + {Key: key_model.KeySearchKeyUsage, Method: domain.SearchMethodEquals, Value: key_model.KeyUsageSigning}, + {Key: key_model.KeySearchKeyExpiry, Method: domain.SearchMethodGreaterThan, Value: time.Now().UTC()}, }, SortingColumn: key_model.KeySearchKeyExpiry, Limit: 1, @@ -54,9 +54,9 @@ func GetActivePublicKeys(db *gorm.DB, table string) ([]*model.KeyView, error) { query := repository.PrepareSearchQuery(table, model.KeySearchRequest{ Queries: []*key_model.KeySearchQuery{ - {Key: key_model.KeySearchKeyPrivate, Method: global_model.SearchMethodEquals, Value: false}, - {Key: key_model.KeySearchKeyUsage, Method: global_model.SearchMethodEquals, Value: key_model.KeyUsageSigning}, - {Key: key_model.KeySearchKeyExpiry, Method: global_model.SearchMethodGreaterThan, Value: time.Now().UTC()}, + {Key: key_model.KeySearchKeyPrivate, Method: domain.SearchMethodEquals, Value: false}, + {Key: key_model.KeySearchKeyUsage, Method: domain.SearchMethodEquals, Value: key_model.KeyUsageSigning}, + {Key: key_model.KeySearchKeyExpiry, Method: domain.SearchMethodGreaterThan, Value: time.Now().UTC()}, }, }, ) diff --git a/internal/key/repository/view/model/authn_key_query.go b/internal/key/repository/view/model/authn_key_query.go index e26c58977e..7189ee34ad 100644 --- a/internal/key/repository/view/model/authn_key_query.go +++ b/internal/key/repository/view/model/authn_key_query.go @@ -1,8 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" key_model "github.com/caos/zitadel/internal/key/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req AuthNKeySearchQuery) GetKey() repository.ColumnKey { return AuthNKeySearchKey(req.Key) } -func (req AuthNKeySearchQuery) GetMethod() global_model.SearchMethod { +func (req AuthNKeySearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/key/repository/view/model/key_query.go b/internal/key/repository/view/model/key_query.go index 85ffd3508c..4c51f01c71 100644 --- a/internal/key/repository/view/model/key_query.go +++ b/internal/key/repository/view/model/key_query.go @@ -1,8 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" key_model "github.com/caos/zitadel/internal/key/model" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req KeySearchQuery) GetKey() repository.ColumnKey { return KeySearchKey(req.Key) } -func (req KeySearchQuery) GetMethod() global_model.SearchMethod { +func (req KeySearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/management/repository/eventsourcing/eventstore/org.go b/internal/management/repository/eventsourcing/eventstore/org.go index e547b07cd1..757f4ef698 100644 --- a/internal/management/repository/eventsourcing/eventstore/org.go +++ b/internal/management/repository/eventsourcing/eventstore/org.go @@ -21,7 +21,6 @@ import ( iam_es_model "github.com/caos/zitadel/internal/iam/repository/view/model" iam_view_model "github.com/caos/zitadel/internal/iam/repository/view/model" mgmt_view "github.com/caos/zitadel/internal/management/repository/eventsourcing/view" - global_model "github.com/caos/zitadel/internal/model" org_model "github.com/caos/zitadel/internal/org/model" org_es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/model" "github.com/caos/zitadel/internal/org/repository/view/model" @@ -74,7 +73,7 @@ func (repo *OrgRepository) GetMyOrgIamPolicy(ctx context.Context) (*iam_model.Or func (repo *OrgRepository) SearchMyOrgDomains(ctx context.Context, request *org_model.OrgDomainSearchRequest) (*org_model.OrgDomainSearchResponse, error) { request.EnsureLimit(repo.SearchLimit) - request.Queries = append(request.Queries, &org_model.OrgDomainSearchQuery{Key: org_model.OrgDomainSearchKeyOrgID, Method: global_model.SearchMethodEquals, Value: authz.GetCtxData(ctx).OrgID}) + request.Queries = append(request.Queries, &org_model.OrgDomainSearchQuery{Key: org_model.OrgDomainSearchKeyOrgID, Method: domain.SearchMethodEquals, Value: authz.GetCtxData(ctx).OrgID}) sequence, sequenceErr := repo.View.GetLatestOrgDomainSequence() logging.Log("EVENT-SLowp").OnError(sequenceErr).WithField("traceID", tracing.TraceIDFromCtx(ctx)).Warn("could not read latest org domain sequence") domains, count, err := repo.View.SearchOrgDomains(request) @@ -124,7 +123,7 @@ func (repo *OrgRepository) OrgMemberByID(ctx context.Context, orgID, userID stri func (repo *OrgRepository) SearchMyOrgMembers(ctx context.Context, request *org_model.OrgMemberSearchRequest) (*org_model.OrgMemberSearchResponse, error) { request.EnsureLimit(repo.SearchLimit) - request.Queries[len(request.Queries)-1] = &org_model.OrgMemberSearchQuery{Key: org_model.OrgMemberSearchKeyOrgID, Method: global_model.SearchMethodEquals, Value: authz.GetCtxData(ctx).OrgID} + request.Queries[len(request.Queries)-1] = &org_model.OrgMemberSearchQuery{Key: org_model.OrgMemberSearchKeyOrgID, Method: domain.SearchMethodEquals, Value: authz.GetCtxData(ctx).OrgID} sequence, sequenceErr := repo.View.GetLatestOrgMemberSequence() logging.Log("EVENT-Smu3d").OnError(sequenceErr).Warn("could not read latest org member sequence") members, count, err := repo.View.SearchOrgMembers(request) diff --git a/internal/management/repository/eventsourcing/eventstore/project.go b/internal/management/repository/eventsourcing/eventstore/project.go index 5661bb6a1f..1369fdc10f 100644 --- a/internal/management/repository/eventsourcing/eventstore/project.go +++ b/internal/management/repository/eventsourcing/eventstore/project.go @@ -21,7 +21,6 @@ import ( key_model "github.com/caos/zitadel/internal/key/model" key_view_model "github.com/caos/zitadel/internal/key/repository/view/model" "github.com/caos/zitadel/internal/management/repository/eventsourcing/view" - global_model "github.com/caos/zitadel/internal/model" proj_model "github.com/caos/zitadel/internal/project/model" proj_view "github.com/caos/zitadel/internal/project/repository/view" "github.com/caos/zitadel/internal/project/repository/view/model" @@ -100,7 +99,7 @@ func (repo *ProjectRepo) SearchProjects(ctx context.Context, request *proj_model return result, nil } } else { - request.Queries = append(request.Queries, &proj_model.ProjectViewSearchQuery{Key: proj_model.ProjectViewSearchKeyProjectID, Method: global_model.SearchMethodIsOneOf, Value: ids}) + request.Queries = append(request.Queries, &proj_model.ProjectViewSearchQuery{Key: proj_model.ProjectViewSearchKeyProjectID, Method: domain.SearchMethodIsOneOf, Value: ids}) } } @@ -392,7 +391,7 @@ func (repo *ProjectRepo) SearchGrantedProjects(ctx context.Context, request *pro return result, nil } } else { - request.Queries = append(request.Queries, &proj_model.ProjectGrantViewSearchQuery{Key: proj_model.GrantedProjectSearchKeyGrantID, Method: global_model.SearchMethodIsOneOf, Value: ids}) + request.Queries = append(request.Queries, &proj_model.ProjectGrantViewSearchQuery{Key: proj_model.GrantedProjectSearchKeyGrantID, Method: domain.SearchMethodIsOneOf, Value: ids}) } } diff --git a/internal/management/repository/eventsourcing/eventstore/user.go b/internal/management/repository/eventsourcing/eventstore/user.go index 4be60f4731..6194d0ed02 100644 --- a/internal/management/repository/eventsourcing/eventstore/user.go +++ b/internal/management/repository/eventsourcing/eventstore/user.go @@ -2,6 +2,7 @@ package eventstore import ( "context" + "github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/eventstore/v1" "github.com/caos/zitadel/internal/eventstore/v1/models" usr_view "github.com/caos/zitadel/internal/user/repository/view" @@ -16,7 +17,6 @@ import ( key_model "github.com/caos/zitadel/internal/key/model" key_view_model "github.com/caos/zitadel/internal/key/repository/view/model" "github.com/caos/zitadel/internal/management/repository/eventsourcing/view" - global_model "github.com/caos/zitadel/internal/model" usr_model "github.com/caos/zitadel/internal/user/model" "github.com/caos/zitadel/internal/user/repository/view/model" "github.com/caos/zitadel/internal/view/repository" @@ -342,10 +342,10 @@ func handleSearchUserMembershipsPermissions(ctx context.Context, request *usr_mo return nil } if !iamPerm { - request.Queries = append(request.Queries, &usr_model.UserMembershipSearchQuery{Key: usr_model.UserMembershipSearchKeyMemberType, Method: global_model.SearchMethodNotEquals, Value: usr_model.MemberTypeIam}) + request.Queries = append(request.Queries, &usr_model.UserMembershipSearchQuery{Key: usr_model.UserMembershipSearchKeyMemberType, Method: domain.SearchMethodNotEquals, Value: usr_model.MemberTypeIam}) } if !orgPerm { - request.Queries = append(request.Queries, &usr_model.UserMembershipSearchQuery{Key: usr_model.UserMembershipSearchKeyMemberType, Method: global_model.SearchMethodNotEquals, Value: usr_model.MemberTypeOrganisation}) + request.Queries = append(request.Queries, &usr_model.UserMembershipSearchQuery{Key: usr_model.UserMembershipSearchKeyMemberType, Method: domain.SearchMethodNotEquals, Value: usr_model.MemberTypeOrganisation}) } ids := authz.GetExplicitPermissionCtxIDs(permissions, projectMemberReadPerm) @@ -372,6 +372,6 @@ func handleSearchUserMembershipsPermissions(ctx context.Context, request *usr_mo return result } } - request.Queries = append(request.Queries, &usr_model.UserMembershipSearchQuery{Key: usr_model.UserMembershipSearchKeyObjectID, Method: global_model.SearchMethodIsOneOf, Value: ids}) + request.Queries = append(request.Queries, &usr_model.UserMembershipSearchQuery{Key: usr_model.UserMembershipSearchKeyObjectID, Method: domain.SearchMethodIsOneOf, Value: ids}) return nil } diff --git a/internal/management/repository/eventsourcing/eventstore/user_grant.go b/internal/management/repository/eventsourcing/eventstore/user_grant.go index 23059845bb..6c2ab8fcf0 100644 --- a/internal/management/repository/eventsourcing/eventstore/user_grant.go +++ b/internal/management/repository/eventsourcing/eventstore/user_grant.go @@ -2,11 +2,11 @@ package eventstore import ( "context" + "github.com/caos/zitadel/internal/domain" "github.com/caos/logging" "github.com/caos/zitadel/internal/api/authz" "github.com/caos/zitadel/internal/management/repository/eventsourcing/view" - global_model "github.com/caos/zitadel/internal/model" grant_model "github.com/caos/zitadel/internal/usergrant/model" "github.com/caos/zitadel/internal/usergrant/repository/view/model" "github.com/caos/zitadel/internal/view/repository" @@ -105,7 +105,7 @@ func handleSearchUserGrantPermissions(ctx context.Context, request *grant_model. return result } } - request.Queries = append(request.Queries, &grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyProjectID, Method: global_model.SearchMethodIsOneOf, Value: ids}) + request.Queries = append(request.Queries, &grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyProjectID, Method: domain.SearchMethodIsOneOf, Value: ids}) return nil } diff --git a/internal/model/enum.go b/internal/model/enum.go deleted file mode 100644 index 84c5e2cf03..0000000000 --- a/internal/model/enum.go +++ /dev/null @@ -1,6 +0,0 @@ -package model - -//Deprecated: Enum is useless, better use normal enums, because we rarely need string value -type Enum interface { - String() string -} diff --git a/internal/model/mfa.go b/internal/model/mfa.go deleted file mode 100644 index 060251b320..0000000000 --- a/internal/model/mfa.go +++ /dev/null @@ -1,12 +0,0 @@ -package model - -import "github.com/caos/zitadel/internal/crypto" - -type Multifactors struct { - OTP OTP -} - -type OTP struct { - Issuer string - CryptoMFA crypto.EncryptionAlgorithm -} diff --git a/internal/org/model/domain_view.go b/internal/org/model/domain_view.go index 4d33ad2b0e..1cb604e3ed 100644 --- a/internal/org/model/domain_view.go +++ b/internal/org/model/domain_view.go @@ -1,9 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" "time" - - "github.com/caos/zitadel/internal/model" ) type OrgDomainView struct { @@ -36,7 +35,7 @@ const ( type OrgDomainSearchQuery struct { Key OrgDomainSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } diff --git a/internal/org/model/org_member_view.go b/internal/org/model/org_member_view.go index a2ea1b52e6..32aa0b85f6 100644 --- a/internal/org/model/org_member_view.go +++ b/internal/org/model/org_member_view.go @@ -1,9 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" "time" - - "github.com/caos/zitadel/internal/model" ) type OrgMemberView struct { @@ -42,7 +41,7 @@ const ( type OrgMemberSearchQuery struct { Key OrgMemberSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } diff --git a/internal/org/model/org_view.go b/internal/org/model/org_view.go index 216c023347..4ba6b5fb89 100644 --- a/internal/org/model/org_view.go +++ b/internal/org/model/org_view.go @@ -1,10 +1,10 @@ package model import ( + "github.com/caos/zitadel/internal/domain" "time" "github.com/caos/zitadel/internal/eventstore/v1/models" - "github.com/caos/zitadel/internal/model" ) type OrgView struct { @@ -39,7 +39,7 @@ const ( type OrgSearchQuery struct { Key OrgSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } diff --git a/internal/org/repository/view/model/org_domain_query.go b/internal/org/repository/view/model/org_domain_query.go index 3b05e1d826..79ec916608 100644 --- a/internal/org/repository/view/model/org_domain_query.go +++ b/internal/org/repository/view/model/org_domain_query.go @@ -1,7 +1,7 @@ package model import ( - global_model "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" org_model "github.com/caos/zitadel/internal/org/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req OrgDomainSearchQuery) GetKey() repository.ColumnKey { return OrgDomainSearchKey(req.Key) } -func (req OrgDomainSearchQuery) GetMethod() global_model.SearchMethod { +func (req OrgDomainSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/org/repository/view/model/org_member_query.go b/internal/org/repository/view/model/org_member_query.go index a4ac8cf3b1..8ad4a9f5c2 100644 --- a/internal/org/repository/view/model/org_member_query.go +++ b/internal/org/repository/view/model/org_member_query.go @@ -1,7 +1,7 @@ package model import ( - global_model "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" org_model "github.com/caos/zitadel/internal/org/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req OrgMemberSearchQuery) GetKey() repository.ColumnKey { return OrgMemberSearchKey(req.Key) } -func (req OrgMemberSearchQuery) GetMethod() global_model.SearchMethod { +func (req OrgMemberSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/org/repository/view/model/org_query.go b/internal/org/repository/view/model/org_query.go index 341be51623..21194936a4 100644 --- a/internal/org/repository/view/model/org_query.go +++ b/internal/org/repository/view/model/org_query.go @@ -1,7 +1,7 @@ package model import ( - global_model "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" usr_model "github.com/caos/zitadel/internal/org/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req OrgSearchQuery) GetKey() repository.ColumnKey { return OrgSearchKey(req.Key) } -func (req OrgSearchQuery) GetMethod() global_model.SearchMethod { +func (req OrgSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/org/repository/view/org_domain_view.go b/internal/org/repository/view/org_domain_view.go index 55f7724c85..d4ab0972cd 100644 --- a/internal/org/repository/view/org_domain_view.go +++ b/internal/org/repository/view/org_domain_view.go @@ -1,8 +1,8 @@ package view import ( + domain2 "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" - global_model "github.com/caos/zitadel/internal/model" org_model "github.com/caos/zitadel/internal/org/model" "github.com/caos/zitadel/internal/org/repository/view/model" "github.com/caos/zitadel/internal/view/repository" @@ -11,8 +11,8 @@ import ( func OrgDomainByOrgIDAndDomain(db *gorm.DB, table, orgID, domain string) (*model.OrgDomainView, error) { domainView := new(model.OrgDomainView) - orgIDQuery := &model.OrgDomainSearchQuery{Key: org_model.OrgDomainSearchKeyOrgID, Value: orgID, Method: global_model.SearchMethodEquals} - domainQuery := &model.OrgDomainSearchQuery{Key: org_model.OrgDomainSearchKeyDomain, Value: domain, Method: global_model.SearchMethodEquals} + orgIDQuery := &model.OrgDomainSearchQuery{Key: org_model.OrgDomainSearchKeyOrgID, Value: orgID, Method: domain2.SearchMethodEquals} + domainQuery := &model.OrgDomainSearchQuery{Key: org_model.OrgDomainSearchKeyDomain, Value: domain, Method: domain2.SearchMethodEquals} query := repository.PrepareGetByQuery(table, orgIDQuery, domainQuery) err := query(db, domainView) if caos_errs.IsNotFound(err) { @@ -23,8 +23,8 @@ func OrgDomainByOrgIDAndDomain(db *gorm.DB, table, orgID, domain string) (*model func VerifiedOrgDomain(db *gorm.DB, table, domain string) (*model.OrgDomainView, error) { domainView := new(model.OrgDomainView) - domainQuery := &model.OrgDomainSearchQuery{Key: org_model.OrgDomainSearchKeyDomain, Value: domain, Method: global_model.SearchMethodEquals} - verifiedQuery := &model.OrgDomainSearchQuery{Key: org_model.OrgDomainSearchKeyVerified, Value: true, Method: global_model.SearchMethodEquals} + domainQuery := &model.OrgDomainSearchQuery{Key: org_model.OrgDomainSearchKeyDomain, Value: domain, Method: domain2.SearchMethodEquals} + verifiedQuery := &model.OrgDomainSearchQuery{Key: org_model.OrgDomainSearchKeyVerified, Value: true, Method: domain2.SearchMethodEquals} query := repository.PrepareGetByQuery(table, domainQuery, verifiedQuery) err := query(db, domainView) if caos_errs.IsNotFound(err) { @@ -49,7 +49,7 @@ func OrgDomainsByOrgID(db *gorm.DB, table string, orgID string) ([]*model.OrgDom { Key: org_model.OrgDomainSearchKeyOrgID, Value: orgID, - Method: global_model.SearchMethodEquals, + Method: domain2.SearchMethodEquals, }, } query := repository.PrepareSearchQuery(table, model.OrgDomainSearchRequest{Queries: queries}) diff --git a/internal/org/repository/view/org_member_view.go b/internal/org/repository/view/org_member_view.go index c9035d38dc..5d8bf657e5 100644 --- a/internal/org/repository/view/org_member_view.go +++ b/internal/org/repository/view/org_member_view.go @@ -1,8 +1,8 @@ package view import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" - global_model "github.com/caos/zitadel/internal/model" org_model "github.com/caos/zitadel/internal/org/model" "github.com/caos/zitadel/internal/org/repository/view/model" "github.com/caos/zitadel/internal/view/repository" @@ -12,8 +12,8 @@ import ( func OrgMemberByIDs(db *gorm.DB, table, orgID, userID string) (*model.OrgMemberView, error) { member := new(model.OrgMemberView) - orgIDQuery := &model.OrgMemberSearchQuery{Key: org_model.OrgMemberSearchKeyOrgID, Value: orgID, Method: global_model.SearchMethodEquals} - userIDQuery := &model.OrgMemberSearchQuery{Key: org_model.OrgMemberSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals} + orgIDQuery := &model.OrgMemberSearchQuery{Key: org_model.OrgMemberSearchKeyOrgID, Value: orgID, Method: domain.SearchMethodEquals} + userIDQuery := &model.OrgMemberSearchQuery{Key: org_model.OrgMemberSearchKeyUserID, Value: userID, Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, orgIDQuery, userIDQuery) err := query(db, member) if caos_errs.IsNotFound(err) { @@ -37,7 +37,7 @@ func OrgMembersByUserID(db *gorm.DB, table string, userID string) ([]*model.OrgM { Key: org_model.OrgMemberSearchKeyUserID, Value: userID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, }, } query := repository.PrepareSearchQuery(table, model.OrgMemberSearchRequest{Queries: queries}) diff --git a/internal/project/model/application_view.go b/internal/project/model/application_view.go index 97fcb8a751..994cae2fc1 100644 --- a/internal/project/model/application_view.go +++ b/internal/project/model/application_view.go @@ -1,9 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" "time" - - "github.com/caos/zitadel/internal/model" ) type ApplicationView struct { @@ -58,7 +57,7 @@ const ( type ApplicationSearchQuery struct { Key AppSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } diff --git a/internal/project/model/project_grant_member_view.go b/internal/project/model/project_grant_member_view.go index 440fd9b940..4108b76f3c 100644 --- a/internal/project/model/project_grant_member_view.go +++ b/internal/project/model/project_grant_member_view.go @@ -1,9 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" "time" - - "github.com/caos/zitadel/internal/model" ) type ProjectGrantMemberView struct { @@ -44,7 +43,7 @@ const ( type ProjectGrantMemberSearchQuery struct { Key ProjectGrantMemberSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } diff --git a/internal/project/model/project_grant_view.go b/internal/project/model/project_grant_view.go index 8d85e7b177..3fd2f8883b 100644 --- a/internal/project/model/project_grant_view.go +++ b/internal/project/model/project_grant_view.go @@ -1,7 +1,7 @@ package model import ( - "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" "time" ) @@ -43,7 +43,7 @@ const ( type ProjectGrantViewSearchQuery struct { Key ProjectGrantViewSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } @@ -66,15 +66,15 @@ func (r *ProjectGrantViewSearchRequest) GetSearchQuery(key ProjectGrantViewSearc } func (r *ProjectGrantViewSearchRequest) AppendMyOrgQuery(orgID string) { - r.Queries = append(r.Queries, &ProjectGrantViewSearchQuery{Key: GrantedProjectSearchKeyOrgID, Method: model.SearchMethodEquals, Value: orgID}) + r.Queries = append(r.Queries, &ProjectGrantViewSearchQuery{Key: GrantedProjectSearchKeyOrgID, Method: domain.SearchMethodEquals, Value: orgID}) } func (r *ProjectGrantViewSearchRequest) AppendNotMyOrgQuery(orgID string) { - r.Queries = append(r.Queries, &ProjectGrantViewSearchQuery{Key: GrantedProjectSearchKeyOrgID, Method: model.SearchMethodNotEquals, Value: orgID}) + r.Queries = append(r.Queries, &ProjectGrantViewSearchQuery{Key: GrantedProjectSearchKeyOrgID, Method: domain.SearchMethodNotEquals, Value: orgID}) } func (r *ProjectGrantViewSearchRequest) AppendMyResourceOwnerQuery(orgID string) { - r.Queries = append(r.Queries, &ProjectGrantViewSearchQuery{Key: GrantedProjectSearchKeyResourceOwner, Method: model.SearchMethodEquals, Value: orgID}) + r.Queries = append(r.Queries, &ProjectGrantViewSearchQuery{Key: GrantedProjectSearchKeyResourceOwner, Method: domain.SearchMethodEquals, Value: orgID}) } func (r *ProjectGrantViewSearchRequest) EnsureLimit(limit uint64) { diff --git a/internal/project/model/project_member_view.go b/internal/project/model/project_member_view.go index fa828fe3fe..f07fcfe2a5 100644 --- a/internal/project/model/project_member_view.go +++ b/internal/project/model/project_member_view.go @@ -1,9 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" "time" - - "github.com/caos/zitadel/internal/model" ) type ProjectMemberView struct { @@ -42,7 +41,7 @@ const ( type ProjectMemberSearchQuery struct { Key ProjectMemberSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } @@ -61,5 +60,5 @@ func (r *ProjectMemberSearchRequest) EnsureLimit(limit uint64) { } } func (r *ProjectMemberSearchRequest) AppendProjectQuery(projectID string) { - r.Queries = append(r.Queries, &ProjectMemberSearchQuery{Key: ProjectMemberSearchKeyProjectID, Method: model.SearchMethodEquals, Value: projectID}) + r.Queries = append(r.Queries, &ProjectMemberSearchQuery{Key: ProjectMemberSearchKeyProjectID, Method: domain.SearchMethodEquals, Value: projectID}) } diff --git a/internal/project/model/project_role_view.go b/internal/project/model/project_role_view.go index 0f358b36ce..4289405606 100644 --- a/internal/project/model/project_role_view.go +++ b/internal/project/model/project_role_view.go @@ -1,9 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" "time" - - "github.com/caos/zitadel/internal/model" ) type ProjectRoleView struct { @@ -39,7 +38,7 @@ const ( type ProjectRoleSearchQuery struct { Key ProjectRoleSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } @@ -53,10 +52,10 @@ type ProjectRoleSearchResponse struct { } func (r *ProjectRoleSearchRequest) AppendMyOrgQuery(orgID string) { - r.Queries = append(r.Queries, &ProjectRoleSearchQuery{Key: ProjectRoleSearchKeyOrgID, Method: model.SearchMethodEquals, Value: orgID}) + r.Queries = append(r.Queries, &ProjectRoleSearchQuery{Key: ProjectRoleSearchKeyOrgID, Method: domain.SearchMethodEquals, Value: orgID}) } func (r *ProjectRoleSearchRequest) AppendProjectQuery(projectID string) { - r.Queries = append(r.Queries, &ProjectRoleSearchQuery{Key: ProjectRoleSearchKeyProjectID, Method: model.SearchMethodEquals, Value: projectID}) + r.Queries = append(r.Queries, &ProjectRoleSearchQuery{Key: ProjectRoleSearchKeyProjectID, Method: domain.SearchMethodEquals, Value: projectID}) } func (r *ProjectRoleSearchRequest) EnsureLimit(limit uint64) { diff --git a/internal/project/model/project_view.go b/internal/project/model/project_view.go index f6764911ff..d2c707c526 100644 --- a/internal/project/model/project_view.go +++ b/internal/project/model/project_view.go @@ -1,9 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" "time" - - "github.com/caos/zitadel/internal/model" ) type ProjectView struct { @@ -37,7 +36,7 @@ const ( type ProjectViewSearchQuery struct { Key ProjectViewSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } @@ -60,7 +59,7 @@ func (r *ProjectViewSearchRequest) GetSearchQuery(key ProjectViewSearchKey) (int } func (r *ProjectViewSearchRequest) AppendMyResourceOwnerQuery(orgID string) { - r.Queries = append(r.Queries, &ProjectViewSearchQuery{Key: ProjectViewSearchKeyResourceOwner, Method: model.SearchMethodEquals, Value: orgID}) + r.Queries = append(r.Queries, &ProjectViewSearchQuery{Key: ProjectViewSearchKeyResourceOwner, Method: domain.SearchMethodEquals, Value: orgID}) } func (r *ProjectViewSearchRequest) EnsureLimit(limit uint64) { diff --git a/internal/project/repository/view/application_view.go b/internal/project/repository/view/application_view.go index 5dd284d96e..92882a6066 100644 --- a/internal/project/repository/view/application_view.go +++ b/internal/project/repository/view/application_view.go @@ -1,8 +1,8 @@ package view import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" - global_model "github.com/caos/zitadel/internal/model" proj_model "github.com/caos/zitadel/internal/project/model" "github.com/caos/zitadel/internal/project/repository/view/model" "github.com/caos/zitadel/internal/view/repository" @@ -11,8 +11,8 @@ import ( func ApplicationByID(db *gorm.DB, table, projectID, appID string) (*model.ApplicationView, error) { app := new(model.ApplicationView) - projectIDQuery := &model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals} - appIDQuery := &model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyAppID, Value: appID, Method: global_model.SearchMethodEquals} + projectIDQuery := &model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyProjectID, Value: projectID, Method: domain.SearchMethodEquals} + appIDQuery := &model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyAppID, Value: appID, Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, projectIDQuery, appIDQuery) err := query(db, app) if caos_errs.IsNotFound(err) { @@ -24,7 +24,7 @@ func ApplicationByID(db *gorm.DB, table, projectID, appID string) (*model.Applic func ApplicationsByProjectID(db *gorm.DB, table, projectID string) ([]*model.ApplicationView, error) { applications := make([]*model.ApplicationView, 0) queries := []*proj_model.ApplicationSearchQuery{ - {Key: proj_model.AppSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}, + {Key: proj_model.AppSearchKeyProjectID, Value: projectID, Method: domain.SearchMethodEquals}, } query := repository.PrepareSearchQuery(table, model.ApplicationSearchRequest{Queries: queries}) _, err := query(db, &applications) @@ -36,7 +36,7 @@ func ApplicationsByProjectID(db *gorm.DB, table, projectID string) ([]*model.App func ApplicationByOIDCClientID(db *gorm.DB, table, clientID string) (*model.ApplicationView, error) { app := new(model.ApplicationView) - clientIDQuery := model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyOIDCClientID, Value: clientID, Method: global_model.SearchMethodEquals} + clientIDQuery := model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyOIDCClientID, Value: clientID, Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, clientIDQuery) err := query(db, app) if caos_errs.IsNotFound(err) { @@ -47,8 +47,8 @@ func ApplicationByOIDCClientID(db *gorm.DB, table, clientID string) (*model.Appl func ApplicationByProjectIDAndAppName(db *gorm.DB, table, projectID, appName string) (*model.ApplicationView, error) { app := new(model.ApplicationView) - projectIDQuery := model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals} - appNameQuery := model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyName, Value: appName, Method: global_model.SearchMethodEquals} + projectIDQuery := model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyProjectID, Value: projectID, Method: domain.SearchMethodEquals} + appNameQuery := model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyName, Value: appName, Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, projectIDQuery, appNameQuery) err := query(db, app) if caos_errs.IsNotFound(err) { diff --git a/internal/project/repository/view/model/application_query.go b/internal/project/repository/view/model/application_query.go index da3860606f..5ce1600dcf 100644 --- a/internal/project/repository/view/model/application_query.go +++ b/internal/project/repository/view/model/application_query.go @@ -1,7 +1,7 @@ package model import ( - global_model "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" proj_model "github.com/caos/zitadel/internal/project/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req ApplicationSearchQuery) GetKey() repository.ColumnKey { return ApplicationSearchKey(req.Key) } -func (req ApplicationSearchQuery) GetMethod() global_model.SearchMethod { +func (req ApplicationSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/project/repository/view/model/project_grant_member_query.go b/internal/project/repository/view/model/project_grant_member_query.go index 8d41e6d517..3b84a2bca0 100644 --- a/internal/project/repository/view/model/project_grant_member_query.go +++ b/internal/project/repository/view/model/project_grant_member_query.go @@ -1,7 +1,7 @@ package model import ( - global_model "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" proj_model "github.com/caos/zitadel/internal/project/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req ProjectGrantMemberSearchQuery) GetKey() repository.ColumnKey { return ProjectGrantMemberSearchKey(req.Key) } -func (req ProjectGrantMemberSearchQuery) GetMethod() global_model.SearchMethod { +func (req ProjectGrantMemberSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/project/repository/view/model/project_grant_query.go b/internal/project/repository/view/model/project_grant_query.go index 22843eee92..f3ff814852 100644 --- a/internal/project/repository/view/model/project_grant_query.go +++ b/internal/project/repository/view/model/project_grant_query.go @@ -1,7 +1,7 @@ package model import ( - global_model "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" proj_model "github.com/caos/zitadel/internal/project/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req ProjectGrantSearchQuery) GetKey() repository.ColumnKey { return ProjectGrantSearchKey(req.Key) } -func (req ProjectGrantSearchQuery) GetMethod() global_model.SearchMethod { +func (req ProjectGrantSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/project/repository/view/model/project_member_query.go b/internal/project/repository/view/model/project_member_query.go index e73d31687e..c9366936d2 100644 --- a/internal/project/repository/view/model/project_member_query.go +++ b/internal/project/repository/view/model/project_member_query.go @@ -1,7 +1,7 @@ package model import ( - global_model "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" proj_model "github.com/caos/zitadel/internal/project/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req ProjectMemberSearchQuery) GetKey() repository.ColumnKey { return ProjectMemberSearchKey(req.Key) } -func (req ProjectMemberSearchQuery) GetMethod() global_model.SearchMethod { +func (req ProjectMemberSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/project/repository/view/model/project_query.go b/internal/project/repository/view/model/project_query.go index d00fe65272..52b08c5c8c 100644 --- a/internal/project/repository/view/model/project_query.go +++ b/internal/project/repository/view/model/project_query.go @@ -1,7 +1,7 @@ package model import ( - global_model "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" proj_model "github.com/caos/zitadel/internal/project/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req ProjectSearchQuery) GetKey() repository.ColumnKey { return ProjectSearchKey(req.Key) } -func (req ProjectSearchQuery) GetMethod() global_model.SearchMethod { +func (req ProjectSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/project/repository/view/model/project_role_query.go b/internal/project/repository/view/model/project_role_query.go index 7213ac0fa5..6a8d6b7744 100644 --- a/internal/project/repository/view/model/project_role_query.go +++ b/internal/project/repository/view/model/project_role_query.go @@ -1,7 +1,7 @@ package model import ( - global_model "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" proj_model "github.com/caos/zitadel/internal/project/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req ProjectRoleSearchQuery) GetKey() repository.ColumnKey { return ProjectRoleSearchKey(req.Key) } -func (req ProjectRoleSearchQuery) GetMethod() global_model.SearchMethod { +func (req ProjectRoleSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/project/repository/view/project_grant_member_view.go b/internal/project/repository/view/project_grant_member_view.go index adff81d8a9..b98e13bdf9 100644 --- a/internal/project/repository/view/project_grant_member_view.go +++ b/internal/project/repository/view/project_grant_member_view.go @@ -1,8 +1,8 @@ package view import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" - global_model "github.com/caos/zitadel/internal/model" proj_model "github.com/caos/zitadel/internal/project/model" "github.com/caos/zitadel/internal/project/repository/view/model" "github.com/caos/zitadel/internal/view/repository" @@ -12,8 +12,8 @@ import ( func ProjectGrantMemberByIDs(db *gorm.DB, table, grantID, userID string) (*model.ProjectGrantMemberView, error) { grant := new(model.ProjectGrantMemberView) - grantIDQuery := model.ProjectGrantMemberSearchQuery{Key: proj_model.ProjectGrantMemberSearchKeyGrantID, Value: grantID, Method: global_model.SearchMethodEquals} - userIDQuery := model.ProjectGrantMemberSearchQuery{Key: proj_model.ProjectGrantMemberSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals} + grantIDQuery := model.ProjectGrantMemberSearchQuery{Key: proj_model.ProjectGrantMemberSearchKeyGrantID, Value: grantID, Method: domain.SearchMethodEquals} + userIDQuery := model.ProjectGrantMemberSearchQuery{Key: proj_model.ProjectGrantMemberSearchKeyUserID, Value: userID, Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, grantIDQuery, userIDQuery) err := query(db, grant) if caos_errs.IsNotFound(err) { @@ -25,7 +25,7 @@ func ProjectGrantMemberByIDs(db *gorm.DB, table, grantID, userID string) (*model func ProjectGrantMembersByProjectID(db *gorm.DB, table, projectID string) ([]*model.ProjectGrantMemberView, error) { members := make([]*model.ProjectGrantMemberView, 0) queries := []*proj_model.ProjectGrantMemberSearchQuery{ - {Key: proj_model.ProjectGrantMemberSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}, + {Key: proj_model.ProjectGrantMemberSearchKeyProjectID, Value: projectID, Method: domain.SearchMethodEquals}, } query := repository.PrepareSearchQuery(table, model.ProjectGrantMemberSearchRequest{Queries: queries}) _, err := query(db, &members) @@ -48,7 +48,7 @@ func SearchProjectGrantMembers(db *gorm.DB, table string, req *proj_model.Projec func ProjectGrantMembersByUserID(db *gorm.DB, table, userID string) ([]*model.ProjectGrantMemberView, error) { members := make([]*model.ProjectGrantMemberView, 0) queries := []*proj_model.ProjectGrantMemberSearchQuery{ - {Key: proj_model.ProjectGrantMemberSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals}, + {Key: proj_model.ProjectGrantMemberSearchKeyUserID, Value: userID, Method: domain.SearchMethodEquals}, } query := repository.PrepareSearchQuery(table, model.ProjectGrantMemberSearchRequest{Queries: queries}) _, err := query(db, &members) diff --git a/internal/project/repository/view/project_grant_view.go b/internal/project/repository/view/project_grant_view.go index d2f583dff4..48a3e162b2 100644 --- a/internal/project/repository/view/project_grant_view.go +++ b/internal/project/repository/view/project_grant_view.go @@ -1,8 +1,8 @@ package view import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" - global_model "github.com/caos/zitadel/internal/model" proj_model "github.com/caos/zitadel/internal/project/model" "github.com/caos/zitadel/internal/project/repository/view/model" "github.com/caos/zitadel/internal/view/repository" @@ -12,8 +12,8 @@ import ( func ProjectGrantByProjectAndOrg(db *gorm.DB, table, projectID, orgID string) (*model.ProjectGrantView, error) { projectGrant := new(model.ProjectGrantView) - projectIDQuery := model.ProjectGrantSearchQuery{Key: proj_model.GrantedProjectSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals} - orgIDQuery := model.ProjectGrantSearchQuery{Key: proj_model.GrantedProjectSearchKeyOrgID, Value: orgID, Method: global_model.SearchMethodEquals} + projectIDQuery := model.ProjectGrantSearchQuery{Key: proj_model.GrantedProjectSearchKeyProjectID, Value: projectID, Method: domain.SearchMethodEquals} + orgIDQuery := model.ProjectGrantSearchQuery{Key: proj_model.GrantedProjectSearchKeyOrgID, Value: orgID, Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, projectIDQuery, orgIDQuery) err := query(db, projectGrant) if caos_errs.IsNotFound(err) { @@ -24,7 +24,7 @@ func ProjectGrantByProjectAndOrg(db *gorm.DB, table, projectID, orgID string) (* func ProjectGrantByID(db *gorm.DB, table, grantID string) (*model.ProjectGrantView, error) { projectGrant := new(model.ProjectGrantView) - grantIDQuery := model.ProjectGrantSearchQuery{Key: proj_model.GrantedProjectSearchKeyGrantID, Value: grantID, Method: global_model.SearchMethodEquals} + grantIDQuery := model.ProjectGrantSearchQuery{Key: proj_model.GrantedProjectSearchKeyGrantID, Value: grantID, Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, grantIDQuery) err := query(db, projectGrant) if caos_errs.IsNotFound(err) { @@ -36,7 +36,7 @@ func ProjectGrantByID(db *gorm.DB, table, grantID string) (*model.ProjectGrantVi func ProjectGrantsByProjectID(db *gorm.DB, table, projectID string) ([]*model.ProjectGrantView, error) { projectGrants := make([]*model.ProjectGrantView, 0) queries := []*proj_model.ProjectGrantViewSearchQuery{ - {Key: proj_model.GrantedProjectSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}, + {Key: proj_model.GrantedProjectSearchKeyProjectID, Value: projectID, Method: domain.SearchMethodEquals}, } query := repository.PrepareSearchQuery(table, model.ProjectGrantSearchRequest{Queries: queries}) _, err := query(db, &projectGrants) @@ -46,8 +46,8 @@ func ProjectGrantsByProjectID(db *gorm.DB, table, projectID string) ([]*model.Pr func ProjectGrantsByProjectIDAndRoleKey(db *gorm.DB, table, projectID, roleKey string) ([]*model.ProjectGrantView, error) { projectGrants := make([]*model.ProjectGrantView, 0) queries := []*proj_model.ProjectGrantViewSearchQuery{ - {Key: proj_model.GrantedProjectSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}, - {Key: proj_model.GrantedProjectSearchKeyRoleKeys, Value: roleKey, Method: global_model.SearchMethodListContains}, + {Key: proj_model.GrantedProjectSearchKeyProjectID, Value: projectID, Method: domain.SearchMethodEquals}, + {Key: proj_model.GrantedProjectSearchKeyRoleKeys, Value: roleKey, Method: domain.SearchMethodListContains}, } query := repository.PrepareSearchQuery(table, model.ProjectGrantSearchRequest{Queries: queries}) _, err := query(db, &projectGrants) diff --git a/internal/project/repository/view/project_member_view.go b/internal/project/repository/view/project_member_view.go index ccd24f6988..248b1a37ed 100644 --- a/internal/project/repository/view/project_member_view.go +++ b/internal/project/repository/view/project_member_view.go @@ -1,8 +1,8 @@ package view import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" - global_model "github.com/caos/zitadel/internal/model" proj_model "github.com/caos/zitadel/internal/project/model" "github.com/caos/zitadel/internal/project/repository/view/model" "github.com/caos/zitadel/internal/view/repository" @@ -12,8 +12,8 @@ import ( func ProjectMemberByIDs(db *gorm.DB, table, projectID, userID string) (*model.ProjectMemberView, error) { role := new(model.ProjectMemberView) - projectIDQuery := model.ProjectMemberSearchQuery{Key: proj_model.ProjectMemberSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals} - userIDQuery := model.ProjectMemberSearchQuery{Key: proj_model.ProjectMemberSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals} + projectIDQuery := model.ProjectMemberSearchQuery{Key: proj_model.ProjectMemberSearchKeyProjectID, Value: projectID, Method: domain.SearchMethodEquals} + userIDQuery := model.ProjectMemberSearchQuery{Key: proj_model.ProjectMemberSearchKeyUserID, Value: userID, Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, projectIDQuery, userIDQuery) err := query(db, role) if caos_errs.IsNotFound(err) { @@ -25,7 +25,7 @@ func ProjectMemberByIDs(db *gorm.DB, table, projectID, userID string) (*model.Pr func ProjectMembersByProjectID(db *gorm.DB, table, projectID string) ([]*model.ProjectMemberView, error) { members := make([]*model.ProjectMemberView, 0) queries := []*proj_model.ProjectMemberSearchQuery{ - &proj_model.ProjectMemberSearchQuery{Key: proj_model.ProjectMemberSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}, + &proj_model.ProjectMemberSearchQuery{Key: proj_model.ProjectMemberSearchKeyProjectID, Value: projectID, Method: domain.SearchMethodEquals}, } query := repository.PrepareSearchQuery(table, model.ProjectMemberSearchRequest{Queries: queries}) _, err := query(db, &members) @@ -47,7 +47,7 @@ func SearchProjectMembers(db *gorm.DB, table string, req *proj_model.ProjectMemb func ProjectMembersByUserID(db *gorm.DB, table string, userID string) ([]*model.ProjectMemberView, error) { members := make([]*model.ProjectMemberView, 0) queries := []*proj_model.ProjectMemberSearchQuery{ - &proj_model.ProjectMemberSearchQuery{Key: proj_model.ProjectMemberSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals}, + &proj_model.ProjectMemberSearchQuery{Key: proj_model.ProjectMemberSearchKeyUserID, Value: userID, Method: domain.SearchMethodEquals}, } query := repository.PrepareSearchQuery(table, model.ProjectMemberSearchRequest{Queries: queries}) _, err := query(db, &members) diff --git a/internal/project/repository/view/project_role_view.go b/internal/project/repository/view/project_role_view.go index fdd27951d4..42e97bf380 100644 --- a/internal/project/repository/view/project_role_view.go +++ b/internal/project/repository/view/project_role_view.go @@ -1,8 +1,8 @@ package view import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" - global_model "github.com/caos/zitadel/internal/model" proj_model "github.com/caos/zitadel/internal/project/model" "github.com/caos/zitadel/internal/project/repository/view/model" "github.com/caos/zitadel/internal/view/repository" @@ -12,9 +12,9 @@ import ( func ProjectRoleByIDs(db *gorm.DB, table, projectID, orgID, key string) (*model.ProjectRoleView, error) { role := new(model.ProjectRoleView) - projectIDQuery := model.ProjectRoleSearchQuery{Key: proj_model.ProjectRoleSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals} - grantIDQuery := model.ProjectRoleSearchQuery{Key: proj_model.ProjectRoleSearchKeyOrgID, Value: orgID, Method: global_model.SearchMethodEquals} - keyQuery := model.ProjectRoleSearchQuery{Key: proj_model.ProjectRoleSearchKeyKey, Value: key, Method: global_model.SearchMethodEquals} + projectIDQuery := model.ProjectRoleSearchQuery{Key: proj_model.ProjectRoleSearchKeyProjectID, Value: projectID, Method: domain.SearchMethodEquals} + grantIDQuery := model.ProjectRoleSearchQuery{Key: proj_model.ProjectRoleSearchKeyOrgID, Value: orgID, Method: domain.SearchMethodEquals} + keyQuery := model.ProjectRoleSearchQuery{Key: proj_model.ProjectRoleSearchKeyKey, Value: key, Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, projectIDQuery, grantIDQuery, keyQuery) err := query(db, role) if caos_errs.IsNotFound(err) { @@ -26,7 +26,7 @@ func ProjectRoleByIDs(db *gorm.DB, table, projectID, orgID, key string) (*model. func ProjectRolesByProjectID(db *gorm.DB, table, projectID string) ([]*model.ProjectRoleView, error) { roles := make([]*model.ProjectRoleView, 0) queries := []*proj_model.ProjectRoleSearchQuery{ - {Key: proj_model.ProjectRoleSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}, + {Key: proj_model.ProjectRoleSearchKeyProjectID, Value: projectID, Method: domain.SearchMethodEquals}, } query := repository.PrepareSearchQuery(table, model.ProjectRoleSearchRequest{Queries: queries}) _, err := query(db, &roles) @@ -39,9 +39,9 @@ func ProjectRolesByProjectID(db *gorm.DB, table, projectID string) ([]*model.Pro func ResourceOwnerProjectRolesByKey(db *gorm.DB, table, projectID, resourceOwner, key string) ([]*model.ProjectRoleView, error) { roles := make([]*model.ProjectRoleView, 0) queries := []*proj_model.ProjectRoleSearchQuery{ - {Key: proj_model.ProjectRoleSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}, - {Key: proj_model.ProjectRoleSearchKeyResourceOwner, Value: resourceOwner, Method: global_model.SearchMethodEquals}, - {Key: proj_model.ProjectRoleSearchKeyKey, Value: key, Method: global_model.SearchMethodEquals}, + {Key: proj_model.ProjectRoleSearchKeyProjectID, Value: projectID, Method: domain.SearchMethodEquals}, + {Key: proj_model.ProjectRoleSearchKeyResourceOwner, Value: resourceOwner, Method: domain.SearchMethodEquals}, + {Key: proj_model.ProjectRoleSearchKeyKey, Value: key, Method: domain.SearchMethodEquals}, } query := repository.PrepareSearchQuery(table, model.ProjectRoleSearchRequest{Queries: queries}) _, err := query(db, &roles) @@ -54,8 +54,8 @@ func ResourceOwnerProjectRolesByKey(db *gorm.DB, table, projectID, resourceOwner func ResourceOwnerProjectRoles(db *gorm.DB, table, projectID, resourceOwner string) ([]*model.ProjectRoleView, error) { roles := make([]*model.ProjectRoleView, 0) queries := []*proj_model.ProjectRoleSearchQuery{ - {Key: proj_model.ProjectRoleSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}, - {Key: proj_model.ProjectRoleSearchKeyResourceOwner, Value: resourceOwner, Method: global_model.SearchMethodEquals}, + {Key: proj_model.ProjectRoleSearchKeyProjectID, Value: projectID, Method: domain.SearchMethodEquals}, + {Key: proj_model.ProjectRoleSearchKeyResourceOwner, Value: resourceOwner, Method: domain.SearchMethodEquals}, } query := repository.PrepareSearchQuery(table, model.ProjectRoleSearchRequest{Queries: queries}) _, err := query(db, &roles) diff --git a/internal/project/repository/view/project_view.go b/internal/project/repository/view/project_view.go index 32224b1c03..92694410b3 100644 --- a/internal/project/repository/view/project_view.go +++ b/internal/project/repository/view/project_view.go @@ -1,8 +1,8 @@ package view import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" - global_model "github.com/caos/zitadel/internal/model" proj_model "github.com/caos/zitadel/internal/project/model" "github.com/caos/zitadel/internal/project/repository/view/model" "github.com/caos/zitadel/internal/view/repository" @@ -12,7 +12,7 @@ import ( func ProjectByID(db *gorm.DB, table, projectID string) (*model.ProjectView, error) { project := new(model.ProjectView) - projectIDQuery := model.ProjectSearchQuery{Key: proj_model.ProjectViewSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals} + projectIDQuery := model.ProjectSearchQuery{Key: proj_model.ProjectViewSearchKeyProjectID, Value: projectID, Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, projectIDQuery) err := query(db, project) if caos_errs.IsNotFound(err) { @@ -24,7 +24,7 @@ func ProjectByID(db *gorm.DB, table, projectID string) (*model.ProjectView, erro func ProjectsByResourceOwner(db *gorm.DB, table, orgID string) ([]*model.ProjectView, error) { projects := make([]*model.ProjectView, 0) queries := []*proj_model.ProjectViewSearchQuery{ - {Key: proj_model.ProjectViewSearchKeyResourceOwner, Value: orgID, Method: global_model.SearchMethodEquals}, + {Key: proj_model.ProjectViewSearchKeyResourceOwner, Value: orgID, Method: domain.SearchMethodEquals}, } query := repository.PrepareSearchQuery(table, model.ProjectSearchRequest{Queries: queries}) _, err := query(db, &projects) diff --git a/internal/query/converter.go b/internal/query/converter.go index 2e3f9ab14f..512f366cdb 100644 --- a/internal/query/converter.go +++ b/internal/query/converter.go @@ -77,7 +77,6 @@ func readModelToLabelPolicy(readModel *IAMLabelPolicyReadModel) *model.LabelPoli PrimaryColor: readModel.PrimaryColor, SecondaryColor: readModel.SecondaryColor, Default: true, - //TODO: OTPState: int32, } } @@ -88,8 +87,6 @@ func readModelToLoginPolicy(readModel *IAMLoginPolicyReadModel) *model.LoginPoli AllowRegister: readModel.AllowRegister, AllowUsernamePassword: readModel.AllowUserNamePassword, Default: true, - //TODO: IDPProviders: []*model.IDPProvider, - //TODO: OTPState: int32, } } func readModelToOrgIAMPolicy(readModel *IAMOrgIAMPolicyReadModel) *model.OrgIAMPolicy { @@ -97,15 +94,13 @@ func readModelToOrgIAMPolicy(readModel *IAMOrgIAMPolicyReadModel) *model.OrgIAMP ObjectRoot: readModelToObjectRoot(readModel.OrgIAMPolicyReadModel.ReadModel), UserLoginMustBeDomain: readModel.UserLoginMustBeDomain, Default: true, - //TODO: OTPState: int32, } } func readModelToPasswordAgePolicy(readModel *IAMPasswordAgePolicyReadModel) *model.PasswordAgePolicy { return &model.PasswordAgePolicy{ ObjectRoot: readModelToObjectRoot(readModel.PasswordAgePolicyReadModel.ReadModel), - ExpireWarnDays: uint64(readModel.ExpireWarnDays), - MaxAgeDays: uint64(readModel.MaxAgeDays), - //TODO: OTPState: int32, + ExpireWarnDays: readModel.ExpireWarnDays, + MaxAgeDays: readModel.MaxAgeDays, } } func readModelToPasswordComplexityPolicy(readModel *IAMPasswordComplexityPolicyReadModel) *model.PasswordComplexityPolicy { @@ -115,16 +110,14 @@ func readModelToPasswordComplexityPolicy(readModel *IAMPasswordComplexityPolicyR HasNumber: readModel.HasNumber, HasSymbol: readModel.HasSymbol, HasUppercase: readModel.HasUpperCase, - MinLength: uint64(readModel.MinLength), - //TODO: OTPState: int32, + MinLength: readModel.MinLength, } } func readModelToPasswordLockoutPolicy(readModel *IAMPasswordLockoutPolicyReadModel) *model.PasswordLockoutPolicy { return &model.PasswordLockoutPolicy{ ObjectRoot: readModelToObjectRoot(readModel.PasswordLockoutPolicyReadModel.ReadModel), - MaxAttempts: uint64(readModel.MaxAttempts), + MaxAttempts: readModel.MaxAttempts, ShowLockOutFailures: readModel.ShowLockOutFailures, - //TODO: OTPState: int32, } } diff --git a/internal/repository/org/eventstore.go b/internal/repository/org/eventstore.go index 86a345f5bf..2b4067a063 100644 --- a/internal/repository/org/eventstore.go +++ b/internal/repository/org/eventstore.go @@ -9,7 +9,6 @@ func RegisterEventMappers(es *eventstore.Eventstore) { RegisterFilterEventMapper(OrgChangedEventType, OrgChangedEventMapper). RegisterFilterEventMapper(OrgDeactivatedEventType, OrgDeactivatedEventMapper). RegisterFilterEventMapper(OrgReactivatedEventType, OrgReactivatedEventMapper). - //RegisterFilterEventMapper(OrgRemovedEventType, OrgRemovedEventMapper). //TODO: implement RegisterFilterEventMapper(OrgDomainAddedEventType, DomainAddedEventMapper). RegisterFilterEventMapper(OrgDomainVerificationAddedEventType, DomainVerificationAddedEventMapper). RegisterFilterEventMapper(OrgDomainVerificationFailedEventType, DomainVerificationFailedEventMapper). diff --git a/internal/repository/user/human_mfa_passwordless.go b/internal/repository/user/human_mfa_passwordless.go index aeffad1d84..02356efb81 100644 --- a/internal/repository/user/human_mfa_passwordless.go +++ b/internal/repository/user/human_mfa_passwordless.go @@ -196,7 +196,10 @@ type HumanPasswordlessCheckSucceededEvent struct { HumanWebAuthNCheckSucceededEvent } -func NewHumanPasswordlessCheckSucceededEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanPasswordlessCheckSucceededEvent { +func NewHumanPasswordlessCheckSucceededEvent( + ctx context.Context, + aggregate *eventstore.Aggregate, + info *AuthRequestInfo) *HumanPasswordlessCheckSucceededEvent { return &HumanPasswordlessCheckSucceededEvent{ HumanWebAuthNCheckSucceededEvent: *NewHumanWebAuthNCheckSucceededEvent( eventstore.NewBaseEventForPush( @@ -204,6 +207,7 @@ func NewHumanPasswordlessCheckSucceededEvent(ctx context.Context, aggregate *eve aggregate, HumanPasswordlessTokenCheckSucceededType, ), + info, ), } } @@ -221,7 +225,10 @@ type HumanPasswordlessCheckFailedEvent struct { HumanWebAuthNCheckFailedEvent } -func NewHumanPasswordlessCheckFailedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanPasswordlessCheckFailedEvent { +func NewHumanPasswordlessCheckFailedEvent( + ctx context.Context, + aggregate *eventstore.Aggregate, + info *AuthRequestInfo) *HumanPasswordlessCheckFailedEvent { return &HumanPasswordlessCheckFailedEvent{ HumanWebAuthNCheckFailedEvent: *NewHumanWebAuthNCheckFailedEvent( eventstore.NewBaseEventForPush( @@ -229,6 +236,7 @@ func NewHumanPasswordlessCheckFailedEvent(ctx context.Context, aggregate *events aggregate, HumanPasswordlessTokenCheckFailedType, ), + info, ), } } diff --git a/internal/repository/user/human_mfa_u2f.go b/internal/repository/user/human_mfa_u2f.go index 530431fa4b..bca2ec773b 100644 --- a/internal/repository/user/human_mfa_u2f.go +++ b/internal/repository/user/human_mfa_u2f.go @@ -196,7 +196,10 @@ type HumanU2FCheckSucceededEvent struct { HumanWebAuthNCheckSucceededEvent } -func NewHumanU2FCheckSucceededEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanU2FCheckSucceededEvent { +func NewHumanU2FCheckSucceededEvent( + ctx context.Context, + aggregate *eventstore.Aggregate, + info *AuthRequestInfo) *HumanU2FCheckSucceededEvent { return &HumanU2FCheckSucceededEvent{ HumanWebAuthNCheckSucceededEvent: *NewHumanWebAuthNCheckSucceededEvent( eventstore.NewBaseEventForPush( @@ -204,6 +207,7 @@ func NewHumanU2FCheckSucceededEvent(ctx context.Context, aggregate *eventstore.A aggregate, HumanU2FTokenCheckSucceededType, ), + info, ), } } @@ -221,7 +225,10 @@ type HumanU2FCheckFailedEvent struct { HumanWebAuthNCheckFailedEvent } -func NewHumanU2FCheckFailedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanU2FCheckFailedEvent { +func NewHumanU2FCheckFailedEvent( + ctx context.Context, + aggregate *eventstore.Aggregate, + info *AuthRequestInfo) *HumanU2FCheckFailedEvent { return &HumanU2FCheckFailedEvent{ HumanWebAuthNCheckFailedEvent: *NewHumanWebAuthNCheckFailedEvent( eventstore.NewBaseEventForPush( @@ -229,6 +236,7 @@ func NewHumanU2FCheckFailedEvent(ctx context.Context, aggregate *eventstore.Aggr aggregate, HumanU2FTokenCheckFailedType, ), + info, ), } } diff --git a/internal/repository/user/human_mfa_web_auth_n.go b/internal/repository/user/human_mfa_web_auth_n.go index 19a928f81f..0af90d8c08 100644 --- a/internal/repository/user/human_mfa_web_auth_n.go +++ b/internal/repository/user/human_mfa_web_auth_n.go @@ -213,9 +213,7 @@ func HumanWebAuthNBeginLoginEventMapper(event *repository.Event) (eventstore.Eve type HumanWebAuthNCheckSucceededEvent struct { eventstore.BaseEvent `json:"-"` - - //TODO: Handle Auth Req?? - //*AuthRequest + *AuthRequestInfo } func (e *HumanWebAuthNCheckSucceededEvent) Data() interface{} { @@ -226,9 +224,12 @@ func (e *HumanWebAuthNCheckSucceededEvent) UniqueConstraints() []*eventstore.Eve return nil } -func NewHumanWebAuthNCheckSucceededEvent(base *eventstore.BaseEvent) *HumanWebAuthNCheckSucceededEvent { +func NewHumanWebAuthNCheckSucceededEvent( + base *eventstore.BaseEvent, + info *AuthRequestInfo) *HumanWebAuthNCheckSucceededEvent { return &HumanWebAuthNCheckSucceededEvent{ - BaseEvent: *base, + BaseEvent: *base, + AuthRequestInfo: info, } } @@ -245,9 +246,7 @@ func HumanWebAuthNCheckSucceededEventMapper(event *repository.Event) (eventstore type HumanWebAuthNCheckFailedEvent struct { eventstore.BaseEvent `json:"-"` - - //TODO: Handle Auth Req?? - //*AuthRequest + *AuthRequestInfo } func (e *HumanWebAuthNCheckFailedEvent) Data() interface{} { @@ -258,9 +257,12 @@ func (e *HumanWebAuthNCheckFailedEvent) UniqueConstraints() []*eventstore.EventU return nil } -func NewHumanWebAuthNCheckFailedEvent(base *eventstore.BaseEvent) *HumanWebAuthNCheckFailedEvent { +func NewHumanWebAuthNCheckFailedEvent( + base *eventstore.BaseEvent, + info *AuthRequestInfo) *HumanWebAuthNCheckFailedEvent { return &HumanWebAuthNCheckFailedEvent{ - BaseEvent: *base, + BaseEvent: *base, + AuthRequestInfo: info, } } diff --git a/internal/setup/setup.go b/internal/setup/setup.go index 7bebbd14a7..4fd256ccd7 100644 --- a/internal/setup/setup.go +++ b/internal/setup/setup.go @@ -11,11 +11,6 @@ import ( "github.com/caos/zitadel/internal/eventstore/v1/models" ) -const ( - OrgOwnerRole = "ORG_OWNER" - SetupUser = "SETUP" -) - func Execute(ctx context.Context, setUpConfig IAMSetUp, iamID string, commands *command.Commands) error { logging.Log("SETUP-JAK2q").Info("starting setup") diff --git a/internal/user/model/external_idp_view.go b/internal/user/model/external_idp_view.go index 9d66247de5..7f4d9f078a 100644 --- a/internal/user/model/external_idp_view.go +++ b/internal/user/model/external_idp_view.go @@ -1,7 +1,7 @@ package model import ( - "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" "time" ) @@ -37,7 +37,7 @@ const ( type ExternalIDPSearchQuery struct { Key ExternalIDPSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } @@ -57,5 +57,5 @@ func (r *ExternalIDPSearchRequest) EnsureLimit(limit uint64) { } func (r *ExternalIDPSearchRequest) AppendUserQuery(userID string) { - r.Queries = append(r.Queries, &ExternalIDPSearchQuery{Key: ExternalIDPSearchKeyUserID, Method: model.SearchMethodEquals, Value: userID}) + r.Queries = append(r.Queries, &ExternalIDPSearchQuery{Key: ExternalIDPSearchKeyUserID, Method: domain.SearchMethodEquals, Value: userID}) } diff --git a/internal/user/model/notify_user.go b/internal/user/model/notify_user.go index 1f6f6cade0..4f0b79c0ff 100644 --- a/internal/user/model/notify_user.go +++ b/internal/user/model/notify_user.go @@ -1,7 +1,7 @@ package model import ( - "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" "time" ) @@ -45,7 +45,7 @@ const ( type NotifyUserSearchQuery struct { Key NotifyUserSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value string } diff --git a/internal/user/model/token_view.go b/internal/user/model/token_view.go index d09c712897..7b76d0670d 100644 --- a/internal/user/model/token_view.go +++ b/internal/user/model/token_view.go @@ -1,9 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" "time" - - "github.com/caos/zitadel/internal/model" ) type TokenView struct { @@ -43,7 +42,7 @@ const ( type TokenSearchQuery struct { Key TokenSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } diff --git a/internal/user/model/user_membership_view.go b/internal/user/model/user_membership_view.go index bad5901ae8..dd3d0f2787 100644 --- a/internal/user/model/user_membership_view.go +++ b/internal/user/model/user_membership_view.go @@ -1,9 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" "time" - - "github.com/caos/zitadel/internal/model" ) type UserMembershipView struct { @@ -53,7 +52,7 @@ const ( type UserMembershipSearchQuery struct { Key UserMembershipSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } @@ -82,9 +81,9 @@ func (r *UserMembershipSearchRequest) GetSearchQuery(key UserMembershipSearchKey } func (r *UserMembershipSearchRequest) AppendResourceOwnerAndIamQuery(orgID, iamID string) { - r.Queries = append(r.Queries, &UserMembershipSearchQuery{Key: UserMembershipSearchKeyResourceOwner, Method: model.SearchMethodIsOneOf, Value: []string{orgID, iamID}}) + r.Queries = append(r.Queries, &UserMembershipSearchQuery{Key: UserMembershipSearchKeyResourceOwner, Method: domain.SearchMethodIsOneOf, Value: []string{orgID, iamID}}) } func (r *UserMembershipSearchRequest) AppendUserIDQuery(userID string) { - r.Queries = append(r.Queries, &UserMembershipSearchQuery{Key: UserMembershipSearchKeyUserID, Method: model.SearchMethodEquals, Value: userID}) + r.Queries = append(r.Queries, &UserMembershipSearchQuery{Key: UserMembershipSearchKeyUserID, Method: domain.SearchMethodEquals, Value: userID}) } diff --git a/internal/user/model/user_session_view.go b/internal/user/model/user_session_view.go index 9860c7d9ed..b36d32e9c6 100644 --- a/internal/user/model/user_session_view.go +++ b/internal/user/model/user_session_view.go @@ -1,10 +1,10 @@ package model import ( + "github.com/caos/zitadel/internal/domain" "time" req_model "github.com/caos/zitadel/internal/auth_request/model" - "github.com/caos/zitadel/internal/model" ) type UserSessionView struct { @@ -48,7 +48,7 @@ const ( type UserSessionSearchQuery struct { Key UserSessionSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } diff --git a/internal/user/model/user_view.go b/internal/user/model/user_view.go index 3635df6cfe..3bcd687949 100644 --- a/internal/user/model/user_view.go +++ b/internal/user/model/user_view.go @@ -10,7 +10,6 @@ import ( "github.com/caos/zitadel/internal/errors" "github.com/caos/zitadel/internal/eventstore/v1/models" iam_model "github.com/caos/zitadel/internal/iam/model" - "github.com/caos/zitadel/internal/model" ) type UserView struct { @@ -95,7 +94,7 @@ const ( type UserSearchQuery struct { Key UserSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } @@ -136,7 +135,7 @@ func (r *UserSearchRequest) EnsureLimit(limit uint64) { } func (r *UserSearchRequest) AppendMyOrgQuery(orgID string) { - r.Queries = append(r.Queries, &UserSearchQuery{Key: UserSearchKeyResourceOwner, Method: model.SearchMethodEquals, Value: orgID}) + r.Queries = append(r.Queries, &UserSearchQuery{Key: UserSearchKeyResourceOwner, Method: domain.SearchMethodEquals, Value: orgID}) } func (u *UserView) MFATypesSetupPossible(level domain.MFALevel, policy *domain.LoginPolicy) []domain.MFAType { diff --git a/internal/user/repository/view/external_idp_view.go b/internal/user/repository/view/external_idp_view.go index d3669c59b2..2df6dae5c0 100644 --- a/internal/user/repository/view/external_idp_view.go +++ b/internal/user/repository/view/external_idp_view.go @@ -1,12 +1,12 @@ package view import ( + "github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/view/repository" "github.com/jinzhu/gorm" caos_errs "github.com/caos/zitadel/internal/errors" - global_model "github.com/caos/zitadel/internal/model" usr_model "github.com/caos/zitadel/internal/user/model" "github.com/caos/zitadel/internal/user/repository/view/model" ) @@ -15,12 +15,12 @@ func ExternalIDPByExternalUserIDAndIDPConfigID(db *gorm.DB, table, externalUserI user := new(model.ExternalIDPView) userIDQuery := &model.ExternalIDPSearchQuery{ Key: usr_model.ExternalIDPSearchKeyExternalUserID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: externalUserID, } idpConfigIDQuery := &model.ExternalIDPSearchQuery{ Key: usr_model.ExternalIDPSearchKeyIdpConfigID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: idpConfigID, } query := repository.PrepareGetByQuery(table, userIDQuery, idpConfigIDQuery) @@ -35,17 +35,17 @@ func ExternalIDPByExternalUserIDAndIDPConfigIDAndResourceOwner(db *gorm.DB, tabl user := new(model.ExternalIDPView) userIDQuery := &model.ExternalIDPSearchQuery{ Key: usr_model.ExternalIDPSearchKeyExternalUserID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: externalUserID, } idpConfigIDQuery := &model.ExternalIDPSearchQuery{ Key: usr_model.ExternalIDPSearchKeyIdpConfigID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: idpConfigID, } resourceOwnerQuery := &model.ExternalIDPSearchQuery{ Key: usr_model.ExternalIDPSearchKeyResourceOwner, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: resourceOwner, } query := repository.PrepareGetByQuery(table, userIDQuery, idpConfigIDQuery, resourceOwnerQuery) @@ -60,7 +60,7 @@ func ExternalIDPsByIDPConfigID(db *gorm.DB, table, idpConfigID string) ([]*model externalIDPs := make([]*model.ExternalIDPView, 0) orgIDQuery := &usr_model.ExternalIDPSearchQuery{ Key: usr_model.ExternalIDPSearchKeyIdpConfigID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: idpConfigID, } query := repository.PrepareSearchQuery(table, model.ExternalIDPSearchRequest{ @@ -74,12 +74,12 @@ func ExternalIDPsByIDPConfigIDAndResourceOwner(db *gorm.DB, table, idpConfigID, externalIDPs := make([]*model.ExternalIDPView, 0) idpConfigIDQuery := &usr_model.ExternalIDPSearchQuery{ Key: usr_model.ExternalIDPSearchKeyIdpConfigID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: idpConfigID, } orgIDQuery := &usr_model.ExternalIDPSearchQuery{ Key: usr_model.ExternalIDPSearchKeyResourceOwner, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: resourceOwner, } query := repository.PrepareSearchQuery(table, model.ExternalIDPSearchRequest{ @@ -93,12 +93,12 @@ func ExternalIDPsByIDPConfigIDAndResourceOwners(db *gorm.DB, table, idpConfigID externalIDPs := make([]*model.ExternalIDPView, 0) idpConfigIDQuery := &usr_model.ExternalIDPSearchQuery{ Key: usr_model.ExternalIDPSearchKeyIdpConfigID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: idpConfigID, } orgIDQuery := &usr_model.ExternalIDPSearchQuery{ Key: usr_model.ExternalIDPSearchKeyResourceOwner, - Method: global_model.SearchMethodIsOneOf, + Method: domain.SearchMethodIsOneOf, Value: resourceOwners, } query := repository.PrepareSearchQuery(table, model.ExternalIDPSearchRequest{ @@ -112,7 +112,7 @@ func ExternalIDPsByUserID(db *gorm.DB, table, userID string) ([]*model.ExternalI externalIDPs := make([]*model.ExternalIDPView, 0) orgIDQuery := &usr_model.ExternalIDPSearchQuery{ Key: usr_model.ExternalIDPSearchKeyUserID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: userID, } query := repository.PrepareSearchQuery(table, model.ExternalIDPSearchRequest{ diff --git a/internal/user/repository/view/model/external_idp_query.go b/internal/user/repository/view/model/external_idp_query.go index 809a9e7f77..08e637f355 100644 --- a/internal/user/repository/view/model/external_idp_query.go +++ b/internal/user/repository/view/model/external_idp_query.go @@ -1,7 +1,7 @@ package model import ( - global_model "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" usr_model "github.com/caos/zitadel/internal/user/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req ExternalIDPSearchQuery) GetKey() repository.ColumnKey { return ExternalIDPSearchKey(req.Key) } -func (req ExternalIDPSearchQuery) GetMethod() global_model.SearchMethod { +func (req ExternalIDPSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/user/repository/view/model/notify_user_query.go b/internal/user/repository/view/model/notify_user_query.go index d036e62200..0d437e5925 100644 --- a/internal/user/repository/view/model/notify_user_query.go +++ b/internal/user/repository/view/model/notify_user_query.go @@ -1,7 +1,7 @@ package model import ( - global_model "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" usr_model "github.com/caos/zitadel/internal/user/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req NotifyUserSearchQuery) GetKey() repository.ColumnKey { return NotifyUserSearchKey(req.Key) } -func (req NotifyUserSearchQuery) GetMethod() global_model.SearchMethod { +func (req NotifyUserSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/user/repository/view/model/token_query.go b/internal/user/repository/view/model/token_query.go index 1148956371..d1e17ccdb0 100644 --- a/internal/user/repository/view/model/token_query.go +++ b/internal/user/repository/view/model/token_query.go @@ -1,7 +1,7 @@ package model import ( - global_model "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/user/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req TokenSearchQuery) GetKey() repository.ColumnKey { return TokenSearchKey(req.Key) } -func (req TokenSearchQuery) GetMethod() global_model.SearchMethod { +func (req TokenSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/user/repository/view/model/user_membership_query.go b/internal/user/repository/view/model/user_membership_query.go index 60822b5bf0..1f9458a00d 100644 --- a/internal/user/repository/view/model/user_membership_query.go +++ b/internal/user/repository/view/model/user_membership_query.go @@ -1,7 +1,7 @@ package model import ( - global_model "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" usr_model "github.com/caos/zitadel/internal/user/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req UserMembershipSearchQuery) GetKey() repository.ColumnKey { return UserMembershipSearchKey(req.Key) } -func (req UserMembershipSearchQuery) GetMethod() global_model.SearchMethod { +func (req UserMembershipSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/user/repository/view/model/user_query.go b/internal/user/repository/view/model/user_query.go index cf6ae30e84..ffe73cd966 100644 --- a/internal/user/repository/view/model/user_query.go +++ b/internal/user/repository/view/model/user_query.go @@ -1,7 +1,7 @@ package model import ( - global_model "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" usr_model "github.com/caos/zitadel/internal/user/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req UserSearchQuery) GetKey() repository.ColumnKey { return UserSearchKey(req.Key) } -func (req UserSearchQuery) GetMethod() global_model.SearchMethod { +func (req UserSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/user/repository/view/model/user_session_query.go b/internal/user/repository/view/model/user_session_query.go index 053742e7f3..49e2b47595 100644 --- a/internal/user/repository/view/model/user_session_query.go +++ b/internal/user/repository/view/model/user_session_query.go @@ -1,7 +1,7 @@ package model import ( - global_model "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" usr_model "github.com/caos/zitadel/internal/user/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req UserSessionSearchQuery) GetKey() repository.ColumnKey { return UserSessionSearchKey(req.Key) } -func (req UserSessionSearchQuery) GetMethod() global_model.SearchMethod { +func (req UserSessionSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/user/repository/view/notify_user.go b/internal/user/repository/view/notify_user.go index 62f61acf00..374d85bdc4 100644 --- a/internal/user/repository/view/notify_user.go +++ b/internal/user/repository/view/notify_user.go @@ -1,8 +1,8 @@ package view import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" - global_model "github.com/caos/zitadel/internal/model" usr_model "github.com/caos/zitadel/internal/user/model" "github.com/caos/zitadel/internal/user/repository/view/model" "github.com/caos/zitadel/internal/view/repository" @@ -23,7 +23,7 @@ func NotifyUsersByOrgID(db *gorm.DB, table, orgID string) ([]*model.NotifyUser, users := make([]*model.NotifyUser, 0) orgIDQuery := &usr_model.NotifyUserSearchQuery{ Key: usr_model.NotifyUserSearchKeyResourceOwner, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: orgID, } query := repository.PrepareSearchQuery(table, model.NotifyUserSearchRequest{ diff --git a/internal/user/repository/view/token_view.go b/internal/user/repository/view/token_view.go index 5666661fdd..93af59ce4a 100644 --- a/internal/user/repository/view/token_view.go +++ b/internal/user/repository/view/token_view.go @@ -1,8 +1,8 @@ package view import ( + "github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/errors" - global_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/user/model" usr_model "github.com/caos/zitadel/internal/user/repository/view/model" "github.com/caos/zitadel/internal/view/repository" @@ -24,7 +24,7 @@ func TokensByUserID(db *gorm.DB, table, userID string) ([]*usr_model.TokenView, tokens := make([]*usr_model.TokenView, 0) userIDQuery := &model.TokenSearchQuery{ Key: model.TokenSearchKeyUserID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: userID, } query := repository.PrepareSearchQuery(table, usr_model.TokenSearchRequest{ diff --git a/internal/user/repository/view/user_session_view.go b/internal/user/repository/view/user_session_view.go index 930559af26..7a49e0c270 100644 --- a/internal/user/repository/view/user_session_view.go +++ b/internal/user/repository/view/user_session_view.go @@ -2,11 +2,11 @@ package view import ( auth_model "github.com/caos/zitadel/internal/auth_request/model" + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" "github.com/caos/zitadel/internal/view/repository" "github.com/jinzhu/gorm" - global_model "github.com/caos/zitadel/internal/model" usr_model "github.com/caos/zitadel/internal/user/model" "github.com/caos/zitadel/internal/user/repository/view/model" ) @@ -15,12 +15,12 @@ func UserSessionByIDs(db *gorm.DB, table, agentID, userID string) (*model.UserSe userSession := new(model.UserSessionView) userAgentQuery := model.UserSessionSearchQuery{ Key: usr_model.UserSessionSearchKeyUserAgentID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: agentID, } userQuery := model.UserSessionSearchQuery{ Key: usr_model.UserSessionSearchKeyUserID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: userID, } query := repository.PrepareGetByQuery(table, userAgentQuery, userQuery) @@ -35,7 +35,7 @@ func UserSessionsByUserID(db *gorm.DB, table, userID string) ([]*model.UserSessi userSessions := make([]*model.UserSessionView, 0) userAgentQuery := &usr_model.UserSessionSearchQuery{ Key: usr_model.UserSessionSearchKeyUserID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: userID, } query := repository.PrepareSearchQuery(table, model.UserSessionSearchRequest{ @@ -49,7 +49,7 @@ func UserSessionsByAgentID(db *gorm.DB, table, agentID string) ([]*model.UserSes userSessions := make([]*model.UserSessionView, 0) userAgentQuery := &usr_model.UserSessionSearchQuery{ Key: usr_model.UserSessionSearchKeyUserAgentID, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: agentID, } query := repository.PrepareSearchQuery(table, model.UserSessionSearchRequest{ @@ -63,7 +63,7 @@ func ActiveUserSessions(db *gorm.DB, table string) ([]*model.UserSessionView, er userSessions := make([]*model.UserSessionView, 0) activeQuery := &usr_model.UserSessionSearchQuery{ Key: usr_model.UserSessionSearchKeyState, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: auth_model.UserSessionStateActive, } query := repository.PrepareSearchQuery(table, model.UserSessionSearchRequest{ diff --git a/internal/user/repository/view/user_view.go b/internal/user/repository/view/user_view.go index 191c4686c4..c00b9a5941 100644 --- a/internal/user/repository/view/user_view.go +++ b/internal/user/repository/view/user_view.go @@ -1,12 +1,12 @@ package view import ( + "github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/view/repository" "github.com/jinzhu/gorm" caos_errs "github.com/caos/zitadel/internal/errors" - global_model "github.com/caos/zitadel/internal/model" usr_model "github.com/caos/zitadel/internal/user/model" "github.com/caos/zitadel/internal/user/repository/view/model" ) @@ -35,7 +35,7 @@ func UserByLoginName(db *gorm.DB, table, loginName string) (*model.UserView, err user := new(model.UserView) loginNameQuery := &model.UserSearchQuery{ Key: usr_model.UserSearchKeyLoginNames, - Method: global_model.SearchMethodListContains, + Method: domain.SearchMethodListContains, Value: loginName, } query := repository.PrepareGetByQuery(table, loginNameQuery) @@ -50,12 +50,12 @@ func UserByLoginNameAndResourceOwner(db *gorm.DB, table, loginName, resourceOwne user := new(model.UserView) loginNameQuery := &model.UserSearchQuery{ Key: usr_model.UserSearchKeyLoginNames, - Method: global_model.SearchMethodListContains, + Method: domain.SearchMethodListContains, Value: loginName, } resourceOwnerQuery := &model.UserSearchQuery{ Key: usr_model.UserSearchKeyResourceOwner, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: resourceOwner, } query := repository.PrepareGetByQuery(table, loginNameQuery, resourceOwnerQuery) @@ -70,7 +70,7 @@ func UsersByOrgID(db *gorm.DB, table, orgID string) ([]*model.UserView, error) { users := make([]*model.UserView, 0) orgIDQuery := &usr_model.UserSearchQuery{ Key: usr_model.UserSearchKeyResourceOwner, - Method: global_model.SearchMethodEquals, + Method: domain.SearchMethodEquals, Value: orgID, } query := repository.PrepareSearchQuery(table, model.UserSearchRequest{ @@ -80,15 +80,15 @@ func UsersByOrgID(db *gorm.DB, table, orgID string) ([]*model.UserView, error) { return users, err } -func UserIDsByDomain(db *gorm.DB, table, domain string) ([]string, error) { +func UserIDsByDomain(db *gorm.DB, table, orgDomain string) ([]string, error) { type id struct { Id string } ids := make([]id, 0) orgIDQuery := &usr_model.UserSearchQuery{ Key: usr_model.UserSearchKeyUserName, - Method: global_model.SearchMethodEndsWithIgnoreCase, - Value: "%" + domain, + Method: domain.SearchMethodEndsWithIgnoreCase, + Value: "%" + orgDomain, } query := repository.PrepareSearchQuery(table, model.UserSearchRequest{ Queries: []*usr_model.UserSearchQuery{orgIDQuery}, @@ -116,7 +116,7 @@ func SearchUsers(db *gorm.DB, table string, req *usr_model.UserSearchRequest) ([ func GetGlobalUserByLoginName(db *gorm.DB, table, loginName string) (*model.UserView, error) { user := new(model.UserView) - query := repository.PrepareGetByQuery(table, &model.UserSearchQuery{Key: usr_model.UserSearchKeyLoginNames, Value: loginName, Method: global_model.SearchMethodListContains}) + query := repository.PrepareGetByQuery(table, &model.UserSearchQuery{Key: usr_model.UserSearchKeyLoginNames, Value: loginName, Method: domain.SearchMethodListContains}) err := query(db, user) if caos_errs.IsNotFound(err) { return nil, caos_errs.ThrowNotFound(nil, "VIEW-8uWer", "Errors.User.NotFound") diff --git a/internal/user/repository/view/usermembership_view.go b/internal/user/repository/view/usermembership_view.go index a2082a06e0..47e3e95d40 100644 --- a/internal/user/repository/view/usermembership_view.go +++ b/internal/user/repository/view/usermembership_view.go @@ -1,7 +1,7 @@ package view import ( - global_model "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/view/repository" "github.com/jinzhu/gorm" @@ -12,10 +12,10 @@ import ( func UserMembershipByIDs(db *gorm.DB, table, userID, aggregateID, objectID string, membertype usr_model.MemberType) (*model.UserMembershipView, error) { memberships := new(model.UserMembershipView) - userIDQuery := &model.UserMembershipSearchQuery{Key: usr_model.UserMembershipSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals} - aggregateIDQuery := &model.UserMembershipSearchQuery{Key: usr_model.UserMembershipSearchKeyAggregateID, Value: aggregateID, Method: global_model.SearchMethodEquals} - objectIDQuery := &model.UserMembershipSearchQuery{Key: usr_model.UserMembershipSearchKeyObjectID, Value: objectID, Method: global_model.SearchMethodEquals} - memberTypeQuery := &model.UserMembershipSearchQuery{Key: usr_model.UserMembershipSearchKeyMemberType, Value: int32(membertype), Method: global_model.SearchMethodEquals} + userIDQuery := &model.UserMembershipSearchQuery{Key: usr_model.UserMembershipSearchKeyUserID, Value: userID, Method: domain.SearchMethodEquals} + aggregateIDQuery := &model.UserMembershipSearchQuery{Key: usr_model.UserMembershipSearchKeyAggregateID, Value: aggregateID, Method: domain.SearchMethodEquals} + objectIDQuery := &model.UserMembershipSearchQuery{Key: usr_model.UserMembershipSearchKeyObjectID, Value: objectID, Method: domain.SearchMethodEquals} + memberTypeQuery := &model.UserMembershipSearchQuery{Key: usr_model.UserMembershipSearchKeyMemberType, Value: int32(membertype), Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, userIDQuery, aggregateIDQuery, objectIDQuery, memberTypeQuery) err := query(db, memberships) @@ -27,7 +27,7 @@ func UserMembershipByIDs(db *gorm.DB, table, userID, aggregateID, objectID strin func UserMembershipsByAggregateID(db *gorm.DB, table, aggregateID string) ([]*model.UserMembershipView, error) { memberships := make([]*model.UserMembershipView, 0) - aggregateIDQuery := &usr_model.UserMembershipSearchQuery{Key: usr_model.UserMembershipSearchKeyAggregateID, Value: aggregateID, Method: global_model.SearchMethodEquals} + aggregateIDQuery := &usr_model.UserMembershipSearchQuery{Key: usr_model.UserMembershipSearchKeyAggregateID, Value: aggregateID, Method: domain.SearchMethodEquals} query := repository.PrepareSearchQuery(table, model.UserMembershipSearchRequest{ Queries: []*usr_model.UserMembershipSearchQuery{aggregateIDQuery}, }) @@ -37,7 +37,7 @@ func UserMembershipsByAggregateID(db *gorm.DB, table, aggregateID string) ([]*mo func UserMembershipsByResourceOwner(db *gorm.DB, table, resourceOwner string) ([]*model.UserMembershipView, error) { memberships := make([]*model.UserMembershipView, 0) - aggregateIDQuery := &usr_model.UserMembershipSearchQuery{Key: usr_model.UserMembershipSearchKeyResourceOwner, Value: resourceOwner, Method: global_model.SearchMethodEquals} + aggregateIDQuery := &usr_model.UserMembershipSearchQuery{Key: usr_model.UserMembershipSearchKeyResourceOwner, Value: resourceOwner, Method: domain.SearchMethodEquals} query := repository.PrepareSearchQuery(table, model.UserMembershipSearchRequest{ Queries: []*usr_model.UserMembershipSearchQuery{aggregateIDQuery}, }) diff --git a/internal/usergrant/model/user_grant_view.go b/internal/usergrant/model/user_grant_view.go index 246a361e0c..9d53e5db7a 100644 --- a/internal/usergrant/model/user_grant_view.go +++ b/internal/usergrant/model/user_grant_view.go @@ -1,9 +1,8 @@ package model import ( + "github.com/caos/zitadel/internal/domain" "time" - - "github.com/caos/zitadel/internal/model" ) type UserGrantView struct { @@ -69,7 +68,7 @@ const ( type UserGrantSearchQuery struct { Key UserGrantSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } @@ -98,9 +97,9 @@ func (r *UserGrantSearchRequest) GetSearchQuery(key UserGrantSearchKey) (int, *U } func (r *UserGrantSearchRequest) AppendMyOrgQuery(orgID string) { - r.Queries = append(r.Queries, &UserGrantSearchQuery{Key: UserGrantSearchKeyResourceOwner, Method: model.SearchMethodEquals, Value: orgID}) + r.Queries = append(r.Queries, &UserGrantSearchQuery{Key: UserGrantSearchKeyResourceOwner, Method: domain.SearchMethodEquals, Value: orgID}) } func (r *UserGrantSearchRequest) AppendProjectIDQuery(projectID string) { - r.Queries = append(r.Queries, &UserGrantSearchQuery{Key: UserGrantSearchKeyProjectID, Method: model.SearchMethodEquals, Value: projectID}) + r.Queries = append(r.Queries, &UserGrantSearchQuery{Key: UserGrantSearchKeyProjectID, Method: domain.SearchMethodEquals, Value: projectID}) } diff --git a/internal/usergrant/repository/view/model/user_grant_query.go b/internal/usergrant/repository/view/model/user_grant_query.go index ad0943a3db..cdb9311072 100644 --- a/internal/usergrant/repository/view/model/user_grant_query.go +++ b/internal/usergrant/repository/view/model/user_grant_query.go @@ -1,7 +1,7 @@ package model import ( - global_model "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" grant_model "github.com/caos/zitadel/internal/usergrant/model" "github.com/caos/zitadel/internal/view/repository" ) @@ -41,7 +41,7 @@ func (req UserGrantSearchQuery) GetKey() repository.ColumnKey { return UserGrantSearchKey(req.Key) } -func (req UserGrantSearchQuery) GetMethod() global_model.SearchMethod { +func (req UserGrantSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/usergrant/repository/view/user_grant_view.go b/internal/usergrant/repository/view/user_grant_view.go index ed31215237..7b9015a168 100644 --- a/internal/usergrant/repository/view/user_grant_view.go +++ b/internal/usergrant/repository/view/user_grant_view.go @@ -1,8 +1,8 @@ package view import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" - global_model "github.com/caos/zitadel/internal/model" grant_model "github.com/caos/zitadel/internal/usergrant/model" "github.com/caos/zitadel/internal/usergrant/repository/view/model" "github.com/caos/zitadel/internal/view/repository" @@ -22,9 +22,9 @@ func UserGrantByID(db *gorm.DB, table, grantID string) (*model.UserGrantView, er func UserGrantByIDs(db *gorm.DB, table, resourceOwnerID, projectID, userID string) (*model.UserGrantView, error) { user := new(model.UserGrantView) - resourceOwnerIDQuery := model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyResourceOwner, Value: resourceOwnerID, Method: global_model.SearchMethodEquals} - projectIDQuery := model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals} - userIDQuery := model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals} + resourceOwnerIDQuery := model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyResourceOwner, Value: resourceOwnerID, Method: domain.SearchMethodEquals} + projectIDQuery := model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyProjectID, Value: projectID, Method: domain.SearchMethodEquals} + userIDQuery := model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyUserID, Value: userID, Method: domain.SearchMethodEquals} query := repository.PrepareGetByQuery(table, resourceOwnerIDQuery, projectIDQuery, userIDQuery) err := query(db, user) if caos_errs.IsNotFound(err) { @@ -72,7 +72,7 @@ func SearchUserGrants(db *gorm.DB, table string, req *grant_model.UserGrantSearc func UserGrantsByUserID(db *gorm.DB, table, userID string) ([]*model.UserGrantView, error) { users := make([]*model.UserGrantView, 0) queries := []*grant_model.UserGrantSearchQuery{ - {Key: grant_model.UserGrantSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals}, + {Key: grant_model.UserGrantSearchKeyUserID, Value: userID, Method: domain.SearchMethodEquals}, } query := repository.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries}) _, err := query(db, &users) @@ -85,7 +85,7 @@ func UserGrantsByUserID(db *gorm.DB, table, userID string) ([]*model.UserGrantVi func UserGrantsByProjectID(db *gorm.DB, table, projectID string) ([]*model.UserGrantView, error) { users := make([]*model.UserGrantView, 0) queries := []*grant_model.UserGrantSearchQuery{ - {Key: grant_model.UserGrantSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}, + {Key: grant_model.UserGrantSearchKeyProjectID, Value: projectID, Method: domain.SearchMethodEquals}, } query := repository.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries}) _, err := query(db, &users) @@ -98,8 +98,8 @@ func UserGrantsByProjectID(db *gorm.DB, table, projectID string) ([]*model.UserG func UserGrantsByProjectAndUserID(db *gorm.DB, table, projectID, userID string) ([]*model.UserGrantView, error) { users := make([]*model.UserGrantView, 0) queries := []*grant_model.UserGrantSearchQuery{ - {Key: grant_model.UserGrantSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}, - {Key: grant_model.UserGrantSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals}, + {Key: grant_model.UserGrantSearchKeyProjectID, Value: projectID, Method: domain.SearchMethodEquals}, + {Key: grant_model.UserGrantSearchKeyUserID, Value: userID, Method: domain.SearchMethodEquals}, } query := repository.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries}) _, err := query(db, &users) @@ -112,8 +112,8 @@ func UserGrantsByProjectAndUserID(db *gorm.DB, table, projectID, userID string) func UserGrantsByProjectAndGrantID(db *gorm.DB, table, projectID, grantID string) ([]*model.UserGrantView, error) { users := make([]*model.UserGrantView, 0) queries := []*grant_model.UserGrantSearchQuery{ - {Key: grant_model.UserGrantSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}, - {Key: grant_model.UserGrantSearchKeyGrantID, Value: grantID, Method: global_model.SearchMethodEquals}, + {Key: grant_model.UserGrantSearchKeyProjectID, Value: projectID, Method: domain.SearchMethodEquals}, + {Key: grant_model.UserGrantSearchKeyGrantID, Value: grantID, Method: domain.SearchMethodEquals}, } query := repository.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries}) _, err := query(db, &users) @@ -126,8 +126,8 @@ func UserGrantsByProjectAndGrantID(db *gorm.DB, table, projectID, grantID string func UserGrantsByProjectIDAndRole(db *gorm.DB, table, projectID, roleKey string) ([]*model.UserGrantView, error) { users := make([]*model.UserGrantView, 0) queries := []*grant_model.UserGrantSearchQuery{ - {Key: grant_model.UserGrantSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}, - {Key: grant_model.UserGrantSearchKeyRoleKey, Value: roleKey, Method: global_model.SearchMethodListContains}, + {Key: grant_model.UserGrantSearchKeyProjectID, Value: projectID, Method: domain.SearchMethodEquals}, + {Key: grant_model.UserGrantSearchKeyRoleKey, Value: roleKey, Method: domain.SearchMethodListContains}, } query := repository.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries}) _, err := query(db, &users) @@ -140,8 +140,8 @@ func UserGrantsByProjectIDAndRole(db *gorm.DB, table, projectID, roleKey string) func UserGrantsByOrgIDAndProjectID(db *gorm.DB, table, orgID, projectID string) ([]*model.UserGrantView, error) { users := make([]*model.UserGrantView, 0) queries := []*grant_model.UserGrantSearchQuery{ - {Key: grant_model.UserGrantSearchKeyResourceOwner, Value: orgID, Method: global_model.SearchMethodEquals}, - {Key: grant_model.UserGrantSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}, + {Key: grant_model.UserGrantSearchKeyResourceOwner, Value: orgID, Method: domain.SearchMethodEquals}, + {Key: grant_model.UserGrantSearchKeyProjectID, Value: projectID, Method: domain.SearchMethodEquals}, } query := repository.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries}) _, err := query(db, &users) @@ -154,7 +154,7 @@ func UserGrantsByOrgIDAndProjectID(db *gorm.DB, table, orgID, projectID string) func UserGrantsByOrgID(db *gorm.DB, table, orgID string) ([]*model.UserGrantView, error) { users := make([]*model.UserGrantView, 0) queries := []*grant_model.UserGrantSearchQuery{ - {Key: grant_model.UserGrantSearchKeyResourceOwner, Value: orgID, Method: global_model.SearchMethodEquals}, + {Key: grant_model.UserGrantSearchKeyResourceOwner, Value: orgID, Method: domain.SearchMethodEquals}, } query := repository.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries}) _, err := query(db, &users) diff --git a/internal/view/model/general_query.go b/internal/view/model/general_query.go index 285628eb3a..5e0134a7ab 100644 --- a/internal/view/model/general_query.go +++ b/internal/view/model/general_query.go @@ -1,6 +1,8 @@ package model -import "github.com/caos/zitadel/internal/model" +import ( + "github.com/caos/zitadel/internal/domain" +) type GeneralSearchRequest struct { Offset uint64 @@ -18,6 +20,6 @@ const ( type GeneralSearchQuery struct { Key GeneralSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } diff --git a/internal/view/repository/db_mock_test.go b/internal/view/repository/db_mock_test.go index 697b9e79fa..0a37295926 100644 --- a/internal/view/repository/db_mock_test.go +++ b/internal/view/repository/db_mock_test.go @@ -3,13 +3,12 @@ package repository import ( "database/sql/driver" "fmt" + "github.com/caos/zitadel/internal/domain" "strconv" "testing" "github.com/DATA-DOG/go-sqlmock" "github.com/jinzhu/gorm" - - "github.com/caos/zitadel/internal/model" ) var ( @@ -73,7 +72,7 @@ func (req TestSearchRequest) GetQueries() []SearchQuery { type TestSearchQuery struct { key TestSearchKey - method model.SearchMethod + method domain.SearchMethod value string } @@ -81,7 +80,7 @@ func (req TestSearchQuery) GetKey() ColumnKey { return req.key } -func (req TestSearchQuery) GetMethod() model.SearchMethod { +func (req TestSearchQuery) GetMethod() domain.SearchMethod { return req.method } diff --git a/internal/view/repository/failed_events.go b/internal/view/repository/failed_events.go index 404aa58d8d..9c4ecbeeec 100644 --- a/internal/view/repository/failed_events.go +++ b/internal/view/repository/failed_events.go @@ -1,10 +1,10 @@ package repository import ( + "github.com/caos/zitadel/internal/domain" "strings" "github.com/caos/zitadel/internal/errors" - "github.com/caos/zitadel/internal/model" view_model "github.com/caos/zitadel/internal/view/model" "github.com/jinzhu/gorm" ) @@ -23,7 +23,7 @@ type FailedEvent struct { type FailedEventSearchQuery struct { Key FailedEventSearchKey - Method model.SearchMethod + Method domain.SearchMethod Value interface{} } @@ -31,7 +31,7 @@ func (req FailedEventSearchQuery) GetKey() ColumnKey { return failedEventSearchKey(req.Key) } -func (req FailedEventSearchQuery) GetMethod() model.SearchMethod { +func (req FailedEventSearchQuery) GetMethod() domain.SearchMethod { return req.Method } @@ -100,8 +100,8 @@ func RemoveFailedEvent(db *gorm.DB, table string, failedEvent *FailedEvent) erro func LatestFailedEvent(db *gorm.DB, table, viewName string, sequence uint64) (*FailedEvent, error) { failedEvent := new(FailedEvent) queries := []SearchQuery{ - FailedEventSearchQuery{Key: FailedEventKeyViewName, Method: model.SearchMethodEqualsIgnoreCase, Value: viewName}, - FailedEventSearchQuery{Key: FailedEventKeyFailedSequence, Method: model.SearchMethodEquals, Value: sequence}, + FailedEventSearchQuery{Key: FailedEventKeyViewName, Method: domain.SearchMethodEqualsIgnoreCase, Value: viewName}, + FailedEventSearchQuery{Key: FailedEventKeyFailedSequence, Method: domain.SearchMethodEquals, Value: sequence}, } query := PrepareGetByQuery(table, queries...) err := query(db, failedEvent) diff --git a/internal/view/repository/general_query.go b/internal/view/repository/general_query.go index df53841c18..8cd264d1d1 100644 --- a/internal/view/repository/general_query.go +++ b/internal/view/repository/general_query.go @@ -1,7 +1,7 @@ package repository import ( - global_model "github.com/caos/zitadel/internal/model" + "github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/view/model" ) @@ -40,7 +40,7 @@ func (req GeneralSearchQuery) GetKey() ColumnKey { return GeneralSearchKey(req.Key) } -func (req GeneralSearchQuery) GetMethod() global_model.SearchMethod { +func (req GeneralSearchQuery) GetMethod() domain.SearchMethod { return req.Method } diff --git a/internal/view/repository/query.go b/internal/view/repository/query.go index 8205cda518..410339735b 100644 --- a/internal/view/repository/query.go +++ b/internal/view/repository/query.go @@ -2,9 +2,9 @@ package repository import ( "fmt" + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" - "github.com/caos/zitadel/internal/model" "github.com/jinzhu/gorm" "github.com/lib/pq" ) @@ -19,7 +19,7 @@ type SearchRequest interface { type SearchQuery interface { GetKey() ColumnKey - GetMethod() model.SearchMethod + GetMethod() domain.SearchMethod GetValue() interface{} } @@ -60,66 +60,66 @@ func PrepareSearchQuery(table string, request SearchRequest) func(db *gorm.DB, r } } -func SetQuery(query *gorm.DB, key ColumnKey, value interface{}, method model.SearchMethod) (*gorm.DB, error) { +func SetQuery(query *gorm.DB, key ColumnKey, value interface{}, method domain.SearchMethod) (*gorm.DB, error) { column := key.ToColumnName() if column == "" { return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-7dz3w", "Column name missing") } switch method { - case model.SearchMethodEquals: + case domain.SearchMethodEquals: query = query.Where(""+column+" = ?", value) - case model.SearchMethodEqualsIgnoreCase: + case domain.SearchMethodEqualsIgnoreCase: valueText, ok := value.(string) if !ok { return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-idu8e", "Equal ignore case only possible for strings") } query = query.Where("LOWER("+column+") = LOWER(?)", valueText) - case model.SearchMethodStartsWith: + case domain.SearchMethodStartsWith: valueText, ok := value.(string) if !ok { return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-SLj7s", "Starts with only possible for strings") } query = query.Where(column+" LIKE ?", valueText+"%") - case model.SearchMethodStartsWithIgnoreCase: + case domain.SearchMethodStartsWithIgnoreCase: valueText, ok := value.(string) if !ok { return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-eidus", "Starts with ignore case only possible for strings") } query = query.Where("LOWER("+column+") LIKE LOWER(?)", valueText+"%") - case model.SearchMethodEndsWith: + case domain.SearchMethodEndsWith: valueText, ok := value.(string) if !ok { return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-Hswd3", "Ends with only possible for strings") } query = query.Where(column+" LIKE ?", "%"+valueText) - case model.SearchMethodEndsWithIgnoreCase: + case domain.SearchMethodEndsWithIgnoreCase: valueText, ok := value.(string) if !ok { return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-dAG31", "Ends with ignore case only possible for strings") } query = query.Where("LOWER("+column+") LIKE LOWER(?)", "%"+valueText) - case model.SearchMethodContains: + case domain.SearchMethodContains: valueText, ok := value.(string) if !ok { return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-3ids", "Contains with only possible for strings") } query = query.Where(column+" LIKE ?", "%"+valueText+"%") - case model.SearchMethodContainsIgnoreCase: + case domain.SearchMethodContainsIgnoreCase: valueText, ok := value.(string) if !ok { return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-eid73", "Contains with ignore case only possible for strings") } query = query.Where("LOWER("+column+") LIKE LOWER(?)", "%"+valueText+"%") - case model.SearchMethodNotEquals: + case domain.SearchMethodNotEquals: query = query.Where(""+column+" <> ?", value) - case model.SearchMethodGreaterThan: + case domain.SearchMethodGreaterThan: query = query.Where(column+" > ?", value) - case model.SearchMethodLessThan: + case domain.SearchMethodLessThan: query = query.Where(column+" < ?", value) - case model.SearchMethodIsOneOf: + case domain.SearchMethodIsOneOf: query = query.Where(column+" IN (?)", value) - case model.SearchMethodListContains: + case domain.SearchMethodListContains: valueText, ok := value.(string) if !ok { return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-Psois", "list contains only possible for strings") diff --git a/internal/view/repository/query_test.go b/internal/view/repository/query_test.go index e3ef16c96e..79c3692298 100644 --- a/internal/view/repository/query_test.go +++ b/internal/view/repository/query_test.go @@ -1,8 +1,8 @@ package repository import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" - "github.com/caos/zitadel/internal/model" "github.com/jinzhu/gorm" "testing" ) @@ -94,7 +94,7 @@ func TestPrepareSearchQuery(t *testing.T) { expectGetSearchRequestWithSearchQuery("TESTTABLE", TestSearchKey_ID.ToColumnName(), "=", "AggregateID", 2, 2), args{ table: "TESTTABLE", - searchRequest: TestSearchRequest{queries: []SearchQuery{TestSearchQuery{key: TestSearchKey_ID, method: model.SearchMethodEqualsIgnoreCase, value: "AggregateID"}}}, + searchRequest: TestSearchRequest{queries: []SearchQuery{TestSearchQuery{key: TestSearchKey_ID, method: domain.SearchMethodEqualsIgnoreCase, value: "AggregateID"}}}, }, res{ count: 2, @@ -107,7 +107,7 @@ func TestPrepareSearchQuery(t *testing.T) { expectGetSearchRequestWithAllParams("TESTTABLE", TestSearchKey_ID.ToColumnName(), "=", "AggregateID", "ASC", TestSearchKey_ID, 2, 2, 2, 5), args{ table: "TESTTABLE", - searchRequest: TestSearchRequest{limit: 2, offset: 2, sortingColumn: TestSearchKey_ID, asc: true, queries: []SearchQuery{TestSearchQuery{key: TestSearchKey_ID, method: model.SearchMethodEqualsIgnoreCase, value: "AggregateID"}}}, + searchRequest: TestSearchRequest{limit: 2, offset: 2, sortingColumn: TestSearchKey_ID, asc: true, queries: []SearchQuery{TestSearchQuery{key: TestSearchKey_ID, method: domain.SearchMethodEqualsIgnoreCase, value: "AggregateID"}}}, }, res{ count: 5, diff --git a/internal/view/repository/requests_test.go b/internal/view/repository/requests_test.go index 20dec59488..20e61555f2 100644 --- a/internal/view/repository/requests_test.go +++ b/internal/view/repository/requests_test.go @@ -1,8 +1,8 @@ package repository import ( + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" - "github.com/caos/zitadel/internal/model" "github.com/jinzhu/gorm" "testing" ) @@ -113,7 +113,7 @@ func TestPrepareGetByQuery(t *testing.T) { expectGetByQuery("TESTTABLE", "test", "=", "VALUE"), args{ table: "TESTTABLE", - searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.SearchMethodEqualsIgnoreCase, value: "VALUE"}, + searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: domain.SearchMethodEqualsIgnoreCase, value: "VALUE"}, }, res{ result: Test{ID: "VALUE"}, @@ -126,7 +126,7 @@ func TestPrepareGetByQuery(t *testing.T) { expectGetByQueryCaseSensitive("TESTTABLE", "test", "=", "VALUE"), args{ table: "TESTTABLE", - searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.SearchMethodEquals, value: "VALUE"}, + searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: domain.SearchMethodEquals, value: "VALUE"}, }, res{ result: Test{ID: "VALUE"}, @@ -139,7 +139,7 @@ func TestPrepareGetByQuery(t *testing.T) { expectGetByQuery("TESTTABLE", "test", "LIKE", "VALUE%"), args{ table: "TESTTABLE", - searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.SearchMethodStartsWithIgnoreCase, value: "VALUE"}, + searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: domain.SearchMethodStartsWithIgnoreCase, value: "VALUE"}, }, res{ result: Test{ID: "VALUE"}, @@ -152,7 +152,7 @@ func TestPrepareGetByQuery(t *testing.T) { expectGetByQueryCaseSensitive("TESTTABLE", "test", "LIKE", "VALUE%"), args{ table: "TESTTABLE", - searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.SearchMethodStartsWith, value: "VALUE"}, + searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: domain.SearchMethodStartsWith, value: "VALUE"}, }, res{ result: Test{ID: "VALUE"}, @@ -165,7 +165,7 @@ func TestPrepareGetByQuery(t *testing.T) { expectGetByQuery("TESTTABLE", "test", "LIKE", "%VALUE%"), args{ table: "TESTTABLE", - searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.SearchMethodContainsIgnoreCase, value: "VALUE"}, + searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: domain.SearchMethodContainsIgnoreCase, value: "VALUE"}, }, res{ result: Test{ID: "VALUE"}, @@ -178,7 +178,7 @@ func TestPrepareGetByQuery(t *testing.T) { expectGetByQueryCaseSensitive("TESTTABLE", "test", "LIKE", "%VALUE%"), args{ table: "TESTTABLE", - searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.SearchMethodContains, value: "VALUE"}, + searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: domain.SearchMethodContains, value: "VALUE"}, }, res{ result: Test{ID: "VALUE"}, @@ -191,7 +191,7 @@ func TestPrepareGetByQuery(t *testing.T) { expectGetByQueryErr("TESTTABLE", "test", "LIKE", "%VALUE%", gorm.ErrRecordNotFound), args{ table: "TESTTABLE", - searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.SearchMethodContainsIgnoreCase, value: "VALUE"}, + searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: domain.SearchMethodContainsIgnoreCase, value: "VALUE"}, }, res{ result: Test{ID: "VALUE"}, @@ -205,7 +205,7 @@ func TestPrepareGetByQuery(t *testing.T) { expectGetByQueryErr("TESTTABLE", "test", "LIKE", "%VALUE%", gorm.ErrUnaddressable), args{ table: "TESTTABLE", - searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.SearchMethodContainsIgnoreCase, value: "VALUE"}, + searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: domain.SearchMethodContainsIgnoreCase, value: "VALUE"}, }, res{ result: Test{ID: "VALUE"}, @@ -219,7 +219,7 @@ func TestPrepareGetByQuery(t *testing.T) { expectGetByQuery("TESTTABLE", "", "=", "VALUE"), args{ table: "TESTTABLE", - searchQuery: TestSearchQuery{key: TestSearchKey_UNDEFINED, method: model.SearchMethodEqualsIgnoreCase, value: "VALUE"}, + searchQuery: TestSearchQuery{key: TestSearchKey_UNDEFINED, method: domain.SearchMethodEqualsIgnoreCase, value: "VALUE"}, }, res{ result: Test{ID: "VALUE"}, diff --git a/internal/view/repository/sequence.go b/internal/view/repository/sequence.go index b1d5f64a3e..c6b6d0354a 100644 --- a/internal/view/repository/sequence.go +++ b/internal/view/repository/sequence.go @@ -1,13 +1,13 @@ package repository import ( + "github.com/caos/zitadel/internal/domain" "strings" "time" "github.com/jinzhu/gorm" caos_errs "github.com/caos/zitadel/internal/errors" - int_model "github.com/caos/zitadel/internal/model" "github.com/caos/zitadel/internal/view/model" ) @@ -60,8 +60,8 @@ func (q *sequenceSearchQuery) GetKey() ColumnKey { return q.key } -func (q *sequenceSearchQuery) GetMethod() int_model.SearchMethod { - return int_model.SearchMethodEquals +func (q *sequenceSearchQuery) GetMethod() domain.SearchMethod { + return domain.SearchMethodEquals } func (q *sequenceSearchQuery) GetValue() interface{} {