diff options
author | Harshil Sharma <harshil.sharma@joshtechnologygroup.com> | 2018-10-10 00:55:47 +0000 |
---|---|---|
committer | Jesse Hallam <jesse.hallam@gmail.com> | 2018-10-09 20:55:47 -0400 |
commit | bffcccf99de8a8f3c68cff9e39d2847f0996b67b (patch) | |
tree | 10bf45d87927dc792a233d0653d6ba273c9a7b28 /model/terms_of_service.go | |
parent | 59319b7915b8eb4c20a0d4878382cc0e41fc536d (diff) | |
download | chat-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/terms_of_service.go')
-rw-r--r-- | model/terms_of_service.go | 70 |
1 files changed, 70 insertions, 0 deletions
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() +} |