From 1f482a5f0b1d0746743f598cf6a682d7dfed063d Mon Sep 17 00:00:00 2001 From: Oleg Gaidarenko Date: Wed, 17 Jul 2019 06:24:56 +0300 Subject: [PATCH] SQLStore: use bool pointer instead of string (#18111) (cherry picked from commit d9f01cb8226896fb3f2fcfb2af19141941779472) --- pkg/models/user.go | 4 +--- pkg/services/sqlstore/user.go | 9 ++------- pkg/services/sqlstore/user_test.go | 9 ++++++--- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/pkg/models/user.go b/pkg/models/user.go index 942fd8e1035..6096e54765f 100644 --- a/pkg/models/user.go +++ b/pkg/models/user.go @@ -147,9 +147,7 @@ type SearchUsersQuery struct { Limit int AuthModule string - // We have to use string not bool, since there is cases when - // we don't care if user is disabled or not - IsDisabled string + IsDisabled *bool Result SearchUserQueryResult } diff --git a/pkg/services/sqlstore/user.go b/pkg/services/sqlstore/user.go index 42dc2177f91..659c2dd864d 100644 --- a/pkg/services/sqlstore/user.go +++ b/pkg/services/sqlstore/user.go @@ -456,14 +456,9 @@ func SearchUsers(query *models.SearchUsersQuery) error { whereParams = append(whereParams, queryWithWildcards, queryWithWildcards, queryWithWildcards) } - if query.IsDisabled != "" { - param, err := strconv.ParseBool(query.IsDisabled) - if err != nil { - return err - } - + if query.IsDisabled != nil { whereConditions = append(whereConditions, "is_disabled = ?") - whereParams = append(whereParams, param) + whereParams = append(whereParams, query.IsDisabled) } if query.AuthModule != "" { diff --git a/pkg/services/sqlstore/user_test.go b/pkg/services/sqlstore/user_test.go index 38e59a53002..ece68ed8915 100644 --- a/pkg/services/sqlstore/user_test.go +++ b/pkg/services/sqlstore/user_test.go @@ -194,7 +194,8 @@ func TestUserDataAccess(t *testing.T) { } }) - query := models.SearchUsersQuery{IsDisabled: "false"} + isDisabled := false + query := models.SearchUsersQuery{IsDisabled: &isDisabled} err := SearchUsers(&query) So(err, ShouldBeNil) @@ -293,7 +294,8 @@ func TestUserDataAccess(t *testing.T) { err := BatchDisableUsers(&disableCmd) So(err, ShouldBeNil) - query := &models.SearchUsersQuery{IsDisabled: "true"} + isDisabled := true + query := &models.SearchUsersQuery{IsDisabled: &isDisabled} err = SearchUsers(query) So(err, ShouldBeNil) @@ -319,7 +321,8 @@ func TestUserDataAccess(t *testing.T) { err := BatchDisableUsers(&disableCmd) So(err, ShouldBeNil) - query := &models.SearchUsersQuery{IsDisabled: "false"} + isDisabled := false + query := &models.SearchUsersQuery{IsDisabled: &isDisabled} err = SearchUsers(query) So(err, ShouldBeNil)