* #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
61
model/user_terms_of_service.go
Обычный файл
61
model/user_terms_of_service.go
Обычный файл
@@ -0,0 +1,61 @@
|
||||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type UserTermsOfService struct {
|
||||
UserId string `json:"user_id"`
|
||||
TermsOfServiceId string `json:"terms_of_service_id"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
}
|
||||
|
||||
func (ut *UserTermsOfService) IsValid() *AppError {
|
||||
if len(ut.UserId) != 26 {
|
||||
return InvalidUserTermsOfServiceError("user_id", ut.UserId)
|
||||
}
|
||||
|
||||
if len(ut.TermsOfServiceId) != 26 {
|
||||
return InvalidUserTermsOfServiceError("terms_of_service_id", ut.UserId)
|
||||
}
|
||||
|
||||
if ut.CreateAt == 0 {
|
||||
return InvalidUserTermsOfServiceError("create_at", ut.UserId)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ut *UserTermsOfService) ToJson() string {
|
||||
b, _ := json.Marshal(ut)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (ut *UserTermsOfService) PreSave() {
|
||||
if ut.UserId == "" {
|
||||
ut.UserId = NewId()
|
||||
}
|
||||
|
||||
ut.CreateAt = GetMillis()
|
||||
}
|
||||
|
||||
func UserTermsOfServiceFromJson(data io.Reader) *UserTermsOfService {
|
||||
var userTermsOfService *UserTermsOfService
|
||||
json.NewDecoder(data).Decode(&userTermsOfService)
|
||||
return userTermsOfService
|
||||
}
|
||||
|
||||
func InvalidUserTermsOfServiceError(fieldName string, userTermsOfServiceId string) *AppError {
|
||||
id := fmt.Sprintf("model.user_terms_of_service.is_valid.%s.app_error", fieldName)
|
||||
details := ""
|
||||
if userTermsOfServiceId != "" {
|
||||
details = "user_terms_of_service_user_id=" + userTermsOfServiceId
|
||||
}
|
||||
return NewAppError("UserTermsOfService.IsValid", id, nil, details, http.StatusBadRequest)
|
||||
}
|
||||
Ссылка в новой задаче
Block a user