MM-54123 Add group slash command (#24553)

* adding group members to channel initial commit

* adding group to channel functionality along with add new team members

* fixing circular dependency

* fixing e2e and other optimizations

* adding e2e tests for adding group members to channels

* cypress lint

* fixing comments

* adding count to button

* improvements

* adjusting some stuff from PR comments

* remove ability to add user to team, update message for non-team members

* remove adding to team from add groups functionality

* update misspelled variable

* lint and unit test fixes

* add tests, cleanup

* lint fix

* revert package-lock.json

* fixes for cypress tests

* rename TeamInviteBanner to TeamWarningBanner, since invites are no longer allowed

* update for warning

* lint fixes

* cleanup

* fix failing e2e tests

* update slash command for user groups

* revert package-lock

* remove unused function

* update based on feedback

* update tests for last change

* i18n-extract, reorder

* retrieve and display user name

---------

Co-authored-by: Benjamin Cooke <benkcooke@gmail.com>
Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Scott Bishel
2023-09-15 11:00:41 -06:00
коммит произвёл GitHub
родитель 0409a2285d
Коммит 64fabbeed3
4 изменённых файлов: 496 добавлений и 146 удалений

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

@@ -74,7 +74,7 @@ func TestInviteProvider(t *testing.T) {
channel2 := th.createChannel(th.BasicTeam, model.ChannelTypeOpen)
msg := "@" + th.BasicUser2.Username + " @" + anotherUser.Username + " ~" + channel1.Name + " ~" + channel2.Name
expected := "api.command_invite.success\napi.command_invite.success\napi.command_invite.success\napi.command_invite.success"
expected := "api.command_invite.success"
runCmd(msg, expected)
checkIsMember(channel1.Id, th.BasicUser2.Id)
checkIsMember(channel2.Id, th.BasicUser2.Id)
@@ -149,7 +149,7 @@ func TestInviteProvider(t *testing.T) {
groupChannel, _ = th.App.UpdateChannel(th.Context, groupChannel)
msg := "@" + th.BasicUser2.Username + " ~" + groupChannel.Name
runCmd(msg, "api.command_invite.group_constrained_user_denied")
runCmd(msg, "api.command_invite.channel_constrained_user_denied")
checkIsNotMember(groupChannel.Id, th.BasicUser2.Id)
})
@@ -264,3 +264,81 @@ func TestInviteGroup(t *testing.T) {
})
}
}
func TestUserGroups(t *testing.T) {
th := setup(t).initBasic()
defer th.tearDown()
privateChannel := th.createChannel(th.BasicTeam, model.ChannelTypePrivate)
id := model.NewId()
teamGroup, err := th.App.CreateGroup(&model.Group{
DisplayName: "dn_" + id,
Name: model.NewString("name" + id),
Source: model.GroupSourceCustom,
Description: "description_" + id,
AllowReference: true,
// MemberIDs: []string{th.BasicUser2.Id},
})
assert.Nil(t, err)
teamGroupCommand := "@" + *teamGroup.Name + " ~" + privateChannel.Name
// th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional))
groupMembers, upsertErr := th.App.UpsertGroupMembers(teamGroup.Id, []string{th.BasicUser2.Id})
require.Nil(t, upsertErr)
assert.Len(t, groupMembers, 1)
basicUser3 := th.createUser()
basicUser4 := th.createUser()
id2 := model.NewId()
nonTeamGroup, err := th.App.CreateGroup(&model.Group{
DisplayName: "dn_" + id2,
Name: model.NewString("name" + id2),
Source: model.GroupSourceCustom,
Description: "description_" + id2,
AllowReference: true,
// MemberIDs: []string{basicUser3.Id, basicUser4.Id},
})
assert.Nil(t, err)
nonTeamGroupCommand := "@" + *nonTeamGroup.Name + " ~" + privateChannel.Name
nonTeamGroupMembers, upsertErr := th.App.UpsertGroupMembers(nonTeamGroup.Id, []string{basicUser3.Id, basicUser4.Id})
require.Nil(t, upsertErr)
assert.Len(t, nonTeamGroupMembers, 2)
InviteP := InviteProvider{}
args := &model.CommandArgs{
T: func(s string, args ...any) string { return s },
ChannelId: th.BasicChannel.Id,
TeamId: th.BasicTeam.Id,
UserId: th.BasicUser.Id,
}
tests := []struct {
desc string
expected string
msg string
}{
{
desc: "try to add an new group of users ",
expected: "api.command_invite.success",
msg: teamGroupCommand,
},
{
desc: "try to add existing users",
expected: "api.command_invite.user_already_in_channel.app_error",
msg: teamGroupCommand,
},
{
desc: "try to add a user NOT part of the team",
expected: "api.command_invite.user_not_in_team.app_error",
msg: nonTeamGroupCommand,
},
}
for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
actual := InviteP.DoCommand(th.App, th.Context, args, test.msg).Text
assert.Equal(t, test.expected, actual)
})
}
}