MM-11229: Fix invite people slash command and add test case. (#9074)
Этот коммит содержится в:
коммит произвёл
Carlos Tadeu Panato Junior
родитель
2d16a71af9
Коммит
af615ffc24
@@ -41,6 +41,14 @@ func (me *InvitePeopleProvider) GetCommand(a *App, T goi18n.TranslateFunc) *mode
|
||||
}
|
||||
|
||||
func (me *InvitePeopleProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
if !a.SessionHasPermissionToTeam(args.Session, args.TeamId, model.PERMISSION_INVITE_USER) {
|
||||
return &model.CommandResponse{Text: args.T("api.command_invite_people.permission.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
if !a.SessionHasPermissionToTeam(args.Session, args.TeamId, model.PERMISSION_ADD_USER_TO_TEAM) {
|
||||
return &model.CommandResponse{Text: args.T("api.command_invite_people.permission.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
if !a.Config().EmailSettings.SendEmailNotifications {
|
||||
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command.invite_people.email_off")}
|
||||
}
|
||||
|
||||
36
app/command_invite_people_test.go
Обычный файл
36
app/command_invite_people_test.go
Обычный файл
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
)
|
||||
|
||||
func TestInvitePeopleProvider(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
cmd := InvitePeopleProvider{}
|
||||
|
||||
// Test without required permissions
|
||||
args := &model.CommandArgs{
|
||||
T: func(s string, args ...interface{}) string { return s },
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
TeamId: th.BasicTeam.Id,
|
||||
UserId: th.BasicUser.Id,
|
||||
Session: model.Session{UserId: th.BasicUser.Id, TeamMembers: []*model.TeamMember{{TeamId: th.BasicTeam.Id, Roles: ""}}},
|
||||
}
|
||||
|
||||
actual := cmd.DoCommand(th.App, args, model.NewId()+"@simulator.amazonses.com")
|
||||
assert.Equal(t, "api.command_invite_people.permission.app_error", actual.Text)
|
||||
|
||||
// Test with required permissions.
|
||||
args.Session.TeamMembers[0].Roles = model.TEAM_USER_ROLE_ID
|
||||
actual = cmd.DoCommand(th.App, args, model.NewId()+"@simulator.amazonses.com")
|
||||
assert.Equal(t, "api.command.invite_people.sent", actual.Text)
|
||||
}
|
||||
@@ -630,6 +630,10 @@
|
||||
"id": "api.command_invite.permission.app_error",
|
||||
"translation": "You don't have enough permissions to add {{.User}} in {{.Channel}}."
|
||||
},
|
||||
{
|
||||
"id": "api.command_invite_people.permission.app_error",
|
||||
"translation": "You don't have permission to invite new users to this server."
|
||||
},
|
||||
{
|
||||
"id": "api.command_invite.private_channel.app_error",
|
||||
"translation": "Could not find the channel {{.Channel}}. Please use the channel handle to identify channels."
|
||||
|
||||
Ссылка в новой задаче
Block a user