MM-18005: Improve display message when attempting to add an outsider to a group-synced team via new team invite flow (#12966)

* Update group errors being returned

* update based on merge, error already added

* remove unnecessary translation

* Revert "remove unnecessary translation"

This reverts commit 5a4ae89618ddca5ea256009aab167f3e071f488c.

* remove unnecessary translation
Этот коммит содержится в:
Scott Bishel
2019-11-10 08:07:49 -07:00
коммит произвёл GitHub
родитель d9a154fc70
Коммит 53ee077cfd
2 изменённых файлов: 73 добавлений и 2 удалений

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

@@ -7,6 +7,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/model"
)
@@ -42,6 +43,15 @@ func TestInviteProvider(t *testing.T) {
userAndInvalidPrivate := "@" + basicUser3.Username + " ~" + privateChannel2.Name
deactivatedUserPublicChannel := "@" + deactivatedUser.Username + " ~" + channel.Name
groupChannel := th.createChannel(th.BasicTeam, model.CHANNEL_PRIVATE)
var err *model.AppError
_, err = th.App.AddChannelMember(th.BasicUser.Id, groupChannel, "", "")
require.Nil(t, err)
groupChannel.GroupConstrained = model.NewBool(true)
groupChannel, _ = th.App.UpdateChannel(groupChannel)
groupChannelNonUser := "@" + th.BasicUser2.Username + " ~" + groupChannel.Name
tests := []struct {
desc string
expected string
@@ -97,6 +107,11 @@ func TestInviteProvider(t *testing.T) {
expected: "api.command_invite.user_not_in_team.app_error",
msg: basicUser4.Username,
},
{
desc: "try to add a user not part of the group to a group channel",
expected: "api.command_invite.group_constrained_user_denied",
msg: groupChannelNonUser,
},
{
desc: "try to add a user to a private channel with no permission",
expected: "api.command_invite.private_channel.app_error",
@@ -116,3 +131,59 @@ func TestInviteProvider(t *testing.T) {
})
}
}
func TestInviteGroup(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th.BasicTeam.GroupConstrained = model.NewBool(true)
var err *model.AppError
_, _ = th.App.AddTeamMember(th.BasicTeam.Id, th.BasicUser.Id)
_, err = th.App.AddTeamMember(th.BasicTeam.Id, th.BasicUser2.Id)
require.Nil(t, err)
th.BasicTeam, _ = th.App.UpdateTeam(th.BasicTeam)
privateChannel := th.createChannel(th.BasicTeam, model.CHANNEL_PRIVATE)
groupChannelUser1 := "@" + th.BasicUser.Username + " ~" + privateChannel.Name
groupChannelUser2 := "@" + th.BasicUser2.Username + " ~" + privateChannel.Name
basicUser3 := th.CreateUser()
groupChannelUser3 := "@" + basicUser3.Username + " ~" + privateChannel.Name
InviteP := InviteProvider{}
args := &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
ChannelId: th.BasicChannel.Id,
TeamId: th.BasicTeam.Id,
Session: model.Session{UserId: th.BasicUser.Id, TeamMembers: []*model.TeamMember{{TeamId: th.BasicTeam.Id, Roles: model.TEAM_USER_ROLE_ID}}},
}
tests := []struct {
desc string
expected string
msg string
}{
{
desc: "try to add an existing user part of the group to a group channel",
expected: "api.command_invite.user_already_in_channel.app_error",
msg: groupChannelUser1,
},
{
desc: "try to add a user part of the group to a group channel",
expected: "api.command_invite.success",
msg: groupChannelUser2,
},
{
desc: "try to add a user NOT part of the group to a group channel",
expected: "api.command_invite.user_not_in_team.app_error",
msg: groupChannelUser3,
},
}
for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
actual := InviteP.DoCommand(th.App, args, test.msg).Text
assert.Equal(t, test.expected, actual)
})
}
}

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

@@ -764,7 +764,7 @@
},
{
"id": "api.command_invite.group_constrained_user_denied",
"translation": "User cannot be added to this channel because it is constrained to group members only."
"translation": "This channel is managed by groups. This user is not part of a group that is synched to this channel."
},
{
"id": "api.command_invite.hint",
@@ -1864,7 +1864,7 @@
},
{
"id": "api.team.add_members.user_denied",
"translation": "Team membership denied to the following users because of group constraints: {{ .UserIDs }}"
"translation": "This team is managed by groups. This user is not part of a group that is synched to this team."
},
{
"id": "api.team.add_user_to_team.added",