From 3cd3a238c2fd1b9bee36e144ab58696076c59c9b Mon Sep 17 00:00:00 2001 From: Fabi <38692350+fgerschwiler@users.noreply.github.com> Date: Tue, 23 Jun 2020 14:47:47 +0200 Subject: [PATCH] fix: all enums same style (#262) * fix: all enums same style * fix: rename process to reduce * add some missing enum renaming Co-authored-by: Livio Amstutz --- .../eventsourcing/eventstore/org.go | 10 +- .../repository/eventsourcing/handler/org.go | 2 +- .../repository/eventsourcing/setup/setup.go | 91 ++++++++-------- .../eventsourcing/eventstore/auth_request.go | 6 +- .../eventstore/auth_request_test.go | 42 ++++---- .../eventsourcing/eventstore/user.go | 2 +- .../eventsourcing/eventstore/user_grant.go | 10 +- .../eventsourcing/handler/application.go | 2 +- .../repository/eventsourcing/handler/key.go | 2 +- .../repository/eventsourcing/handler/org.go | 2 +- .../repository/eventsourcing/handler/token.go | 2 +- .../repository/eventsourcing/handler/user.go | 2 +- .../eventsourcing/handler/user_grant.go | 2 +- .../eventsourcing/handler/user_session.go | 2 +- .../eventsourcing/view/application.go | 8 +- .../eventsourcing/handler/application.go | 2 +- .../eventsourcing/handler/user_grant.go | 2 +- internal/eventstore/query/handler.go | 2 +- internal/eventstore/spooler/mock/spooler.go | 8 +- internal/eventstore/spooler/spooler.go | 2 +- internal/eventstore/spooler/spooler_test.go | 2 +- internal/key/model/key_view.go | 10 +- internal/key/repository/view/key.go | 22 ++-- .../key/repository/view/model/key_query.go | 10 +- .../eventsourcing/eventstore/org.go | 4 +- .../eventsourcing/eventstore/project.go | 2 +- .../eventsourcing/handler/application.go | 2 +- .../repository/eventsourcing/handler/org.go | 2 +- .../eventsourcing/handler/org_domain.go | 2 +- .../eventsourcing/handler/org_member.go | 2 +- .../eventsourcing/handler/project.go | 2 +- .../eventsourcing/handler/project_grant.go | 2 +- .../handler/project_grant_member.go | 2 +- .../eventsourcing/handler/project_member.go | 2 +- .../eventsourcing/handler/project_role.go | 2 +- .../repository/eventsourcing/handler/user.go | 2 +- .../eventsourcing/handler/user_grant.go | 2 +- internal/model/search_method.go | 22 ++-- .../eventsourcing/handler/notification.go | 6 +- .../eventsourcing/handler/notify_user.go | 2 +- internal/org/model/domain_view.go | 10 +- internal/org/model/org.go | 8 +- internal/org/model/org_iam_policy.go | 4 +- internal/org/model/org_member_view.go | 14 +-- internal/org/model/org_view.go | 12 +-- .../org/repository/eventsourcing/model/org.go | 4 +- .../eventsourcing/model/org_test.go | 14 +-- internal/org/repository/eventsourcing/org.go | 4 +- .../org/repository/eventsourcing/org_test.go | 8 +- internal/org/repository/view/model/org.go | 6 +- .../repository/view/model/org_domain_query.go | 10 +- .../repository/view/model/org_member_query.go | 14 +-- .../org/repository/view/model/org_query.go | 12 +-- .../org/repository/view/org_domain_view.go | 16 +-- .../org/repository/view/org_member_view.go | 8 +- internal/org/repository/view/org_view.go | 4 +- internal/policy/model/types.go | 7 +- .../eventsourcing/policy_age_test.go | 8 +- .../eventsourcing/policy_complexity_test.go | 8 +- .../eventsourcing/policy_lockout_test.go | 8 +- internal/project/model/application.go | 14 +-- internal/project/model/application_test.go | 54 +++++----- internal/project/model/application_view.go | 16 +-- internal/project/model/oidc_config.go | 32 +++--- internal/project/model/project.go | 10 +- internal/project/model/project_grant.go | 8 +- .../model/project_grant_member_view.go | 14 +-- internal/project/model/project_grant_view.go | 20 ++-- internal/project/model/project_member_view.go | 16 +-- internal/project/model/project_role_view.go | 16 +-- internal/project/model/project_view.go | 10 +- .../repository/eventsourcing/eventstore.go | 8 +- .../eventsourcing/eventstore_mock_test.go | 4 +- .../eventsourcing/eventstore_test.go | 98 ++++++++--------- .../eventsourcing/model/application_test.go | 12 +-- .../eventsourcing/model/oidc_config.go | 2 +- .../repository/eventsourcing/model/project.go | 16 +-- .../eventsourcing/model/project_grant_test.go | 8 +- .../eventsourcing/model/project_test.go | 16 +-- .../repository/eventsourcing/project_test.go | 100 +++++++++--------- .../repository/view/application_view.go | 10 +- .../repository/view/model/application.go | 4 +- .../view/model/application_query.go | 14 +-- .../repository/view/model/application_test.go | 22 ++-- .../project/repository/view/model/project.go | 6 +- .../repository/view/model/project_grant.go | 6 +- .../view/model/project_grant_member_query.go | 14 +-- .../view/model/project_grant_query.go | 14 +-- .../view/model/project_grant_test.go | 14 +-- .../view/model/project_member_query.go | 14 +-- .../repository/view/model/project_query.go | 8 +- .../view/model/project_role_query.go | 10 +- .../repository/view/model/project_test.go | 14 +-- .../view/project_grant_member_view.go | 6 +- .../repository/view/project_grant_view.go | 14 +-- .../repository/view/project_member_view.go | 6 +- .../repository/view/project_role_view.go | 16 +-- .../project/repository/view/project_view.go | 6 +- internal/token/model/token.go | 14 +-- .../repository/view/model/token_query.go | 14 +-- internal/token/repository/view/token.go | 12 +-- internal/user/model/mfa.go | 16 +-- internal/user/model/notify_user.go | 4 +- internal/user/model/password.go | 4 +- internal/user/model/user.go | 32 +++--- internal/user/model/user_session_view.go | 10 +- internal/user/model/user_view.go | 28 ++--- .../eventsourcing/eventstore_test.go | 16 +-- .../repository/eventsourcing/model/mfa.go | 4 +- .../eventsourcing/model/mfa_test.go | 4 +- .../eventsourcing/model/profile_test.go | 16 +-- .../repository/eventsourcing/model/user.go | 12 +-- .../eventsourcing/model/user_test.go | 8 +- internal/user/repository/view/model/user.go | 20 ++-- .../user/repository/view/model/user_query.go | 22 ++-- .../view/model/user_session_query.go | 10 +- .../user/repository/view/model/user_test.go | 70 ++++++------ internal/user/repository/view/notify_user.go | 4 +- .../user/repository/view/user_session_view.go | 18 ++-- internal/user/repository/view/user_view.go | 24 ++--- internal/usergrant/model/user_grant.go | 10 +- internal/usergrant/model/user_grant_view.go | 18 ++-- .../repository/eventsourcing/eventstore.go | 2 +- .../eventsourcing/eventstore_test.go | 4 +- .../eventsourcing/model/user_grant.go | 6 +- .../eventsourcing/model/user_grant_test.go | 12 +-- .../repository/eventsourcing/user_grant.go | 2 +- .../repository/view/model/user_grant.go | 6 +- .../repository/view/model/user_grant_query.go | 16 +-- .../repository/view/model/user_grant_test.go | 14 +-- .../repository/view/user_grant_view.go | 24 ++--- internal/view/failed_events.go | 14 +-- internal/view/query.go | 22 ++-- internal/view/query_test.go | 4 +- internal/view/requests_test.go | 18 ++-- internal/view/sequence.go | 8 +- pkg/admin/api/grpc/org_converter.go | 38 +++---- pkg/auth/api/grpc/search_converter.go | 14 +-- pkg/auth/api/grpc/user_converter.go | 28 ++--- pkg/auth/api/grpc/user_grant_converter.go | 12 +-- pkg/auth/api/oidc/client.go | 8 +- pkg/auth/api/oidc/client_converter.go | 6 +- .../api/grpc/application_converter.go | 72 ++++++------- pkg/management/api/grpc/org_converter.go | 8 +- .../api/grpc/org_member_converter.go | 22 ++-- pkg/management/api/grpc/project_converter.go | 18 ++-- .../api/grpc/project_grant_converter.go | 18 ++-- .../grpc/project_grant_member_converter.go | 10 +- .../api/grpc/project_member_converter.go | 10 +- pkg/management/api/grpc/search_converter.go | 20 ++-- pkg/management/api/grpc/user_converter.go | 56 +++++----- .../api/grpc/user_grant_converter.go | 14 +-- 152 files changed, 1026 insertions(+), 1024 deletions(-) diff --git a/internal/admin/repository/eventsourcing/eventstore/org.go b/internal/admin/repository/eventsourcing/eventstore/org.go index 10dc33e06a..ce3ee097ab 100644 --- a/internal/admin/repository/eventsourcing/eventstore/org.go +++ b/internal/admin/repository/eventsourcing/eventstore/org.go @@ -2,7 +2,6 @@ package eventstore import ( "context" - "github.com/caos/zitadel/internal/org/repository/view/model" admin_model "github.com/caos/zitadel/internal/admin/model" admin_view "github.com/caos/zitadel/internal/admin/repository/eventsourcing/view" @@ -10,13 +9,14 @@ import ( "github.com/caos/zitadel/internal/eventstore/sdk" org_model "github.com/caos/zitadel/internal/org/model" org_es "github.com/caos/zitadel/internal/org/repository/eventsourcing" + "github.com/caos/zitadel/internal/org/repository/view/model" + policy_model "github.com/caos/zitadel/internal/policy/model" policy_es "github.com/caos/zitadel/internal/policy/repository/eventsourcing" usr_es "github.com/caos/zitadel/internal/user/repository/eventsourcing" ) const ( - DEFAULT_POLICY = "0" - orgOwnerRole = "ORG_OWNER" + orgOwnerRole = "ORG_OWNER" ) type OrgRepo struct { @@ -31,11 +31,11 @@ type OrgRepo struct { } func (repo *OrgRepo) SetUpOrg(ctx context.Context, setUp *admin_model.SetupOrg) (*admin_model.SetupOrg, error) { - pwPolicy, err := repo.PolicyEventstore.GetPasswordComplexityPolicy(ctx, DEFAULT_POLICY) + pwPolicy, err := repo.PolicyEventstore.GetPasswordComplexityPolicy(ctx, policy_model.DefaultPolicy) if err != nil { return nil, err } - orgPolicy, err := repo.OrgEventstore.GetOrgIamPolicy(ctx, DEFAULT_POLICY) + orgPolicy, err := repo.OrgEventstore.GetOrgIamPolicy(ctx, policy_model.DefaultPolicy) if err != nil { return nil, err } diff --git a/internal/admin/repository/eventsourcing/handler/org.go b/internal/admin/repository/eventsourcing/handler/org.go index f61156358c..0427739ddb 100644 --- a/internal/admin/repository/eventsourcing/handler/org.go +++ b/internal/admin/repository/eventsourcing/handler/org.go @@ -33,7 +33,7 @@ func (o *Org) EventQuery() (*es_models.SearchQuery, error) { return eventsourcing.OrgQuery(sequence), nil } -func (o *Org) Process(event *es_models.Event) error { +func (o *Org) Reduce(event *es_models.Event) error { org := new(org_model.OrgView) switch event.Type { diff --git a/internal/admin/repository/eventsourcing/setup/setup.go b/internal/admin/repository/eventsourcing/setup/setup.go index d820de9657..b1569ace6d 100644 --- a/internal/admin/repository/eventsourcing/setup/setup.go +++ b/internal/admin/repository/eventsourcing/setup/setup.go @@ -45,21 +45,20 @@ type initializer struct { } const ( - OrgOwnerRole = "ORG_OWNER" - SETUP_USER = "SETUP" - OIDCResponseType_CODE = "CODE" - OIDCResponseType_ID_TOKEN = "ID_TOKEN" - OIDCResponseType_TOKEN = "TOKEN" - OIDCGrantType_AUTHORIZATION_CODE = "AUTHORIZATION_CODE" - OIDCGrantType_IMPLICIT = "IMPLICIT" - OIDCGrantType_REFRESH_TOKEN = "REFRESH_TOKEN" - OIDCApplicationType_NATIVE = "NATIVE" - OIDCApplicationType_USER_AGENT = "USER_AGENT" - OIDCApplicationType_WEB = "WEB" - OIDCAuthMethodType_NONE = "NONE" - OIDCAuthMethodType_BASIC = "BASIC" - OIDCAuthMethodType_POST = "POST" - DEFAULT_POLICY = "0" + OrgOwnerRole = "ORG_OWNER" + SetupUser = "SETUP" + OIDCResponseTypeCode = "CODE" + OIDCResponseTypeIDToken = "ID_TOKEN" + OIDCResponseTypeToken = "TOKEN" + OIDCGrantTypeAuthorizationCode = "AUTHORIZATION_CODE" + OIDCGrantTypeImplicit = "IMPLICIT" + OIDCGrantTypeRefreshToken = "REFRESH_TOKEN" + OIDCApplicationTypeNative = "NATIVE" + OIDCApplicationTypeUserAgent = "USER_AGENT" + OIDCApplicationTypeWeb = "WEB" + OIDCAuthMethodTypeNone = "NONE" + OIDCAuthMethodTypeBasic = "BASIC" + OIDCAuthMethodTypePost = "POST" ) func StartSetup(sd systemdefaults.SystemDefaults, repos EventstoreRepos) *Setup { @@ -97,7 +96,7 @@ func (s *Setup) Execute(ctx context.Context) error { createdProjects: make(map[string]*proj_model.Project), } - pwComplexityPolicy, err := s.repos.PolicyEvents.GetPasswordComplexityPolicy(ctx, DEFAULT_POLICY) + pwComplexityPolicy, err := s.repos.PolicyEvents.GetPasswordComplexityPolicy(ctx, policy_model.DefaultPolicy) if err != nil { logging.Log("SETUP-9osWF").WithError(err).Error("unable to read complexity policy") return err @@ -175,7 +174,7 @@ func (setUp *initializer) orgs(ctx context.Context, orgs []types.Org) error { return err } } else { - policy, err = setUp.repos.OrgEvents.GetOrgIamPolicy(ctx, DEFAULT_POLICY) + policy, err = setUp.repos.OrgEvents.GetOrgIamPolicy(ctx, policy_model.DefaultPolicy) if err != nil { logging.LogWithFields("SETUP-IS8wS", "Org Iam Policy", iamOrg.Name).WithError(err).Error("unable to get default iam org policy") return err @@ -380,14 +379,14 @@ func getOIDCResponseTypes(responseTypes []string) []proj_model.OIDCResponseType func getOIDCResponseType(responseType string) proj_model.OIDCResponseType { switch responseType { - case OIDCResponseType_CODE: - return proj_model.OIDCRESPONSETYPE_CODE - case OIDCResponseType_ID_TOKEN: - return proj_model.OIDCRESPONSETYPE_ID_TOKEN - case OIDCResponseType_TOKEN: - return proj_model.OIDCRESPONSETYPE_TOKEN + case OIDCResponseTypeCode: + return proj_model.OIDCResponseTypeCode + case OIDCResponseTypeIDToken: + return proj_model.OIDCResponseTypeIDToken + case OIDCResponseTypeToken: + return proj_model.OIDCResponseTypeToken } - return proj_model.OIDCRESPONSETYPE_CODE + return proj_model.OIDCResponseTypeCode } func getOIDCGrantTypes(grantTypes []string) []proj_model.OIDCGrantType { @@ -400,40 +399,40 @@ func getOIDCGrantTypes(grantTypes []string) []proj_model.OIDCGrantType { func getOIDCGrantType(grantTypes string) proj_model.OIDCGrantType { switch grantTypes { - case OIDCGrantType_AUTHORIZATION_CODE: - return proj_model.OIDCGRANTTYPE_AUTHORIZATION_CODE - case OIDCGrantType_IMPLICIT: - return proj_model.OIDCGRANTTYPE_IMPLICIT - case OIDCGrantType_REFRESH_TOKEN: - return proj_model.OIDCGRANTTYPE_REFRESH_TOKEN + case OIDCGrantTypeAuthorizationCode: + return proj_model.OIDCGrantTypeAuthorizationCode + case OIDCGrantTypeImplicit: + return proj_model.OIDCGrantTypeImplicit + case OIDCGrantTypeRefreshToken: + return proj_model.OIDCGrantTypeRefreshToken } - return proj_model.OIDCGRANTTYPE_AUTHORIZATION_CODE + return proj_model.OIDCGrantTypeAuthorizationCode } func getOIDCApplicationType(appType string) proj_model.OIDCApplicationType { switch appType { - case OIDCApplicationType_NATIVE: - return proj_model.OIDCAPPLICATIONTYPE_NATIVE - case OIDCApplicationType_USER_AGENT: - return proj_model.OIDCAPPLICATIONTYPE_USER_AGENT - case OIDCApplicationType_WEB: - return proj_model.OIDCAPPLICATIONTYPE_WEB + case OIDCApplicationTypeNative: + return proj_model.OIDCApplicationTypeNative + case OIDCApplicationTypeUserAgent: + return proj_model.OIDCApplicationTypeUserAgent + case OIDCApplicationTypeWeb: + return proj_model.OIDCApplicationTypeWeb } - return proj_model.OIDCAPPLICATIONTYPE_WEB + return proj_model.OIDCApplicationTypeWeb } func getOIDCAuthMethod(authMethod string) proj_model.OIDCAuthMethodType { switch authMethod { - case OIDCAuthMethodType_NONE: - return proj_model.OIDCAUTHMETHODTYPE_NONE - case OIDCAuthMethodType_BASIC: - return proj_model.OIDCAUTHMETHODTYPE_BASIC - case OIDCAuthMethodType_POST: - return proj_model.OIDCAUTHMETHODTYPE_POST + case OIDCAuthMethodTypeNone: + return proj_model.OIDCAuthMethodTypeNone + case OIDCAuthMethodTypeBasic: + return proj_model.OIDCAuthMethodTypeBasic + case OIDCAuthMethodTypePost: + return proj_model.OIDCAuthMethodTypePost } - return proj_model.OIDCAUTHMETHODTYPE_NONE + return proj_model.OIDCAuthMethodTypeNone } func setSetUpContextData(ctx context.Context, orgID string) context.Context { - return auth.SetCtxData(ctx, auth.CtxData{UserID: SETUP_USER, OrgID: orgID}) + return auth.SetCtxData(ctx, auth.CtxData{UserID: SetupUser, OrgID: orgID}) } diff --git a/internal/auth/repository/eventsourcing/eventstore/auth_request.go b/internal/auth/repository/eventsourcing/eventstore/auth_request.go index 1ffa718b77..d520ca8580 100644 --- a/internal/auth/repository/eventsourcing/eventstore/auth_request.go +++ b/internal/auth/repository/eventsourcing/eventstore/auth_request.go @@ -350,17 +350,17 @@ func activeUserByID(ctx context.Context, userViewProvider userViewProvider, user if err != nil { return nil, err } - if user.State == user_model.USERSTATE_LOCKED || user.State == user_model.USERSTATE_SUSPEND { + if user.State == user_model.UserStateLocked || user.State == user_model.UserStateSuspend { return nil, errors.ThrowPreconditionFailed(nil, "EVENT-FJ262", "Errors.User.Locked") } - if !(user.State == user_model.USERSTATE_ACTIVE || user.State == user_model.USERSTATE_INITIAL) { + if !(user.State == user_model.UserStateActive || user.State == user_model.UserStateInitial) { return nil, errors.ThrowPreconditionFailed(nil, "EVENT-FJ262", "Errors.User.NotActive") } org, err := orgViewProvider.OrgByID(user.ResourceOwner) if err != nil { return nil, err } - if org.State != int32(org_model.ORGSTATE_ACTIVE) { + if org.State != int32(org_model.OrgStateActive) { return nil, errors.ThrowPreconditionFailed(nil, "EVENT-Zws3s", "Errors.User.NotActive") } return user, nil diff --git a/internal/auth/repository/eventsourcing/eventstore/auth_request_test.go b/internal/auth/repository/eventsourcing/eventstore/auth_request_test.go index 72ed9a4789..45ee40a5c7 100644 --- a/internal/auth/repository/eventsourcing/eventstore/auth_request_test.go +++ b/internal/auth/repository/eventsourcing/eventstore/auth_request_test.go @@ -113,7 +113,7 @@ func (m *mockViewUser) UserByID(string) (*user_view_model.UserView, error) { OTPState: m.OTPState, MfaMaxSetUp: m.MfaMaxSetUp, MfaInitSkipped: m.MfaInitSkipped, - State: int32(user_model.USERSTATE_ACTIVE), + State: int32(user_model.UserStateActive), }, nil } @@ -242,7 +242,7 @@ func TestAuthRequestRepo_nextSteps(t *testing.T) { Type: user_es_model.UserDeactivated, }, }, - orgViewProvider: &mockViewOrg{State: org_model.ORGSTATE_ACTIVE}, + orgViewProvider: &mockViewOrg{State: org_model.OrgStateActive}, }, args{&model.AuthRequest{UserID: "UserID"}, false}, nil, @@ -264,7 +264,7 @@ func TestAuthRequestRepo_nextSteps(t *testing.T) { fields{ userViewProvider: &mockViewUser{}, userEventProvider: &mockEventUser{}, - orgViewProvider: &mockViewOrg{State: org_model.ORGSTATE_INACTIVE}, + orgViewProvider: &mockViewOrg{State: org_model.OrgStateInactive}, }, args{&model.AuthRequest{UserID: "UserID"}, false}, nil, @@ -278,7 +278,7 @@ func TestAuthRequestRepo_nextSteps(t *testing.T) { PasswordSet: true, }, userEventProvider: &mockEventUser{}, - orgViewProvider: &mockViewOrg{State: org_model.ORGSTATE_ACTIVE}, + orgViewProvider: &mockViewOrg{State: org_model.OrgStateActive}, }, args{&model.AuthRequest{UserID: "UserID"}, false}, []model.NextStep{&model.PasswordStep{}}, @@ -290,7 +290,7 @@ func TestAuthRequestRepo_nextSteps(t *testing.T) { userSessionViewProvider: &mockViewErrUserSession{}, userViewProvider: &mockViewUser{}, userEventProvider: &mockEventUser{}, - orgViewProvider: &mockViewOrg{State: org_model.ORGSTATE_ACTIVE}, + orgViewProvider: &mockViewOrg{State: org_model.OrgStateActive}, }, args{&model.AuthRequest{UserID: "UserID"}, false}, nil, @@ -305,7 +305,7 @@ func TestAuthRequestRepo_nextSteps(t *testing.T) { PasswordSet: true, }, userEventProvider: &mockEventUser{}, - orgViewProvider: &mockViewOrg{State: org_model.ORGSTATE_ACTIVE}, + orgViewProvider: &mockViewOrg{State: org_model.OrgStateActive}, }, args{&model.AuthRequest{UserID: "UserID"}, false}, []model.NextStep{&model.InitUserStep{ @@ -319,7 +319,7 @@ func TestAuthRequestRepo_nextSteps(t *testing.T) { userSessionViewProvider: &mockViewUserSession{}, userViewProvider: &mockViewUser{}, userEventProvider: &mockEventUser{}, - orgViewProvider: &mockViewOrg{State: org_model.ORGSTATE_ACTIVE}, + orgViewProvider: &mockViewOrg{State: org_model.OrgStateActive}, }, args{&model.AuthRequest{UserID: "UserID"}, false}, []model.NextStep{&model.InitPasswordStep{}}, @@ -333,7 +333,7 @@ func TestAuthRequestRepo_nextSteps(t *testing.T) { PasswordSet: true, }, userEventProvider: &mockEventUser{}, - orgViewProvider: &mockViewOrg{State: org_model.ORGSTATE_ACTIVE}, + orgViewProvider: &mockViewOrg{State: org_model.OrgStateActive}, PasswordCheckLifeTime: 10 * 24 * time.Hour, }, args{&model.AuthRequest{UserID: "UserID"}, false}, @@ -348,11 +348,11 @@ func TestAuthRequestRepo_nextSteps(t *testing.T) { }, userViewProvider: &mockViewUser{ PasswordSet: true, - OTPState: int32(user_model.MFASTATE_READY), + OTPState: int32(user_model.MfaStateReady), MfaMaxSetUp: int32(model.MfaLevelSoftware), }, userEventProvider: &mockEventUser{}, - orgViewProvider: &mockViewOrg{State: org_model.ORGSTATE_ACTIVE}, + orgViewProvider: &mockViewOrg{State: org_model.OrgStateActive}, PasswordCheckLifeTime: 10 * 24 * time.Hour, MfaSoftwareCheckLifeTime: 18 * time.Hour, }, @@ -376,7 +376,7 @@ func TestAuthRequestRepo_nextSteps(t *testing.T) { MfaMaxSetUp: int32(model.MfaLevelSoftware), }, userEventProvider: &mockEventUser{}, - orgViewProvider: &mockViewOrg{State: org_model.ORGSTATE_ACTIVE}, + orgViewProvider: &mockViewOrg{State: org_model.OrgStateActive}, PasswordCheckLifeTime: 10 * 24 * time.Hour, MfaSoftwareCheckLifeTime: 18 * time.Hour, }, @@ -396,7 +396,7 @@ func TestAuthRequestRepo_nextSteps(t *testing.T) { MfaMaxSetUp: int32(model.MfaLevelSoftware), }, userEventProvider: &mockEventUser{}, - orgViewProvider: &mockViewOrg{State: org_model.ORGSTATE_ACTIVE}, + orgViewProvider: &mockViewOrg{State: org_model.OrgStateActive}, PasswordCheckLifeTime: 10 * 24 * time.Hour, MfaSoftwareCheckLifeTime: 18 * time.Hour, }, @@ -417,7 +417,7 @@ func TestAuthRequestRepo_nextSteps(t *testing.T) { MfaMaxSetUp: int32(model.MfaLevelSoftware), }, userEventProvider: &mockEventUser{}, - orgViewProvider: &mockViewOrg{State: org_model.ORGSTATE_ACTIVE}, + orgViewProvider: &mockViewOrg{State: org_model.OrgStateActive}, PasswordCheckLifeTime: 10 * 24 * time.Hour, MfaSoftwareCheckLifeTime: 18 * time.Hour, }, @@ -438,7 +438,7 @@ func TestAuthRequestRepo_nextSteps(t *testing.T) { MfaMaxSetUp: int32(model.MfaLevelSoftware), }, userEventProvider: &mockEventUser{}, - orgViewProvider: &mockViewOrg{State: org_model.ORGSTATE_ACTIVE}, + orgViewProvider: &mockViewOrg{State: org_model.OrgStateActive}, PasswordCheckLifeTime: 10 * 24 * time.Hour, MfaSoftwareCheckLifeTime: 18 * time.Hour, }, @@ -459,7 +459,7 @@ func TestAuthRequestRepo_nextSteps(t *testing.T) { MfaMaxSetUp: int32(model.MfaLevelSoftware), }, userEventProvider: &mockEventUser{}, - orgViewProvider: &mockViewOrg{State: org_model.ORGSTATE_ACTIVE}, + orgViewProvider: &mockViewOrg{State: org_model.OrgStateActive}, PasswordCheckLifeTime: 10 * 24 * time.Hour, MfaSoftwareCheckLifeTime: 18 * time.Hour, }, @@ -517,7 +517,7 @@ func TestAuthRequestRepo_mfaChecked(t *testing.T) { // args{ // request: &model.AuthRequest{PossibleLOAs: []model.LevelOfAssurance{}}, // user: &user_model.UserView{ - // OTPState: user_model.MFASTATE_READY, + // OTPState: user_model.MfaStateReady, // }, // }, // false, @@ -564,7 +564,7 @@ func TestAuthRequestRepo_mfaChecked(t *testing.T) { request: &model.AuthRequest{}, user: &user_model.UserView{ MfaMaxSetUp: model.MfaLevelSoftware, - OTPState: user_model.MFASTATE_READY, + OTPState: user_model.MfaStateReady, }, userSession: &user_model.UserSessionView{MfaSoftwareVerification: time.Now().UTC().Add(-5 * time.Hour)}, }, @@ -580,7 +580,7 @@ func TestAuthRequestRepo_mfaChecked(t *testing.T) { request: &model.AuthRequest{}, user: &user_model.UserView{ MfaMaxSetUp: model.MfaLevelSoftware, - OTPState: user_model.MFASTATE_READY, + OTPState: user_model.MfaStateReady, }, userSession: &user_model.UserSessionView{}, }, @@ -851,7 +851,7 @@ func Test_userByID(t *testing.T) { }, &user_model.UserView{ PasswordChangeRequired: true, - State: user_model.USERSTATE_ACTIVE, + State: user_model.UserStateActive, }, nil, }, @@ -872,7 +872,7 @@ func Test_userByID(t *testing.T) { }, &user_model.UserView{ PasswordChangeRequired: true, - State: user_model.USERSTATE_ACTIVE, + State: user_model.UserStateActive, }, nil, }, @@ -897,7 +897,7 @@ func Test_userByID(t *testing.T) { &user_model.UserView{ PasswordChangeRequired: false, ChangeDate: time.Now().UTC().Round(1 * time.Second), - State: user_model.USERSTATE_ACTIVE, + State: user_model.UserStateActive, PasswordChanged: time.Now().UTC().Round(1 * time.Second), }, nil, diff --git a/internal/auth/repository/eventsourcing/eventstore/user.go b/internal/auth/repository/eventsourcing/eventstore/user.go index f8f1aa1139..ae55f3e0a0 100644 --- a/internal/auth/repository/eventsourcing/eventstore/user.go +++ b/internal/auth/repository/eventsourcing/eventstore/user.go @@ -212,7 +212,7 @@ func (repo *UserRepo) RequestPasswordReset(ctx context.Context, loginname string if err != nil { return err } - return repo.UserEvents.RequestSetPassword(ctx, user.ID, model.NOTIFICATIONTYPE_EMAIL) + return repo.UserEvents.RequestSetPassword(ctx, user.ID, model.NotificationTypeEmail) } func (repo *UserRepo) SetPassword(ctx context.Context, userID, code, password string) error { diff --git a/internal/auth/repository/eventsourcing/eventstore/user_grant.go b/internal/auth/repository/eventsourcing/eventstore/user_grant.go index 93b79f5b9a..c388ace528 100644 --- a/internal/auth/repository/eventsourcing/eventstore/user_grant.go +++ b/internal/auth/repository/eventsourcing/eventstore/user_grant.go @@ -23,7 +23,7 @@ type UserGrantRepo struct { func (repo *UserGrantRepo) SearchMyUserGrants(ctx context.Context, request *grant_model.UserGrantSearchRequest) (*grant_model.UserGrantSearchResponse, error) { request.EnsureLimit(repo.SearchLimit) - request.Queries = append(request.Queries, &grant_model.UserGrantSearchQuery{Key: grant_model.USERGRANTSEARCHKEY_USER_ID, Method: global_model.SEARCHMETHOD_EQUALS, Value: auth.GetCtxData(ctx).UserID}) + request.Queries = append(request.Queries, &grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyUserID, Method: global_model.SearchMethodEquals, Value: auth.GetCtxData(ctx).UserID}) grants, count, err := repo.View.SearchUserGrants(request) if err != nil { return nil, err @@ -55,7 +55,7 @@ func (repo *UserGrantRepo) SearchMyProjectOrgs(ctx context.Context, request *gra return repo.SearchAdminOrgs(request) } } - request.Queries = append(request.Queries, &grant_model.UserGrantSearchQuery{Key: grant_model.USERGRANTSEARCHKEY_PROJECT_ID, Method: global_model.SEARCHMETHOD_EQUALS, Value: ctxData.ProjectID}) + request.Queries = append(request.Queries, &grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyProjectID, Method: global_model.SearchMethodEquals, Value: ctxData.ProjectID}) grants, err := repo.SearchMyUserGrants(ctx, request) if err != nil { @@ -98,8 +98,8 @@ func (repo *UserGrantRepo) SearchAdminOrgs(request *grant_model.UserGrantSearchR searchRequest := &org_model.OrgSearchRequest{} if len(request.Queries) > 0 { for _, q := range request.Queries { - if q.Key == grant_model.USERGRANTSEARCHKEY_ORG_NAME { - searchRequest.Queries = append(searchRequest.Queries, &org_model.OrgSearchQuery{Key: org_model.ORGSEARCHKEY_ORG_NAME, Method: q.Method, Value: q.Value}) + if q.Key == grant_model.UserGrantSearchKeyOrgName { + searchRequest.Queries = append(searchRequest.Queries, &org_model.OrgSearchQuery{Key: org_model.OrgSearchKeyOrgName, Method: q.Method, Value: q.Value}) } } } @@ -113,7 +113,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{ - &grant_model.UserGrantSearchQuery{Key: grant_model.USERGRANTSEARCHKEY_RESOURCEOWNER, Method: global_model.SEARCHMETHOD_EQUALS, Value: repo.IamID}, + &grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyResourceOwner, Method: global_model.SearchMethodEquals, Value: repo.IamID}, }} result, err := repo.SearchMyUserGrants(ctx, grantSearch) if err != nil { diff --git a/internal/auth/repository/eventsourcing/handler/application.go b/internal/auth/repository/eventsourcing/handler/application.go index 43b7704340..06a069cda6 100644 --- a/internal/auth/repository/eventsourcing/handler/application.go +++ b/internal/auth/repository/eventsourcing/handler/application.go @@ -34,7 +34,7 @@ func (p *Application) EventQuery() (*models.SearchQuery, error) { return eventsourcing.ProjectQuery(sequence), nil } -func (p *Application) Process(event *models.Event) (err error) { +func (p *Application) Reduce(event *models.Event) (err error) { app := new(view_model.ApplicationView) switch event.Type { case es_model.ApplicationAdded: diff --git a/internal/auth/repository/eventsourcing/handler/key.go b/internal/auth/repository/eventsourcing/handler/key.go index 46824e8438..cb4f66c603 100644 --- a/internal/auth/repository/eventsourcing/handler/key.go +++ b/internal/auth/repository/eventsourcing/handler/key.go @@ -35,7 +35,7 @@ func (k *Key) EventQuery() (*models.SearchQuery, error) { return eventsourcing.KeyPairQuery(sequence), nil } -func (k *Key) Process(event *models.Event) error { +func (k *Key) Reduce(event *models.Event) error { switch event.Type { case es_model.KeyPairAdded: privateKey, publicKey, err := view_model.KeysFromPairEvent(event) diff --git a/internal/auth/repository/eventsourcing/handler/org.go b/internal/auth/repository/eventsourcing/handler/org.go index effc8d6a4d..3f0e679fb6 100644 --- a/internal/auth/repository/eventsourcing/handler/org.go +++ b/internal/auth/repository/eventsourcing/handler/org.go @@ -32,7 +32,7 @@ func (o *Org) EventQuery() (*es_models.SearchQuery, error) { return eventsourcing.OrgQuery(sequence), nil } -func (o *Org) Process(event *es_models.Event) error { +func (o *Org) Reduce(event *es_models.Event) error { org := new(org_model.OrgView) switch event.Type { diff --git a/internal/auth/repository/eventsourcing/handler/token.go b/internal/auth/repository/eventsourcing/handler/token.go index 2bb193c7fd..fe8d0885d3 100644 --- a/internal/auth/repository/eventsourcing/handler/token.go +++ b/internal/auth/repository/eventsourcing/handler/token.go @@ -44,7 +44,7 @@ func (u *Token) EventQuery() (*models.SearchQuery, error) { LatestSequenceFilter(sequence), nil } -func (u *Token) Process(event *models.Event) (err error) { +func (u *Token) Reduce(event *models.Event) (err error) { switch event.Type { case user_es_model.SignedOut: id, err := agentIDFromSession(event) diff --git a/internal/auth/repository/eventsourcing/handler/user.go b/internal/auth/repository/eventsourcing/handler/user.go index 3344bf5be9..dd0d587c2a 100644 --- a/internal/auth/repository/eventsourcing/handler/user.go +++ b/internal/auth/repository/eventsourcing/handler/user.go @@ -43,7 +43,7 @@ func (p *User) EventQuery() (*models.SearchQuery, error) { LatestSequenceFilter(sequence), nil } -func (u *User) Process(event *models.Event) (err error) { +func (u *User) Reduce(event *models.Event) (err error) { switch event.AggregateType { case es_model.UserAggregate: return u.ProcessUser(event) diff --git a/internal/auth/repository/eventsourcing/handler/user_grant.go b/internal/auth/repository/eventsourcing/handler/user_grant.go index 119ec3acfc..92eb36c55f 100644 --- a/internal/auth/repository/eventsourcing/handler/user_grant.go +++ b/internal/auth/repository/eventsourcing/handler/user_grant.go @@ -63,7 +63,7 @@ func (u *UserGrant) EventQuery() (*models.SearchQuery, error) { LatestSequenceFilter(sequence), nil } -func (u *UserGrant) Process(event *models.Event) (err error) { +func (u *UserGrant) Reduce(event *models.Event) (err error) { switch event.AggregateType { case grant_es_model.UserGrantAggregate: err = u.processUserGrant(event) diff --git a/internal/auth/repository/eventsourcing/handler/user_session.go b/internal/auth/repository/eventsourcing/handler/user_session.go index e8bca1cd57..df88874b28 100644 --- a/internal/auth/repository/eventsourcing/handler/user_session.go +++ b/internal/auth/repository/eventsourcing/handler/user_session.go @@ -39,7 +39,7 @@ func (u *UserSession) EventQuery() (*models.SearchQuery, error) { return eventsourcing.UserQuery(sequence), nil } -func (u *UserSession) Process(event *models.Event) (err error) { +func (u *UserSession) Reduce(event *models.Event) (err error) { var session *view_model.UserSessionView switch event.Type { case es_model.UserPasswordCheckSucceeded, diff --git a/internal/auth/repository/eventsourcing/view/application.go b/internal/auth/repository/eventsourcing/view/application.go index 60b7f89570..75cf45e1f4 100644 --- a/internal/auth/repository/eventsourcing/view/application.go +++ b/internal/auth/repository/eventsourcing/view/application.go @@ -60,8 +60,8 @@ func (v *View) ApplicationByClientID(_ context.Context, clientID string) (*model Limit: 1, Queries: []*proj_model.ApplicationSearchQuery{ { - Key: proj_model.APPLICATIONSEARCHKEY_OIDC_CLIENT_ID, - Method: global_model.SEARCHMETHOD_EQUALS, + Key: proj_model.AppSearchKeyOIDCClientID, + Method: global_model.SearchMethodEquals, Value: clientID, }, }, @@ -84,8 +84,8 @@ func (v *View) AppIDsFromProjectByClientID(ctx context.Context, clientID string) req := &proj_model.ApplicationSearchRequest{ Queries: []*proj_model.ApplicationSearchQuery{ { - Key: proj_model.APPLICATIONSEARCHKEY_PROJECT_ID, - Method: global_model.SEARCHMETHOD_EQUALS, + Key: proj_model.AppSearchKeyProjectID, + Method: global_model.SearchMethodEquals, Value: app.ProjectID, }, }, diff --git a/internal/authz/repository/eventsourcing/handler/application.go b/internal/authz/repository/eventsourcing/handler/application.go index ea8708b9ef..8138efc717 100644 --- a/internal/authz/repository/eventsourcing/handler/application.go +++ b/internal/authz/repository/eventsourcing/handler/application.go @@ -32,7 +32,7 @@ func (p *Application) EventQuery() (*models.SearchQuery, error) { return eventsourcing.ProjectQuery(sequence), nil } -func (p *Application) Process(event *models.Event) (err error) { +func (p *Application) Reduce(event *models.Event) (err error) { app := new(view_model.ApplicationView) switch event.Type { case es_model.ApplicationAdded: diff --git a/internal/authz/repository/eventsourcing/handler/user_grant.go b/internal/authz/repository/eventsourcing/handler/user_grant.go index b9a353f88e..3ee646740c 100644 --- a/internal/authz/repository/eventsourcing/handler/user_grant.go +++ b/internal/authz/repository/eventsourcing/handler/user_grant.go @@ -52,7 +52,7 @@ func (u *UserGrant) EventQuery() (*models.SearchQuery, error) { LatestSequenceFilter(sequence), nil } -func (u *UserGrant) Process(event *models.Event) (err error) { +func (u *UserGrant) Reduce(event *models.Event) (err error) { switch event.AggregateType { case proj_es_model.ProjectAggregate: err = u.processProject(event) diff --git a/internal/eventstore/query/handler.go b/internal/eventstore/query/handler.go index b874ebbd6d..cea58baf84 100755 --- a/internal/eventstore/query/handler.go +++ b/internal/eventstore/query/handler.go @@ -7,6 +7,6 @@ import ( type Handler interface { ViewModel() string EventQuery() (*models.SearchQuery, error) - Process(*models.Event) error + Reduce(*models.Event) error OnError(event *models.Event, err error) error } diff --git a/internal/eventstore/spooler/mock/spooler.go b/internal/eventstore/spooler/mock/spooler.go index f0a6224b4a..4e49d6ba65 100644 --- a/internal/eventstore/spooler/mock/spooler.go +++ b/internal/eventstore/spooler/mock/spooler.go @@ -63,18 +63,18 @@ func (mr *MockHandlerMockRecorder) EventQuery() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EventQuery", reflect.TypeOf((*MockHandler)(nil).EventQuery)) } -// Process mocks base method +// Reduce mocks base method func (m *MockHandler) Process(arg0 *models.Event) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Process", arg0) + ret := m.ctrl.Call(m, "Reduce", arg0) ret0, _ := ret[0].(error) return ret0 } -// Process indicates an expected call of Process +// Reduce indicates an expected call of Reduce func (mr *MockHandlerMockRecorder) Process(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Process", reflect.TypeOf((*MockHandler)(nil).Process), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Reduce", reflect.TypeOf((*MockHandler)(nil).Process), arg0) } // MinimumCycleDuration mocks base method diff --git a/internal/eventstore/spooler/spooler.go b/internal/eventstore/spooler/spooler.go index 91b41c4e8f..51bfacab55 100644 --- a/internal/eventstore/spooler/spooler.go +++ b/internal/eventstore/spooler/spooler.go @@ -95,7 +95,7 @@ func (s *spooledHandler) process(ctx context.Context, events []*models.Event) er logging.Log("SPOOL-FTKwH").WithField("view", s.ViewModel()).Debug("context canceled") return nil default: - if err := s.Process(event); err != nil { + if err := s.Reduce(event); err != nil { return s.OnError(event, err) } } diff --git a/internal/eventstore/spooler/spooler_test.go b/internal/eventstore/spooler/spooler_test.go index 55774009bc..962b9e3cd9 100644 --- a/internal/eventstore/spooler/spooler_test.go +++ b/internal/eventstore/spooler/spooler_test.go @@ -26,7 +26,7 @@ func (h *testHandler) ViewModel() string { func (h *testHandler) EventQuery() (*models.SearchQuery, error) { return nil, h.queryError } -func (h *testHandler) Process(*models.Event) error { +func (h *testHandler) Reduce(*models.Event) error { <-time.After(h.processSleep) return h.processError } diff --git a/internal/key/model/key_view.go b/internal/key/model/key_view.go index 545f986158..ac8507f8de 100644 --- a/internal/key/model/key_view.go +++ b/internal/key/model/key_view.go @@ -42,11 +42,11 @@ type KeySearchRequest struct { type KeySearchKey int32 const ( - KEYSEARCHKEY_UNSPECIFIED KeySearchKey = iota - KEYSEARCHKEY_ID - KEYSEARCHKEY_PRIVATE - KEYSEARCHKEY_EXPIRY - KEYSEARCHKEY_USAGE + KeySearchKeyUnspecified KeySearchKey = iota + KeySearchKeyID + KeySearchKeyPrivate + KeySearchKeyExpiry + KeySearchKeyUsage ) type KeySearchQuery struct { diff --git a/internal/key/repository/view/key.go b/internal/key/repository/view/key.go index 482ddf9370..b9439c2460 100644 --- a/internal/key/repository/view/key.go +++ b/internal/key/repository/view/key.go @@ -14,8 +14,8 @@ import ( func KeyByIDAndType(db *gorm.DB, table, keyID string, private bool) (*model.KeyView, error) { key := new(model.KeyView) query := view.PrepareGetByQuery(table, - model.KeySearchQuery{Key: key_model.KEYSEARCHKEY_ID, Method: global_model.SEARCHMETHOD_EQUALS, Value: keyID}, - model.KeySearchQuery{Key: key_model.KEYSEARCHKEY_PRIVATE, Method: global_model.SEARCHMETHOD_EQUALS, Value: private}, + model.KeySearchQuery{Key: key_model.KeySearchKeyID, Method: global_model.SearchMethodEquals, Value: keyID}, + model.KeySearchQuery{Key: key_model.KeySearchKeyPrivate, Method: global_model.SearchMethodEquals, Value: private}, ) err := query(db, key) return key, err @@ -24,9 +24,9 @@ func KeyByIDAndType(db *gorm.DB, table, keyID string, private bool) (*model.KeyV func GetSigningKey(db *gorm.DB, table string) (*model.KeyView, error) { key := new(model.KeyView) query := view.PrepareGetByQuery(table, - model.KeySearchQuery{Key: key_model.KEYSEARCHKEY_PRIVATE, Method: global_model.SEARCHMETHOD_EQUALS, Value: true}, - model.KeySearchQuery{Key: key_model.KEYSEARCHKEY_USAGE, Method: global_model.SEARCHMETHOD_EQUALS, Value: key_model.KeyUsageSigning}, - model.KeySearchQuery{Key: key_model.KEYSEARCHKEY_EXPIRY, Method: global_model.SEARCHMETHOD_GREATER_THAN, Value: time.Now().UTC()}, + model.KeySearchQuery{Key: key_model.KeySearchKeyPrivate, Method: global_model.SearchMethodEquals, Value: true}, + model.KeySearchQuery{Key: key_model.KeySearchKeyUsage, Method: global_model.SearchMethodEquals, Value: key_model.KeyUsageSigning}, + model.KeySearchQuery{Key: key_model.KeySearchKeyExpiry, Method: global_model.SearchMethodGreaterThan, Value: time.Now().UTC()}, ) err := query(db, key) return key, err @@ -37,9 +37,9 @@ func GetActivePublicKeys(db *gorm.DB, table string) ([]*model.KeyView, error) { query := view.PrepareSearchQuery(table, model.KeySearchRequest{ Queries: []*key_model.KeySearchQuery{ - {Key: key_model.KEYSEARCHKEY_PRIVATE, Method: global_model.SEARCHMETHOD_EQUALS, Value: false}, - {Key: key_model.KEYSEARCHKEY_USAGE, Method: global_model.SEARCHMETHOD_EQUALS, Value: key_model.KeyUsageSigning}, - {Key: key_model.KEYSEARCHKEY_EXPIRY, Method: global_model.SEARCHMETHOD_GREATER_THAN, Value: time.Now().UTC()}, + {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()}, }, }, ) @@ -58,13 +58,13 @@ func PutKeys(db *gorm.DB, table string, privateKey, publicKey *model.KeyView) er func DeleteKey(db *gorm.DB, table, keyID string, private bool) error { delete := view.PrepareDeleteByKeys(table, - view.Key{Key: model.KeySearchKey(key_model.KEYSEARCHKEY_ID), Value: keyID}, - view.Key{Key: model.KeySearchKey(key_model.KEYSEARCHKEY_PRIVATE), Value: private}, + view.Key{Key: model.KeySearchKey(key_model.KeySearchKeyID), Value: keyID}, + view.Key{Key: model.KeySearchKey(key_model.KeySearchKeyPrivate), Value: private}, ) return delete(db) } func DeleteKeyPair(db *gorm.DB, table, keyID string) error { - delete := view.PrepareDeleteByKey(table, model.KeySearchKey(key_model.KEYSEARCHKEY_ID), keyID) + delete := view.PrepareDeleteByKey(table, model.KeySearchKey(key_model.KeySearchKeyID), keyID) return delete(db) } diff --git a/internal/key/repository/view/model/key_query.go b/internal/key/repository/view/model/key_query.go index 68764231e5..8af86159ef 100644 --- a/internal/key/repository/view/model/key_query.go +++ b/internal/key/repository/view/model/key_query.go @@ -19,7 +19,7 @@ func (req KeySearchRequest) GetOffset() uint64 { } func (req KeySearchRequest) GetSortingColumn() view.ColumnKey { - if req.SortingColumn == key_model.KEYSEARCHKEY_UNSPECIFIED { + if req.SortingColumn == key_model.KeySearchKeyUnspecified { return nil } return KeySearchKey(req.SortingColumn) @@ -51,13 +51,13 @@ func (req KeySearchQuery) GetValue() interface{} { func (key KeySearchKey) ToColumnName() string { switch key_model.KeySearchKey(key) { - case key_model.KEYSEARCHKEY_ID: + case key_model.KeySearchKeyID: return KeyKeyID - case key_model.KEYSEARCHKEY_PRIVATE: + case key_model.KeySearchKeyPrivate: return KeyPrivate - case key_model.KEYSEARCHKEY_USAGE: + case key_model.KeySearchKeyUsage: return KeyUsage - case key_model.KEYSEARCHKEY_EXPIRY: + case key_model.KeySearchKeyExpiry: return KeyExpiry default: return "" diff --git a/internal/management/repository/eventsourcing/eventstore/org.go b/internal/management/repository/eventsourcing/eventstore/org.go index 25eb2ba872..ea29ae692a 100644 --- a/internal/management/repository/eventsourcing/eventstore/org.go +++ b/internal/management/repository/eventsourcing/eventstore/org.go @@ -54,7 +54,7 @@ func (repo *OrgRepository) GetMyOrgIamPolicy(ctx context.Context) (*org_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.ORGDOMAINSEARCHKEY_ORG_ID, Method: global_model.SEARCHMETHOD_EQUALS, Value: auth.GetCtxData(ctx).OrgID}) + request.Queries = append(request.Queries, &org_model.OrgDomainSearchQuery{Key: org_model.OrgDomainSearchKeyOrgID, Method: global_model.SearchMethodEquals, Value: auth.GetCtxData(ctx).OrgID}) domains, count, err := repo.View.SearchOrgDomains(request) if err != nil { return nil, err @@ -110,7 +110,7 @@ func (repo *OrgRepository) RemoveMyOrgMember(ctx context.Context, userID string) 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.ORGMEMBERSEARCHKEY_ORG_ID, Method: global_model.SEARCHMETHOD_EQUALS, Value: auth.GetCtxData(ctx).OrgID} + request.Queries[len(request.Queries)-1] = &org_model.OrgMemberSearchQuery{Key: org_model.OrgMemberSearchKeyOrgID, Method: global_model.SearchMethodEquals, Value: auth.GetCtxData(ctx).OrgID} members, count, err := repo.View.SearchOrgMembers(request) if err != nil { return nil, err diff --git a/internal/management/repository/eventsourcing/eventstore/project.go b/internal/management/repository/eventsourcing/eventstore/project.go index 2a6a7c231f..49f7d59dae 100644 --- a/internal/management/repository/eventsourcing/eventstore/project.go +++ b/internal/management/repository/eventsourcing/eventstore/project.go @@ -62,7 +62,7 @@ func (repo *ProjectRepo) SearchProjects(ctx context.Context, request *proj_model permissions := auth.GetPermissionsFromCtx(ctx) if !auth.HasGlobalPermission(permissions) { ids := auth.GetPermissionCtxIDs(permissions) - request.Queries = append(request.Queries, &proj_model.ProjectViewSearchQuery{Key: proj_model.PROJECTSEARCHKEY_PROJECTID, Method: global_model.SEARCHMETHOD_IS_ONE_OF, Value: ids}) + request.Queries = append(request.Queries, &proj_model.ProjectViewSearchQuery{Key: proj_model.ProjectViewSearchKeyProjectID, Method: global_model.SearchMethodIsOneOf, Value: ids}) } projects, count, err := repo.View.SearchProjects(request) diff --git a/internal/management/repository/eventsourcing/handler/application.go b/internal/management/repository/eventsourcing/handler/application.go index adf5b6cb1f..f6895b90f1 100644 --- a/internal/management/repository/eventsourcing/handler/application.go +++ b/internal/management/repository/eventsourcing/handler/application.go @@ -34,7 +34,7 @@ func (p *Application) EventQuery() (*models.SearchQuery, error) { return eventsourcing.ProjectQuery(sequence), nil } -func (p *Application) Process(event *models.Event) (err error) { +func (p *Application) Reduce(event *models.Event) (err error) { app := new(view_model.ApplicationView) switch event.Type { case es_model.ApplicationAdded: diff --git a/internal/management/repository/eventsourcing/handler/org.go b/internal/management/repository/eventsourcing/handler/org.go index ca90a92857..9d8da51c65 100644 --- a/internal/management/repository/eventsourcing/handler/org.go +++ b/internal/management/repository/eventsourcing/handler/org.go @@ -33,7 +33,7 @@ func (o *Org) EventQuery() (*es_models.SearchQuery, error) { return eventsourcing.OrgQuery(sequence), nil } -func (o *Org) Process(event *es_models.Event) error { +func (o *Org) Reduce(event *es_models.Event) error { org := new(org_model.OrgView) switch event.Type { diff --git a/internal/management/repository/eventsourcing/handler/org_domain.go b/internal/management/repository/eventsourcing/handler/org_domain.go index 35760d02f7..11b96502a6 100644 --- a/internal/management/repository/eventsourcing/handler/org_domain.go +++ b/internal/management/repository/eventsourcing/handler/org_domain.go @@ -35,7 +35,7 @@ func (d *OrgDomain) EventQuery() (*models.SearchQuery, error) { LatestSequenceFilter(sequence), nil } -func (d *OrgDomain) Process(event *models.Event) (err error) { +func (d *OrgDomain) Reduce(event *models.Event) (err error) { switch event.AggregateType { case model.OrgAggregate: err = d.processOrgDomain(event) diff --git a/internal/management/repository/eventsourcing/handler/org_member.go b/internal/management/repository/eventsourcing/handler/org_member.go index 1e39fdb660..00fa95a887 100644 --- a/internal/management/repository/eventsourcing/handler/org_member.go +++ b/internal/management/repository/eventsourcing/handler/org_member.go @@ -40,7 +40,7 @@ func (m *OrgMember) EventQuery() (*models.SearchQuery, error) { LatestSequenceFilter(sequence), nil } -func (m *OrgMember) Process(event *models.Event) (err error) { +func (m *OrgMember) Reduce(event *models.Event) (err error) { switch event.AggregateType { case model.OrgAggregate: err = m.processOrgMember(event) diff --git a/internal/management/repository/eventsourcing/handler/project.go b/internal/management/repository/eventsourcing/handler/project.go index aee979230b..b27d002e15 100644 --- a/internal/management/repository/eventsourcing/handler/project.go +++ b/internal/management/repository/eventsourcing/handler/project.go @@ -36,7 +36,7 @@ func (p *Project) EventQuery() (*models.SearchQuery, error) { return proj_event.ProjectQuery(sequence), nil } -func (p *Project) Process(event *models.Event) (err error) { +func (p *Project) Reduce(event *models.Event) (err error) { project := new(view_model.ProjectView) switch event.Type { case es_model.ProjectAdded: diff --git a/internal/management/repository/eventsourcing/handler/project_grant.go b/internal/management/repository/eventsourcing/handler/project_grant.go index ab9c926fff..fa8e75ec13 100644 --- a/internal/management/repository/eventsourcing/handler/project_grant.go +++ b/internal/management/repository/eventsourcing/handler/project_grant.go @@ -42,7 +42,7 @@ func (p *ProjectGrant) EventQuery() (*models.SearchQuery, error) { return proj_event.ProjectQuery(sequence), nil } -func (p *ProjectGrant) Process(event *models.Event) (err error) { +func (p *ProjectGrant) Reduce(event *models.Event) (err error) { grantedProject := new(view_model.ProjectGrantView) switch event.Type { case es_model.ProjectChanged: diff --git a/internal/management/repository/eventsourcing/handler/project_grant_member.go b/internal/management/repository/eventsourcing/handler/project_grant_member.go index 4ce1999307..5d2a5fdf21 100644 --- a/internal/management/repository/eventsourcing/handler/project_grant_member.go +++ b/internal/management/repository/eventsourcing/handler/project_grant_member.go @@ -39,7 +39,7 @@ func (p *ProjectGrantMember) EventQuery() (*models.SearchQuery, error) { LatestSequenceFilter(sequence), nil } -func (p *ProjectGrantMember) Process(event *models.Event) (err error) { +func (p *ProjectGrantMember) Reduce(event *models.Event) (err error) { switch event.AggregateType { case proj_es_model.ProjectAggregate: err = p.processProjectGrantMember(event) diff --git a/internal/management/repository/eventsourcing/handler/project_member.go b/internal/management/repository/eventsourcing/handler/project_member.go index 5e3fa3b90a..f9de43f4cc 100644 --- a/internal/management/repository/eventsourcing/handler/project_member.go +++ b/internal/management/repository/eventsourcing/handler/project_member.go @@ -39,7 +39,7 @@ func (p *ProjectMember) EventQuery() (*models.SearchQuery, error) { LatestSequenceFilter(sequence), nil } -func (p *ProjectMember) Process(event *models.Event) (err error) { +func (p *ProjectMember) Reduce(event *models.Event) (err error) { switch event.AggregateType { case proj_es_model.ProjectAggregate: err = p.processProjectMember(event) diff --git a/internal/management/repository/eventsourcing/handler/project_role.go b/internal/management/repository/eventsourcing/handler/project_role.go index 401d002d37..5d1bb1cde1 100644 --- a/internal/management/repository/eventsourcing/handler/project_role.go +++ b/internal/management/repository/eventsourcing/handler/project_role.go @@ -36,7 +36,7 @@ func (p *ProjectRole) EventQuery() (*models.SearchQuery, error) { return eventsourcing.ProjectQuery(sequence), nil } -func (p *ProjectRole) Process(event *models.Event) (err error) { +func (p *ProjectRole) Reduce(event *models.Event) (err error) { role := new(view_model.ProjectRoleView) switch event.Type { case es_model.ProjectRoleAdded: diff --git a/internal/management/repository/eventsourcing/handler/user.go b/internal/management/repository/eventsourcing/handler/user.go index 21a978b783..5aa769313b 100644 --- a/internal/management/repository/eventsourcing/handler/user.go +++ b/internal/management/repository/eventsourcing/handler/user.go @@ -43,7 +43,7 @@ func (p *User) EventQuery() (*models.SearchQuery, error) { LatestSequenceFilter(sequence), nil } -func (u *User) Process(event *models.Event) (err error) { +func (u *User) Reduce(event *models.Event) (err error) { switch event.AggregateType { case es_model.UserAggregate: return u.ProcessUser(event) diff --git a/internal/management/repository/eventsourcing/handler/user_grant.go b/internal/management/repository/eventsourcing/handler/user_grant.go index d7b14984d4..837b52fc99 100644 --- a/internal/management/repository/eventsourcing/handler/user_grant.go +++ b/internal/management/repository/eventsourcing/handler/user_grant.go @@ -51,7 +51,7 @@ func (u *UserGrant) EventQuery() (*models.SearchQuery, error) { LatestSequenceFilter(sequence), nil } -func (u *UserGrant) Process(event *models.Event) (err error) { +func (u *UserGrant) Reduce(event *models.Event) (err error) { switch event.AggregateType { case grant_es_model.UserGrantAggregate: err = u.processUserGrant(event) diff --git a/internal/model/search_method.go b/internal/model/search_method.go index 92c74fccbd..c22f259792 100644 --- a/internal/model/search_method.go +++ b/internal/model/search_method.go @@ -3,15 +3,15 @@ package model type SearchMethod int32 const ( - SEARCHMETHOD_EQUALS SearchMethod = iota - SEARCHMETHOD_STARTS_WITH - SEARCHMETHOD_CONTAINS - SEARCHMETHOD_EQUALS_IGNORE_CASE - SEARCHMETHOD_STARTS_WITH_IGNORE_CASE - SEARCHMETHOD_CONTAINS_IGNORE_CASE - SEARCHMETHOD_NOT_EQUALS - SEARCHMETHOD_GREATER_THAN - SEARCHMETHOD_LESS_THAN - SEARCHMETHOD_IS_ONE_OF - SEARCHMETHOD_LIST_CONTAINS + SearchMethodEquals SearchMethod = iota + SearchMethodStartsWith + SearchMethodContains + SearchMethodEqualsIgnoreCase + SearchMethodStartsWithIgnoreCase + SearchMethodContainsIgnoreCase + SearchMethodNotEquals + SearchMethodGreaterThan + SearchMethodLessThan + SearchMethodIsOneOf + SearchMethodListContains ) diff --git a/internal/notification/repository/eventsourcing/handler/notification.go b/internal/notification/repository/eventsourcing/handler/notification.go index dade8b6ce8..e722a88260 100644 --- a/internal/notification/repository/eventsourcing/handler/notification.go +++ b/internal/notification/repository/eventsourcing/handler/notification.go @@ -32,7 +32,7 @@ type Notification struct { const ( notificationTable = "notification.notifications" - NOTIFY_USER = "NOTIFICATION" + NotifyUserID = "NOTIFICATION" ) func (n *Notification) MinimumCycleDuration() time.Duration { return n.cycleDuration } @@ -49,7 +49,7 @@ func (n *Notification) EventQuery() (*models.SearchQuery, error) { return eventsourcing.UserQuery(sequence), nil } -func (n *Notification) Process(event *models.Event) (err error) { +func (n *Notification) Reduce(event *models.Event) (err error) { switch event.Type { case es_model.InitializedUserCodeAdded: err = n.handleInitUserCode(event) @@ -168,5 +168,5 @@ func (n *Notification) OnError(event *models.Event, err error) error { } func getSetNotifyContextData(orgID string) context.Context { - return auth.SetCtxData(context.Background(), auth.CtxData{UserID: NOTIFY_USER, OrgID: orgID}) + return auth.SetCtxData(context.Background(), auth.CtxData{UserID: NotifyUserID, OrgID: orgID}) } diff --git a/internal/notification/repository/eventsourcing/handler/notify_user.go b/internal/notification/repository/eventsourcing/handler/notify_user.go index b99de4efd3..a74aaf8c4d 100644 --- a/internal/notification/repository/eventsourcing/handler/notify_user.go +++ b/internal/notification/repository/eventsourcing/handler/notify_user.go @@ -36,7 +36,7 @@ func (p *NotifyUser) EventQuery() (*models.SearchQuery, error) { return eventsourcing.UserQuery(sequence), nil } -func (p *NotifyUser) Process(event *models.Event) (err error) { +func (p *NotifyUser) Reduce(event *models.Event) (err error) { user := new(view_model.NotifyUser) switch event.Type { case es_model.UserAdded, diff --git a/internal/org/model/domain_view.go b/internal/org/model/domain_view.go index 02aad1a39c..e2c3ed3bc6 100644 --- a/internal/org/model/domain_view.go +++ b/internal/org/model/domain_view.go @@ -25,11 +25,11 @@ type OrgDomainSearchRequest struct { type OrgDomainSearchKey int32 const ( - ORGDOMAINSEARCHKEY_UNSPECIFIED OrgDomainSearchKey = iota - ORGDOMAINSEARCHKEY_DOMAIN - ORGDOMAINSEARCHKEY_ORG_ID - ORGDOMAINSEARCHKEY_VERIFIED - ORGDOMAINSEARCHKEY_PRIMARY + OrgDomainSearchKeyUnspecified OrgDomainSearchKey = iota + OrgDomainSearchKeyDomain + OrgDomainSearchKeyOrgID + OrgDomainSearchKeyVerified + OrgDomainSearchKeyPrimary ) type OrgDomainSearchQuery struct { diff --git a/internal/org/model/org.go b/internal/org/model/org.go index 8564f4e7b0..1d8e0e0ea6 100644 --- a/internal/org/model/org.go +++ b/internal/org/model/org.go @@ -32,16 +32,16 @@ type OrgChange struct { type OrgState int32 const ( - ORGSTATE_ACTIVE OrgState = iota - ORGSTATE_INACTIVE + OrgStateActive OrgState = iota + OrgStateInactive ) func NewOrg(id string) *Org { - return &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: id}, State: ORGSTATE_ACTIVE} + return &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: id}, State: OrgStateActive} } func (o *Org) IsActive() bool { - return o.State == ORGSTATE_ACTIVE + return o.State == OrgStateActive } func (o *Org) IsValid() bool { diff --git a/internal/org/model/org_iam_policy.go b/internal/org/model/org_iam_policy.go index cca3943575..827fdbbf36 100644 --- a/internal/org/model/org_iam_policy.go +++ b/internal/org/model/org_iam_policy.go @@ -16,6 +16,6 @@ type OrgIamPolicy struct { type PolicyState int32 const ( - POLICYSTATE_ACTIVE PolicyState = iota - POLICYSTATE_REMOVED + PolicyStateActive PolicyState = iota + PolicyStateRemoved ) diff --git a/internal/org/model/org_member_view.go b/internal/org/model/org_member_view.go index 873b08c581..1c5f4f16ba 100644 --- a/internal/org/model/org_member_view.go +++ b/internal/org/model/org_member_view.go @@ -30,13 +30,13 @@ type OrgMemberSearchRequest struct { type OrgMemberSearchKey int32 const ( - ORGMEMBERSEARCHKEY_UNSPECIFIED OrgMemberSearchKey = iota - ORGMEMBERSEARCHKEY_USER_NAME - ORGMEMBERSEARCHKEY_EMAIL - ORGMEMBERSEARCHKEY_FIRST_NAME - ORGMEMBERSEARCHKEY_LAST_NAME - ORGMEMBERSEARCHKEY_ORG_ID - ORGMEMBERSEARCHKEY_USER_ID + OrgMemberSearchKeyUnspecified OrgMemberSearchKey = iota + OrgMemberSearchKeyUserName + OrgMemberSearchKeyEmail + OrgMemberSearchKeyFirstName + OrgMemberSearchKeyLastName + OrgMemberSearchKeyOrgID + OrgMemberSearchKeyUserID ) type OrgMemberSearchQuery struct { diff --git a/internal/org/model/org_view.go b/internal/org/model/org_view.go index 507abac6d5..e433e087ad 100644 --- a/internal/org/model/org_view.go +++ b/internal/org/model/org_view.go @@ -29,12 +29,12 @@ type OrgSearchRequest struct { type OrgSearchKey int32 const ( - ORGSEARCHKEY_UNSPECIFIED OrgSearchKey = iota - ORGSEARCHKEY_ORG_ID - ORGSEARCHKEY_ORG_NAME - ORGSEARCHKEY_ORG_DOMAIN - ORGSEARCHKEY_STATE - ORGSEARCHKEY_RESOURCEOWNER + OrgSearchKeyUnspecified OrgSearchKey = iota + OrgSearchKeyOrgID + OrgSearchKeyOrgName + OrgSearchKeyOrgDomain + OrgSearchKeyState + OrgSearchKeyResourceOwner ) type OrgSearchQuery struct { diff --git a/internal/org/repository/eventsourcing/model/org.go b/internal/org/repository/eventsourcing/model/org.go index 1f8593d7d4..6837765bae 100644 --- a/internal/org/repository/eventsourcing/model/org.go +++ b/internal/org/repository/eventsourcing/model/org.go @@ -84,9 +84,9 @@ func (o *Org) AppendEvent(event *es_models.Event) error { return err } case OrgDeactivated: - o.State = int32(org_model.ORGSTATE_INACTIVE) + o.State = int32(org_model.OrgStateInactive) case OrgReactivated: - o.State = int32(org_model.ORGSTATE_ACTIVE) + o.State = int32(org_model.OrgStateActive) case OrgMemberAdded: member, err := OrgMemberFromEvent(nil, event) if err != nil { diff --git a/internal/org/repository/eventsourcing/model/org_test.go b/internal/org/repository/eventsourcing/model/org_test.go index ea0a2c3b17..96ad8c628e 100644 --- a/internal/org/repository/eventsourcing/model/org_test.go +++ b/internal/org/repository/eventsourcing/model/org_test.go @@ -26,7 +26,7 @@ func TestOrgFromEvents(t *testing.T) { }, org: &Org{Name: "OrgName"}, }, - result: &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, State: int32(model.ORGSTATE_ACTIVE), Name: "OrgName"}, + result: &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, State: int32(model.OrgStateActive), Name: "OrgName"}, }, { name: "org from events, nil org", @@ -36,7 +36,7 @@ func TestOrgFromEvents(t *testing.T) { }, org: nil, }, - result: &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, State: int32(model.ORGSTATE_ACTIVE)}, + result: &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, State: int32(model.OrgStateActive)}, }, } for _, tt := range tests { @@ -69,7 +69,7 @@ func TestAppendEvent(t *testing.T) { event: &es_models.Event{AggregateID: "ID", Sequence: 1, Type: OrgAdded}, org: &Org{Name: "OrgName"}, }, - result: &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, State: int32(model.ORGSTATE_ACTIVE), Name: "OrgName"}, + result: &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, State: int32(model.OrgStateActive), Name: "OrgName"}, }, { name: "append change event", @@ -77,28 +77,28 @@ func TestAppendEvent(t *testing.T) { event: &es_models.Event{AggregateID: "ID", Sequence: 1, Type: OrgChanged, Data: []byte(`{"name": "OrgName}`)}, org: &Org{Name: "OrgNameChanged"}, }, - result: &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, State: int32(model.ORGSTATE_ACTIVE), Name: "OrgNameChanged"}, + result: &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, State: int32(model.OrgStateActive), Name: "OrgNameChanged"}, }, { name: "append deactivate event", args: args{ event: &es_models.Event{AggregateID: "ID", Sequence: 1, Type: OrgDeactivated}, }, - result: &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, State: int32(model.ORGSTATE_INACTIVE)}, + result: &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, State: int32(model.OrgStateInactive)}, }, { name: "append reactivate event", args: args{ event: &es_models.Event{AggregateID: "ID", Sequence: 1, Type: OrgReactivated}, }, - result: &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, State: int32(model.ORGSTATE_ACTIVE)}, + result: &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, State: int32(model.OrgStateActive)}, }, { name: "append added domain event", args: args{ event: &es_models.Event{AggregateID: "ID", Sequence: 1, Type: OrgDomainAdded}, }, - result: &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, State: int32(model.ORGSTATE_ACTIVE)}, + result: &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, State: int32(model.OrgStateActive)}, }, } for _, tt := range tests { diff --git a/internal/org/repository/eventsourcing/org.go b/internal/org/repository/eventsourcing/org.go index 9093ee67ba..4fb1c6bb48 100644 --- a/internal/org/repository/eventsourcing/org.go +++ b/internal/org/repository/eventsourcing/org.go @@ -141,7 +141,7 @@ func orgDeactivateAggregate(aggCreator *es_models.AggregateCreator, org *model.O if org == nil { return nil, errors.ThrowPreconditionFailed(nil, "EVENT-R03z8", "Errors.Internal") } - if org.State == int32(org_model.ORGSTATE_INACTIVE) { + if org.State == int32(org_model.OrgStateInactive) { return nil, errors.ThrowInvalidArgument(nil, "EVENT-mcPH0", "Errors.Internal.AlreadyDeactivated") } agg, err := OrgAggregate(ctx, aggCreator, org.AggregateID, org.Sequence) @@ -158,7 +158,7 @@ func orgReactivateAggregate(aggCreator *es_models.AggregateCreator, org *model.O if org == nil { return nil, errors.ThrowPreconditionFailed(nil, "EVENT-cTHLd", "Errors.Internal") } - if org.State == int32(org_model.ORGSTATE_ACTIVE) { + if org.State == int32(org_model.OrgStateActive) { return nil, errors.ThrowInvalidArgument(nil, "EVENT-pUSMs", "Errors.Org.AlreadyActive") } agg, err := OrgAggregate(ctx, aggCreator, org.AggregateID, org.Sequence) diff --git a/internal/org/repository/eventsourcing/org_test.go b/internal/org/repository/eventsourcing/org_test.go index b2f26f3781..58e67f4f76 100644 --- a/internal/org/repository/eventsourcing/org_test.go +++ b/internal/org/repository/eventsourcing/org_test.go @@ -236,7 +236,7 @@ func TestOrgReactivateAggregate(t *testing.T) { AggregateID: "orgID", Sequence: 2, }, - State: int32(org_model.ORGSTATE_INACTIVE), + State: int32(org_model.OrgStateInactive), }, }, }, @@ -250,7 +250,7 @@ func TestOrgReactivateAggregate(t *testing.T) { AggregateID: "orgID", Sequence: 2, }, - State: int32(org_model.ORGSTATE_ACTIVE), + State: int32(org_model.OrgStateActive), }, }, res: res{ @@ -310,7 +310,7 @@ func TestOrgDeactivateAggregate(t *testing.T) { AggregateID: "orgID", Sequence: 2, }, - State: int32(org_model.ORGSTATE_ACTIVE), + State: int32(org_model.OrgStateActive), }, }, }, @@ -324,7 +324,7 @@ func TestOrgDeactivateAggregate(t *testing.T) { AggregateID: "orgID", Sequence: 2, }, - State: int32(org_model.ORGSTATE_INACTIVE), + State: int32(org_model.OrgStateInactive), }, }, res: res{ diff --git a/internal/org/repository/view/model/org.go b/internal/org/repository/view/model/org.go index ac75b3bd42..c9db56f63d 100644 --- a/internal/org/repository/view/model/org.go +++ b/internal/org/repository/view/model/org.go @@ -69,16 +69,16 @@ func (o *OrgView) AppendEvent(event *es_models.Event) (err error) { switch event.Type { case model.OrgAdded: o.CreationDate = event.CreationDate - o.State = int32(org_model.ORGSTATE_ACTIVE) + o.State = int32(org_model.OrgStateActive) o.setRootData(event) err = o.SetData(event) case model.OrgChanged: o.setRootData(event) err = o.SetData(event) case model.OrgDeactivated: - o.State = int32(org_model.ORGSTATE_INACTIVE) + o.State = int32(org_model.OrgStateInactive) case model.OrgReactivated: - o.State = int32(org_model.ORGSTATE_ACTIVE) + o.State = int32(org_model.OrgStateActive) } return err } diff --git a/internal/org/repository/view/model/org_domain_query.go b/internal/org/repository/view/model/org_domain_query.go index 951ddcbc3b..326968bad7 100644 --- a/internal/org/repository/view/model/org_domain_query.go +++ b/internal/org/repository/view/model/org_domain_query.go @@ -19,7 +19,7 @@ func (req OrgDomainSearchRequest) GetOffset() uint64 { } func (req OrgDomainSearchRequest) GetSortingColumn() view.ColumnKey { - if req.SortingColumn == org_model.ORGDOMAINSEARCHKEY_UNSPECIFIED { + if req.SortingColumn == org_model.OrgDomainSearchKeyUnspecified { return nil } return OrgDomainSearchKey(req.SortingColumn) @@ -51,13 +51,13 @@ func (req OrgDomainSearchQuery) GetValue() interface{} { func (key OrgDomainSearchKey) ToColumnName() string { switch org_model.OrgDomainSearchKey(key) { - case org_model.ORGDOMAINSEARCHKEY_DOMAIN: + case org_model.OrgDomainSearchKeyDomain: return OrgDomainKeyDomain - case org_model.ORGDOMAINSEARCHKEY_ORG_ID: + case org_model.OrgDomainSearchKeyOrgID: return OrgDomainKeyOrgID - case org_model.ORGDOMAINSEARCHKEY_VERIFIED: + case org_model.OrgDomainSearchKeyVerified: return OrgDomainKeyVerified - case org_model.ORGDOMAINSEARCHKEY_PRIMARY: + case org_model.OrgDomainSearchKeyPrimary: return OrgDomainKeyPrimary default: return "" diff --git a/internal/org/repository/view/model/org_member_query.go b/internal/org/repository/view/model/org_member_query.go index dd8c2d8163..21e6d62475 100644 --- a/internal/org/repository/view/model/org_member_query.go +++ b/internal/org/repository/view/model/org_member_query.go @@ -19,7 +19,7 @@ func (req OrgMemberSearchRequest) GetOffset() uint64 { } func (req OrgMemberSearchRequest) GetSortingColumn() view.ColumnKey { - if req.SortingColumn == proj_model.ORGMEMBERSEARCHKEY_UNSPECIFIED { + if req.SortingColumn == proj_model.OrgMemberSearchKeyUnspecified { return nil } return OrgMemberSearchKey(req.SortingColumn) @@ -51,17 +51,17 @@ func (req OrgMemberSearchQuery) GetValue() interface{} { func (key OrgMemberSearchKey) ToColumnName() string { switch proj_model.OrgMemberSearchKey(key) { - case proj_model.ORGMEMBERSEARCHKEY_EMAIL: + case proj_model.OrgMemberSearchKeyEmail: return OrgMemberKeyEmail - case proj_model.ORGMEMBERSEARCHKEY_FIRST_NAME: + case proj_model.OrgMemberSearchKeyFirstName: return OrgMemberKeyFirstName - case proj_model.ORGMEMBERSEARCHKEY_LAST_NAME: + case proj_model.OrgMemberSearchKeyLastName: return OrgMemberKeyLastName - case proj_model.ORGMEMBERSEARCHKEY_USER_NAME: + case proj_model.OrgMemberSearchKeyUserName: return OrgMemberKeyUserName - case proj_model.ORGMEMBERSEARCHKEY_USER_ID: + case proj_model.OrgMemberSearchKeyUserID: return OrgMemberKeyUserID - case proj_model.ORGMEMBERSEARCHKEY_ORG_ID: + case proj_model.OrgMemberSearchKeyOrgID: return OrgMemberKeyOrgID default: return "" diff --git a/internal/org/repository/view/model/org_query.go b/internal/org/repository/view/model/org_query.go index 831727538a..3d4696b0f0 100644 --- a/internal/org/repository/view/model/org_query.go +++ b/internal/org/repository/view/model/org_query.go @@ -19,7 +19,7 @@ func (req OrgSearchRequest) GetOffset() uint64 { } func (req OrgSearchRequest) GetSortingColumn() view.ColumnKey { - if req.SortingColumn == usr_model.ORGSEARCHKEY_UNSPECIFIED { + if req.SortingColumn == usr_model.OrgSearchKeyUnspecified { return nil } return OrgSearchKey(req.SortingColumn) @@ -51,15 +51,15 @@ func (req OrgSearchQuery) GetValue() interface{} { func (key OrgSearchKey) ToColumnName() string { switch usr_model.OrgSearchKey(key) { - case usr_model.ORGSEARCHKEY_ORG_DOMAIN: + case usr_model.OrgSearchKeyOrgDomain: return OrgKeyOrgDomain - case usr_model.ORGSEARCHKEY_ORG_ID: + case usr_model.OrgSearchKeyOrgID: return OrgKeyOrgID - case usr_model.ORGSEARCHKEY_ORG_NAME: + case usr_model.OrgSearchKeyOrgName: return OrgKeyOrgName - case usr_model.ORGSEARCHKEY_RESOURCEOWNER: + case usr_model.OrgSearchKeyResourceOwner: return OrgKeyResourceOwner - case usr_model.ORGSEARCHKEY_STATE: + case usr_model.OrgSearchKeyState: return OrgKeyState default: return "" diff --git a/internal/org/repository/view/org_domain_view.go b/internal/org/repository/view/org_domain_view.go index a9b3c39ad4..a790395866 100644 --- a/internal/org/repository/view/org_domain_view.go +++ b/internal/org/repository/view/org_domain_view.go @@ -10,8 +10,8 @@ import ( func OrgDomainByOrgIDAndDomain(db *gorm.DB, table, orgID, domain string) (*model.OrgDomainView, error) { domainView := new(model.OrgDomainView) - orgIDQuery := &model.OrgDomainSearchQuery{Key: org_model.ORGDOMAINSEARCHKEY_ORG_ID, Value: orgID, Method: global_model.SEARCHMETHOD_EQUALS} - domainQuery := &model.OrgDomainSearchQuery{Key: org_model.ORGDOMAINSEARCHKEY_DOMAIN, Value: domain, Method: global_model.SEARCHMETHOD_EQUALS} + 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} query := view.PrepareGetByQuery(table, orgIDQuery, domainQuery) err := query(db, domainView) return domainView, err @@ -19,8 +19,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.ORGDOMAINSEARCHKEY_DOMAIN, Value: domain, Method: global_model.SEARCHMETHOD_EQUALS} - verifiedQuery := &model.OrgDomainSearchQuery{Key: org_model.ORGDOMAINSEARCHKEY_VERIFIED, Value: true, Method: global_model.SEARCHMETHOD_EQUALS} + 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} query := view.PrepareGetByQuery(table, domainQuery, verifiedQuery) err := query(db, domainView) return domainView, err @@ -40,9 +40,9 @@ func OrgDomainsByOrgID(db *gorm.DB, table string, orgID string) ([]*model.OrgDom domains := make([]*model.OrgDomainView, 0) queries := []*org_model.OrgDomainSearchQuery{ { - Key: org_model.ORGDOMAINSEARCHKEY_ORG_ID, + Key: org_model.OrgDomainSearchKeyOrgID, Value: orgID, - Method: global_model.SEARCHMETHOD_EQUALS, + Method: global_model.SearchMethodEquals, }, } query := view.PrepareSearchQuery(table, model.OrgDomainSearchRequest{Queries: queries}) @@ -60,8 +60,8 @@ func PutOrgDomain(db *gorm.DB, table string, role *model.OrgDomainView) error { func DeleteOrgDomain(db *gorm.DB, table, orgID, domain string) error { delete := view.PrepareDeleteByKeys(table, - view.Key{Key: model.OrgDomainSearchKey(org_model.ORGDOMAINSEARCHKEY_DOMAIN), Value: domain}, - view.Key{Key: model.OrgDomainSearchKey(org_model.ORGDOMAINSEARCHKEY_ORG_ID), Value: orgID}, + view.Key{Key: model.OrgDomainSearchKey(org_model.OrgDomainSearchKeyDomain), Value: domain}, + view.Key{Key: model.OrgDomainSearchKey(org_model.OrgDomainSearchKeyOrgID), Value: orgID}, ) return delete(db) } diff --git a/internal/org/repository/view/org_member_view.go b/internal/org/repository/view/org_member_view.go index 427b50f180..7a4b9127dd 100644 --- a/internal/org/repository/view/org_member_view.go +++ b/internal/org/repository/view/org_member_view.go @@ -11,8 +11,8 @@ import ( func OrgMemberByIDs(db *gorm.DB, table, orgID, userID string) (*model.OrgMemberView, error) { member := new(model.OrgMemberView) - orgIDQuery := &model.OrgMemberSearchQuery{Key: org_model.ORGMEMBERSEARCHKEY_ORG_ID, Value: orgID, Method: global_model.SEARCHMETHOD_EQUALS} - userIDQuery := &model.OrgMemberSearchQuery{Key: org_model.ORGMEMBERSEARCHKEY_USER_ID, Value: userID, Method: global_model.SEARCHMETHOD_EQUALS} + 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} query := view.PrepareGetByQuery(table, orgIDQuery, userIDQuery) err := query(db, member) return member, err @@ -31,9 +31,9 @@ func OrgMembersByUserID(db *gorm.DB, table string, userID string) ([]*model.OrgM members := make([]*model.OrgMemberView, 0) queries := []*org_model.OrgMemberSearchQuery{ { - Key: org_model.ORGMEMBERSEARCHKEY_USER_ID, + Key: org_model.OrgMemberSearchKeyUserID, Value: userID, - Method: global_model.SEARCHMETHOD_EQUALS, + Method: global_model.SearchMethodEquals, }, } query := view.PrepareSearchQuery(table, model.OrgMemberSearchRequest{Queries: queries}) diff --git a/internal/org/repository/view/org_view.go b/internal/org/repository/view/org_view.go index d7724484f2..bb42abfedc 100644 --- a/internal/org/repository/view/org_view.go +++ b/internal/org/repository/view/org_view.go @@ -9,7 +9,7 @@ import ( func OrgByID(db *gorm.DB, table, orgID string) (*model.OrgView, error) { org := new(model.OrgView) - query := view.PrepareGetByKey(table, model.OrgSearchKey(org_model.ORGSEARCHKEY_ORG_ID), orgID) + query := view.PrepareGetByKey(table, model.OrgSearchKey(org_model.OrgSearchKeyOrgID), orgID) err := query(db, org) return org, err } @@ -30,6 +30,6 @@ func PutOrg(db *gorm.DB, table string, org *model.OrgView) error { } func DeleteOrg(db *gorm.DB, table, orgID string) error { - delete := view.PrepareDeleteByKey(table, model.OrgSearchKey(org_model.ORGSEARCHKEY_ORG_ID), orgID) + delete := view.PrepareDeleteByKey(table, model.OrgSearchKey(org_model.OrgSearchKeyOrgID), orgID) return delete(db) } diff --git a/internal/policy/model/types.go b/internal/policy/model/types.go index e506394b68..82d66d5eef 100644 --- a/internal/policy/model/types.go +++ b/internal/policy/model/types.go @@ -3,6 +3,9 @@ package model import "github.com/caos/zitadel/internal/eventstore/models" const ( + //default + DefaultPolicy = "0" + // complexity PasswordComplexityPolicyAggregate models.AggregateType = "policy.password.complexity" @@ -25,6 +28,6 @@ const ( type PolicyState int32 const ( - POLICYSTATE_ACTIVE PolicyState = iota - POLICYSTATE_INACTIVE + PolicyStateActive PolicyState = iota + PolicyStateInactive ) diff --git a/internal/policy/repository/eventsourcing/policy_age_test.go b/internal/policy/repository/eventsourcing/policy_age_test.go index 6357e2347e..ea456572ed 100644 --- a/internal/policy/repository/eventsourcing/policy_age_test.go +++ b/internal/policy/repository/eventsourcing/policy_age_test.go @@ -143,7 +143,7 @@ func TestPasswordAgePolicyCreateAggregate(t *testing.T) { name: "policy update aggregate ok", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - new: &PasswordAgePolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "PolicyName", State: int32(policy_model.POLICYSTATE_ACTIVE)}, + new: &PasswordAgePolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "PolicyName", State: int32(policy_model.PolicyStateActive)}, aggCreator: models.NewAggregateCreator("Test"), }, res: res{ @@ -208,8 +208,8 @@ func TestPasswordAgePolicyUpdateAggregate(t *testing.T) { name: "policy update aggregate ok", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &PasswordAgePolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "PolicyName", State: int32(policy_model.POLICYSTATE_ACTIVE)}, - new: &PasswordAgePolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "PolicyName_Changed", State: int32(policy_model.POLICYSTATE_ACTIVE)}, + existing: &PasswordAgePolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "PolicyName", State: int32(policy_model.PolicyStateActive)}, + new: &PasswordAgePolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "PolicyName_Changed", State: int32(policy_model.PolicyStateActive)}, aggCreator: models.NewAggregateCreator("Test"), }, res: res{ @@ -235,7 +235,7 @@ func TestPasswordAgePolicyUpdateAggregate(t *testing.T) { name: "new policy nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &PasswordAgePolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "ProjectName", State: int32(policy_model.POLICYSTATE_ACTIVE)}, + existing: &PasswordAgePolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "ProjectName", State: int32(policy_model.PolicyStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, diff --git a/internal/policy/repository/eventsourcing/policy_complexity_test.go b/internal/policy/repository/eventsourcing/policy_complexity_test.go index 369b90d75f..dd1dde06dc 100644 --- a/internal/policy/repository/eventsourcing/policy_complexity_test.go +++ b/internal/policy/repository/eventsourcing/policy_complexity_test.go @@ -143,7 +143,7 @@ func TestPasswordComplexityPolicyCreateAggregate(t *testing.T) { name: "policy update aggregate ok", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - new: &PasswordComplexityPolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "PolicyName", State: int32(policy_model.POLICYSTATE_ACTIVE)}, + new: &PasswordComplexityPolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "PolicyName", State: int32(policy_model.PolicyStateActive)}, aggCreator: models.NewAggregateCreator("Test"), }, res: res{ @@ -208,8 +208,8 @@ func TestPasswordComplexityPolicyUpdateAggregate(t *testing.T) { name: "policy update aggregate ok", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &PasswordComplexityPolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "PolicyName", State: int32(policy_model.POLICYSTATE_ACTIVE)}, - new: &PasswordComplexityPolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "PolicyName_Changed", State: int32(policy_model.POLICYSTATE_ACTIVE)}, + existing: &PasswordComplexityPolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "PolicyName", State: int32(policy_model.PolicyStateActive)}, + new: &PasswordComplexityPolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "PolicyName_Changed", State: int32(policy_model.PolicyStateActive)}, aggCreator: models.NewAggregateCreator("Test"), }, res: res{ @@ -235,7 +235,7 @@ func TestPasswordComplexityPolicyUpdateAggregate(t *testing.T) { name: "new policy nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &PasswordComplexityPolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "ProjectName", State: int32(policy_model.POLICYSTATE_ACTIVE)}, + existing: &PasswordComplexityPolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "ProjectName", State: int32(policy_model.PolicyStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, diff --git a/internal/policy/repository/eventsourcing/policy_lockout_test.go b/internal/policy/repository/eventsourcing/policy_lockout_test.go index 9d9d19d8f8..542cc8dde3 100644 --- a/internal/policy/repository/eventsourcing/policy_lockout_test.go +++ b/internal/policy/repository/eventsourcing/policy_lockout_test.go @@ -143,7 +143,7 @@ func TestPasswordLockoutPolicyCreateAggregate(t *testing.T) { name: "policy update aggregate ok", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - new: &PasswordLockoutPolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "PolicyName", State: int32(policy_model.POLICYSTATE_ACTIVE)}, + new: &PasswordLockoutPolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "PolicyName", State: int32(policy_model.PolicyStateActive)}, aggCreator: models.NewAggregateCreator("Test"), }, res: res{ @@ -208,8 +208,8 @@ func TestPasswordLockoutPolicyUpdateAggregate(t *testing.T) { name: "policy update aggregate ok", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &PasswordLockoutPolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "PolicyName", State: int32(policy_model.POLICYSTATE_ACTIVE)}, - new: &PasswordLockoutPolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "PolicyName_Changed", State: int32(policy_model.POLICYSTATE_ACTIVE)}, + existing: &PasswordLockoutPolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "PolicyName", State: int32(policy_model.PolicyStateActive)}, + new: &PasswordLockoutPolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "PolicyName_Changed", State: int32(policy_model.PolicyStateActive)}, aggCreator: models.NewAggregateCreator("Test"), }, res: res{ @@ -235,7 +235,7 @@ func TestPasswordLockoutPolicyUpdateAggregate(t *testing.T) { name: "new policy nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &PasswordLockoutPolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "ProjectName", State: int32(policy_model.POLICYSTATE_ACTIVE)}, + existing: &PasswordLockoutPolicy{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Description: "ProjectName", State: int32(policy_model.PolicyStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, diff --git a/internal/project/model/application.go b/internal/project/model/application.go index 63a0cf6c46..46ea70bcc5 100644 --- a/internal/project/model/application.go +++ b/internal/project/model/application.go @@ -30,20 +30,20 @@ type ApplicationChange struct { type AppState int32 const ( - APPSTATE_ACTIVE AppState = iota - APPSTATE_INACTIVE + AppStateActive AppState = iota + AppStateInactive ) type AppType int32 const ( - APPTYPE_UNDEFINED AppType = iota - APPTYPE_OIDC - APPTYPE_SAML + AppTypeUnspecified AppType = iota + AppTypeOIDC + AppTypeSAML ) func NewApplication(projectID, appID string) *Application { - return &Application{ObjectRoot: es_models.ObjectRoot{AggregateID: projectID}, AppID: appID, State: APPSTATE_ACTIVE} + return &Application{ObjectRoot: es_models.ObjectRoot{AggregateID: projectID}, AppID: appID, State: AppStateActive} } func (a *Application) IsValid(includeConfig bool) bool { @@ -53,7 +53,7 @@ func (a *Application) IsValid(includeConfig bool) bool { if !includeConfig { return true } - if a.Type == APPTYPE_OIDC && !a.OIDCConfig.IsValid() { + if a.Type == AppTypeOIDC && !a.OIDCConfig.IsValid() { return false } return true diff --git a/internal/project/model/application_test.go b/internal/project/model/application_test.go index 89635fc5cc..6047a55a25 100644 --- a/internal/project/model/application_test.go +++ b/internal/project/model/application_test.go @@ -21,10 +21,10 @@ func TestApplicationValid(t *testing.T) { ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, AppID: "AppID", Name: "Name", - Type: APPTYPE_OIDC, + Type: AppTypeOIDC, OIDCConfig: &OIDCConfig{ - ResponseTypes: []OIDCResponseType{OIDCRESPONSETYPE_CODE}, - GrantTypes: []OIDCGrantType{OIDCGRANTTYPE_AUTHORIZATION_CODE}, + ResponseTypes: []OIDCResponseType{OIDCResponseTypeCode}, + GrantTypes: []OIDCGrantType{OIDCGrantTypeAuthorizationCode}, }, }, }, @@ -37,10 +37,10 @@ func TestApplicationValid(t *testing.T) { ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, AppID: "AppID", Name: "Name", - Type: APPTYPE_OIDC, + Type: AppTypeOIDC, OIDCConfig: &OIDCConfig{ - ResponseTypes: []OIDCResponseType{OIDCRESPONSETYPE_CODE}, - GrantTypes: []OIDCGrantType{OIDCGRANTTYPE_IMPLICIT}, + ResponseTypes: []OIDCResponseType{OIDCResponseTypeCode}, + GrantTypes: []OIDCGrantType{OIDCGrantTypeImplicit}, }, }, }, @@ -53,10 +53,10 @@ func TestApplicationValid(t *testing.T) { ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, AppID: "AppID", Name: "Name", - Type: APPTYPE_OIDC, + Type: AppTypeOIDC, OIDCConfig: &OIDCConfig{ - ResponseTypes: []OIDCResponseType{OIDCRESPONSETYPE_ID_TOKEN}, - GrantTypes: []OIDCGrantType{OIDCGRANTTYPE_IMPLICIT}, + ResponseTypes: []OIDCResponseType{OIDCResponseTypeIDToken}, + GrantTypes: []OIDCGrantType{OIDCGrantTypeImplicit}, }, }, }, @@ -69,10 +69,10 @@ func TestApplicationValid(t *testing.T) { ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, AppID: "AppID", Name: "Name", - Type: APPTYPE_OIDC, + Type: AppTypeOIDC, OIDCConfig: &OIDCConfig{ - ResponseTypes: []OIDCResponseType{OIDCRESPONSETYPE_ID_TOKEN}, - GrantTypes: []OIDCGrantType{OIDCGRANTTYPE_AUTHORIZATION_CODE}, + ResponseTypes: []OIDCResponseType{OIDCResponseTypeIDToken}, + GrantTypes: []OIDCGrantType{OIDCGrantTypeAuthorizationCode}, }, }, }, @@ -85,10 +85,10 @@ func TestApplicationValid(t *testing.T) { ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, AppID: "AppID", Name: "Name", - Type: APPTYPE_OIDC, + Type: AppTypeOIDC, OIDCConfig: &OIDCConfig{ - ResponseTypes: []OIDCResponseType{OIDCRESPONSETYPE_TOKEN}, - GrantTypes: []OIDCGrantType{OIDCGRANTTYPE_IMPLICIT}, + ResponseTypes: []OIDCResponseType{OIDCResponseTypeToken}, + GrantTypes: []OIDCGrantType{OIDCGrantTypeImplicit}, }, }, }, @@ -101,10 +101,10 @@ func TestApplicationValid(t *testing.T) { ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, AppID: "AppID", Name: "Name", - Type: APPTYPE_OIDC, + Type: AppTypeOIDC, OIDCConfig: &OIDCConfig{ - ResponseTypes: []OIDCResponseType{OIDCRESPONSETYPE_TOKEN}, - GrantTypes: []OIDCGrantType{OIDCGRANTTYPE_AUTHORIZATION_CODE}, + ResponseTypes: []OIDCResponseType{OIDCResponseTypeToken}, + GrantTypes: []OIDCGrantType{OIDCGrantTypeAuthorizationCode}, }, }, }, @@ -117,10 +117,10 @@ func TestApplicationValid(t *testing.T) { ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, AppID: "AppID", Name: "Name", - Type: APPTYPE_OIDC, + Type: AppTypeOIDC, OIDCConfig: &OIDCConfig{ - ResponseTypes: []OIDCResponseType{OIDCRESPONSETYPE_CODE, OIDCRESPONSETYPE_ID_TOKEN}, - GrantTypes: []OIDCGrantType{OIDCGRANTTYPE_AUTHORIZATION_CODE, OIDCGRANTTYPE_IMPLICIT}, + ResponseTypes: []OIDCResponseType{OIDCResponseTypeCode, OIDCResponseTypeIDToken}, + GrantTypes: []OIDCGrantType{OIDCGrantTypeAuthorizationCode, OIDCGrantTypeImplicit}, }, }, }, @@ -133,10 +133,10 @@ func TestApplicationValid(t *testing.T) { ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, AppID: "AppID", Name: "Name", - Type: APPTYPE_OIDC, + Type: AppTypeOIDC, OIDCConfig: &OIDCConfig{ - ResponseTypes: []OIDCResponseType{OIDCRESPONSETYPE_CODE, OIDCRESPONSETYPE_TOKEN}, - GrantTypes: []OIDCGrantType{OIDCGRANTTYPE_AUTHORIZATION_CODE, OIDCGRANTTYPE_IMPLICIT}, + ResponseTypes: []OIDCResponseType{OIDCResponseTypeCode, OIDCResponseTypeToken}, + GrantTypes: []OIDCGrantType{OIDCGrantTypeAuthorizationCode, OIDCGrantTypeImplicit}, }, }, }, @@ -149,10 +149,10 @@ func TestApplicationValid(t *testing.T) { ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, AppID: "AppID", Name: "Name", - Type: APPTYPE_OIDC, + Type: AppTypeOIDC, OIDCConfig: &OIDCConfig{ - ResponseTypes: []OIDCResponseType{OIDCRESPONSETYPE_CODE, OIDCRESPONSETYPE_ID_TOKEN, OIDCRESPONSETYPE_TOKEN}, - GrantTypes: []OIDCGrantType{OIDCGRANTTYPE_AUTHORIZATION_CODE, OIDCGRANTTYPE_IMPLICIT}, + ResponseTypes: []OIDCResponseType{OIDCResponseTypeCode, OIDCResponseTypeIDToken, OIDCResponseTypeToken}, + GrantTypes: []OIDCGrantType{OIDCGrantTypeAuthorizationCode, OIDCGrantTypeImplicit}, }, }, }, diff --git a/internal/project/model/application_view.go b/internal/project/model/application_view.go index 86f0d10555..939b0f8a98 100644 --- a/internal/project/model/application_view.go +++ b/internal/project/model/application_view.go @@ -28,23 +28,23 @@ type ApplicationView struct { type ApplicationSearchRequest struct { Offset uint64 Limit uint64 - SortingColumn ApplicationSearchKey + SortingColumn AppSearchKey Asc bool Queries []*ApplicationSearchQuery } -type ApplicationSearchKey int32 +type AppSearchKey int32 const ( - APPLICATIONSEARCHKEY_UNSPECIFIED ApplicationSearchKey = iota - APPLICATIONSEARCHKEY_NAME - APPLICATIONSEARCHKEY_OIDC_CLIENT_ID - APPLICATIONSEARCHKEY_PROJECT_ID - APPLICATIONSEARCHKEY_APP_ID + AppSearchKeyUnspecified AppSearchKey = iota + AppSearchKeyName + AppSearchKeyOIDCClientID + AppSearchKeyProjectID + AppSearchKeyAppID ) type ApplicationSearchQuery struct { - Key ApplicationSearchKey + Key AppSearchKey Method model.SearchMethod Value interface{} } diff --git a/internal/project/model/oidc_config.go b/internal/project/model/oidc_config.go index 2b2c06ab03..6c32bb1ee0 100644 --- a/internal/project/model/oidc_config.go +++ b/internal/project/model/oidc_config.go @@ -22,33 +22,33 @@ type OIDCConfig struct { type OIDCResponseType int32 const ( - OIDCRESPONSETYPE_CODE OIDCResponseType = iota - OIDCRESPONSETYPE_ID_TOKEN - OIDCRESPONSETYPE_TOKEN + OIDCResponseTypeCode OIDCResponseType = iota + OIDCResponseTypeIDToken + OIDCResponseTypeToken ) type OIDCGrantType int32 const ( - OIDCGRANTTYPE_AUTHORIZATION_CODE OIDCGrantType = iota - OIDCGRANTTYPE_IMPLICIT - OIDCGRANTTYPE_REFRESH_TOKEN + OIDCGrantTypeAuthorizationCode OIDCGrantType = iota + OIDCGrantTypeImplicit + OIDCGrantTypeRefreshToken ) type OIDCApplicationType int32 const ( - OIDCAPPLICATIONTYPE_WEB OIDCApplicationType = iota - OIDCAPPLICATIONTYPE_USER_AGENT - OIDCAPPLICATIONTYPE_NATIVE + OIDCApplicationTypeWeb OIDCApplicationType = iota + OIDCApplicationTypeUserAgent + OIDCApplicationTypeNative ) type OIDCAuthMethodType int32 const ( - OIDCAUTHMETHODTYPE_BASIC OIDCAuthMethodType = iota - OIDCAUTHMETHODTYPE_POST - OIDCAUTHMETHODTYPE_NONE + OIDCAuthMethodTypeBasic OIDCAuthMethodType = iota + OIDCAuthMethodTypePost + OIDCAuthMethodTypeNone ) func (c *OIDCConfig) IsValid() bool { @@ -67,11 +67,11 @@ func (c *OIDCConfig) getRequiredGrantTypes() []OIDCGrantType { implicit := false for _, r := range c.ResponseTypes { switch r { - case OIDCRESPONSETYPE_CODE: - grantTypes = append(grantTypes, OIDCGRANTTYPE_AUTHORIZATION_CODE) - case OIDCRESPONSETYPE_ID_TOKEN, OIDCRESPONSETYPE_TOKEN: + case OIDCResponseTypeCode: + grantTypes = append(grantTypes, OIDCGrantTypeAuthorizationCode) + case OIDCResponseTypeIDToken, OIDCResponseTypeToken: if !implicit { - grantTypes = append(grantTypes, OIDCGRANTTYPE_IMPLICIT) + grantTypes = append(grantTypes, OIDCGrantTypeImplicit) } } } diff --git a/internal/project/model/project.go b/internal/project/model/project.go index e8cbc8d02a..fc1cdfe8b8 100644 --- a/internal/project/model/project.go +++ b/internal/project/model/project.go @@ -31,17 +31,17 @@ type ProjectChange struct { type ProjectState int32 const ( - PROJECTSTATE_ACTIVE ProjectState = iota - PROJECTSTATE_INACTIVE - PROJECTSTATE_REMOVED + ProjectStateActive ProjectState = iota + ProjectStateInactive + ProjectStateRemoved ) func NewProject(id string) *Project { - return &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: id}, State: PROJECTSTATE_ACTIVE} + return &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: id}, State: ProjectStateActive} } func (p *Project) IsActive() bool { - return p.State == PROJECTSTATE_ACTIVE + return p.State == ProjectStateActive } func (p *Project) IsValid() bool { diff --git a/internal/project/model/project_grant.go b/internal/project/model/project_grant.go index acf9463892..9a0b5b8ce0 100644 --- a/internal/project/model/project_grant.go +++ b/internal/project/model/project_grant.go @@ -22,16 +22,16 @@ type ProjectGrantIDs struct { type ProjectGrantState int32 const ( - PROJECTGRANTSTATE_ACTIVE ProjectGrantState = iota - PROJECTGRANTSTATE_INACTIVE + ProjectGrantStateActive ProjectGrantState = iota + ProjectGrantStateInactive ) func NewProjectGrant(projectID, grantID string) *ProjectGrant { - return &ProjectGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: projectID}, GrantID: grantID, State: PROJECTGRANTSTATE_ACTIVE} + return &ProjectGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: projectID}, GrantID: grantID, State: ProjectGrantStateActive} } func (p *ProjectGrant) IsActive() bool { - return p.State == PROJECTGRANTSTATE_ACTIVE + return p.State == ProjectGrantStateActive } func (p *ProjectGrant) IsValid() bool { diff --git a/internal/project/model/project_grant_member_view.go b/internal/project/model/project_grant_member_view.go index 016fa0e8e8..ee49fdc727 100644 --- a/internal/project/model/project_grant_member_view.go +++ b/internal/project/model/project_grant_member_view.go @@ -30,13 +30,13 @@ type ProjectGrantMemberSearchRequest struct { type ProjectGrantMemberSearchKey int32 const ( - PROJECTGRANTMEMBERSEARCHKEY_UNSPECIFIED ProjectGrantMemberSearchKey = iota - PROJECTGRANTMEMBERSEARCHKEY_USER_NAME - PROJECTGRANTMEMBERSEARCHKEY_EMAIL - PROJECTGRANTMEMBERSEARCHKEY_FIRST_NAME - PROJECTGRANTMEMBERSEARCHKEY_LAST_NAME - PROJECTGRANTMEMBERSEARCHKEY_GRANT_ID - PROJECTGRANTMEMBERSEARCHKEY_USER_ID + ProjectGrantMemberSearchKeyUnspecified ProjectGrantMemberSearchKey = iota + ProjectGrantMemberSearchKeyUserName + ProjectGrantMemberSearchKeyEmail + ProjectGrantMemberSearchKeyFirstName + ProjectGrantMemberSearchKeyLastName + ProjectGrantMemberSearchKeyGrantID + ProjectGrantMemberSearchKeyUserID ) type ProjectGrantMemberSearchQuery struct { diff --git a/internal/project/model/project_grant_view.go b/internal/project/model/project_grant_view.go index 278fe6a130..b807529e09 100644 --- a/internal/project/model/project_grant_view.go +++ b/internal/project/model/project_grant_view.go @@ -32,13 +32,13 @@ type ProjectGrantViewSearchRequest struct { type ProjectGrantViewSearchKey int32 const ( - GRANTEDPROJECTSEARCHKEY_UNSPECIFIED ProjectGrantViewSearchKey = iota - GRANTEDPROJECTSEARCHKEY_NAME - GRANTEDPROJECTSEARCHKEY_PROJECTID - GRANTEDPROJECTSEARCHKEY_GRANTID - GRANTEDPROJECTSEARCHKEY_ORGID - GRANTEDPROJECTSEARCHKEY_RESOURCE_OWNER - GRANTEDPROJECTSEARCHKEY_ROLE_KEYS + GrantedProjectSearchKeyUnspecified ProjectGrantViewSearchKey = iota + GrantedProjectSearchKeyName + GrantedProjectSearchKeyProjectID + GrantedProjectSearchKeyGrantID + GrantedProjectSearchKeyOrgID + GrantedProjectSearchKeyResourceOwner + GrantedProjectSearchKeyRoleKeys ) type ProjectGrantViewSearchQuery struct { @@ -55,15 +55,15 @@ type ProjectGrantViewSearchResponse struct { } func (r *ProjectGrantViewSearchRequest) AppendMyOrgQuery(orgID string) { - r.Queries = append(r.Queries, &ProjectGrantViewSearchQuery{Key: GRANTEDPROJECTSEARCHKEY_ORGID, Method: model.SEARCHMETHOD_EQUALS, Value: orgID}) + r.Queries = append(r.Queries, &ProjectGrantViewSearchQuery{Key: GrantedProjectSearchKeyOrgID, Method: model.SearchMethodEquals, Value: orgID}) } func (r *ProjectGrantViewSearchRequest) AppendNotMyOrgQuery(orgID string) { - r.Queries = append(r.Queries, &ProjectGrantViewSearchQuery{Key: GRANTEDPROJECTSEARCHKEY_ORGID, Method: model.SEARCHMETHOD_NOT_EQUALS, Value: orgID}) + r.Queries = append(r.Queries, &ProjectGrantViewSearchQuery{Key: GrantedProjectSearchKeyOrgID, Method: model.SearchMethodNotEquals, Value: orgID}) } func (r *ProjectGrantViewSearchRequest) AppendMyResourceOwnerQuery(orgID string) { - r.Queries = append(r.Queries, &ProjectGrantViewSearchQuery{Key: GRANTEDPROJECTSEARCHKEY_RESOURCE_OWNER, Method: model.SEARCHMETHOD_EQUALS, Value: orgID}) + r.Queries = append(r.Queries, &ProjectGrantViewSearchQuery{Key: GrantedProjectSearchKeyResourceOwner, Method: model.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 d844153da8..8dcb978fff 100644 --- a/internal/project/model/project_member_view.go +++ b/internal/project/model/project_member_view.go @@ -29,13 +29,13 @@ type ProjectMemberSearchRequest struct { type ProjectMemberSearchKey int32 const ( - PROJECTMEMBERSEARCHKEY_UNSPECIFIED ProjectMemberSearchKey = iota - PROJECTMEMBERSEARCHKEY_USER_NAME - PROJECTMEMBERSEARCHKEY_EMAIL - PROJECTMEMBERSEARCHKEY_FIRST_NAME - PROJECTMEMBERSEARCHKEY_LAST_NAME - PROJECTMEMBERSEARCHKEY_PROJECT_ID - PROJECTMEMBERSEARCHKEY_USER_ID + ProjectMemberSearchKeyUnspecified ProjectMemberSearchKey = iota + ProjectMemberSearchKeyUserName + ProjectMemberSearchKeyEmail + ProjectMemberSearchKeyFirstName + ProjectMemberSearchKeyLastName + ProjectMemberSearchKeyProjectID + ProjectMemberSearchKeyUserID ) type ProjectMemberSearchQuery struct { @@ -57,5 +57,5 @@ func (r *ProjectMemberSearchRequest) EnsureLimit(limit uint64) { } } func (r *ProjectMemberSearchRequest) AppendProjectQuery(projectID string) { - r.Queries = append(r.Queries, &ProjectMemberSearchQuery{Key: PROJECTMEMBERSEARCHKEY_PROJECT_ID, Method: model.SEARCHMETHOD_EQUALS, Value: projectID}) + r.Queries = append(r.Queries, &ProjectMemberSearchQuery{Key: ProjectMemberSearchKeyProjectID, Method: model.SearchMethodEquals, Value: projectID}) } diff --git a/internal/project/model/project_role_view.go b/internal/project/model/project_role_view.go index 31d5609b80..d4dc3dc262 100644 --- a/internal/project/model/project_role_view.go +++ b/internal/project/model/project_role_view.go @@ -27,12 +27,12 @@ type ProjectRoleSearchRequest struct { type ProjectRoleSearchKey int32 const ( - PROJECTROLESEARCHKEY_UNSPECIFIED ProjectRoleSearchKey = iota - PROJECTROLESEARCHKEY_KEY - PROJECTROLESEARCHKEY_PROJECTID - PROJECTROLESEARCHKEY_ORGID - PROJECTROLESEARCHKEY_RESOURCEOWNER - PROJECTROLESEARCHKEY_DISPLAY_NAME + ProjectRoleSearchKeyUnspecified ProjectRoleSearchKey = iota + ProjectRoleSearchKeyKey + ProjectRoleSearchKeyProjectID + ProjectRoleSearchKeyOrgID + ProjectRoleSearchKeyResourceOwner + ProjectRoleSearchKeyDisplayName ) type ProjectRoleSearchQuery struct { @@ -49,10 +49,10 @@ type ProjectRoleSearchResponse struct { } func (r *ProjectRoleSearchRequest) AppendMyOrgQuery(orgID string) { - r.Queries = append(r.Queries, &ProjectRoleSearchQuery{Key: PROJECTROLESEARCHKEY_ORGID, Method: model.SEARCHMETHOD_EQUALS, Value: orgID}) + r.Queries = append(r.Queries, &ProjectRoleSearchQuery{Key: ProjectRoleSearchKeyOrgID, Method: model.SearchMethodEquals, Value: orgID}) } func (r *ProjectRoleSearchRequest) AppendProjectQuery(projectID string) { - r.Queries = append(r.Queries, &ProjectRoleSearchQuery{Key: PROJECTROLESEARCHKEY_PROJECTID, Method: model.SEARCHMETHOD_EQUALS, Value: projectID}) + r.Queries = append(r.Queries, &ProjectRoleSearchQuery{Key: ProjectRoleSearchKeyProjectID, Method: model.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 3cb467aff8..70cdc0ced7 100644 --- a/internal/project/model/project_view.go +++ b/internal/project/model/project_view.go @@ -26,10 +26,10 @@ type ProjectViewSearchRequest struct { type ProjectViewSearchKey int32 const ( - PROJECTSEARCHKEY_UNSPECIFIED ProjectViewSearchKey = iota - PROJECTSEARCHKEY_NAME - PROJECTSEARCHKEY_PROJECTID - PROJECTSEARCHKEY_RESOURCE_OWNER + ProjectViewSearchKeyUnspecified ProjectViewSearchKey = iota + ProjectViewSearchKeyName + ProjectViewSearchKeyProjectID + ProjectViewSearchKeyResourceOwner ) type ProjectViewSearchQuery struct { @@ -46,7 +46,7 @@ type ProjectViewSearchResponse struct { } func (r *ProjectViewSearchRequest) AppendMyResourceOwnerQuery(orgID string) { - r.Queries = append(r.Queries, &ProjectViewSearchQuery{Key: PROJECTSEARCHKEY_RESOURCE_OWNER, Method: model.SEARCHMETHOD_EQUALS, Value: orgID}) + r.Queries = append(r.Queries, &ProjectViewSearchQuery{Key: ProjectViewSearchKeyResourceOwner, Method: model.SearchMethodEquals, Value: orgID}) } func (r *ProjectViewSearchRequest) EnsureLimit(limit uint64) { diff --git a/internal/project/repository/eventsourcing/eventstore.go b/internal/project/repository/eventsourcing/eventstore.go index d34d4a7fe3..505d0295c6 100644 --- a/internal/project/repository/eventsourcing/eventstore.go +++ b/internal/project/repository/eventsourcing/eventstore.go @@ -80,7 +80,7 @@ func (es *ProjectEventstore) CreateProject(ctx context.Context, project *proj_mo return nil, err } project.AggregateID = id - project.State = proj_model.PROJECTSTATE_ACTIVE + project.State = proj_model.ProjectStateActive repoProject := model.ProjectFromModel(project) member := &model.ProjectMember{ UserID: auth.GetCtxData(ctx).UserID, @@ -658,7 +658,7 @@ func (es *ProjectEventstore) ChangeOIDCConfig(ctx context.Context, config *proj_ if _, app = existing.GetApp(config.AppID); app == nil { return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-dkso8", "Errors.Project.AppNoExisting") } - if app.Type != proj_model.APPTYPE_OIDC { + if app.Type != proj_model.AppTypeOIDC { return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-98uje", "Errors.Project.AppIsNotOIDC") } repoProject := model.ProjectFromModel(existing) @@ -688,7 +688,7 @@ func (es *ProjectEventstore) ChangeOIDCConfigSecret(ctx context.Context, project if _, app = existing.GetApp(appID); app == nil { return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-9odi4", "Errors.Project.AppNotExisting") } - if app.Type != proj_model.APPTYPE_OIDC { + if app.Type != proj_model.AppTypeOIDC { return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-dile4", "Errors.Project.AppIsNotOIDC") } repoProject := model.ProjectFromModel(existing) @@ -726,7 +726,7 @@ func (es *ProjectEventstore) VerifyOIDCClientSecret(ctx context.Context, project if _, app = existing.GetApp(appID); app == nil { return caos_errs.ThrowPreconditionFailed(nil, "EVENT-D6hba", "Errors.Project.AppNoExisting") } - if app.Type != proj_model.APPTYPE_OIDC { + if app.Type != proj_model.AppTypeOIDC { return caos_errs.ThrowPreconditionFailed(nil, "EVENT-huywq", "Errors.Project.AppIsNotOIDC") } diff --git a/internal/project/repository/eventsourcing/eventstore_mock_test.go b/internal/project/repository/eventsourcing/eventstore_mock_test.go index d7f718c1db..3df206a77d 100644 --- a/internal/project/repository/eventsourcing/eventstore_mock_test.go +++ b/internal/project/repository/eventsourcing/eventstore_mock_test.go @@ -136,8 +136,8 @@ func GetMockManipulateProjectWithOIDCApp(ctrl *gomock.Controller) *ProjectEvents appData, _ := json.Marshal(model.Application{AppID: "AppID", Name: "Name"}) oidcData, _ := json.Marshal(model.OIDCConfig{ AppID: "AppID", - ResponseTypes: []int32{int32(proj_model.OIDCRESPONSETYPE_CODE)}, - GrantTypes: []int32{int32(proj_model.OIDCGRANTTYPE_AUTHORIZATION_CODE)}, + ResponseTypes: []int32{int32(proj_model.OIDCResponseTypeCode)}, + GrantTypes: []int32{int32(proj_model.OIDCGrantTypeAuthorizationCode)}, }) events := []*es_models.Event{ &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.ProjectAdded, Data: data}, diff --git a/internal/project/repository/eventsourcing/eventstore_test.go b/internal/project/repository/eventsourcing/eventstore_test.go index 7c12695902..38076ab38c 100644 --- a/internal/project/repository/eventsourcing/eventstore_test.go +++ b/internal/project/repository/eventsourcing/eventstore_test.go @@ -226,10 +226,10 @@ func TestDeactivateProject(t *testing.T) { args: args{ es: GetMockManipulateProject(ctrl), ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.PROJECTSTATE_ACTIVE}, + existing: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.ProjectStateActive}, }, res: res{ - project: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "NameNew", State: model.PROJECTSTATE_INACTIVE}, + project: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "NameNew", State: model.ProjectStateInactive}, }, }, { @@ -237,7 +237,7 @@ func TestDeactivateProject(t *testing.T) { args: args{ es: GetMockManipulateInactiveProject(ctrl), ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.PROJECTSTATE_INACTIVE}, + existing: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.ProjectStateInactive}, }, res: res{ wantErr: true, @@ -249,7 +249,7 @@ func TestDeactivateProject(t *testing.T) { args: args{ es: GetMockManipulateProjectNoEvents(ctrl), ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.PROJECTSTATE_ACTIVE}, + existing: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.ProjectStateActive}, }, res: res{ wantErr: true, @@ -297,10 +297,10 @@ func TestReactivateProject(t *testing.T) { args: args{ es: GetMockManipulateInactiveProject(ctrl), ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.PROJECTSTATE_INACTIVE}, + existing: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.ProjectStateInactive}, }, res: res{ - project: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "NameNew", State: model.PROJECTSTATE_ACTIVE}, + project: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "NameNew", State: model.ProjectStateActive}, }, }, { @@ -308,7 +308,7 @@ func TestReactivateProject(t *testing.T) { args: args{ es: GetMockManipulateProject(ctrl), ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.PROJECTSTATE_ACTIVE}, + existing: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.ProjectStateActive}, }, res: res{ wantErr: true, @@ -320,7 +320,7 @@ func TestReactivateProject(t *testing.T) { args: args{ es: GetMockManipulateProjectNoEvents(ctrl), ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.PROJECTSTATE_ACTIVE}, + existing: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.ProjectStateActive}, }, res: res{ wantErr: true, @@ -1041,8 +1041,8 @@ func TestAddApplication(t *testing.T) { AppID: "AppID", Name: "Name", OIDCConfig: &model.OIDCConfig{ - ResponseTypes: []model.OIDCResponseType{model.OIDCRESPONSETYPE_CODE}, - GrantTypes: []model.OIDCGrantType{model.OIDCGRANTTYPE_AUTHORIZATION_CODE}, + ResponseTypes: []model.OIDCResponseType{model.OIDCResponseTypeCode}, + GrantTypes: []model.OIDCGrantType{model.OIDCGrantTypeAuthorizationCode}, }, }, }, @@ -1050,8 +1050,8 @@ func TestAddApplication(t *testing.T) { result: &model.Application{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", OIDCConfig: &model.OIDCConfig{ - ResponseTypes: []model.OIDCResponseType{model.OIDCRESPONSETYPE_CODE}, - GrantTypes: []model.OIDCGrantType{model.OIDCGRANTTYPE_AUTHORIZATION_CODE}, + ResponseTypes: []model.OIDCResponseType{model.OIDCResponseTypeCode}, + GrantTypes: []model.OIDCGrantType{model.OIDCGrantTypeAuthorizationCode}, }, }, }, @@ -1077,8 +1077,8 @@ func TestAddApplication(t *testing.T) { AppID: "AppID", Name: "Name", OIDCConfig: &model.OIDCConfig{ - ResponseTypes: []model.OIDCResponseType{model.OIDCRESPONSETYPE_CODE}, - GrantTypes: []model.OIDCGrantType{model.OIDCGRANTTYPE_AUTHORIZATION_CODE}, + ResponseTypes: []model.OIDCResponseType{model.OIDCResponseTypeCode}, + GrantTypes: []model.OIDCGrantType{model.OIDCGrantTypeAuthorizationCode}, }, }, }, @@ -1143,8 +1143,8 @@ func TestChangeApp(t *testing.T) { AppID: "AppID", Name: "NameChanged", OIDCConfig: &model.OIDCConfig{ - ResponseTypes: []model.OIDCResponseType{model.OIDCRESPONSETYPE_CODE}, - GrantTypes: []model.OIDCGrantType{model.OIDCGRANTTYPE_AUTHORIZATION_CODE}, + ResponseTypes: []model.OIDCResponseType{model.OIDCResponseTypeCode}, + GrantTypes: []model.OIDCGrantType{model.OIDCGrantTypeAuthorizationCode}, }, }, }, @@ -1172,8 +1172,8 @@ func TestChangeApp(t *testing.T) { AppID: "AppID", Name: "Name", OIDCConfig: &model.OIDCConfig{ - ResponseTypes: []model.OIDCResponseType{model.OIDCRESPONSETYPE_CODE}, - GrantTypes: []model.OIDCGrantType{model.OIDCGRANTTYPE_AUTHORIZATION_CODE}, + ResponseTypes: []model.OIDCResponseType{model.OIDCResponseTypeCode}, + GrantTypes: []model.OIDCGrantType{model.OIDCGrantTypeAuthorizationCode}, }, }, }, @@ -1191,8 +1191,8 @@ func TestChangeApp(t *testing.T) { AppID: "AppID", Name: "Name", OIDCConfig: &model.OIDCConfig{ - ResponseTypes: []model.OIDCResponseType{model.OIDCRESPONSETYPE_CODE}, - GrantTypes: []model.OIDCGrantType{model.OIDCGRANTTYPE_AUTHORIZATION_CODE}, + ResponseTypes: []model.OIDCResponseType{model.OIDCResponseTypeCode}, + GrantTypes: []model.OIDCGrantType{model.OIDCGrantTypeAuthorizationCode}, }, }, }, @@ -1334,10 +1334,10 @@ func TestDeactivateApp(t *testing.T) { result: &model.Application{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, AppID: "AppID", Name: "Name", - State: model.APPSTATE_INACTIVE, + State: model.AppStateInactive, OIDCConfig: &model.OIDCConfig{ - ResponseTypes: []model.OIDCResponseType{model.OIDCRESPONSETYPE_CODE}, - GrantTypes: []model.OIDCGrantType{model.OIDCGRANTTYPE_AUTHORIZATION_CODE}, + ResponseTypes: []model.OIDCResponseType{model.OIDCResponseTypeCode}, + GrantTypes: []model.OIDCGrantType{model.OIDCGrantTypeAuthorizationCode}, }, }, }, @@ -1363,8 +1363,8 @@ func TestDeactivateApp(t *testing.T) { AppID: "AppID", Name: "Name", OIDCConfig: &model.OIDCConfig{ - ResponseTypes: []model.OIDCResponseType{model.OIDCRESPONSETYPE_CODE}, - GrantTypes: []model.OIDCGrantType{model.OIDCGRANTTYPE_AUTHORIZATION_CODE}, + ResponseTypes: []model.OIDCResponseType{model.OIDCResponseTypeCode}, + GrantTypes: []model.OIDCGrantType{model.OIDCGrantTypeAuthorizationCode}, }, }, }, @@ -1382,8 +1382,8 @@ func TestDeactivateApp(t *testing.T) { AppID: "AppID", Name: "Name", OIDCConfig: &model.OIDCConfig{ - ResponseTypes: []model.OIDCResponseType{model.OIDCRESPONSETYPE_CODE}, - GrantTypes: []model.OIDCGrantType{model.OIDCGRANTTYPE_AUTHORIZATION_CODE}, + ResponseTypes: []model.OIDCResponseType{model.OIDCResponseTypeCode}, + GrantTypes: []model.OIDCGrantType{model.OIDCGrantTypeAuthorizationCode}, }, }, }, @@ -1444,10 +1444,10 @@ func TestReactivateApp(t *testing.T) { result: &model.Application{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, AppID: "AppID", Name: "Name", - State: model.APPSTATE_ACTIVE, + State: model.AppStateActive, OIDCConfig: &model.OIDCConfig{ - ResponseTypes: []model.OIDCResponseType{model.OIDCRESPONSETYPE_CODE}, - GrantTypes: []model.OIDCGrantType{model.OIDCGRANTTYPE_AUTHORIZATION_CODE}, + ResponseTypes: []model.OIDCResponseType{model.OIDCResponseTypeCode}, + GrantTypes: []model.OIDCGrantType{model.OIDCGrantTypeAuthorizationCode}, }, }, }, @@ -1473,8 +1473,8 @@ func TestReactivateApp(t *testing.T) { AppID: "AppID", Name: "Name", OIDCConfig: &model.OIDCConfig{ - ResponseTypes: []model.OIDCResponseType{model.OIDCRESPONSETYPE_CODE}, - GrantTypes: []model.OIDCGrantType{model.OIDCGRANTTYPE_AUTHORIZATION_CODE}, + ResponseTypes: []model.OIDCResponseType{model.OIDCResponseTypeCode}, + GrantTypes: []model.OIDCGrantType{model.OIDCGrantTypeAuthorizationCode}, }, }, }, @@ -1492,8 +1492,8 @@ func TestReactivateApp(t *testing.T) { AppID: "AppID", Name: "Name", OIDCConfig: &model.OIDCConfig{ - ResponseTypes: []model.OIDCResponseType{model.OIDCRESPONSETYPE_CODE}, - GrantTypes: []model.OIDCGrantType{model.OIDCGRANTTYPE_AUTHORIZATION_CODE}, + ResponseTypes: []model.OIDCResponseType{model.OIDCResponseTypeCode}, + GrantTypes: []model.OIDCGrantType{model.OIDCGrantTypeAuthorizationCode}, }, }, }, @@ -1548,16 +1548,16 @@ func TestChangeOIDCConfig(t *testing.T) { config: &model.OIDCConfig{ ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 0}, AppID: "AppID", - ResponseTypes: []model.OIDCResponseType{model.OIDCRESPONSETYPE_ID_TOKEN}, - GrantTypes: []model.OIDCGrantType{model.OIDCGRANTTYPE_IMPLICIT}, + ResponseTypes: []model.OIDCResponseType{model.OIDCResponseTypeIDToken}, + GrantTypes: []model.OIDCGrantType{model.OIDCGrantTypeImplicit}, }, }, res: res{ result: &model.OIDCConfig{ ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 0}, AppID: "AppID", - ResponseTypes: []model.OIDCResponseType{model.OIDCRESPONSETYPE_ID_TOKEN}, - GrantTypes: []model.OIDCGrantType{model.OIDCGRANTTYPE_IMPLICIT}, + ResponseTypes: []model.OIDCResponseType{model.OIDCResponseTypeIDToken}, + GrantTypes: []model.OIDCGrantType{model.OIDCGrantTypeImplicit}, }, }, }, @@ -1569,7 +1569,7 @@ func TestChangeOIDCConfig(t *testing.T) { config: &model.OIDCConfig{ ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 0}, AppID: "AppID", - ResponseTypes: []model.OIDCResponseType{model.OIDCRESPONSETYPE_ID_TOKEN}, + ResponseTypes: []model.OIDCResponseType{model.OIDCResponseTypeIDToken}, }, }, res: res{ @@ -1585,8 +1585,8 @@ func TestChangeOIDCConfig(t *testing.T) { config: &model.OIDCConfig{ ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 0}, AppID: "AppID", - ResponseTypes: []model.OIDCResponseType{model.OIDCRESPONSETYPE_ID_TOKEN}, - GrantTypes: []model.OIDCGrantType{model.OIDCGRANTTYPE_IMPLICIT}, + ResponseTypes: []model.OIDCResponseType{model.OIDCResponseTypeIDToken}, + GrantTypes: []model.OIDCGrantType{model.OIDCGrantTypeImplicit}, }, }, res: res{ @@ -1602,8 +1602,8 @@ func TestChangeOIDCConfig(t *testing.T) { config: &model.OIDCConfig{ ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 0}, AppID: "AppID", - ResponseTypes: []model.OIDCResponseType{model.OIDCRESPONSETYPE_ID_TOKEN}, - GrantTypes: []model.OIDCGrantType{model.OIDCGRANTTYPE_IMPLICIT}, + ResponseTypes: []model.OIDCResponseType{model.OIDCResponseTypeIDToken}, + GrantTypes: []model.OIDCGrantType{model.OIDCGrantTypeImplicit}, }, }, res: res{ @@ -1619,8 +1619,8 @@ func TestChangeOIDCConfig(t *testing.T) { config: &model.OIDCConfig{ ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 0}, AppID: "AppID", - ResponseTypes: []model.OIDCResponseType{model.OIDCRESPONSETYPE_ID_TOKEN}, - GrantTypes: []model.OIDCGrantType{model.OIDCGRANTTYPE_IMPLICIT}, + ResponseTypes: []model.OIDCResponseType{model.OIDCResponseTypeIDToken}, + GrantTypes: []model.OIDCGrantType{model.OIDCGrantTypeImplicit}, }, }, res: res{ @@ -1680,8 +1680,8 @@ func TestChangeOIDCConfigSecret(t *testing.T) { result: &model.OIDCConfig{ ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 0}, AppID: "AppID", - ResponseTypes: []model.OIDCResponseType{model.OIDCRESPONSETYPE_ID_TOKEN}, - GrantTypes: []model.OIDCGrantType{model.OIDCGRANTTYPE_IMPLICIT}, + ResponseTypes: []model.OIDCResponseType{model.OIDCResponseTypeIDToken}, + GrantTypes: []model.OIDCGrantType{model.OIDCGrantTypeImplicit}, }, }, }, @@ -2059,7 +2059,7 @@ func TestDeactivateProjectGrant(t *testing.T) { res: res{ result: &model.ProjectGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID", Sequence: 1}, GrantID: "GrantID", - State: model.PROJECTGRANTSTATE_INACTIVE, + State: model.ProjectGrantStateInactive, }, }, }, @@ -2153,7 +2153,7 @@ func TestReactivateProjectGrant(t *testing.T) { res: res{ result: &model.ProjectGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID", Sequence: 1}, GrantID: "GrantID", - State: model.PROJECTGRANTSTATE_ACTIVE, + State: model.ProjectGrantStateActive, }, }, }, diff --git a/internal/project/repository/eventsourcing/model/application_test.go b/internal/project/repository/eventsourcing/model/application_test.go index 697459c338..7d8bd2294a 100644 --- a/internal/project/repository/eventsourcing/model/application_test.go +++ b/internal/project/repository/eventsourcing/model/application_test.go @@ -177,22 +177,22 @@ func TestAppendAppStateEvent(t *testing.T) { { name: "append deactivate application event", args: args{ - project: &Project{Applications: []*Application{&Application{AppID: "AppID", Name: "Application", State: int32(model.APPSTATE_ACTIVE)}}}, + project: &Project{Applications: []*Application{&Application{AppID: "AppID", Name: "Application", State: int32(model.AppStateActive)}}}, app: &ApplicationID{AppID: "AppID"}, event: &es_models.Event{}, - state: model.APPSTATE_INACTIVE, + state: model.AppStateInactive, }, - result: &Project{Applications: []*Application{&Application{AppID: "AppID", Name: "Application", State: int32(model.APPSTATE_INACTIVE)}}}, + result: &Project{Applications: []*Application{&Application{AppID: "AppID", Name: "Application", State: int32(model.AppStateInactive)}}}, }, { name: "append reactivate application event", args: args{ - project: &Project{Applications: []*Application{&Application{AppID: "AppID", Name: "Application", State: int32(model.APPSTATE_INACTIVE)}}}, + project: &Project{Applications: []*Application{&Application{AppID: "AppID", Name: "Application", State: int32(model.AppStateInactive)}}}, app: &ApplicationID{AppID: "AppID"}, event: &es_models.Event{}, - state: model.APPSTATE_ACTIVE, + state: model.AppStateActive, }, - result: &Project{Applications: []*Application{&Application{AppID: "AppID", Name: "Application", State: int32(model.APPSTATE_ACTIVE)}}}, + result: &Project{Applications: []*Application{&Application{AppID: "AppID", Name: "Application", State: int32(model.AppStateActive)}}}, }, } for _, tt := range tests { diff --git a/internal/project/repository/eventsourcing/model/oidc_config.go b/internal/project/repository/eventsourcing/model/oidc_config.go index 303aea917b..d139369a8a 100644 --- a/internal/project/repository/eventsourcing/model/oidc_config.go +++ b/internal/project/repository/eventsourcing/model/oidc_config.go @@ -100,7 +100,7 @@ func (p *Project) appendAddOIDCConfigEvent(event *es_models.Event) error { } config.ObjectRoot.CreationDate = event.CreationDate if i, a := GetApplication(p.Applications, config.AppID); a != nil { - p.Applications[i].Type = int32(model.APPTYPE_OIDC) + p.Applications[i].Type = int32(model.AppTypeOIDC) p.Applications[i].OIDCConfig = config } return nil diff --git a/internal/project/repository/eventsourcing/model/project.go b/internal/project/repository/eventsourcing/model/project.go index e259179132..0fd1dc98a4 100644 --- a/internal/project/repository/eventsourcing/model/project.go +++ b/internal/project/repository/eventsourcing/model/project.go @@ -118,9 +118,9 @@ func (p *Project) AppendEvent(event *es_models.Event) error { case ApplicationRemoved: return p.appendRemoveAppEvent(event) case ApplicationDeactivated: - return p.appendAppStateEvent(event, model.APPSTATE_INACTIVE) + return p.appendAppStateEvent(event, model.AppStateInactive) case ApplicationReactivated: - return p.appendAppStateEvent(event, model.APPSTATE_ACTIVE) + return p.appendAppStateEvent(event, model.AppStateActive) case OIDCConfigAdded: return p.appendAddOIDCConfigEvent(event) case OIDCConfigChanged, OIDCConfigSecretChanged: @@ -130,9 +130,9 @@ func (p *Project) AppendEvent(event *es_models.Event) error { case ProjectGrantChanged, ProjectGrantCascadeChanged: return p.appendChangeGrantEvent(event) case ProjectGrantDeactivated: - return p.appendGrantStateEvent(event, model.PROJECTGRANTSTATE_INACTIVE) + return p.appendGrantStateEvent(event, model.ProjectGrantStateInactive) case ProjectGrantReactivated: - return p.appendGrantStateEvent(event, model.PROJECTGRANTSTATE_ACTIVE) + return p.appendGrantStateEvent(event, model.ProjectGrantStateActive) case ProjectGrantRemoved: return p.appendRemoveGrantEvent(event) case ProjectGrantMemberAdded: @@ -147,22 +147,22 @@ func (p *Project) AppendEvent(event *es_models.Event) error { func (p *Project) AppendAddProjectEvent(event *es_models.Event) error { p.setData(event) - p.State = int32(model.PROJECTSTATE_ACTIVE) + p.State = int32(model.ProjectStateActive) return nil } func (p *Project) appendDeactivatedEvent() error { - p.State = int32(model.PROJECTSTATE_INACTIVE) + p.State = int32(model.ProjectStateInactive) return nil } func (p *Project) appendReactivatedEvent() error { - p.State = int32(model.PROJECTSTATE_ACTIVE) + p.State = int32(model.ProjectStateActive) return nil } func (p *Project) appendRemovedEvent() error { - p.State = int32(model.PROJECTSTATE_REMOVED) + p.State = int32(model.ProjectStateRemoved) return nil } diff --git a/internal/project/repository/eventsourcing/model/project_grant_test.go b/internal/project/repository/eventsourcing/model/project_grant_test.go index 2c5ff3d570..ed59a1075f 100644 --- a/internal/project/repository/eventsourcing/model/project_grant_test.go +++ b/internal/project/repository/eventsourcing/model/project_grant_test.go @@ -136,9 +136,9 @@ func TestAppendGrantStateEvent(t *testing.T) { project: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "GrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}}}}, grant: &ProjectGrantID{GrantID: "GrantID"}, event: &es_models.Event{}, - state: model.PROJECTGRANTSTATE_INACTIVE, + state: model.ProjectGrantStateInactive, }, - result: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "GrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}, State: int32(model.PROJECTGRANTSTATE_INACTIVE)}}}, + result: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "GrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}, State: int32(model.ProjectGrantStateInactive)}}}, }, { name: "append reactivate grant event", @@ -146,9 +146,9 @@ func TestAppendGrantStateEvent(t *testing.T) { project: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "GrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}}}}, grant: &ProjectGrantID{GrantID: "GrantID"}, event: &es_models.Event{}, - state: model.PROJECTGRANTSTATE_ACTIVE, + state: model.ProjectGrantStateActive, }, - result: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "GrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}, State: int32(model.PROJECTGRANTSTATE_ACTIVE)}}}, + result: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "GrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}, State: int32(model.ProjectGrantStateActive)}}}, }, } for _, tt := range tests { diff --git a/internal/project/repository/eventsourcing/model/project_test.go b/internal/project/repository/eventsourcing/model/project_test.go index 704b330caa..edccbcedec 100644 --- a/internal/project/repository/eventsourcing/model/project_test.go +++ b/internal/project/repository/eventsourcing/model/project_test.go @@ -69,7 +69,7 @@ func TestProjectFromEvents(t *testing.T) { }, project: &Project{Name: "ProjectName"}, }, - result: &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, State: int32(model.PROJECTSTATE_ACTIVE), Name: "ProjectName"}, + result: &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, State: int32(model.ProjectStateActive), Name: "ProjectName"}, }, { name: "project from events, nil project", @@ -79,7 +79,7 @@ func TestProjectFromEvents(t *testing.T) { }, project: nil, }, - result: &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, State: int32(model.PROJECTSTATE_ACTIVE)}, + result: &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, State: int32(model.ProjectStateActive)}, }, } for _, tt := range tests { @@ -112,7 +112,7 @@ func TestAppendEvent(t *testing.T) { event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: ProjectAdded}, project: &Project{Name: "ProjectName"}, }, - result: &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, State: int32(model.PROJECTSTATE_ACTIVE), Name: "ProjectName"}, + result: &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, State: int32(model.ProjectStateActive), Name: "ProjectName"}, }, { name: "append change event", @@ -120,21 +120,21 @@ func TestAppendEvent(t *testing.T) { event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: ProjectChanged}, project: &Project{Name: "ProjectName"}, }, - result: &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, State: int32(model.PROJECTSTATE_ACTIVE), Name: "ProjectName"}, + result: &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, State: int32(model.ProjectStateActive), Name: "ProjectName"}, }, { name: "append deactivate event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: ProjectDeactivated}, }, - result: &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, State: int32(model.PROJECTSTATE_INACTIVE)}, + result: &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, State: int32(model.ProjectStateInactive)}, }, { name: "append reactivate event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: ProjectReactivated}, }, - result: &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, State: int32(model.PROJECTSTATE_ACTIVE)}, + result: &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, State: int32(model.ProjectStateActive)}, }, } for _, tt := range tests { @@ -172,7 +172,7 @@ func TestAppendDeactivatedEvent(t *testing.T) { args: args{ project: &Project{}, }, - result: &Project{State: int32(model.PROJECTSTATE_INACTIVE)}, + result: &Project{State: int32(model.ProjectStateInactive)}, }, } for _, tt := range tests { @@ -199,7 +199,7 @@ func TestAppendReactivatedEvent(t *testing.T) { args: args{ project: &Project{}, }, - result: &Project{State: int32(model.PROJECTSTATE_ACTIVE)}, + result: &Project{State: int32(model.ProjectStateActive)}, }, } for _, tt := range tests { diff --git a/internal/project/repository/eventsourcing/project_test.go b/internal/project/repository/eventsourcing/project_test.go index ace426f014..47822415e5 100644 --- a/internal/project/repository/eventsourcing/project_test.go +++ b/internal/project/repository/eventsourcing/project_test.go @@ -182,7 +182,7 @@ func TestProjectCreateAggregate(t *testing.T) { name: "project update aggregate ok", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - new: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + new: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, member: &model.ProjectMember{UserID: "UserID"}, aggCreator: models.NewAggregateCreator("Test"), }, @@ -208,7 +208,7 @@ func TestProjectCreateAggregate(t *testing.T) { name: "new member nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - new: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + new: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, member: nil, aggCreator: models.NewAggregateCreator("Test"), }, @@ -266,8 +266,8 @@ func TestProjectUpdateAggregate(t *testing.T) { name: "project update aggregate ok", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, - new: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName_Changed", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, + new: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName_Changed", State: int32(proj_model.ProjectStateActive)}, aggCreator: models.NewAggregateCreator("Test"), }, res: res{ @@ -293,7 +293,7 @@ func TestProjectUpdateAggregate(t *testing.T) { name: "new project nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, @@ -346,7 +346,7 @@ func TestProjectDeactivateAggregate(t *testing.T) { name: "project deactivate aggregate ok", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, aggCreator: models.NewAggregateCreator("Test"), }, res: res{ @@ -407,7 +407,7 @@ func TestProjectReactivateAggregate(t *testing.T) { name: "project reactivate aggregate ok", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_INACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateInactive)}, aggCreator: models.NewAggregateCreator("Test"), }, res: res{ @@ -469,7 +469,7 @@ func TestProjectMemberAddedAggregate(t *testing.T) { name: "projectmember added ok", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: &model.ProjectMember{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, UserID: "UserID", Roles: []string{"Roles"}}, aggCreator: models.NewAggregateCreator("Test"), }, @@ -496,7 +496,7 @@ func TestProjectMemberAddedAggregate(t *testing.T) { name: "member nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, @@ -550,7 +550,7 @@ func TestProjectMemberChangedAggregate(t *testing.T) { name: "projectmember changed ok", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: &model.ProjectMember{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, UserID: "UserID", Roles: []string{"Roles"}}, aggCreator: models.NewAggregateCreator("Test"), }, @@ -577,7 +577,7 @@ func TestProjectMemberChangedAggregate(t *testing.T) { name: "member nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, @@ -631,7 +631,7 @@ func TestProjectMemberRemovedAggregate(t *testing.T) { name: "projectmember removed ok", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: &model.ProjectMember{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, UserID: "UserID", Roles: []string{"Roles"}}, aggCreator: models.NewAggregateCreator("Test"), }, @@ -658,7 +658,7 @@ func TestProjectMemberRemovedAggregate(t *testing.T) { name: "member nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, @@ -712,7 +712,7 @@ func TestProjectRoleAddedAggregate(t *testing.T) { name: "projectrole added ok", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: []*model.ProjectRole{&model.ProjectRole{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Key: "Key"}}, aggCreator: models.NewAggregateCreator("Test"), }, @@ -725,7 +725,7 @@ func TestProjectRoleAddedAggregate(t *testing.T) { name: "projectrole multiple added ok", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: []*model.ProjectRole{ &model.ProjectRole{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Key: "Key"}, &model.ProjectRole{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Key: "Key2"}, @@ -755,7 +755,7 @@ func TestProjectRoleAddedAggregate(t *testing.T) { name: "member nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, @@ -809,7 +809,7 @@ func TestProjectRoleChangedAggregate(t *testing.T) { name: "projectmember changed ok", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: &model.ProjectRole{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Key: "Key"}, aggCreator: models.NewAggregateCreator("Test"), }, @@ -836,7 +836,7 @@ func TestProjectRoleChangedAggregate(t *testing.T) { name: "member nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, @@ -891,7 +891,7 @@ func TestProjectRoleRemovedAggregate(t *testing.T) { name: "projectrole changed ok", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: &model.ProjectRole{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Key: "Key"}, aggCreator: models.NewAggregateCreator("Test"), }, @@ -907,7 +907,7 @@ func TestProjectRoleRemovedAggregate(t *testing.T) { existing: &model.Project{ ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", - State: int32(proj_model.PROJECTSTATE_ACTIVE), + State: int32(proj_model.ProjectStateActive), Grants: []*model.ProjectGrant{&model.ProjectGrant{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, GrantID: "GrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"ROLE"}}}, }, new: &model.ProjectRole{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Key: "Key"}, @@ -935,7 +935,7 @@ func TestProjectRoleRemovedAggregate(t *testing.T) { name: "member nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, @@ -992,7 +992,7 @@ func TestProjectAppAddedAggregate(t *testing.T) { name: "add oidc application", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: &model.Application{ ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, AppID: "AppId", @@ -1022,7 +1022,7 @@ func TestProjectAppAddedAggregate(t *testing.T) { name: "app nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, @@ -1082,7 +1082,7 @@ func TestProjectAppChangedAggregate(t *testing.T) { existing: &model.Project{ ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", - State: int32(proj_model.PROJECTSTATE_ACTIVE), + State: int32(proj_model.ProjectStateActive), Applications: []*model.Application{ &model.Application{AppID: "AppID", Name: "Name"}, }}, @@ -1114,7 +1114,7 @@ func TestProjectAppChangedAggregate(t *testing.T) { name: "app nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, @@ -1172,7 +1172,7 @@ func TestProjectAppRemovedAggregate(t *testing.T) { existing: &model.Project{ ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", - State: int32(proj_model.PROJECTSTATE_ACTIVE), + State: int32(proj_model.ProjectStateActive), Applications: []*model.Application{ &model.Application{AppID: "AppID", Name: "Name"}, }}, @@ -1204,7 +1204,7 @@ func TestProjectAppRemovedAggregate(t *testing.T) { name: "app nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, @@ -1262,7 +1262,7 @@ func TestProjectAppDeactivatedAggregate(t *testing.T) { existing: &model.Project{ ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", - State: int32(proj_model.PROJECTSTATE_ACTIVE), + State: int32(proj_model.ProjectStateActive), Applications: []*model.Application{ &model.Application{AppID: "AppID", Name: "Name"}, }}, @@ -1294,7 +1294,7 @@ func TestProjectAppDeactivatedAggregate(t *testing.T) { name: "app nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, @@ -1352,7 +1352,7 @@ func TestProjectAppReactivatedAggregate(t *testing.T) { existing: &model.Project{ ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", - State: int32(proj_model.PROJECTSTATE_ACTIVE), + State: int32(proj_model.ProjectStateActive), Applications: []*model.Application{ &model.Application{AppID: "AppID", Name: "Name"}, }}, @@ -1384,7 +1384,7 @@ func TestProjectAppReactivatedAggregate(t *testing.T) { name: "app nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, @@ -1442,7 +1442,7 @@ func TestOIDCConfigchangAggregate(t *testing.T) { existing: &model.Project{ ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", - State: int32(proj_model.PROJECTSTATE_ACTIVE), + State: int32(proj_model.ProjectStateActive), Applications: []*model.Application{ &model.Application{AppID: "AppID", Name: "Name", OIDCConfig: &model.OIDCConfig{AppID: "AppID", AuthMethodType: 1}}, }}, @@ -1474,7 +1474,7 @@ func TestOIDCConfigchangAggregate(t *testing.T) { name: "app nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, @@ -1532,7 +1532,7 @@ func TestOIDCConfigSecretChangeAggregate(t *testing.T) { existing: &model.Project{ ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"}, Name: "ProjectName", - State: int32(proj_model.PROJECTSTATE_ACTIVE), + State: int32(proj_model.ProjectStateActive), Applications: []*model.Application{ &model.Application{AppID: "AppID", Name: "Name", OIDCConfig: &model.OIDCConfig{AppID: "AppID", AuthMethodType: 1}}, }}, @@ -1610,7 +1610,7 @@ func TestProjectGrantAddedAggregate(t *testing.T) { name: "projectgrant added ok", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: &model.ProjectGrant{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, GrantID: "GrantID", GrantedOrgID: "OrgID"}, aggCreator: models.NewAggregateCreator("Test"), }, @@ -1637,7 +1637,7 @@ func TestProjectGrantAddedAggregate(t *testing.T) { name: "grant nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, @@ -1694,7 +1694,7 @@ func TestProjectGrantChangedAggregate(t *testing.T) { existing: &model.Project{ ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", - State: int32(proj_model.PROJECTSTATE_ACTIVE), + State: int32(proj_model.ProjectStateActive), Grants: []*model.ProjectGrant{ &model.ProjectGrant{GrantID: "GrantID", GrantedOrgID: "GrantedOrgID", RoleKeys: []string{"Key"}}, }}, @@ -1727,7 +1727,7 @@ func TestProjectGrantChangedAggregate(t *testing.T) { name: "projectgrant nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, @@ -1785,7 +1785,7 @@ func TestProjectGrantRemovedAggregate(t *testing.T) { existing: &model.Project{ ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", - State: int32(proj_model.PROJECTSTATE_ACTIVE), + State: int32(proj_model.ProjectStateActive), Grants: []*model.ProjectGrant{ &model.ProjectGrant{GrantID: "GrantID", GrantedOrgID: "GrantedOrgID"}, }}, @@ -1818,7 +1818,7 @@ func TestProjectGrantRemovedAggregate(t *testing.T) { name: "projectgrant nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, @@ -1876,7 +1876,7 @@ func TestProjectGrantDeactivatedAggregate(t *testing.T) { existing: &model.Project{ ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", - State: int32(proj_model.PROJECTSTATE_ACTIVE), + State: int32(proj_model.ProjectStateActive), Grants: []*model.ProjectGrant{ &model.ProjectGrant{GrantID: "GrantID", GrantedOrgID: "GrantedOrgID"}, }}, @@ -1909,7 +1909,7 @@ func TestProjectGrantDeactivatedAggregate(t *testing.T) { name: "grant nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, @@ -1967,7 +1967,7 @@ func TestProjectGrantReactivatedAggregate(t *testing.T) { existing: &model.Project{ ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", - State: int32(proj_model.PROJECTSTATE_INACTIVE), + State: int32(proj_model.ProjectStateInactive), Grants: []*model.ProjectGrant{ &model.ProjectGrant{GrantID: "GrantID", GrantedOrgID: "GrantedOrgID"}, }}, @@ -2000,7 +2000,7 @@ func TestProjectGrantReactivatedAggregate(t *testing.T) { name: "grant nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_INACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateInactive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, @@ -2055,7 +2055,7 @@ func TestProjectGrantMemberAddedAggregate(t *testing.T) { name: "project grant member added ok", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: &model.ProjectGrantMember{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, GrantID: "GrantID", UserID: "UserID", Roles: []string{"Roles"}}, aggCreator: models.NewAggregateCreator("Test"), }, @@ -2082,7 +2082,7 @@ func TestProjectGrantMemberAddedAggregate(t *testing.T) { name: "member nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, @@ -2136,7 +2136,7 @@ func TestProjectGrantMemberChangedAggregate(t *testing.T) { name: "project grant member changed ok", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: &model.ProjectGrantMember{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", Roles: []string{"RolesChanged"}}, aggCreator: models.NewAggregateCreator("Test"), }, @@ -2163,7 +2163,7 @@ func TestProjectGrantMemberChangedAggregate(t *testing.T) { name: "member nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, @@ -2217,7 +2217,7 @@ func TestProjectGrantMemberRemovedAggregate(t *testing.T) { name: "project grant member removed ok", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: &model.ProjectGrantMember{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", Roles: []string{"Roles"}}, aggCreator: models.NewAggregateCreator("Test"), }, @@ -2244,7 +2244,7 @@ func TestProjectGrantMemberRemovedAggregate(t *testing.T) { name: "member nil", args: args{ ctx: auth.NewMockContext("orgID", "userID"), - existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.PROJECTSTATE_ACTIVE)}, + existing: &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, Name: "ProjectName", State: int32(proj_model.ProjectStateActive)}, new: nil, aggCreator: models.NewAggregateCreator("Test"), }, diff --git a/internal/project/repository/view/application_view.go b/internal/project/repository/view/application_view.go index 2b660f04ef..caa95c470f 100644 --- a/internal/project/repository/view/application_view.go +++ b/internal/project/repository/view/application_view.go @@ -10,14 +10,14 @@ import ( func ApplicationByID(db *gorm.DB, table, appID string) (*model.ApplicationView, error) { app := new(model.ApplicationView) - query := view.PrepareGetByKey(table, model.ApplicationSearchKey(proj_model.APPLICATIONSEARCHKEY_APP_ID), appID) + query := view.PrepareGetByKey(table, model.ApplicationSearchKey(proj_model.AppSearchKeyAppID), appID) err := query(db, app) return app, err } func ApplicationByOIDCClientID(db *gorm.DB, table, clientID string) (*model.ApplicationView, error) { app := new(model.ApplicationView) - clientIDQuery := model.ApplicationSearchQuery{Key: proj_model.APPLICATIONSEARCHKEY_OIDC_CLIENT_ID, Value: clientID, Method: global_model.SEARCHMETHOD_EQUALS} + clientIDQuery := model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyOIDCClientID, Value: clientID, Method: global_model.SearchMethodEquals} query := view.PrepareGetByQuery(table, clientIDQuery) err := query(db, app) return app, err @@ -25,8 +25,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.APPLICATIONSEARCHKEY_PROJECT_ID, Value: projectID, Method: global_model.SEARCHMETHOD_EQUALS} - appNameQuery := model.ApplicationSearchQuery{Key: proj_model.APPLICATIONSEARCHKEY_NAME, Value: appName, Method: global_model.SEARCHMETHOD_EQUALS} + 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} query := view.PrepareGetByQuery(table, projectIDQuery, appNameQuery) err := query(db, app) return app, err @@ -45,6 +45,6 @@ func PutApplication(db *gorm.DB, table string, app *model.ApplicationView) error } func DeleteApplication(db *gorm.DB, table, appID string) error { - delete := view.PrepareDeleteByKey(table, model.ApplicationSearchKey(proj_model.APPLICATIONSEARCHKEY_APP_ID), appID) + delete := view.PrepareDeleteByKey(table, model.ApplicationSearchKey(proj_model.AppSearchKeyAppID), appID) return delete(db) } diff --git a/internal/project/repository/view/model/application.go b/internal/project/repository/view/model/application.go index e4ced437fb..fd219742f4 100644 --- a/internal/project/repository/view/model/application.go +++ b/internal/project/repository/view/model/application.go @@ -136,9 +136,9 @@ func (a *ApplicationView) AppendEvent(event *models.Event) (err error) { es_model.ApplicationChanged: err = a.SetData(event) case es_model.ApplicationDeactivated: - a.State = int32(model.APPSTATE_INACTIVE) + a.State = int32(model.AppStateInactive) case es_model.ApplicationReactivated: - a.State = int32(model.APPSTATE_ACTIVE) + a.State = int32(model.AppStateActive) } return err } diff --git a/internal/project/repository/view/model/application_query.go b/internal/project/repository/view/model/application_query.go index fd3957fdcc..3a7b583ea2 100644 --- a/internal/project/repository/view/model/application_query.go +++ b/internal/project/repository/view/model/application_query.go @@ -8,7 +8,7 @@ import ( type ApplicationSearchRequest proj_model.ApplicationSearchRequest type ApplicationSearchQuery proj_model.ApplicationSearchQuery -type ApplicationSearchKey proj_model.ApplicationSearchKey +type ApplicationSearchKey proj_model.AppSearchKey func (req ApplicationSearchRequest) GetLimit() uint64 { return req.Limit @@ -19,7 +19,7 @@ func (req ApplicationSearchRequest) GetOffset() uint64 { } func (req ApplicationSearchRequest) GetSortingColumn() view.ColumnKey { - if req.SortingColumn == proj_model.APPLICATIONSEARCHKEY_UNSPECIFIED { + if req.SortingColumn == proj_model.AppSearchKeyUnspecified { return nil } return ApplicationSearchKey(req.SortingColumn) @@ -50,14 +50,14 @@ func (req ApplicationSearchQuery) GetValue() interface{} { } func (key ApplicationSearchKey) ToColumnName() string { - switch proj_model.ApplicationSearchKey(key) { - case proj_model.APPLICATIONSEARCHKEY_APP_ID: + switch proj_model.AppSearchKey(key) { + case proj_model.AppSearchKeyAppID: return ApplicationKeyID - case proj_model.APPLICATIONSEARCHKEY_NAME: + case proj_model.AppSearchKeyName: return ApplicationKeyName - case proj_model.APPLICATIONSEARCHKEY_PROJECT_ID: + case proj_model.AppSearchKeyProjectID: return ApplicationKeyProjectID - case proj_model.APPLICATIONSEARCHKEY_OIDC_CLIENT_ID: + case proj_model.AppSearchKeyOIDCClientID: return ApplicationKeyOIDCClientID default: return "" diff --git a/internal/project/repository/view/model/application_test.go b/internal/project/repository/view/model/application_test.go index 375e9ca758..ae131ab5f4 100644 --- a/internal/project/repository/view/model/application_test.go +++ b/internal/project/repository/view/model/application_test.go @@ -34,47 +34,47 @@ func TestApplicationAppendEvent(t *testing.T) { event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.ApplicationAdded, Data: mockAppData(&es_model.Application{Name: "AppName"})}, app: &ApplicationView{}, }, - result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.APPSTATE_ACTIVE)}, + result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.AppStateActive)}, }, { name: "append changed app event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.ApplicationChanged, Data: mockAppData(&es_model.Application{Name: "AppNameChanged"})}, - app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.APPSTATE_ACTIVE)}, + app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.AppStateActive)}, }, - result: &ApplicationView{ProjectID: "AggregateID", Name: "AppNameChanged", State: int32(model.APPSTATE_ACTIVE)}, + result: &ApplicationView{ProjectID: "AggregateID", Name: "AppNameChanged", State: int32(model.AppStateActive)}, }, { name: "append deactivate app event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.ApplicationDeactivated}, - app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.APPSTATE_ACTIVE)}, + app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.AppStateActive)}, }, - result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.APPSTATE_INACTIVE)}, + result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.AppStateInactive)}, }, { name: "append reactivate app event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.ApplicationReactivated}, - app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.APPSTATE_INACTIVE)}, + app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.AppStateInactive)}, }, - result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.APPSTATE_ACTIVE)}, + result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.AppStateActive)}, }, { name: "append added oidc config event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.OIDCConfigAdded, Data: mockOIDCConfigData(&es_model.OIDCConfig{ClientID: "clientID"})}, - app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.APPSTATE_ACTIVE)}, + app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.AppStateActive)}, }, - result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", IsOIDC: true, OIDCClientID: "clientID", State: int32(model.APPSTATE_ACTIVE)}, + result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", IsOIDC: true, OIDCClientID: "clientID", State: int32(model.AppStateActive)}, }, { name: "append changed oidc config event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.OIDCConfigAdded, Data: mockOIDCConfigData(&es_model.OIDCConfig{ClientID: "clientIDChanged"})}, - app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", OIDCClientID: "clientID", State: int32(model.APPSTATE_ACTIVE)}, + app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", OIDCClientID: "clientID", State: int32(model.AppStateActive)}, }, - result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", IsOIDC: true, OIDCClientID: "clientIDChanged", State: int32(model.APPSTATE_ACTIVE)}, + result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", IsOIDC: true, OIDCClientID: "clientIDChanged", State: int32(model.AppStateActive)}, }, } for _, tt := range tests { diff --git a/internal/project/repository/view/model/project.go b/internal/project/repository/view/model/project.go index f6e3c0f363..e496dd3349 100644 --- a/internal/project/repository/view/model/project.go +++ b/internal/project/repository/view/model/project.go @@ -63,16 +63,16 @@ func (p *ProjectView) AppendEvent(event *models.Event) (err error) { p.Sequence = event.Sequence switch event.Type { case es_model.ProjectAdded: - p.State = int32(model.PROJECTSTATE_ACTIVE) + p.State = int32(model.ProjectStateActive) p.CreationDate = event.CreationDate p.setRootData(event) err = p.setData(event) case es_model.ProjectChanged: err = p.setData(event) case es_model.ProjectDeactivated: - p.State = int32(model.PROJECTSTATE_INACTIVE) + p.State = int32(model.ProjectStateInactive) case es_model.ProjectReactivated: - p.State = int32(model.PROJECTSTATE_ACTIVE) + p.State = int32(model.ProjectStateActive) } return err } diff --git a/internal/project/repository/view/model/project_grant.go b/internal/project/repository/view/model/project_grant.go index 8c9f5ee5c5..80d386e236 100644 --- a/internal/project/repository/view/model/project_grant.go +++ b/internal/project/repository/view/model/project_grant.go @@ -88,16 +88,16 @@ func (p *ProjectGrantView) AppendEvent(event *models.Event) (err error) { p.Sequence = event.Sequence switch event.Type { case es_model.ProjectGrantAdded: - p.State = int32(model.PROJECTSTATE_ACTIVE) + p.State = int32(model.ProjectStateActive) p.CreationDate = event.CreationDate p.setRootData(event) err = p.setProjectGrantData(event) case es_model.ProjectGrantChanged, es_model.ProjectGrantCascadeChanged: err = p.setProjectGrantData(event) case es_model.ProjectGrantDeactivated: - p.State = int32(model.PROJECTSTATE_INACTIVE) + p.State = int32(model.ProjectStateInactive) case es_model.ProjectGrantReactivated: - p.State = int32(model.PROJECTSTATE_ACTIVE) + p.State = int32(model.ProjectStateActive) } return err } 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 1b4f7019f9..1cae740564 100644 --- a/internal/project/repository/view/model/project_grant_member_query.go +++ b/internal/project/repository/view/model/project_grant_member_query.go @@ -19,7 +19,7 @@ func (req ProjectGrantMemberSearchRequest) GetOffset() uint64 { } func (req ProjectGrantMemberSearchRequest) GetSortingColumn() view.ColumnKey { - if req.SortingColumn == proj_model.PROJECTGRANTMEMBERSEARCHKEY_UNSPECIFIED { + if req.SortingColumn == proj_model.ProjectGrantMemberSearchKeyUnspecified { return nil } return ProjectGrantMemberSearchKey(req.SortingColumn) @@ -51,17 +51,17 @@ func (req ProjectGrantMemberSearchQuery) GetValue() interface{} { func (key ProjectGrantMemberSearchKey) ToColumnName() string { switch proj_model.ProjectGrantMemberSearchKey(key) { - case proj_model.PROJECTGRANTMEMBERSEARCHKEY_EMAIL: + case proj_model.ProjectGrantMemberSearchKeyEmail: return ProjectGrantMemberKeyEmail - case proj_model.PROJECTGRANTMEMBERSEARCHKEY_FIRST_NAME: + case proj_model.ProjectGrantMemberSearchKeyFirstName: return ProjectGrantMemberKeyFirstName - case proj_model.PROJECTGRANTMEMBERSEARCHKEY_LAST_NAME: + case proj_model.ProjectGrantMemberSearchKeyLastName: return ProjectGrantMemberKeyLastName - case proj_model.PROJECTGRANTMEMBERSEARCHKEY_USER_NAME: + case proj_model.ProjectGrantMemberSearchKeyUserName: return ProjectGrantMemberKeyUserName - case proj_model.PROJECTGRANTMEMBERSEARCHKEY_USER_ID: + case proj_model.ProjectGrantMemberSearchKeyUserID: return ProjectGrantMemberKeyUserID - case proj_model.PROJECTGRANTMEMBERSEARCHKEY_GRANT_ID: + case proj_model.ProjectGrantMemberSearchKeyGrantID: return ProjectGrantMemberKeyGrantID default: return "" diff --git a/internal/project/repository/view/model/project_grant_query.go b/internal/project/repository/view/model/project_grant_query.go index 417ca345c4..d577a2aacb 100644 --- a/internal/project/repository/view/model/project_grant_query.go +++ b/internal/project/repository/view/model/project_grant_query.go @@ -19,7 +19,7 @@ func (req ProjectGrantSearchRequest) GetOffset() uint64 { } func (req ProjectGrantSearchRequest) GetSortingColumn() view.ColumnKey { - if req.SortingColumn == proj_model.GRANTEDPROJECTSEARCHKEY_UNSPECIFIED { + if req.SortingColumn == proj_model.GrantedProjectSearchKeyUnspecified { return nil } return ProjectGrantSearchKey(req.SortingColumn) @@ -51,17 +51,17 @@ func (req ProjectGrantSearchQuery) GetValue() interface{} { func (key ProjectGrantSearchKey) ToColumnName() string { switch proj_model.ProjectGrantViewSearchKey(key) { - case proj_model.GRANTEDPROJECTSEARCHKEY_NAME: + case proj_model.GrantedProjectSearchKeyName: return ProjectGrantKeyName - case proj_model.GRANTEDPROJECTSEARCHKEY_GRANTID: + case proj_model.GrantedProjectSearchKeyGrantID: return ProjectGrantKeyGrantID - case proj_model.GRANTEDPROJECTSEARCHKEY_ORGID: + case proj_model.GrantedProjectSearchKeyOrgID: return ProjectGrantKeyOrgID - case proj_model.GRANTEDPROJECTSEARCHKEY_PROJECTID: + case proj_model.GrantedProjectSearchKeyProjectID: return ProjectGrantKeyProjectID - case proj_model.GRANTEDPROJECTSEARCHKEY_RESOURCE_OWNER: + case proj_model.GrantedProjectSearchKeyResourceOwner: return ProjectGrantKeyResourceOwner - case proj_model.GRANTEDPROJECTSEARCHKEY_ROLE_KEYS: + case proj_model.GrantedProjectSearchKeyRoleKeys: return ProjectGrantKeyRoleKeys default: return "" diff --git a/internal/project/repository/view/model/project_grant_test.go b/internal/project/repository/view/model/project_grant_test.go index 84d020599a..70e91c1e8e 100644 --- a/internal/project/repository/view/model/project_grant_test.go +++ b/internal/project/repository/view/model/project_grant_test.go @@ -36,31 +36,31 @@ func TestProjectGrantAppendEvent(t *testing.T) { event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.ProjectGrantAdded, ResourceOwner: "OrgID", Data: mockProjectGrantData(&es_model.ProjectGrant{GrantID: "GrantID", GrantedOrgID: "GrantedOrgID", RoleKeys: pq.StringArray{"Role"}})}, project: &ProjectGrantView{}, }, - result: &ProjectGrantView{ProjectID: "AggregateID", ResourceOwner: "OrgID", OrgID: "GrantedOrgID", State: int32(model.PROJECTSTATE_ACTIVE), GrantedRoleKeys: pq.StringArray{"Role"}}, + result: &ProjectGrantView{ProjectID: "AggregateID", ResourceOwner: "OrgID", OrgID: "GrantedOrgID", State: int32(model.ProjectStateActive), GrantedRoleKeys: pq.StringArray{"Role"}}, }, { name: "append change project grant event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.ProjectGrantChanged, ResourceOwner: "OrgID", Data: mockProjectGrantData(&es_model.ProjectGrant{GrantID: "GrantID", RoleKeys: pq.StringArray{"RoleChanged"}})}, - project: &ProjectGrantView{ProjectID: "AggregateID", ResourceOwner: "OrgID", OrgID: "GrantedOrgID", State: int32(model.PROJECTSTATE_ACTIVE), GrantedRoleKeys: pq.StringArray{"Role"}}, + project: &ProjectGrantView{ProjectID: "AggregateID", ResourceOwner: "OrgID", OrgID: "GrantedOrgID", State: int32(model.ProjectStateActive), GrantedRoleKeys: pq.StringArray{"Role"}}, }, - result: &ProjectGrantView{ProjectID: "AggregateID", ResourceOwner: "OrgID", OrgID: "GrantedOrgID", State: int32(model.PROJECTSTATE_ACTIVE), GrantedRoleKeys: pq.StringArray{"RoleChanged"}}, + result: &ProjectGrantView{ProjectID: "AggregateID", ResourceOwner: "OrgID", OrgID: "GrantedOrgID", State: int32(model.ProjectStateActive), GrantedRoleKeys: pq.StringArray{"RoleChanged"}}, }, { name: "append deactivate project grant event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.ProjectGrantDeactivated, ResourceOwner: "OrgID", Data: mockProjectGrantData(&es_model.ProjectGrant{GrantID: "GrantID"})}, - project: &ProjectGrantView{ProjectID: "AggregateID", ResourceOwner: "OrgID", OrgID: "GrantedOrgID", State: int32(model.PROJECTSTATE_ACTIVE), GrantedRoleKeys: pq.StringArray{"Role"}}, + project: &ProjectGrantView{ProjectID: "AggregateID", ResourceOwner: "OrgID", OrgID: "GrantedOrgID", State: int32(model.ProjectStateActive), GrantedRoleKeys: pq.StringArray{"Role"}}, }, - result: &ProjectGrantView{ProjectID: "AggregateID", ResourceOwner: "OrgID", OrgID: "GrantedOrgID", State: int32(model.PROJECTSTATE_INACTIVE), GrantedRoleKeys: pq.StringArray{"Role"}}, + result: &ProjectGrantView{ProjectID: "AggregateID", ResourceOwner: "OrgID", OrgID: "GrantedOrgID", State: int32(model.ProjectStateInactive), GrantedRoleKeys: pq.StringArray{"Role"}}, }, { name: "append reactivate project grant event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.ProjectGrantReactivated, ResourceOwner: "OrgID", Data: mockProjectGrantData(&es_model.ProjectGrant{GrantID: "GrantID"})}, - project: &ProjectGrantView{ProjectID: "AggregateID", ResourceOwner: "OrgID", OrgID: "GrantedOrgID", State: int32(model.PROJECTSTATE_INACTIVE), GrantedRoleKeys: pq.StringArray{"Role"}}, + project: &ProjectGrantView{ProjectID: "AggregateID", ResourceOwner: "OrgID", OrgID: "GrantedOrgID", State: int32(model.ProjectStateInactive), GrantedRoleKeys: pq.StringArray{"Role"}}, }, - result: &ProjectGrantView{ProjectID: "AggregateID", ResourceOwner: "OrgID", OrgID: "GrantedOrgID", State: int32(model.PROJECTSTATE_ACTIVE), GrantedRoleKeys: pq.StringArray{"Role"}}, + result: &ProjectGrantView{ProjectID: "AggregateID", ResourceOwner: "OrgID", OrgID: "GrantedOrgID", State: int32(model.ProjectStateActive), GrantedRoleKeys: pq.StringArray{"Role"}}, }, } for _, tt := range tests { diff --git a/internal/project/repository/view/model/project_member_query.go b/internal/project/repository/view/model/project_member_query.go index db63855bba..e601cdda08 100644 --- a/internal/project/repository/view/model/project_member_query.go +++ b/internal/project/repository/view/model/project_member_query.go @@ -19,7 +19,7 @@ func (req ProjectMemberSearchRequest) GetOffset() uint64 { } func (req ProjectMemberSearchRequest) GetSortingColumn() view.ColumnKey { - if req.SortingColumn == proj_model.PROJECTMEMBERSEARCHKEY_UNSPECIFIED { + if req.SortingColumn == proj_model.ProjectMemberSearchKeyUnspecified { return nil } return ProjectMemberSearchKey(req.SortingColumn) @@ -51,17 +51,17 @@ func (req ProjectMemberSearchQuery) GetValue() interface{} { func (key ProjectMemberSearchKey) ToColumnName() string { switch proj_model.ProjectMemberSearchKey(key) { - case proj_model.PROJECTMEMBERSEARCHKEY_EMAIL: + case proj_model.ProjectMemberSearchKeyEmail: return ProjectMemberKeyEmail - case proj_model.PROJECTMEMBERSEARCHKEY_FIRST_NAME: + case proj_model.ProjectMemberSearchKeyFirstName: return ProjectMemberKeyFirstName - case proj_model.PROJECTMEMBERSEARCHKEY_LAST_NAME: + case proj_model.ProjectMemberSearchKeyLastName: return ProjectMemberKeyLastName - case proj_model.PROJECTMEMBERSEARCHKEY_USER_NAME: + case proj_model.ProjectMemberSearchKeyUserName: return ProjectMemberKeyUserName - case proj_model.PROJECTMEMBERSEARCHKEY_USER_ID: + case proj_model.ProjectMemberSearchKeyUserID: return ProjectMemberKeyUserID - case proj_model.PROJECTMEMBERSEARCHKEY_PROJECT_ID: + case proj_model.ProjectMemberSearchKeyProjectID: return ProjectMemberKeyProjectID default: return "" diff --git a/internal/project/repository/view/model/project_query.go b/internal/project/repository/view/model/project_query.go index 13e7eea1af..4fe013a43c 100644 --- a/internal/project/repository/view/model/project_query.go +++ b/internal/project/repository/view/model/project_query.go @@ -19,7 +19,7 @@ func (req ProjectSearchRequest) GetOffset() uint64 { } func (req ProjectSearchRequest) GetSortingColumn() view.ColumnKey { - if req.SortingColumn == proj_model.PROJECTSEARCHKEY_UNSPECIFIED { + if req.SortingColumn == proj_model.ProjectViewSearchKeyUnspecified { return nil } return ProjectSearchKey(req.SortingColumn) @@ -51,11 +51,11 @@ func (req ProjectSearchQuery) GetValue() interface{} { func (key ProjectSearchKey) ToColumnName() string { switch proj_model.ProjectViewSearchKey(key) { - case proj_model.PROJECTSEARCHKEY_NAME: + case proj_model.ProjectViewSearchKeyName: return ProjectKeyName - case proj_model.PROJECTSEARCHKEY_PROJECTID: + case proj_model.ProjectViewSearchKeyProjectID: return ProjectKeyProjectID - case proj_model.PROJECTSEARCHKEY_RESOURCE_OWNER: + case proj_model.ProjectViewSearchKeyResourceOwner: return ProjectKeyResourceOwner default: return "" diff --git a/internal/project/repository/view/model/project_role_query.go b/internal/project/repository/view/model/project_role_query.go index fedc3d7110..68871d0811 100644 --- a/internal/project/repository/view/model/project_role_query.go +++ b/internal/project/repository/view/model/project_role_query.go @@ -19,7 +19,7 @@ func (req ProjectRoleSearchRequest) GetOffset() uint64 { } func (req ProjectRoleSearchRequest) GetSortingColumn() view.ColumnKey { - if req.SortingColumn == proj_model.PROJECTROLESEARCHKEY_UNSPECIFIED { + if req.SortingColumn == proj_model.ProjectRoleSearchKeyUnspecified { return nil } return ProjectRoleSearchKey(req.SortingColumn) @@ -51,13 +51,13 @@ func (req ProjectRoleSearchQuery) GetValue() interface{} { func (key ProjectRoleSearchKey) ToColumnName() string { switch proj_model.ProjectRoleSearchKey(key) { - case proj_model.PROJECTROLESEARCHKEY_KEY: + case proj_model.ProjectRoleSearchKeyKey: return ProjectRoleKeyKey - case proj_model.PROJECTROLESEARCHKEY_ORGID: + case proj_model.ProjectRoleSearchKeyOrgID: return ProjectRoleKeyOrgID - case proj_model.PROJECTROLESEARCHKEY_PROJECTID: + case proj_model.ProjectRoleSearchKeyProjectID: return ProjectRoleKeyProjectID - case proj_model.PROJECTROLESEARCHKEY_RESOURCEOWNER: + case proj_model.ProjectRoleSearchKeyResourceOwner: return ProjectRoleKeyResourceOwner default: return "" diff --git a/internal/project/repository/view/model/project_test.go b/internal/project/repository/view/model/project_test.go index b22d6d4948..72c0f79405 100644 --- a/internal/project/repository/view/model/project_test.go +++ b/internal/project/repository/view/model/project_test.go @@ -23,31 +23,31 @@ func TestProjectAppendEvent(t *testing.T) { event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.ProjectAdded, ResourceOwner: "OrgID", Data: mockProjectData(&es_model.Project{Name: "ProjectName"})}, project: &ProjectView{}, }, - result: &ProjectView{ProjectID: "AggregateID", ResourceOwner: "OrgID", Name: "ProjectName", State: int32(model.PROJECTSTATE_ACTIVE)}, + result: &ProjectView{ProjectID: "AggregateID", ResourceOwner: "OrgID", Name: "ProjectName", State: int32(model.ProjectStateActive)}, }, { name: "append change project event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.ProjectChanged, ResourceOwner: "OrgID", Data: mockProjectData(&es_model.Project{Name: "ProjectNameChanged"})}, - project: &ProjectView{ProjectID: "AggregateID", ResourceOwner: "OrgID", Name: "ProjectName", State: int32(model.PROJECTSTATE_ACTIVE)}, + project: &ProjectView{ProjectID: "AggregateID", ResourceOwner: "OrgID", Name: "ProjectName", State: int32(model.ProjectStateActive)}, }, - result: &ProjectView{ProjectID: "AggregateID", ResourceOwner: "OrgID", Name: "ProjectNameChanged", State: int32(model.PROJECTSTATE_ACTIVE)}, + result: &ProjectView{ProjectID: "AggregateID", ResourceOwner: "OrgID", Name: "ProjectNameChanged", State: int32(model.ProjectStateActive)}, }, { name: "append project deactivate event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.ProjectDeactivated, ResourceOwner: "OrgID"}, - project: &ProjectView{ProjectID: "AggregateID", ResourceOwner: "OrgID", Name: "ProjectName", State: int32(model.PROJECTSTATE_ACTIVE)}, + project: &ProjectView{ProjectID: "AggregateID", ResourceOwner: "OrgID", Name: "ProjectName", State: int32(model.ProjectStateActive)}, }, - result: &ProjectView{ProjectID: "AggregateID", ResourceOwner: "OrgID", Name: "ProjectName", State: int32(model.PROJECTSTATE_INACTIVE)}, + result: &ProjectView{ProjectID: "AggregateID", ResourceOwner: "OrgID", Name: "ProjectName", State: int32(model.ProjectStateInactive)}, }, { name: "append project reactivate event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.ProjectReactivated, ResourceOwner: "OrgID"}, - project: &ProjectView{ProjectID: "AggregateID", ResourceOwner: "OrgID", Name: "ProjectName", State: int32(model.PROJECTSTATE_INACTIVE)}, + project: &ProjectView{ProjectID: "AggregateID", ResourceOwner: "OrgID", Name: "ProjectName", State: int32(model.ProjectStateInactive)}, }, - result: &ProjectView{ProjectID: "AggregateID", ResourceOwner: "OrgID", Name: "ProjectName", State: int32(model.PROJECTSTATE_ACTIVE)}, + result: &ProjectView{ProjectID: "AggregateID", ResourceOwner: "OrgID", Name: "ProjectName", State: int32(model.ProjectStateActive)}, }, } for _, tt := range tests { diff --git a/internal/project/repository/view/project_grant_member_view.go b/internal/project/repository/view/project_grant_member_view.go index 3276ba9e56..e769c41a58 100644 --- a/internal/project/repository/view/project_grant_member_view.go +++ b/internal/project/repository/view/project_grant_member_view.go @@ -11,8 +11,8 @@ import ( func ProjectGrantMemberByIDs(db *gorm.DB, table, grantID, userID string) (*model.ProjectGrantMemberView, error) { role := new(model.ProjectGrantMemberView) - grantIDQuery := model.ProjectGrantMemberSearchQuery{Key: proj_model.PROJECTGRANTMEMBERSEARCHKEY_GRANT_ID, Value: grantID, Method: global_model.SEARCHMETHOD_EQUALS} - userIDQuery := model.ProjectGrantMemberSearchQuery{Key: proj_model.PROJECTGRANTMEMBERSEARCHKEY_USER_ID, Value: userID, Method: global_model.SEARCHMETHOD_EQUALS} + 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} query := view.PrepareGetByQuery(table, grantIDQuery, userIDQuery) err := query(db, role) return role, err @@ -31,7 +31,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{ - &proj_model.ProjectGrantMemberSearchQuery{Key: proj_model.PROJECTGRANTMEMBERSEARCHKEY_USER_ID, Value: userID, Method: global_model.SEARCHMETHOD_EQUALS}, + &proj_model.ProjectGrantMemberSearchQuery{Key: proj_model.ProjectGrantMemberSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals}, } query := view.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 3e132f116d..30fa9fe793 100644 --- a/internal/project/repository/view/project_grant_view.go +++ b/internal/project/repository/view/project_grant_view.go @@ -11,8 +11,8 @@ import ( func ProjectGrantByProjectAndOrg(db *gorm.DB, table, projectID, orgID string) (*model.ProjectGrantView, error) { project := new(model.ProjectGrantView) - projectIDQuery := model.ProjectGrantSearchQuery{Key: proj_model.GRANTEDPROJECTSEARCHKEY_PROJECTID, Value: projectID, Method: global_model.SEARCHMETHOD_EQUALS} - orgIDQuery := model.ProjectGrantSearchQuery{Key: proj_model.GRANTEDPROJECTSEARCHKEY_ORGID, Value: orgID, Method: global_model.SEARCHMETHOD_EQUALS} + 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} query := view.PrepareGetByQuery(table, projectIDQuery, orgIDQuery) err := query(db, project) return project, err @@ -20,7 +20,7 @@ func ProjectGrantByProjectAndOrg(db *gorm.DB, table, projectID, orgID string) (* func ProjectGrantByID(db *gorm.DB, table, grantID string) (*model.ProjectGrantView, error) { project := new(model.ProjectGrantView) - grantIDQuery := model.ProjectGrantSearchQuery{Key: proj_model.GRANTEDPROJECTSEARCHKEY_GRANTID, Value: grantID, Method: global_model.SEARCHMETHOD_EQUALS} + grantIDQuery := model.ProjectGrantSearchQuery{Key: proj_model.GrantedProjectSearchKeyGrantID, Value: grantID, Method: global_model.SearchMethodEquals} query := view.PrepareGetByQuery(table, grantIDQuery) err := query(db, project) return project, err @@ -29,7 +29,7 @@ func ProjectGrantByID(db *gorm.DB, table, grantID string) (*model.ProjectGrantVi func ProjectGrantsByProjectID(db *gorm.DB, table, projectID string) ([]*model.ProjectGrantView, error) { projects := make([]*model.ProjectGrantView, 0) queries := []*proj_model.ProjectGrantViewSearchQuery{ - &proj_model.ProjectGrantViewSearchQuery{Key: proj_model.GRANTEDPROJECTSEARCHKEY_PROJECTID, Value: projectID, Method: global_model.SEARCHMETHOD_EQUALS}, + &proj_model.ProjectGrantViewSearchQuery{Key: proj_model.GrantedProjectSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}, } query := view.PrepareSearchQuery(table, model.ProjectGrantSearchRequest{Queries: queries}) _, err := query(db, &projects) @@ -42,8 +42,8 @@ func ProjectGrantsByProjectID(db *gorm.DB, table, projectID string) ([]*model.Pr func ProjectGrantsByProjectIDAndRoleKey(db *gorm.DB, table, projectID, roleKey string) ([]*model.ProjectGrantView, error) { projects := make([]*model.ProjectGrantView, 0) queries := []*proj_model.ProjectGrantViewSearchQuery{ - &proj_model.ProjectGrantViewSearchQuery{Key: proj_model.GRANTEDPROJECTSEARCHKEY_PROJECTID, Value: projectID, Method: global_model.SEARCHMETHOD_EQUALS}, - &proj_model.ProjectGrantViewSearchQuery{Key: proj_model.GRANTEDPROJECTSEARCHKEY_ROLE_KEYS, Value: roleKey, Method: global_model.SEARCHMETHOD_LIST_CONTAINS}, + &proj_model.ProjectGrantViewSearchQuery{Key: proj_model.GrantedProjectSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}, + &proj_model.ProjectGrantViewSearchQuery{Key: proj_model.GrantedProjectSearchKeyRoleKeys, Value: roleKey, Method: global_model.SearchMethodListContains}, } query := view.PrepareSearchQuery(table, model.ProjectGrantSearchRequest{Queries: queries}) _, err := query(db, &projects) @@ -69,6 +69,6 @@ func PutProjectGrant(db *gorm.DB, table string, project *model.ProjectGrantView) } func DeleteProjectGrant(db *gorm.DB, table, grantID string) error { - delete := view.PrepareDeleteByKey(table, model.ProjectSearchKey(proj_model.GRANTEDPROJECTSEARCHKEY_GRANTID), grantID) + delete := view.PrepareDeleteByKey(table, model.ProjectSearchKey(proj_model.GrantedProjectSearchKeyGrantID), grantID) return delete(db) } diff --git a/internal/project/repository/view/project_member_view.go b/internal/project/repository/view/project_member_view.go index 7cd01fd0de..43d8291597 100644 --- a/internal/project/repository/view/project_member_view.go +++ b/internal/project/repository/view/project_member_view.go @@ -11,8 +11,8 @@ import ( func ProjectMemberByIDs(db *gorm.DB, table, projectID, userID string) (*model.ProjectMemberView, error) { role := new(model.ProjectMemberView) - projectIDQuery := model.ProjectMemberSearchQuery{Key: proj_model.PROJECTMEMBERSEARCHKEY_PROJECT_ID, Value: projectID, Method: global_model.SEARCHMETHOD_EQUALS} - userIDQuery := model.ProjectMemberSearchQuery{Key: proj_model.PROJECTMEMBERSEARCHKEY_USER_ID, Value: userID, Method: global_model.SEARCHMETHOD_EQUALS} + 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} query := view.PrepareGetByQuery(table, projectIDQuery, userIDQuery) err := query(db, role) return role, err @@ -30,7 +30,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.PROJECTMEMBERSEARCHKEY_USER_ID, Value: userID, Method: global_model.SEARCHMETHOD_EQUALS}, + &proj_model.ProjectMemberSearchQuery{Key: proj_model.ProjectMemberSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals}, } query := view.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 e9245ad9b5..1771766e39 100644 --- a/internal/project/repository/view/project_role_view.go +++ b/internal/project/repository/view/project_role_view.go @@ -11,9 +11,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.PROJECTROLESEARCHKEY_PROJECTID, Value: projectID, Method: global_model.SEARCHMETHOD_EQUALS} - grantIDQuery := model.ProjectRoleSearchQuery{Key: proj_model.PROJECTROLESEARCHKEY_ORGID, Value: orgID, Method: global_model.SEARCHMETHOD_EQUALS} - keyQuery := model.ProjectRoleSearchQuery{Key: proj_model.PROJECTROLESEARCHKEY_KEY, Value: orgID, Method: global_model.SEARCHMETHOD_EQUALS} + 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: orgID, Method: global_model.SearchMethodEquals} query := view.PrepareGetByQuery(table, projectIDQuery, grantIDQuery, keyQuery) err := query(db, role) return role, err @@ -22,9 +22,9 @@ func ProjectRoleByIDs(db *gorm.DB, table, projectID, orgID, key string) (*model. func ResourceOwnerProjectRolesByKey(db *gorm.DB, table, projectID, resourceOwner, key string) ([]*model.ProjectRoleView, error) { roles := make([]*model.ProjectRoleView, 0) queries := []*proj_model.ProjectRoleSearchQuery{ - &proj_model.ProjectRoleSearchQuery{Key: proj_model.PROJECTROLESEARCHKEY_PROJECTID, Value: projectID, Method: global_model.SEARCHMETHOD_EQUALS}, - &proj_model.ProjectRoleSearchQuery{Key: proj_model.PROJECTROLESEARCHKEY_RESOURCEOWNER, Value: resourceOwner, Method: global_model.SEARCHMETHOD_EQUALS}, - &proj_model.ProjectRoleSearchQuery{Key: proj_model.PROJECTROLESEARCHKEY_KEY, Value: key, Method: global_model.SEARCHMETHOD_EQUALS}, + &proj_model.ProjectRoleSearchQuery{Key: proj_model.ProjectRoleSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}, + &proj_model.ProjectRoleSearchQuery{Key: proj_model.ProjectRoleSearchKeyResourceOwner, Value: resourceOwner, Method: global_model.SearchMethodEquals}, + &proj_model.ProjectRoleSearchQuery{Key: proj_model.ProjectRoleSearchKeyKey, Value: key, Method: global_model.SearchMethodEquals}, } query := view.PrepareSearchQuery(table, model.ProjectRoleSearchRequest{Queries: queries}) _, err := query(db, &roles) @@ -37,8 +37,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{ - &proj_model.ProjectRoleSearchQuery{Key: proj_model.PROJECTROLESEARCHKEY_PROJECTID, Value: projectID, Method: global_model.SEARCHMETHOD_EQUALS}, - &proj_model.ProjectRoleSearchQuery{Key: proj_model.PROJECTROLESEARCHKEY_RESOURCEOWNER, Value: resourceOwner, Method: global_model.SEARCHMETHOD_EQUALS}, + &proj_model.ProjectRoleSearchQuery{Key: proj_model.ProjectRoleSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}, + &proj_model.ProjectRoleSearchQuery{Key: proj_model.ProjectRoleSearchKeyResourceOwner, Value: resourceOwner, Method: global_model.SearchMethodEquals}, } query := view.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 15e6a19971..080040204a 100644 --- a/internal/project/repository/view/project_view.go +++ b/internal/project/repository/view/project_view.go @@ -11,7 +11,7 @@ import ( func ProjectByID(db *gorm.DB, table, projectID string) (*model.ProjectView, error) { project := new(model.ProjectView) - projectIDQuery := model.ProjectSearchQuery{Key: proj_model.PROJECTSEARCHKEY_PROJECTID, Value: projectID, Method: global_model.SEARCHMETHOD_EQUALS} + projectIDQuery := model.ProjectSearchQuery{Key: proj_model.ProjectViewSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals} query := view.PrepareGetByQuery(table, projectIDQuery) err := query(db, project) return project, err @@ -20,7 +20,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{ - &proj_model.ProjectViewSearchQuery{Key: proj_model.PROJECTSEARCHKEY_RESOURCE_OWNER, Value: orgID, Method: global_model.SEARCHMETHOD_EQUALS}, + &proj_model.ProjectViewSearchQuery{Key: proj_model.ProjectViewSearchKeyResourceOwner, Value: orgID, Method: global_model.SearchMethodEquals}, } query := view.PrepareSearchQuery(table, model.ProjectSearchRequest{Queries: queries}) _, err := query(db, &projects) @@ -46,6 +46,6 @@ func PutProject(db *gorm.DB, table string, project *model.ProjectView) error { } func DeleteProject(db *gorm.DB, table, projectID string) error { - delete := view.PrepareDeleteByKey(table, model.ProjectSearchKey(proj_model.PROJECTSEARCHKEY_PROJECTID), projectID) + delete := view.PrepareDeleteByKey(table, model.ProjectSearchKey(proj_model.ProjectViewSearchKeyProjectID), projectID) return delete(db) } diff --git a/internal/token/model/token.go b/internal/token/model/token.go index 5e3b6a74d6..f0ab1bd1c4 100644 --- a/internal/token/model/token.go +++ b/internal/token/model/token.go @@ -31,13 +31,13 @@ type TokenSearchRequest struct { type TokenSearchKey int32 const ( - TOKENSEARCHKEY_UNSPECIFIED TokenSearchKey = iota - TOKENSEARCHKEY_TOKEN_ID - TOKENSEARCHKEY_USER_ID - TOKENSEARCHKEY_APPLICATION_ID - TOKENSEARCHKEY_USER_AGENT_ID - TOKENSEARCHKEY_EXPIRATION - TOKENSEARCHKEY_RESOURCEOWNER + TokenSearchKeyUnspecified TokenSearchKey = iota + TokenSearchKeyTokenID + TokenSearchKeyUserID + TokenSearchKeyApplicationID + TokenSearchKeyUserAgentID + TokenSearchKeyExpiration + TokenSearchKeyResourceOwner ) type TokenSearchQuery struct { diff --git a/internal/token/repository/view/model/token_query.go b/internal/token/repository/view/model/token_query.go index 0867270ac1..62089c1a18 100644 --- a/internal/token/repository/view/model/token_query.go +++ b/internal/token/repository/view/model/token_query.go @@ -19,7 +19,7 @@ func (req TokenSearchRequest) GetOffset() uint64 { } func (req TokenSearchRequest) GetSortingColumn() view.ColumnKey { - if req.SortingColumn == token_model.TOKENSEARCHKEY_UNSPECIFIED { + if req.SortingColumn == token_model.TokenSearchKeyUnspecified { return nil } return TokenSearchKey(req.SortingColumn) @@ -51,17 +51,17 @@ func (req TokenSearchQuery) GetValue() interface{} { func (key TokenSearchKey) ToColumnName() string { switch token_model.TokenSearchKey(key) { - case token_model.TOKENSEARCHKEY_TOKEN_ID: + case token_model.TokenSearchKeyTokenID: return TokenKeyTokenID - case token_model.TOKENSEARCHKEY_USER_AGENT_ID: + case token_model.TokenSearchKeyUserAgentID: return TokenKeyUserAgentID - case token_model.TOKENSEARCHKEY_USER_ID: + case token_model.TokenSearchKeyUserID: return TokenKeyUserID - case token_model.TOKENSEARCHKEY_APPLICATION_ID: + case token_model.TokenSearchKeyApplicationID: return TokenKeyApplicationID - case token_model.TOKENSEARCHKEY_EXPIRATION: + case token_model.TokenSearchKeyExpiration: return TokenKeyExpiration - case token_model.TOKENSEARCHKEY_RESOURCEOWNER: + case token_model.TokenSearchKeyResourceOwner: return TokenKeyResourceOwner default: return "" diff --git a/internal/token/repository/view/token.go b/internal/token/repository/view/token.go index 46614f4db5..ad6c1cc2d5 100644 --- a/internal/token/repository/view/token.go +++ b/internal/token/repository/view/token.go @@ -14,7 +14,7 @@ import ( func TokenByID(db *gorm.DB, table, tokenID string) (*model.Token, error) { token := new(model.Token) - query := view.PrepareGetByKey(table, model.TokenSearchKey(token_model.TOKENSEARCHKEY_TOKEN_ID), tokenID) + query := view.PrepareGetByKey(table, model.TokenSearchKey(token_model.TokenSearchKeyTokenID), tokenID) err := query(db, token) return token, err } @@ -36,24 +36,24 @@ func PutToken(db *gorm.DB, table string, token *model.Token) error { } func DeleteToken(db *gorm.DB, table, tokenID string) error { - delete := view.PrepareDeleteByKey(table, model.TokenSearchKey(token_model.TOKENSEARCHKEY_TOKEN_ID), tokenID) + delete := view.PrepareDeleteByKey(table, model.TokenSearchKey(token_model.TokenSearchKeyTokenID), tokenID) return delete(db) } func DeleteSessionTokens(db *gorm.DB, table, agentID, userID string) error { delete := view.PrepareDeleteByKeys(table, - view.Key{Key: model.TokenSearchKey(token_model.TOKENSEARCHKEY_USER_AGENT_ID), Value: agentID}, - view.Key{Key: model.TokenSearchKey(token_model.TOKENSEARCHKEY_USER_ID), Value: userID}, + view.Key{Key: model.TokenSearchKey(token_model.TokenSearchKeyUserAgentID), Value: agentID}, + view.Key{Key: model.TokenSearchKey(token_model.TokenSearchKeyUserID), Value: userID}, ) return delete(db) } func DeleteUserTokens(db *gorm.DB, table, userID string) error { - delete := view.PrepareDeleteByKey(table, model.TokenSearchKey(token_model.TOKENSEARCHKEY_USER_ID), userID) + delete := view.PrepareDeleteByKey(table, model.TokenSearchKey(token_model.TokenSearchKeyUserID), userID) return delete(db) } func DeleteApplicationTokens(db *gorm.DB, table string, appIDs []string) error { - delete := view.PrepareDeleteByKey(table, model.TokenSearchKey(token_model.TOKENSEARCHKEY_APPLICATION_ID), pq.StringArray(appIDs)) + delete := view.PrepareDeleteByKey(table, model.TokenSearchKey(token_model.TokenSearchKeyApplicationID), pq.StringArray(appIDs)) return delete(db) } diff --git a/internal/user/model/mfa.go b/internal/user/model/mfa.go index b8be1bd0fa..6a188c144e 100644 --- a/internal/user/model/mfa.go +++ b/internal/user/model/mfa.go @@ -17,20 +17,20 @@ type OTP struct { type MfaState int32 const ( - MFASTATE_UNSPECIFIED MfaState = iota - MFASTATE_NOTREADY - MFASTATE_READY + MfaStateUnspecified MfaState = iota + MfaStateNotReady + MfaStateReady ) type MultiFactor struct { - Type MFAType + Type MfaType State MfaState } -type MFAType int32 +type MfaType int32 const ( - MFATYPE_UNSPECIFIED MFAType = iota - MFATYPE_OTP - MFATYPE_SMS + MfaTypeUnspecified MfaType = iota + MfaTypeOTP + MfaTypeSMS ) diff --git a/internal/user/model/notify_user.go b/internal/user/model/notify_user.go index 339a177f18..7635b50c0a 100644 --- a/internal/user/model/notify_user.go +++ b/internal/user/model/notify_user.go @@ -36,8 +36,8 @@ type NotifyUserSearchRequest struct { type NotifyUserSearchKey int32 const ( - NOTIFYUSERSEARCHKEY_UNSPECIFIED UserSearchKey = iota - NOTIFYUSERSEARCHKEY_USER_ID + NotifyUserSearchKeyUnspecified UserSearchKey = iota + NotifyUserSearchKeyUserID ) type NotifyUserSearchQuery struct { diff --git a/internal/user/model/password.go b/internal/user/model/password.go index a52fdac5c8..57fb9957d6 100644 --- a/internal/user/model/password.go +++ b/internal/user/model/password.go @@ -27,8 +27,8 @@ type PasswordCode struct { type NotificationType int32 const ( - NOTIFICATIONTYPE_EMAIL NotificationType = iota - NOTIFICATIONTYPE_SMS + NotificationTypeEmail NotificationType = iota + NotificationTypeSms ) func (p *Password) IsValid() bool { diff --git a/internal/user/model/user.go b/internal/user/model/user.go index a2f20b4dfe..2f252a4139 100644 --- a/internal/user/model/user.go +++ b/internal/user/model/user.go @@ -50,22 +50,22 @@ type InitUserCode struct { type UserState int32 const ( - USERSTATE_UNSPECIFIED UserState = iota - USERSTATE_ACTIVE - USERSTATE_INACTIVE - USERSTATE_DELETED - USERSTATE_LOCKED - USERSTATE_SUSPEND - USERSTATE_INITIAL + UserStateUnspecified UserState = iota + UserStateActive + UserStateInactive + UserStateDeleted + UserStateLocked + UserStateSuspend + UserStateInitial ) type Gender int32 const ( - GENDER_UNDEFINED Gender = iota - GENDER_FEMALE - GENDER_MALE - GENDER_DIVERSE + GenderUnspecified Gender = iota + GenderFemale + GenderMale + GenderDiverse ) func (u *User) CheckOrgIamPolicy(policy *org_model.OrgIamPolicy) error { @@ -96,23 +96,23 @@ func (u *User) IsInitialState() bool { } func (u *User) IsActive() bool { - return u.State == USERSTATE_ACTIVE + return u.State == UserStateActive } func (u *User) IsInitial() bool { - return u.State == USERSTATE_INITIAL + return u.State == UserStateInitial } func (u *User) IsInactive() bool { - return u.State == USERSTATE_INACTIVE + return u.State == UserStateInactive } func (u *User) IsLocked() bool { - return u.State == USERSTATE_LOCKED + return u.State == UserStateLocked } func (u *User) IsOTPReady() bool { - return u.OTP != nil && u.OTP.State == MFASTATE_READY + return u.OTP != nil && u.OTP.State == MfaStateReady } func (u *User) HashPasswordIfExisting(policy *policy_model.PasswordComplexityPolicy, passwordAlg crypto.HashAlgorithm, onetime bool) error { diff --git a/internal/user/model/user_session_view.go b/internal/user/model/user_session_view.go index 188a3e05f9..ce6cfccae2 100644 --- a/internal/user/model/user_session_view.go +++ b/internal/user/model/user_session_view.go @@ -36,11 +36,11 @@ type UserSessionSearchRequest struct { type UserSessionSearchKey int32 const ( - USERSESSIONSEARCHKEY_UNSPECIFIED UserSessionSearchKey = iota - USERSESSIONSEARCHKEY_USER_AGENT_ID - USERSESSIONSEARCHKEY_USER_ID - USERSESSIONSEARCHKEY_STATE - USERSESSIONSEARCHKEY_RESOURCEOWNER + UserSessionSearchKeyUnspecified UserSessionSearchKey = iota + UserSessionSearchKeyUserAgentID + UserSessionSearchKeyUserID + UserSessionSearchKeyState + UserSessionSearchKeyResourceOwner ) type UserSessionSearchQuery struct { diff --git a/internal/user/model/user_view.go b/internal/user/model/user_view.go index debf7be753..205654aa72 100644 --- a/internal/user/model/user_view.go +++ b/internal/user/model/user_view.go @@ -55,17 +55,17 @@ type UserSearchRequest struct { type UserSearchKey int32 const ( - USERSEARCHKEY_UNSPECIFIED UserSearchKey = iota - USERSEARCHKEY_USER_ID - USERSEARCHKEY_USER_NAME - USERSEARCHKEY_FIRST_NAME - USERSEARCHKEY_LAST_NAME - USERSEARCHKEY_NICK_NAME - USERSEARCHKEY_DISPLAY_NAME - USERSEARCHKEY_EMAIL - USERSEARCHKEY_STATE - USERSEARCHKEY_RESOURCEOWNER - USERSEARCHKEY_LOGIN_NAMES + UserSearchKeyUnspecified UserSearchKey = iota + UserSearchKeyUserID + UserSearchKeyUserName + UserSearchKeyFirstName + UserSearchKeyLastName + UserSearchKeyNickName + UserSearchKeyDisplayName + UserSearchKeyEmail + UserSearchKeyState + UserSearchKeyResourceOwner + UserSearchKeyLoginNames ) type UserSearchQuery struct { @@ -88,7 +88,7 @@ func (r *UserSearchRequest) EnsureLimit(limit uint64) { } func (r *UserSearchRequest) AppendMyOrgQuery(orgID string) { - r.Queries = append(r.Queries, &UserSearchQuery{Key: USERSEARCHKEY_RESOURCEOWNER, Method: model.SEARCHMETHOD_EQUALS, Value: orgID}) + r.Queries = append(r.Queries, &UserSearchQuery{Key: UserSearchKeyResourceOwner, Method: model.SearchMethodEquals, Value: orgID}) } func (u *UserView) MfaTypesSetupPossible(level req_model.MfaLevel) []req_model.MfaType { @@ -97,7 +97,7 @@ func (u *UserView) MfaTypesSetupPossible(level req_model.MfaLevel) []req_model.M default: fallthrough case req_model.MfaLevelSoftware: - if u.OTPState != MFASTATE_READY { + if u.OTPState != MfaStateReady { types = append(types, req_model.MfaTypeOTP) } //PLANNED: add sms @@ -114,7 +114,7 @@ func (u *UserView) MfaTypesAllowed(level req_model.MfaLevel) []req_model.MfaType default: fallthrough case req_model.MfaLevelSoftware: - if u.OTPState == MFASTATE_READY { + if u.OTPState == MfaStateReady { types = append(types, req_model.MfaTypeOTP) } //PLANNED: add sms diff --git a/internal/user/repository/eventsourcing/eventstore_test.go b/internal/user/repository/eventsourcing/eventstore_test.go index 7d116e458b..629bcee285 100644 --- a/internal/user/repository/eventsourcing/eventstore_test.go +++ b/internal/user/repository/eventsourcing/eventstore_test.go @@ -2,9 +2,9 @@ package eventsourcing import ( "context" + "encoding/json" org_model "github.com/caos/zitadel/internal/org/model" policy_model "github.com/caos/zitadel/internal/policy/model" - "encoding/json" "net" "testing" "time" @@ -539,7 +539,7 @@ func TestDeactivateUser(t *testing.T) { existing: &model.User{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}}, }, res: res{ - user: &model.User{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, State: model.USERSTATE_INACTIVE}, + user: &model.User{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, State: model.UserStateInactive}, }, }, { @@ -606,7 +606,7 @@ func TestReactivateUser(t *testing.T) { existing: &model.User{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}}, }, res: res{ - user: &model.User{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, State: model.USERSTATE_ACTIVE}, + user: &model.User{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, State: model.UserStateActive}, }, }, { @@ -673,7 +673,7 @@ func TestLockUser(t *testing.T) { existing: &model.User{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}}, }, res: res{ - user: &model.User{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, State: model.USERSTATE_LOCKED}, + user: &model.User{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, State: model.UserStateLocked}, }, }, { @@ -740,7 +740,7 @@ func TestUnlockUser(t *testing.T) { existing: &model.User{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}}, }, res: res{ - user: &model.User{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, State: model.USERSTATE_ACTIVE}, + user: &model.User{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, State: model.UserStateActive}, }, }, { @@ -1752,7 +1752,7 @@ func TestRequestSetPassword(t *testing.T) { es: GetMockManipulateUserWithPasswordCodeGen(ctrl, repo_model.User{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}}), ctx: auth.NewMockContext("orgID", "userID"), userID: "AggregateID", - notifyType: model.NOTIFICATIONTYPE_EMAIL, + notifyType: model.NotificationTypeEmail, }, res: res{ password: &model.Password{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, ChangeRequired: false}, @@ -1762,7 +1762,7 @@ func TestRequestSetPassword(t *testing.T) { name: "empty userid", args: args{ es: GetMockManipulateUser(ctrl), - notifyType: model.NOTIFICATIONTYPE_EMAIL, + notifyType: model.NotificationTypeEmail, }, res: res{ errFunc: caos_errs.IsPreconditionFailed, @@ -1774,7 +1774,7 @@ func TestRequestSetPassword(t *testing.T) { es: GetMockManipulateUserNoEvents(ctrl), ctx: auth.NewMockContext("orgID", "userID"), userID: "AggregateID", - notifyType: model.NOTIFICATIONTYPE_EMAIL, + notifyType: model.NotificationTypeEmail, }, res: res{ errFunc: caos_errs.IsNotFound, diff --git a/internal/user/repository/eventsourcing/model/mfa.go b/internal/user/repository/eventsourcing/model/mfa.go index b423c70853..1fe059a6e1 100644 --- a/internal/user/repository/eventsourcing/model/mfa.go +++ b/internal/user/repository/eventsourcing/model/mfa.go @@ -34,13 +34,13 @@ func OTPToModel(otp *OTP) *model.OTP { func (u *User) appendOtpAddedEvent(event *es_models.Event) error { u.OTP = &OTP{ - State: int32(model.MFASTATE_NOTREADY), + State: int32(model.MfaStateNotReady), } return u.OTP.setData(event) } func (u *User) appendOtpVerifiedEvent() { - u.OTP.State = int32(model.MFASTATE_READY) + u.OTP.State = int32(model.MfaStateReady) } func (u *User) appendOtpRemovedEvent() { diff --git a/internal/user/repository/eventsourcing/model/mfa_test.go b/internal/user/repository/eventsourcing/model/mfa_test.go index 820753d168..23e0fab3e5 100644 --- a/internal/user/repository/eventsourcing/model/mfa_test.go +++ b/internal/user/repository/eventsourcing/model/mfa_test.go @@ -26,7 +26,7 @@ func TestAppendMfaOTPAddedEvent(t *testing.T) { otp: &OTP{Secret: &crypto.CryptoValue{KeyID: "KeyID"}}, event: &es_models.Event{}, }, - result: &User{OTP: &OTP{Secret: &crypto.CryptoValue{KeyID: "KeyID"}, State: int32(model.MFASTATE_NOTREADY)}}, + result: &User{OTP: &OTP{Secret: &crypto.CryptoValue{KeyID: "KeyID"}, State: int32(model.MfaStateNotReady)}}, }, } for _, tt := range tests { @@ -61,7 +61,7 @@ func TestAppendMfaOTPVerifyEvent(t *testing.T) { otp: &OTP{Secret: &crypto.CryptoValue{KeyID: "KeyID"}}, event: &es_models.Event{}, }, - result: &User{OTP: &OTP{Secret: &crypto.CryptoValue{KeyID: "KeyID"}, State: int32(model.MFASTATE_READY)}}, + result: &User{OTP: &OTP{Secret: &crypto.CryptoValue{KeyID: "KeyID"}, State: int32(model.MfaStateReady)}}, }, } for _, tt := range tests { diff --git a/internal/user/repository/eventsourcing/model/profile_test.go b/internal/user/repository/eventsourcing/model/profile_test.go index 7e98c6eb09..1a58efed70 100644 --- a/internal/user/repository/eventsourcing/model/profile_test.go +++ b/internal/user/repository/eventsourcing/model/profile_test.go @@ -22,8 +22,8 @@ func TestProfileChanges(t *testing.T) { { name: "all attributes changed", args: args{ - existing: &Profile{UserName: "UserName", FirstName: "FirstName", LastName: "LastName", NickName: "NickName", DisplayName: "DisplayName", PreferredLanguage: language.German, Gender: int32(user_model.GENDER_FEMALE)}, - new: &Profile{UserName: "UserNameChanged", FirstName: "FirstNameChanged", LastName: "LastNameChanged", NickName: "NickNameChanged", DisplayName: "DisplayNameChanged", PreferredLanguage: language.English, Gender: int32(user_model.GENDER_MALE)}, + existing: &Profile{UserName: "UserName", FirstName: "FirstName", LastName: "LastName", NickName: "NickName", DisplayName: "DisplayName", PreferredLanguage: language.German, Gender: int32(user_model.GenderFemale)}, + new: &Profile{UserName: "UserNameChanged", FirstName: "FirstNameChanged", LastName: "LastNameChanged", NickName: "NickNameChanged", DisplayName: "DisplayNameChanged", PreferredLanguage: language.English, Gender: int32(user_model.GenderMale)}, }, res: res{ changesLen: 6, @@ -32,8 +32,8 @@ func TestProfileChanges(t *testing.T) { { name: "no changes", args: args{ - existing: &Profile{UserName: "UserName", FirstName: "FirstName", LastName: "LastName", NickName: "NickName", DisplayName: "DisplayName", PreferredLanguage: language.German, Gender: int32(user_model.GENDER_FEMALE)}, - new: &Profile{UserName: "UserName", FirstName: "FirstName", LastName: "LastName", NickName: "NickName", DisplayName: "DisplayName", PreferredLanguage: language.German, Gender: int32(user_model.GENDER_FEMALE)}, + existing: &Profile{UserName: "UserName", FirstName: "FirstName", LastName: "LastName", NickName: "NickName", DisplayName: "DisplayName", PreferredLanguage: language.German, Gender: int32(user_model.GenderFemale)}, + new: &Profile{UserName: "UserName", FirstName: "FirstName", LastName: "LastName", NickName: "NickName", DisplayName: "DisplayName", PreferredLanguage: language.German, Gender: int32(user_model.GenderFemale)}, }, res: res{ changesLen: 0, @@ -42,8 +42,8 @@ func TestProfileChanges(t *testing.T) { { name: "username changed", args: args{ - existing: &Profile{UserName: "UserName", FirstName: "FirstName", LastName: "LastName", NickName: "NickName", DisplayName: "DisplayName", PreferredLanguage: language.German, Gender: int32(user_model.GENDER_FEMALE)}, - new: &Profile{UserName: "UserNameChanged", FirstName: "FirstName", LastName: "LastName", NickName: "NickName", DisplayName: "DisplayName", PreferredLanguage: language.German, Gender: int32(user_model.GENDER_FEMALE)}, + existing: &Profile{UserName: "UserName", FirstName: "FirstName", LastName: "LastName", NickName: "NickName", DisplayName: "DisplayName", PreferredLanguage: language.German, Gender: int32(user_model.GenderFemale)}, + new: &Profile{UserName: "UserNameChanged", FirstName: "FirstName", LastName: "LastName", NickName: "NickName", DisplayName: "DisplayName", PreferredLanguage: language.German, Gender: int32(user_model.GenderFemale)}, }, res: res{ changesLen: 0, @@ -52,8 +52,8 @@ func TestProfileChanges(t *testing.T) { { name: "empty names", args: args{ - existing: &Profile{UserName: "UserName", FirstName: "FirstName", LastName: "LastName", NickName: "NickName", DisplayName: "DisplayName", PreferredLanguage: language.German, Gender: int32(user_model.GENDER_FEMALE)}, - new: &Profile{UserName: "UserName", FirstName: "", LastName: "", NickName: "NickName", DisplayName: "DisplayName", PreferredLanguage: language.German, Gender: int32(user_model.GENDER_FEMALE)}, + existing: &Profile{UserName: "UserName", FirstName: "FirstName", LastName: "LastName", NickName: "NickName", DisplayName: "DisplayName", PreferredLanguage: language.German, Gender: int32(user_model.GenderFemale)}, + new: &Profile{UserName: "UserName", FirstName: "", LastName: "", NickName: "NickName", DisplayName: "DisplayName", PreferredLanguage: language.German, Gender: int32(user_model.GenderFemale)}, }, res: res{ changesLen: 0, diff --git a/internal/user/repository/eventsourcing/model/user.go b/internal/user/repository/eventsourcing/model/user.go index 2b0689c678..1ee933a9bd 100644 --- a/internal/user/repository/eventsourcing/model/user.go +++ b/internal/user/repository/eventsourcing/model/user.go @@ -180,9 +180,9 @@ func (u *User) AppendEvent(event *es_models.Event) (err error) { func (u *User) ComputeObject() { if u.State == 0 { if u.Email != nil && u.IsEmailVerified { - u.State = int32(model.USERSTATE_ACTIVE) + u.State = int32(model.UserStateActive) } else { - u.State = int32(model.USERSTATE_INITIAL) + u.State = int32(model.UserStateInitial) } } if u.Password != nil && u.Password.ObjectRoot.IsZero() { @@ -211,19 +211,19 @@ func (u *User) setData(event *es_models.Event) error { } func (u *User) appendDeactivatedEvent() { - u.State = int32(model.USERSTATE_INACTIVE) + u.State = int32(model.UserStateInactive) } func (u *User) appendReactivatedEvent() { - u.State = int32(model.USERSTATE_ACTIVE) + u.State = int32(model.UserStateActive) } func (u *User) appendLockedEvent() { - u.State = int32(model.USERSTATE_LOCKED) + u.State = int32(model.UserStateLocked) } func (u *User) appendUnlockedEvent() { - u.State = int32(model.USERSTATE_ACTIVE) + u.State = int32(model.UserStateActive) } func (u *User) appendInitUsercodeCreatedEvent(event *es_models.Event) error { diff --git a/internal/user/repository/eventsourcing/model/user_test.go b/internal/user/repository/eventsourcing/model/user_test.go index 84386f8b26..1b14d194ed 100644 --- a/internal/user/repository/eventsourcing/model/user_test.go +++ b/internal/user/repository/eventsourcing/model/user_test.go @@ -22,7 +22,7 @@ func TestAppendDeactivatedEvent(t *testing.T) { args: args{ user: &User{}, }, - result: &User{State: int32(model.USERSTATE_INACTIVE)}, + result: &User{State: int32(model.UserStateInactive)}, }, } for _, tt := range tests { @@ -49,7 +49,7 @@ func TestAppendReactivatedEvent(t *testing.T) { args: args{ user: &User{}, }, - result: &User{State: int32(model.USERSTATE_ACTIVE)}, + result: &User{State: int32(model.UserStateActive)}, }, } for _, tt := range tests { @@ -76,7 +76,7 @@ func TestAppendLockEvent(t *testing.T) { args: args{ user: &User{}, }, - result: &User{State: int32(model.USERSTATE_LOCKED)}, + result: &User{State: int32(model.UserStateLocked)}, }, } for _, tt := range tests { @@ -103,7 +103,7 @@ func TestAppendUnlockEvent(t *testing.T) { args: args{ user: &User{}, }, - result: &User{State: int32(model.USERSTATE_ACTIVE)}, + result: &User{State: int32(model.UserStateActive)}, }, } for _, tt := range tests { diff --git a/internal/user/repository/view/model/user.go b/internal/user/repository/view/model/user.go index 8f8202028e..0cd52ca308 100644 --- a/internal/user/repository/view/model/user.go +++ b/internal/user/repository/view/model/user.go @@ -194,19 +194,19 @@ func (u *UserView) AppendEvent(event *models.Event) (err error) { case es_model.UserPhoneVerified: u.IsPhoneVerified = true case es_model.UserDeactivated: - u.State = int32(model.USERSTATE_INACTIVE) + u.State = int32(model.UserStateInactive) case es_model.UserReactivated, es_model.UserUnlocked: - u.State = int32(model.USERSTATE_ACTIVE) + u.State = int32(model.UserStateActive) case es_model.UserLocked: - u.State = int32(model.USERSTATE_LOCKED) + u.State = int32(model.UserStateLocked) case es_model.MfaOtpAdded: - u.OTPState = int32(model.MFASTATE_NOTREADY) + u.OTPState = int32(model.MfaStateNotReady) case es_model.MfaOtpVerified: - u.OTPState = int32(model.MFASTATE_READY) + u.OTPState = int32(model.MfaStateReady) u.MfaInitSkipped = time.Time{} case es_model.MfaOtpRemoved: - u.OTPState = int32(model.MFASTATE_UNSPECIFIED) + u.OTPState = int32(model.MfaStateUnspecified) case es_model.MfaInitSkipped: u.MfaInitSkipped = event.CreationDate case es_model.InitializedUserCodeAdded: @@ -244,14 +244,14 @@ func (u *UserView) setPasswordData(event *models.Event) error { } func (u *UserView) ComputeObject() { - if u.State == int32(model.USERSTATE_UNSPECIFIED) || u.State == int32(model.USERSTATE_INITIAL) { + if u.State == int32(model.UserStateUnspecified) || u.State == int32(model.UserStateInitial) { if u.IsEmailVerified { - u.State = int32(model.USERSTATE_ACTIVE) + u.State = int32(model.UserStateActive) } else { - u.State = int32(model.USERSTATE_INITIAL) + u.State = int32(model.UserStateInitial) } } - if u.OTPState == int32(model.MFASTATE_READY) { + if u.OTPState == int32(model.MfaStateReady) { u.MfaMaxSetUp = int32(req_model.MfaLevelSoftware) } } diff --git a/internal/user/repository/view/model/user_query.go b/internal/user/repository/view/model/user_query.go index 1ea7168835..f812587cdc 100644 --- a/internal/user/repository/view/model/user_query.go +++ b/internal/user/repository/view/model/user_query.go @@ -19,7 +19,7 @@ func (req UserSearchRequest) GetOffset() uint64 { } func (req UserSearchRequest) GetSortingColumn() view.ColumnKey { - if req.SortingColumn == usr_model.USERSEARCHKEY_UNSPECIFIED { + if req.SortingColumn == usr_model.UserSearchKeyUnspecified { return nil } return UserSearchKey(req.SortingColumn) @@ -51,25 +51,25 @@ func (req UserSearchQuery) GetValue() interface{} { func (key UserSearchKey) ToColumnName() string { switch usr_model.UserSearchKey(key) { - case usr_model.USERSEARCHKEY_USER_ID: + case usr_model.UserSearchKeyUserID: return UserKeyUserID - case usr_model.USERSEARCHKEY_USER_NAME: + case usr_model.UserSearchKeyUserName: return UserKeyUserName - case usr_model.USERSEARCHKEY_FIRST_NAME: + case usr_model.UserSearchKeyFirstName: return UserKeyFirstName - case usr_model.USERSEARCHKEY_LAST_NAME: + case usr_model.UserSearchKeyLastName: return UserKeyLastName - case usr_model.USERSEARCHKEY_DISPLAY_NAME: + case usr_model.UserSearchKeyDisplayName: return UserKeyDisplayName - case usr_model.USERSEARCHKEY_NICK_NAME: + case usr_model.UserSearchKeyNickName: return UserKeyNickName - case usr_model.USERSEARCHKEY_EMAIL: + case usr_model.UserSearchKeyEmail: return UserKeyEmail - case usr_model.USERSEARCHKEY_STATE: + case usr_model.UserSearchKeyState: return UserKeyState - case usr_model.USERSEARCHKEY_RESOURCEOWNER: + case usr_model.UserSearchKeyResourceOwner: return UserKeyResourceOwner - case usr_model.USERSEARCHKEY_LOGIN_NAMES: + case usr_model.UserSearchKeyLoginNames: return UserKeyLoginNames default: return "" diff --git a/internal/user/repository/view/model/user_session_query.go b/internal/user/repository/view/model/user_session_query.go index 897648cabb..654d206b0f 100644 --- a/internal/user/repository/view/model/user_session_query.go +++ b/internal/user/repository/view/model/user_session_query.go @@ -19,7 +19,7 @@ func (req UserSessionSearchRequest) GetOffset() uint64 { } func (req UserSessionSearchRequest) GetSortingColumn() view.ColumnKey { - if req.SortingColumn == usr_model.USERSESSIONSEARCHKEY_UNSPECIFIED { + if req.SortingColumn == usr_model.UserSessionSearchKeyUnspecified { return nil } return UserSessionSearchKey(req.SortingColumn) @@ -51,13 +51,13 @@ func (req UserSessionSearchQuery) GetValue() interface{} { func (key UserSessionSearchKey) ToColumnName() string { switch usr_model.UserSessionSearchKey(key) { - case usr_model.USERSESSIONSEARCHKEY_USER_AGENT_ID: + case usr_model.UserSessionSearchKeyUserAgentID: return UserSessionKeyUserAgentID - case usr_model.USERSESSIONSEARCHKEY_USER_ID: + case usr_model.UserSessionSearchKeyUserID: return UserSessionKeyUserID - case usr_model.USERSESSIONSEARCHKEY_STATE: + case usr_model.UserSessionSearchKeyState: return UserSessionKeyState - case usr_model.USERSESSIONSEARCHKEY_RESOURCEOWNER: + case usr_model.UserSessionSearchKeyResourceOwner: return UserSessionKeyResourceOwner default: return "" diff --git a/internal/user/repository/view/model/user_test.go b/internal/user/repository/view/model/user_test.go index f7fae956e1..7a3f4e3c0e 100644 --- a/internal/user/repository/view/model/user_test.go +++ b/internal/user/repository/view/model/user_test.go @@ -77,7 +77,7 @@ func TestUserAppendEvent(t *testing.T) { event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.UserAdded, ResourceOwner: "OrgID", Data: mockUserData(getFullUser(nil))}, user: &UserView{}, }, - result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_INITIAL)}, + result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateInitial)}, }, { name: "append added user with password event", @@ -85,7 +85,7 @@ func TestUserAppendEvent(t *testing.T) { event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.UserAdded, ResourceOwner: "OrgID", Data: mockUserData(getFullUser(&es_model.Password{Secret: &crypto.CryptoValue{}}))}, user: &UserView{}, }, - result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_INITIAL), PasswordSet: true}, + result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateInitial), PasswordSet: true}, }, { name: "append added user with password but change required event", @@ -93,135 +93,135 @@ func TestUserAppendEvent(t *testing.T) { event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.UserAdded, ResourceOwner: "OrgID", Data: mockUserData(getFullUser(&es_model.Password{ChangeRequired: true, Secret: &crypto.CryptoValue{}}))}, user: &UserView{}, }, - result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_INITIAL), PasswordSet: true, PasswordChangeRequired: true}, + result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateInitial), PasswordSet: true, PasswordChangeRequired: true}, }, { name: "append password change event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.UserPasswordChanged, ResourceOwner: "OrgID", Data: mockPasswordData(&es_model.Password{Secret: &crypto.CryptoValue{}})}, - user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", IsEmailVerified: true, Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE)}, + user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", IsEmailVerified: true, Phone: "Phone", Country: "Country", State: int32(model.UserStateActive)}, }, - result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", IsEmailVerified: true, Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE), PasswordSet: true}, + result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", IsEmailVerified: true, Phone: "Phone", Country: "Country", State: int32(model.UserStateActive), PasswordSet: true}, }, { name: "append password change with change required event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.UserPasswordChanged, ResourceOwner: "OrgID", Data: mockPasswordData(&es_model.Password{ChangeRequired: true, Secret: &crypto.CryptoValue{}})}, - user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", IsEmailVerified: true, Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE)}, + user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", IsEmailVerified: true, Phone: "Phone", Country: "Country", State: int32(model.UserStateActive)}, }, - result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", IsEmailVerified: true, Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE), PasswordSet: true, PasswordChangeRequired: true}, + result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", IsEmailVerified: true, Phone: "Phone", Country: "Country", State: int32(model.UserStateActive), PasswordSet: true, PasswordChangeRequired: true}, }, { name: "append change user profile event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.UserProfileChanged, ResourceOwner: "OrgID", Data: mockProfileData(&es_model.Profile{FirstName: "FirstNameChanged"})}, - user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_INITIAL)}, + user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateInitial)}, }, - result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstNameChanged", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_INITIAL)}, + result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstNameChanged", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateInitial)}, }, { name: "append change user email event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.UserEmailChanged, ResourceOwner: "OrgID", Data: mockEmailData(&es_model.Email{EmailAddress: "EmailChanged"})}, - user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", IsEmailVerified: true, Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE)}, + user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", IsEmailVerified: true, Phone: "Phone", Country: "Country", State: int32(model.UserStateActive)}, }, - result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "EmailChanged", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE)}, + result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "EmailChanged", Phone: "Phone", Country: "Country", State: int32(model.UserStateActive)}, }, { name: "append verify user email event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.UserEmailVerified, ResourceOwner: "OrgID"}, - user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_INITIAL)}, + user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateInitial)}, }, - result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", IsEmailVerified: true, Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE)}, + result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", IsEmailVerified: true, Phone: "Phone", Country: "Country", State: int32(model.UserStateActive)}, }, { name: "append change user phone event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.UserPhoneChanged, ResourceOwner: "OrgID", Data: mockPhoneData(&es_model.Phone{PhoneNumber: "PhoneChanged"})}, - user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", IsEmailVerified: true, Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE)}, + user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", IsEmailVerified: true, Phone: "Phone", Country: "Country", State: int32(model.UserStateActive)}, }, - result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", IsEmailVerified: true, Phone: "PhoneChanged", Country: "Country", State: int32(model.USERSTATE_ACTIVE)}, + result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", IsEmailVerified: true, Phone: "PhoneChanged", Country: "Country", State: int32(model.UserStateActive)}, }, { name: "append verify user phone event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.UserPhoneVerified, ResourceOwner: "OrgID"}, - user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE)}, + user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateActive)}, }, - result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", IsPhoneVerified: true, Country: "Country", State: int32(model.USERSTATE_ACTIVE)}, + result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", IsPhoneVerified: true, Country: "Country", State: int32(model.UserStateActive)}, }, { name: "append change user address event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.UserAddressChanged, ResourceOwner: "OrgID", Data: mockAddressData(&es_model.Address{Country: "CountryChanged"})}, - user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", IsEmailVerified: true, Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE)}, + user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", IsEmailVerified: true, Phone: "Phone", Country: "Country", State: int32(model.UserStateActive)}, }, - result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", IsEmailVerified: true, Phone: "Phone", Country: "CountryChanged", State: int32(model.USERSTATE_ACTIVE)}, + result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", IsEmailVerified: true, Phone: "Phone", Country: "CountryChanged", State: int32(model.UserStateActive)}, }, { name: "append user deactivate event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.UserDeactivated, ResourceOwner: "OrgID"}, - user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE)}, + user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateActive)}, }, - result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_INACTIVE)}, + result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateInactive)}, }, { name: "append user reactivate event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.UserReactivated, ResourceOwner: "OrgID"}, - user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_INACTIVE)}, + user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateInactive)}, }, - result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE)}, + result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateActive)}, }, { name: "append user lock event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.UserLocked, ResourceOwner: "OrgID"}, - user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE)}, + user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateActive)}, }, - result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_LOCKED)}, + result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateLocked)}, }, { name: "append user unlock event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.UserUnlocked, ResourceOwner: "OrgID"}, - user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_LOCKED)}, + user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateLocked)}, }, - result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE)}, + result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateActive)}, }, { name: "append user add otp event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.MfaOtpAdded, ResourceOwner: "OrgID"}, - user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE)}, + user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateActive)}, }, - result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE), OTPState: int32(model.MFASTATE_NOTREADY)}, + result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateActive), OTPState: int32(model.MfaStateNotReady)}, }, { name: "append user verify otp event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.MfaOtpVerified, ResourceOwner: "OrgID"}, - user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE), OTPState: int32(model.MFASTATE_NOTREADY)}, + user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateActive), OTPState: int32(model.MfaStateNotReady)}, }, - result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE), OTPState: int32(model.MFASTATE_READY)}, + result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateActive), OTPState: int32(model.MfaStateReady)}, }, { name: "append user remove otp event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.MfaOtpRemoved, ResourceOwner: "OrgID"}, - user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE), OTPState: int32(model.MFASTATE_READY)}, + user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateActive), OTPState: int32(model.MfaStateReady)}, }, - result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE), OTPState: int32(model.MFASTATE_UNSPECIFIED)}, + result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateActive), OTPState: int32(model.MfaStateUnspecified)}, }, { name: "append mfa init skipped event", args: args{ event: &es_models.Event{Sequence: 1, CreationDate: time.Now().UTC(), Type: es_model.MfaInitSkipped, AggregateID: "AggregateID", ResourceOwner: "OrgID"}, - user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE)}, + user: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateActive)}, }, - result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.USERSTATE_ACTIVE), MfaInitSkipped: time.Now().UTC()}, + result: &UserView{ID: "AggregateID", ResourceOwner: "OrgID", UserName: "UserName", FirstName: "FirstName", LastName: "LastName", Email: "Email", Phone: "Phone", Country: "Country", State: int32(model.UserStateActive), MfaInitSkipped: time.Now().UTC()}, }, } for _, tt := range tests { diff --git a/internal/user/repository/view/notify_user.go b/internal/user/repository/view/notify_user.go index 8599dccf37..325cb08223 100644 --- a/internal/user/repository/view/notify_user.go +++ b/internal/user/repository/view/notify_user.go @@ -9,7 +9,7 @@ import ( func NotifyUserByID(db *gorm.DB, table, userID string) (*model.NotifyUser, error) { user := new(model.NotifyUser) - query := view.PrepareGetByKey(table, model.UserSearchKey(usr_model.NOTIFYUSERSEARCHKEY_USER_ID), userID) + query := view.PrepareGetByKey(table, model.UserSearchKey(usr_model.NotifyUserSearchKeyUserID), userID) err := query(db, user) return user, err } @@ -20,6 +20,6 @@ func PutNotifyUser(db *gorm.DB, table string, project *model.NotifyUser) error { } func DeleteNotifyUser(db *gorm.DB, table, userID string) error { - delete := view.PrepareDeleteByKey(table, model.UserSearchKey(usr_model.NOTIFYUSERSEARCHKEY_USER_ID), userID) + delete := view.PrepareDeleteByKey(table, model.UserSearchKey(usr_model.NotifyUserSearchKeyUserID), userID) return delete(db) } diff --git a/internal/user/repository/view/user_session_view.go b/internal/user/repository/view/user_session_view.go index e07c08efde..fa583aa29f 100644 --- a/internal/user/repository/view/user_session_view.go +++ b/internal/user/repository/view/user_session_view.go @@ -12,13 +12,13 @@ import ( func UserSessionByIDs(db *gorm.DB, table, agentID, userID string) (*model.UserSessionView, error) { userSession := new(model.UserSessionView) userAgentQuery := model.UserSessionSearchQuery{ - Key: usr_model.USERSESSIONSEARCHKEY_USER_AGENT_ID, - Method: global_model.SEARCHMETHOD_EQUALS, + Key: usr_model.UserSessionSearchKeyUserAgentID, + Method: global_model.SearchMethodEquals, Value: agentID, } userQuery := model.UserSessionSearchQuery{ - Key: usr_model.USERSESSIONSEARCHKEY_USER_ID, - Method: global_model.SEARCHMETHOD_EQUALS, + Key: usr_model.UserSessionSearchKeyUserID, + Method: global_model.SearchMethodEquals, Value: userID, } query := view.PrepareGetByQuery(table, userAgentQuery, userQuery) @@ -29,8 +29,8 @@ func UserSessionByIDs(db *gorm.DB, table, agentID, userID string) (*model.UserSe func UserSessionsByUserID(db *gorm.DB, table, userID string) ([]*model.UserSessionView, error) { userSessions := make([]*model.UserSessionView, 0) userAgentQuery := &usr_model.UserSessionSearchQuery{ - Key: usr_model.USERSESSIONSEARCHKEY_USER_ID, - Method: global_model.SEARCHMETHOD_EQUALS, + Key: usr_model.UserSessionSearchKeyUserID, + Method: global_model.SearchMethodEquals, Value: userID, } query := view.PrepareSearchQuery(table, model.UserSessionSearchRequest{ @@ -43,8 +43,8 @@ func UserSessionsByUserID(db *gorm.DB, table, userID string) ([]*model.UserSessi func UserSessionsByAgentID(db *gorm.DB, table, agentID string) ([]*model.UserSessionView, error) { userSessions := make([]*model.UserSessionView, 0) userAgentQuery := &usr_model.UserSessionSearchQuery{ - Key: usr_model.USERSESSIONSEARCHKEY_USER_AGENT_ID, - Method: global_model.SEARCHMETHOD_EQUALS, + Key: usr_model.UserSessionSearchKeyUserAgentID, + Method: global_model.SearchMethodEquals, Value: agentID, } query := view.PrepareSearchQuery(table, model.UserSessionSearchRequest{ @@ -60,6 +60,6 @@ func PutUserSession(db *gorm.DB, table string, session *model.UserSessionView) e } func DeleteUserSessions(db *gorm.DB, table, userID string) error { - delete := view.PrepareDeleteByKey(table, model.UserSessionSearchKey(usr_model.USERSESSIONSEARCHKEY_USER_ID), userID) + delete := view.PrepareDeleteByKey(table, model.UserSessionSearchKey(usr_model.UserSessionSearchKeyUserID), userID) return delete(db) } diff --git a/internal/user/repository/view/user_view.go b/internal/user/repository/view/user_view.go index 0892250ef9..b6a8d9d27e 100644 --- a/internal/user/repository/view/user_view.go +++ b/internal/user/repository/view/user_view.go @@ -12,7 +12,7 @@ import ( func UserByID(db *gorm.DB, table, userID string) (*model.UserView, error) { user := new(model.UserView) - query := view.PrepareGetByKey(table, model.UserSearchKey(usr_model.USERSEARCHKEY_USER_ID), userID) + query := view.PrepareGetByKey(table, model.UserSearchKey(usr_model.UserSearchKeyUserID), userID) err := query(db, user) if caos_errs.IsNotFound(err) { return nil, caos_errs.ThrowNotFound(nil, "VIEW-sj8Sw", "Errors.User.NotFound") @@ -22,7 +22,7 @@ func UserByID(db *gorm.DB, table, userID string) (*model.UserView, error) { func UserByUserName(db *gorm.DB, table, userName string) (*model.UserView, error) { user := new(model.UserView) - query := view.PrepareGetByKey(table, model.UserSearchKey(usr_model.USERSEARCHKEY_USER_NAME), userName) + query := view.PrepareGetByKey(table, model.UserSearchKey(usr_model.UserSearchKeyUserName), userName) err := query(db, user) if caos_errs.IsNotFound(err) { return nil, caos_errs.ThrowNotFound(nil, "VIEW-Lso9s", "Errors.User.NotFound") @@ -33,8 +33,8 @@ func UserByUserName(db *gorm.DB, table, userName string) (*model.UserView, error func UserByLoginName(db *gorm.DB, table, loginName string) (*model.UserView, error) { user := new(model.UserView) loginNameQuery := &model.UserSearchQuery{ - Key: usr_model.USERSEARCHKEY_LOGIN_NAMES, - Method: global_model.SEARCHMETHOD_LIST_CONTAINS, + Key: usr_model.UserSearchKeyLoginNames, + Method: global_model.SearchMethodListContains, Value: loginName, } query := view.PrepareGetByQuery(table, loginNameQuery) @@ -45,8 +45,8 @@ func UserByLoginName(db *gorm.DB, table, loginName string) (*model.UserView, err func UsersByOrgID(db *gorm.DB, table, orgID string) ([]*model.UserView, error) { users := make([]*model.UserView, 0) orgIDQuery := &usr_model.UserSearchQuery{ - Key: usr_model.USERSEARCHKEY_RESOURCEOWNER, - Method: global_model.SEARCHMETHOD_EQUALS, + Key: usr_model.UserSearchKeyResourceOwner, + Method: global_model.SearchMethodEquals, Value: orgID, } query := view.PrepareSearchQuery(table, model.UserSearchRequest{ @@ -68,7 +68,7 @@ func SearchUsers(db *gorm.DB, table string, req *usr_model.UserSearchRequest) ([ func GetGlobalUserByEmail(db *gorm.DB, table, email string) (*model.UserView, error) { user := new(model.UserView) - query := view.PrepareGetByKey(table, model.UserSearchKey(usr_model.USERSEARCHKEY_EMAIL), email) + query := view.PrepareGetByKey(table, model.UserSearchKey(usr_model.UserSearchKeyEmail), email) err := query(db, user) if caos_errs.IsNotFound(err) { return nil, caos_errs.ThrowNotFound(nil, "VIEW-8uWer", "Errors.User.NotFound") @@ -78,7 +78,7 @@ func GetGlobalUserByEmail(db *gorm.DB, table, email string) (*model.UserView, er func IsUserUnique(db *gorm.DB, table, userName, email string) (bool, error) { user := new(model.UserView) - query := view.PrepareGetByKey(table, model.UserSearchKey(usr_model.USERSEARCHKEY_EMAIL), email) + query := view.PrepareGetByKey(table, model.UserSearchKey(usr_model.UserSearchKeyEmail), email) err := query(db, user) if err != nil && !caos_errs.IsNotFound(err) { return false, err @@ -86,7 +86,7 @@ func IsUserUnique(db *gorm.DB, table, userName, email string) (bool, error) { if user != nil { return false, nil } - query = view.PrepareGetByKey(table, model.UserSearchKey(usr_model.USERSEARCHKEY_USER_NAME), email) + query = view.PrepareGetByKey(table, model.UserSearchKey(usr_model.UserSearchKeyUserName), email) err = query(db, user) if err != nil && !caos_errs.IsNotFound(err) { return false, err @@ -99,10 +99,10 @@ func UserMfas(db *gorm.DB, table, userID string) ([]*usr_model.MultiFactor, erro if err != nil { return nil, err } - if user.OTPState == int32(usr_model.MFASTATE_UNSPECIFIED) { + if user.OTPState == int32(usr_model.MfaStateUnspecified) { return []*usr_model.MultiFactor{}, nil } - return []*usr_model.MultiFactor{&usr_model.MultiFactor{Type: usr_model.MFATYPE_OTP, State: usr_model.MfaState(user.OTPState)}}, nil + return []*usr_model.MultiFactor{&usr_model.MultiFactor{Type: usr_model.MfaTypeOTP, State: usr_model.MfaState(user.OTPState)}}, nil } func PutUser(db *gorm.DB, table string, project *model.UserView) error { @@ -111,6 +111,6 @@ func PutUser(db *gorm.DB, table string, project *model.UserView) error { } func DeleteUser(db *gorm.DB, table, userID string) error { - delete := view.PrepareDeleteByKey(table, model.UserSearchKey(usr_model.USERSEARCHKEY_USER_ID), userID) + delete := view.PrepareDeleteByKey(table, model.UserSearchKey(usr_model.UserSearchKeyUserID), userID) return delete(db) } diff --git a/internal/usergrant/model/user_grant.go b/internal/usergrant/model/user_grant.go index 4ec178a6c6..a53a5dccde 100644 --- a/internal/usergrant/model/user_grant.go +++ b/internal/usergrant/model/user_grant.go @@ -14,9 +14,9 @@ type UserGrant struct { type UserGrantState int32 const ( - USERGRANTSTATE_ACTIVE UserGrantState = iota - USERGRANTSTATE_INACTIVE - USERGRANTSTATE_REMOVED + UserGrantStateActive UserGrantState = iota + UserGrantStateInactive + UserGrantStateRemoved ) func (u *UserGrant) IsValid() bool { @@ -24,11 +24,11 @@ func (u *UserGrant) IsValid() bool { } func (u *UserGrant) IsActive() bool { - return u.State == USERGRANTSTATE_ACTIVE + return u.State == UserGrantStateActive } func (u *UserGrant) IsInactive() bool { - return u.State == USERGRANTSTATE_INACTIVE + return u.State == UserGrantStateInactive } func (u *UserGrant) RemoveRoleKeyIfExisting(key string) bool { diff --git a/internal/usergrant/model/user_grant_view.go b/internal/usergrant/model/user_grant_view.go index 80201663cd..9b6ff37df9 100644 --- a/internal/usergrant/model/user_grant_view.go +++ b/internal/usergrant/model/user_grant_view.go @@ -37,14 +37,14 @@ type UserGrantSearchRequest struct { type UserGrantSearchKey int32 const ( - USERGRANTSEARCHKEY_UNSPECIFIED UserGrantSearchKey = iota - USERGRANTSEARCHKEY_USER_ID - USERGRANTSEARCHKEY_PROJECT_ID - USERGRANTSEARCHKEY_RESOURCEOWNER - USERGRANTSEARCHKEY_STATE - USERGRANTSEARCHKEY_GRANT_ID - USERGRANTSEARCHKEY_ORG_NAME - USERGRANTSEARCHKEY_ROLE_KEY + UserGrantSearchKeyUnspecified UserGrantSearchKey = iota + UserGrantSearchKeyUserID + UserGrantSearchKeyProjectID + UserGrantSearchKeyResourceOwner + UserGrantSearchKeyState + UserGrantSearchKeyGrantID + UserGrantSearchKeyOrgName + UserGrantSearchKeyRoleKey ) type UserGrantSearchQuery struct { @@ -67,5 +67,5 @@ func (r *UserGrantSearchRequest) EnsureLimit(limit uint64) { } func (r *UserGrantSearchRequest) AppendMyOrgQuery(orgID string) { - r.Queries = append(r.Queries, &UserGrantSearchQuery{Key: USERGRANTSEARCHKEY_RESOURCEOWNER, Method: model.SEARCHMETHOD_EQUALS, Value: orgID}) + r.Queries = append(r.Queries, &UserGrantSearchQuery{Key: UserGrantSearchKeyResourceOwner, Method: model.SearchMethodEquals, Value: orgID}) } diff --git a/internal/usergrant/repository/eventsourcing/eventstore.go b/internal/usergrant/repository/eventsourcing/eventstore.go index cc3f815914..03bf61da27 100644 --- a/internal/usergrant/repository/eventsourcing/eventstore.go +++ b/internal/usergrant/repository/eventsourcing/eventstore.go @@ -48,7 +48,7 @@ func (es *UserGrantEventStore) UserGrantByID(ctx context.Context, id string) (*g return nil, err } es.userGrantCache.cacheUserGrant(grant) - if grant.State == int32(grant_model.USERGRANTSTATE_REMOVED) { + if grant.State == int32(grant_model.UserGrantStateRemoved) { return nil, caos_errs.ThrowNotFound(nil, "EVENT-2ks8d", "Errors.UserGrant.NotFound") } return model.UserGrantToModel(grant), nil diff --git a/internal/usergrant/repository/eventsourcing/eventstore_test.go b/internal/usergrant/repository/eventsourcing/eventstore_test.go index 8ac3fe2bbf..828885b967 100644 --- a/internal/usergrant/repository/eventsourcing/eventstore_test.go +++ b/internal/usergrant/repository/eventsourcing/eventstore_test.go @@ -317,7 +317,7 @@ func TestDeactivateUserGrant(t *testing.T) { res: res{ result: &model.UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, ProjectID: "ProjectID", - State: model.USERGRANTSTATE_INACTIVE, + State: model.UserGrantStateInactive, }, }, }, @@ -392,7 +392,7 @@ func TestReactivateUserGrant(t *testing.T) { }, res: res{ result: &model.UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, - State: model.USERGRANTSTATE_ACTIVE, + State: model.UserGrantStateActive, }, }, }, diff --git a/internal/usergrant/repository/eventsourcing/model/user_grant.go b/internal/usergrant/repository/eventsourcing/model/user_grant.go index 32b1eea0d1..8a35202973 100644 --- a/internal/usergrant/repository/eventsourcing/model/user_grant.go +++ b/internal/usergrant/repository/eventsourcing/model/user_grant.go @@ -72,12 +72,12 @@ func (g *UserGrant) AppendEvent(event *es_models.Event) error { UserGrantCascadeChanged: return g.setData(event) case UserGrantDeactivated: - g.appendGrantStateEvent(model.USERGRANTSTATE_INACTIVE) + g.appendGrantStateEvent(model.UserGrantStateInactive) case UserGrantReactivated: - g.appendGrantStateEvent(model.USERGRANTSTATE_ACTIVE) + g.appendGrantStateEvent(model.UserGrantStateActive) case UserGrantRemoved, UserGrantCascadeRemoved: - g.appendGrantStateEvent(model.USERGRANTSTATE_REMOVED) + g.appendGrantStateEvent(model.UserGrantStateRemoved) } return nil } diff --git a/internal/usergrant/repository/eventsourcing/model/user_grant_test.go b/internal/usergrant/repository/eventsourcing/model/user_grant_test.go index 0de4b304fc..b83cafa86e 100644 --- a/internal/usergrant/repository/eventsourcing/model/user_grant_test.go +++ b/internal/usergrant/repository/eventsourcing/model/user_grant_test.go @@ -24,9 +24,9 @@ func TestAppendGrantStateEvent(t *testing.T) { existing: &UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID", RoleKeys: []string{"Key"}}, grant: &UserGrantID{GrantID: "GrantID"}, event: &es_models.Event{}, - state: model.USERGRANTSTATE_INACTIVE, + state: model.UserGrantStateInactive, }, - result: &UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID", RoleKeys: []string{"Key"}, State: int32(model.USERGRANTSTATE_INACTIVE)}, + result: &UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID", RoleKeys: []string{"Key"}, State: int32(model.UserGrantStateInactive)}, }, { name: "append reactivate grant event", @@ -34,9 +34,9 @@ func TestAppendGrantStateEvent(t *testing.T) { existing: &UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID", RoleKeys: []string{"Key"}}, grant: &UserGrantID{GrantID: "GrantID"}, event: &es_models.Event{}, - state: model.USERGRANTSTATE_ACTIVE, + state: model.UserGrantStateActive, }, - result: &UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID", RoleKeys: []string{"Key"}, State: int32(model.USERGRANTSTATE_ACTIVE)}, + result: &UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID", RoleKeys: []string{"Key"}, State: int32(model.UserGrantStateActive)}, }, { name: "append remove grant event", @@ -44,9 +44,9 @@ func TestAppendGrantStateEvent(t *testing.T) { existing: &UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID", RoleKeys: []string{"Key"}}, grant: &UserGrantID{GrantID: "GrantID"}, event: &es_models.Event{}, - state: model.USERGRANTSTATE_REMOVED, + state: model.UserGrantStateRemoved, }, - result: &UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID", RoleKeys: []string{"Key"}, State: int32(model.USERGRANTSTATE_REMOVED)}, + result: &UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID", RoleKeys: []string{"Key"}, State: int32(model.UserGrantStateRemoved)}, }, } for _, tt := range tests { diff --git a/internal/usergrant/repository/eventsourcing/user_grant.go b/internal/usergrant/repository/eventsourcing/user_grant.go index e53a447eb8..b8fe64f1c8 100644 --- a/internal/usergrant/repository/eventsourcing/user_grant.go +++ b/internal/usergrant/repository/eventsourcing/user_grant.go @@ -217,7 +217,7 @@ func addUserGrantValidation(resourceOwner string, grant *model.UserGrant) func(. } func checkProjectConditions(resourceOwner string, grant *model.UserGrant, project *proj_es_model.Project) error { - if project.State == int32(proj_model.PROJECTSTATE_REMOVED) { + if project.State == int32(proj_model.ProjectStateRemoved) { return errors.ThrowPreconditionFailed(nil, "EVENT-Lxp0s", "project doesn't exist") } if resourceOwner == project.ResourceOwner { diff --git a/internal/usergrant/repository/view/model/user_grant.go b/internal/usergrant/repository/view/model/user_grant.go index b82db52810..15b6313712 100644 --- a/internal/usergrant/repository/view/model/user_grant.go +++ b/internal/usergrant/repository/view/model/user_grant.go @@ -95,16 +95,16 @@ func (g *UserGrantView) AppendEvent(event *models.Event) (err error) { g.Sequence = event.Sequence switch event.Type { case es_model.UserGrantAdded: - g.State = int32(model.USERGRANTSTATE_ACTIVE) + g.State = int32(model.UserGrantStateActive) g.CreationDate = event.CreationDate g.setRootData(event) err = g.setData(event) case es_model.UserGrantChanged, es_model.UserGrantCascadeChanged: err = g.setData(event) case es_model.UserGrantDeactivated: - g.State = int32(model.USERGRANTSTATE_INACTIVE) + g.State = int32(model.UserGrantStateInactive) case es_model.UserGrantReactivated: - g.State = int32(model.USERGRANTSTATE_ACTIVE) + g.State = int32(model.UserGrantStateActive) } return err } diff --git a/internal/usergrant/repository/view/model/user_grant_query.go b/internal/usergrant/repository/view/model/user_grant_query.go index df64139e00..f5e858b4d0 100644 --- a/internal/usergrant/repository/view/model/user_grant_query.go +++ b/internal/usergrant/repository/view/model/user_grant_query.go @@ -19,7 +19,7 @@ func (req UserGrantSearchRequest) GetOffset() uint64 { } func (req UserGrantSearchRequest) GetSortingColumn() view.ColumnKey { - if req.SortingColumn == grant_model.USERGRANTSEARCHKEY_UNSPECIFIED { + if req.SortingColumn == grant_model.UserGrantSearchKeyUnspecified { return nil } return UserGrantSearchKey(req.SortingColumn) @@ -51,19 +51,19 @@ func (req UserGrantSearchQuery) GetValue() interface{} { func (key UserGrantSearchKey) ToColumnName() string { switch grant_model.UserGrantSearchKey(key) { - case grant_model.USERGRANTSEARCHKEY_USER_ID: + case grant_model.UserGrantSearchKeyUserID: return UserGrantKeyUserID - case grant_model.USERGRANTSEARCHKEY_PROJECT_ID: + case grant_model.UserGrantSearchKeyProjectID: return UserGrantKeyProjectID - case grant_model.USERGRANTSEARCHKEY_STATE: + case grant_model.UserGrantSearchKeyState: return UserGrantKeyState - case grant_model.USERGRANTSEARCHKEY_RESOURCEOWNER: + case grant_model.UserGrantSearchKeyResourceOwner: return UserGrantKeyResourceOwner - case grant_model.USERGRANTSEARCHKEY_GRANT_ID: + case grant_model.UserGrantSearchKeyGrantID: return UserGrantKeyID - case grant_model.USERGRANTSEARCHKEY_ORG_NAME: + case grant_model.UserGrantSearchKeyOrgName: return UserGrantKeyOrgName - case grant_model.USERGRANTSEARCHKEY_ROLE_KEY: + case grant_model.UserGrantSearchKeyRoleKey: return UserGrantKeyRole default: return "" diff --git a/internal/usergrant/repository/view/model/user_grant_test.go b/internal/usergrant/repository/view/model/user_grant_test.go index 12887147f6..40f5edb1af 100644 --- a/internal/usergrant/repository/view/model/user_grant_test.go +++ b/internal/usergrant/repository/view/model/user_grant_test.go @@ -31,31 +31,31 @@ func TestUserAppendEvent(t *testing.T) { event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.UserGrantAdded, ResourceOwner: "OrgID", Data: mockUserGrantData(&es_model.UserGrant{UserID: "UserID", ProjectID: "ProjectID", RoleKeys: pq.StringArray{"Keys"}})}, grant: &UserGrantView{}, }, - result: &UserGrantView{ID: "AggregateID", ResourceOwner: "OrgID", UserID: "UserID", ProjectID: "ProjectID", RoleKeys: pq.StringArray{"Keys"}, State: int32(model.USERGRANTSTATE_ACTIVE)}, + result: &UserGrantView{ID: "AggregateID", ResourceOwner: "OrgID", UserID: "UserID", ProjectID: "ProjectID", RoleKeys: pq.StringArray{"Keys"}, State: int32(model.UserGrantStateActive)}, }, { name: "append change grant profile event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.UserGrantChanged, ResourceOwner: "OrgID", Data: mockUserGrantData(&es_model.UserGrant{RoleKeys: pq.StringArray{"KeysChanged"}})}, - grant: &UserGrantView{ID: "AggregateID", ResourceOwner: "OrgID", UserID: "UserID", ProjectID: "ProjectID", RoleKeys: pq.StringArray{"Keys"}, State: int32(model.USERGRANTSTATE_ACTIVE)}, + grant: &UserGrantView{ID: "AggregateID", ResourceOwner: "OrgID", UserID: "UserID", ProjectID: "ProjectID", RoleKeys: pq.StringArray{"Keys"}, State: int32(model.UserGrantStateActive)}, }, - result: &UserGrantView{ID: "AggregateID", ResourceOwner: "OrgID", UserID: "UserID", ProjectID: "ProjectID", RoleKeys: pq.StringArray{"KeysChanged"}, State: int32(model.USERGRANTSTATE_ACTIVE)}, + result: &UserGrantView{ID: "AggregateID", ResourceOwner: "OrgID", UserID: "UserID", ProjectID: "ProjectID", RoleKeys: pq.StringArray{"KeysChanged"}, State: int32(model.UserGrantStateActive)}, }, { name: "append grant deactivate event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.UserGrantDeactivated, ResourceOwner: "OrgID"}, - grant: &UserGrantView{ID: "AggregateID", ResourceOwner: "OrgID", UserID: "UserID", ProjectID: "ProjectID", RoleKeys: pq.StringArray{"Keys"}, State: int32(model.USERGRANTSTATE_ACTIVE)}, + grant: &UserGrantView{ID: "AggregateID", ResourceOwner: "OrgID", UserID: "UserID", ProjectID: "ProjectID", RoleKeys: pq.StringArray{"Keys"}, State: int32(model.UserGrantStateActive)}, }, - result: &UserGrantView{ID: "AggregateID", ResourceOwner: "OrgID", UserID: "UserID", ProjectID: "ProjectID", RoleKeys: pq.StringArray{"Keys"}, State: int32(model.USERGRANTSTATE_INACTIVE)}, + result: &UserGrantView{ID: "AggregateID", ResourceOwner: "OrgID", UserID: "UserID", ProjectID: "ProjectID", RoleKeys: pq.StringArray{"Keys"}, State: int32(model.UserGrantStateInactive)}, }, { name: "append grant reactivate event", args: args{ event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.UserGrantReactivated, ResourceOwner: "OrgID"}, - grant: &UserGrantView{ID: "AggregateID", ResourceOwner: "OrgID", UserID: "UserID", ProjectID: "ProjectID", RoleKeys: pq.StringArray{"Keys"}, State: int32(model.USERGRANTSTATE_INACTIVE)}, + grant: &UserGrantView{ID: "AggregateID", ResourceOwner: "OrgID", UserID: "UserID", ProjectID: "ProjectID", RoleKeys: pq.StringArray{"Keys"}, State: int32(model.UserGrantStateInactive)}, }, - result: &UserGrantView{ID: "AggregateID", ResourceOwner: "OrgID", UserID: "UserID", ProjectID: "ProjectID", RoleKeys: pq.StringArray{"Keys"}, State: int32(model.USERGRANTSTATE_ACTIVE)}, + result: &UserGrantView{ID: "AggregateID", ResourceOwner: "OrgID", UserID: "UserID", ProjectID: "ProjectID", RoleKeys: pq.StringArray{"Keys"}, State: int32(model.UserGrantStateActive)}, }, } for _, tt := range tests { diff --git a/internal/usergrant/repository/view/user_grant_view.go b/internal/usergrant/repository/view/user_grant_view.go index 35bea603bd..fbd2aca151 100644 --- a/internal/usergrant/repository/view/user_grant_view.go +++ b/internal/usergrant/repository/view/user_grant_view.go @@ -10,7 +10,7 @@ import ( func UserGrantByID(db *gorm.DB, table, grantID string) (*model.UserGrantView, error) { user := new(model.UserGrantView) - query := view.PrepareGetByKey(table, model.UserGrantSearchKey(grant_model.USERGRANTSEARCHKEY_GRANT_ID), grantID) + query := view.PrepareGetByKey(table, model.UserGrantSearchKey(grant_model.UserGrantSearchKeyGrantID), grantID) err := query(db, user) return user, err } @@ -18,9 +18,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.USERGRANTSEARCHKEY_RESOURCEOWNER, Value: resourceOwnerID, Method: global_model.SEARCHMETHOD_EQUALS} - projectIDQuery := model.UserGrantSearchQuery{Key: grant_model.USERGRANTSEARCHKEY_PROJECT_ID, Value: projectID, Method: global_model.SEARCHMETHOD_EQUALS} - userIDQuery := model.UserGrantSearchQuery{Key: grant_model.USERGRANTSEARCHKEY_USER_ID, Value: userID, Method: global_model.SEARCHMETHOD_EQUALS} + 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} query := view.PrepareGetByQuery(table, resourceOwnerIDQuery, projectIDQuery, userIDQuery) err := query(db, user) return user, err @@ -39,7 +39,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{ - &grant_model.UserGrantSearchQuery{Key: grant_model.USERGRANTSEARCHKEY_USER_ID, Value: userID, Method: global_model.SEARCHMETHOD_EQUALS}, + &grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals}, } query := view.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries}) _, err := query(db, &users) @@ -52,7 +52,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{ - &grant_model.UserGrantSearchQuery{Key: grant_model.USERGRANTSEARCHKEY_PROJECT_ID, Value: projectID, Method: global_model.SEARCHMETHOD_EQUALS}, + &grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}, } query := view.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries}) _, err := query(db, &users) @@ -65,8 +65,8 @@ func UserGrantsByProjectID(db *gorm.DB, table, projectID string) ([]*model.UserG func UserGrantsByProjectIDAndRole(db *gorm.DB, table, projectID, roleKey string) ([]*model.UserGrantView, error) { users := make([]*model.UserGrantView, 0) queries := []*grant_model.UserGrantSearchQuery{ - &grant_model.UserGrantSearchQuery{Key: grant_model.USERGRANTSEARCHKEY_PROJECT_ID, Value: projectID, Method: global_model.SEARCHMETHOD_EQUALS}, - &grant_model.UserGrantSearchQuery{Key: grant_model.USERGRANTSEARCHKEY_ROLE_KEY, Value: roleKey, Method: global_model.SEARCHMETHOD_LIST_CONTAINS}, + &grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}, + &grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyRoleKey, Value: roleKey, Method: global_model.SearchMethodListContains}, } query := view.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries}) _, err := query(db, &users) @@ -79,8 +79,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{ - &grant_model.UserGrantSearchQuery{Key: grant_model.USERGRANTSEARCHKEY_RESOURCEOWNER, Value: orgID, Method: global_model.SEARCHMETHOD_EQUALS}, - &grant_model.UserGrantSearchQuery{Key: grant_model.USERGRANTSEARCHKEY_PROJECT_ID, Value: projectID, Method: global_model.SEARCHMETHOD_EQUALS}, + &grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyResourceOwner, Value: orgID, Method: global_model.SearchMethodEquals}, + &grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}, } query := view.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries}) _, err := query(db, &users) @@ -93,7 +93,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{ - &grant_model.UserGrantSearchQuery{Key: grant_model.USERGRANTSEARCHKEY_RESOURCEOWNER, Value: orgID, Method: global_model.SEARCHMETHOD_EQUALS}, + &grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyResourceOwner, Value: orgID, Method: global_model.SearchMethodEquals}, } query := view.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries}) _, err := query(db, &users) @@ -109,6 +109,6 @@ func PutUserGrant(db *gorm.DB, table string, grant *model.UserGrantView) error { } func DeleteUserGrant(db *gorm.DB, table, grantID string) error { - delete := view.PrepareDeleteByKey(table, model.UserGrantSearchKey(grant_model.USERGRANTSEARCHKEY_GRANT_ID), grantID) + delete := view.PrepareDeleteByKey(table, model.UserGrantSearchKey(grant_model.UserGrantSearchKeyGrantID), grantID) return delete(db) } diff --git a/internal/view/failed_events.go b/internal/view/failed_events.go index 1dbac725e2..3d74022694 100644 --- a/internal/view/failed_events.go +++ b/internal/view/failed_events.go @@ -39,18 +39,18 @@ func (req FailedEventSearchQuery) GetValue() interface{} { type FailedEventSearchKey int32 const ( - FAILEDEVENTKEY_UNDEFINED FailedEventSearchKey = iota - FAILEDEVENTKEY_VIEW_NAME - FAILEDEVENTKEY_FAILED_SEQUENCE + FailedEventKeyUndefined FailedEventSearchKey = iota + FailedEventKeyViewName + FailedEventKeyFailedSequence ) type failedEventSearchKey FailedEventSearchKey func (key failedEventSearchKey) ToColumnName() string { switch FailedEventSearchKey(key) { - case FAILEDEVENTKEY_VIEW_NAME: + case FailedEventKeyViewName: return "view_name" - case FAILEDEVENTKEY_FAILED_SEQUENCE: + case FailedEventKeyFailedSequence: return "failed_sequence" default: return "" @@ -70,8 +70,8 @@ func SaveFailedEvent(db *gorm.DB, table string, failedEvent *FailedEvent) error func LatestFailedEvent(db *gorm.DB, table, viewName string, sequence uint64) (*FailedEvent, error) { failedEvent := new(FailedEvent) queries := []SearchQuery{ - FailedEventSearchQuery{Key: FAILEDEVENTKEY_VIEW_NAME, Method: model.SEARCHMETHOD_EQUALS_IGNORE_CASE, Value: viewName}, - FailedEventSearchQuery{Key: FAILEDEVENTKEY_FAILED_SEQUENCE, Method: model.SEARCHMETHOD_EQUALS, Value: sequence}, + FailedEventSearchQuery{Key: FailedEventKeyViewName, Method: model.SearchMethodEqualsIgnoreCase, Value: viewName}, + FailedEventSearchQuery{Key: FailedEventKeyFailedSequence, Method: model.SearchMethodEquals, Value: sequence}, } query := PrepareGetByQuery(table, queries...) err := query(db, failedEvent) diff --git a/internal/view/query.go b/internal/view/query.go index aa800d2dca..fe4c73b0dd 100644 --- a/internal/view/query.go +++ b/internal/view/query.go @@ -65,47 +65,47 @@ func SetQuery(query *gorm.DB, key ColumnKey, value interface{}, method model.Sea } switch method { - case model.SEARCHMETHOD_EQUALS: + case model.SearchMethodEquals: query = query.Where(""+column+" = ?", value) - case model.SEARCHMETHOD_EQUALS_IGNORE_CASE: + case model.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.SEARCHMETHOD_STARTS_WITH: + case model.SearchMethodStartsWith: valueText, ok := value.(string) if !ok { return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-idu8e", "Starts with only possible for strings") } query = query.Where(column+" LIKE ?", valueText+"%") - case model.SEARCHMETHOD_STARTS_WITH_IGNORE_CASE: + case model.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.SEARCHMETHOD_CONTAINS: + case model.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.SEARCHMETHOD_CONTAINS_IGNORE_CASE: + case model.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.SEARCHMETHOD_NOT_EQUALS: + case model.SearchMethodNotEquals: query = query.Where(""+column+" <> ?", value) - case model.SEARCHMETHOD_GREATER_THAN: + case model.SearchMethodGreaterThan: query = query.Where(column+" > ?", value) - case model.SEARCHMETHOD_LESS_THAN: + case model.SearchMethodLessThan: query = query.Where(column+" < ?", value) - case model.SEARCHMETHOD_IS_ONE_OF: + case model.SearchMethodIsOneOf: query = query.Where(column+" IN (?)", value) - case model.SEARCHMETHOD_LIST_CONTAINS: + case model.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/query_test.go b/internal/view/query_test.go index fe3589ea6b..05ea399461 100644 --- a/internal/view/query_test.go +++ b/internal/view/query_test.go @@ -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.SEARCHMETHOD_EQUALS_IGNORE_CASE, value: "AggregateID"}}}, + searchRequest: TestSearchRequest{queries: []SearchQuery{TestSearchQuery{key: TestSearchKey_ID, method: model.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.SEARCHMETHOD_EQUALS_IGNORE_CASE, value: "AggregateID"}}}, + searchRequest: TestSearchRequest{limit: 2, offset: 2, sortingColumn: TestSearchKey_ID, asc: true, queries: []SearchQuery{TestSearchQuery{key: TestSearchKey_ID, method: model.SearchMethodEqualsIgnoreCase, value: "AggregateID"}}}, }, res{ count: 5, diff --git a/internal/view/requests_test.go b/internal/view/requests_test.go index c5c3007ff4..510999e29e 100644 --- a/internal/view/requests_test.go +++ b/internal/view/requests_test.go @@ -113,7 +113,7 @@ func TestPrepareGetByQuery(t *testing.T) { expectGetByQuery("TESTTABLE", "test", "=", "VALUE"), args{ table: "TESTTABLE", - searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.SEARCHMETHOD_EQUALS_IGNORE_CASE, value: "VALUE"}, + searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.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.SEARCHMETHOD_EQUALS, value: "VALUE"}, + searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.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.SEARCHMETHOD_STARTS_WITH_IGNORE_CASE, value: "VALUE"}, + searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.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.SEARCHMETHOD_STARTS_WITH, value: "VALUE"}, + searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.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.SEARCHMETHOD_CONTAINS_IGNORE_CASE, value: "VALUE"}, + searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.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.SEARCHMETHOD_CONTAINS, value: "VALUE"}, + searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.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.SEARCHMETHOD_CONTAINS_IGNORE_CASE, value: "VALUE"}, + searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.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.SEARCHMETHOD_CONTAINS_IGNORE_CASE, value: "VALUE"}, + searchQuery: TestSearchQuery{key: TestSearchKey_TEST, method: model.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.SEARCHMETHOD_EQUALS_IGNORE_CASE, value: "VALUE"}, + searchQuery: TestSearchQuery{key: TestSearchKey_UNDEFINED, method: model.SearchMethodEqualsIgnoreCase, value: "VALUE"}, }, res{ result: Test{ID: "VALUE"}, diff --git a/internal/view/sequence.go b/internal/view/sequence.go index 96da06b33f..6742a3bf51 100644 --- a/internal/view/sequence.go +++ b/internal/view/sequence.go @@ -17,15 +17,15 @@ type currentSequence struct { type SequenceSearchKey int32 const ( - SEQUENCESEARCHKEY_UNDEFINED SequenceSearchKey = iota - SEQUENCESEARCHKEY_VIEW_NAME + SequenceSearchKeyUndefined SequenceSearchKey = iota + SequenceSearchKeyViewName ) type sequenceSearchKey SequenceSearchKey func (key sequenceSearchKey) ToColumnName() string { switch SequenceSearchKey(key) { - case SEQUENCESEARCHKEY_VIEW_NAME: + case SequenceSearchKeyViewName: return "view_name" default: return "" @@ -44,7 +44,7 @@ func SaveCurrentSequence(db *gorm.DB, table, viewName string, sequence uint64) e func LatestSequence(db *gorm.DB, table, viewName string) (uint64, error) { sequence := new(actualSequece) - query := PrepareGetByKey(table, sequenceSearchKey(SEQUENCESEARCHKEY_VIEW_NAME), viewName) + query := PrepareGetByKey(table, sequenceSearchKey(SequenceSearchKeyViewName), viewName) err := query(db, sequence) if err == nil { diff --git a/pkg/admin/api/grpc/org_converter.go b/pkg/admin/api/grpc/org_converter.go index 92db7eb2be..d8905b1c8f 100644 --- a/pkg/admin/api/grpc/org_converter.go +++ b/pkg/admin/api/grpc/org_converter.go @@ -148,9 +148,9 @@ func userFromModel(user *usr_model.User) *User { func orgStateFromModel(state org_model.OrgState) OrgState { switch state { - case org_model.ORGSTATE_ACTIVE: + case org_model.OrgStateActive: return OrgState_ORGSTATE_ACTIVE - case org_model.ORGSTATE_INACTIVE: + case org_model.OrgStateInactive: return OrgState_ORGSTATE_INACTIVE default: return OrgState_ORGSTATE_UNSPECIFIED @@ -159,11 +159,11 @@ func orgStateFromModel(state org_model.OrgState) OrgState { func genderFromModel(gender usr_model.Gender) Gender { switch gender { - case usr_model.GENDER_FEMALE: + case usr_model.GenderFemale: return Gender_GENDER_FEMALE - case usr_model.GENDER_MALE: + case usr_model.GenderMale: return Gender_GENDER_MALE - case usr_model.GENDER_DIVERSE: + case usr_model.GenderDiverse: return Gender_GENDER_DIVERSE default: return Gender_GENDER_UNSPECIFIED @@ -173,23 +173,23 @@ func genderFromModel(gender usr_model.Gender) Gender { func genderToModel(gender Gender) usr_model.Gender { switch gender { case Gender_GENDER_FEMALE: - return usr_model.GENDER_FEMALE + return usr_model.GenderFemale case Gender_GENDER_MALE: - return usr_model.GENDER_MALE + return usr_model.GenderMale case Gender_GENDER_DIVERSE: - return usr_model.GENDER_DIVERSE + return usr_model.GenderDiverse default: - return usr_model.GENDER_UNDEFINED + return usr_model.GenderUnspecified } } func userStateFromModel(state usr_model.UserState) UserState { switch state { - case usr_model.USERSTATE_ACTIVE: + case usr_model.UserStateActive: return UserState_USERSTATE_ACTIVE - case usr_model.USERSTATE_INACTIVE: + case usr_model.UserStateInactive: return UserState_USERSTATE_INACTIVE - case usr_model.USERSTATE_LOCKED: + case usr_model.UserStateLocked: return UserState_USERSTATE_LOCKED default: return UserState_USERSTATE_UNSPECIFIED @@ -227,24 +227,24 @@ func orgQueryToModel(query *OrgSearchQuery) *org_model.OrgSearchQuery { func orgQueryKeyToModel(key OrgSearchKey) org_model.OrgSearchKey { switch key { case OrgSearchKey_ORGSEARCHKEY_DOMAIN: - return org_model.ORGSEARCHKEY_ORG_DOMAIN + return org_model.OrgSearchKeyOrgDomain case OrgSearchKey_ORGSEARCHKEY_ORG_NAME: - return org_model.ORGSEARCHKEY_ORG_NAME + return org_model.OrgSearchKeyOrgName case OrgSearchKey_ORGSEARCHKEY_STATE: - return org_model.ORGSEARCHKEY_STATE + return org_model.OrgSearchKeyState default: - return org_model.ORGSEARCHKEY_UNSPECIFIED + return org_model.OrgSearchKeyUnspecified } } func orgQueryMethodToModel(method OrgSearchMethod) model.SearchMethod { switch method { case OrgSearchMethod_ORGSEARCHMETHOD_CONTAINS: - return model.SEARCHMETHOD_CONTAINS + return model.SearchMethodContains case OrgSearchMethod_ORGSEARCHMETHOD_EQUALS: - return model.SEARCHMETHOD_EQUALS + return model.SearchMethodEquals case OrgSearchMethod_ORGSEARCHMETHOD_STARTS_WITH: - return model.SEARCHMETHOD_STARTS_WITH + return model.SearchMethodStartsWith default: return 0 } diff --git a/pkg/auth/api/grpc/search_converter.go b/pkg/auth/api/grpc/search_converter.go index d50c224171..a875da5019 100644 --- a/pkg/auth/api/grpc/search_converter.go +++ b/pkg/auth/api/grpc/search_converter.go @@ -5,18 +5,18 @@ import "github.com/caos/zitadel/internal/model" func searchMethodToModel(method SearchMethod) model.SearchMethod { switch method { case SearchMethod_SEARCHMETHOD_EQUALS: - return model.SEARCHMETHOD_EQUALS + return model.SearchMethodEquals case SearchMethod_SEARCHMETHOD_CONTAINS: - return model.SEARCHMETHOD_CONTAINS + return model.SearchMethodContains case SearchMethod_SEARCHMETHOD_STARTS_WITH: - return model.SEARCHMETHOD_STARTS_WITH + return model.SearchMethodStartsWith case SearchMethod_SEARCHMETHOD_EQUALS_IGNORE_CASE: - return model.SEARCHMETHOD_EQUALS_IGNORE_CASE + return model.SearchMethodEqualsIgnoreCase case SearchMethod_SEARCHMETHOD_CONTAINS_IGNORE_CASE: - return model.SEARCHMETHOD_CONTAINS_IGNORE_CASE + return model.SearchMethodContainsIgnoreCase case SearchMethod_SEARCHMETHOD_STARTS_WITH_IGNORE_CASE: - return model.SEARCHMETHOD_STARTS_WITH_IGNORE_CASE + return model.SearchMethodStartsWithIgnoreCase default: - return model.SEARCHMETHOD_EQUALS + return model.SearchMethodEquals } } diff --git a/pkg/auth/api/grpc/user_converter.go b/pkg/auth/api/grpc/user_converter.go index 51bc1800e6..88a4f7705a 100644 --- a/pkg/auth/api/grpc/user_converter.go +++ b/pkg/auth/api/grpc/user_converter.go @@ -258,15 +258,15 @@ func otpFromModel(otp *usr_model.OTP) *MfaOtpResponse { func userStateFromModel(state usr_model.UserState) UserState { switch state { - case usr_model.USERSTATE_ACTIVE: + case usr_model.UserStateActive: return UserState_USERSTATE_ACTIVE - case usr_model.USERSTATE_INACTIVE: + case usr_model.UserStateInactive: return UserState_USERSTATE_INACTIVE - case usr_model.USERSTATE_LOCKED: + case usr_model.UserStateLocked: return UserState_USERSTATE_LOCKED - case usr_model.USERSTATE_INITIAL: + case usr_model.UserStateInitial: return UserState_USERSTATE_INITIAL - case usr_model.USERSTATE_SUSPEND: + case usr_model.UserStateSuspend: return UserState_USERSTATE_SUSPEND default: return UserState_USERSTATE_UNSPECIFIED @@ -275,11 +275,11 @@ func userStateFromModel(state usr_model.UserState) UserState { func genderFromModel(gender usr_model.Gender) Gender { switch gender { - case usr_model.GENDER_FEMALE: + case usr_model.GenderFemale: return Gender_GENDER_FEMALE - case usr_model.GENDER_MALE: + case usr_model.GenderMale: return Gender_GENDER_MALE - case usr_model.GENDER_DIVERSE: + case usr_model.GenderDiverse: return Gender_GENDER_DIVERSE default: return Gender_GENDER_UNSPECIFIED @@ -289,21 +289,21 @@ func genderFromModel(gender usr_model.Gender) Gender { func genderToModel(gender Gender) usr_model.Gender { switch gender { case Gender_GENDER_FEMALE: - return usr_model.GENDER_FEMALE + return usr_model.GenderFemale case Gender_GENDER_MALE: - return usr_model.GENDER_MALE + return usr_model.GenderMale case Gender_GENDER_DIVERSE: - return usr_model.GENDER_DIVERSE + return usr_model.GenderDiverse default: - return usr_model.GENDER_UNDEFINED + return usr_model.GenderUnspecified } } func mfaStateFromModel(state usr_model.MfaState) MFAState { switch state { - case usr_model.MFASTATE_READY: + case usr_model.MfaStateReady: return MFAState_MFASTATE_NOT_READY - case usr_model.MFASTATE_NOTREADY: + case usr_model.MfaStateNotReady: return MFAState_MFASTATE_NOT_READY default: return MFAState_MFASTATE_UNSPECIFIED diff --git a/pkg/auth/api/grpc/user_grant_converter.go b/pkg/auth/api/grpc/user_grant_converter.go index 2de2b539bc..5ad99419aa 100644 --- a/pkg/auth/api/grpc/user_grant_converter.go +++ b/pkg/auth/api/grpc/user_grant_converter.go @@ -31,11 +31,11 @@ func userGrantSearchQueryToModel(query *UserGrantSearchQuery) *grant_model.UserG func userGrantSearchKeyToModel(key UserGrantSearchKey) grant_model.UserGrantSearchKey { switch key { case UserGrantSearchKey_UserGrantSearchKey_ORG_ID: - return grant_model.USERGRANTSEARCHKEY_RESOURCEOWNER + return grant_model.UserGrantSearchKeyResourceOwner case UserGrantSearchKey_UserGrantSearchKey_PROJECT_ID: - return grant_model.USERGRANTSEARCHKEY_PROJECT_ID + return grant_model.UserGrantSearchKeyProjectID default: - return grant_model.USERGRANTSEARCHKEY_UNSPECIFIED + return grant_model.UserGrantSearchKeyUnspecified } } @@ -44,7 +44,7 @@ func myProjectOrgSearchRequestRequestsToModel(request *MyProjectOrgSearchRequest Offset: request.Offset, Limit: request.Limit, Asc: request.Asc, - SortingColumn: grant_model.USERGRANTSEARCHKEY_RESOURCEOWNER, + SortingColumn: grant_model.UserGrantSearchKeyResourceOwner, Queries: myProjectOrgSearchQueriesToModel(request.Queries), } } @@ -68,9 +68,9 @@ func myProjectOrgSearchQueryToModel(query *MyProjectOrgSearchQuery) *grant_model func myProjectOrgSearchKeyToModel(key MyProjectOrgSearchKey) grant_model.UserGrantSearchKey { switch key { case MyProjectOrgSearchKey_MYPROJECTORGSEARCHKEY_ORG_NAME: - return grant_model.USERGRANTSEARCHKEY_ORG_NAME + return grant_model.UserGrantSearchKeyOrgName default: - return grant_model.USERGRANTSEARCHKEY_UNSPECIFIED + return grant_model.UserGrantSearchKeyUnspecified } } diff --git a/pkg/auth/api/oidc/client.go b/pkg/auth/api/oidc/client.go index 79410e2bf6..de84854c2e 100644 --- a/pkg/auth/api/oidc/client.go +++ b/pkg/auth/api/oidc/client.go @@ -27,7 +27,7 @@ func (o *OPStorage) GetClientByClientID(ctx context.Context, id string) (op.Clie if err != nil { return nil, err } - if client.State != proj_model.APPSTATE_ACTIVE { + if client.State != proj_model.AppStateActive { return nil, errors.ThrowPreconditionFailed(nil, "OIDC-sdaGg", "client is not active") } return ClientFromBusiness(client, o.defaultLoginURL, o.defaultAccessTokenLifetime, o.defaultIdTokenLifetime) @@ -86,11 +86,11 @@ func (o *OPStorage) GetUserinfoFromScopes(ctx context.Context, userID string, sc func getGender(gender user_model.Gender) string { switch gender { - case user_model.GENDER_FEMALE: + case user_model.GenderFemale: return "female" - case user_model.GENDER_MALE: + case user_model.GenderMale: return "male" - case user_model.GENDER_DIVERSE: + case user_model.GenderDiverse: return "diverse" } return "" diff --git a/pkg/auth/api/oidc/client_converter.go b/pkg/auth/api/oidc/client_converter.go index e2aaf3a4bf..816eebb513 100644 --- a/pkg/auth/api/oidc/client_converter.go +++ b/pkg/auth/api/oidc/client_converter.go @@ -61,11 +61,11 @@ func (c *Client) AccessTokenType() op.AccessTokenType { func authMethodToOIDC(authType model.OIDCAuthMethodType) op.AuthMethod { switch authType { - case model.OIDCAUTHMETHODTYPE_BASIC: + case model.OIDCAuthMethodTypeBasic: return op.AuthMethodBasic - case model.OIDCAUTHMETHODTYPE_POST: + case model.OIDCAuthMethodTypePost: return op.AuthMethodPost - case model.OIDCAUTHMETHODTYPE_NONE: + case model.OIDCAuthMethodTypeNone: return op.AuthMethodNone default: return op.AuthMethodBasic diff --git a/pkg/management/api/grpc/application_converter.go b/pkg/management/api/grpc/application_converter.go index 98b8c56367..a3c68e389c 100644 --- a/pkg/management/api/grpc/application_converter.go +++ b/pkg/management/api/grpc/application_converter.go @@ -31,7 +31,7 @@ func appFromModel(app *proj_model.Application) *Application { } func appConfigFromModel(app *proj_model.Application) isApplication_AppConfig { - if app.Type == proj_model.APPTYPE_OIDC { + if app.Type == proj_model.AppTypeOIDC { return &Application_OidcConfig{ OidcConfig: oidcConfigFromModel(app.OIDCConfig), } @@ -70,7 +70,7 @@ func oidcAppCreateToModel(app *OIDCApplicationCreate) *proj_model.Application { AggregateID: app.ProjectId, }, Name: app.Name, - Type: proj_model.APPTYPE_OIDC, + Type: proj_model.AppTypeOIDC, OIDCConfig: &proj_model.OIDCConfig{ RedirectUris: app.RedirectUris, ResponseTypes: oidcResponseTypesToModel(app.ResponseTypes), @@ -120,7 +120,7 @@ func applicationSearchQueriesToModel(projectID string, queries []*ApplicationSea for i, q := range queries { converted[i] = applicationSearchQueryToModel(q) } - converted[len(queries)] = &proj_model.ApplicationSearchQuery{Key: proj_model.APPLICATIONSEARCHKEY_PROJECT_ID, Method: model.SEARCHMETHOD_EQUALS, Value: projectID} + converted[len(queries)] = &proj_model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyProjectID, Method: model.SearchMethodEquals, Value: projectID} return converted } @@ -133,12 +133,12 @@ func applicationSearchQueryToModel(query *ApplicationSearchQuery) *proj_model.Ap } } -func applicationSearchKeyToModel(key ApplicationSearchKey) proj_model.ApplicationSearchKey { +func applicationSearchKeyToModel(key ApplicationSearchKey) proj_model.AppSearchKey { switch key { case ApplicationSearchKey_APPLICATIONSEARCHKEY_APP_NAME: - return proj_model.APPLICATIONSEARCHKEY_NAME + return proj_model.AppSearchKeyName default: - return proj_model.APPLICATIONSEARCHKEY_UNSPECIFIED + return proj_model.AppSearchKeyUnspecified } } @@ -184,9 +184,9 @@ func applicationViewFromModel(application *proj_model.ApplicationView) *Applicat func appStateFromModel(state proj_model.AppState) AppState { switch state { - case proj_model.APPSTATE_ACTIVE: + case proj_model.AppStateActive: return AppState_APPSTATE_ACTIVE - case proj_model.APPSTATE_INACTIVE: + case proj_model.AppStateInactive: return AppState_APPSTATE_INACTIVE default: return AppState_APPSTATE_UNSPECIFIED @@ -195,18 +195,18 @@ func appStateFromModel(state proj_model.AppState) AppState { func oidcResponseTypesToModel(responseTypes []OIDCResponseType) []proj_model.OIDCResponseType { if responseTypes == nil || len(responseTypes) == 0 { - return []proj_model.OIDCResponseType{proj_model.OIDCRESPONSETYPE_CODE} + return []proj_model.OIDCResponseType{proj_model.OIDCResponseTypeCode} } oidcResponseTypes := make([]proj_model.OIDCResponseType, len(responseTypes)) for i, responseType := range responseTypes { switch responseType { case OIDCResponseType_OIDCRESPONSETYPE_CODE: - oidcResponseTypes[i] = proj_model.OIDCRESPONSETYPE_CODE + oidcResponseTypes[i] = proj_model.OIDCResponseTypeCode case OIDCResponseType_OIDCRESPONSETYPE_ID_TOKEN: - oidcResponseTypes[i] = proj_model.OIDCRESPONSETYPE_ID_TOKEN + oidcResponseTypes[i] = proj_model.OIDCResponseTypeIDToken case OIDCResponseType_OIDCRESPONSETYPE_TOKEN: - oidcResponseTypes[i] = proj_model.OIDCRESPONSETYPE_TOKEN + oidcResponseTypes[i] = proj_model.OIDCResponseTypeToken } } @@ -218,11 +218,11 @@ func oidcResponseTypesFromModel(responseTypes []proj_model.OIDCResponseType) []O for i, responseType := range responseTypes { switch responseType { - case proj_model.OIDCRESPONSETYPE_CODE: + case proj_model.OIDCResponseTypeCode: oidcResponseTypes[i] = OIDCResponseType_OIDCRESPONSETYPE_CODE - case proj_model.OIDCRESPONSETYPE_ID_TOKEN: + case proj_model.OIDCResponseTypeIDToken: oidcResponseTypes[i] = OIDCResponseType_OIDCRESPONSETYPE_ID_TOKEN - case proj_model.OIDCRESPONSETYPE_TOKEN: + case proj_model.OIDCResponseTypeToken: oidcResponseTypes[i] = OIDCResponseType_OIDCRESPONSETYPE_TOKEN } } @@ -232,18 +232,18 @@ func oidcResponseTypesFromModel(responseTypes []proj_model.OIDCResponseType) []O func oidcGrantTypesToModel(grantTypes []OIDCGrantType) []proj_model.OIDCGrantType { if grantTypes == nil || len(grantTypes) == 0 { - return []proj_model.OIDCGrantType{proj_model.OIDCGRANTTYPE_AUTHORIZATION_CODE} + return []proj_model.OIDCGrantType{proj_model.OIDCGrantTypeAuthorizationCode} } oidcGrantTypes := make([]proj_model.OIDCGrantType, len(grantTypes)) for i, grantType := range grantTypes { switch grantType { case OIDCGrantType_OIDCGRANTTYPE_AUTHORIZATION_CODE: - oidcGrantTypes[i] = proj_model.OIDCGRANTTYPE_AUTHORIZATION_CODE + oidcGrantTypes[i] = proj_model.OIDCGrantTypeAuthorizationCode case OIDCGrantType_OIDCGRANTTYPE_IMPLICIT: - oidcGrantTypes[i] = proj_model.OIDCGRANTTYPE_IMPLICIT + oidcGrantTypes[i] = proj_model.OIDCGrantTypeImplicit case OIDCGrantType_OIDCGRANTTYPE_REFRESH_TOKEN: - oidcGrantTypes[i] = proj_model.OIDCGRANTTYPE_REFRESH_TOKEN + oidcGrantTypes[i] = proj_model.OIDCGrantTypeRefreshToken } } return oidcGrantTypes @@ -254,11 +254,11 @@ func oidcGrantTypesFromModel(grantTypes []proj_model.OIDCGrantType) []OIDCGrantT for i, grantType := range grantTypes { switch grantType { - case proj_model.OIDCGRANTTYPE_AUTHORIZATION_CODE: + case proj_model.OIDCGrantTypeAuthorizationCode: oidcGrantTypes[i] = OIDCGrantType_OIDCGRANTTYPE_AUTHORIZATION_CODE - case proj_model.OIDCGRANTTYPE_IMPLICIT: + case proj_model.OIDCGrantTypeImplicit: oidcGrantTypes[i] = OIDCGrantType_OIDCGRANTTYPE_IMPLICIT - case proj_model.OIDCGRANTTYPE_REFRESH_TOKEN: + case proj_model.OIDCGrantTypeRefreshToken: oidcGrantTypes[i] = OIDCGrantType_OIDCGRANTTYPE_REFRESH_TOKEN } } @@ -268,22 +268,22 @@ func oidcGrantTypesFromModel(grantTypes []proj_model.OIDCGrantType) []OIDCGrantT func oidcApplicationTypeToModel(appType OIDCApplicationType) proj_model.OIDCApplicationType { switch appType { case OIDCApplicationType_OIDCAPPLICATIONTYPE_WEB: - return proj_model.OIDCAPPLICATIONTYPE_WEB + return proj_model.OIDCApplicationTypeWeb case OIDCApplicationType_OIDCAPPLICATIONTYPE_USER_AGENT: - return proj_model.OIDCAPPLICATIONTYPE_USER_AGENT + return proj_model.OIDCApplicationTypeUserAgent case OIDCApplicationType_OIDCAPPLICATIONTYPE_NATIVE: - return proj_model.OIDCAPPLICATIONTYPE_NATIVE + return proj_model.OIDCApplicationTypeNative } - return proj_model.OIDCAPPLICATIONTYPE_WEB + return proj_model.OIDCApplicationTypeWeb } func oidcApplicationTypeFromModel(appType proj_model.OIDCApplicationType) OIDCApplicationType { switch appType { - case proj_model.OIDCAPPLICATIONTYPE_WEB: + case proj_model.OIDCApplicationTypeWeb: return OIDCApplicationType_OIDCAPPLICATIONTYPE_WEB - case proj_model.OIDCAPPLICATIONTYPE_USER_AGENT: + case proj_model.OIDCApplicationTypeUserAgent: return OIDCApplicationType_OIDCAPPLICATIONTYPE_USER_AGENT - case proj_model.OIDCAPPLICATIONTYPE_NATIVE: + case proj_model.OIDCApplicationTypeNative: return OIDCApplicationType_OIDCAPPLICATIONTYPE_NATIVE default: return OIDCApplicationType_OIDCAPPLICATIONTYPE_WEB @@ -293,23 +293,23 @@ func oidcApplicationTypeFromModel(appType proj_model.OIDCApplicationType) OIDCAp func oidcAuthMethodTypeToModel(authType OIDCAuthMethodType) proj_model.OIDCAuthMethodType { switch authType { case OIDCAuthMethodType_OIDCAUTHMETHODTYPE_BASIC: - return proj_model.OIDCAUTHMETHODTYPE_BASIC + return proj_model.OIDCAuthMethodTypeBasic case OIDCAuthMethodType_OIDCAUTHMETHODTYPE_POST: - return proj_model.OIDCAUTHMETHODTYPE_POST + return proj_model.OIDCAuthMethodTypePost case OIDCAuthMethodType_OIDCAUTHMETHODTYPE_NONE: - return proj_model.OIDCAUTHMETHODTYPE_NONE + return proj_model.OIDCAuthMethodTypeNone default: - return proj_model.OIDCAUTHMETHODTYPE_BASIC + return proj_model.OIDCAuthMethodTypeBasic } } func oidcAuthMethodTypeFromModel(authType proj_model.OIDCAuthMethodType) OIDCAuthMethodType { switch authType { - case proj_model.OIDCAUTHMETHODTYPE_BASIC: + case proj_model.OIDCAuthMethodTypeBasic: return OIDCAuthMethodType_OIDCAUTHMETHODTYPE_BASIC - case proj_model.OIDCAUTHMETHODTYPE_POST: + case proj_model.OIDCAuthMethodTypePost: return OIDCAuthMethodType_OIDCAUTHMETHODTYPE_POST - case proj_model.OIDCAUTHMETHODTYPE_NONE: + case proj_model.OIDCAuthMethodTypeNone: return OIDCAuthMethodType_OIDCAUTHMETHODTYPE_NONE default: return OIDCAuthMethodType_OIDCAUTHMETHODTYPE_BASIC diff --git a/pkg/management/api/grpc/org_converter.go b/pkg/management/api/grpc/org_converter.go index ec54a1828d..f95ff05910 100644 --- a/pkg/management/api/grpc/org_converter.go +++ b/pkg/management/api/grpc/org_converter.go @@ -52,9 +52,9 @@ func orgViewFromModel(org *org_model.OrgView) *OrgView { func orgStateFromModel(state org_model.OrgState) OrgState { switch state { - case org_model.ORGSTATE_ACTIVE: + case org_model.OrgStateActive: return OrgState_ORGSTATE_ACTIVE - case org_model.ORGSTATE_INACTIVE: + case org_model.OrgStateInactive: return OrgState_ORGSTATE_INACTIVE default: return OrgState_ORGSTATE_UNSPECIFIED @@ -128,9 +128,9 @@ func orgDomainSearchQueryToModel(query *OrgDomainSearchQuery) *org_model.OrgDoma func orgDomainSearchKeyToModel(key OrgDomainSearchKey) org_model.OrgDomainSearchKey { switch key { case OrgDomainSearchKey_ORGDOMAINSEARCHKEY_DOMAIN: - return org_model.ORGDOMAINSEARCHKEY_DOMAIN + return org_model.OrgDomainSearchKeyDomain default: - return org_model.ORGDOMAINSEARCHKEY_UNSPECIFIED + return org_model.OrgDomainSearchKeyUnspecified } } diff --git a/pkg/management/api/grpc/org_member_converter.go b/pkg/management/api/grpc/org_member_converter.go index 532595073d..a3e1e1d6f2 100644 --- a/pkg/management/api/grpc/org_member_converter.go +++ b/pkg/management/api/grpc/org_member_converter.go @@ -70,32 +70,32 @@ func orgMemberSearchQueryToModel(query *OrgMemberSearchQuery) *org_model.OrgMemb func orgMemberSearchKeyToModel(key OrgMemberSearchKey) org_model.OrgMemberSearchKey { switch key { case OrgMemberSearchKey_ORGMEMBERSEARCHKEY_EMAIL: - return org_model.ORGMEMBERSEARCHKEY_EMAIL + return org_model.OrgMemberSearchKeyEmail case OrgMemberSearchKey_ORGMEMBERSEARCHKEY_FIRST_NAME: - return org_model.ORGMEMBERSEARCHKEY_FIRST_NAME + return org_model.OrgMemberSearchKeyFirstName case OrgMemberSearchKey_ORGMEMBERSEARCHKEY_LAST_NAME: - return org_model.ORGMEMBERSEARCHKEY_LAST_NAME + return org_model.OrgMemberSearchKeyLastName case OrgMemberSearchKey_ORGMEMBERSEARCHKEY_USER_ID: - return org_model.ORGMEMBERSEARCHKEY_USER_ID + return org_model.OrgMemberSearchKeyUserID default: - return org_model.ORGMEMBERSEARCHKEY_UNSPECIFIED + return org_model.OrgMemberSearchKeyUnspecified } } func orgMemberSearchMethodToModel(key SearchMethod) model.SearchMethod { switch key { case SearchMethod_SEARCHMETHOD_CONTAINS: - return model.SEARCHMETHOD_CONTAINS + return model.SearchMethodContains case SearchMethod_SEARCHMETHOD_CONTAINS_IGNORE_CASE: - return model.SEARCHMETHOD_CONTAINS_IGNORE_CASE + return model.SearchMethodContainsIgnoreCase case SearchMethod_SEARCHMETHOD_EQUALS: - return model.SEARCHMETHOD_EQUALS + return model.SearchMethodEquals case SearchMethod_SEARCHMETHOD_EQUALS_IGNORE_CASE: - return model.SEARCHMETHOD_EQUALS_IGNORE_CASE + return model.SearchMethodEqualsIgnoreCase case SearchMethod_SEARCHMETHOD_STARTS_WITH: - return model.SEARCHMETHOD_STARTS_WITH + return model.SearchMethodStartsWith case SearchMethod_SEARCHMETHOD_STARTS_WITH_IGNORE_CASE: - return model.SEARCHMETHOD_STARTS_WITH_IGNORE_CASE + return model.SearchMethodStartsWithIgnoreCase default: return -1 } diff --git a/pkg/management/api/grpc/project_converter.go b/pkg/management/api/grpc/project_converter.go index 20ba75674f..308fe9885a 100644 --- a/pkg/management/api/grpc/project_converter.go +++ b/pkg/management/api/grpc/project_converter.go @@ -96,9 +96,9 @@ func projectRoleViewFromModel(role *proj_model.ProjectRoleView) *ProjectRoleView func projectStateFromModel(state proj_model.ProjectState) ProjectState { switch state { - case proj_model.PROJECTSTATE_ACTIVE: + case proj_model.ProjectStateActive: return ProjectState_PROJECTSTATE_ACTIVE - case proj_model.PROJECTSTATE_INACTIVE: + case proj_model.ProjectStateInactive: return ProjectState_PROJECTSTATE_INACTIVE default: return ProjectState_PROJECTSTATE_UNSPECIFIED @@ -202,9 +202,9 @@ func projectSearchQueryToModel(query *ProjectSearchQuery) *proj_model.ProjectVie func projectSearchKeyToModel(key ProjectSearchKey) proj_model.ProjectViewSearchKey { switch key { case ProjectSearchKey_PROJECTSEARCHKEY_PROJECT_NAME: - return proj_model.PROJECTSEARCHKEY_NAME + return proj_model.ProjectViewSearchKeyName default: - return proj_model.PROJECTSEARCHKEY_UNSPECIFIED + return proj_model.ProjectViewSearchKeyUnspecified } } @@ -227,9 +227,9 @@ func grantedProjectSearchQueryToModel(query *ProjectSearchQuery) *proj_model.Pro func projectGrantSearchKeyToModel(key ProjectSearchKey) proj_model.ProjectGrantViewSearchKey { switch key { case ProjectSearchKey_PROJECTSEARCHKEY_PROJECT_NAME: - return proj_model.GRANTEDPROJECTSEARCHKEY_NAME + return proj_model.GrantedProjectSearchKeyName default: - return proj_model.GRANTEDPROJECTSEARCHKEY_UNSPECIFIED + return proj_model.GrantedProjectSearchKeyUnspecified } } @@ -260,11 +260,11 @@ func projectRoleSearchQueryToModel(query *ProjectRoleSearchQuery) *proj_model.Pr func projectRoleSearchKeyToModel(key ProjectRoleSearchKey) proj_model.ProjectRoleSearchKey { switch key { case ProjectRoleSearchKey_PROJECTROLESEARCHKEY_KEY: - return proj_model.PROJECTROLESEARCHKEY_KEY + return proj_model.ProjectRoleSearchKeyKey case ProjectRoleSearchKey_PROJECTROLESEARCHKEY_DISPLAY_NAME: - return proj_model.PROJECTROLESEARCHKEY_DISPLAY_NAME + return proj_model.ProjectRoleSearchKeyDisplayName default: - return proj_model.PROJECTROLESEARCHKEY_UNSPECIFIED + return proj_model.ProjectRoleSearchKeyUnspecified } } diff --git a/pkg/management/api/grpc/project_grant_converter.go b/pkg/management/api/grpc/project_grant_converter.go index be02c74bba..e477357ad9 100644 --- a/pkg/management/api/grpc/project_grant_converter.go +++ b/pkg/management/api/grpc/project_grant_converter.go @@ -58,8 +58,8 @@ func projectGrantSearchRequestsToModel(request *ProjectGrantSearchRequest) *proj func projectGrantSearchQueriesToModel(projectId string, queries []*ProjectGrantSearchQuery) []*proj_model.ProjectGrantViewSearchQuery { converted := make([]*proj_model.ProjectGrantViewSearchQuery, 0) converted = append(converted, &proj_model.ProjectGrantViewSearchQuery{ - Key: proj_model.GRANTEDPROJECTSEARCHKEY_PROJECTID, - Method: model.SEARCHMETHOD_EQUALS, + Key: proj_model.GrantedProjectSearchKeyProjectID, + Method: model.SearchMethodEquals, Value: projectId, }) for i, query := range queries { @@ -79,11 +79,11 @@ func projectGrantSearchQueryToModel(query *ProjectGrantSearchQuery) *proj_model. func projectGrantViewSearchKeyToModel(key ProjectGrantSearchKey) proj_model.ProjectGrantViewSearchKey { switch key { case ProjectGrantSearchKey_PROJECTGRANTSEARCHKEY_PROJECT_NAME: - return proj_model.GRANTEDPROJECTSEARCHKEY_PROJECTID + return proj_model.GrantedProjectSearchKeyProjectID case ProjectGrantSearchKey_PROJECTGRANTSEARCHKEY_ROLE_KEY: - return proj_model.GRANTEDPROJECTSEARCHKEY_ROLE_KEYS + return proj_model.GrantedProjectSearchKeyRoleKeys default: - return proj_model.GRANTEDPROJECTSEARCHKEY_UNSPECIFIED + return proj_model.GrantedProjectSearchKeyUnspecified } } @@ -129,9 +129,9 @@ func projectGrantFromGrantedProjectModel(project *proj_model.ProjectGrantView) * func projectGrantStateFromModel(state proj_model.ProjectGrantState) ProjectGrantState { switch state { - case proj_model.PROJECTGRANTSTATE_ACTIVE: + case proj_model.ProjectGrantStateActive: return ProjectGrantState_PROJECTGRANTSTATE_ACTIVE - case proj_model.PROJECTGRANTSTATE_INACTIVE: + case proj_model.ProjectGrantStateInactive: return ProjectGrantState_PROJECTGRANTSTATE_INACTIVE default: return ProjectGrantState_PROJECTGRANTSTATE_UNSPECIFIED @@ -140,9 +140,9 @@ func projectGrantStateFromModel(state proj_model.ProjectGrantState) ProjectGrant func projectGrantStateFromProjectStateModel(state proj_model.ProjectState) ProjectGrantState { switch state { - case proj_model.PROJECTSTATE_ACTIVE: + case proj_model.ProjectStateActive: return ProjectGrantState_PROJECTGRANTSTATE_ACTIVE - case proj_model.PROJECTSTATE_INACTIVE: + case proj_model.ProjectStateInactive: return ProjectGrantState_PROJECTGRANTSTATE_INACTIVE default: return ProjectGrantState_PROJECTGRANTSTATE_UNSPECIFIED diff --git a/pkg/management/api/grpc/project_grant_member_converter.go b/pkg/management/api/grpc/project_grant_member_converter.go index 4ed2c7d344..388c39e079 100644 --- a/pkg/management/api/grpc/project_grant_member_converter.go +++ b/pkg/management/api/grpc/project_grant_member_converter.go @@ -72,15 +72,15 @@ func projectGrantMemberSearchQueryToModel(query *ProjectGrantMemberSearchQuery) func projectGrantMemberSearchKeyToModel(key ProjectGrantMemberSearchKey) proj_model.ProjectGrantMemberSearchKey { switch key { case ProjectGrantMemberSearchKey_PROJECTGRANTMEMBERSEARCHKEY_EMAIL: - return proj_model.PROJECTGRANTMEMBERSEARCHKEY_EMAIL + return proj_model.ProjectGrantMemberSearchKeyEmail case ProjectGrantMemberSearchKey_PROJECTGRANTMEMBERSEARCHKEY_FIRST_NAME: - return proj_model.PROJECTGRANTMEMBERSEARCHKEY_FIRST_NAME + return proj_model.ProjectGrantMemberSearchKeyFirstName case ProjectGrantMemberSearchKey_PROJECTGRANTMEMBERSEARCHKEY_LAST_NAME: - return proj_model.PROJECTGRANTMEMBERSEARCHKEY_LAST_NAME + return proj_model.ProjectGrantMemberSearchKeyLastName case ProjectGrantMemberSearchKey_PROJECTGRANTMEMBERSEARCHKEY_USER_NAME: - return proj_model.PROJECTGRANTMEMBERSEARCHKEY_USER_NAME + return proj_model.ProjectGrantMemberSearchKeyUserName default: - return proj_model.PROJECTGRANTMEMBERSEARCHKEY_UNSPECIFIED + return proj_model.ProjectGrantMemberSearchKeyUnspecified } } diff --git a/pkg/management/api/grpc/project_member_converter.go b/pkg/management/api/grpc/project_member_converter.go index 8ed29fa3d2..9843b98e49 100644 --- a/pkg/management/api/grpc/project_member_converter.go +++ b/pkg/management/api/grpc/project_member_converter.go @@ -70,15 +70,15 @@ func projectMemberSearchQueryToModel(query *ProjectMemberSearchQuery) *proj_mode func projectMemberSearchKeyToModel(key ProjectMemberSearchKey) proj_model.ProjectMemberSearchKey { switch key { case ProjectMemberSearchKey_PROJECTMEMBERSEARCHKEY_EMAIL: - return proj_model.PROJECTMEMBERSEARCHKEY_EMAIL + return proj_model.ProjectMemberSearchKeyEmail case ProjectMemberSearchKey_PROJECTMEMBERSEARCHKEY_FIRST_NAME: - return proj_model.PROJECTMEMBERSEARCHKEY_FIRST_NAME + return proj_model.ProjectMemberSearchKeyFirstName case ProjectMemberSearchKey_PROJECTMEMBERSEARCHKEY_LAST_NAME: - return proj_model.PROJECTMEMBERSEARCHKEY_LAST_NAME + return proj_model.ProjectMemberSearchKeyLastName case ProjectMemberSearchKey_PROJECTMEMBERSEARCHKEY_USER_NAME: - return proj_model.PROJECTMEMBERSEARCHKEY_USER_NAME + return proj_model.ProjectMemberSearchKeyUserName default: - return proj_model.PROJECTMEMBERSEARCHKEY_UNSPECIFIED + return proj_model.ProjectMemberSearchKeyUnspecified } } diff --git a/pkg/management/api/grpc/search_converter.go b/pkg/management/api/grpc/search_converter.go index d914ccebed..20e56dfecd 100644 --- a/pkg/management/api/grpc/search_converter.go +++ b/pkg/management/api/grpc/search_converter.go @@ -5,24 +5,24 @@ import "github.com/caos/zitadel/internal/model" func searchMethodToModel(method SearchMethod) model.SearchMethod { switch method { case SearchMethod_SEARCHMETHOD_EQUALS: - return model.SEARCHMETHOD_EQUALS + return model.SearchMethodEquals case SearchMethod_SEARCHMETHOD_CONTAINS: - return model.SEARCHMETHOD_CONTAINS + return model.SearchMethodContains case SearchMethod_SEARCHMETHOD_STARTS_WITH: - return model.SEARCHMETHOD_STARTS_WITH + return model.SearchMethodStartsWith case SearchMethod_SEARCHMETHOD_EQUALS_IGNORE_CASE: - return model.SEARCHMETHOD_EQUALS_IGNORE_CASE + return model.SearchMethodEqualsIgnoreCase case SearchMethod_SEARCHMETHOD_CONTAINS_IGNORE_CASE: - return model.SEARCHMETHOD_CONTAINS_IGNORE_CASE + return model.SearchMethodContainsIgnoreCase case SearchMethod_SEARCHMETHOD_STARTS_WITH_IGNORE_CASE: - return model.SEARCHMETHOD_STARTS_WITH_IGNORE_CASE + return model.SearchMethodStartsWithIgnoreCase case SearchMethod_SEARCHMETHOD_NOT_EQUALS: - return model.SEARCHMETHOD_NOT_EQUALS + return model.SearchMethodNotEquals case SearchMethod_SEARCHMETHOD_IS_ONE_OF: - return model.SEARCHMETHOD_IS_ONE_OF + return model.SearchMethodIsOneOf case SearchMethod_SEARCHMETHOD_LIST_CONTAINS: - return model.SEARCHMETHOD_LIST_CONTAINS + return model.SearchMethodListContains default: - return model.SEARCHMETHOD_EQUALS + return model.SearchMethodEquals } } diff --git a/pkg/management/api/grpc/user_converter.go b/pkg/management/api/grpc/user_converter.go index 06953fc721..c0fa63e01c 100644 --- a/pkg/management/api/grpc/user_converter.go +++ b/pkg/management/api/grpc/user_converter.go @@ -119,21 +119,21 @@ func userSearchQueryToModel(query *UserSearchQuery) *usr_model.UserSearchQuery { func userSearchKeyToModel(key UserSearchKey) usr_model.UserSearchKey { switch key { case UserSearchKey_USERSEARCHKEY_USER_NAME: - return usr_model.USERSEARCHKEY_USER_NAME + return usr_model.UserSearchKeyUserName case UserSearchKey_USERSEARCHKEY_FIRST_NAME: - return usr_model.USERSEARCHKEY_FIRST_NAME + return usr_model.UserSearchKeyFirstName case UserSearchKey_USERSEARCHKEY_LAST_NAME: - return usr_model.USERSEARCHKEY_LAST_NAME + return usr_model.UserSearchKeyLastName case UserSearchKey_USERSEARCHKEY_NICK_NAME: - return usr_model.USERSEARCHKEY_NICK_NAME + return usr_model.UserSearchKeyNickName case UserSearchKey_USERSEARCHKEY_DISPLAY_NAME: - return usr_model.USERSEARCHKEY_DISPLAY_NAME + return usr_model.UserSearchKeyDisplayName case UserSearchKey_USERSEARCHKEY_EMAIL: - return usr_model.USERSEARCHKEY_EMAIL + return usr_model.UserSearchKeyEmail case UserSearchKey_USERSEARCHKEY_STATE: - return usr_model.USERSEARCHKEY_STATE + return usr_model.UserSearchKeyState default: - return usr_model.USERSEARCHKEY_UNSPECIFIED + return usr_model.UserSearchKeyUnspecified } } @@ -409,25 +409,25 @@ func mfaFromModel(mfa *usr_model.MultiFactor) *MultiFactor { func notifyTypeToModel(state NotificationType) usr_model.NotificationType { switch state { case NotificationType_NOTIFICATIONTYPE_EMAIL: - return usr_model.NOTIFICATIONTYPE_EMAIL + return usr_model.NotificationTypeEmail case NotificationType_NOTIFICATIONTYPE_SMS: - return usr_model.NOTIFICATIONTYPE_SMS + return usr_model.NotificationTypeSms default: - return usr_model.NOTIFICATIONTYPE_EMAIL + return usr_model.NotificationTypeEmail } } func userStateFromModel(state usr_model.UserState) UserState { switch state { - case usr_model.USERSTATE_ACTIVE: + case usr_model.UserStateActive: return UserState_USERSTATE_ACTIVE - case usr_model.USERSTATE_INACTIVE: + case usr_model.UserStateInactive: return UserState_USERSTATE_INACTIVE - case usr_model.USERSTATE_LOCKED: + case usr_model.UserStateLocked: return UserState_USERSTATE_LOCKED - case usr_model.USERSTATE_INITIAL: + case usr_model.UserStateInitial: return UserState_USERSTATE_INITIAL - case usr_model.USERSTATE_SUSPEND: + case usr_model.UserStateSuspend: return UserState_USERSTATE_SUSPEND default: return UserState_USERSTATE_UNSPECIFIED @@ -436,11 +436,11 @@ func userStateFromModel(state usr_model.UserState) UserState { func genderFromModel(gender usr_model.Gender) Gender { switch gender { - case usr_model.GENDER_FEMALE: + case usr_model.GenderFemale: return Gender_GENDER_FEMALE - case usr_model.GENDER_MALE: + case usr_model.GenderMale: return Gender_GENDER_MALE - case usr_model.GENDER_DIVERSE: + case usr_model.GenderDiverse: return Gender_GENDER_DIVERSE default: return Gender_GENDER_UNSPECIFIED @@ -450,21 +450,21 @@ func genderFromModel(gender usr_model.Gender) Gender { func genderToModel(gender Gender) usr_model.Gender { switch gender { case Gender_GENDER_FEMALE: - return usr_model.GENDER_FEMALE + return usr_model.GenderFemale case Gender_GENDER_MALE: - return usr_model.GENDER_MALE + return usr_model.GenderMale case Gender_GENDER_DIVERSE: - return usr_model.GENDER_DIVERSE + return usr_model.GenderDiverse default: - return usr_model.GENDER_UNDEFINED + return usr_model.GenderUnspecified } } -func mfaTypeFromModel(mfatype usr_model.MFAType) MfaType { +func mfaTypeFromModel(mfatype usr_model.MfaType) MfaType { switch mfatype { - case usr_model.MFATYPE_OTP: + case usr_model.MfaTypeOTP: return MfaType_MFATYPE_OTP - case usr_model.MFATYPE_SMS: + case usr_model.MfaTypeSMS: return MfaType_MFATYPE_SMS default: return MfaType_MFATYPE_UNSPECIFIED @@ -473,9 +473,9 @@ func mfaTypeFromModel(mfatype usr_model.MFAType) MfaType { func mfaStateFromModel(state usr_model.MfaState) MFAState { switch state { - case usr_model.MFASTATE_READY: + case usr_model.MfaStateReady: return MFAState_MFASTATE_READY - case usr_model.MFASTATE_NOTREADY: + case usr_model.MfaStateNotReady: return MFAState_MFASTATE_NOT_READY default: return MFAState_MFASTATE_UNSPECIFIED diff --git a/pkg/management/api/grpc/user_grant_converter.go b/pkg/management/api/grpc/user_grant_converter.go index 8141af32ad..23e02df725 100644 --- a/pkg/management/api/grpc/user_grant_converter.go +++ b/pkg/management/api/grpc/user_grant_converter.go @@ -115,15 +115,15 @@ func userGrantSearchQueryToModel(query *UserGrantSearchQuery) *grant_model.UserG func userGrantSearchKeyToModel(key UserGrantSearchKey) grant_model.UserGrantSearchKey { switch key { case UserGrantSearchKey_USERGRANTSEARCHKEY_ORG_ID: - return grant_model.USERGRANTSEARCHKEY_RESOURCEOWNER + return grant_model.UserGrantSearchKeyResourceOwner case UserGrantSearchKey_USERGRANTSEARCHKEY_PROJECT_ID: - return grant_model.USERGRANTSEARCHKEY_PROJECT_ID + return grant_model.UserGrantSearchKeyProjectID case UserGrantSearchKey_USERGRANTSEARCHKEY_USER_ID: - return grant_model.USERGRANTSEARCHKEY_USER_ID + return grant_model.UserGrantSearchKeyUserID case UserGrantSearchKey_USERGRANTSEARCHKEY_ROLE_KEY: - return grant_model.USERGRANTSEARCHKEY_ROLE_KEY + return grant_model.UserGrantSearchKeyRoleKey default: - return grant_model.USERGRANTSEARCHKEY_UNSPECIFIED + return grant_model.UserGrantSearchKeyUnspecified } } @@ -171,9 +171,9 @@ func userGrantViewFromModel(grant *grant_model.UserGrantView) *UserGrantView { func usergrantStateFromModel(state grant_model.UserGrantState) UserGrantState { switch state { - case grant_model.USERGRANTSTATE_ACTIVE: + case grant_model.UserGrantStateActive: return UserGrantState_USERGRANTSTATE_ACTIVE - case grant_model.USERGRANTSTATE_INACTIVE: + case grant_model.UserGrantStateInactive: return UserGrantState_USERGRANTSTATE_INACTIVE default: return UserGrantState_USERGRANTSTATE_UNSPECIFIED