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
Этот коммит содержится в:
коммит произвёл
Jesse Hallam
родитель
59319b7915
Коммит
bffcccf99d
@@ -401,11 +401,11 @@ func (c *Client4) GetRedirectLocationRoute() string {
|
||||
return fmt.Sprintf("/redirect_location")
|
||||
}
|
||||
|
||||
func (c *Client4) GetRegisterServiceTermsRoute(userId string) string {
|
||||
func (c *Client4) GetRegisterTermsOfServiceRoute(userId string) string {
|
||||
return c.GetUserRoute(userId) + "/terms_of_service"
|
||||
}
|
||||
|
||||
func (c *Client4) GetServiceTermsRoute() string {
|
||||
func (c *Client4) GetTermsOfServiceRoute() string {
|
||||
return "/terms_of_service"
|
||||
}
|
||||
|
||||
@@ -3828,9 +3828,9 @@ func (c *Client4) GetRedirectLocation(urlParam, etag string) (string, *Response)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client4) RegisterServiceTermsAction(userId, serviceTermsId string, accepted bool) (*bool, *Response) {
|
||||
url := c.GetRegisterServiceTermsRoute(userId)
|
||||
data := map[string]interface{}{"serviceTermsId": serviceTermsId, "accepted": accepted}
|
||||
func (c *Client4) RegisteTermsOfServiceAction(userId, termsOfServiceId string, accepted bool) (*bool, *Response) {
|
||||
url := c.GetRegisterTermsOfServiceRoute(userId)
|
||||
data := map[string]interface{}{"termsOfServiceId": termsOfServiceId, "accepted": accepted}
|
||||
|
||||
if r, err := c.DoApiPost(url, StringInterfaceToJson(data)); err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
@@ -3840,25 +3840,25 @@ func (c *Client4) RegisterServiceTermsAction(userId, serviceTermsId string, acce
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client4) GetServiceTerms(etag string) (*ServiceTerms, *Response) {
|
||||
url := c.GetServiceTermsRoute()
|
||||
func (c *Client4) GetTermsOfService(etag string) (*TermsOfService, *Response) {
|
||||
url := c.GetTermsOfServiceRoute()
|
||||
|
||||
if r, err := c.DoApiGet(url, etag); err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
} else {
|
||||
defer closeBody(r)
|
||||
return ServiceTermsFromJson(r.Body), BuildResponse(r)
|
||||
return TermsOfServiceFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client4) CreateServiceTerms(text, userId string) (*ServiceTerms, *Response) {
|
||||
url := c.GetServiceTermsRoute()
|
||||
func (c *Client4) CreateTermsOfService(text, userId string) (*TermsOfService, *Response) {
|
||||
url := c.GetTermsOfServiceRoute()
|
||||
|
||||
data := map[string]string{"text": text}
|
||||
if r, err := c.DoApiPost(url, MapToJson(data)); err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
} else {
|
||||
defer closeBody(r)
|
||||
return ServiceTermsFromJson(r.Body), BuildResponse(r)
|
||||
return TermsOfServiceFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -996,13 +996,13 @@ type PrivacySettings struct {
|
||||
}
|
||||
|
||||
type SupportSettings struct {
|
||||
TermsOfServiceLink *string
|
||||
PrivacyPolicyLink *string
|
||||
AboutLink *string
|
||||
HelpLink *string
|
||||
ReportAProblemLink *string
|
||||
SupportEmail *string
|
||||
CustomServiceTermsEnabled *bool
|
||||
TermsOfServiceLink *string
|
||||
PrivacyPolicyLink *string
|
||||
AboutLink *string
|
||||
HelpLink *string
|
||||
ReportAProblemLink *string
|
||||
SupportEmail *string
|
||||
CustomTermsOfServiceEnabled *bool
|
||||
}
|
||||
|
||||
func (s *SupportSettings) SetDefaults() {
|
||||
@@ -1050,8 +1050,8 @@ func (s *SupportSettings) SetDefaults() {
|
||||
s.SupportEmail = NewString(SUPPORT_SETTINGS_DEFAULT_SUPPORT_EMAIL)
|
||||
}
|
||||
|
||||
if s.CustomServiceTermsEnabled == nil {
|
||||
s.CustomServiceTermsEnabled = NewBool(false)
|
||||
if s.CustomTermsOfServiceEnabled == nil {
|
||||
s.CustomTermsOfServiceEnabled = NewBool(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// we only ever need the latest version of service terms
|
||||
const SERVICE_TERMS_CACHE_SIZE = 1
|
||||
|
||||
type ServiceTerms struct {
|
||||
Id string `json:"id"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
UserId string `json:"user_id"`
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
func (t *ServiceTerms) IsValid() *AppError {
|
||||
if len(t.Id) != 26 {
|
||||
return InvalidServiceTermsError("id", "")
|
||||
}
|
||||
|
||||
if t.CreateAt == 0 {
|
||||
return InvalidServiceTermsError("create_at", t.Id)
|
||||
}
|
||||
|
||||
if len(t.UserId) != 26 {
|
||||
return InvalidServiceTermsError("user_id", t.Id)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(t.Text) > POST_MESSAGE_MAX_RUNES_V2 {
|
||||
return InvalidServiceTermsError("text", t.Id)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *ServiceTerms) ToJson() string {
|
||||
b, _ := json.Marshal(t)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ServiceTermsFromJson(data io.Reader) *ServiceTerms {
|
||||
var serviceTerms *ServiceTerms
|
||||
json.NewDecoder(data).Decode(&serviceTerms)
|
||||
return serviceTerms
|
||||
}
|
||||
|
||||
func InvalidServiceTermsError(fieldName string, serviceTermsId string) *AppError {
|
||||
id := fmt.Sprintf("model.service_terms.is_valid.%s.app_error", fieldName)
|
||||
details := ""
|
||||
if serviceTermsId != "" {
|
||||
details = "service_terms_id=" + serviceTermsId
|
||||
}
|
||||
return NewAppError("ServiceTerms.IsValid", id, map[string]interface{}{"MaxLength": POST_MESSAGE_MAX_RUNES_V2}, details, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
func (t *ServiceTerms) PreSave() {
|
||||
if t.Id == "" {
|
||||
t.Id = NewId()
|
||||
}
|
||||
|
||||
t.CreateAt = GetMillis()
|
||||
}
|
||||
70
model/terms_of_service.go
Обычный файл
70
model/terms_of_service.go
Обычный файл
@@ -0,0 +1,70 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// we only ever need the latest version of terms of service
|
||||
const TERMS_OF_SERVICE_CACHE_SIZE = 1
|
||||
|
||||
type TermsOfService struct {
|
||||
Id string `json:"id"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
UserId string `json:"user_id"`
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
func (t *TermsOfService) IsValid() *AppError {
|
||||
if len(t.Id) != 26 {
|
||||
return InvalidTermsOfServiceError("id", "")
|
||||
}
|
||||
|
||||
if t.CreateAt == 0 {
|
||||
return InvalidTermsOfServiceError("create_at", t.Id)
|
||||
}
|
||||
|
||||
if len(t.UserId) != 26 {
|
||||
return InvalidTermsOfServiceError("user_id", t.Id)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(t.Text) > POST_MESSAGE_MAX_RUNES_V2 {
|
||||
return InvalidTermsOfServiceError("text", t.Id)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *TermsOfService) ToJson() string {
|
||||
b, _ := json.Marshal(t)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func TermsOfServiceFromJson(data io.Reader) *TermsOfService {
|
||||
var termsOfService *TermsOfService
|
||||
json.NewDecoder(data).Decode(&termsOfService)
|
||||
return termsOfService
|
||||
}
|
||||
|
||||
func InvalidTermsOfServiceError(fieldName string, termsOfServiceId string) *AppError {
|
||||
id := fmt.Sprintf("model.terms_of_service.is_valid.%s.app_error", fieldName)
|
||||
details := ""
|
||||
if termsOfServiceId != "" {
|
||||
details = "terms_of_service_id=" + termsOfServiceId
|
||||
}
|
||||
return NewAppError("TermsOfServiceStore.IsValid", id, map[string]interface{}{"MaxLength": POST_MESSAGE_MAX_RUNES_V2}, details, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
func (t *TermsOfService) PreSave() {
|
||||
if t.Id == "" {
|
||||
t.Id = NewId()
|
||||
}
|
||||
|
||||
t.CreateAt = GetMillis()
|
||||
}
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestServiceTermsIsValid(t *testing.T) {
|
||||
s := ServiceTerms{}
|
||||
func TestTermsOfServiceIsValid(t *testing.T) {
|
||||
s := TermsOfService{}
|
||||
|
||||
if err := s.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
@@ -47,15 +47,15 @@ func TestServiceTermsIsValid(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceTermsJson(t *testing.T) {
|
||||
o := ServiceTerms{
|
||||
func TestTermsOfServiceJson(t *testing.T) {
|
||||
o := TermsOfService{
|
||||
Id: NewId(),
|
||||
Text: NewId(),
|
||||
CreateAt: GetMillis(),
|
||||
UserId: NewId(),
|
||||
}
|
||||
j := o.ToJson()
|
||||
ro := ServiceTermsFromJson(strings.NewReader(j))
|
||||
ro := TermsOfServiceFromJson(strings.NewReader(j))
|
||||
|
||||
assert.NotNil(t, ro)
|
||||
assert.Equal(t, o, *ro)
|
||||
@@ -48,33 +48,33 @@ const (
|
||||
)
|
||||
|
||||
type User struct {
|
||||
Id string `json:"id"`
|
||||
CreateAt int64 `json:"create_at,omitempty"`
|
||||
UpdateAt int64 `json:"update_at,omitempty"`
|
||||
DeleteAt int64 `json:"delete_at"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password,omitempty"`
|
||||
AuthData *string `json:"auth_data,omitempty"`
|
||||
AuthService string `json:"auth_service"`
|
||||
Email string `json:"email"`
|
||||
EmailVerified bool `json:"email_verified,omitempty"`
|
||||
Nickname string `json:"nickname"`
|
||||
FirstName string `json:"first_name"`
|
||||
LastName string `json:"last_name"`
|
||||
Position string `json:"position"`
|
||||
Roles string `json:"roles"`
|
||||
AllowMarketing bool `json:"allow_marketing,omitempty"`
|
||||
Props StringMap `json:"props,omitempty"`
|
||||
NotifyProps StringMap `json:"notify_props,omitempty"`
|
||||
LastPasswordUpdate int64 `json:"last_password_update,omitempty"`
|
||||
LastPictureUpdate int64 `json:"last_picture_update,omitempty"`
|
||||
FailedAttempts int `json:"failed_attempts,omitempty"`
|
||||
Locale string `json:"locale"`
|
||||
Timezone StringMap `json:"timezone"`
|
||||
MfaActive bool `json:"mfa_active,omitempty"`
|
||||
MfaSecret string `json:"mfa_secret,omitempty"`
|
||||
LastActivityAt int64 `db:"-" json:"last_activity_at,omitempty"`
|
||||
AcceptedServiceTermsId string `json:"accepted_service_terms_id,omitempty"`
|
||||
Id string `json:"id"`
|
||||
CreateAt int64 `json:"create_at,omitempty"`
|
||||
UpdateAt int64 `json:"update_at,omitempty"`
|
||||
DeleteAt int64 `json:"delete_at"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password,omitempty"`
|
||||
AuthData *string `json:"auth_data,omitempty"`
|
||||
AuthService string `json:"auth_service"`
|
||||
Email string `json:"email"`
|
||||
EmailVerified bool `json:"email_verified,omitempty"`
|
||||
Nickname string `json:"nickname"`
|
||||
FirstName string `json:"first_name"`
|
||||
LastName string `json:"last_name"`
|
||||
Position string `json:"position"`
|
||||
Roles string `json:"roles"`
|
||||
AllowMarketing bool `json:"allow_marketing,omitempty"`
|
||||
Props StringMap `json:"props,omitempty"`
|
||||
NotifyProps StringMap `json:"notify_props,omitempty"`
|
||||
LastPasswordUpdate int64 `json:"last_password_update,omitempty"`
|
||||
LastPictureUpdate int64 `json:"last_picture_update,omitempty"`
|
||||
FailedAttempts int `json:"failed_attempts,omitempty"`
|
||||
Locale string `json:"locale"`
|
||||
Timezone StringMap `json:"timezone"`
|
||||
MfaActive bool `json:"mfa_active,omitempty"`
|
||||
MfaSecret string `json:"mfa_secret,omitempty"`
|
||||
LastActivityAt int64 `db:"-" json:"last_activity_at,omitempty"`
|
||||
AcceptedTermsOfServiceId string `json:"accepted_terms_of_service_id,omitempty"` // TODO remove this field when new TOS user action table is created
|
||||
}
|
||||
|
||||
type UserPatch struct {
|
||||
|
||||
Ссылка в новой задаче
Block a user