[MM-10458] Change system response to "Could not find the channel" - bug fix (#8738)

* [MM-10458] Change system response to "Could not find the channel" when trying to invite user to private channel you can't see

* add another check to check if user have permission to add another in pvt channel
Этот коммит содержится в:
Carlos Tadeu Panato Junior
2018-05-11 17:20:47 +02:00
коммит произвёл Derrick Anderson
родитель 21d3b247d9
Коммит 0dbaa2d032
4 изменённых файлов: 43 добавлений и 1 удалений

Просмотреть файл

@@ -79,10 +79,18 @@ 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}
}
if channelToJoin.Type == model.CHANNEL_PRIVATE && !a.SessionHasPermissionToChannel(args.Session, channelToJoin.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) {
// Check if the user who wants to add another is trying to add in a pvt channel, but does not have permission
// but is in the channel
_, err = a.GetChannelMember(channelToJoin.Id, args.UserId)
if channelToJoin.Type == model.CHANNEL_PRIVATE && !a.SessionHasPermissionToChannel(args.Session, channelToJoin.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) && err == nil {
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}
}
// In this case just check if is a pvt channel and user has permission
if channelToJoin.Type == model.CHANNEL_PRIVATE && !a.SessionHasPermissionToChannel(args.Session, channelToJoin.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) {
return &model.CommandResponse{Text: args.T("api.command_invite.private_channel.app_error", map[string]interface{}{"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 {