github.com/mattermosttest/mattermost-server/v5@v5.0.0-20200917143240-9dfa12e121f9/model/command_webhook.go (about) 1 // Copyright (c) 2015-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 !IsValidId(o.Id) { 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 !IsValidId(o.CommandId) { 45 return NewAppError("CommandWebhook.IsValid", "model.command_hook.command_id.app_error", nil, "", http.StatusBadRequest) 46 } 47 48 if !IsValidId(o.UserId) { 49 return NewAppError("CommandWebhook.IsValid", "model.command_hook.user_id.app_error", nil, "", http.StatusBadRequest) 50 } 51 52 if !IsValidId(o.ChannelId) { 53 return NewAppError("CommandWebhook.IsValid", "model.command_hook.channel_id.app_error", nil, "", http.StatusBadRequest) 54 } 55 56 if len(o.RootId) != 0 && !IsValidId(o.RootId) { 57 return NewAppError("CommandWebhook.IsValid", "model.command_hook.root_id.app_error", nil, "", http.StatusBadRequest) 58 } 59 60 if len(o.ParentId) != 0 && !IsValidId(o.ParentId) { 61 return NewAppError("CommandWebhook.IsValid", "model.command_hook.parent_id.app_error", nil, "", http.StatusBadRequest) 62 } 63 64 return nil 65 }