* #132 added UserTermsOfService model * #132 added UserTermsOfService model * #132 added logic to save user TOS data in a new table * #132 Added logic to save and delete user TOS. Updated user TOS action logic * #132 updated store mocks * #132 added tests * #132 removed cache from UserTermsOfService SQL store * #132 fixed styling and license check * #132 added message translations in en.json * #132 fixed save user TOS logic to work second time as well * #132 removed User.AcceptedTermsOfService colum and migrated accepted TOS data into new table * #132 fixed formatting * #132 fixed formatting * #146 added field 'mandatory' to terms of service * #146 updated tests * #146 added getLatestTermsOfService API * #146 Added tests * #146 fixed styling * #146 removed code for managing mandatory/optional TOS * #146 Added TOS re-acceptance period config * #146 fixed styling * #146 removed some code left for debugging * #146 added TOS re-acceptance period in config * #146 fixed a json name from service_terms to terms_of_service * #146 Minor refactoring and added TOS re-acceptance period to diagnistics * Fixed style * Updated upgraded script to keep app backward compatible
Этот коммит содержится в:
коммит произвёл
Jesse Hallam
родитель
c52e808e34
Коммит
0c5f60f89b
@@ -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
|
||||
}
|
||||
|
||||
@@ -20,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}
|
||||
|
||||
@@ -504,7 +504,6 @@ 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)
|
||||
}
|
||||
}
|
||||
@@ -516,9 +515,12 @@ func UpgradeDatabaseToVersion55(sqlStore SqlStore) {
|
||||
}
|
||||
|
||||
func UpgradeDatabaseToVersion56(sqlStore SqlStore) {
|
||||
// TODO: Uncomment following condition when version 5.5.0 is released
|
||||
// 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")
|
||||
// saveSchemaVersion(sqlStore, VERSION_5_5_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()})
|
||||
//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
|
||||
|
||||
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)
|
||||
}
|
||||
Ссылка в новой задаче
Block a user