summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
authorHarshil Sharma <harshil.sharma@joshtechnologygroup.com>2018-10-10 00:55:47 +0000
committerJesse Hallam <jesse.hallam@gmail.com>2018-10-09 20:55:47 -0400
commitbffcccf99de8a8f3c68cff9e39d2847f0996b67b (patch)
tree10bf45d87927dc792a233d0653d6ba273c9a7b28 /model
parent59319b7915b8eb4c20a0d4878382cc0e41fc536d (diff)
downloadchat-bffcccf99de8a8f3c68cff9e39d2847f0996b67b.tar.gz
chat-bffcccf99de8a8f3c68cff9e39d2847f0996b67b.tar.bz2
chat-bffcccf99de8a8f3c68cff9e39d2847f0996b67b.zip
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
Diffstat (limited to 'model')
-rw-r--r--model/client4.go22
-rw-r--r--model/config.go18
-rw-r--r--model/service_terms.go70
-rw-r--r--model/terms_of_service.go70
-rw-r--r--model/terms_of_service_test.go (renamed from model/service_terms_test.go)10
-rw-r--r--model/user.go54
6 files changed, 122 insertions, 122 deletions
diff --git a/model/client4.go b/model/client4.go
index 964218a68..903687ece 100644
--- a/model/client4.go
+++ b/model/client4.go
@@ -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)
}
}
diff --git a/model/config.go b/model/config.go
index 5e6a676ae..d59b8d6db 100644
--- a/model/config.go
+++ b/model/config.go
@@ -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)
}
}
diff --git a/model/service_terms.go b/model/service_terms.go
deleted file mode 100644
index 84ee0d395..000000000
--- a/model/service_terms.go
+++ /dev/null
@@ -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()
-}
diff --git a/model/terms_of_service.go b/model/terms_of_service.go
new file mode 100644
index 000000000..c99a78568
--- /dev/null
+++ b/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()
+}
diff --git a/model/service_terms_test.go b/model/terms_of_service_test.go
index 89b8ff9b5..134172a61 100644
--- a/model/service_terms_test.go
+++ b/model/terms_of_service_test.go
@@ -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)
diff --git a/model/user.go b/model/user.go
index d94a28b2d..781bcae66 100644
--- a/model/user.go
+++ b/model/user.go
@@ -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 {