github.com/coincircle/mattermost-server@v4.8.1-0.20180321182714-9d701c704416+incompatible/app/command_channel_header.go (about) 1 // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package app 5 6 import ( 7 "github.com/mattermost/mattermost-server/model" 8 9 goi18n "github.com/nicksnyder/go-i18n/i18n" 10 ) 11 12 type HeaderProvider struct { 13 } 14 15 const ( 16 CMD_HEADER = "header" 17 ) 18 19 func init() { 20 RegisterCommandProvider(&HeaderProvider{}) 21 } 22 23 func (me *HeaderProvider) GetTrigger() string { 24 return CMD_HEADER 25 } 26 27 func (me *HeaderProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command { 28 return &model.Command{ 29 Trigger: CMD_HEADER, 30 AutoComplete: true, 31 AutoCompleteDesc: T("api.command_channel_header.desc"), 32 AutoCompleteHint: T("api.command_channel_header.hint"), 33 DisplayName: T("api.command_channel_header.name"), 34 } 35 } 36 37 func (me *HeaderProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse { 38 channel, err := a.GetChannel(args.ChannelId) 39 if err != nil { 40 return &model.CommandResponse{Text: args.T("api.command_channel_header.channel.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} 41 } 42 43 if channel.Type == model.CHANNEL_OPEN && !a.SessionHasPermissionToChannel(args.Session, args.ChannelId, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) { 44 return &model.CommandResponse{Text: args.T("api.command_channel_header.permission.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} 45 } 46 47 if channel.Type == model.CHANNEL_PRIVATE && !a.SessionHasPermissionToChannel(args.Session, args.ChannelId, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES) { 48 return &model.CommandResponse{Text: args.T("api.command_channel_header.permission.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} 49 } 50 51 if len(message) == 0 { 52 return &model.CommandResponse{Text: args.T("api.command_channel_header.message.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} 53 } 54 55 patch := &model.ChannelPatch{ 56 Header: new(string), 57 } 58 *patch.Header = message 59 60 _, err = a.PatchChannel(channel, patch, args.UserId) 61 if err != nil { 62 return &model.CommandResponse{Text: args.T("api.command_channel_header.update_channel.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} 63 } 64 65 return &model.CommandResponse{} 66 }