MM-34002: Improve AddUserToChannel (#17174)
* MM-34002: Improve AddUserToChannel When we would add a user to a channel, we would check whether the user is removed from that team or not. During LDAP sync, this check is not required because the team member would have just been created. Hence, we pass a boolean flag to bypass the check. And with that done, we can freely query the replica. https://mattermost.atlassian.net/browse/MM-34002 ```release-note NONE ``` * Refactor code * Rename a struct field * fix double negative
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
4f0cfbe329
Коммит
db01f2a91b
@@ -140,7 +140,9 @@ func (*InviteProvider) DoCommand(a *app.App, args *model.CommandArgs, message st
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := a.AddChannelMember(userProfile.Id, channelToJoin, args.UserId, ""); err != nil {
|
||||
if _, err := a.AddChannelMember(userProfile.Id, channelToJoin, app.ChannelMemberOpts{
|
||||
UserRequestorID: args.UserId,
|
||||
}); err != nil {
|
||||
var text string
|
||||
if err.Id == "api.channel.add_members.user_denied" {
|
||||
text = args.T("api.command_invite.group_constrained_user_denied")
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/app"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
)
|
||||
|
||||
@@ -72,7 +73,7 @@ func TestInviteProvider(t *testing.T) {
|
||||
deactivatedUserPublicChannel := "@" + deactivatedUser.Username + " ~" + channel.Name
|
||||
|
||||
groupChannel := th.createChannel(th.BasicTeam, model.CHANNEL_PRIVATE)
|
||||
_, err = th.App.AddChannelMember(th.BasicUser.Id, groupChannel, "", "")
|
||||
_, err = th.App.AddChannelMember(th.BasicUser.Id, groupChannel, app.ChannelMemberOpts{})
|
||||
require.Nil(t, err)
|
||||
groupChannel.GroupConstrained = model.NewBool(true)
|
||||
groupChannel, _ = th.App.UpdateChannel(groupChannel)
|
||||
|
||||
@@ -41,11 +41,11 @@ func TestLeaveProviderDoCommand(t *testing.T) {
|
||||
guest := th.createGuest()
|
||||
|
||||
th.App.AddUserToTeam(th.BasicTeam.Id, th.BasicUser.Id, th.BasicUser.Id)
|
||||
th.App.AddUserToChannel(th.BasicUser, publicChannel)
|
||||
th.App.AddUserToChannel(th.BasicUser, privateChannel)
|
||||
th.App.AddUserToChannel(th.BasicUser, publicChannel, false)
|
||||
th.App.AddUserToChannel(th.BasicUser, privateChannel, false)
|
||||
th.App.AddUserToTeam(th.BasicTeam.Id, guest.Id, guest.Id)
|
||||
th.App.AddUserToChannel(guest, publicChannel)
|
||||
th.App.AddUserToChannel(guest, defaultChannel)
|
||||
th.App.AddUserToChannel(guest, publicChannel, false)
|
||||
th.App.AddUserToChannel(guest, defaultChannel, false)
|
||||
|
||||
t.Run("Should error when no Channel ID in args", func(t *testing.T) {
|
||||
args := &model.CommandArgs{
|
||||
|
||||
@@ -35,8 +35,8 @@ func TestRemoveProviderDoCommand(t *testing.T) {
|
||||
|
||||
targetUser := th.createUser()
|
||||
th.App.AddUserToTeam(th.BasicTeam.Id, targetUser.Id, targetUser.Id)
|
||||
th.App.AddUserToChannel(targetUser, publicChannel)
|
||||
th.App.AddUserToChannel(targetUser, privateChannel)
|
||||
th.App.AddUserToChannel(targetUser, publicChannel, false)
|
||||
th.App.AddUserToChannel(targetUser, privateChannel, false)
|
||||
|
||||
// Try a public channel *without* permission.
|
||||
args := &model.CommandArgs{
|
||||
@@ -49,7 +49,7 @@ func TestRemoveProviderDoCommand(t *testing.T) {
|
||||
assert.Equal(t, "api.command_remove.permission.app_error", actual)
|
||||
|
||||
// Try a public channel *with* permission.
|
||||
th.App.AddUserToChannel(th.BasicUser, publicChannel)
|
||||
th.App.AddUserToChannel(th.BasicUser, publicChannel, false)
|
||||
args = &model.CommandArgs{
|
||||
T: func(s string, args ...interface{}) string { return s },
|
||||
ChannelId: publicChannel.Id,
|
||||
@@ -70,7 +70,7 @@ func TestRemoveProviderDoCommand(t *testing.T) {
|
||||
assert.Equal(t, "api.command_remove.permission.app_error", actual)
|
||||
|
||||
// Try a private channel *with* permission.
|
||||
th.App.AddUserToChannel(th.BasicUser, privateChannel)
|
||||
th.App.AddUserToChannel(th.BasicUser, privateChannel, false)
|
||||
args = &model.CommandArgs{
|
||||
T: func(s string, args ...interface{}) string { return s },
|
||||
ChannelId: privateChannel.Id,
|
||||
@@ -110,7 +110,7 @@ func TestRemoveProviderDoCommand(t *testing.T) {
|
||||
// Try a public channel with a deactivated user.
|
||||
deactivatedUser := th.createUser()
|
||||
th.App.AddUserToTeam(th.BasicTeam.Id, deactivatedUser.Id, deactivatedUser.Id)
|
||||
th.App.AddUserToChannel(deactivatedUser, publicChannel)
|
||||
th.App.AddUserToChannel(deactivatedUser, publicChannel, false)
|
||||
th.App.UpdateActive(deactivatedUser, false)
|
||||
|
||||
args = &model.CommandArgs{
|
||||
|
||||
@@ -358,7 +358,7 @@ func (th *TestHelper) linkUserToTeam(user *model.User, team *model.Team) {
|
||||
func (th *TestHelper) addUserToChannel(user *model.User, channel *model.Channel) *model.ChannelMember {
|
||||
utils.DisableDebugLogForTest()
|
||||
|
||||
member, err := th.App.AddUserToChannel(user, channel)
|
||||
member, err := th.App.AddUserToChannel(user, channel, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user