* #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
@@ -408,13 +408,14 @@ func (a *App) trackConfig() {
|
||||
})
|
||||
|
||||
a.SendDiagnostic(TRACK_CONFIG_SUPPORT, map[string]interface{}{
|
||||
"isdefault_terms_of_service_link": isDefault(*cfg.SupportSettings.TermsOfServiceLink, model.SUPPORT_SETTINGS_DEFAULT_TERMS_OF_SERVICE_LINK),
|
||||
"isdefault_privacy_policy_link": isDefault(*cfg.SupportSettings.PrivacyPolicyLink, model.SUPPORT_SETTINGS_DEFAULT_PRIVACY_POLICY_LINK),
|
||||
"isdefault_about_link": isDefault(*cfg.SupportSettings.AboutLink, model.SUPPORT_SETTINGS_DEFAULT_ABOUT_LINK),
|
||||
"isdefault_help_link": isDefault(*cfg.SupportSettings.HelpLink, model.SUPPORT_SETTINGS_DEFAULT_HELP_LINK),
|
||||
"isdefault_report_a_problem_link": isDefault(*cfg.SupportSettings.ReportAProblemLink, model.SUPPORT_SETTINGS_DEFAULT_REPORT_A_PROBLEM_LINK),
|
||||
"isdefault_support_email": isDefault(*cfg.SupportSettings.SupportEmail, model.SUPPORT_SETTINGS_DEFAULT_SUPPORT_EMAIL),
|
||||
"custom_terms_of_service_enabled": *cfg.SupportSettings.CustomTermsOfServiceEnabled,
|
||||
"isdefault_terms_of_service_link": isDefault(*cfg.SupportSettings.TermsOfServiceLink, model.SUPPORT_SETTINGS_DEFAULT_TERMS_OF_SERVICE_LINK),
|
||||
"isdefault_privacy_policy_link": isDefault(*cfg.SupportSettings.PrivacyPolicyLink, model.SUPPORT_SETTINGS_DEFAULT_PRIVACY_POLICY_LINK),
|
||||
"isdefault_about_link": isDefault(*cfg.SupportSettings.AboutLink, model.SUPPORT_SETTINGS_DEFAULT_ABOUT_LINK),
|
||||
"isdefault_help_link": isDefault(*cfg.SupportSettings.HelpLink, model.SUPPORT_SETTINGS_DEFAULT_HELP_LINK),
|
||||
"isdefault_report_a_problem_link": isDefault(*cfg.SupportSettings.ReportAProblemLink, model.SUPPORT_SETTINGS_DEFAULT_REPORT_A_PROBLEM_LINK),
|
||||
"isdefault_support_email": isDefault(*cfg.SupportSettings.SupportEmail, model.SUPPORT_SETTINGS_DEFAULT_SUPPORT_EMAIL),
|
||||
"custom_terms_of_service_enabled": *cfg.SupportSettings.CustomTermsOfServiceEnabled,
|
||||
"custom_terms_of_service_re_acceptance_period": *cfg.SupportSettings.CustomTermsOfServiceReAcceptancePeriod,
|
||||
})
|
||||
|
||||
a.SendDiagnostic(TRACK_CONFIG_LDAP, map[string]interface{}{
|
||||
|
||||
19
app/user.go
19
app/user.go
@@ -1622,22 +1622,3 @@ func (a *App) UpdateOAuthUserAttrs(userData io.Reader, user *model.User, provide
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) RecordUserTermsOfServiceAction(userId, termsOfServiceId string, accepted bool) *model.AppError {
|
||||
user, err := a.GetUser(userId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if accepted {
|
||||
user.AcceptedTermsOfServiceId = termsOfServiceId
|
||||
} else {
|
||||
user.AcceptedTermsOfServiceId = ""
|
||||
}
|
||||
_, err = a.UpdateUser(user, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
33
app/user_terms_of_service.go
Обычный файл
33
app/user_terms_of_service.go
Обычный файл
@@ -0,0 +1,33 @@
|
||||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package app
|
||||
|
||||
import "github.com/mattermost/mattermost-server/model"
|
||||
|
||||
func (a *App) GetUserTermsOfService(userId string) (*model.UserTermsOfService, *model.AppError) {
|
||||
if result := <-a.Srv.Store.UserTermsOfService().GetByUser(userId); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.(*model.UserTermsOfService), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) SaveUserTermsOfService(userId, termsOfServiceId string, accepted bool) *model.AppError {
|
||||
if accepted {
|
||||
userTermsOfService := &model.UserTermsOfService{
|
||||
UserId: userId,
|
||||
TermsOfServiceId: termsOfServiceId,
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.UserTermsOfService().Save(userTermsOfService); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
} else {
|
||||
if result := <-a.Srv.Store.UserTermsOfService().Delete(userId, termsOfServiceId); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
34
app/user_terms_of_service_test.go
Обычный файл
34
app/user_terms_of_service_test.go
Обычный файл
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUserTermsOfService(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
userTermsOfService, err := th.App.GetUserTermsOfService(th.BasicUser.Id)
|
||||
checkError(t, err)
|
||||
assert.Nil(t, userTermsOfService)
|
||||
assert.Equal(t, "store.sql_user_terms_of_service.get_by_user.no_rows.app_error", err.Id)
|
||||
|
||||
termsOfService, err := th.App.CreateTermsOfService("terms of service", th.BasicUser.Id)
|
||||
checkNoError(t, err)
|
||||
|
||||
err = th.App.SaveUserTermsOfService(th.BasicUser.Id, termsOfService.Id, true)
|
||||
checkNoError(t, err)
|
||||
|
||||
userTermsOfService, err = th.App.GetUserTermsOfService(th.BasicUser.Id)
|
||||
checkNoError(t, err)
|
||||
assert.NotNil(t, userTermsOfService)
|
||||
assert.NotEmpty(t, userTermsOfService)
|
||||
|
||||
assert.Equal(t, th.BasicUser.Id, userTermsOfService.UserId)
|
||||
assert.Equal(t, termsOfService.Id, userTermsOfService.TermsOfServiceId)
|
||||
assert.NotEmpty(t, userTermsOfService.CreateAt)
|
||||
}
|
||||
@@ -544,43 +544,3 @@ func TestPermanentDeleteUser(t *testing.T) {
|
||||
t.Fatal("GetFileInfo after DeleteUser is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecordUserTermsOfServiceAction(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
user := &model.User{
|
||||
Email: strings.ToLower(model.NewId()) + "success+test@example.com",
|
||||
Nickname: "Luke Skywalker", // trying to bring balance to the "Force", one test user at a time
|
||||
Username: "luke" + model.NewId(),
|
||||
Password: "passwd1",
|
||||
AuthService: "",
|
||||
}
|
||||
user, err := th.App.CreateUser(user)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create user: %v", err)
|
||||
}
|
||||
|
||||
defer th.App.PermanentDeleteUser(user)
|
||||
|
||||
termsOfService, err := th.App.CreateTermsOfService("text", user.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create terms of service: %v", err)
|
||||
}
|
||||
|
||||
err = th.App.RecordUserTermsOfServiceAction(user.Id, termsOfService.Id, true)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to record user action: %v", err)
|
||||
}
|
||||
|
||||
nuser, err := th.App.GetUser(user.Id)
|
||||
assert.Equal(t, termsOfService.Id, nuser.AcceptedTermsOfServiceId)
|
||||
|
||||
err = th.App.RecordUserTermsOfServiceAction(user.Id, termsOfService.Id, false)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to record user action: %v", err)
|
||||
}
|
||||
|
||||
nuser, err = th.App.GetUser(user.Id)
|
||||
assert.Empty(t, nuser.AcceptedTermsOfServiceId)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user