Merge branch 'master' into post-metadata
Этот коммит содержится в:
@@ -173,6 +173,10 @@ func (s *LayeredStore) TermsOfService() TermsOfServiceStore {
|
||||
return s.DatabaseLayer.TermsOfService()
|
||||
}
|
||||
|
||||
func (s *LayeredStore) UserTermsOfService() UserTermsOfServiceStore {
|
||||
return s.DatabaseLayer.UserTermsOfService()
|
||||
}
|
||||
|
||||
func (s *LayeredStore) Scheme() SchemeStore {
|
||||
return s.SchemeStore
|
||||
}
|
||||
|
||||
@@ -94,4 +94,5 @@ type SqlStore interface {
|
||||
Role() store.RoleStore
|
||||
Scheme() store.SchemeStore
|
||||
TermsOfService() store.TermsOfServiceStore
|
||||
UserTermsOfService() store.UserTermsOfServiceStore
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@ type SqlSupplierOldStores struct {
|
||||
role store.RoleStore
|
||||
scheme store.SchemeStore
|
||||
TermsOfService store.TermsOfServiceStore
|
||||
UserTermsOfService store.UserTermsOfServiceStore
|
||||
}
|
||||
|
||||
type SqlSupplier struct {
|
||||
@@ -142,6 +143,7 @@ func NewSqlSupplier(settings model.SqlSettings, metrics einterfaces.MetricsInter
|
||||
supplier.oldStores.channelMemberHistory = NewSqlChannelMemberHistoryStore(supplier)
|
||||
supplier.oldStores.plugin = NewSqlPluginStore(supplier)
|
||||
supplier.oldStores.TermsOfService = NewSqlTermsOfServiceStore(supplier, metrics)
|
||||
supplier.oldStores.UserTermsOfService = NewSqlUserTermsOfServiceStore(supplier)
|
||||
|
||||
initSqlSupplierReactions(supplier)
|
||||
initSqlSupplierRoles(supplier)
|
||||
@@ -178,6 +180,7 @@ func NewSqlSupplier(settings model.SqlSettings, metrics einterfaces.MetricsInter
|
||||
supplier.oldStores.userAccessToken.(*SqlUserAccessTokenStore).CreateIndexesIfNotExists()
|
||||
supplier.oldStores.plugin.(*SqlPluginStore).CreateIndexesIfNotExists()
|
||||
supplier.oldStores.TermsOfService.(SqlTermsOfServiceStore).CreateIndexesIfNotExists()
|
||||
supplier.oldStores.UserTermsOfService.(SqlUserTermsOfServiceStore).CreateIndexesIfNotExists()
|
||||
|
||||
supplier.oldStores.preference.(*SqlPreferenceStore).DeleteUnusedFeatures()
|
||||
|
||||
@@ -963,6 +966,10 @@ func (ss *SqlSupplier) TermsOfService() store.TermsOfServiceStore {
|
||||
return ss.oldStores.TermsOfService
|
||||
}
|
||||
|
||||
func (ss *SqlSupplier) UserTermsOfService() store.UserTermsOfServiceStore {
|
||||
return ss.oldStores.UserTermsOfService
|
||||
}
|
||||
|
||||
func (ss *SqlSupplier) Scheme() store.SchemeStore {
|
||||
return ss.oldStores.scheme
|
||||
}
|
||||
|
||||
@@ -5,11 +5,12 @@ package sqlstore
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"net/http"
|
||||
|
||||
"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 {
|
||||
@@ -19,7 +20,9 @@ type SqlTermsOfServiceStore struct {
|
||||
|
||||
var termsOfServiceCache = utils.NewLru(model.TERMS_OF_SERVICE_CACHE_SIZE)
|
||||
|
||||
const termsOfServiceCacheName = "TermsOfServiceStore"
|
||||
const (
|
||||
termsOfServiceCacheName = "TermsOfServiceStore"
|
||||
)
|
||||
|
||||
func NewSqlTermsOfServiceStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) store.TermsOfServiceStore {
|
||||
s := SqlTermsOfServiceStore{sqlStore, metrics}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package sqlstore
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/store/storetest"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/store/storetest"
|
||||
)
|
||||
|
||||
func TestTermsOfServiceStore(t *testing.T) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
VERSION_5_6_0 = "5.6.0"
|
||||
VERSION_5_5_0 = "5.5.0"
|
||||
VERSION_5_4_0 = "5.4.0"
|
||||
VERSION_5_3_0 = "5.3.0"
|
||||
@@ -88,6 +89,7 @@ func UpgradeDatabase(sqlStore SqlStore) {
|
||||
UpgradeDatabaseToVersion53(sqlStore)
|
||||
UpgradeDatabaseToVersion54(sqlStore)
|
||||
UpgradeDatabaseToVersion55(sqlStore)
|
||||
UpgradeDatabaseToVersion56(sqlStore)
|
||||
|
||||
// If the SchemaVersion is empty this this is the first time it has ran
|
||||
// so lets set it to the current version.
|
||||
@@ -502,15 +504,31 @@ func UpgradeDatabaseToVersion54(sqlStore SqlStore) {
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
}
|
||||
sqlStore.CreateColumnIfNotExists("Users", "AcceptedTermsOfServiceId", "varchar(64)", "varchar(64)", "")
|
||||
saveSchemaVersion(sqlStore, VERSION_5_4_0)
|
||||
}
|
||||
}
|
||||
|
||||
func UpgradeDatabaseToVersion55(sqlStore SqlStore) {
|
||||
// TODO: Uncomment following condition when version 5.5.0 is released
|
||||
// if shouldPerformUpgrade(sqlStore, VERSION_5_4_0, VERSION_5_5_0) {
|
||||
sqlStore.CreateColumnIfNotExists("PluginKeyValueStore", "ExpireAt", "bigint(20)", "bigint", "0")
|
||||
// saveSchemaVersion(sqlStore, VERSION_5_5_0)
|
||||
// }
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_4_0, VERSION_5_5_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_5_0)
|
||||
}
|
||||
}
|
||||
|
||||
func UpgradeDatabaseToVersion56(sqlStore SqlStore) {
|
||||
// TODO: Uncomment following condition when version 5.6.0 is released
|
||||
//if shouldPerformUpgrade(sqlStore, VERSION_5_5_0, VERSION_5_6_0) {
|
||||
sqlStore.CreateColumnIfNotExists("PluginKeyValueStore", "ExpireAt", "bigint(20)", "bigint", "0")
|
||||
|
||||
// migrating user's accepted terms of service data into the new table
|
||||
sqlStore.GetMaster().Exec("INSERT INTO UserTermsOfService SELECT Id, AcceptedTermsOfServiceId as TermsOfServiceId, :CreateAt FROM Users WHERE AcceptedTermsOfServiceId != \"\" AND AcceptedTermsOfServiceId IS NOT NULL", map[string]interface{}{"CreateAt": model.GetMillis()})
|
||||
|
||||
if sqlStore.DriverName() == model.DATABASE_DRIVER_POSTGRES {
|
||||
sqlStore.RemoveIndexIfExists("idx_users_email_lower", "lower(Email)")
|
||||
sqlStore.RemoveIndexIfExists("idx_users_username_lower", "lower(Username)")
|
||||
sqlStore.RemoveIndexIfExists("idx_users_nickname_lower", "lower(Nickname)")
|
||||
sqlStore.RemoveIndexIfExists("idx_users_firstname_lower", "lower(FirstName)")
|
||||
sqlStore.RemoveIndexIfExists("idx_users_lastname_lower", "lower(LastName)")
|
||||
}
|
||||
//saveSchemaVersion(sqlStore, VERSION_5_6_0)
|
||||
//}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,6 @@ 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
|
||||
@@ -95,11 +94,11 @@ func (us SqlUserStore) CreateIndexesIfNotExists() {
|
||||
us.CreateIndexIfNotExists("idx_users_delete_at", "Users", "DeleteAt")
|
||||
|
||||
if us.DriverName() == model.DATABASE_DRIVER_POSTGRES {
|
||||
us.CreateIndexIfNotExists("idx_users_email_lower", "Users", "lower(Email)")
|
||||
us.CreateIndexIfNotExists("idx_users_username_lower", "Users", "lower(Username)")
|
||||
us.CreateIndexIfNotExists("idx_users_nickname_lower", "Users", "lower(Nickname)")
|
||||
us.CreateIndexIfNotExists("idx_users_firstname_lower", "Users", "lower(FirstName)")
|
||||
us.CreateIndexIfNotExists("idx_users_lastname_lower", "Users", "lower(LastName)")
|
||||
us.CreateIndexIfNotExists("idx_users_email_lower_textpattern", "Users", "lower(Email) text_pattern_ops")
|
||||
us.CreateIndexIfNotExists("idx_users_username_lower_textpattern", "Users", "lower(Username) text_pattern_ops")
|
||||
us.CreateIndexIfNotExists("idx_users_nickname_lower_textpattern", "Users", "lower(Nickname) text_pattern_ops")
|
||||
us.CreateIndexIfNotExists("idx_users_firstname_lower_textpattern", "Users", "lower(FirstName) text_pattern_ops")
|
||||
us.CreateIndexIfNotExists("idx_users_lastname_lower_textpattern", "Users", "lower(LastName) text_pattern_ops")
|
||||
}
|
||||
|
||||
us.CreateFullTextIndexIfNotExists("idx_users_all_txt", "Users", strings.Join(USER_SEARCH_TYPE_ALL, ", "))
|
||||
@@ -1167,7 +1166,7 @@ func generateSearchQuery(searchQuery string, terms []string, fields []string, pa
|
||||
}
|
||||
}
|
||||
searchTerms = append(searchTerms, fmt.Sprintf("(%s)", strings.Join(searchFields, " OR ")))
|
||||
parameters[fmt.Sprintf("Term%d", i)] = fmt.Sprintf("%s%%", term)
|
||||
parameters[fmt.Sprintf("Term%d", i)] = fmt.Sprintf("%s%%", strings.TrimLeft(term, "@"))
|
||||
}
|
||||
|
||||
searchClause := strings.Join(searchTerms, " AND ")
|
||||
|
||||
89
store/sqlstore/user_terms_of_service.go
Обычный файл
89
store/sqlstore/user_terms_of_service.go
Обычный файл
@@ -0,0 +1,89 @@
|
||||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package sqlstore
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type SqlUserTermsOfServiceStore struct {
|
||||
SqlStore
|
||||
}
|
||||
|
||||
func NewSqlUserTermsOfServiceStore(sqlStore SqlStore) store.UserTermsOfServiceStore {
|
||||
s := SqlUserTermsOfServiceStore{sqlStore}
|
||||
|
||||
for _, db := range sqlStore.GetAllConns() {
|
||||
table := db.AddTableWithName(model.UserTermsOfService{}, "UserTermsOfService").SetKeys(false, "UserId")
|
||||
table.ColMap("UserId").SetMaxSize(26)
|
||||
table.ColMap("TermsOfServiceId").SetMaxSize(26)
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s SqlUserTermsOfServiceStore) CreateIndexesIfNotExists() {
|
||||
s.CreateIndexIfNotExists("idx_user_terms_of_service_user_id", "UserTermsOfService", "UserId")
|
||||
}
|
||||
|
||||
func (s SqlUserTermsOfServiceStore) GetByUser(userId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
var userTermsOfService *model.UserTermsOfService
|
||||
|
||||
err := s.GetReplica().SelectOne(&userTermsOfService, "SELECT * FROM UserTermsOfService WHERE UserId = :userId", map[string]interface{}{"userId": userId})
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
result.Err = model.NewAppError("NewSqlUserTermsOfServiceStore.GetByUser", "store.sql_user_terms_of_service.get_by_user.no_rows.app_error", nil, "", http.StatusNotFound)
|
||||
} else {
|
||||
result.Err = model.NewAppError("NewSqlUserTermsOfServiceStore.GetByUser", "store.sql_user_terms_of_service.get_by_user.app_error", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
} else {
|
||||
result.Data = userTermsOfService
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlUserTermsOfServiceStore) Save(userTermsOfService *model.UserTermsOfService) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
userTermsOfService.PreSave()
|
||||
|
||||
if result.Err = userTermsOfService.IsValid(); result.Err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if c, err := s.GetMaster().Update(userTermsOfService); err != nil {
|
||||
result.Err = model.NewAppError(
|
||||
"SqlUserTermsOfServiceStore.Save",
|
||||
"store.sql_user_terms_of_service.save.app_error",
|
||||
nil,
|
||||
"user_terms_of_service_user_id="+userTermsOfService.UserId+",user_terms_of_service_terms_of_service_id="+userTermsOfService.TermsOfServiceId+",err="+err.Error(),
|
||||
http.StatusInternalServerError,
|
||||
)
|
||||
} else if c == 0 {
|
||||
if err := s.GetMaster().Insert(userTermsOfService); err != nil {
|
||||
result.Err = model.NewAppError(
|
||||
"SqlUserTermsOfServiceStore.Save",
|
||||
"store.sql_user_terms_of_service.save.app_error",
|
||||
nil,
|
||||
"user_terms_of_service_user_id="+userTermsOfService.UserId+",user_terms_of_service_terms_of_service_id="+userTermsOfService.TermsOfServiceId+",err="+err.Error(),
|
||||
http.StatusInternalServerError,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
result.Data = userTermsOfService
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlUserTermsOfServiceStore) Delete(userId, termsOfServiceId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
if _, err := s.GetMaster().Exec("DELETE FROM UserTermsOfService WHERE UserId = :UserId AND TermsOfServiceId = :TermsOfServiceId", map[string]interface{}{"UserId": userId, "TermsOfServiceId": termsOfServiceId}); err != nil {
|
||||
result.Err = model.NewAppError("SqlUserTermsOfServiceStore.Delete", "store.sql_user_terms_of_service.delete.app_error", nil, "userId="+userId+", termsOfServiceId="+termsOfServiceId, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
})
|
||||
}
|
||||
10
store/sqlstore/user_terms_of_service_store_test.go
Обычный файл
10
store/sqlstore/user_terms_of_service_store_test.go
Обычный файл
@@ -0,0 +1,10 @@
|
||||
package sqlstore
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/store/storetest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUserTermsOfServiceStore(t *testing.T) {
|
||||
StoreTest(t, storetest.TestUserTermsOfServiceStore)
|
||||
}
|
||||
@@ -66,6 +66,7 @@ type Store interface {
|
||||
ChannelMemberHistory() ChannelMemberHistoryStore
|
||||
Plugin() PluginStore
|
||||
TermsOfService() TermsOfServiceStore
|
||||
UserTermsOfService() UserTermsOfServiceStore
|
||||
MarkSystemRanUnitTests()
|
||||
Close()
|
||||
LockToMaster()
|
||||
@@ -528,3 +529,9 @@ type TermsOfServiceStore interface {
|
||||
GetLatest(allowFromCache bool) StoreChannel
|
||||
Get(id string, allowFromCache bool) StoreChannel
|
||||
}
|
||||
|
||||
type UserTermsOfServiceStore interface {
|
||||
GetByUser(userId string) StoreChannel
|
||||
Save(userTermsOfService *model.UserTermsOfService) StoreChannel
|
||||
Delete(userId, termsOfServiceId string) StoreChannel
|
||||
}
|
||||
|
||||
@@ -909,6 +909,22 @@ func (_m *LayeredStoreDatabaseLayer) UserAccessToken() store.UserAccessTokenStor
|
||||
return r0
|
||||
}
|
||||
|
||||
// UserTermsOfService provides a mock function with given fields:
|
||||
func (_m *LayeredStoreDatabaseLayer) UserTermsOfService() store.UserTermsOfServiceStore {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 store.UserTermsOfServiceStore
|
||||
if rf, ok := ret.Get(0).(func() store.UserTermsOfServiceStore); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.UserTermsOfServiceStore)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Webhook provides a mock function with given fields:
|
||||
func (_m *LayeredStoreDatabaseLayer) Webhook() store.WebhookStore {
|
||||
ret := _m.Called()
|
||||
|
||||
@@ -778,6 +778,22 @@ func (_m *SqlStore) UserAccessToken() store.UserAccessTokenStore {
|
||||
return r0
|
||||
}
|
||||
|
||||
// UserTermsOfService provides a mock function with given fields:
|
||||
func (_m *SqlStore) UserTermsOfService() store.UserTermsOfServiceStore {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 store.UserTermsOfServiceStore
|
||||
if rf, ok := ret.Get(0).(func() store.UserTermsOfServiceStore); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.UserTermsOfServiceStore)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Webhook provides a mock function with given fields:
|
||||
func (_m *SqlStore) Webhook() store.WebhookStore {
|
||||
ret := _m.Called()
|
||||
|
||||
@@ -495,6 +495,22 @@ func (_m *Store) UserAccessToken() store.UserAccessTokenStore {
|
||||
return r0
|
||||
}
|
||||
|
||||
// UserTermsOfService provides a mock function with given fields:
|
||||
func (_m *Store) UserTermsOfService() store.UserTermsOfServiceStore {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 store.UserTermsOfServiceStore
|
||||
if rf, ok := ret.Get(0).(func() store.UserTermsOfServiceStore); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.UserTermsOfServiceStore)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Webhook provides a mock function with given fields:
|
||||
func (_m *Store) Webhook() store.WebhookStore {
|
||||
ret := _m.Called()
|
||||
|
||||
62
store/storetest/mocks/UserTermsOfServiceStore.go
Обычный файл
62
store/storetest/mocks/UserTermsOfServiceStore.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"
|
||||
|
||||
// UserTermsOfServiceStore is an autogenerated mock type for the UserTermsOfServiceStore type
|
||||
type UserTermsOfServiceStore struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
// Delete provides a mock function with given fields: userId, termsOfServiceId
|
||||
func (_m *UserTermsOfServiceStore) Delete(userId string, termsOfServiceId string) store.StoreChannel {
|
||||
ret := _m.Called(userId, termsOfServiceId)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string, string) store.StoreChannel); ok {
|
||||
r0 = rf(userId, termsOfServiceId)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// GetByUser provides a mock function with given fields: userId
|
||||
func (_m *UserTermsOfServiceStore) GetByUser(userId string) store.StoreChannel {
|
||||
ret := _m.Called(userId)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
||||
r0 = rf(userId)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Save provides a mock function with given fields: userTermsOfService
|
||||
func (_m *UserTermsOfServiceStore) Save(userTermsOfService *model.UserTermsOfService) store.StoreChannel {
|
||||
ret := _m.Called(userTermsOfService)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(*model.UserTermsOfService) store.StoreChannel); ok {
|
||||
r0 = rf(userTermsOfService)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
@@ -46,34 +46,36 @@ type Store struct {
|
||||
RoleStore mocks.RoleStore
|
||||
SchemeStore mocks.SchemeStore
|
||||
TermsOfServiceStore mocks.TermsOfServiceStore
|
||||
UserTermsOfServiceStore mocks.UserTermsOfServiceStore
|
||||
}
|
||||
|
||||
func (s *Store) Team() store.TeamStore { return &s.TeamStore }
|
||||
func (s *Store) Channel() store.ChannelStore { return &s.ChannelStore }
|
||||
func (s *Store) Post() store.PostStore { return &s.PostStore }
|
||||
func (s *Store) User() store.UserStore { return &s.UserStore }
|
||||
func (s *Store) Audit() store.AuditStore { return &s.AuditStore }
|
||||
func (s *Store) ClusterDiscovery() store.ClusterDiscoveryStore { return &s.ClusterDiscoveryStore }
|
||||
func (s *Store) Compliance() store.ComplianceStore { return &s.ComplianceStore }
|
||||
func (s *Store) Session() store.SessionStore { return &s.SessionStore }
|
||||
func (s *Store) OAuth() store.OAuthStore { return &s.OAuthStore }
|
||||
func (s *Store) System() store.SystemStore { return &s.SystemStore }
|
||||
func (s *Store) Webhook() store.WebhookStore { return &s.WebhookStore }
|
||||
func (s *Store) Command() store.CommandStore { return &s.CommandStore }
|
||||
func (s *Store) CommandWebhook() store.CommandWebhookStore { return &s.CommandWebhookStore }
|
||||
func (s *Store) Preference() store.PreferenceStore { return &s.PreferenceStore }
|
||||
func (s *Store) License() store.LicenseStore { return &s.LicenseStore }
|
||||
func (s *Store) Token() store.TokenStore { return &s.TokenStore }
|
||||
func (s *Store) Emoji() store.EmojiStore { return &s.EmojiStore }
|
||||
func (s *Store) Status() store.StatusStore { return &s.StatusStore }
|
||||
func (s *Store) FileInfo() store.FileInfoStore { return &s.FileInfoStore }
|
||||
func (s *Store) Reaction() store.ReactionStore { return &s.ReactionStore }
|
||||
func (s *Store) Job() store.JobStore { return &s.JobStore }
|
||||
func (s *Store) UserAccessToken() store.UserAccessTokenStore { return &s.UserAccessTokenStore }
|
||||
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) TermsOfService() store.TermsOfServiceStore { return &s.TermsOfServiceStore }
|
||||
func (s *Store) Team() store.TeamStore { return &s.TeamStore }
|
||||
func (s *Store) Channel() store.ChannelStore { return &s.ChannelStore }
|
||||
func (s *Store) Post() store.PostStore { return &s.PostStore }
|
||||
func (s *Store) User() store.UserStore { return &s.UserStore }
|
||||
func (s *Store) Audit() store.AuditStore { return &s.AuditStore }
|
||||
func (s *Store) ClusterDiscovery() store.ClusterDiscoveryStore { return &s.ClusterDiscoveryStore }
|
||||
func (s *Store) Compliance() store.ComplianceStore { return &s.ComplianceStore }
|
||||
func (s *Store) Session() store.SessionStore { return &s.SessionStore }
|
||||
func (s *Store) OAuth() store.OAuthStore { return &s.OAuthStore }
|
||||
func (s *Store) System() store.SystemStore { return &s.SystemStore }
|
||||
func (s *Store) Webhook() store.WebhookStore { return &s.WebhookStore }
|
||||
func (s *Store) Command() store.CommandStore { return &s.CommandStore }
|
||||
func (s *Store) CommandWebhook() store.CommandWebhookStore { return &s.CommandWebhookStore }
|
||||
func (s *Store) Preference() store.PreferenceStore { return &s.PreferenceStore }
|
||||
func (s *Store) License() store.LicenseStore { return &s.LicenseStore }
|
||||
func (s *Store) Token() store.TokenStore { return &s.TokenStore }
|
||||
func (s *Store) Emoji() store.EmojiStore { return &s.EmojiStore }
|
||||
func (s *Store) Status() store.StatusStore { return &s.StatusStore }
|
||||
func (s *Store) FileInfo() store.FileInfoStore { return &s.FileInfoStore }
|
||||
func (s *Store) Reaction() store.ReactionStore { return &s.ReactionStore }
|
||||
func (s *Store) Job() store.JobStore { return &s.JobStore }
|
||||
func (s *Store) UserAccessToken() store.UserAccessTokenStore { return &s.UserAccessTokenStore }
|
||||
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) TermsOfService() store.TermsOfServiceStore { return &s.TermsOfServiceStore }
|
||||
func (s *Store) UserTermsOfService() store.UserTermsOfServiceStore { return &s.UserTermsOfServiceStore }
|
||||
func (s *Store) ChannelMemberHistory() store.ChannelMemberHistoryStore {
|
||||
return &s.ChannelMemberHistoryStore
|
||||
}
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
package storetest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"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) {
|
||||
|
||||
@@ -1658,6 +1658,16 @@ func testUserStoreSearch(t *testing.T, ss store.Store) {
|
||||
},
|
||||
[]*model.User{u1},
|
||||
},
|
||||
{
|
||||
"leading @ should be ignored",
|
||||
tid,
|
||||
"@jimb",
|
||||
&model.UserSearchOptions{
|
||||
AllowFullNames: true,
|
||||
Limit: model.USER_SEARCH_DEFAULT_LIMIT,
|
||||
},
|
||||
[]*model.User{u1},
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
|
||||
81
store/storetest/user_terms_of_service.go
Обычный файл
81
store/storetest/user_terms_of_service.go
Обычный файл
@@ -0,0 +1,81 @@
|
||||
// Copyright (c) 2016-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 TestUserTermsOfServiceStore(t *testing.T, ss store.Store) {
|
||||
t.Run("TestSaveUserTermsOfService", func(t *testing.T) { testSaveUserTermsOfService(t, ss) })
|
||||
t.Run("TestGetByUserTermsOfService", func(t *testing.T) { testGetByUserTermsOfService(t, ss) })
|
||||
t.Run("TestDeleteUserTermsOfService", func(t *testing.T) { testDeleteUserTermsOfService(t, ss) })
|
||||
}
|
||||
|
||||
func testSaveUserTermsOfService(t *testing.T, ss store.Store) {
|
||||
userTermsOfService := &model.UserTermsOfService{
|
||||
UserId: model.NewId(),
|
||||
TermsOfServiceId: model.NewId(),
|
||||
}
|
||||
|
||||
r1 := <-ss.UserTermsOfService().Save(userTermsOfService)
|
||||
if r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
}
|
||||
|
||||
savedUserTermsOfService := r1.Data.(*model.UserTermsOfService)
|
||||
assert.Equal(t, userTermsOfService.UserId, savedUserTermsOfService.UserId)
|
||||
assert.Equal(t, userTermsOfService.TermsOfServiceId, savedUserTermsOfService.TermsOfServiceId)
|
||||
assert.NotEmpty(t, savedUserTermsOfService.CreateAt)
|
||||
}
|
||||
|
||||
func testGetByUserTermsOfService(t *testing.T, ss store.Store) {
|
||||
userTermsOfService := &model.UserTermsOfService{
|
||||
UserId: model.NewId(),
|
||||
TermsOfServiceId: model.NewId(),
|
||||
}
|
||||
|
||||
r1 := <-ss.UserTermsOfService().Save(userTermsOfService)
|
||||
if r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
}
|
||||
|
||||
r1 = <-ss.UserTermsOfService().GetByUser(userTermsOfService.UserId)
|
||||
if r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
}
|
||||
|
||||
fetchedUserTermsOfService := r1.Data.(*model.UserTermsOfService)
|
||||
assert.Equal(t, userTermsOfService.UserId, fetchedUserTermsOfService.UserId)
|
||||
assert.Equal(t, userTermsOfService.TermsOfServiceId, fetchedUserTermsOfService.TermsOfServiceId)
|
||||
assert.NotEmpty(t, fetchedUserTermsOfService.CreateAt)
|
||||
}
|
||||
|
||||
func testDeleteUserTermsOfService(t *testing.T, ss store.Store) {
|
||||
userTermsOfService := &model.UserTermsOfService{
|
||||
UserId: model.NewId(),
|
||||
TermsOfServiceId: model.NewId(),
|
||||
}
|
||||
|
||||
r1 := <-ss.UserTermsOfService().Save(userTermsOfService)
|
||||
if r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
}
|
||||
|
||||
r1 = <-ss.UserTermsOfService().GetByUser(userTermsOfService.UserId)
|
||||
if r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
}
|
||||
|
||||
r1 = <-ss.UserTermsOfService().Delete(userTermsOfService.UserId, userTermsOfService.TermsOfServiceId)
|
||||
if r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
}
|
||||
|
||||
r1 = <-ss.UserTermsOfService().GetByUser(userTermsOfService.UserId)
|
||||
assert.Equal(t, "store.sql_user_terms_of_service.get_by_user.no_rows.app_error", r1.Err.Id)
|
||||
}
|
||||
Ссылка в новой задаче
Block a user