From 4200d7b2466c4603e63b9750e016f654599a6306 Mon Sep 17 00:00:00 2001 From: Eric Leijonmarck Date: Mon, 3 Oct 2022 12:24:26 +0200 Subject: [PATCH] Auth: fix check for conflict login in validation (#56154) * fix: check for conflict login * review comment fix --- pkg/cmd/grafana-cli/commands/conflict_user_command.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/grafana-cli/commands/conflict_user_command.go b/pkg/cmd/grafana-cli/commands/conflict_user_command.go index d4f5f7acbd6..4a60232c697 100644 --- a/pkg/cmd/grafana-cli/commands/conflict_user_command.go +++ b/pkg/cmd/grafana-cli/commands/conflict_user_command.go @@ -220,10 +220,12 @@ func getValidConflictUsers(r *ConflictResolver, b []byte) error { // need to verify that id or email exists previouslySeenIds := map[string]bool{} previouslySeenEmails := map[string]bool{} + previouslySeenLogins := map[string]bool{} for _, users := range r.Blocks { for _, u := range users { previouslySeenIds[strings.ToLower(u.ID)] = true previouslySeenEmails[strings.ToLower(u.Email)] = true + previouslySeenLogins[strings.ToLower(u.Login)] = true } } @@ -256,8 +258,11 @@ func getValidConflictUsers(r *ConflictResolver, b []byte) error { if err != nil { return fmt.Errorf("could not parse the content of the file with error %e", err) } - if !previouslySeenEmails[strings.ToLower(newUser.Email)] { - return fmt.Errorf("not valid email: %s, email not in previous conflicts seen", newUser.Email) + if newUser.ConflictEmail != "" && !previouslySeenEmails[strings.ToLower(newUser.Email)] { + return fmt.Errorf("not valid email: %s, email not seen in previous conflicts", newUser.Email) + } + if newUser.ConflictLogin != "" && !previouslySeenLogins[strings.ToLower(newUser.Login)] { + return fmt.Errorf("not valid login: %s, login not seen in previous conflicts", newUser.Login) } // valid entry newConflicts = append(newConflicts, *newUser)