From f9286574a948a0dcdac14eb98ade28b8f758c384 Mon Sep 17 00:00:00 2001 From: Livio Amstutz Date: Wed, 7 Apr 2021 09:56:45 +0200 Subject: [PATCH] fix: sort admin orgs by name (#1536) * fix: sort admin orgs by name * handle nil pointer in webauthn methods * rename --- .../eventsourcing/eventstore/user_grant.go | 5 ++++- internal/command/user_human_webauthn.go | 12 ++++++++++-- internal/org/model/org_view.go | 6 +++--- internal/org/repository/view/model/org_query.go | 2 ++ internal/org/repository/view/org_view.go | 2 +- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/internal/auth/repository/eventsourcing/eventstore/user_grant.go b/internal/auth/repository/eventsourcing/eventstore/user_grant.go index f283514a80..ab8ab93a24 100644 --- a/internal/auth/repository/eventsourcing/eventstore/user_grant.go +++ b/internal/auth/repository/eventsourcing/eventstore/user_grant.go @@ -2,7 +2,9 @@ package eventstore import ( "context" + "github.com/caos/logging" + "github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/api/authz" @@ -195,7 +197,8 @@ func (repo *UserGrantRepo) SearchMyProjectPermissions(ctx context.Context) ([]st func (repo *UserGrantRepo) SearchAdminOrgs(request *grant_model.UserGrantSearchRequest) (*grant_model.ProjectOrgSearchResponse, error) { searchRequest := &org_model.OrgSearchRequest{ - SortingColumn: org_model.OrgSearchKeyOrgName, + SortingColumn: org_model.OrgSearchKeyOrgNameIgnoreCase, + Asc: true, } if len(request.Queries) > 0 { for _, q := range request.Queries { diff --git a/internal/command/user_human_webauthn.go b/internal/command/user_human_webauthn.go index 3f18761638..c602b81c46 100644 --- a/internal/command/user_human_webauthn.go +++ b/internal/command/user_human_webauthn.go @@ -322,6 +322,10 @@ func (c *Commands) HumanFinishU2FLogin(ctx context.Context, userID, resourceOwne userAgg, token, signCount, err := c.finishWebAuthNLogin(ctx, userID, resourceOwner, credentialData, webAuthNLogin, u2fTokens, isLoginUI) if err != nil { + if userAgg == nil { + logging.LogWithFields("EVENT-Addqd", "userID", userID, "resourceOwner", resourceOwner).WithError(err).Warn("missing userAggregate for pushing failed u2f check event") + return err + } _, pushErr := c.eventstore.PushEvents(ctx, usr_repo.NewHumanU2FCheckFailedEvent( ctx, @@ -329,7 +333,7 @@ func (c *Commands) HumanFinishU2FLogin(ctx context.Context, userID, resourceOwne authRequestDomainToAuthRequestInfo(authRequest), ), ) - logging.Log("EVENT-33M9f").OnError(pushErr).WithField("userID", userID).Warn("could not push failed passwordless check event") + logging.LogWithFields("EVENT-Bdgd2", "userID", userID, "resourceOwner", resourceOwner).OnError(pushErr).Warn("could not push failed u2f check event") return err } @@ -363,6 +367,10 @@ func (c *Commands) HumanFinishPasswordlessLogin(ctx context.Context, userID, res userAgg, token, signCount, err := c.finishWebAuthNLogin(ctx, userID, resourceOwner, credentialData, webAuthNLogin, passwordlessTokens, isLoginUI) if err != nil { + if userAgg == nil { + logging.LogWithFields("EVENT-Dbbbw", "userID", userID, "resourceOwner", resourceOwner).WithError(err).Warn("missing userAggregate for pushing failed passwordless check event") + return err + } _, pushErr := c.eventstore.PushEvents(ctx, usr_repo.NewHumanPasswordlessCheckFailedEvent( ctx, @@ -370,7 +378,7 @@ func (c *Commands) HumanFinishPasswordlessLogin(ctx context.Context, userID, res authRequestDomainToAuthRequestInfo(authRequest), ), ) - logging.Log("EVENT-33M9f").OnError(pushErr).WithField("userID", userID).Warn("could not push failed passwordless check event") + logging.LogWithFields("EVENT-33M9f", "userID", userID, "resourceOwner", resourceOwner).OnError(pushErr).Warn("could not push failed passwordless check event") return err } diff --git a/internal/org/model/org_view.go b/internal/org/model/org_view.go index 3bc63f36a3..dd8b5242b1 100644 --- a/internal/org/model/org_view.go +++ b/internal/org/model/org_view.go @@ -1,11 +1,10 @@ package model import ( - "github.com/caos/zitadel/internal/domain" - caos_errors "github.com/caos/zitadel/internal/errors" - "time" + "github.com/caos/zitadel/internal/domain" + caos_errors "github.com/caos/zitadel/internal/errors" "github.com/caos/zitadel/internal/eventstore/v1/models" ) @@ -37,6 +36,7 @@ const ( OrgSearchKeyOrgDomain OrgSearchKeyState OrgSearchKeyResourceOwner + OrgSearchKeyOrgNameIgnoreCase //used for lowercase search ) type OrgSearchQuery struct { diff --git a/internal/org/repository/view/model/org_query.go b/internal/org/repository/view/model/org_query.go index 21194936a4..a875f1a968 100644 --- a/internal/org/repository/view/model/org_query.go +++ b/internal/org/repository/view/model/org_query.go @@ -57,6 +57,8 @@ func (key OrgSearchKey) ToColumnName() string { return OrgKeyOrgID case usr_model.OrgSearchKeyOrgName: return OrgKeyOrgName + case usr_model.OrgSearchKeyOrgNameIgnoreCase: + return "LOWER(" + OrgKeyOrgName + ")" //used for lowercase search case usr_model.OrgSearchKeyResourceOwner: return OrgKeyResourceOwner case usr_model.OrgSearchKeyState: diff --git a/internal/org/repository/view/org_view.go b/internal/org/repository/view/org_view.go index 705abbf9c6..46706aae65 100644 --- a/internal/org/repository/view/org_view.go +++ b/internal/org/repository/view/org_view.go @@ -31,7 +31,7 @@ func OrgByPrimaryDomain(db *gorm.DB, table, primaryDomain string) (*model.OrgVie func SearchOrgs(db *gorm.DB, table string, req *org_model.OrgSearchRequest) ([]*model.OrgView, uint64, error) { orgs := make([]*model.OrgView, 0) - query := repository.PrepareSearchQuery(table, model.OrgSearchRequest{Limit: req.Limit, Offset: req.Offset, Queries: req.Queries, SortingColumn: req.SortingColumn}) + query := repository.PrepareSearchQuery(table, model.OrgSearchRequest{Limit: req.Limit, Offset: req.Offset, Queries: req.Queries, SortingColumn: req.SortingColumn, Asc: req.Asc}) count, err := query(db, &orgs) if err != nil { return nil, 0, err