MM-45193 Use context for channel logging (#20575)

Этот коммит содержится в:
Tim Scheuermann
2022-07-14 12:01:29 +03:00
коммит произвёл GitHub
родитель 5f4da3f308
Коммит 6dc897b04f
122 изменённых файлов: 2133 добавлений и 2082 удалений

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

@@ -184,7 +184,7 @@ func TestUpdateChannel(t *testing.T) {
require.Equal(t, private.Purpose, newPrivateChannel.Purpose, "Update failed for Purpose in private channel")
//Test updating default channel's name and returns error
defaultChannel, _ := th.App.GetChannelByName(model.DefaultChannelName, team.Id, false)
defaultChannel, _ := th.App.GetChannelByName(th.Context, model.DefaultChannelName, team.Id, false)
defaultChannel.Name = "testing"
_, resp, err = client.UpdateChannel(defaultChannel)
require.Error(t, err)
@@ -286,7 +286,7 @@ func TestPatchChannel(t *testing.T) {
require.Equal(t, oldName, channel.Name, "should not have updated")
//Test updating default channel's name and returns error
defaultChannel, _ := th.App.GetChannelByName(model.DefaultChannelName, team.Id, false)
defaultChannel, _ := th.App.GetChannelByName(th.Context, model.DefaultChannelName, team.Id, false)
defaultChannelPatch := &model.ChannelPatch{
Name: new(string),
}
@@ -560,7 +560,7 @@ func TestCreateGroupChannel(t *testing.T) {
require.NotNil(t, rgc, "should have created a group channel")
require.Equal(t, model.ChannelTypeGroup, rgc.Type, "should have created a channel of group type")
m, _ := th.App.GetChannelMembersPage(rgc.Id, 0, 10)
m, _ := th.App.GetChannelMembersPage(th.Context, rgc.Id, 0, 10)
require.Len(t, m, 3, "should have 3 channel members")
// saving duplicate group channel
@@ -568,7 +568,7 @@ func TestCreateGroupChannel(t *testing.T) {
require.NoError(t, err)
require.Equal(t, rgc.Id, rgc2.Id, "should have returned existing channel")
m2, _ := th.App.GetChannelMembersPage(rgc2.Id, 0, 10)
m2, _ := th.App.GetChannelMembersPage(th.Context, rgc2.Id, 0, 10)
require.Equal(t, m, m2)
_, resp, err = client.CreateGroupChannel([]string{user2.Id})
@@ -1030,7 +1030,7 @@ func TestGetChannelsForTeamForUser(t *testing.T) {
CreatorId: th.BasicUser.Id,
}
th.App.CreateChannel(th.Context, testChannel, true)
defer th.App.PermanentDeleteChannel(testChannel)
defer th.App.PermanentDeleteChannel(th.Context, testChannel)
channels, _, err := client.GetChannelsForTeamForUser(th.BasicTeam.Id, th.BasicUser.Id, false, "")
require.NoError(t, err)
assert.Equal(t, 6, len(channels))
@@ -1063,8 +1063,8 @@ func TestGetChannelsForUser(t *testing.T) {
ch1 := th.CreateChannelWithClientAndTeam(client, model.ChannelTypeOpen, myTeam.Id)
ch2 := th.CreateChannelWithClientAndTeam(client, model.ChannelTypePrivate, myTeam.Id)
th.LinkUserToTeam(th.BasicUser, myTeam)
th.App.AddUserToChannel(th.BasicUser, ch1, false)
th.App.AddUserToChannel(th.BasicUser, ch2, false)
th.App.AddUserToChannel(th.Context, th.BasicUser, ch1, false)
th.App.AddUserToChannel(th.Context, th.BasicUser, ch2, false)
channels, _, err := client.GetChannelsForUserWithLastDeleteAt(th.BasicUser.Id, 0)
require.NoError(t, err)
@@ -1096,7 +1096,7 @@ func TestGetChannelsForUser(t *testing.T) {
// Creating some more channels to be exactly 100 to test page size boundaries.
for i := 0; i < 91; i++ {
ch1 = th.CreateChannelWithClientAndTeam(client, model.ChannelTypeOpen, myTeam.Id)
th.App.AddUserToChannel(th.BasicUser, ch1, false)
th.App.AddUserToChannel(th.Context, th.BasicUser, ch1, false)
}
channels, _, err = client.GetChannelsForUserWithLastDeleteAt(th.BasicUser.Id, 0)
@@ -1790,7 +1790,7 @@ func TestDeleteChannel(t *testing.T) {
_, err := client.DeleteChannel(publicChannel1.Id)
require.NoError(t, err)
ch, appErr := th.App.GetChannel(publicChannel1.Id)
ch, appErr := th.App.GetChannel(th.Context, publicChannel1.Id)
require.Nilf(t, appErr, "Expected nil, Got %v", appErr)
require.True(t, ch.DeleteAt != 0, "should have returned one with a populated DeleteAt.")
@@ -1805,13 +1805,13 @@ func TestDeleteChannel(t *testing.T) {
// successful delete of channel with multiple members
publicChannel3 := th.CreatePublicChannel()
th.App.AddUserToChannel(user, publicChannel3, false)
th.App.AddUserToChannel(user2, publicChannel3, false)
th.App.AddUserToChannel(th.Context, user, publicChannel3, false)
th.App.AddUserToChannel(th.Context, user2, publicChannel3, false)
_, err = client.DeleteChannel(publicChannel3.Id)
require.NoError(t, err)
// default channel cannot be deleted.
defaultChannel, _ := th.App.GetChannelByName(model.DefaultChannelName, team.Id, false)
defaultChannel, _ := th.App.GetChannelByName(th.Context, model.DefaultChannelName, team.Id, false)
resp, err = client.DeleteChannel(defaultChannel.Id)
require.Error(t, err)
CheckBadRequestStatus(t, resp)
@@ -1885,9 +1885,9 @@ func TestDeleteChannel2(t *testing.T) {
// channels created by SystemAdmin
publicChannel6 := th.CreateChannelWithClient(th.SystemAdminClient, model.ChannelTypeOpen)
privateChannel7 := th.CreateChannelWithClient(th.SystemAdminClient, model.ChannelTypePrivate)
th.App.AddUserToChannel(user, publicChannel6, false)
th.App.AddUserToChannel(user, privateChannel7, false)
th.App.AddUserToChannel(user, privateChannel7, false)
th.App.AddUserToChannel(th.Context, user, publicChannel6, false)
th.App.AddUserToChannel(th.Context, user, privateChannel7, false)
th.App.AddUserToChannel(th.Context, user, privateChannel7, false)
// successful delete by user
_, err := client.DeleteChannel(publicChannel6.Id)
@@ -1905,9 +1905,9 @@ func TestDeleteChannel2(t *testing.T) {
// channels created by SystemAdmin
publicChannel6 = th.CreateChannelWithClient(th.SystemAdminClient, model.ChannelTypeOpen)
privateChannel7 = th.CreateChannelWithClient(th.SystemAdminClient, model.ChannelTypePrivate)
th.App.AddUserToChannel(user, publicChannel6, false)
th.App.AddUserToChannel(user, privateChannel7, false)
th.App.AddUserToChannel(user, privateChannel7, false)
th.App.AddUserToChannel(th.Context, user, publicChannel6, false)
th.App.AddUserToChannel(th.Context, user, privateChannel7, false)
th.App.AddUserToChannel(th.Context, user, privateChannel7, false)
// cannot delete by user
resp, err := client.DeleteChannel(publicChannel6.Id)
@@ -1975,7 +1975,7 @@ func TestPermanentDeleteChannel(t *testing.T) {
_, err := c.PermanentDeleteChannel(publicChannel.Id)
require.NoError(t, err)
_, appErr := th.App.GetChannel(publicChannel.Id)
_, appErr := th.App.GetChannel(th.Context, publicChannel.Id)
assert.NotNil(t, appErr)
resp, err := c.PermanentDeleteChannel("junk")
@@ -1988,7 +1988,7 @@ func TestUpdateChannelPrivacy(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
defaultChannel, _ := th.App.GetChannelByName(model.DefaultChannelName, th.BasicTeam.Id, false)
defaultChannel, _ := th.App.GetChannelByName(th.Context, model.DefaultChannelName, th.BasicTeam.Id, false)
type testTable []struct {
name string
@@ -2045,7 +2045,7 @@ func TestUpdateChannelPrivacy(t *testing.T) {
updatedChannel, _, err := client.UpdateChannelPrivacy(tc.channel.Id, tc.expectedPrivacy)
require.NoError(t, err)
assert.Equal(t, tc.expectedPrivacy, updatedChannel.Type)
updatedChannel, appErr := th.App.GetChannel(tc.channel.Id)
updatedChannel, appErr := th.App.GetChannel(th.Context, tc.channel.Id)
require.Nil(t, appErr)
assert.Equal(t, tc.expectedPrivacy, updatedChannel.Type)
})
@@ -2424,7 +2424,7 @@ func TestViewChannel(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "OK", viewResp.Status, "should have passed")
channel, _ := th.App.GetChannel(th.BasicChannel.Id)
channel, _ := th.App.GetChannel(th.Context, th.BasicChannel.Id)
require.Equal(t, channel.LastPostAt, viewResp.LastViewedAtTimes[channel.Id], "LastPostAt does not match returned LastViewedAt time")
@@ -2637,7 +2637,7 @@ func TestUpdateChannelRoles(t *testing.T) {
channel := th.CreatePublicChannel()
// Adds User 2 to the channel, making them a channel member by default.
th.App.AddUserToChannel(th.BasicUser2, channel, false)
th.App.AddUserToChannel(th.Context, th.BasicUser2, channel, false)
// User 1 promotes User 2
_, err := client.UpdateChannelRoles(channel.Id, th.BasicUser2.Id, ChannelAdmin)
@@ -2847,7 +2847,7 @@ func TestUpdateChannelNotifyProps(t *testing.T) {
_, err := client.UpdateChannelNotifyProps(th.BasicChannel.Id, th.BasicUser.Id, props)
require.NoError(t, err)
member, appErr := th.App.GetChannelMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
member, appErr := th.App.GetChannelMember(th.Context, th.BasicChannel.Id, th.BasicUser.Id)
require.Nil(t, appErr)
require.Equal(t, model.ChannelNotifyMention, member.NotifyProps[model.DesktopNotifyProp], "bad update")
require.Equal(t, model.ChannelMarkUnreadMention, member.NotifyProps[model.MarkUnreadNotifyProp], "bad update")
@@ -3039,7 +3039,7 @@ func TestAddChannelMember(t *testing.T) {
// Set a channel to group-constrained
privateChannel.GroupConstrained = model.NewBool(true)
_, appErr := th.App.UpdateChannel(privateChannel)
_, appErr := th.App.UpdateChannel(th.Context, privateChannel)
require.Nil(t, appErr)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
@@ -3266,9 +3266,9 @@ func TestRemoveChannelMember(t *testing.T) {
t.Run("success", func(t *testing.T) {
// Setup the system administrator to listen for websocket events from the channels.
th.LinkUserToTeam(th.SystemAdminUser, th.BasicTeam)
_, appErr := th.App.AddUserToChannel(th.SystemAdminUser, th.BasicChannel, false)
_, appErr := th.App.AddUserToChannel(th.Context, th.SystemAdminUser, th.BasicChannel, false)
require.Nil(t, appErr)
_, appErr = th.App.AddUserToChannel(th.SystemAdminUser, th.BasicChannel2, false)
_, appErr = th.App.AddUserToChannel(th.Context, th.SystemAdminUser, th.BasicChannel2, false)
require.Nil(t, appErr)
props := map[string]string{}
props[model.DesktopNotifyProp] = model.ChannelNotifyAll
@@ -3312,7 +3312,7 @@ func TestRemoveChannelMember(t *testing.T) {
}
}
th.App.AddUserToChannel(th.BasicUser2, th.BasicChannel, false)
th.App.AddUserToChannel(th.Context, th.BasicUser2, th.BasicChannel, false)
_, err2 = client.RemoveUserFromChannel(th.BasicChannel.Id, th.BasicUser2.Id)
require.NoError(t, err2)
@@ -3343,18 +3343,18 @@ func TestRemoveChannelMember(t *testing.T) {
// Leave deleted channel
th.LoginBasic()
deletedChannel := th.CreatePublicChannel()
th.App.AddUserToChannel(th.BasicUser, deletedChannel, false)
th.App.AddUserToChannel(th.BasicUser2, deletedChannel, false)
th.App.AddUserToChannel(th.Context, th.BasicUser, deletedChannel, false)
th.App.AddUserToChannel(th.Context, th.BasicUser2, deletedChannel, false)
deletedChannel.DeleteAt = 1
th.App.UpdateChannel(deletedChannel)
th.App.UpdateChannel(th.Context, deletedChannel)
_, err = client.RemoveUserFromChannel(deletedChannel.Id, th.BasicUser.Id)
require.NoError(t, err)
th.LoginBasic()
private := th.CreatePrivateChannel()
th.App.AddUserToChannel(th.BasicUser2, private, false)
th.App.AddUserToChannel(th.Context, th.BasicUser2, private, false)
_, err = client.RemoveUserFromChannel(private.Id, th.BasicUser2.Id)
require.NoError(t, err)
@@ -3365,7 +3365,7 @@ func TestRemoveChannelMember(t *testing.T) {
CheckForbiddenStatus(t, resp)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
th.App.AddUserToChannel(th.BasicUser, private, false)
th.App.AddUserToChannel(th.Context, th.BasicUser, private, false)
_, err = client.RemoveUserFromChannel(private.Id, th.BasicUser.Id)
require.NoError(t, err)
})
@@ -3421,7 +3421,7 @@ func TestRemoveChannelMember(t *testing.T) {
// If the channel is group-constrained the user cannot be removed
privateChannel.GroupConstrained = model.NewBool(true)
_, appErr := th.App.UpdateChannel(privateChannel)
_, appErr := th.App.UpdateChannel(th.Context, privateChannel)
require.Nil(t, appErr)
_, err = client.RemoveUserFromChannel(privateChannel.Id, user2.Id)
CheckErrorID(t, err, "api.channel.remove_member.group_constrained.app_error")
@@ -3913,7 +3913,7 @@ func TestChannelMembersMinusGroupMembers(t *testing.T) {
require.Nil(t, appErr)
channel.GroupConstrained = model.NewBool(true)
channel, appErr = th.App.UpdateChannel(channel)
channel, appErr = th.App.UpdateChannel(th.Context, channel)
require.Nil(t, appErr)
group1 := th.CreateGroup()
@@ -4056,7 +4056,7 @@ func TestGetChannelModerations(t *testing.T) {
t.Run("Returns value false and enabled true for permissions that are not present in channel scheme but present in team scheme", func(t *testing.T) {
scheme := th.SetupChannelScheme()
channel.SchemeId = &scheme.Id
_, appErr := th.App.UpdateChannelScheme(channel)
_, appErr := th.App.UpdateChannelScheme(th.Context, channel)
require.Nil(t, appErr)
th.RemovePermissionFromRole(model.PermissionCreatePost.Id, scheme.DefaultChannelGuestRole)
@@ -4081,7 +4081,7 @@ func TestGetChannelModerations(t *testing.T) {
scheme := th.SetupChannelScheme()
channel.SchemeId = &scheme.Id
th.App.UpdateChannelScheme(channel)
th.App.UpdateChannelScheme(th.Context, channel)
th.RemovePermissionFromRole(model.PermissionCreatePost.Id, scheme.DefaultChannelGuestRole)
th.RemovePermissionFromRole(model.PermissionCreatePost.Id, teamScheme.DefaultChannelGuestRole)
@@ -4230,12 +4230,12 @@ func TestPatchChannelModerations(t *testing.T) {
require.Equal(t, moderation.Roles.Members.Enabled, true)
}
}
channel, _ = th.App.GetChannel(channel.Id)
channel, _ = th.App.GetChannel(th.Context, channel.Id)
require.NotNil(t, channel.SchemeId)
})
t.Run("Removes the existing scheme when moderated permissions are set back to higher scoped values", func(t *testing.T) {
channel, _ = th.App.GetChannel(channel.Id)
channel, _ = th.App.GetChannel(th.Context, channel.Id)
schemeId := channel.SchemeId
scheme, _ := th.App.GetScheme(*schemeId)
@@ -4263,7 +4263,7 @@ func TestPatchChannelModerations(t *testing.T) {
require.Equal(t, moderation.Roles.Members.Enabled, true)
}
channel, _ = th.App.GetChannel(channel.Id)
channel, _ = th.App.GetChannel(th.Context, channel.Id)
require.Nil(t, channel.SchemeId)
scheme, _ = th.App.GetScheme(*schemeId)
@@ -4462,7 +4462,7 @@ func TestMoveChannel(t *testing.T) {
t.Run("Should fail when trying to move a group channel", func(t *testing.T) {
user := th.CreateUser()
gmChannel, appErr := th.App.CreateGroupChannel([]string{th.BasicUser.Id, th.SystemAdminUser.Id, th.TeamAdminUser.Id}, user.Id)
gmChannel, appErr := th.App.CreateGroupChannel(th.Context, []string{th.BasicUser.Id, th.SystemAdminUser.Id, th.TeamAdminUser.Id}, user.Id)
require.Nil(t, appErr)
_, _, err := client.MoveChannel(gmChannel.Id, team1.Id, false)
require.Error(t, err)