Unverified Commit 7c2e6198 authored by Harshil Sharma's avatar Harshil Sharma Committed by Jesse Hallam

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
parent 19771ae6
......@@ -108,7 +108,7 @@ type Routes struct {
Webrtc *mux.Router // 'api/v4/webrtc'
ServiceTerms *mux.Router // 'api/v4/service_terms
TermsOfService *mux.Router // 'api/v4/terms_of_service
}
type API struct {
......@@ -205,7 +205,7 @@ func Init(a *app.App, root *mux.Router) *API {
api.BaseRoutes.Image = api.BaseRoutes.ApiRoot.PathPrefix("/image").Subrouter()
api.BaseRoutes.ServiceTerms = api.BaseRoutes.ApiRoot.PathPrefix("/terms_of_service").Subrouter()
api.BaseRoutes.TermsOfService = api.BaseRoutes.ApiRoot.PathPrefix("/terms_of_service").Subrouter()
api.InitUser()
api.InitTeam()
......@@ -235,7 +235,7 @@ func Init(a *app.App, root *mux.Router) *API {
api.InitRole()
api.InitScheme()
api.InitImage()
api.InitServiceTerms()
api.InitTermsOfService()
root.Handle("/api/v4/{anything:.*}", http.HandlerFunc(api.Handle404))
......
......@@ -9,29 +9,29 @@ import (
"net/http"
)
func (api *API) InitServiceTerms() {
api.BaseRoutes.ServiceTerms.Handle("", api.ApiSessionRequired(getServiceTerms)).Methods("GET")
api.BaseRoutes.ServiceTerms.Handle("", api.ApiSessionRequired(createServiceTerms)).Methods("POST")
func (api *API) InitTermsOfService() {
api.BaseRoutes.TermsOfService.Handle("", api.ApiSessionRequired(getTermsOfService)).Methods("GET")
api.BaseRoutes.TermsOfService.Handle("", api.ApiSessionRequired(createTermsOfService)).Methods("POST")
}
func getServiceTerms(c *Context, w http.ResponseWriter, r *http.Request) {
serviceTerms, err := c.App.GetLatestServiceTerms()
func getTermsOfService(c *Context, w http.ResponseWriter, r *http.Request) {
termsOfService, err := c.App.GetLatestTermsOfService()
if err != nil {
c.Err = err
return
}
w.Write([]byte(serviceTerms.ToJson()))
w.Write([]byte(termsOfService.ToJson()))
}
func createServiceTerms(c *Context, w http.ResponseWriter, r *http.Request) {
func createTermsOfService(c *Context, w http.ResponseWriter, r *http.Request) {
if !c.App.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
return
}
if license := c.App.License(); license == nil || !*license.Features.CustomTermsOfService {
c.Err = model.NewAppError("createServiceTerms", "api.create_service_terms.custom_service_terms_disabled.app_error", nil, "", http.StatusBadRequest)
c.Err = model.NewAppError("createTermsOfService", "api.create_terms_of_service.custom_terms_of_service_disabled.app_error", nil, "", http.StatusBadRequest)
return
}
......@@ -40,25 +40,25 @@ func createServiceTerms(c *Context, w http.ResponseWriter, r *http.Request) {
userId := c.Session.UserId
if text == "" {
c.Err = model.NewAppError("Config.IsValid", "api.create_service_terms.empty_text.app_error", nil, "", http.StatusBadRequest)
c.Err = model.NewAppError("Config.IsValid", "api.create_terms_of_service.empty_text.app_error", nil, "", http.StatusBadRequest)
return
}
oldServiceTerms, err := c.App.GetLatestServiceTerms()
if err != nil && err.Id != app.ERROR_SERVICE_TERMS_NO_ROWS_FOUND {
oldTermsOfService, err := c.App.GetLatestTermsOfService()
if err != nil && err.Id != app.ERROR_TERMS_OF_SERVICE_NO_ROWS_FOUND {
c.Err = err
return
}
if oldServiceTerms == nil || oldServiceTerms.Text != text {
serviceTerms, err := c.App.CreateServiceTerms(text, userId)
if oldTermsOfService == nil || oldTermsOfService.Text != text {
termsOfService, err := c.App.CreateTermsOfService(text, userId)
if err != nil {
c.Err = err
return
}
w.Write([]byte(serviceTerms.ToJson()))
w.Write([]byte(termsOfService.ToJson()))
} else {
w.Write([]byte(oldServiceTerms.ToJson()))
w.Write([]byte(oldTermsOfService.ToJson()))
}
}
......@@ -6,48 +6,48 @@ import (
"testing"
)
func TestGetServiceTerms(t *testing.T) {
func TestGetTermsOfService(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
_, err := th.App.CreateServiceTerms("abc", th.BasicUser.Id)
_, err := th.App.CreateTermsOfService("abc", th.BasicUser.Id)
if err != nil {
t.Fatal(err)
}
serviceTerms, resp := Client.GetServiceTerms("")
termsOfService, resp := Client.GetTermsOfService("")
CheckNoError(t, resp)
assert.NotNil(t, serviceTerms)
assert.Equal(t, "abc", serviceTerms.Text)
assert.NotEmpty(t, serviceTerms.Id)
assert.NotEmpty(t, serviceTerms.CreateAt)
assert.NotNil(t, termsOfService)
assert.Equal(t, "abc", termsOfService.Text)
assert.NotEmpty(t, termsOfService.Id)
assert.NotEmpty(t, termsOfService.CreateAt)
}
func TestCreateServiceTerms(t *testing.T) {
func TestCreateTermsOfService(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
_, resp := Client.CreateServiceTerms("service terms new", th.BasicUser.Id)
_, resp := Client.CreateTermsOfService("terms of service new", th.BasicUser.Id)
CheckErrorMessage(t, resp, "api.context.permissions.app_error")
}
func TestCreateServiceTermsAdminUser(t *testing.T) {
func TestCreateTermsOfServiceAdminUser(t *testing.T) {
th := Setup().InitSystemAdmin()
defer th.TearDown()
Client := th.SystemAdminClient
serviceTerms, resp := Client.CreateServiceTerms("service terms new", th.SystemAdminUser.Id)
CheckErrorMessage(t, resp, "api.create_service_terms.custom_service_terms_disabled.app_error")
termsOfService, resp := Client.CreateTermsOfService("terms of service new", th.SystemAdminUser.Id)
CheckErrorMessage(t, resp, "api.create_terms_of_service.custom_terms_of_service_disabled.app_error")
th.App.SetLicense(model.NewTestLicense("EnableCustomServiceTerms"))
th.App.SetLicense(model.NewTestLicense("EnableCustomTermsOfService"))
serviceTerms, resp = Client.CreateServiceTerms("service terms new_2", th.SystemAdminUser.Id)
termsOfService, resp = Client.CreateTermsOfService("terms of service new_2", th.SystemAdminUser.Id)
CheckNoError(t, resp)
assert.NotEmpty(t, serviceTerms.Id)
assert.NotEmpty(t, serviceTerms.CreateAt)
assert.Equal(t, "service terms new_2", serviceTerms.Text)
assert.Equal(t, th.SystemAdminUser.Id, serviceTerms.UserId)
assert.NotEmpty(t, termsOfService.Id)
assert.NotEmpty(t, termsOfService.CreateAt)
assert.Equal(t, "terms of service new_2", termsOfService.Text)
assert.Equal(t, th.SystemAdminUser.Id, termsOfService.UserId)
}
......@@ -39,7 +39,7 @@ func (api *API) InitUser() {
api.BaseRoutes.Users.Handle("/password/reset/send", api.ApiHandler(sendPasswordReset)).Methods("POST")
api.BaseRoutes.Users.Handle("/email/verify", api.ApiHandler(verifyUserEmail)).Methods("POST")
api.BaseRoutes.Users.Handle("/email/verify/send", api.ApiHandler(sendVerificationEmail)).Methods("POST")
api.BaseRoutes.User.Handle("/terms_of_service", api.ApiSessionRequired(registerServiceTermsAction)).Methods("POST")
api.BaseRoutes.User.Handle("/terms_of_service", api.ApiSessionRequired(registerTermsOfServiceAction)).Methods("POST")
api.BaseRoutes.User.Handle("/auth", api.ApiSessionRequiredTrustRequester(updateUserAuth)).Methods("PUT")
......@@ -1553,23 +1553,23 @@ func enableUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
ReturnStatusOK(w)
}
func registerServiceTermsAction(c *Context, w http.ResponseWriter, r *http.Request) {
func registerTermsOfServiceAction(c *Context, w http.ResponseWriter, r *http.Request) {
props := model.StringInterfaceFromJson(r.Body)
userId := c.Session.UserId
serviceTermsId := props["serviceTermsId"].(string)
termsOfServiceId := props["termsOfServiceId"].(string)
accepted := props["accepted"].(bool)
if _, err := c.App.GetServiceTerms(serviceTermsId); err != nil {
if _, err := c.App.GetTermsOfService(termsOfServiceId); err != nil {
c.Err = err
return
}
if err := c.App.RecordUserServiceTermsAction(userId, serviceTermsId, accepted); err != nil {
if err := c.App.RecordUserTermsOfServiceAction(userId, termsOfServiceId, accepted); err != nil {
c.Err = err
return
}
c.LogAudit("ServiceTermsId=" + serviceTermsId + ", accepted=" + strconv.FormatBool(accepted))
c.LogAudit("TermsOfServiceId=" + termsOfServiceId + ", accepted=" + strconv.FormatBool(accepted))
ReturnStatusOK(w)
}
......@@ -3025,20 +3025,20 @@ func TestGetUsersByStatus(t *testing.T) {
})
}
func TestRegisterServiceTermsAction(t *testing.T) {
func TestRegisterTermsOfServiceAction(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
success, resp := Client.RegisterServiceTermsAction(th.BasicUser.Id, "st_1", true)
CheckErrorMessage(t, resp, "store.sql_service_terms_store.get.no_rows.app_error")
success, resp := Client.RegisteTermsOfServiceAction(th.BasicUser.Id, "st_1", true)
CheckErrorMessage(t, resp, "store.sql_terms_of_service_store.get.no_rows.app_error")
serviceTerms, err := th.App.CreateServiceTerms("service terms", th.BasicUser.Id)
termsOfService, err := th.App.CreateTermsOfService("terms of service", th.BasicUser.Id)
if err != nil {
t.Fatal(err)
}
success, resp = Client.RegisterServiceTermsAction(th.BasicUser.Id, serviceTerms.Id, true)
success, resp = Client.RegisteTermsOfServiceAction(th.BasicUser.Id, termsOfService.Id, true)
CheckNoError(t, resp)
assert.True(t, *success)
......@@ -3047,5 +3047,5 @@ func TestRegisterServiceTermsAction(t *testing.T) {
t.Fatal(err)
}
assert.Equal(t, user.AcceptedServiceTermsId, serviceTerms.Id)
assert.Equal(t, user.AcceptedTermsOfServiceId, termsOfService.Id)
}
......@@ -24,7 +24,7 @@ import (
)
const (
ERROR_SERVICE_TERMS_NO_ROWS_FOUND = "store.sql_service_terms_store.get.no_rows.app_error"
ERROR_TERMS_OF_SERVICE_NO_ROWS_FOUND = "store.sql_terms_of_service_store.get.no_rows.app_error"
)
func (a *App) Config() *model.Config {
......@@ -247,12 +247,12 @@ func (a *App) AsymmetricSigningKey() *ecdsa.PrivateKey {
func (a *App) regenerateClientConfig() {
a.clientConfig = utils.GenerateClientConfig(a.Config(), a.DiagnosticId(), a.License())
if a.clientConfig["EnableCustomServiceTerms"] == "true" {
serviceTerms, err := a.GetLatestServiceTerms()
if a.clientConfig["EnableCustomTermsOfService"] == "true" {
termsOfService, err := a.GetLatestTermsOfService()
if err != nil {
mlog.Err(err)
} else {
a.clientConfig["CustomServiceTermsId"] = serviceTerms.Id
a.clientConfig["CustomTermsOfServiceId"] = termsOfService.Id
}
}
......
......@@ -417,7 +417,7 @@ func (a *App) trackConfig() {
"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_service_terms_enabled": *cfg.SupportSettings.CustomServiceTermsEnabled,
"custom_terms_of_service_enabled": *cfg.SupportSettings.CustomTermsOfServiceEnabled,
})
a.SendDiagnostic(TRACK_CONFIG_LDAP, map[string]interface{}{
......
......@@ -7,8 +7,8 @@ import (
"github.com/mattermost/mattermost-server/model"
)
func (a *App) CreateServiceTerms(text, userId string) (*model.ServiceTerms, *model.AppError) {
serviceTerms := &model.ServiceTerms{
func (a *App) CreateTermsOfService(text, userId string) (*model.TermsOfService, *model.AppError) {
termsOfService := &model.TermsOfService{
Text: text,
UserId: userId,
}
......@@ -17,29 +17,29 @@ func (a *App) CreateServiceTerms(text, userId string) (*model.ServiceTerms, *mod
return nil, err
}
result := <-a.Srv.Store.ServiceTerms().Save(serviceTerms)
result := <-a.Srv.Store.TermsOfService().Save(termsOfService)
if result.Err != nil {
return nil, result.Err
}
serviceTerms = result.Data.(*model.ServiceTerms)
return serviceTerms, nil
termsOfService = result.Data.(*model.TermsOfService)
return termsOfService, nil
}
func (a *App) GetLatestServiceTerms() (*model.ServiceTerms, *model.AppError) {
if result := <-a.Srv.Store.ServiceTerms().GetLatest(true); result.Err != nil {
func (a *App) GetLatestTermsOfService() (*model.TermsOfService, *model.AppError) {
if result := <-a.Srv.Store.TermsOfService().GetLatest(true); result.Err != nil {
return nil, result.Err
} else {
serviceTerms := result.Data.(*model.ServiceTerms)
return serviceTerms, nil
termsOfService := result.Data.(*model.TermsOfService)
return termsOfService, nil
}
}
func (a *App) GetServiceTerms(id string) (*model.ServiceTerms, *model.AppError) {
if result := <-a.Srv.Store.ServiceTerms().Get(id, true); result.Err != nil {
func (a *App) GetTermsOfService(id string) (*model.TermsOfService, *model.AppError) {
if result := <-a.Srv.Store.TermsOfService().Get(id, true); result.Err != nil {
return nil, result.Err
} else {
serviceTerms := result.Data.(*model.ServiceTerms)
return serviceTerms, nil
termsOfService := result.Data.(*model.TermsOfService)
return termsOfService, nil
}
}
......@@ -1616,16 +1616,16 @@ func (a *App) UpdateOAuthUserAttrs(userData io.Reader, user *model.User, provide
return nil
}
func (a *App) RecordUserServiceTermsAction(userId, serviceTermsId string, accepted bool) *model.AppError {
func (a *App) RecordUserTermsOfServiceAction(userId, termsOfServiceId string, accepted bool) *model.AppError {
user, err := a.GetUser(userId)
if err != nil {
return err
}
if accepted {
user.AcceptedServiceTermsId = serviceTermsId
user.AcceptedTermsOfServiceId = termsOfServiceId
} else {
user.AcceptedServiceTermsId = ""
user.AcceptedTermsOfServiceId = ""
}
_, err = a.UpdateUser(user, false)
if err != nil {
......
......@@ -525,7 +525,7 @@ func TestPermanentDeleteUser(t *testing.T) {
}
}
func TestRecordUserServiceTermsAction(t *testing.T) {
func TestRecordUserTermsOfServiceAction(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
......@@ -543,24 +543,24 @@ func TestRecordUserServiceTermsAction(t *testing.T) {
defer th.App.PermanentDeleteUser(user)
serviceTerms, err := th.App.CreateServiceTerms("text", user.Id)
termsOfService, err := th.App.CreateTermsOfService("text", user.Id)
if err != nil {
t.Fatalf("failed to create service terms: %v", err)
t.Fatalf("failed to create terms of service: %v", err)
}
err = th.App.RecordUserServiceTermsAction(user.Id, serviceTerms.Id, true)
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, serviceTerms.Id, nuser.AcceptedServiceTermsId)
assert.Equal(t, termsOfService.Id, nuser.AcceptedTermsOfServiceId)
err = th.App.RecordUserServiceTermsAction(user.Id, serviceTerms.Id, false)
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.AcceptedServiceTermsId)
assert.Empty(t, nuser.AcceptedTermsOfServiceId)
}
......@@ -2371,7 +2371,7 @@
"translation": "Bad verify email token type."
},
{
"id": "api.user.register_service_terms_action.bad_value.app_error",
"id": "api.user.register_terms_of_service_action.bad_value.app_error",
"translation": "Bad accepted value"
},
{
......@@ -2435,11 +2435,11 @@
"translation": "Invalid {{.Name}} parameter"
},
{
"id": "api.create_service_terms.empty_text.app_error",
"id": "api.create_terms_of_service.empty_text.app_error",
"translation": "Please enter text for your Custom Terms of Service."
},
{
"id": "api.create_service_terms.custom_service_terms_disabled.app_error",
"id": "api.create_terms_of_service.custom_terms_of_service_disabled.app_error",
"translation": "Custom terms of service feature is disabled"
},
{
......@@ -4811,19 +4811,19 @@
"translation": "Unable to connect to the WebSocket server."
},
{
"id": "model.service_terms.is_valid.id.app_error",
"id": "model.terms_of_service.is_valid.id.app_error",
"translation": "Invalid term of service id."
},
{
"id": "model.service_terms.is_valid.create_at.app_error",
"id": "model.terms_of_service.is_valid.create_at.app_error",
"translation": "Missing required term of service property: create_at."
},
{
"id": "model.service_terms.is_valid.user_id.app_error",
"id": "model.terms_of_service.is_valid.user_id.app_error",
"translation": "Missing required terms of service property: user_id."
},
{
"id": "model.service_terms.is_valid.text.app_error",
"id": "model.terms_of_service.is_valid.text.app_error",
"translation": "Custom terms of service text is too long. Maximum {{.MaxLength}} characters allowed."
},
{
......@@ -6459,19 +6459,19 @@
"translation": "Unable to update the webhook"
},
{
"id": "store.sql_service_terms_store.save.existing.app_error",
"id": "store.sql_terms_of_service_store.save.existing.app_error",
"translation": "Must not call save for existing terms of service."
},
{
"id": "store.sql_service_terms.save.app_error",
"id": "store.sql_terms_of_service.save.app_error",
"translation": "Unable to save terms of service."
},
{
"id": "store.sql_service_terms_store.get.app_error",
"id": "store.sql_terms_of_service_store.get.app_error",
"translation": "Unable to fetch terms of service."
},
{
"id": "store.sql_service_terms_store.get.no_rows.app_error",
"id": "store.sql_terms_of_service_store.get.no_rows.app_error",
"translation": "No terms of service found."
},
{
......
......@@ -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"
}
......@@ -3803,9 +3803,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)
......@@ -3815,25 +3815,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)
}
}
......
......@@ -11,57 +11,57 @@ import (
"unicode/utf8"
)
// we only ever need the latest version of service terms
const SERVICE_TERMS_CACHE_SIZE = 1
// we only ever need the latest version of terms of service
const TERMS_OF_SERVICE_CACHE_SIZE = 1
type ServiceTerms struct {
type TermsOfService struct {
Id string `json:"id"`
CreateAt int64 `json:"create_at"`
UserId string `json:"user_id"`
Text string `json:"text"`
}
func (t *ServiceTerms) IsValid() *AppError {
func (t *TermsOfService) IsValid() *AppError {
if len(t.Id) != 26 {
return InvalidServiceTermsError("id", "")
return InvalidTermsOfServiceError("id", "")
}
if t.CreateAt == 0 {
return InvalidServiceTermsError("create_at", t.Id)
return InvalidTermsOfServiceError("create_at", t.Id)
}
if len(t.UserId) != 26 {
return InvalidServiceTermsError("user_id", t.Id)
return InvalidTermsOfServiceError("user_id", t.Id)
}
if utf8.RuneCountInString(t.Text) > POST_MESSAGE_MAX_RUNES_V2 {
return InvalidServiceTermsError("text", t.Id)
return InvalidTermsOfServiceError("text", t.Id)
}
return nil
}
func (t *ServiceTerms) ToJson() string {
func (t *TermsOfService) 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 TermsOfServiceFromJson(data io.Reader) *TermsOfService {
var termsOfService *TermsOfService
json.NewDecoder(data).Decode(&termsOfService)
return termsOfService
}
func InvalidServiceTermsError(fieldName string, serviceTermsId string) *AppError {
id := fmt.Sprintf("model.service_terms.is_valid.%s.app_error", fieldName)
func InvalidTermsOfServiceError(fieldName string, termsOfServiceId string) *AppError {
id := fmt.Sprintf("model.terms_of_service.is_valid.%s.app_error", fieldName)
details := ""
if serviceTermsId != "" {
details = "service_terms_id=" + serviceTermsId
if termsOfServiceId != "" {
details = "terms_of_service_id=" + termsOfServiceId
}
return NewAppError("ServiceTerms.IsValid", id, map[string]interface{}{"MaxLength": POST_MESSAGE_MAX_RUNES_V2}, details, http.StatusBadRequest)
return NewAppError("TermsOfServiceStore.IsValid", id, map[string]interface{}{"MaxLength": POST_MESSAGE_MAX_RUNES_V2}, details, http.StatusBadRequest)
}
func (t *ServiceTerms) PreSave() {
func (t *TermsOfService) PreSave() {
if t.Id == "" {
t.Id = NewId()
}
......
......@@ -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"`