fix: sort admin orgs by name (#1536)

* fix: sort admin orgs by name

* handle nil pointer in webauthn methods

* rename
This commit is contained in:
Livio Amstutz 2021-04-07 09:56:45 +02:00 committed by GitHub
parent e4fe097ec4
commit f9286574a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 7 deletions

View File

@ -2,7 +2,9 @@ package eventstore
import ( import (
"context" "context"
"github.com/caos/logging" "github.com/caos/logging"
"github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/api/authz" "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) { func (repo *UserGrantRepo) SearchAdminOrgs(request *grant_model.UserGrantSearchRequest) (*grant_model.ProjectOrgSearchResponse, error) {
searchRequest := &org_model.OrgSearchRequest{ searchRequest := &org_model.OrgSearchRequest{
SortingColumn: org_model.OrgSearchKeyOrgName, SortingColumn: org_model.OrgSearchKeyOrgNameIgnoreCase,
Asc: true,
} }
if len(request.Queries) > 0 { if len(request.Queries) > 0 {
for _, q := range request.Queries { for _, q := range request.Queries {

View File

@ -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) userAgg, token, signCount, err := c.finishWebAuthNLogin(ctx, userID, resourceOwner, credentialData, webAuthNLogin, u2fTokens, isLoginUI)
if err != nil { 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, _, pushErr := c.eventstore.PushEvents(ctx,
usr_repo.NewHumanU2FCheckFailedEvent( usr_repo.NewHumanU2FCheckFailedEvent(
ctx, ctx,
@ -329,7 +333,7 @@ func (c *Commands) HumanFinishU2FLogin(ctx context.Context, userID, resourceOwne
authRequestDomainToAuthRequestInfo(authRequest), 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 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) userAgg, token, signCount, err := c.finishWebAuthNLogin(ctx, userID, resourceOwner, credentialData, webAuthNLogin, passwordlessTokens, isLoginUI)
if err != nil { 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, _, pushErr := c.eventstore.PushEvents(ctx,
usr_repo.NewHumanPasswordlessCheckFailedEvent( usr_repo.NewHumanPasswordlessCheckFailedEvent(
ctx, ctx,
@ -370,7 +378,7 @@ func (c *Commands) HumanFinishPasswordlessLogin(ctx context.Context, userID, res
authRequestDomainToAuthRequestInfo(authRequest), 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 return err
} }

View File

@ -1,11 +1,10 @@
package model package model
import ( import (
"github.com/caos/zitadel/internal/domain"
caos_errors "github.com/caos/zitadel/internal/errors"
"time" "time"
"github.com/caos/zitadel/internal/domain"
caos_errors "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore/v1/models" "github.com/caos/zitadel/internal/eventstore/v1/models"
) )
@ -37,6 +36,7 @@ const (
OrgSearchKeyOrgDomain OrgSearchKeyOrgDomain
OrgSearchKeyState OrgSearchKeyState
OrgSearchKeyResourceOwner OrgSearchKeyResourceOwner
OrgSearchKeyOrgNameIgnoreCase //used for lowercase search
) )
type OrgSearchQuery struct { type OrgSearchQuery struct {

View File

@ -57,6 +57,8 @@ func (key OrgSearchKey) ToColumnName() string {
return OrgKeyOrgID return OrgKeyOrgID
case usr_model.OrgSearchKeyOrgName: case usr_model.OrgSearchKeyOrgName:
return OrgKeyOrgName return OrgKeyOrgName
case usr_model.OrgSearchKeyOrgNameIgnoreCase:
return "LOWER(" + OrgKeyOrgName + ")" //used for lowercase search
case usr_model.OrgSearchKeyResourceOwner: case usr_model.OrgSearchKeyResourceOwner:
return OrgKeyResourceOwner return OrgKeyResourceOwner
case usr_model.OrgSearchKeyState: case usr_model.OrgSearchKeyState:

View File

@ -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) { func SearchOrgs(db *gorm.DB, table string, req *org_model.OrgSearchRequest) ([]*model.OrgView, uint64, error) {
orgs := make([]*model.OrgView, 0) 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) count, err := query(db, &orgs)
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err