mirror of
https://github.com/mattermost/mattermost.git
synced 2026-04-15 22:12:19 -04:00
* model -> public/model * plugin -> public/plugin * public/model/utils -> public/utils * platform/shared/mlog -> public/shared/mlog * platform/shared/i18n -> public/shared/i18n * platform/shared/markdown -> public/shared/markdown * platform/services/timezones -> public/shared/timezones * channels/einterfaces -> einterfaces * expose public/ submodule * go mod tidy * .github: cache-dependency-path, setup-go-work * modules-tidy for public/ too * remove old gomodtidy
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package model
|
|
|
|
import (
|
|
"fmt"
|
|
"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 !IsValidId(ut.UserId) {
|
|
return InvalidUserTermsOfServiceError("user_id", ut.UserId)
|
|
}
|
|
|
|
if !IsValidId(ut.TermsOfServiceId) {
|
|
return InvalidUserTermsOfServiceError("terms_of_service_id", ut.UserId)
|
|
}
|
|
|
|
if ut.CreateAt == 0 {
|
|
return InvalidUserTermsOfServiceError("create_at", ut.UserId)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (ut *UserTermsOfService) PreSave() {
|
|
if ut.UserId == "" {
|
|
ut.UserId = NewId()
|
|
}
|
|
|
|
ut.CreateAt = GetMillis()
|
|
}
|
|
|
|
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)
|
|
}
|