[MM-32622] Remove app.WaitForChannelMembership() (#17048)

* Remove app.WaitForChannelMembership

* Fix tests

* Fix test

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Claudio Costa
2021-03-31 09:40:35 +02:00
коммит произвёл GitHub
родитель 4ba0c09fc7
Коммит ee3f986da0
32 изменённых файлов: 211 добавлений и 227 удалений

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

@@ -1055,7 +1055,7 @@ func (th *TestHelper) cleanupTestFile(info *model.FileInfo) error {
func (th *TestHelper) MakeUserChannelAdmin(user *model.User, channel *model.Channel) {
utils.DisableDebugLogForTest()
if cm, err := th.App.Srv().Store.Channel().GetMember(channel.Id, user.Id); err == nil {
if cm, err := th.App.Srv().Store.Channel().GetMember(context.Background(), channel.Id, user.Id); err == nil {
cm.SchemeAdmin = true
if _, err = th.App.Srv().Store.Channel().UpdateMember(cm); err != nil {
utils.EnableDebugLogForTest()

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

@@ -4,6 +4,7 @@
package api4
import (
"context"
"encoding/json"
"net/http"
"strconv"
@@ -158,7 +159,7 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
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.
if _, errGet := c.App.GetChannelMember(channel.Id, c.App.Session().UserId); errGet != nil {
if _, errGet := c.App.GetChannelMember(context.Background(), channel.Id, c.App.Session().UserId); errGet != nil {
c.Err = model.NewAppError("updateChannel", "api.channel.patch_update_channel.forbidden.app_error", nil, "", http.StatusForbidden)
return
}
@@ -371,7 +372,7 @@ func patchChannel(c *Context, w http.ResponseWriter, r *http.Request) {
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.
if _, err = c.App.GetChannelMember(c.Params.ChannelId, c.App.Session().UserId); err != nil {
if _, err = c.App.GetChannelMember(context.Background(), c.Params.ChannelId, c.App.Session().UserId); err != nil {
c.Err = model.NewAppError("patchChannel", "api.channel.patch_update_channel.forbidden.app_error", nil, "", http.StatusForbidden)
return
}
@@ -1249,7 +1250,7 @@ func getChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
member, err := c.App.GetChannelMember(c.Params.ChannelId, c.Params.UserId)
member, err := c.App.GetChannelMember(app.WithMaster(context.Background()), c.Params.ChannelId, c.Params.UserId)
if err != nil {
c.Err = err
return
@@ -1480,7 +1481,7 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
}
isNewMembership := false
if _, err = c.App.GetChannelMember(member.ChannelId, member.UserId); err != nil {
if _, err = c.App.GetChannelMember(context.Background(), member.ChannelId, member.UserId); err != nil {
if err.Id == app.MissingChannelMemberError {
isNewMembership = true
} else {
@@ -1736,7 +1737,7 @@ func channelMemberCountsByGroup(c *Context, w http.ResponseWriter, r *http.Reque
includeTimezones := r.URL.Query().Get("include_timezones") == "true"
channelMemberCounts, err := c.App.GetMemberCountsByGroup(c.Params.ChannelId, includeTimezones)
channelMemberCounts, err := c.App.GetMemberCountsByGroup(app.WithMaster(context.Background()), c.Params.ChannelId, includeTimezones)
if err != nil {
c.Err = err
return

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

@@ -4,6 +4,7 @@
package api4
import (
"context"
"fmt"
"net/http"
"sort"
@@ -2491,7 +2492,7 @@ func TestUpdateChannelNotifyProps(t *testing.T) {
CheckNoError(t, resp)
require.True(t, pass, "should have passed")
member, err := th.App.GetChannelMember(th.BasicChannel.Id, th.BasicUser.Id)
member, err := th.App.GetChannelMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
require.Nil(t, err)
require.Equal(t, model.CHANNEL_NOTIFY_MENTION, member.NotifyProps[model.DESKTOP_NOTIFY_PROP], "bad update")
require.Equal(t, model.CHANNEL_MARK_UNREAD_MENTION, member.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP], "bad update")

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

@@ -4,6 +4,7 @@
package api4
import (
"context"
"encoding/json"
"errors"
"fmt"
@@ -1732,7 +1733,7 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
// Set channel member's last viewed to 0.
// All returned posts are latest posts as if all previous posts were already read by the user.
channelMember, err := th.App.Srv().Store.Channel().GetMember(channelId, userId)
channelMember, err := th.App.Srv().Store.Channel().GetMember(context.Background(), channelId, userId)
require.NoError(t, err)
channelMember.LastViewedAt = 0
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)
@@ -1753,7 +1754,7 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
postIdNames[systemPost1.Id] = "system post 1"
// Set channel member's last viewed before post1.
channelMember, err = th.App.Srv().Store.Channel().GetMember(channelId, userId)
channelMember, err = th.App.Srv().Store.Channel().GetMember(context.Background(), channelId, userId)
require.NoError(t, err)
channelMember.LastViewedAt = post1.CreateAt - 1
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)
@@ -1777,7 +1778,7 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
}, posts)
// Set channel member's last viewed before post6.
channelMember, err = th.App.Srv().Store.Channel().GetMember(channelId, userId)
channelMember, err = th.App.Srv().Store.Channel().GetMember(context.Background(), channelId, userId)
require.NoError(t, err)
channelMember.LastViewedAt = post6.CreateAt - 1
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)
@@ -1804,7 +1805,7 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
}, posts)
// Set channel member's last viewed before post10.
channelMember, err = th.App.Srv().Store.Channel().GetMember(channelId, userId)
channelMember, err = th.App.Srv().Store.Channel().GetMember(context.Background(), channelId, userId)
require.NoError(t, err)
channelMember.LastViewedAt = post10.CreateAt - 1
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)
@@ -1829,7 +1830,7 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
}, posts)
// Set channel member's last viewed equal to post10.
channelMember, err = th.App.Srv().Store.Channel().GetMember(channelId, userId)
channelMember, err = th.App.Srv().Store.Channel().GetMember(context.Background(), channelId, userId)
require.NoError(t, err)
channelMember.LastViewedAt = post10.CreateAt
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)
@@ -1869,7 +1870,7 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
postIdNames[post12.Id] = "post12 (reply to post4)"
postIdNames[post13.Id] = "post13"
channelMember, err = th.App.Srv().Store.Channel().GetMember(channelId, userId)
channelMember, err = th.App.Srv().Store.Channel().GetMember(context.Background(), channelId, userId)
require.NoError(t, err)
channelMember.LastViewedAt = post12.CreateAt - 1
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)