[MM-32622] Remove app.WaitForChannelMembership() (#17048)
* Remove app.WaitForChannelMembership * Fix tests * Fix test Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
4ba0c09fc7
Коммит
ee3f986da0
@@ -4,6 +4,8 @@
|
||||
package slashcommands
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/app"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/shared/i18n"
|
||||
@@ -63,7 +65,7 @@ func (*HeaderProvider) DoCommand(a *app.App, args *model.CommandArgs, message st
|
||||
case model.CHANNEL_GROUP, model.CHANNEL_DIRECT:
|
||||
// Modifying the header is not linked to any specific permission for group/dm channels, so just check for membership.
|
||||
var channelMember *model.ChannelMember
|
||||
channelMember, err = a.GetChannelMember(args.ChannelId, args.UserId)
|
||||
channelMember, err = a.GetChannelMember(context.Background(), args.ChannelId, args.UserId)
|
||||
if err != nil || channelMember == nil {
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_channel_header.permission.app_error"),
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package slashcommands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/app"
|
||||
@@ -103,7 +104,7 @@ func (*InviteProvider) DoCommand(a *app.App, args *model.CommandArgs, message st
|
||||
}
|
||||
case model.CHANNEL_PRIVATE:
|
||||
if !a.HasPermissionToChannel(args.UserId, channelToJoin.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) {
|
||||
if _, err = a.GetChannelMember(channelToJoin.Id, args.UserId); err == nil {
|
||||
if _, err = a.GetChannelMember(context.Background(), channelToJoin.Id, args.UserId); err == nil {
|
||||
// User doing the inviting is a member of the channel.
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_invite.permission.app_error", map[string]interface{}{
|
||||
@@ -129,7 +130,7 @@ func (*InviteProvider) DoCommand(a *app.App, args *model.CommandArgs, message st
|
||||
}
|
||||
|
||||
// Check if user is already in the channel
|
||||
_, err = a.GetChannelMember(channelToJoin.Id, userProfile.Id)
|
||||
_, err = a.GetChannelMember(context.Background(), channelToJoin.Id, userProfile.Id)
|
||||
if err == nil {
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_invite.user_already_in_channel.app_error", map[string]interface{}{
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package slashcommands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -80,7 +81,7 @@ func TestLeaveProviderDoCommand(t *testing.T) {
|
||||
assert.Equal(t, args.SiteURL+"/"+th.BasicTeam.Name+"/channels/"+model.DEFAULT_CHANNEL, actual.GotoLocation)
|
||||
assert.Equal(t, "", actual.ResponseType)
|
||||
|
||||
_, err = th.App.GetChannelMember(publicChannel.Id, th.BasicUser.Id)
|
||||
_, err = th.App.GetChannelMember(context.Background(), publicChannel.Id, th.BasicUser.Id)
|
||||
assert.NotNil(t, err)
|
||||
assert.NotNil(t, err.Id, "app.channel.get_member.missing.app_error")
|
||||
})
|
||||
@@ -122,7 +123,7 @@ func TestLeaveProviderDoCommand(t *testing.T) {
|
||||
assert.Equal(t, args.SiteURL+"/"+th.BasicTeam.Name+"/channels/"+publicChannel.Name, actual.GotoLocation)
|
||||
assert.Equal(t, "", actual.ResponseType)
|
||||
|
||||
_, err = th.App.GetChannelMember(defaultChannel.Id, guest.Id)
|
||||
_, err = th.App.GetChannelMember(context.Background(), defaultChannel.Id, guest.Id)
|
||||
assert.NotNil(t, err)
|
||||
assert.NotNil(t, err.Id, "app.channel.get_member.missing.app_error")
|
||||
})
|
||||
@@ -140,7 +141,7 @@ func TestLeaveProviderDoCommand(t *testing.T) {
|
||||
assert.Equal(t, args.SiteURL+"/", actual.GotoLocation)
|
||||
assert.Equal(t, "", actual.ResponseType)
|
||||
|
||||
_, err = th.App.GetChannelMember(publicChannel.Id, guest.Id)
|
||||
_, err = th.App.GetChannelMember(context.Background(), publicChannel.Id, guest.Id)
|
||||
assert.NotNil(t, err)
|
||||
assert.NotNil(t, err.Id, "app.channel.get_member.missing.app_error")
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package slashcommands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -22,7 +23,7 @@ func TestMuteCommandNoChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
channel1 := th.BasicChannel
|
||||
channel1M, channel1MError := th.App.GetChannelMember(channel1.Id, th.BasicUser.Id)
|
||||
channel1M, channel1MError := th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
|
||||
assert.Nil(t, channel1MError, "User is not a member of channel 1")
|
||||
assert.NotEqual(
|
||||
@@ -45,7 +46,7 @@ func TestMuteCommandNoArgs(t *testing.T) {
|
||||
defer th.tearDown()
|
||||
|
||||
channel1 := th.BasicChannel
|
||||
channel1M, _ := th.App.GetChannelMember(channel1.Id, th.BasicUser.Id)
|
||||
channel1M, _ := th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
|
||||
assert.Equal(t, model.CHANNEL_NOTIFY_ALL, channel1M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP])
|
||||
|
||||
@@ -87,7 +88,7 @@ func TestMuteCommandSpecificChannel(t *testing.T) {
|
||||
CreatorId: th.BasicUser.Id,
|
||||
}, true)
|
||||
|
||||
channel2M, _ := th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
|
||||
channel2M, _ := th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
|
||||
assert.Equal(t, model.CHANNEL_NOTIFY_ALL, channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP])
|
||||
|
||||
@@ -100,7 +101,7 @@ func TestMuteCommandSpecificChannel(t *testing.T) {
|
||||
UserId: th.BasicUser.Id,
|
||||
}, channel2.Name)
|
||||
assert.Equal(t, "api.command_mute.success_mute", resp.Text)
|
||||
channel2M, _ = th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
|
||||
channel2M, _ = th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
assert.Equal(t, model.CHANNEL_NOTIFY_MENTION, channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP])
|
||||
|
||||
// Now unmute the channel
|
||||
@@ -111,7 +112,7 @@ func TestMuteCommandSpecificChannel(t *testing.T) {
|
||||
}, "~"+channel2.Name)
|
||||
|
||||
assert.Equal(t, "api.command_mute.success_unmute", resp.Text)
|
||||
channel2M, _ = th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
|
||||
channel2M, _ = th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
assert.Equal(t, model.CHANNEL_NOTIFY_ALL, channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP])
|
||||
}
|
||||
|
||||
@@ -173,7 +174,7 @@ func TestMuteCommandDMChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
channel2, _ := th.App.GetOrCreateDirectChannel(th.BasicUser.Id, th.BasicUser2.Id)
|
||||
channel2M, _ := th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
|
||||
channel2M, _ := th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
|
||||
assert.Equal(t, model.CHANNEL_NOTIFY_ALL, channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP])
|
||||
|
||||
@@ -187,7 +188,7 @@ func TestMuteCommandDMChannel(t *testing.T) {
|
||||
}, "")
|
||||
assert.Equal(t, "api.command_mute.success_mute_direct_msg", resp.Text)
|
||||
time.Sleep(time.Millisecond)
|
||||
channel2M, _ = th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
|
||||
channel2M, _ = th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
assert.Equal(t, model.CHANNEL_NOTIFY_MENTION, channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP])
|
||||
|
||||
// Now unmute the channel
|
||||
@@ -199,6 +200,6 @@ func TestMuteCommandDMChannel(t *testing.T) {
|
||||
|
||||
assert.Equal(t, "api.command_mute.success_unmute_direct_msg", resp.Text)
|
||||
time.Sleep(time.Millisecond)
|
||||
channel2M, _ = th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
|
||||
channel2M, _ = th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
assert.Equal(t, model.CHANNEL_NOTIFY_ALL, channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP])
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package slashcommands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/app"
|
||||
@@ -122,7 +123,7 @@ func doCommand(a *app.App, args *model.CommandArgs, message string) *model.Comma
|
||||
}
|
||||
}
|
||||
|
||||
_, err = a.GetChannelMember(args.ChannelId, userProfile.Id)
|
||||
_, err = a.GetChannelMember(context.Background(), args.ChannelId, userProfile.Id)
|
||||
if err != nil {
|
||||
nameFormat := *a.Config().TeamSettings.TeammateNameDisplay
|
||||
return &model.CommandResponse{
|
||||
|
||||
Ссылка в новой задаче
Block a user