From 00112cae5123b02eee79e8b991618ed5069e07b1 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 23 Sep 2015 15:52:59 -0700 Subject: Assiging first user system_admin role --- store/sql_user_store.go | 19 +++++++++++++++++++ store/sql_user_store_test.go | 18 ++++++++++++++++++ store/store.go | 1 + 3 files changed, 38 insertions(+) (limited to 'store') diff --git a/store/sql_user_store.go b/store/sql_user_store.go index 3fd1c82b5..0a723d965 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -481,3 +481,22 @@ func (us SqlUserStore) GetForExport(teamId string) StoreChannel { return storeChannel } + +func (us SqlUserStore) GetTotalUsersCount() StoreChannel { + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + if count, err := us.GetReplica().SelectInt("SELECT COUNT(Id) FROM Users"); err != nil { + result.Err = model.NewAppError("SqlUserStore.GetTotalUsersCount", "We could not count the users", err.Error()) + } else { + result.Data = count + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} diff --git a/store/sql_user_store_test.go b/store/sql_user_store_test.go index 466da2845..e2a454023 100644 --- a/store/sql_user_store_test.go +++ b/store/sql_user_store_test.go @@ -206,6 +206,24 @@ func TestUserStoreGet(t *testing.T) { } } +func TestUserCountt(t *testing.T) { + Setup() + + u1 := model.User{} + u1.TeamId = model.NewId() + u1.Email = model.NewId() + Must(store.User().Save(&u1)) + + if result := <-store.User().GetTotalUsersCount(); result.Err != nil { + t.Fatal(result.Err) + } else { + count := result.Data.(int64) + if count <= 0 { + t.Fatal() + } + } +} + func TestUserStoreGetProfiles(t *testing.T) { Setup() diff --git a/store/store.go b/store/store.go index 7ba3e1d99..23580f452 100644 --- a/store/store.go +++ b/store/store.go @@ -103,6 +103,7 @@ type UserStore interface { GetEtagForProfiles(teamId string) StoreChannel UpdateFailedPasswordAttempts(userId string, attempts int) StoreChannel GetForExport(teamId string) StoreChannel + GetTotalUsersCount() StoreChannel } type SessionStore interface { -- cgit v1.2.3-1-g7c22