github.com/coincircle/mattermost-server@v4.8.1-0.20180321182714-9d701c704416+incompatible/model/command_webhook.go (about) 1 // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package model 5 6 import ( 7 "net/http" 8 ) 9 10 type CommandWebhook struct { 11 Id string 12 CreateAt int64 13 CommandId string 14 UserId string 15 ChannelId string 16 RootId string 17 ParentId string 18 UseCount int 19 } 20 21 const ( 22 COMMAND_WEBHOOK_LIFETIME = 1000 * 60 * 30 23 ) 24 25 func (o *CommandWebhook) PreSave() { 26 if o.Id == "" { 27 o.Id = NewId() 28 } 29 30 if o.CreateAt == 0 { 31 o.CreateAt = GetMillis() 32 } 33 } 34 35 func (o *CommandWebhook) IsValid() *AppError { 36 if len(o.Id) != 26 { 37 return NewAppError("CommandWebhook.IsValid", "model.command_hook.id.app_error", nil, "", http.StatusBadRequest) 38 } 39 40 if o.CreateAt == 0 { 41 return NewAppError("CommandWebhook.IsValid", "model.command_hook.create_at.app_error", nil, "id="+o.Id, http.StatusBadRequest) 42 } 43 44 if len(o.CommandId) != 26 { 45 return NewAppError("CommandWebhook.IsValid", "model.command_hook.command_id.app_error", nil, "", http.StatusBadRequest) 46 } 47 48 if len(o.UserId) != 26 { 49 return NewAppError("CommandWebhook.IsValid", "model.command_hook.user_id.app_error", nil, "", http.StatusBadRequest) 50 } 51 52 if len(o.ChannelId) != 26 { 53 return NewAppError("CommandWebhook.IsValid", "model.command_hook.channel_id.app_error", nil, "", http.StatusBadRequest) 54 } 55 56 if len(o.RootId) != 0 && len(o.RootId) != 26 { 57 return NewAppError("CommandWebhook.IsValid", "model.command_hook.root_id.app_error", nil, "", http.StatusBadRequest) 58 } 59 60 if len(o.ParentId) != 0 && len(o.ParentId) != 26 { 61 return NewAppError("CommandWebhook.IsValid", "model.command_hook.parent_id.app_error", nil, "", http.StatusBadRequest) 62 } 63 64 return nil 65 }