diff options
author | Martin Kraft <martinkraft@gmail.com> | 2018-05-09 15:00:07 -0400 |
---|---|---|
committer | Martin Kraft <martinkraft@gmail.com> | 2018-05-09 15:00:07 -0400 |
commit | d3e14a1bf86ac6148e09f888384cb46c61f23cdc (patch) | |
tree | 1c634c90166964f5184cb1ebd20ffb8ed209b120 /app/command_invite.go | |
parent | 60cf74352f13874a7d07c609c03b1c763af19cea (diff) | |
parent | c1853c7f40dd67c49524c8ea884ab61883a6abdd (diff) | |
download | chat-d3e14a1bf86ac6148e09f888384cb46c61f23cdc.tar.gz chat-d3e14a1bf86ac6148e09f888384cb46c61f23cdc.tar.bz2 chat-d3e14a1bf86ac6148e09f888384cb46c61f23cdc.zip |
Merge remote-tracking branch 'origin/master' into advanced-permissions-phase-2
Diffstat (limited to 'app/command_invite.go')
-rw-r--r-- | app/command_invite.go | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/app/command_invite.go b/app/command_invite.go index 9045365ad..4b76c0c45 100644 --- a/app/command_invite.go +++ b/app/command_invite.go @@ -4,7 +4,6 @@ package app import ( - "fmt" "strings" "github.com/mattermost/mattermost-server/mlog" @@ -42,8 +41,6 @@ func (me *InviteProvider) DoCommand(a *App, args *model.CommandArgs, message str return &model.CommandResponse{Text: args.T("api.command_invite.missing_message.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} } - mlog.Debug(fmt.Sprint(message)) - splitMessage := strings.SplitN(message, " ", 2) targetUsername := splitMessage[0] targetUsername = strings.TrimPrefix(targetUsername, "@") @@ -77,12 +74,7 @@ func (me *InviteProvider) DoCommand(a *App, args *model.CommandArgs, message str return &model.CommandResponse{Text: args.T("api.command_invite.directchannel.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} } - // Check if user is already in the channel - _, err = a.GetChannelMember(channelToJoin.Id, userProfile.Id) - if err == nil { - return &model.CommandResponse{Text: args.T("api.command_invite.user_already_in_channel.app_error", map[string]interface{}{"User": userProfile.Username}), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} - } - + // Check Permissions if channelToJoin.Type == model.CHANNEL_OPEN && !a.SessionHasPermissionToChannel(args.Session, channelToJoin.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS) { return &model.CommandResponse{Text: args.T("api.command_invite.permission.app_error", map[string]interface{}{"User": userProfile.Username, "Channel": channelToJoin.Name}), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} } @@ -91,6 +83,12 @@ func (me *InviteProvider) DoCommand(a *App, args *model.CommandArgs, message str return &model.CommandResponse{Text: args.T("api.command_invite.permission.app_error", map[string]interface{}{"User": userProfile.Username, "Channel": channelToJoin.Name}), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} } + // Check if user is already in the channel + _, err = a.GetChannelMember(channelToJoin.Id, userProfile.Id) + if err == nil { + return &model.CommandResponse{Text: args.T("api.command_invite.user_already_in_channel.app_error", map[string]interface{}{"User": userProfile.Username}), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} + } + if _, err := a.AddChannelMember(userProfile.Id, channelToJoin, args.Session.UserId, ""); err != nil { return &model.CommandResponse{Text: args.T("api.command_invite.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} } |