[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
@@ -543,7 +543,7 @@ type AppIface interface {
|
||||
GetChannelByNameForTeamName(channelName, teamName string, includeDeleted bool) (*model.Channel, *model.AppError)
|
||||
GetChannelCounts(teamID string, userID string) (*model.ChannelCounts, *model.AppError)
|
||||
GetChannelGuestCount(channelID string) (int64, *model.AppError)
|
||||
GetChannelMember(channelID string, userID string) (*model.ChannelMember, *model.AppError)
|
||||
GetChannelMember(ctx context.Context, channelID string, userID string) (*model.ChannelMember, *model.AppError)
|
||||
GetChannelMemberCount(channelID string) (int64, *model.AppError)
|
||||
GetChannelMembersByIds(channelID string, userIDs []string) (*model.ChannelMembers, *model.AppError)
|
||||
GetChannelMembersForUser(teamID string, userID string) (*model.ChannelMembers, *model.AppError)
|
||||
@@ -610,7 +610,7 @@ type AppIface interface {
|
||||
GetLatestTermsOfService() (*model.TermsOfService, *model.AppError)
|
||||
GetLogs(page, perPage int) ([]string, *model.AppError)
|
||||
GetLogsSkipSend(page, perPage int) ([]string, *model.AppError)
|
||||
GetMemberCountsByGroup(channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, *model.AppError)
|
||||
GetMemberCountsByGroup(ctx context.Context, channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, *model.AppError)
|
||||
GetMessageForNotification(post *model.Post, translateFunc i18n.TranslateFunc) string
|
||||
GetMultipleEmojiByName(names []string) ([]*model.Emoji, *model.AppError)
|
||||
GetNewUsersForTeamPage(teamID string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||
@@ -1044,6 +1044,5 @@ type AppIface interface {
|
||||
VerifyEmailFromToken(userSuppliedTokenString string) *model.AppError
|
||||
VerifyUserEmail(userID, email string) *model.AppError
|
||||
ViewChannel(view *model.ChannelView, userID string, currentSessionId string) (map[string]int64, *model.AppError)
|
||||
WaitForChannelMembership(channelID string, userID string)
|
||||
WriteFile(fr io.Reader, path string) (int64, *model.AppError)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
@@ -175,7 +176,7 @@ func (a *App) HasPermissionToChannel(askingUserId string, channelID string, perm
|
||||
return false
|
||||
}
|
||||
|
||||
channelMember, err := a.GetChannelMember(channelID, askingUserId)
|
||||
channelMember, err := a.GetChannelMember(context.Background(), channelID, askingUserId)
|
||||
if err == nil {
|
||||
roles := channelMember.GetRoles()
|
||||
if a.RolesGrantPermission(roles, permission.Id) {
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/plugin"
|
||||
@@ -341,7 +340,6 @@ func (a *App) GetOrCreateDirectChannel(userID, otherUserID string) (*model.Chann
|
||||
return nil, err
|
||||
}
|
||||
|
||||
a.WaitForChannelMembership(channel.Id, userID)
|
||||
a.handleCreationEvent(userID, otherUserID, channel)
|
||||
return channel, nil
|
||||
}
|
||||
@@ -364,7 +362,6 @@ func (a *App) getOrCreateDirectChannelWithUser(user, otherUser *model.User) (*mo
|
||||
return nil, err
|
||||
}
|
||||
|
||||
a.WaitForChannelMembership(channel.Id, user.Id)
|
||||
a.handleCreationEvent(user.Id, otherUser.Id, channel)
|
||||
return channel, nil
|
||||
}
|
||||
@@ -466,34 +463,6 @@ func (a *App) createDirectChannelWithUser(user, otherUser *model.User) (*model.C
|
||||
return channel, nil
|
||||
}
|
||||
|
||||
func (a *App) WaitForChannelMembership(channelID string, userID string) {
|
||||
if len(a.Config().SqlSettings.DataSourceReplicas) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
now := model.GetMillis()
|
||||
|
||||
for model.GetMillis()-now < 12000 {
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
_, err := a.Srv().Store.Channel().GetMember(channelID, userID)
|
||||
|
||||
// If the membership was found then return
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// If we received an error, but it wasn't a missing channel member then return
|
||||
var nfErr *store.ErrNotFound
|
||||
if !errors.As(err, &nfErr) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
mlog.Error("WaitForChannelMembership giving up", mlog.String("channel_id", channelID), mlog.String("user_id", userID))
|
||||
}
|
||||
|
||||
func (a *App) CreateGroupChannel(userIDs []string, creatorId string) (*model.Channel, *model.AppError) {
|
||||
channel, err := a.createGroupChannel(userIDs)
|
||||
if err != nil {
|
||||
@@ -504,10 +473,6 @@ func (a *App) CreateGroupChannel(userIDs []string, creatorId string) (*model.Cha
|
||||
}
|
||||
|
||||
for _, userID := range userIDs {
|
||||
if userID == creatorId {
|
||||
a.WaitForChannelMembership(channel.Id, creatorId)
|
||||
}
|
||||
|
||||
a.InvalidateCacheForUser(userID)
|
||||
}
|
||||
|
||||
@@ -1087,7 +1052,7 @@ func buildChannelModerations(channelType string, memberRole *model.Role, guestRo
|
||||
func (a *App) UpdateChannelMemberRoles(channelID string, userID string, newRoles string) (*model.ChannelMember, *model.AppError) {
|
||||
var member *model.ChannelMember
|
||||
var err *model.AppError
|
||||
if member, err = a.GetChannelMember(channelID, userID); err != nil {
|
||||
if member, err = a.GetChannelMember(context.Background(), channelID, userID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1144,7 +1109,7 @@ func (a *App) UpdateChannelMemberRoles(channelID string, userID string, newRoles
|
||||
}
|
||||
|
||||
func (a *App) UpdateChannelMemberSchemeRoles(channelID string, userID string, isSchemeGuest bool, isSchemeUser bool, isSchemeAdmin bool) (*model.ChannelMember, *model.AppError) {
|
||||
member, err := a.GetChannelMember(channelID, userID)
|
||||
member, err := a.GetChannelMember(context.Background(), channelID, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1168,7 +1133,7 @@ func (a *App) UpdateChannelMemberSchemeRoles(channelID string, userID string, is
|
||||
func (a *App) UpdateChannelMemberNotifyProps(data map[string]string, channelID string, userID string) (*model.ChannelMember, *model.AppError) {
|
||||
var member *model.ChannelMember
|
||||
var err *model.AppError
|
||||
if member, err = a.GetChannelMember(channelID, userID); err != nil {
|
||||
if member, err = a.GetChannelMember(context.Background(), channelID, userID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1334,7 +1299,7 @@ func (a *App) addUserToChannel(user *model.User, channel *model.Channel) (*model
|
||||
return nil, model.NewAppError("AddUserToChannel", "api.channel.add_user_to_channel.type.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
channelMember, nErr := a.Srv().Store.Channel().GetMember(channel.Id, user.Id)
|
||||
channelMember, nErr := a.Srv().Store.Channel().GetMember(context.Background(), channel.Id, user.Id)
|
||||
if nErr != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
if !errors.As(nErr, &nfErr) {
|
||||
@@ -1375,7 +1340,6 @@ func (a *App) addUserToChannel(user *model.User, channel *model.Channel) (*model
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("AddUserToChannel", "api.channel.add_user.to.channel.failed.app_error", nil, fmt.Sprintf("failed to add member: user_id: %s, channel_id:%s", user.Id, channel.Id), http.StatusInternalServerError)
|
||||
}
|
||||
a.WaitForChannelMembership(channel.Id, user.Id)
|
||||
|
||||
if nErr := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); nErr != nil {
|
||||
return nil, model.NewAppError("AddUserToChannel", "app.channel_member_history.log_join_event.internal_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
@@ -1417,7 +1381,7 @@ func (a *App) AddUserToChannel(user *model.User, channel *model.Channel) (*model
|
||||
}
|
||||
|
||||
func (a *App) AddChannelMember(userID string, channel *model.Channel, userRequestorId string, postRootId string) (*model.ChannelMember, *model.AppError) {
|
||||
if member, err := a.Srv().Store.Channel().GetMember(channel.Id, userID); err != nil {
|
||||
if member, err := a.Srv().Store.Channel().GetMember(context.Background(), channel.Id, userID); err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
if !errors.As(err, &nfErr) {
|
||||
return nil, model.NewAppError("AddChannelMember", "app.channel.get_member.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
@@ -1782,8 +1746,8 @@ func (a *App) GetPrivateChannelsForTeam(teamID string, offset int, limit int) (*
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (a *App) GetChannelMember(channelID string, userID string) (*model.ChannelMember, *model.AppError) {
|
||||
channelMember, err := a.Srv().Store.Channel().GetMember(channelID, userID)
|
||||
func (a *App) GetChannelMember(ctx context.Context, channelID string, userID string) (*model.ChannelMember, *model.AppError) {
|
||||
channelMember, err := a.Srv().Store.Channel().GetMember(ctx, channelID, userID)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
@@ -1921,7 +1885,7 @@ func (a *App) JoinChannel(channel *model.Channel, userID string) *model.AppError
|
||||
close(userChan)
|
||||
}()
|
||||
go func() {
|
||||
member, err := a.Srv().Store.Channel().GetMember(channel.Id, userID)
|
||||
member, err := a.Srv().Store.Channel().GetMember(context.Background(), channel.Id, userID)
|
||||
memberChan <- store.StoreResult{Data: member, NErr: err}
|
||||
close(memberChan)
|
||||
}()
|
||||
@@ -2215,7 +2179,7 @@ func (a *App) removeUserFromChannel(userIDToRemove string, removerUserId string,
|
||||
}
|
||||
}
|
||||
|
||||
cm, err := a.GetChannelMember(channel.Id, userIDToRemove)
|
||||
cm, err := a.GetChannelMember(context.Background(), channel.Id, userIDToRemove)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -2558,7 +2522,7 @@ func (a *App) MarkChannelsAsViewed(channelIDs []string, userID string, currentSe
|
||||
continue
|
||||
}
|
||||
|
||||
member, err := a.Srv().Store.Channel().GetMember(channelID, userID)
|
||||
member, err := a.Srv().Store.Channel().GetMember(context.Background(), channelID, userID)
|
||||
if err != nil {
|
||||
mlog.Warn("Failed to get membership", mlog.Err(err))
|
||||
continue
|
||||
@@ -2846,7 +2810,7 @@ func (a *App) GetPinnedPosts(channelID string) (*model.PostList, *model.AppError
|
||||
}
|
||||
|
||||
func (a *App) ToggleMuteChannel(channelID, userID string) (*model.ChannelMember, *model.AppError) {
|
||||
member, nErr := a.Srv().Store.Channel().GetMember(channelID, userID)
|
||||
member, nErr := a.Srv().Store.Channel().GetMember(context.Background(), channelID, userID)
|
||||
if nErr != nil {
|
||||
var appErr *model.AppError
|
||||
var nfErr *store.ErrNotFound
|
||||
@@ -3029,8 +2993,8 @@ func (a *App) ClearChannelMembersCache(channelID string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) GetMemberCountsByGroup(channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, *model.AppError) {
|
||||
channelMemberCounts, err := a.Srv().Store.Channel().GetMemberCountsByGroup(channelID, includeTimezones)
|
||||
func (a *App) GetMemberCountsByGroup(ctx context.Context, channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, *model.AppError) {
|
||||
channelMemberCounts, err := a.Srv().Store.Channel().GetMemberCountsByGroup(ctx, channelID, includeTimezones)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetMemberCountsByGroup", "app.channel.get_member_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -168,10 +169,10 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
assert.True(t, updated[0].Muted)
|
||||
|
||||
// Confirm that the channels are now muted
|
||||
member1, err := th.App.GetChannelMember(channel1.Id, th.BasicUser.Id)
|
||||
member1, err := th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member1.IsChannelMuted())
|
||||
member2, err := th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
|
||||
member2, err := th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member2.IsChannelMuted())
|
||||
|
||||
@@ -189,10 +190,10 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
assert.False(t, updated[0].Muted)
|
||||
|
||||
// Confirm that the channels are now unmuted
|
||||
member1, err = th.App.GetChannelMember(channel1.Id, th.BasicUser.Id)
|
||||
member1, err = th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member1.IsChannelMuted())
|
||||
member2, err = th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
|
||||
member2, err = th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member2.IsChannelMuted())
|
||||
})
|
||||
@@ -250,10 +251,10 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// Confirm that the channels are now muted
|
||||
member1, err := th.App.GetChannelMember(channel1.Id, th.BasicUser.Id)
|
||||
member1, err := th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member1.IsChannelMuted())
|
||||
member2, err := th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
|
||||
member2, err := th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member2.IsChannelMuted())
|
||||
|
||||
@@ -279,10 +280,10 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// Confirm that the channels are now unmuted
|
||||
member1, err = th.App.GetChannelMember(channel1.Id, th.BasicUser.Id)
|
||||
member1, err = th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member1.IsChannelMuted())
|
||||
member2, err = th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
|
||||
member2, err = th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member2.IsChannelMuted())
|
||||
})
|
||||
@@ -340,10 +341,10 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// Confirm that the channels are still unmuted
|
||||
member1, err := th.App.GetChannelMember(channel1.Id, th.BasicUser.Id)
|
||||
member1, err := th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member1.IsChannelMuted())
|
||||
member2, err := th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
|
||||
member2, err := th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member2.IsChannelMuted())
|
||||
|
||||
@@ -375,10 +376,10 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// Confirm that the channels are still muted
|
||||
member1, err = th.App.GetChannelMember(channel1.Id, th.BasicUser.Id)
|
||||
member1, err = th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member1.IsChannelMuted())
|
||||
member2, err = th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
|
||||
member2, err = th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member2.IsChannelMuted())
|
||||
})
|
||||
@@ -436,10 +437,10 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// Confirm that the channels are still unmuted
|
||||
member1, err := th.App.GetChannelMember(channel1.Id, th.BasicUser.Id)
|
||||
member1, err := th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member1.IsChannelMuted())
|
||||
member2, err := th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
|
||||
member2, err := th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member2.IsChannelMuted())
|
||||
|
||||
@@ -471,10 +472,10 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// Confirm that the channels are still muted
|
||||
member1, err = th.App.GetChannelMember(channel1.Id, th.BasicUser.Id)
|
||||
member1, err = th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member1.IsChannelMuted())
|
||||
member2, err = th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
|
||||
member2, err = th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member2.IsChannelMuted())
|
||||
})
|
||||
|
||||
@@ -337,7 +337,7 @@ func TestJoinDefaultChannelsExperimentalDefaultChannels(t *testing.T) {
|
||||
channel, err := th.App.GetChannelByName(channelName, th.BasicTeam.Id, false)
|
||||
require.Nil(t, err, "Expected nil, didn't receive nil")
|
||||
|
||||
member, err := th.App.GetChannelMember(channel.Id, user.Id)
|
||||
member, err := th.App.GetChannelMember(context.Background(), channel.Id, user.Id)
|
||||
|
||||
require.NotNil(t, member, "Expected member object, got nil")
|
||||
require.Nil(t, err, "Expected nil object, didn't receive nil")
|
||||
@@ -526,14 +526,14 @@ func TestLeaveDefaultChannel(t *testing.T) {
|
||||
err = th.App.LeaveChannel(townSquare.Id, th.BasicUser.Id)
|
||||
assert.NotNil(t, err, "It should fail to remove a regular user from the default channel")
|
||||
assert.Equal(t, err.Id, "api.channel.remove.default.app_error")
|
||||
_, err = th.App.GetChannelMember(townSquare.Id, th.BasicUser.Id)
|
||||
_, err = th.App.GetChannelMember(context.Background(), townSquare.Id, th.BasicUser.Id)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
t.Run("Guest leaves the default channel", func(t *testing.T) {
|
||||
err = th.App.LeaveChannel(townSquare.Id, guest.Id)
|
||||
assert.Nil(t, err, "It should allow to remove a guest user from the default channel")
|
||||
_, err = th.App.GetChannelMember(townSquare.Id, guest.Id)
|
||||
_, err = th.App.GetChannelMember(context.Background(), townSquare.Id, guest.Id)
|
||||
assert.NotNil(t, err)
|
||||
})
|
||||
}
|
||||
@@ -560,7 +560,7 @@ func TestLeaveLastChannel(t *testing.T) {
|
||||
t.Run("Guest leaves last channel", func(t *testing.T) {
|
||||
err = th.App.LeaveChannel(th.BasicChannel.Id, guest.Id)
|
||||
assert.Nil(t, err, "It should allow to remove a guest user from the default channel")
|
||||
_, err = th.App.GetChannelMember(th.BasicChannel.Id, guest.Id)
|
||||
_, err = th.App.GetChannelMember(context.Background(), th.BasicChannel.Id, guest.Id)
|
||||
assert.NotNil(t, err)
|
||||
_, err = th.App.GetTeamMember(th.BasicTeam.Id, guest.Id)
|
||||
assert.Nil(t, err, "It should remove the team membership")
|
||||
@@ -636,11 +636,11 @@ func TestSetChannelsMuted(t *testing.T) {
|
||||
th.AddUserToChannel(th.BasicUser, channel2)
|
||||
|
||||
// Ensure that both channels start unmuted
|
||||
member1, err := th.App.GetChannelMember(channel1.Id, th.BasicUser.Id)
|
||||
member1, err := th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
require.False(t, member1.IsChannelMuted())
|
||||
|
||||
member2, err := th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
|
||||
member2, err := th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
require.False(t, member2.IsChannelMuted())
|
||||
|
||||
@@ -651,11 +651,11 @@ func TestSetChannelsMuted(t *testing.T) {
|
||||
assert.True(t, updated[1].IsChannelMuted())
|
||||
|
||||
// Verify that the channels are muted in the database
|
||||
member1, err = th.App.GetChannelMember(channel1.Id, th.BasicUser.Id)
|
||||
member1, err = th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
require.True(t, member1.IsChannelMuted())
|
||||
|
||||
member2, err = th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
|
||||
member2, err = th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
require.True(t, member2.IsChannelMuted())
|
||||
|
||||
@@ -666,11 +666,11 @@ func TestSetChannelsMuted(t *testing.T) {
|
||||
assert.False(t, updated[1].IsChannelMuted())
|
||||
|
||||
// Verify that the channels are muted in the database
|
||||
member1, err = th.App.GetChannelMember(channel1.Id, th.BasicUser.Id)
|
||||
member1, err = th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
require.False(t, member1.IsChannelMuted())
|
||||
|
||||
member2, err = th.App.GetChannelMember(channel2.Id, th.BasicUser.Id)
|
||||
member2, err = th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
require.False(t, member2.IsChannelMuted())
|
||||
})
|
||||
@@ -1411,7 +1411,7 @@ func TestAddUserToChannel(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// verify user was added as a non-admin
|
||||
cm1, err := th.App.GetChannelMember(th.BasicChannel.Id, ruser1.Id)
|
||||
cm1, err := th.App.GetChannelMember(context.Background(), th.BasicChannel.Id, ruser1.Id)
|
||||
require.Nil(t, err)
|
||||
require.False(t, cm1.SchemeAdmin)
|
||||
|
||||
@@ -1435,7 +1435,7 @@ func TestAddUserToChannel(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// verify user was added as an admin
|
||||
cm2, err := th.App.GetChannelMember(th.BasicChannel.Id, ruser2.Id)
|
||||
cm2, err := th.App.GetChannelMember(context.Background(), th.BasicChannel.Id, ruser2.Id)
|
||||
require.Nil(t, err)
|
||||
require.True(t, cm2.SchemeAdmin)
|
||||
|
||||
@@ -1945,7 +1945,7 @@ func TestMarkChannelsAsViewedPanic(t *testing.T) {
|
||||
mockUserStore.On("Get", context.Background(), "userID").Return(nil, model.NewAppError("SqlUserStore.Get", "app.user.get.app_error", nil, "user_id=userID", http.StatusInternalServerError))
|
||||
mockChannelStore := mocks.ChannelStore{}
|
||||
mockChannelStore.On("Get", "channelID", true).Return(&model.Channel{}, nil)
|
||||
mockChannelStore.On("GetMember", "channelID", "userID").Return(&model.ChannelMember{
|
||||
mockChannelStore.On("GetMember", context.Background(), "channelID", "userID").Return(&model.ChannelMember{
|
||||
NotifyProps: model.StringMap{
|
||||
model.PUSH_NOTIFY_PROP: model.CHANNEL_NOTIFY_DEFAULT,
|
||||
}}, nil)
|
||||
@@ -1996,9 +1996,9 @@ func TestGetMemberCountsByGroup(t *testing.T) {
|
||||
ChannelMemberTimezonesCount: int64(i),
|
||||
})
|
||||
}
|
||||
mockChannelStore.On("GetMemberCountsByGroup", "channelID", true).Return(cmc, nil)
|
||||
mockChannelStore.On("GetMemberCountsByGroup", context.Background(), "channelID", true).Return(cmc, nil)
|
||||
mockStore.On("Channel").Return(&mockChannelStore)
|
||||
resp, err := th.App.GetMemberCountsByGroup("channelID", true)
|
||||
resp, err := th.App.GetMemberCountsByGroup(context.Background(), "channelID", true)
|
||||
require.Nil(t, err)
|
||||
require.ElementsMatch(t, cmc, resp)
|
||||
}
|
||||
|
||||
@@ -571,7 +571,7 @@ func (a *App) HandleCommandResponsePost(command *model.Command, args *model.Comm
|
||||
post.SetProps(response.Props)
|
||||
|
||||
if response.ChannelId != "" {
|
||||
_, err := a.GetChannelMember(response.ChannelId, args.UserId)
|
||||
_, err := a.GetChannelMember(context.Background(), response.ChannelId, args.UserId)
|
||||
if err != nil {
|
||||
err = model.NewAppError("HandleCommandResponsePost", "api.command.command_post.forbidden.app_error", nil, err.Error(), http.StatusForbidden)
|
||||
return nil, err
|
||||
|
||||
15
app/context.go
Обычный файл
15
app/context.go
Обычный файл
@@ -0,0 +1,15 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/store/sqlstore"
|
||||
)
|
||||
|
||||
// WithMaster adds the context value that master DB should be selected for this request.
|
||||
func WithMaster(ctx context.Context) context.Context {
|
||||
return sqlstore.WithMaster(ctx)
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -89,7 +90,7 @@ func TestCheckPendingNotifications(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
channelMember, err := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
channelMember, err := th.App.Srv().Store.Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
channelMember.LastViewedAt = 9999999
|
||||
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)
|
||||
@@ -110,7 +111,7 @@ func TestCheckPendingNotifications(t *testing.T) {
|
||||
require.Len(t, job.pendingNotifications[th.BasicUser.Id], 1, "shouldn't have sent queued post")
|
||||
|
||||
// test that notifications are cleared if the user has acted
|
||||
channelMember, err = th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
channelMember, err = th.App.Srv().Store.Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
channelMember.LastViewedAt = 10001000
|
||||
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)
|
||||
@@ -208,7 +209,7 @@ func TestCheckPendingNotificationsDefaultInterval(t *testing.T) {
|
||||
job := NewEmailBatchingJob(th.Server.EmailService, 128)
|
||||
|
||||
// bypasses recent user activity check
|
||||
channelMember, err := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
channelMember, err := th.App.Srv().Store.Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
channelMember.LastViewedAt = 9999000
|
||||
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)
|
||||
@@ -246,7 +247,7 @@ func TestCheckPendingNotificationsCantParseInterval(t *testing.T) {
|
||||
job := NewEmailBatchingJob(th.Server.EmailService, 128)
|
||||
|
||||
// bypasses recent user activity check
|
||||
channelMember, err := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
channelMember, err := th.App.Srv().Store.Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
channelMember.LastViewedAt = 9999000
|
||||
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)
|
||||
|
||||
@@ -1084,7 +1084,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
require.Equal(t, channelMemberCount+1, cmc, "Number of channel members not as expected")
|
||||
|
||||
// Check channel member properties.
|
||||
channelMember, appErr := th.App.GetChannelMember(channel.Id, user.Id)
|
||||
channelMember, appErr := th.App.GetChannelMember(context.Background(), channel.Id, user.Id)
|
||||
require.Nil(t, appErr, "Failed to get channel member from database.")
|
||||
assert.Equal(t, "channel_user", channelMember.Roles)
|
||||
assert.Equal(t, "default", channelMember.NotifyProps[model.DESKTOP_NOTIFY_PROP])
|
||||
@@ -1119,7 +1119,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
require.Nil(t, appErr, "Failed to get team member from database.")
|
||||
require.Equal(t, "team_user team_admin", teamMember.Roles)
|
||||
|
||||
channelMember, appErr = th.App.GetChannelMember(channel.Id, user.Id)
|
||||
channelMember, appErr = th.App.GetChannelMember(context.Background(), channel.Id, user.Id)
|
||||
require.Nil(t, appErr, "Failed to get channel member Desktop from database.")
|
||||
assert.Equal(t, "channel_user channel_admin", channelMember.Roles)
|
||||
assert.Equal(t, model.USER_NOTIFY_MENTION, channelMember.NotifyProps[model.DESKTOP_NOTIFY_PROP])
|
||||
@@ -1435,7 +1435,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
assert.False(t, teamMember.SchemeGuest)
|
||||
assert.Equal(t, "", teamMember.ExplicitRoles)
|
||||
|
||||
channelMember, appErr = th.App.GetChannelMember(channel.Id, user.Id)
|
||||
channelMember, appErr = th.App.GetChannelMember(context.Background(), channel.Id, user.Id)
|
||||
require.Nil(t, appErr, "Failed to get the channel member")
|
||||
|
||||
assert.True(t, channelMember.SchemeAdmin)
|
||||
@@ -1477,7 +1477,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
assert.False(t, teamMember.SchemeGuest)
|
||||
assert.Equal(t, "", teamMember.ExplicitRoles)
|
||||
|
||||
channelMember, appErr = th.App.GetChannelMember(channel.Id, user.Id)
|
||||
channelMember, appErr = th.App.GetChannelMember(context.Background(), channel.Id, user.Id)
|
||||
require.Nil(t, appErr, "Failed to get the channel member")
|
||||
|
||||
assert.False(t, teamMember.SchemeAdmin)
|
||||
@@ -1519,7 +1519,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
assert.True(t, teamMember.SchemeGuest)
|
||||
assert.Equal(t, "", teamMember.ExplicitRoles)
|
||||
|
||||
channelMember, appErr = th.App.GetChannelMember(channel.Id, user.Id)
|
||||
channelMember, appErr = th.App.GetChannelMember(context.Background(), channel.Id, user.Id)
|
||||
require.Nil(t, appErr, "Failed to get the channel member")
|
||||
|
||||
assert.False(t, teamMember.SchemeAdmin)
|
||||
|
||||
@@ -4697,7 +4697,7 @@ func (a *OpenTracingAppLayer) GetChannelGuestCount(channelID string) (int64, *mo
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetChannelMember(channelID string, userID string) (*model.ChannelMember, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetChannelMember(ctx context.Context, channelID string, userID string) (*model.ChannelMember, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetChannelMember")
|
||||
|
||||
@@ -4709,7 +4709,7 @@ func (a *OpenTracingAppLayer) GetChannelMember(channelID string, userID string)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetChannelMember(channelID, userID)
|
||||
resultVar0, resultVar1 := a.app.GetChannelMember(ctx, channelID, userID)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -6366,7 +6366,7 @@ func (a *OpenTracingAppLayer) GetMarketplacePlugins(filter *model.MarketplacePlu
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetMemberCountsByGroup(channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetMemberCountsByGroup(ctx context.Context, channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetMemberCountsByGroup")
|
||||
|
||||
@@ -6378,7 +6378,7 @@ func (a *OpenTracingAppLayer) GetMemberCountsByGroup(channelID string, includeTi
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetMemberCountsByGroup(channelID, includeTimezones)
|
||||
resultVar0, resultVar1 := a.app.GetMemberCountsByGroup(ctx, channelID, includeTimezones)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -16240,21 +16240,6 @@ func (a *OpenTracingAppLayer) ViewChannel(view *model.ChannelView, userID string
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) WaitForChannelMembership(channelID string, userID string) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.WaitForChannelMembership")
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
a.app.Srv().Store.SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
a.app.WaitForChannelMembership(channelID, userID)
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) WriteFile(fr io.Reader, path string) (int64, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.WriteFile")
|
||||
|
||||
@@ -5,6 +5,7 @@ package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -501,7 +502,7 @@ func (api *PluginAPI) AddUserToChannel(channelID, userID, asUserId string) (*mod
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetChannelMember(channelID, userID string) (*model.ChannelMember, *model.AppError) {
|
||||
return api.app.GetChannelMember(channelID, userID)
|
||||
return api.app.GetChannelMember(context.Background(), channelID, userID)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetChannelMembers(channelID string, page, perPage int) (*model.ChannelMembers, *model.AppError) {
|
||||
|
||||
@@ -974,7 +974,7 @@ func (a *App) AddCursorIdsForPostList(originalList *model.PostList, afterPost, b
|
||||
func (a *App) GetPostsForChannelAroundLastUnread(channelID, userID string, limitBefore, limitAfter int, skipFetchThreads bool, collapsedThreads, collapsedThreadsExtended bool) (*model.PostList, *model.AppError) {
|
||||
var member *model.ChannelMember
|
||||
var err *model.AppError
|
||||
if member, err = a.GetChannelMember(channelID, userID); err != nil {
|
||||
if member, err = a.GetChannelMember(context.Background(), channelID, userID); err != nil {
|
||||
return nil, err
|
||||
} else if member.LastViewedAt == 0 {
|
||||
return model.NewPostList(), nil
|
||||
@@ -1419,7 +1419,7 @@ func (a *App) countMentionsFromPost(user *model.User, post *model.Post) (int, *m
|
||||
return count, nil
|
||||
}
|
||||
|
||||
channelMember, err := a.GetChannelMember(channel.Id, user.Id)
|
||||
channelMember, err := a.GetChannelMember(context.Background(), channel.Id, user.Id)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -855,14 +856,14 @@ func TestCreatePostAsUser(t *testing.T) {
|
||||
UserId: th.BasicUser.Id,
|
||||
}
|
||||
|
||||
channelMemberBefore, err := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
channelMemberBefore, err := th.App.Srv().Store.Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
_, appErr := th.App.CreatePostAsUser(post, "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
channelMemberAfter, err := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
channelMemberAfter, err := th.App.Srv().Store.Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Greater(t, channelMemberAfter.LastViewedAt, channelMemberBefore.LastViewedAt)
|
||||
@@ -879,14 +880,14 @@ func TestCreatePostAsUser(t *testing.T) {
|
||||
}
|
||||
post.AddProp("from_webhook", "true")
|
||||
|
||||
channelMemberBefore, err := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
channelMemberBefore, err := th.App.Srv().Store.Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
_, appErr := th.App.CreatePostAsUser(post, "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
channelMemberAfter, err := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
channelMemberAfter, err := th.App.Srv().Store.Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, channelMemberAfter.LastViewedAt, channelMemberBefore.LastViewedAt)
|
||||
@@ -910,14 +911,14 @@ func TestCreatePostAsUser(t *testing.T) {
|
||||
UserId: bot.UserId,
|
||||
}
|
||||
|
||||
channelMemberBefore, nErr := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
channelMemberBefore, nErr := th.App.Srv().Store.Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
_, appErr = th.App.CreatePostAsUser(post, "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
channelMemberAfter, nErr := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
channelMemberAfter, nErr := th.App.Srv().Store.Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
require.Equal(t, channelMemberAfter.LastViewedAt, channelMemberBefore.LastViewedAt)
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -113,7 +114,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("error retrieving team member: %s", err.Error())
|
||||
}
|
||||
_, err = th.App.GetChannelMember(practiceChannel.Id, singer1.Id)
|
||||
_, err = th.App.GetChannelMember(context.Background(), practiceChannel.Id, singer1.Id)
|
||||
if err != nil {
|
||||
t.Errorf("error retrieving channel member: %s", err.Error())
|
||||
}
|
||||
@@ -142,7 +143,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
t.Errorf("wrong error: %s", err.Id)
|
||||
}
|
||||
|
||||
_, err = th.App.GetChannelMember(experimentsChannel.Id, scientist1.Id)
|
||||
_, err = th.App.GetChannelMember(context.Background(), experimentsChannel.Id, scientist1.Id)
|
||||
if err.Id != "app.channel.get_member.missing.app_error" {
|
||||
t.Errorf("wrong error: %s", err.Id)
|
||||
}
|
||||
@@ -184,7 +185,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
t.Errorf("error retrieving team member: %s", err.Error())
|
||||
}
|
||||
|
||||
_, err = th.App.GetChannelMember(experimentsChannel.Id, scientist1.Id)
|
||||
_, err = th.App.GetChannelMember(context.Background(), experimentsChannel.Id, scientist1.Id)
|
||||
if err.Id != "app.channel.get_member.missing.app_error" {
|
||||
t.Errorf("wrong error: %s", err.Id)
|
||||
}
|
||||
@@ -255,7 +256,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
t.Error("expected team member to remain deleted")
|
||||
}
|
||||
|
||||
_, err = th.App.GetChannelMember(practiceChannel.Id, singer1.Id)
|
||||
_, err = th.App.GetChannelMember(context.Background(), practiceChannel.Id, singer1.Id)
|
||||
if err == nil {
|
||||
t.Error("Expected channel member to remain deleted")
|
||||
}
|
||||
@@ -308,7 +309,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
t.Errorf("failed to populate syncables: %s", pErr.Error())
|
||||
}
|
||||
|
||||
_, err = th.App.GetChannelMember(experimentsChannel.Id, scientist1.Id)
|
||||
_, err = th.App.GetChannelMember(context.Background(), experimentsChannel.Id, scientist1.Id)
|
||||
if err == nil {
|
||||
t.Error("Expected channel member to remain deleted")
|
||||
}
|
||||
@@ -325,7 +326,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
}
|
||||
|
||||
// Channel member is re-added.
|
||||
_, err = th.App.GetChannelMember(experimentsChannel.Id, scientist1.Id)
|
||||
_, err = th.App.GetChannelMember(context.Background(), experimentsChannel.Id, scientist1.Id)
|
||||
if err != nil {
|
||||
t.Errorf("expected channel member: %s", err.Error())
|
||||
}
|
||||
@@ -501,7 +502,7 @@ func TestSyncSyncableRoles(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
require.True(t, tm.SchemeAdmin)
|
||||
|
||||
cm, err := th.App.GetChannelMember(channel.Id, user.Id)
|
||||
cm, err := th.App.GetChannelMember(context.Background(), channel.Id, user.Id)
|
||||
require.Nil(t, err)
|
||||
require.True(t, cm.SchemeAdmin)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"image"
|
||||
@@ -1145,7 +1146,7 @@ func TestPromoteGuestToUser(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, teamMember.SchemeGuest)
|
||||
assert.True(t, teamMember.SchemeUser)
|
||||
channelMember, err = th.App.GetChannelMember(th.BasicChannel.Id, guest.Id)
|
||||
channelMember, err = th.App.GetChannelMember(context.Background(), th.BasicChannel.Id, guest.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, teamMember.SchemeGuest)
|
||||
assert.True(t, teamMember.SchemeUser)
|
||||
@@ -1177,7 +1178,7 @@ func TestPromoteGuestToUser(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, teamMember.SchemeGuest)
|
||||
assert.True(t, teamMember.SchemeUser)
|
||||
channelMember, err = th.App.GetChannelMember(th.BasicChannel.Id, guest.Id)
|
||||
channelMember, err = th.App.GetChannelMember(context.Background(), th.BasicChannel.Id, guest.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, teamMember.SchemeGuest)
|
||||
assert.True(t, teamMember.SchemeUser)
|
||||
@@ -1308,7 +1309,7 @@ func TestDemoteUserToGuest(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, teamMember.SchemeUser)
|
||||
assert.True(t, teamMember.SchemeGuest)
|
||||
channelMember, err = th.App.GetChannelMember(th.BasicChannel.Id, user.Id)
|
||||
channelMember, err = th.App.GetChannelMember(context.Background(), th.BasicChannel.Id, user.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, teamMember.SchemeUser)
|
||||
assert.True(t, teamMember.SchemeGuest)
|
||||
@@ -1340,7 +1341,7 @@ func TestDemoteUserToGuest(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, teamMember.SchemeUser)
|
||||
assert.True(t, teamMember.SchemeGuest)
|
||||
channelMember, err = th.App.GetChannelMember(th.BasicChannel.Id, user.Id)
|
||||
channelMember, err = th.App.GetChannelMember(context.Background(), th.BasicChannel.Id, user.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, teamMember.SchemeUser)
|
||||
assert.True(t, teamMember.SchemeGuest)
|
||||
@@ -1370,7 +1371,7 @@ func TestDemoteUserToGuest(t *testing.T) {
|
||||
th.AddUserToChannel(user, channel)
|
||||
th.App.UpdateChannelMemberSchemeRoles(channel.Id, user.Id, false, true, true)
|
||||
|
||||
channelMember, err := th.App.GetChannelMember(channel.Id, user.Id)
|
||||
channelMember, err := th.App.GetChannelMember(context.Background(), channel.Id, user.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.True(t, channelMember.SchemeUser)
|
||||
assert.True(t, channelMember.SchemeAdmin)
|
||||
@@ -1389,7 +1390,7 @@ func TestDemoteUserToGuest(t *testing.T) {
|
||||
assert.False(t, teamMember.SchemeAdmin)
|
||||
assert.True(t, teamMember.SchemeGuest)
|
||||
|
||||
channelMember, err = th.App.GetChannelMember(channel.Id, user.Id)
|
||||
channelMember, err = th.App.GetChannelMember(context.Background(), channel.Id, user.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, channelMember.SchemeUser)
|
||||
assert.False(t, channelMember.SchemeAdmin)
|
||||
|
||||
Ссылка в новой задаче
Block a user