From bffcccf99de8a8f3c68cff9e39d2847f0996b67b Mon Sep 17 00:00:00 2001 From: Harshil Sharma Date: Wed, 10 Oct 2018 00:55:47 +0000 Subject: Refactored to rename "service terms" to "terms of service" (#9581) * #124 renamed identififers from service terms to terms of service * #124 renamed identififers from service terms to terms of service * 124 renamed ServiceTerms model to TermsOfService * 124 Renamed EnableCustomServiceTerms feature flag to EnableCustomTermsOfService * 124 Renamed EnableCustomServiceTerms feature flag to EnableCustomTermsOfService * #124 fixed formatting * #124 fixed formatting * #132 renamed table ServiceTerms to TermsOfService * #124 renamed some missed files from 'service_terms' to 'terms_of_service' * #124 removed fixed TODOs * drop migrate of ServiceTerms table, since backporting * s/ServiceTerms/TermsOfService/ in tests * s/AcceptedServiceTermsId/AcceptedTermsOfServiceId/ Change the model attribute, even though the column name will eventually be removed. * s/accepted_service_terms_id/accepted_terms_of_service_id/ to match redux * s/serviceTerms/termsOfService * rename column too, and add max size constraint * s/EnableCustomServiceTerms/EnableCustomTermsOfService --- store/layered_store.go | 4 +- store/sqlstore/service_terms_store.go | 143 --------------------- store/sqlstore/service_terms_store_test.go | 10 -- store/sqlstore/store.go | 2 +- store/sqlstore/supplier.go | 10 +- store/sqlstore/terms_of_service_store.go | 143 +++++++++++++++++++++ store/sqlstore/terms_of_service_store_test.go | 10 ++ store/sqlstore/upgrade.go | 2 +- store/sqlstore/user_store.go | 1 + store/store.go | 6 +- store/storetest/mocks/LayeredStoreDatabaseLayer.go | 32 ++--- store/storetest/mocks/ServiceTermsStore.go | 62 --------- store/storetest/mocks/SqlStore.go | 32 ++--- store/storetest/mocks/Store.go | 32 ++--- store/storetest/mocks/TermsOfServiceStore.go | 62 +++++++++ store/storetest/service_terms_store.go | 82 ------------ store/storetest/store.go | 4 +- store/storetest/terms_of_service_store.go | 82 ++++++++++++ 18 files changed, 360 insertions(+), 359 deletions(-) delete mode 100644 store/sqlstore/service_terms_store.go delete mode 100644 store/sqlstore/service_terms_store_test.go create mode 100644 store/sqlstore/terms_of_service_store.go create mode 100644 store/sqlstore/terms_of_service_store_test.go delete mode 100644 store/storetest/mocks/ServiceTermsStore.go create mode 100644 store/storetest/mocks/TermsOfServiceStore.go delete mode 100644 store/storetest/service_terms_store.go create mode 100644 store/storetest/terms_of_service_store.go (limited to 'store') diff --git a/store/layered_store.go b/store/layered_store.go index f5f1f9b54..da2880fa5 100644 --- a/store/layered_store.go +++ b/store/layered_store.go @@ -169,8 +169,8 @@ func (s *LayeredStore) Role() RoleStore { return s.RoleStore } -func (s *LayeredStore) ServiceTerms() ServiceTermsStore { - return s.DatabaseLayer.ServiceTerms() +func (s *LayeredStore) TermsOfService() TermsOfServiceStore { + return s.DatabaseLayer.TermsOfService() } func (s *LayeredStore) Scheme() SchemeStore { diff --git a/store/sqlstore/service_terms_store.go b/store/sqlstore/service_terms_store.go deleted file mode 100644 index 43a1189f6..000000000 --- a/store/sqlstore/service_terms_store.go +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -package sqlstore - -import ( - "database/sql" - "github.com/mattermost/mattermost-server/einterfaces" - "github.com/mattermost/mattermost-server/model" - "github.com/mattermost/mattermost-server/store" - "github.com/mattermost/mattermost-server/utils" - "net/http" -) - -type SqlServiceTermsStore struct { - SqlStore - metrics einterfaces.MetricsInterface -} - -var serviceTermsCache = utils.NewLru(model.SERVICE_TERMS_CACHE_SIZE) - -const serviceTermsCacheName = "ServiceTerms" - -func NewSqlTermStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) store.ServiceTermsStore { - s := SqlServiceTermsStore{sqlStore, metrics} - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.ServiceTerms{}, "ServiceTerms").SetKeys(false, "Id") - table.ColMap("Id").SetMaxSize(26) - table.ColMap("UserId").SetMaxSize(26) - table.ColMap("Text").SetMaxSize(model.POST_MESSAGE_MAX_BYTES_V2) - } - - return s -} - -func (s SqlServiceTermsStore) CreateIndexesIfNotExists() { -} - -func (s SqlServiceTermsStore) Save(serviceTerms *model.ServiceTerms) store.StoreChannel { - return store.Do(func(result *store.StoreResult) { - if len(serviceTerms.Id) > 0 { - result.Err = model.NewAppError( - "SqlServiceTermsStore.Save", - "store.sql_service_terms_store.save.existing.app_error", - nil, - "id="+serviceTerms.Id, http.StatusBadRequest, - ) - return - } - - serviceTerms.PreSave() - - if result.Err = serviceTerms.IsValid(); result.Err != nil { - return - } - - if err := s.GetMaster().Insert(serviceTerms); err != nil { - result.Err = model.NewAppError( - "SqlServiceTermsStore.Save", - "store.sql_service_terms.save.app_error", - nil, - "service_term_id="+serviceTerms.Id+",err="+err.Error(), - http.StatusInternalServerError, - ) - } - - result.Data = serviceTerms - - serviceTermsCache.AddWithDefaultExpires(serviceTerms.Id, serviceTerms) - }) -} - -func (s SqlServiceTermsStore) GetLatest(allowFromCache bool) store.StoreChannel { - return store.Do(func(result *store.StoreResult) { - if allowFromCache { - if serviceTermsCache.Len() == 0 { - if s.metrics != nil { - s.metrics.IncrementMemCacheMissCounter(serviceTermsCacheName) - } - } else { - if cacheItem, ok := serviceTermsCache.Get(serviceTermsCache.Keys()[0]); ok { - if s.metrics != nil { - s.metrics.IncrementMemCacheHitCounter(serviceTermsCacheName) - } - - result.Data = cacheItem.(*model.ServiceTerms) - return - } else if s.metrics != nil { - s.metrics.IncrementMemCacheMissCounter(serviceTermsCacheName) - } - } - } - - var serviceTerms *model.ServiceTerms - - err := s.GetReplica().SelectOne(&serviceTerms, "SELECT * FROM ServiceTerms ORDER BY CreateAt DESC LIMIT 1") - if err != nil { - if err == sql.ErrNoRows { - result.Err = model.NewAppError("SqlServiceTermsStore.GetLatest", "store.sql_service_terms_store.get.no_rows.app_error", nil, "err="+err.Error(), http.StatusNotFound) - } else { - result.Err = model.NewAppError("SqlServiceTermsStore.GetLatest", "store.sql_service_terms_store.get.app_error", nil, "err="+err.Error(), http.StatusInternalServerError) - } - } else { - result.Data = serviceTerms - - if allowFromCache { - serviceTermsCache.AddWithDefaultExpires(serviceTerms.Id, serviceTerms) - } - } - }) -} - -func (s SqlServiceTermsStore) Get(id string, allowFromCache bool) store.StoreChannel { - return store.Do(func(result *store.StoreResult) { - if allowFromCache { - if serviceTermsCache.Len() == 0 { - if s.metrics != nil { - s.metrics.IncrementMemCacheMissCounter(serviceTermsCacheName) - } - } else { - if cacheItem, ok := serviceTermsCache.Get(id); ok { - if s.metrics != nil { - s.metrics.IncrementMemCacheHitCounter(serviceTermsCacheName) - } - - result.Data = cacheItem.(*model.ServiceTerms) - return - } else if s.metrics != nil { - s.metrics.IncrementMemCacheMissCounter(serviceTermsCacheName) - } - } - } - - if obj, err := s.GetReplica().Get(model.ServiceTerms{}, id); err != nil { - result.Err = model.NewAppError("SqlServiceTermsStore.Get", "store.sql_service_terms_store.get.app_error", nil, "err="+err.Error(), http.StatusInternalServerError) - } else if obj == nil { - result.Err = model.NewAppError("SqlServiceTermsStore.GetLatest", "store.sql_service_terms_store.get.no_rows.app_error", nil, "", http.StatusNotFound) - } else { - result.Data = obj.(*model.ServiceTerms) - } - }) -} diff --git a/store/sqlstore/service_terms_store_test.go b/store/sqlstore/service_terms_store_test.go deleted file mode 100644 index 030d0d7ae..000000000 --- a/store/sqlstore/service_terms_store_test.go +++ /dev/null @@ -1,10 +0,0 @@ -package sqlstore - -import ( - "github.com/mattermost/mattermost-server/store/storetest" - "testing" -) - -func TestServiceTermsStore(t *testing.T) { - StoreTest(t, storetest.TestServiceTermsStore) -} diff --git a/store/sqlstore/store.go b/store/sqlstore/store.go index b6f0fa84e..0408c5feb 100644 --- a/store/sqlstore/store.go +++ b/store/sqlstore/store.go @@ -93,5 +93,5 @@ type SqlStore interface { UserAccessToken() store.UserAccessTokenStore Role() store.RoleStore Scheme() store.SchemeStore - ServiceTerms() store.ServiceTermsStore + TermsOfService() store.TermsOfServiceStore } diff --git a/store/sqlstore/supplier.go b/store/sqlstore/supplier.go index 62c1102ca..2fc299dc9 100644 --- a/store/sqlstore/supplier.go +++ b/store/sqlstore/supplier.go @@ -92,7 +92,7 @@ type SqlSupplierOldStores struct { channelMemberHistory store.ChannelMemberHistoryStore role store.RoleStore scheme store.SchemeStore - serviceTerms store.ServiceTermsStore + TermsOfService store.TermsOfServiceStore } type SqlSupplier struct { @@ -146,7 +146,7 @@ func NewSqlSupplier(settings model.SqlSettings, metrics einterfaces.MetricsInter supplier.oldStores.userAccessToken = NewSqlUserAccessTokenStore(supplier) supplier.oldStores.channelMemberHistory = NewSqlChannelMemberHistoryStore(supplier) supplier.oldStores.plugin = NewSqlPluginStore(supplier) - supplier.oldStores.serviceTerms = NewSqlTermStore(supplier, metrics) + supplier.oldStores.TermsOfService = NewSqlTermsOfServiceStore(supplier, metrics) initSqlSupplierReactions(supplier) initSqlSupplierRoles(supplier) @@ -182,7 +182,7 @@ func NewSqlSupplier(settings model.SqlSettings, metrics einterfaces.MetricsInter supplier.oldStores.job.(*SqlJobStore).CreateIndexesIfNotExists() supplier.oldStores.userAccessToken.(*SqlUserAccessTokenStore).CreateIndexesIfNotExists() supplier.oldStores.plugin.(*SqlPluginStore).CreateIndexesIfNotExists() - supplier.oldStores.serviceTerms.(SqlServiceTermsStore).CreateIndexesIfNotExists() + supplier.oldStores.TermsOfService.(SqlTermsOfServiceStore).CreateIndexesIfNotExists() supplier.oldStores.preference.(*SqlPreferenceStore).DeleteUnusedFeatures() @@ -964,8 +964,8 @@ func (ss *SqlSupplier) Role() store.RoleStore { return ss.oldStores.role } -func (ss *SqlSupplier) ServiceTerms() store.ServiceTermsStore { - return ss.oldStores.serviceTerms +func (ss *SqlSupplier) TermsOfService() store.TermsOfServiceStore { + return ss.oldStores.TermsOfService } func (ss *SqlSupplier) Scheme() store.SchemeStore { diff --git a/store/sqlstore/terms_of_service_store.go b/store/sqlstore/terms_of_service_store.go new file mode 100644 index 000000000..dc9ce5b5c --- /dev/null +++ b/store/sqlstore/terms_of_service_store.go @@ -0,0 +1,143 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package sqlstore + +import ( + "database/sql" + "github.com/mattermost/mattermost-server/einterfaces" + "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/store" + "github.com/mattermost/mattermost-server/utils" + "net/http" +) + +type SqlTermsOfServiceStore struct { + SqlStore + metrics einterfaces.MetricsInterface +} + +var termsOfServiceCache = utils.NewLru(model.TERMS_OF_SERVICE_CACHE_SIZE) + +const termsOfServiceCacheName = "TermsOfServiceStore" + +func NewSqlTermsOfServiceStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) store.TermsOfServiceStore { + s := SqlTermsOfServiceStore{sqlStore, metrics} + + for _, db := range sqlStore.GetAllConns() { + table := db.AddTableWithName(model.TermsOfService{}, "TermsOfService").SetKeys(false, "Id") + table.ColMap("Id").SetMaxSize(26) + table.ColMap("UserId").SetMaxSize(26) + table.ColMap("Text").SetMaxSize(model.POST_MESSAGE_MAX_BYTES_V2) + } + + return s +} + +func (s SqlTermsOfServiceStore) CreateIndexesIfNotExists() { +} + +func (s SqlTermsOfServiceStore) Save(termsOfService *model.TermsOfService) store.StoreChannel { + return store.Do(func(result *store.StoreResult) { + if len(termsOfService.Id) > 0 { + result.Err = model.NewAppError( + "SqlTermsOfServiceStore.Save", + "store.sql_terms_of_service_store.save.existing.app_error", + nil, + "id="+termsOfService.Id, http.StatusBadRequest, + ) + return + } + + termsOfService.PreSave() + + if result.Err = termsOfService.IsValid(); result.Err != nil { + return + } + + if err := s.GetMaster().Insert(termsOfService); err != nil { + result.Err = model.NewAppError( + "SqlTermsOfServiceStore.Save", + "store.sql_terms_of_service.save.app_error", + nil, + "terms_of_service_id="+termsOfService.Id+",err="+err.Error(), + http.StatusInternalServerError, + ) + } + + result.Data = termsOfService + + termsOfServiceCache.AddWithDefaultExpires(termsOfService.Id, termsOfService) + }) +} + +func (s SqlTermsOfServiceStore) GetLatest(allowFromCache bool) store.StoreChannel { + return store.Do(func(result *store.StoreResult) { + if allowFromCache { + if termsOfServiceCache.Len() == 0 { + if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter(termsOfServiceCacheName) + } + } else { + if cacheItem, ok := termsOfServiceCache.Get(termsOfServiceCache.Keys()[0]); ok { + if s.metrics != nil { + s.metrics.IncrementMemCacheHitCounter(termsOfServiceCacheName) + } + + result.Data = cacheItem.(*model.TermsOfService) + return + } else if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter(termsOfServiceCacheName) + } + } + } + + var termsOfService *model.TermsOfService + + err := s.GetReplica().SelectOne(&termsOfService, "SELECT * FROM TermsOfService ORDER BY CreateAt DESC LIMIT 1") + if err != nil { + if err == sql.ErrNoRows { + result.Err = model.NewAppError("SqlTermsOfServiceStore.GetLatest", "store.sql_terms_of_service_store.get.no_rows.app_error", nil, "err="+err.Error(), http.StatusNotFound) + } else { + result.Err = model.NewAppError("SqlTermsOfServiceStore.GetLatest", "store.sql_terms_of_service_store.get.app_error", nil, "err="+err.Error(), http.StatusInternalServerError) + } + } else { + result.Data = termsOfService + + if allowFromCache { + termsOfServiceCache.AddWithDefaultExpires(termsOfService.Id, termsOfService) + } + } + }) +} + +func (s SqlTermsOfServiceStore) Get(id string, allowFromCache bool) store.StoreChannel { + return store.Do(func(result *store.StoreResult) { + if allowFromCache { + if termsOfServiceCache.Len() == 0 { + if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter(termsOfServiceCacheName) + } + } else { + if cacheItem, ok := termsOfServiceCache.Get(id); ok { + if s.metrics != nil { + s.metrics.IncrementMemCacheHitCounter(termsOfServiceCacheName) + } + + result.Data = cacheItem.(*model.TermsOfService) + return + } else if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter(termsOfServiceCacheName) + } + } + } + + if obj, err := s.GetReplica().Get(model.TermsOfService{}, id); err != nil { + result.Err = model.NewAppError("SqlTermsOfServiceStore.Get", "store.sql_terms_of_service_store.get.app_error", nil, "err="+err.Error(), http.StatusInternalServerError) + } else if obj == nil { + result.Err = model.NewAppError("SqlTermsOfServiceStore.GetLatest", "store.sql_terms_of_service_store.get.no_rows.app_error", nil, "", http.StatusNotFound) + } else { + result.Data = obj.(*model.TermsOfService) + } + }) +} diff --git a/store/sqlstore/terms_of_service_store_test.go b/store/sqlstore/terms_of_service_store_test.go new file mode 100644 index 000000000..c41fe7210 --- /dev/null +++ b/store/sqlstore/terms_of_service_store_test.go @@ -0,0 +1,10 @@ +package sqlstore + +import ( + "github.com/mattermost/mattermost-server/store/storetest" + "testing" +) + +func TestTermsOfServiceStore(t *testing.T) { + StoreTest(t, storetest.TestTermsOfServiceStore) +} diff --git a/store/sqlstore/upgrade.go b/store/sqlstore/upgrade.go index 31815e41e..42d34f525 100644 --- a/store/sqlstore/upgrade.go +++ b/store/sqlstore/upgrade.go @@ -502,7 +502,7 @@ func UpgradeDatabaseToVersion54(sqlStore SqlStore) { time.Sleep(time.Second) os.Exit(EXIT_GENERIC_FAILURE) } - sqlStore.CreateColumnIfNotExists("Users", "AcceptedServiceTermsId", "varchar(64)", "varchar(64)", "") + sqlStore.CreateColumnIfNotExists("Users", "AcceptedTermsOfServiceId", "varchar(64)", "varchar(64)", "") saveSchemaVersion(sqlStore, VERSION_5_4_0) } } diff --git a/store/sqlstore/user_store.go b/store/sqlstore/user_store.go index 1b9752064..f0839c3b7 100644 --- a/store/sqlstore/user_store.go +++ b/store/sqlstore/user_store.go @@ -82,6 +82,7 @@ func NewSqlUserStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) st table.ColMap("MfaSecret").SetMaxSize(128) table.ColMap("Position").SetMaxSize(128) table.ColMap("Timezone").SetMaxSize(256) + table.ColMap("AcceptedTermsOfServiceId").SetMaxSize(64) } return us diff --git a/store/store.go b/store/store.go index 8a2051527..29028130e 100644 --- a/store/store.go +++ b/store/store.go @@ -65,7 +65,7 @@ type Store interface { UserAccessToken() UserAccessTokenStore ChannelMemberHistory() ChannelMemberHistoryStore Plugin() PluginStore - ServiceTerms() ServiceTermsStore + TermsOfService() TermsOfServiceStore MarkSystemRanUnitTests() Close() LockToMaster() @@ -523,8 +523,8 @@ type SchemeStore interface { PermanentDeleteAll() StoreChannel } -type ServiceTermsStore interface { - Save(serviceTerms *model.ServiceTerms) StoreChannel +type TermsOfServiceStore interface { + Save(termsOfService *model.TermsOfService) StoreChannel GetLatest(allowFromCache bool) StoreChannel Get(id string, allowFromCache bool) StoreChannel } diff --git a/store/storetest/mocks/LayeredStoreDatabaseLayer.go b/store/storetest/mocks/LayeredStoreDatabaseLayer.go index 7f653fc2f..3b06bbdf5 100644 --- a/store/storetest/mocks/LayeredStoreDatabaseLayer.go +++ b/store/storetest/mocks/LayeredStoreDatabaseLayer.go @@ -729,22 +729,6 @@ func (_m *LayeredStoreDatabaseLayer) SchemeSave(ctx context.Context, scheme *mod return r0 } -// ServiceTerms provides a mock function with given fields: -func (_m *LayeredStoreDatabaseLayer) ServiceTerms() store.ServiceTermsStore { - ret := _m.Called() - - var r0 store.ServiceTermsStore - if rf, ok := ret.Get(0).(func() store.ServiceTermsStore); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(store.ServiceTermsStore) - } - } - - return r0 -} - // Session provides a mock function with given fields: func (_m *LayeredStoreDatabaseLayer) Session() store.SessionStore { ret := _m.Called() @@ -814,6 +798,22 @@ func (_m *LayeredStoreDatabaseLayer) Team() store.TeamStore { return r0 } +// TermsOfService provides a mock function with given fields: +func (_m *LayeredStoreDatabaseLayer) TermsOfService() store.TermsOfServiceStore { + ret := _m.Called() + + var r0 store.TermsOfServiceStore + if rf, ok := ret.Get(0).(func() store.TermsOfServiceStore); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(store.TermsOfServiceStore) + } + } + + return r0 +} + // Token provides a mock function with given fields: func (_m *LayeredStoreDatabaseLayer) Token() store.TokenStore { ret := _m.Called() diff --git a/store/storetest/mocks/ServiceTermsStore.go b/store/storetest/mocks/ServiceTermsStore.go deleted file mode 100644 index 9115e6093..000000000 --- a/store/storetest/mocks/ServiceTermsStore.go +++ /dev/null @@ -1,62 +0,0 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. - -// Regenerate this file using `make store-mocks`. - -package mocks - -import mock "github.com/stretchr/testify/mock" -import model "github.com/mattermost/mattermost-server/model" -import store "github.com/mattermost/mattermost-server/store" - -// ServiceTermsStore is an autogenerated mock type for the ServiceTermsStore type -type ServiceTermsStore struct { - mock.Mock -} - -// Get provides a mock function with given fields: id, allowFromCache -func (_m *ServiceTermsStore) Get(id string, allowFromCache bool) store.StoreChannel { - ret := _m.Called(id, allowFromCache) - - var r0 store.StoreChannel - if rf, ok := ret.Get(0).(func(string, bool) store.StoreChannel); ok { - r0 = rf(id, allowFromCache) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(store.StoreChannel) - } - } - - return r0 -} - -// GetLatest provides a mock function with given fields: allowFromCache -func (_m *ServiceTermsStore) GetLatest(allowFromCache bool) store.StoreChannel { - ret := _m.Called(allowFromCache) - - var r0 store.StoreChannel - if rf, ok := ret.Get(0).(func(bool) store.StoreChannel); ok { - r0 = rf(allowFromCache) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(store.StoreChannel) - } - } - - return r0 -} - -// Save provides a mock function with given fields: serviceTerms -func (_m *ServiceTermsStore) Save(serviceTerms *model.ServiceTerms) store.StoreChannel { - ret := _m.Called(serviceTerms) - - var r0 store.StoreChannel - if rf, ok := ret.Get(0).(func(*model.ServiceTerms) store.StoreChannel); ok { - r0 = rf(serviceTerms) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(store.StoreChannel) - } - } - - return r0 -} diff --git a/store/storetest/mocks/SqlStore.go b/store/storetest/mocks/SqlStore.go index c2852f3a1..278ca1a61 100644 --- a/store/storetest/mocks/SqlStore.go +++ b/store/storetest/mocks/SqlStore.go @@ -603,22 +603,6 @@ func (_m *SqlStore) Scheme() store.SchemeStore { return r0 } -// ServiceTerms provides a mock function with given fields: -func (_m *SqlStore) ServiceTerms() store.ServiceTermsStore { - ret := _m.Called() - - var r0 store.ServiceTermsStore - if rf, ok := ret.Get(0).(func() store.ServiceTermsStore); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(store.ServiceTermsStore) - } - } - - return r0 -} - // Session provides a mock function with given fields: func (_m *SqlStore) Session() store.SessionStore { ret := _m.Called() @@ -683,6 +667,22 @@ func (_m *SqlStore) Team() store.TeamStore { return r0 } +// TermsOfService provides a mock function with given fields: +func (_m *SqlStore) TermsOfService() store.TermsOfServiceStore { + ret := _m.Called() + + var r0 store.TermsOfServiceStore + if rf, ok := ret.Get(0).(func() store.TermsOfServiceStore); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(store.TermsOfServiceStore) + } + } + + return r0 +} + // Token provides a mock function with given fields: func (_m *SqlStore) Token() store.TokenStore { ret := _m.Called() diff --git a/store/storetest/mocks/Store.go b/store/storetest/mocks/Store.go index 8f15650e8..b55df2097 100644 --- a/store/storetest/mocks/Store.go +++ b/store/storetest/mocks/Store.go @@ -320,22 +320,6 @@ func (_m *Store) Scheme() store.SchemeStore { return r0 } -// ServiceTerms provides a mock function with given fields: -func (_m *Store) ServiceTerms() store.ServiceTermsStore { - ret := _m.Called() - - var r0 store.ServiceTermsStore - if rf, ok := ret.Get(0).(func() store.ServiceTermsStore); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(store.ServiceTermsStore) - } - } - - return r0 -} - // Session provides a mock function with given fields: func (_m *Store) Session() store.SessionStore { ret := _m.Called() @@ -400,6 +384,22 @@ func (_m *Store) Team() store.TeamStore { return r0 } +// TermsOfService provides a mock function with given fields: +func (_m *Store) TermsOfService() store.TermsOfServiceStore { + ret := _m.Called() + + var r0 store.TermsOfServiceStore + if rf, ok := ret.Get(0).(func() store.TermsOfServiceStore); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(store.TermsOfServiceStore) + } + } + + return r0 +} + // Token provides a mock function with given fields: func (_m *Store) Token() store.TokenStore { ret := _m.Called() diff --git a/store/storetest/mocks/TermsOfServiceStore.go b/store/storetest/mocks/TermsOfServiceStore.go new file mode 100644 index 000000000..54dcee1fc --- /dev/null +++ b/store/storetest/mocks/TermsOfServiceStore.go @@ -0,0 +1,62 @@ +// Code generated by mockery v1.0.0. DO NOT EDIT. + +// Regenerate this file using `make store-mocks`. + +package mocks + +import mock "github.com/stretchr/testify/mock" +import model "github.com/mattermost/mattermost-server/model" +import store "github.com/mattermost/mattermost-server/store" + +// TermsOfServiceStore is an autogenerated mock type for the TermsOfServiceStore type +type TermsOfServiceStore struct { + mock.Mock +} + +// Get provides a mock function with given fields: id, allowFromCache +func (_m *TermsOfServiceStore) Get(id string, allowFromCache bool) store.StoreChannel { + ret := _m.Called(id, allowFromCache) + + var r0 store.StoreChannel + if rf, ok := ret.Get(0).(func(string, bool) store.StoreChannel); ok { + r0 = rf(id, allowFromCache) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(store.StoreChannel) + } + } + + return r0 +} + +// GetLatest provides a mock function with given fields: allowFromCache +func (_m *TermsOfServiceStore) GetLatest(allowFromCache bool) store.StoreChannel { + ret := _m.Called(allowFromCache) + + var r0 store.StoreChannel + if rf, ok := ret.Get(0).(func(bool) store.StoreChannel); ok { + r0 = rf(allowFromCache) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(store.StoreChannel) + } + } + + return r0 +} + +// Save provides a mock function with given fields: termsOfService +func (_m *TermsOfServiceStore) Save(termsOfService *model.TermsOfService) store.StoreChannel { + ret := _m.Called(termsOfService) + + var r0 store.StoreChannel + if rf, ok := ret.Get(0).(func(*model.TermsOfService) store.StoreChannel); ok { + r0 = rf(termsOfService) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(store.StoreChannel) + } + } + + return r0 +} diff --git a/store/storetest/service_terms_store.go b/store/storetest/service_terms_store.go deleted file mode 100644 index fcb209934..000000000 --- a/store/storetest/service_terms_store.go +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -package storetest - -import ( - "github.com/mattermost/mattermost-server/model" - "github.com/mattermost/mattermost-server/store" - "github.com/stretchr/testify/assert" - "testing" -) - -func TestServiceTermsStore(t *testing.T, ss store.Store) { - t.Run("TestSaveServiceTerms", func(t *testing.T) { testSaveServiceTerms(t, ss) }) - t.Run("TestGetLatestServiceTerms", func(t *testing.T) { testGetLatestServiceTerms(t, ss) }) - t.Run("TestGetServiceTerms", func(t *testing.T) { testGetServiceTerms(t, ss) }) -} - -func testSaveServiceTerms(t *testing.T, ss store.Store) { - u1 := model.User{} - u1.Username = model.NewId() - u1.Email = MakeEmail() - u1.Nickname = model.NewId() - store.Must(ss.User().Save(&u1)) - - serviceTerms := &model.ServiceTerms{Text: "service terms", UserId: u1.Id} - r1 := <-ss.ServiceTerms().Save(serviceTerms) - - if r1.Err != nil { - t.Fatal(r1.Err) - } - - savedServiceTerms := r1.Data.(*model.ServiceTerms) - if len(savedServiceTerms.Id) != 26 { - t.Fatal("Id should have been populated") - } - - if savedServiceTerms.CreateAt == 0 { - t.Fatal("Create at should have been populated") - } -} - -func testGetLatestServiceTerms(t *testing.T, ss store.Store) { - u1 := model.User{} - u1.Username = model.NewId() - u1.Email = MakeEmail() - u1.Nickname = model.NewId() - store.Must(ss.User().Save(&u1)) - - serviceTerms := &model.ServiceTerms{Text: "service terms", UserId: u1.Id} - store.Must(ss.ServiceTerms().Save(serviceTerms)) - - r1 := <-ss.ServiceTerms().GetLatest(true) - if r1.Err != nil { - t.Fatal(r1.Err) - } - - fetchedServiceTerms := r1.Data.(*model.ServiceTerms) - assert.Equal(t, serviceTerms.Text, fetchedServiceTerms.Text) - assert.Equal(t, serviceTerms.UserId, fetchedServiceTerms.UserId) -} - -func testGetServiceTerms(t *testing.T, ss store.Store) { - u1 := model.User{} - u1.Username = model.NewId() - u1.Email = MakeEmail() - u1.Nickname = model.NewId() - store.Must(ss.User().Save(&u1)) - - serviceTerms := &model.ServiceTerms{Text: "service terms", UserId: u1.Id} - store.Must(ss.ServiceTerms().Save(serviceTerms)) - - r1 := <-ss.ServiceTerms().Get("an_invalid_id", true) - assert.NotNil(t, r1.Err) - assert.Nil(t, r1.Data) - - r1 = <-ss.ServiceTerms().Get(serviceTerms.Id, true) - assert.Nil(t, r1.Err) - - receivedServiceTerms := r1.Data.(*model.ServiceTerms) - assert.Equal(t, "service terms", receivedServiceTerms.Text) -} diff --git a/store/storetest/store.go b/store/storetest/store.go index e7086a3a5..d6ef4fcd0 100644 --- a/store/storetest/store.go +++ b/store/storetest/store.go @@ -45,7 +45,7 @@ type Store struct { ChannelMemberHistoryStore mocks.ChannelMemberHistoryStore RoleStore mocks.RoleStore SchemeStore mocks.SchemeStore - ServiceTermsStore mocks.ServiceTermsStore + TermsOfServiceStore mocks.TermsOfServiceStore } func (s *Store) Team() store.TeamStore { return &s.TeamStore } @@ -73,7 +73,7 @@ func (s *Store) UserAccessToken() store.UserAccessTokenStore { return &s.UserA func (s *Store) Plugin() store.PluginStore { return &s.PluginStore } func (s *Store) Role() store.RoleStore { return &s.RoleStore } func (s *Store) Scheme() store.SchemeStore { return &s.SchemeStore } -func (s *Store) ServiceTerms() store.ServiceTermsStore { return &s.ServiceTermsStore } +func (s *Store) TermsOfService() store.TermsOfServiceStore { return &s.TermsOfServiceStore } func (s *Store) ChannelMemberHistory() store.ChannelMemberHistoryStore { return &s.ChannelMemberHistoryStore } diff --git a/store/storetest/terms_of_service_store.go b/store/storetest/terms_of_service_store.go new file mode 100644 index 000000000..90af5c1ee --- /dev/null +++ b/store/storetest/terms_of_service_store.go @@ -0,0 +1,82 @@ +// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package storetest + +import ( + "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/store" + "github.com/stretchr/testify/assert" + "testing" +) + +func TestTermsOfServiceStore(t *testing.T, ss store.Store) { + t.Run("TestSaveTermsOfService", func(t *testing.T) { testSaveTermsOfService(t, ss) }) + t.Run("TestGetLatestTermsOfService", func(t *testing.T) { testGetLatestTermsOfService(t, ss) }) + t.Run("TestGetTermsOfService", func(t *testing.T) { testGetTermsOfService(t, ss) }) +} + +func testSaveTermsOfService(t *testing.T, ss store.Store) { + u1 := model.User{} + u1.Username = model.NewId() + u1.Email = MakeEmail() + u1.Nickname = model.NewId() + store.Must(ss.User().Save(&u1)) + + termsOfService := &model.TermsOfService{Text: "terms of service", UserId: u1.Id} + r1 := <-ss.TermsOfService().Save(termsOfService) + + if r1.Err != nil { + t.Fatal(r1.Err) + } + + savedTermsOfService := r1.Data.(*model.TermsOfService) + if len(savedTermsOfService.Id) != 26 { + t.Fatal("Id should have been populated") + } + + if savedTermsOfService.CreateAt == 0 { + t.Fatal("Create at should have been populated") + } +} + +func testGetLatestTermsOfService(t *testing.T, ss store.Store) { + u1 := model.User{} + u1.Username = model.NewId() + u1.Email = MakeEmail() + u1.Nickname = model.NewId() + store.Must(ss.User().Save(&u1)) + + termsOfService := &model.TermsOfService{Text: "terms of service", UserId: u1.Id} + store.Must(ss.TermsOfService().Save(termsOfService)) + + r1 := <-ss.TermsOfService().GetLatest(true) + if r1.Err != nil { + t.Fatal(r1.Err) + } + + fetchedTermsOfService := r1.Data.(*model.TermsOfService) + assert.Equal(t, termsOfService.Text, fetchedTermsOfService.Text) + assert.Equal(t, termsOfService.UserId, fetchedTermsOfService.UserId) +} + +func testGetTermsOfService(t *testing.T, ss store.Store) { + u1 := model.User{} + u1.Username = model.NewId() + u1.Email = MakeEmail() + u1.Nickname = model.NewId() + store.Must(ss.User().Save(&u1)) + + termsOfService := &model.TermsOfService{Text: "terms of service", UserId: u1.Id} + store.Must(ss.TermsOfService().Save(termsOfService)) + + r1 := <-ss.TermsOfService().Get("an_invalid_id", true) + assert.NotNil(t, r1.Err) + assert.Nil(t, r1.Data) + + r1 = <-ss.TermsOfService().Get(termsOfService.Id, true) + assert.Nil(t, r1.Err) + + receivedTermsOfService := r1.Data.(*model.TermsOfService) + assert.Equal(t, "terms of service", receivedTermsOfService.Text) +} -- cgit v1.2.3-1-g7c22