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

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

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

@@ -146,9 +146,10 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent
Server: s,
ConfigStore: configStore,
IncludeCacheLayer: includeCache,
Context: &request.Context{},
Context: request.EmptyContext(testLogger),
TestLogger: testLogger,
}
th.Context.SetLogger(testLogger)
if s.SearchEngine != nil && s.SearchEngine.BleveEngine != nil && searchEngine != nil {
searchEngine.BleveEngine = s.SearchEngine.BleveEngine
@@ -467,14 +468,14 @@ func (th *TestHelper) InitBasic() *TestHelper {
th.BasicPost = th.CreatePost()
th.LinkUserToTeam(th.BasicUser, th.BasicTeam)
th.LinkUserToTeam(th.BasicUser2, th.BasicTeam)
th.App.AddUserToChannel(th.BasicUser, th.BasicChannel, false)
th.App.AddUserToChannel(th.BasicUser2, th.BasicChannel, false)
th.App.AddUserToChannel(th.BasicUser, th.BasicChannel2, false)
th.App.AddUserToChannel(th.BasicUser2, th.BasicChannel2, false)
th.App.AddUserToChannel(th.BasicUser, th.BasicPrivateChannel, false)
th.App.AddUserToChannel(th.BasicUser2, th.BasicPrivateChannel, false)
th.App.AddUserToChannel(th.BasicUser, th.BasicDeletedChannel, false)
th.App.AddUserToChannel(th.BasicUser2, th.BasicDeletedChannel, false)
th.App.AddUserToChannel(th.Context, th.BasicUser, th.BasicChannel, false)
th.App.AddUserToChannel(th.Context, th.BasicUser2, th.BasicChannel, false)
th.App.AddUserToChannel(th.Context, th.BasicUser, th.BasicChannel2, false)
th.App.AddUserToChannel(th.Context, th.BasicUser2, th.BasicChannel2, false)
th.App.AddUserToChannel(th.Context, th.BasicUser, th.BasicPrivateChannel, false)
th.App.AddUserToChannel(th.Context, th.BasicUser2, th.BasicPrivateChannel, false)
th.App.AddUserToChannel(th.Context, th.BasicUser, th.BasicDeletedChannel, false)
th.App.AddUserToChannel(th.Context, th.BasicUser2, th.BasicDeletedChannel, false)
th.App.UpdateUserRoles(th.BasicUser.Id, model.SystemUserRoleId, false)
th.Client.DeleteChannel(th.BasicDeletedChannel.Id)
th.LoginBasic()
@@ -894,7 +895,7 @@ func (th *TestHelper) UnlinkUserFromTeam(user *model.User, team *model.Team) {
}
func (th *TestHelper) AddUserToChannel(user *model.User, channel *model.Channel) *model.ChannelMember {
member, err := th.App.AddUserToChannel(user, channel, false)
member, err := th.App.AddUserToChannel(th.Context, user, channel, false)
if err != nil {
panic(err)
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@@ -23,7 +23,7 @@ func getCategoriesForTeamForUser(c *Context, w http.ResponseWriter, r *http.Requ
return
}
categories, err := c.App.GetSidebarCategoriesForTeamForUser(c.Params.UserId, c.Params.TeamId)
categories, err := c.App.GetSidebarCategoriesForTeamForUser(c.AppContext, c.Params.UserId, c.Params.TeamId)
if err != nil {
c.Err = err
return
@@ -64,7 +64,7 @@ func createCategoryForTeamForUser(c *Context, w http.ResponseWriter, r *http.Req
return
}
category, appErr := c.App.CreateSidebarCategory(c.Params.UserId, c.Params.TeamId, &categoryCreateRequest)
category, appErr := c.App.CreateSidebarCategory(c.AppContext, c.Params.UserId, c.Params.TeamId, &categoryCreateRequest)
if appErr != nil {
c.Err = appErr
return
@@ -92,7 +92,7 @@ func getCategoryOrderForTeamForUser(c *Context, w http.ResponseWriter, r *http.R
return
}
order, err := c.App.GetSidebarCategoryOrder(c.Params.UserId, c.Params.TeamId)
order, err := c.App.GetSidebarCategoryOrder(c.AppContext, c.Params.UserId, c.Params.TeamId)
if err != nil {
c.Err = err
return
@@ -118,13 +118,13 @@ func updateCategoryOrderForTeamForUser(c *Context, w http.ResponseWriter, r *htt
categoryOrder := model.ArrayFromJSON(r.Body)
for _, categoryId := range categoryOrder {
if !c.App.SessionHasPermissionToCategory(*c.AppContext.Session(), c.Params.UserId, c.Params.TeamId, categoryId) {
if !c.App.SessionHasPermissionToCategory(c.AppContext, *c.AppContext.Session(), c.Params.UserId, c.Params.TeamId, categoryId) {
c.SetInvalidParam("category")
return
}
}
err := c.App.UpdateSidebarCategoryOrder(c.Params.UserId, c.Params.TeamId, categoryOrder)
err := c.App.UpdateSidebarCategoryOrder(c.AppContext, c.Params.UserId, c.Params.TeamId, categoryOrder)
if err != nil {
c.Err = err
return
@@ -140,12 +140,12 @@ func getCategoryForTeamForUser(c *Context, w http.ResponseWriter, r *http.Reques
return
}
if !c.App.SessionHasPermissionToCategory(*c.AppContext.Session(), c.Params.UserId, c.Params.TeamId, c.Params.CategoryId) {
if !c.App.SessionHasPermissionToCategory(c.AppContext, *c.AppContext.Session(), c.Params.UserId, c.Params.TeamId, c.Params.CategoryId) {
c.SetPermissionError(model.PermissionEditOtherUsers)
return
}
categories, err := c.App.GetSidebarCategory(c.Params.CategoryId)
categories, err := c.App.GetSidebarCategory(c.AppContext, c.Params.CategoryId)
if err != nil {
c.Err = err
return
@@ -182,7 +182,7 @@ func updateCategoriesForTeamForUser(c *Context, w http.ResponseWriter, r *http.R
}
for _, category := range categoriesUpdateRequest {
if !c.App.SessionHasPermissionToCategory(*c.AppContext.Session(), c.Params.UserId, c.Params.TeamId, category.Id) {
if !c.App.SessionHasPermissionToCategory(c.AppContext, *c.AppContext.Session(), c.Params.UserId, c.Params.TeamId, category.Id) {
c.SetInvalidParam("category")
return
}
@@ -193,7 +193,7 @@ func updateCategoriesForTeamForUser(c *Context, w http.ResponseWriter, r *http.R
return
}
categories, appErr := c.App.UpdateSidebarCategories(c.Params.UserId, c.Params.TeamId, categoriesUpdateRequest)
categories, appErr := c.App.UpdateSidebarCategories(c.AppContext, c.Params.UserId, c.Params.TeamId, categoriesUpdateRequest)
if appErr != nil {
c.Err = appErr
return
@@ -210,7 +210,7 @@ func updateCategoriesForTeamForUser(c *Context, w http.ResponseWriter, r *http.R
}
func validateSidebarCategory(c *Context, teamId, userId string, category *model.SidebarCategoryWithChannels) *model.AppError {
channels, err := c.App.GetChannelsForTeamForUser(teamId, userId, &model.ChannelSearchOpts{
channels, err := c.App.GetChannelsForTeamForUser(c.AppContext, teamId, userId, &model.ChannelSearchOpts{
IncludeDeleted: true,
LastDeleteAt: 0,
})
@@ -218,13 +218,13 @@ func validateSidebarCategory(c *Context, teamId, userId string, category *model.
return model.NewAppError("validateSidebarCategory", "api.invalid_channel", nil, err.Error(), http.StatusBadRequest)
}
category.Channels = validateSidebarCategoryChannels(userId, category.Channels, channels)
category.Channels = validateSidebarCategoryChannels(c, userId, category.Channels, channels)
return nil
}
func validateSidebarCategories(c *Context, teamId, userId string, categories []*model.SidebarCategoryWithChannels) *model.AppError {
channels, err := c.App.GetChannelsForTeamForUser(teamId, userId, &model.ChannelSearchOpts{
channels, err := c.App.GetChannelsForTeamForUser(c.AppContext, teamId, userId, &model.ChannelSearchOpts{
IncludeDeleted: true,
LastDeleteAt: 0,
})
@@ -233,13 +233,13 @@ func validateSidebarCategories(c *Context, teamId, userId string, categories []*
}
for _, category := range categories {
category.Channels = validateSidebarCategoryChannels(userId, category.Channels, channels)
category.Channels = validateSidebarCategoryChannels(c, userId, category.Channels, channels)
}
return nil
}
func validateSidebarCategoryChannels(userId string, channelIds []string, channels model.ChannelList) []string {
func validateSidebarCategoryChannels(c *Context, userId string, channelIds []string, channels model.ChannelList) []string {
var filtered []string
for _, channelId := range channelIds {
@@ -254,7 +254,7 @@ func validateSidebarCategoryChannels(userId string, channelIds []string, channel
if found {
filtered = append(filtered, channelId)
} else {
mlog.Info("Stopping user from adding channel to their sidebar when they are not a member", mlog.String("user_id", userId), mlog.String("channel_id", channelId))
c.Logger.Info("Stopping user from adding channel to their sidebar when they are not a member", mlog.String("user_id", userId), mlog.String("channel_id", channelId))
}
}
@@ -267,7 +267,7 @@ func updateCategoryForTeamForUser(c *Context, w http.ResponseWriter, r *http.Req
return
}
if !c.App.SessionHasPermissionToCategory(*c.AppContext.Session(), c.Params.UserId, c.Params.TeamId, c.Params.CategoryId) {
if !c.App.SessionHasPermissionToCategory(c.AppContext, *c.AppContext.Session(), c.Params.UserId, c.Params.TeamId, c.Params.CategoryId) {
c.SetPermissionError(model.PermissionEditOtherUsers)
return
}
@@ -289,7 +289,7 @@ func updateCategoryForTeamForUser(c *Context, w http.ResponseWriter, r *http.Req
categoryUpdateRequest.Id = c.Params.CategoryId
categories, appErr := c.App.UpdateSidebarCategories(c.Params.UserId, c.Params.TeamId, []*model.SidebarCategoryWithChannels{&categoryUpdateRequest})
categories, appErr := c.App.UpdateSidebarCategories(c.AppContext, c.Params.UserId, c.Params.TeamId, []*model.SidebarCategoryWithChannels{&categoryUpdateRequest})
if appErr != nil {
c.Err = appErr
return
@@ -311,7 +311,7 @@ func deleteCategoryForTeamForUser(c *Context, w http.ResponseWriter, r *http.Req
return
}
if !c.App.SessionHasPermissionToCategory(*c.AppContext.Session(), c.Params.UserId, c.Params.TeamId, c.Params.CategoryId) {
if !c.App.SessionHasPermissionToCategory(c.AppContext, *c.AppContext.Session(), c.Params.UserId, c.Params.TeamId, c.Params.CategoryId) {
c.SetPermissionError(model.PermissionEditOtherUsers)
return
}
@@ -319,7 +319,7 @@ func deleteCategoryForTeamForUser(c *Context, w http.ResponseWriter, r *http.Req
auditRec := c.MakeAuditRecord("deleteCategoryForTeamForUser", audit.Fail)
defer c.LogAuditRec(auditRec)
appErr := c.App.DeleteSidebarCategory(c.Params.UserId, c.Params.TeamId, c.Params.CategoryId)
appErr := c.App.DeleteSidebarCategory(c.AppContext, c.Params.UserId, c.Params.TeamId, c.Params.CategoryId)
if appErr != nil {
c.Err = appErr
return

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

@@ -61,7 +61,7 @@ func localCreateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(sc); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -78,7 +78,7 @@ func localUpdateChannelPrivacy(c *Context, w http.ResponseWriter, r *http.Reques
return
}
channel, err := c.App.GetChannel(c.Params.ChannelId)
channel, err := c.App.GetChannel(c.AppContext, c.Params.ChannelId)
if err != nil {
c.Err = err
return
@@ -105,7 +105,7 @@ func localUpdateChannelPrivacy(c *Context, w http.ResponseWriter, r *http.Reques
c.LogAudit("name=" + updatedChannel.Name)
if err := json.NewEncoder(w).Encode(updatedChannel); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -115,7 +115,7 @@ func localRestoreChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
channel, err := c.App.GetChannel(c.Params.ChannelId)
channel, err := c.App.GetChannel(c.AppContext, c.Params.ChannelId)
if err != nil {
c.Err = err
return
@@ -135,7 +135,7 @@ func localRestoreChannel(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("name=" + channel.Name)
if err := json.NewEncoder(w).Encode(channel); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -175,7 +175,7 @@ func localAddChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
channel, err := c.App.GetChannel(member.ChannelId)
channel, err := c.App.GetChannel(c.AppContext, member.ChannelId)
if err != nil {
c.Err = err
return
@@ -220,7 +220,7 @@ func localAddChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(cm); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -230,7 +230,7 @@ func localRemoveChannelMember(c *Context, w http.ResponseWriter, r *http.Request
return
}
channel, err := c.App.GetChannel(c.Params.ChannelId)
channel, err := c.App.GetChannel(c.AppContext, c.Params.ChannelId)
if err != nil {
c.Err = err
return
@@ -281,7 +281,7 @@ func localPatchChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
originalOldChannel, appErr := c.App.GetChannel(c.Params.ChannelId)
originalOldChannel, appErr := c.App.GetChannel(c.AppContext, c.Params.ChannelId)
if appErr != nil {
c.Err = appErr
return
@@ -293,13 +293,13 @@ func localPatchChannel(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec.AddMeta("channel", channel)
channel.Patch(patch)
rchannel, appErr := c.App.UpdateChannel(channel)
rchannel, appErr := c.App.UpdateChannel(c.AppContext, channel)
if appErr != nil {
c.Err = appErr
return
}
appErr = c.App.FillInChannelProps(rchannel)
appErr = c.App.FillInChannelProps(c.AppContext, rchannel)
if appErr != nil {
c.Err = appErr
return
@@ -310,7 +310,7 @@ func localPatchChannel(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec.AddMeta("patch", rchannel)
if err := json.NewEncoder(w).Encode(rchannel); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -320,7 +320,7 @@ func localMoveChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
channel, err := c.App.GetChannel(c.Params.ChannelId)
channel, err := c.App.GetChannel(c.AppContext, c.Params.ChannelId)
if err != nil {
c.Err = err
return
@@ -357,7 +357,7 @@ func localMoveChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
err = c.App.RemoveAllDeactivatedMembersFromChannel(channel)
err = c.App.RemoveAllDeactivatedMembersFromChannel(c.AppContext, channel)
if err != nil {
c.Err = err
return
@@ -382,7 +382,7 @@ func localMoveChannel(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("team=" + team.Name)
if err := json.NewEncoder(w).Encode(channel); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -392,7 +392,7 @@ func localDeleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
channel, err := c.App.GetChannel(c.Params.ChannelId)
channel, err := c.App.GetChannel(c.AppContext, c.Params.ChannelId)
if err != nil {
c.Err = err
return
@@ -408,7 +408,7 @@ func localDeleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
if c.Params.Permanent {
err = c.App.PermanentDeleteChannel(channel)
err = c.App.PermanentDeleteChannel(c.AppContext, channel)
} else {
err = c.App.DeleteChannel(c.AppContext, channel, "")
}

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

@@ -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)

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

@@ -314,12 +314,12 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec.AddMeta("commandargs", commandArgs)
// checks that user is a member of the specified channel, and that they have permission to use slash commands in it
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), commandArgs.ChannelId, model.PermissionUseSlashCommands) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), commandArgs.ChannelId, model.PermissionUseSlashCommands) {
c.SetPermissionError(model.PermissionUseSlashCommands)
return
}
channel, err := c.App.GetChannel(commandArgs.ChannelId)
channel, err := c.App.GetChannel(c.AppContext, commandArgs.ChannelId)
if err != nil {
c.Err = err
return

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

@@ -356,7 +356,7 @@ func searchChannelsInPolicy(c *Context, w http.ResponseWriter, r *http.Request)
TeamIds: props.TeamIds,
}
channels, _, appErr := c.App.SearchAllChannels(props.Term, opts)
channels, _, appErr := c.App.SearchAllChannels(c.AppContext, props.Term, opts)
if appErr != nil {
c.Err = appErr
return

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

@@ -167,7 +167,7 @@ func uploadFileSimple(c *Context, r *http.Request, timestamp time.Time) *model.F
defer c.LogAuditRec(auditRec)
auditRec.AddMeta("channel_id", c.Params.ChannelId)
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), c.Params.ChannelId, model.PermissionUploadFile) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), c.Params.ChannelId, model.PermissionUploadFile) {
c.SetPermissionError(model.PermissionUploadFile)
return nil
}
@@ -312,7 +312,7 @@ NextPart:
if c.Err != nil {
return nil
}
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), c.Params.ChannelId, model.PermissionUploadFile) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), c.Params.ChannelId, model.PermissionUploadFile) {
c.SetPermissionError(model.PermissionUploadFile)
return nil
}
@@ -401,7 +401,7 @@ func uploadFileMultipartLegacy(c *Context, mr *multipart.Reader,
if c.Err != nil {
return nil
}
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), channelId, model.PermissionUploadFile) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), channelId, model.PermissionUploadFile) {
c.SetPermissionError(model.PermissionUploadFile)
return nil
}

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

@@ -575,7 +575,7 @@ func verifyLinkUnlinkPermission(c *Context, syncableType model.GroupSyncableType
return c.App.MakePermissionError(c.AppContext.Session(), []*model.Permission{model.PermissionManageTeam})
}
case model.GroupSyncableTypeChannel:
channel, err := c.App.GetChannel(syncableID)
channel, err := c.App.GetChannel(c.AppContext, syncableID)
if err != nil {
return err
}
@@ -587,7 +587,7 @@ func verifyLinkUnlinkPermission(c *Context, syncableType model.GroupSyncableType
permission = model.PermissionManagePublicChannelMembers
}
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), syncableID, permission) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), syncableID, permission) {
return c.App.MakePermissionError(c.AppContext.Session(), []*model.Permission{permission})
}
}
@@ -716,7 +716,7 @@ func getGroupsByChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
channel, err := c.App.GetChannel(c.Params.ChannelId)
channel, err := c.App.GetChannel(c.AppContext, c.Params.ChannelId)
if err != nil {
c.Err = err
return
@@ -727,7 +727,7 @@ func getGroupsByChannel(c *Context, w http.ResponseWriter, r *http.Request) {
} else {
permission = model.PermissionReadPublicChannelGroups
}
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), c.Params.ChannelId, permission) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), c.Params.ChannelId, permission) {
c.SetPermissionError(permission)
return
}
@@ -889,7 +889,7 @@ func getGroups(c *Context, w http.ResponseWriter, r *http.Request) {
}
if channelID != "" {
channel, err := c.App.GetChannel(channelID)
channel, err := c.App.GetChannel(c.AppContext, channelID)
if err != nil {
c.Err = err
return
@@ -900,7 +900,7 @@ func getGroups(c *Context, w http.ResponseWriter, r *http.Request) {
} else {
permission = model.PermissionManagePublicChannelMembers
}
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), channelID, permission) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), channelID, permission) {
c.SetPermissionError(permission)
return
}

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

@@ -8,7 +8,6 @@ import (
"net/http"
"time"
"github.com/mattermost/mattermost-server/v6/app"
"github.com/mattermost/mattermost-server/v6/model"
)
@@ -149,7 +148,7 @@ func getTopChannelsForTeamSince(c *Context, w http.ResponseWriter, r *http.Reque
loc := user.GetTimezoneLocation()
startTime := model.StartOfDayForTimeRange(c.Params.TimeRange, loc)
topChannels, err := c.App.GetTopChannelsForTeamSince(c.Params.TeamId, c.AppContext.Session().UserId, &model.InsightsOpts{
topChannels, err := c.App.GetTopChannelsForTeamSince(c.AppContext, c.Params.TeamId, c.AppContext.Session().UserId, &model.InsightsOpts{
StartUnixMilli: startTime.UnixMilli(),
Page: c.Params.Page,
PerPage: c.Params.PerPage,
@@ -159,7 +158,7 @@ func getTopChannelsForTeamSince(c *Context, w http.ResponseWriter, r *http.Reque
return
}
topChannels.PostCountByDuration, err = postCountByDurationViewModel(c.App, topChannels, startTime, c.Params.TimeRange, nil, loc)
topChannels.PostCountByDuration, err = postCountByDurationViewModel(c, topChannels, startTime, c.Params.TimeRange, nil, loc)
if err != nil {
c.Err = err
return
@@ -205,7 +204,7 @@ func getTopChannelsForUserSince(c *Context, w http.ResponseWriter, r *http.Reque
loc := user.GetTimezoneLocation()
startTime := model.StartOfDayForTimeRange(c.Params.TimeRange, loc)
topChannels, err := c.App.GetTopChannelsForUserSince(c.AppContext.Session().UserId, c.Params.TeamId, &model.InsightsOpts{
topChannels, err := c.App.GetTopChannelsForUserSince(c.AppContext, c.AppContext.Session().UserId, c.Params.TeamId, &model.InsightsOpts{
StartUnixMilli: startTime.UnixMilli(),
Page: c.Params.Page,
PerPage: c.Params.PerPage,
@@ -216,7 +215,7 @@ func getTopChannelsForUserSince(c *Context, w http.ResponseWriter, r *http.Reque
return
}
topChannels.PostCountByDuration, err = postCountByDurationViewModel(c.App, topChannels, startTime, c.Params.TimeRange, &c.AppContext.Session().UserId, loc)
topChannels.PostCountByDuration, err = postCountByDurationViewModel(c, topChannels, startTime, c.Params.TimeRange, &c.AppContext.Session().UserId, loc)
if err != nil {
c.Err = err
return
@@ -265,7 +264,7 @@ func getTopThreadsForTeamSince(c *Context, w http.ResponseWriter, r *http.Reques
startTime := model.StartOfDayForTimeRange(c.Params.TimeRange, user.GetTimezoneLocation())
topThreads, err := c.App.GetTopThreadsForTeamSince(c.Params.TeamId, c.AppContext.Session().UserId, &model.InsightsOpts{
topThreads, err := c.App.GetTopThreadsForTeamSince(c.AppContext, c.Params.TeamId, c.AppContext.Session().UserId, &model.InsightsOpts{
StartUnixMilli: startTime.UnixMilli(),
Page: c.Params.Page,
PerPage: c.Params.PerPage,
@@ -321,7 +320,7 @@ func getTopThreadsForUserSince(c *Context, w http.ResponseWriter, r *http.Reques
startTime := model.StartOfDayForTimeRange(c.Params.TimeRange, user.GetTimezoneLocation())
topThreads, err := c.App.GetTopThreadsForUserSince(c.Params.TeamId, c.AppContext.Session().UserId, &model.InsightsOpts{
topThreads, err := c.App.GetTopThreadsForUserSince(c.AppContext, c.Params.TeamId, c.AppContext.Session().UserId, &model.InsightsOpts{
StartUnixMilli: startTime.UnixMilli(),
Page: c.Params.Page,
PerPage: c.Params.PerPage,
@@ -342,7 +341,7 @@ func getTopThreadsForUserSince(c *Context, w http.ResponseWriter, r *http.Reques
}
// postCountByDurationViewModel expects a list of channels that are pre-authorized for the given user to view.
func postCountByDurationViewModel(app app.AppIface, topChannelList *model.TopChannelList, startTime *time.Time, timeRange string, userID *string, location *time.Location) (model.ChannelPostCountByDuration, *model.AppError) {
func postCountByDurationViewModel(c *Context, topChannelList *model.TopChannelList, startTime *time.Time, timeRange string, userID *string, location *time.Location) (model.ChannelPostCountByDuration, *model.AppError) {
if len(topChannelList.Items) == 0 {
return nil, nil
}
@@ -354,7 +353,7 @@ func postCountByDurationViewModel(app app.AppIface, topChannelList *model.TopCha
} else {
grouping = model.PostsByDay
}
postCountsByDay, err := app.PostCountsByDuration(channelIDs, startTime.UnixMilli(), userID, grouping, location)
postCountsByDay, err := c.App.PostCountsByDuration(c.AppContext, channelIDs, startTime.UnixMilli(), userID, grouping, location)
if err != nil {
return nil, err
}

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

@@ -439,9 +439,9 @@ func TestGetTopChannelsForTeamSince(t *testing.T) {
channel4 := th.CreatePublicChannel()
channel5 := th.CreatePrivateChannel()
channel6 := th.CreatePrivateChannel()
th.App.AddUserToChannel(th.BasicUser, channel4, false)
th.App.AddUserToChannel(th.BasicUser, channel5, false)
th.App.AddUserToChannel(th.BasicUser, channel6, false)
th.App.AddUserToChannel(th.Context, th.BasicUser, channel4, false)
th.App.AddUserToChannel(th.Context, th.BasicUser, channel5, false)
th.App.AddUserToChannel(th.Context, th.BasicUser, channel6, false)
channelIDs := [6]string{th.BasicChannel.Id, th.BasicChannel2.Id, th.BasicPrivateChannel.Id, channel4.Id, channel5.Id, channel6.Id}
@@ -535,9 +535,9 @@ func TestGetTopChannelsForUserSince(t *testing.T) {
channel4 := th.CreatePublicChannel()
channel5 := th.CreatePrivateChannel()
channel6 := th.CreatePrivateChannel()
th.App.AddUserToChannel(th.BasicUser, channel4, false)
th.App.AddUserToChannel(th.BasicUser, channel5, false)
th.App.AddUserToChannel(th.BasicUser, channel6, false)
th.App.AddUserToChannel(th.Context, th.BasicUser, channel4, false)
th.App.AddUserToChannel(th.Context, th.BasicUser, channel5, false)
th.App.AddUserToChannel(th.Context, th.BasicUser, channel6, false)
channelIDs := [6]string{th.BasicChannel.Id, th.BasicChannel2.Id, th.BasicPrivateChannel.Id, channel4.Id, channel5.Id, channel6.Id}
@@ -612,9 +612,9 @@ func TestGetTopThreadsForTeamSince(t *testing.T) {
channelPublic := th.BasicChannel
channelPrivate := th.BasicPrivateChannel
th.App.AddUserToChannel(th.BasicUser, channelPublic, false)
th.App.AddUserToChannel(th.BasicUser, channelPrivate, false)
th.App.AddUserToChannel(th.BasicUser2, channelPublic, false)
th.App.AddUserToChannel(th.Context, th.BasicUser, channelPublic, false)
th.App.AddUserToChannel(th.Context, th.BasicUser, channelPrivate, false)
th.App.AddUserToChannel(th.Context, th.BasicUser2, channelPublic, false)
th.App.RemoveUserFromChannel(th.Context, th.BasicUser2.Id, th.BasicUser.Id, channelPrivate)
// create two threads: one in public channel, one in private
@@ -698,9 +698,9 @@ func TestGetTopThreadsForUserSince(t *testing.T) {
channelPublic := th.BasicChannel
channelPrivate := th.BasicPrivateChannel
th.App.AddUserToChannel(th.BasicUser, channelPublic, false)
th.App.AddUserToChannel(th.BasicUser, channelPrivate, false)
th.App.AddUserToChannel(th.BasicUser2, channelPublic, false)
th.App.AddUserToChannel(th.Context, th.BasicUser, channelPublic, false)
th.App.AddUserToChannel(th.Context, th.BasicUser, channelPrivate, false)
th.App.AddUserToChannel(th.Context, th.BasicUser2, channelPublic, false)
// create two threads: one in public channel, one in private
// post in public channel has both users interacting, post in private only has user1 interacting
@@ -770,7 +770,7 @@ func TestGetTopThreadsForUserSince(t *testing.T) {
require.Equal(t, topUser2Threads.Items[0].Post.ReplyCount, int64(1))
// deleting the root post results in the thread not making it to top threads list
_, appErr = th.App.DeletePost(rootPostPublicChannel.Id, th.BasicUser.Id)
_, appErr = th.App.DeletePost(th.Context, rootPostPublicChannel.Id, th.BasicUser.Id)
require.Nil(t, appErr)
client.Logout()
@@ -803,7 +803,7 @@ func TestGetTopThreadsForUserSince(t *testing.T) {
require.Len(t, topUser2ThreadsAfterPrivateReply.Items, 1)
// deleting reply, and unfollowing thread
_, appErr = th.App.DeletePost(replyPostUser2InPrivate.Id, th.BasicUser2.Id)
_, appErr = th.App.DeletePost(th.Context, replyPostUser2InPrivate.Id, th.BasicUser2.Id)
require.Nil(t, appErr)
// unfollow thread
_, err := th.App.Srv().Store.Thread().MaintainMembership(th.BasicUser2.Id, rootPostPrivateChannel.Id, store.ThreadMembershipOpts{

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

@@ -39,7 +39,7 @@ func doPostAction(c *Context, w http.ResponseWriter, r *http.Request) {
c.Err = model.NewAppError("DoPostAction", "api.post.do_action.action_integration.app_error", nil, "err="+err.Error(), http.StatusBadRequest)
return
}
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), cookie.ChannelId, model.PermissionReadChannel) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), cookie.ChannelId, model.PermissionReadChannel) {
c.SetPermissionError(model.PermissionReadChannel)
return
}
@@ -101,7 +101,7 @@ func submitDialog(c *Context, w http.ResponseWriter, r *http.Request) {
submit.UserId = c.AppContext.Session().UserId
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), submit.ChannelId, model.PermissionReadChannel) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), submit.ChannelId, model.PermissionReadChannel) {
c.SetPermissionError(model.PermissionReadChannel)
return
}

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

@@ -55,9 +55,9 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec.AddMeta("post", &post)
hasPermission := false
if c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), post.ChannelId, model.PermissionCreatePost) {
if c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), post.ChannelId, model.PermissionCreatePost) {
hasPermission = true
} else if channel, err := c.App.GetChannel(post.ChannelId); err == nil {
} else if channel, err := c.App.GetChannel(c.AppContext, post.ChannelId); err == nil {
// Temporary permission check method until advanced permissions, please do not copy
if channel.Type == model.ChannelTypeOpen && c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), channel.TeamId, model.PermissionCreatePostPublic) {
hasPermission = true
@@ -129,12 +129,12 @@ func createEphemeralPost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
rp := c.App.SendEphemeralPost(ephRequest.UserID, c.App.PostWithProxyRemovedFromImageURLs(ephRequest.Post))
rp := c.App.SendEphemeralPost(c.AppContext, ephRequest.UserID, c.App.PostWithProxyRemovedFromImageURLs(ephRequest.Post))
w.WriteHeader(http.StatusCreated)
rp = model.AddPostActionCookies(rp, c.App.PostActionCookieSecret())
rp = c.App.PreparePostForClientWithEmbedsAndImages(rp, true, false)
rp, err := c.App.SanitizePostMetadataForUser(rp, c.AppContext.Session().UserId)
rp = c.App.PreparePostForClientWithEmbedsAndImages(c.AppContext, rp, true, false)
rp, err := c.App.SanitizePostMetadataForUser(c.AppContext, rp, c.AppContext.Session().UserId)
if err != nil {
c.Err = err
return
@@ -179,13 +179,13 @@ func getPostsForChannel(c *Context, w http.ResponseWriter, r *http.Request) {
page := c.Params.Page
perPage := c.Params.PerPage
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), channelId, model.PermissionReadChannel) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), channelId, model.PermissionReadChannel) {
c.SetPermissionError(model.PermissionReadChannel)
return
}
if !*c.App.Config().TeamSettings.ExperimentalViewArchivedChannels {
channel, err := c.App.GetChannel(channelId)
channel, err := c.App.GetChannel(c.AppContext, channelId)
if err != nil {
c.Err = err
return
@@ -238,8 +238,8 @@ func getPostsForChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
c.App.AddCursorIdsForPostList(list, afterPost, beforePost, since, page, perPage, collapsedThreads)
clientPostList := c.App.PreparePostListForClient(list)
clientPostList, err = c.App.SanitizePostListMetadataForUser(clientPostList, c.AppContext.Session().UserId)
clientPostList := c.App.PreparePostListForClient(c.AppContext, list)
clientPostList, err = c.App.SanitizePostListMetadataForUser(c.AppContext, clientPostList, c.AppContext.Session().UserId)
if err != nil {
c.Err = err
return
@@ -263,7 +263,7 @@ func getPostsForChannelAroundLastUnread(c *Context, w http.ResponseWriter, r *ht
}
channelId := c.Params.ChannelId
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), channelId, model.PermissionReadChannel) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), channelId, model.PermissionReadChannel) {
c.SetPermissionError(model.PermissionReadChannel)
return
}
@@ -277,7 +277,7 @@ func getPostsForChannelAroundLastUnread(c *Context, w http.ResponseWriter, r *ht
collapsedThreads := r.URL.Query().Get("collapsedThreads") == "true"
collapsedThreadsExtended := r.URL.Query().Get("collapsedThreadsExtended") == "true"
postList, err := c.App.GetPostsForChannelAroundLastUnread(channelId, userId, c.Params.LimitBefore, c.Params.LimitAfter, skipFetchThreads, collapsedThreads, collapsedThreadsExtended)
postList, err := c.App.GetPostsForChannelAroundLastUnread(c.AppContext, channelId, userId, c.Params.LimitBefore, c.Params.LimitAfter, skipFetchThreads, collapsedThreads, collapsedThreadsExtended)
if err != nil {
c.Err = err
return
@@ -301,8 +301,8 @@ func getPostsForChannelAroundLastUnread(c *Context, w http.ResponseWriter, r *ht
postList.NextPostId = c.App.GetNextPostIdFromPostList(postList, collapsedThreads)
postList.PrevPostId = c.App.GetPrevPostIdFromPostList(postList, collapsedThreads)
clientPostList := c.App.PreparePostListForClient(postList)
clientPostList, err = c.App.SanitizePostListMetadataForUser(clientPostList, c.AppContext.Session().UserId)
clientPostList := c.App.PreparePostListForClient(c.AppContext, postList)
clientPostList, err = c.App.SanitizePostListMetadataForUser(c.AppContext, clientPostList, c.AppContext.Session().UserId)
if err != nil {
c.Err = err
return
@@ -354,7 +354,7 @@ func getFlaggedPostsForUser(c *Context, w http.ResponseWriter, r *http.Request)
if !ok {
allowed = false
if c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), post.ChannelId, model.PermissionReadChannel) {
if c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), post.ChannelId, model.PermissionReadChannel) {
allowed = true
}
@@ -370,8 +370,8 @@ func getFlaggedPostsForUser(c *Context, w http.ResponseWriter, r *http.Request)
}
pl.SortByCreateAt()
clientPostList := c.App.PreparePostListForClient(pl)
clientPostList, err = c.App.SanitizePostListMetadataForUser(clientPostList, c.AppContext.Session().UserId)
clientPostList := c.App.PreparePostListForClient(c.AppContext, pl)
clientPostList, err = c.App.SanitizePostListMetadataForUser(c.AppContext, clientPostList, c.AppContext.Session().UserId)
if err != nil {
c.Err = err
return
@@ -394,7 +394,7 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
post, err := c.App.GetPostIfAuthorized(c.Params.PostId, c.AppContext.Session(), includeDeleted)
post, err := c.App.GetPostIfAuthorized(c.AppContext, c.Params.PostId, c.AppContext.Session(), includeDeleted)
if err != nil {
c.Err = err
@@ -406,8 +406,8 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
post = c.App.PreparePostForClientWithEmbedsAndImages(post, false, false)
post, err = c.App.SanitizePostMetadataForUser(post, c.AppContext.Session().UserId)
post = c.App.PreparePostForClientWithEmbedsAndImages(c.AppContext, post, false, false)
post, err = c.App.SanitizePostMetadataForUser(c.AppContext, post, c.AppContext.Session().UserId)
if err != nil {
c.Err = err
return
@@ -451,7 +451,7 @@ func getPostsByIds(c *Context, w http.ResponseWriter, r *http.Request) {
if val, ok := channelMap[post.ChannelId]; ok {
channel = val
} else {
channel, err = c.App.GetChannel(post.ChannelId)
channel, err = c.App.GetChannel(c.AppContext, post.ChannelId)
if err != nil {
c.Err = err
return
@@ -459,7 +459,7 @@ func getPostsByIds(c *Context, w http.ResponseWriter, r *http.Request) {
channelMap[channel.Id] = channel
}
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), channel.Id, model.PermissionReadChannel) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), channel.Id, model.PermissionReadChannel) {
if channel.Type != model.ChannelTypeOpen || (channel.Type == model.ChannelTypeOpen && !c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), channel.TeamId, model.PermissionReadPublicChannel)) {
continue
}
@@ -495,18 +495,18 @@ func deletePost(c *Context, w http.ResponseWriter, _ *http.Request) {
auditRec.AddMeta("post", post)
if c.AppContext.Session().UserId == post.UserId {
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), post.ChannelId, model.PermissionDeletePost) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), post.ChannelId, model.PermissionDeletePost) {
c.SetPermissionError(model.PermissionDeletePost)
return
}
} else {
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), post.ChannelId, model.PermissionDeleteOthersPosts) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), post.ChannelId, model.PermissionDeleteOthersPosts) {
c.SetPermissionError(model.PermissionDeleteOthersPosts)
return
}
}
if _, err := c.App.DeletePost(c.Params.PostId, c.AppContext.Session().UserId); err != nil {
if _, err := c.App.DeletePost(c.AppContext, c.Params.PostId, c.AppContext.Session().UserId); err != nil {
c.Err = err
return
}
@@ -579,7 +579,7 @@ func getPostThread(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if _, err = c.App.GetPostIfAuthorized(post.Id, c.AppContext.Session(), false); err != nil {
if _, err = c.App.GetPostIfAuthorized(c.AppContext, post.Id, c.AppContext.Session(), false); err != nil {
c.Err = err
return
}
@@ -588,8 +588,8 @@ func getPostThread(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
clientPostList := c.App.PreparePostListForClient(list)
clientPostList, err = c.App.SanitizePostListMetadataForUser(clientPostList, c.AppContext.Session().UserId)
clientPostList := c.App.PreparePostListForClient(c.AppContext, list)
clientPostList, err = c.App.SanitizePostListMetadataForUser(c.AppContext, clientPostList, c.AppContext.Session().UserId)
if err != nil {
c.Err = err
return
@@ -683,8 +683,8 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request, teamId stri
return
}
clientPostList := c.App.PreparePostListForClient(results.PostList)
clientPostList, err = c.App.SanitizePostListMetadataForUser(clientPostList, c.AppContext.Session().UserId)
clientPostList := c.App.PreparePostListForClient(c.AppContext, results.PostList)
clientPostList, err = c.App.SanitizePostListMetadataForUser(c.AppContext, clientPostList, c.AppContext.Session().UserId)
if err != nil {
c.Err = err
return
@@ -826,7 +826,7 @@ func setPostUnread(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
state, err := c.App.MarkChannelAsUnreadFromPost(c.Params.PostId, c.Params.UserId, collapsedThreadsSupported)
state, err := c.App.MarkChannelAsUnreadFromPost(c.AppContext, c.Params.PostId, c.Params.UserId, collapsedThreadsSupported)
if err != nil {
c.Err = err
return

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

@@ -546,7 +546,7 @@ func TestCreatePostSendOutOfChannelMentions(t *testing.T) {
inChannelUser := th.CreateUser()
th.LinkUserToTeam(inChannelUser, th.BasicTeam)
th.App.AddUserToChannel(inChannelUser, th.BasicChannel, false)
th.App.AddUserToChannel(th.Context, inChannelUser, th.BasicChannel, false)
post1 := &model.Post{ChannelId: th.BasicChannel.Id, Message: "@" + inChannelUser.Username}
_, resp, err := client.CreatePost(post1)
@@ -2113,7 +2113,7 @@ func TestDeletePostEvent(t *testing.T) {
func TestDeletePostMessage(t *testing.T) {
th := Setup(t).InitBasic()
th.LinkUserToTeam(th.SystemAdminUser, th.BasicTeam)
th.App.AddUserToChannel(th.SystemAdminUser, th.BasicChannel, false)
th.App.AddUserToChannel(th.Context, th.SystemAdminUser, th.BasicChannel, false)
defer th.TearDown()
@@ -2469,8 +2469,8 @@ func TestSearchPostsFromUser(t *testing.T) {
th.LoginTeamAdmin()
user := th.CreateUser()
th.LinkUserToTeam(user, th.BasicTeam)
th.App.AddUserToChannel(user, th.BasicChannel, false)
th.App.AddUserToChannel(user, th.BasicChannel2, false)
th.App.AddUserToChannel(th.Context, user, th.BasicChannel, false)
th.App.AddUserToChannel(th.Context, user, th.BasicChannel2, false)
message := "sgtitlereview with space"
_ = th.CreateMessagePost(message)
@@ -2653,15 +2653,15 @@ func TestSetChannelUnread(t *testing.T) {
require.NotNil(t, pp2)
// Ensure that post have been read
unread, err := th.App.GetChannelUnread(c1.Id, u1.Id)
unread, err := th.App.GetChannelUnread(th.Context, c1.Id, u1.Id)
require.Nil(t, err)
require.Equal(t, int64(4), unread.MsgCount)
unread, appErr := th.App.GetChannelUnread(c1.Id, u2.Id)
unread, appErr := th.App.GetChannelUnread(th.Context, c1.Id, u2.Id)
require.Nil(t, appErr)
require.Equal(t, int64(4), unread.MsgCount)
_, appErr = th.App.ViewChannel(c1toc2, u2.Id, s2.Id, false)
_, appErr = th.App.ViewChannel(th.Context, c1toc2, u2.Id, s2.Id, false)
require.Nil(t, appErr)
unread, appErr = th.App.GetChannelUnread(c1.Id, u2.Id)
unread, appErr = th.App.GetChannelUnread(th.Context, c1.Id, u2.Id)
require.Nil(t, appErr)
require.Equal(t, int64(0), unread.MsgCount)
@@ -2669,7 +2669,7 @@ func TestSetChannelUnread(t *testing.T) {
r, err := th.Client.SetPostUnread(u1.Id, p2.Id, true)
require.NoError(t, err)
CheckOKStatus(t, r)
unread, appErr := th.App.GetChannelUnread(c1.Id, u1.Id)
unread, appErr := th.App.GetChannelUnread(th.Context, c1.Id, u1.Id)
require.Nil(t, appErr)
assert.Equal(t, int64(2), unread.MsgCount)
})
@@ -2684,32 +2684,32 @@ func TestSetChannelUnread(t *testing.T) {
require.NotNil(t, p1)
// Ensure that post have been read
unread, err := th.App.GetChannelUnread(dc.Id, u1.Id)
unread, err := th.App.GetChannelUnread(th.Context, dc.Id, u1.Id)
require.Nil(t, err)
require.Equal(t, int64(4), unread.MsgCount)
cv := &model.ChannelView{ChannelId: dc.Id}
_, appErr := th.App.ViewChannel(cv, u1.Id, s2.Id, false)
_, appErr := th.App.ViewChannel(th.Context, cv, u1.Id, s2.Id, false)
require.Nil(t, appErr)
unread, err = th.App.GetChannelUnread(dc.Id, u1.Id)
unread, err = th.App.GetChannelUnread(th.Context, dc.Id, u1.Id)
require.Nil(t, err)
require.Equal(t, int64(0), unread.MsgCount)
r, _ := th.Client.SetPostUnread(u1.Id, p.Id, false)
assert.Equal(t, 200, r.StatusCode)
unread, err = th.App.GetChannelUnread(dc.Id, u1.Id)
unread, err = th.App.GetChannelUnread(th.Context, dc.Id, u1.Id)
require.Nil(t, err)
require.Equal(t, int64(3), unread.MsgCount)
// Ensure that post have been read
_, appErr = th.App.ViewChannel(cv, u1.Id, s2.Id, false)
_, appErr = th.App.ViewChannel(th.Context, cv, u1.Id, s2.Id, false)
require.Nil(t, appErr)
unread, err = th.App.GetChannelUnread(dc.Id, u1.Id)
unread, err = th.App.GetChannelUnread(th.Context, dc.Id, u1.Id)
require.Nil(t, err)
require.Equal(t, int64(0), unread.MsgCount)
r, _ = th.Client.SetPostUnread(u1.Id, p1.Id, false)
assert.Equal(t, 200, r.StatusCode)
unread, err = th.App.GetChannelUnread(dc.Id, u1.Id)
unread, err = th.App.GetChannelUnread(th.Context, dc.Id, u1.Id)
require.Nil(t, err)
require.Equal(t, int64(1), unread.MsgCount)
})
@@ -2726,36 +2726,36 @@ func TestSetChannelUnread(t *testing.T) {
require.Nil(t, appErr)
// Ensure that post have been read
unread, err := th.App.GetChannelUnread(dc.Id, u1.Id)
unread, err := th.App.GetChannelUnread(th.Context, dc.Id, u1.Id)
require.Nil(t, err)
require.Equal(t, int64(4), unread.MsgCount)
require.Equal(t, int64(1), unread.MsgCountRoot)
cv := &model.ChannelView{ChannelId: dc.Id}
_, appErr = th.App.ViewChannel(cv, u1.Id, s2.Id, false)
_, appErr = th.App.ViewChannel(th.Context, cv, u1.Id, s2.Id, false)
require.Nil(t, appErr)
unread, err = th.App.GetChannelUnread(dc.Id, u1.Id)
unread, err = th.App.GetChannelUnread(th.Context, dc.Id, u1.Id)
require.Nil(t, err)
require.Equal(t, int64(0), unread.MsgCount)
require.Equal(t, int64(0), unread.MsgCountRoot)
r, _ := th.Client.SetPostUnread(u1.Id, rootPost.Id, false)
assert.Equal(t, 200, r.StatusCode)
unread, err = th.App.GetChannelUnread(dc.Id, u1.Id)
unread, err = th.App.GetChannelUnread(th.Context, dc.Id, u1.Id)
require.Nil(t, err)
require.Equal(t, int64(4), unread.MsgCount)
require.Equal(t, int64(1), unread.MsgCountRoot)
// Ensure that post have been read
_, appErr = th.App.ViewChannel(cv, u1.Id, s2.Id, false)
_, appErr = th.App.ViewChannel(th.Context, cv, u1.Id, s2.Id, false)
require.Nil(t, appErr)
unread, err = th.App.GetChannelUnread(dc.Id, u1.Id)
unread, err = th.App.GetChannelUnread(th.Context, dc.Id, u1.Id)
require.Nil(t, err)
require.Equal(t, int64(0), unread.MsgCount)
require.Equal(t, int64(0), unread.MsgCountRoot)
r, _ = th.Client.SetPostUnread(u1.Id, reply2.Id, false)
assert.Equal(t, 200, r.StatusCode)
unread, err = th.App.GetChannelUnread(dc.Id, u1.Id)
unread, err = th.App.GetChannelUnread(th.Context, dc.Id, u1.Id)
require.Nil(t, err)
require.Equal(t, int64(2), unread.MsgCount)
require.Equal(t, int64(0), unread.MsgCountRoot)
@@ -2764,12 +2764,12 @@ func TestSetChannelUnread(t *testing.T) {
t.Run("Unread on a private channel", func(t *testing.T) {
r, _ := th.Client.SetPostUnread(u1.Id, pp2.Id, true)
assert.Equal(t, 200, r.StatusCode)
unread, appErr := th.App.GetChannelUnread(th.BasicPrivateChannel.Id, u1.Id)
unread, appErr := th.App.GetChannelUnread(th.Context, th.BasicPrivateChannel.Id, u1.Id)
require.Nil(t, appErr)
assert.Equal(t, int64(1), unread.MsgCount)
r, _ = th.Client.SetPostUnread(u1.Id, pp1.Id, true)
assert.Equal(t, 200, r.StatusCode)
unread, appErr = th.App.GetChannelUnread(th.BasicPrivateChannel.Id, u1.Id)
unread, appErr = th.App.GetChannelUnread(th.Context, th.BasicPrivateChannel.Id, u1.Id)
require.Nil(t, appErr)
assert.Equal(t, int64(2), unread.MsgCount)
})
@@ -2843,7 +2843,7 @@ func TestSetPostUnreadWithoutCollapsedThreads(t *testing.T) {
_, err = th.Client.SetPostUnread(th.BasicUser.Id, replyPost1.Id, false)
require.NoError(t, err)
channelUnread, appErr := th.App.GetChannelUnread(th.BasicChannel.Id, th.BasicUser.Id)
channelUnread, appErr := th.App.GetChannelUnread(th.Context, th.BasicChannel.Id, th.BasicUser.Id)
require.Nil(t, appErr)
require.Equal(t, int64(3), channelUnread.MentionCount)
@@ -2891,7 +2891,7 @@ func TestSetPostUnreadWithoutCollapsedThreads(t *testing.T) {
t.Run("Mark root post as unread", func(t *testing.T) {
_, err := th.Client.SetPostUnread(th.BasicUser.Id, rootPost1.Id, false)
require.NoError(t, err)
channelUnread, appErr := th.App.GetChannelUnread(th.BasicChannel.Id, th.BasicUser.Id)
channelUnread, appErr := th.App.GetChannelUnread(th.Context, th.BasicChannel.Id, th.BasicUser.Id)
require.Nil(t, appErr)
require.Equal(t, int64(4), channelUnread.MentionCount)

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

@@ -116,7 +116,7 @@ func updatePreferences(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), post.ChannelId, model.PermissionReadChannel) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), post.ChannelId, model.PermissionReadChannel) {
c.SetPermissionError(model.PermissionReadChannel)
return
}

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

@@ -80,7 +80,7 @@ func (r *resolver) Channels(ctx context.Context, args struct {
}
// TODO: convert this to a streaming API.
channels, appErr := c.App.GetChannelsForTeamForUserWithCursor(args.TeamID, args.UserID, &model.ChannelSearchOpts{
channels, appErr := c.App.GetChannelsForTeamForUserWithCursor(c.AppContext, args.TeamID, args.UserID, &model.ChannelSearchOpts{
IncludeDeleted: args.IncludeDeleted,
LastDeleteAt: int(args.LastDeleteAt),
LastUpdateAt: int(args.LastUpdateAt),
@@ -90,7 +90,7 @@ func (r *resolver) Channels(ctx context.Context, args struct {
return nil, appErr
}
appErr = c.App.FillInChannelsProps(channels)
appErr = c.App.FillInChannelsProps(c.AppContext, channels)
if appErr != nil {
return nil, appErr
}
@@ -236,12 +236,14 @@ func (*resolver) ChannelMembers(ctx context.Context, args struct {
// If it's a single channel
if args.ChannelID != "" {
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), args.ChannelID, model.PermissionReadChannel) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), args.ChannelID, model.PermissionReadChannel) {
c.SetPermissionError(model.PermissionReadChannel)
return nil, c.Err
}
member, appErr := c.App.GetChannelMember(app.WithMaster(context.Background()), args.ChannelID, args.UserID)
ctx := c.AppContext
ctx.SetContext(app.WithMaster(ctx.Context()))
member, appErr := c.App.GetChannelMember(ctx, args.ChannelID, args.UserID)
if appErr != nil {
return nil, appErr
}
@@ -345,7 +347,7 @@ func (*resolver) SidebarCategories(ctx context.Context, args struct {
var categories *model.OrderedSidebarCategories
var appErr *model.AppError
if !args.ExcludeTeam {
categories, appErr = c.App.GetSidebarCategoriesForTeamForUser(args.UserID, args.TeamID)
categories, appErr = c.App.GetSidebarCategoriesForTeamForUser(c.AppContext, args.UserID, args.TeamID)
if appErr != nil {
return nil, appErr
}
@@ -354,7 +356,7 @@ func (*resolver) SidebarCategories(ctx context.Context, args struct {
TeamID: args.TeamID,
ExcludeTeam: args.ExcludeTeam,
}
categories, appErr = c.App.GetSidebarCategories(args.UserID, opts)
categories, appErr = c.App.GetSidebarCategories(c.AppContext, args.UserID, opts)
if appErr != nil {
return nil, appErr
}

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

@@ -36,22 +36,22 @@ func (ch *channel) Stats(ctx context.Context) (*model.ChannelStats, error) {
return nil, err
}
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), ch.Id, model.PermissionReadChannel) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), ch.Id, model.PermissionReadChannel) {
c.SetPermissionError(model.PermissionReadChannel)
return nil, c.Err
}
memberCount, appErr := c.App.GetChannelMemberCount(ch.Id)
memberCount, appErr := c.App.GetChannelMemberCount(c.AppContext, ch.Id)
if appErr != nil {
return nil, appErr
}
guestCount, appErr := c.App.GetChannelGuestCount(ch.Id)
guestCount, appErr := c.App.GetChannelGuestCount(c.AppContext, ch.Id)
if appErr != nil {
return nil, appErr
}
pinnedPostCount, appErr := c.App.GetChannelPinnedPostCount(ch.Id)
pinnedPostCount, appErr := c.App.GetChannelPinnedPostCount(c.AppContext, ch.Id)
if appErr != nil {
return nil, appErr
}

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

@@ -68,7 +68,7 @@ func graphQLChannelsLoader(ctx context.Context, keys dataloader.Keys) []*dataloa
}
func getGraphQLChannels(c *web.Context, channelIDs []string) ([]*channel, error) {
channels, appErr := c.App.GetChannels(channelIDs)
channels, appErr := c.App.GetChannels(c.AppContext, channelIDs)
if appErr != nil {
return nil, appErr
}
@@ -92,18 +92,18 @@ func getGraphQLChannels(c *web.Context, channelIDs []string) ([]*channel, error)
teamsForOpenChannels = append(teamsForOpenChannels, teamID)
}
if len(openChannels) > 0 && !c.App.SessionHasPermissionToChannels(*c.AppContext.Session(), openChannels, model.PermissionReadChannel) &&
!c.App.SessionHasPermissionToTeams(*c.AppContext.Session(), teamsForOpenChannels, model.PermissionReadPublicChannel) {
if len(openChannels) > 0 && !c.App.SessionHasPermissionToChannels(c.AppContext, *c.AppContext.Session(), openChannels, model.PermissionReadChannel) &&
!c.App.SessionHasPermissionToTeams(c.AppContext, *c.AppContext.Session(), teamsForOpenChannels, model.PermissionReadPublicChannel) {
c.SetPermissionError(model.PermissionReadPublicChannel)
return nil, c.Err
}
if len(nonOpenChannels) > 0 && !c.App.SessionHasPermissionToChannels(*c.AppContext.Session(), nonOpenChannels, model.PermissionReadChannel) {
if len(nonOpenChannels) > 0 && !c.App.SessionHasPermissionToChannels(c.AppContext, *c.AppContext.Session(), nonOpenChannels, model.PermissionReadChannel) {
c.SetPermissionError(model.PermissionReadChannel)
return nil, c.Err
}
appErr = c.App.FillInChannelsProps(model.ChannelList(channels))
appErr = c.App.FillInChannelsProps(c.AppContext, model.ChannelList(channels))
if appErr != nil {
return nil, appErr
}

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

@@ -24,8 +24,8 @@ func TestGraphQLChannelMembers(t *testing.T) {
ch1 := th.CreateChannelWithClientAndTeam(th.Client, model.ChannelTypeOpen, myTeam.Id)
ch2 := th.CreateChannelWithClientAndTeam(th.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)
// Creating some msgcount
th.CreateMessagePostWithClient(th.Client, th.BasicChannel, "basic post")

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

@@ -24,8 +24,8 @@ func TestGraphQLChannels(t *testing.T) {
ch1 := th.CreateChannelWithClientAndTeam(th.Client, model.ChannelTypeOpen, myTeam.Id)
ch2 := th.CreateChannelWithClientAndTeam(th.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)
th.CreateDmChannel(th.BasicUser2)
var q struct {
@@ -413,7 +413,7 @@ func TestGraphQLChannels(t *testing.T) {
require.Len(t, q.Channels, 3)
for _, ch := range q.Channels {
require.Equal(t, ch.ID, ch.Stats.ChannelId)
count, appErr := th.App.GetChannelMemberCount(ch.Stats.ChannelId)
count, appErr := th.App.GetChannelMemberCount(th.Context, ch.Stats.ChannelId)
require.Nil(t, appErr)
require.Equal(t, float64(count), ch.Stats.MemberCount)
}

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

@@ -101,8 +101,8 @@ func TestGraphQLSidebarCategories(t *testing.T) {
ch1 := th.CreateChannelWithClientAndTeam(th.Client, model.ChannelTypeOpen, myTeam.Id)
ch2 := th.CreateChannelWithClientAndTeam(th.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)
input = graphQLInput{
OperationName: "sidebarCategories",

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

@@ -71,7 +71,7 @@ func getGraphQLTeams(c *web.Context, teamIDs []string) ([]*model.Team, error) {
}
}
if !c.App.SessionHasPermissionToTeams(*c.AppContext.Session(), teamsToCheck, model.PermissionViewMembers) {
if !c.App.SessionHasPermissionToTeams(c.AppContext, *c.AppContext.Session(), teamsToCheck, model.PermissionViewMembers) {
c.SetPermissionError(model.PermissionViewTeam)
return nil, c.Err
}

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

@@ -179,8 +179,8 @@ func TestGraphQLTeamMembers(t *testing.T) {
ch1 := th.CreateChannelWithClientAndTeam(th.Client, model.ChannelTypeOpen, myTeam.Id)
ch2 := th.CreateChannelWithClientAndTeam(th.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)
input := graphQLInput{
OperationName: "teamMembers",

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

@@ -44,7 +44,7 @@ func TestGetAllSharedChannels(t *testing.T) {
CreatorId: th.BasicChannel.CreatorId,
RemoteId: model.NewId(),
}
_, err := th.App.SaveSharedChannel(sc)
_, err := th.App.SaveSharedChannel(th.Context, sc)
require.NoError(t, err)
savedIds = append(savedIds, channel.Id)
}
@@ -124,7 +124,7 @@ func TestGetRemoteClusterById(t *testing.T) {
CreatorId: th.BasicChannel.CreatorId,
RemoteId: rc.RemoteId,
}
sc, err := th.App.SaveSharedChannel(sc)
sc, err := th.App.SaveSharedChannel(th.Context, sc)
require.NoError(t, err)
// create a shared channel remote to connect them

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

@@ -569,7 +569,7 @@ func pushNotificationAck(c *Context, w http.ResponseWriter, r *http.Request) {
// Return post data only when PostId is passed.
if ack.PostId != "" && ack.NotificationType == model.PushTypeMessage {
if _, appErr := c.App.GetPostIfAuthorized(ack.PostId, c.AppContext.Session(), false); appErr != nil {
if _, appErr := c.App.GetPostIfAuthorized(c.AppContext, ack.PostId, c.AppContext.Session(), false); appErr != nil {
c.Err = appErr
return
}

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

@@ -431,7 +431,7 @@ func deleteTeam(c *Context, w http.ResponseWriter, r *http.Request) {
var err *model.AppError
if c.Params.Permanent {
if *c.App.Config().ServiceSettings.EnableAPITeamDeletion {
err = c.App.PermanentDeleteTeamId(c.Params.TeamId)
err = c.App.PermanentDeleteTeamId(c.AppContext, c.Params.TeamId)
} else {
err = model.NewAppError("deleteTeam", "api.user.delete_team.not_enabled.app_error", nil, "teamId="+c.Params.TeamId, http.StatusUnauthorized)
}

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

@@ -52,7 +52,7 @@ func localDeleteTeam(c *Context, w http.ResponseWriter, r *http.Request) {
var err *model.AppError
if c.Params.Permanent {
err = c.App.PermanentDeleteTeamId(c.Params.TeamId)
err = c.App.PermanentDeleteTeamId(c.AppContext, c.Params.TeamId)
} else {
err = c.App.SoftDeleteTeam(c.Params.TeamId)
}

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

@@ -54,7 +54,7 @@ func createUpload(c *Context, w http.ResponseWriter, r *http.Request) {
}
} else {
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), us.ChannelId, model.PermissionUploadFile) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), us.ChannelId, model.PermissionUploadFile) {
c.SetPermissionError(model.PermissionUploadFile)
return
}
@@ -65,7 +65,7 @@ func createUpload(c *Context, w http.ResponseWriter, r *http.Request) {
if c.AppContext.Session().UserId != "" {
us.UserId = c.AppContext.Session().UserId
}
rus, err := c.App.CreateUploadSession(&us)
rus, err := c.App.CreateUploadSession(c.AppContext, &us)
if err != nil {
c.Err = err
return
@@ -132,7 +132,7 @@ func uploadData(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
} else {
if us.UserId != c.AppContext.Session().UserId || !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), us.ChannelId, model.PermissionUploadFile) {
if us.UserId != c.AppContext.Session().UserId || !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), us.ChannelId, model.PermissionUploadFile) {
c.SetPermissionError(model.PermissionUploadFile)
return
}

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

@@ -116,7 +116,7 @@ func TestGetUpload(t *testing.T) {
Filename: "upload",
FileSize: 8 * 1024 * 1024,
}
us, err := th.App.CreateUploadSession(us)
us, err := th.App.CreateUploadSession(th.Context, us)
require.Nil(t, err)
require.NotNil(t, us)
require.NotEmpty(t, us)
@@ -176,7 +176,7 @@ func TestGetUploadsForUser(t *testing.T) {
Filename: "upload",
FileSize: 8 * 1024 * 1024,
}
us, err := th.App.CreateUploadSession(us)
us, err := th.App.CreateUploadSession(th.Context, us)
require.Nil(t, err)
require.NotNil(t, us)
require.NotEmpty(t, us)
@@ -210,7 +210,7 @@ func TestUploadData(t *testing.T) {
Filename: "upload",
FileSize: 8 * 1024 * 1024,
}
us, err := th.App.CreateUploadSession(us)
us, err := th.App.CreateUploadSession(th.Context, us)
require.Nil(t, err)
require.NotNil(t, us)
require.NotEmpty(t, us)
@@ -251,7 +251,7 @@ func TestUploadData(t *testing.T) {
Filename: "upload",
FileSize: 8 * 1024 * 1024,
}
_, appErr := th.App.CreateUploadSession(us2)
_, appErr := th.App.CreateUploadSession(th.Context, us2)
require.Nil(t, appErr)
info, resp, err := th.SystemAdminClient.UploadData(us2.Id, bytes.NewReader(data))

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

@@ -739,7 +739,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
if inChannelId != "" {
if !*c.App.Config().TeamSettings.ExperimentalViewArchivedChannels {
channel, appErr := c.App.GetChannel(inChannelId)
channel, appErr := c.App.GetChannel(c.AppContext, inChannelId)
if appErr != nil {
c.Err = appErr
return
@@ -760,7 +760,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
profiles, err = c.App.GetUsersWithoutTeamPage(userGetOptions, c.IsSystemAdmin())
} else if notInChannelId != "" {
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), notInChannelId, model.PermissionReadChannel) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), notInChannelId, model.PermissionReadChannel) {
c.SetPermissionError(model.PermissionReadChannel)
return
}
@@ -796,7 +796,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
profiles, err = c.App.GetUsersInTeamPage(userGetOptions, c.IsSystemAdmin())
}
} else if inChannelId != "" {
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), inChannelId, model.PermissionReadChannel) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), inChannelId, model.PermissionReadChannel) {
c.SetPermissionError(model.PermissionReadChannel)
return
}
@@ -1002,12 +1002,12 @@ func searchUsers(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
if props.InChannelId != "" && !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), props.InChannelId, model.PermissionReadChannel) {
if props.InChannelId != "" && !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), props.InChannelId, model.PermissionReadChannel) {
c.SetPermissionError(model.PermissionReadChannel)
return
}
if props.NotInChannelId != "" && !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), props.NotInChannelId, model.PermissionReadChannel) {
if props.NotInChannelId != "" && !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), props.NotInChannelId, model.PermissionReadChannel) {
c.SetPermissionError(model.PermissionReadChannel)
return
}
@@ -1093,7 +1093,7 @@ func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) {
}
if channelId != "" {
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), channelId, model.PermissionReadChannel) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), channelId, model.PermissionReadChannel) {
c.SetPermissionError(model.PermissionReadChannel)
return
}
@@ -2697,7 +2697,7 @@ func demoteUserToGuest(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if err := c.App.DemoteUserToGuest(user); err != nil {
if err := c.App.DemoteUserToGuest(c.AppContext, user); err != nil {
c.Err = err
return
}
@@ -2723,7 +2723,7 @@ func publishUserTyping(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if !c.App.HasPermissionToChannel(c.Params.UserId, typingRequest.ChannelId, model.PermissionCreatePost) {
if !c.App.HasPermissionToChannel(c.AppContext, c.Params.UserId, typingRequest.ChannelId, model.PermissionCreatePost) {
c.SetPermissionError(model.PermissionCreatePost)
return
}
@@ -2846,7 +2846,7 @@ func getChannelMembersForUser(c *Context, w http.ResponseWriter, r *http.Request
return
}
members, err := c.App.GetChannelMembersWithTeamDataForUserWithPagination(c.Params.UserId, c.Params.Page, c.Params.PerPage)
members, err := c.App.GetChannelMembersWithTeamDataForUserWithPagination(c.AppContext, c.Params.UserId, c.Params.Page, c.Params.PerPage)
if err != nil {
c.Err = err
return
@@ -3092,7 +3092,7 @@ func updateReadStateThreadByUser(c *Context, w http.ResponseWriter, r *http.Requ
return
}
thread, err := c.App.UpdateThreadReadForUser(c.AppContext.Session().Id, c.Params.UserId, c.Params.TeamId, c.Params.ThreadId, c.Params.Timestamp)
thread, err := c.App.UpdateThreadReadForUser(c.AppContext, c.AppContext.Session().Id, c.Params.UserId, c.Params.TeamId, c.Params.ThreadId, c.Params.Timestamp)
if err != nil {
c.Err = err
return
@@ -3128,7 +3128,7 @@ func setUnreadThreadByPostId(c *Context, w http.ResponseWriter, r *http.Request)
return
}
thread, err := c.App.UpdateThreadReadForUserByPost(c.AppContext.Session().Id, c.Params.UserId, c.Params.TeamId, c.Params.ThreadId, c.Params.PostId)
thread, err := c.App.UpdateThreadReadForUserByPost(c.AppContext, c.AppContext.Session().Id, c.Params.UserId, c.Params.TeamId, c.Params.ThreadId, c.Params.PostId)
if err != nil {
c.Err = err
return

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

@@ -408,7 +408,7 @@ func TestCreateUserWebSocketEvent(t *testing.T) {
_, _, errr = th.App.AddUserToTeam(th.Context, th.BasicTeam.Id, guest.Id, "")
require.Nil(t, errr)
_, errr = th.App.AddUserToChannel(guest, th.BasicChannel, false)
_, errr = th.App.AddUserToChannel(th.Context, guest, th.BasicChannel, false)
require.Nil(t, errr)
guestClient := th.CreateClient()
@@ -1603,7 +1603,7 @@ func TestGetUsersByGroupChannelIds(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
gc1, appErr := th.App.CreateGroupChannel([]string{th.BasicUser.Id, th.SystemAdminUser.Id, th.TeamAdminUser.Id}, th.BasicUser.Id)
gc1, appErr := th.App.CreateGroupChannel(th.Context, []string{th.BasicUser.Id, th.SystemAdminUser.Id, th.TeamAdminUser.Id}, th.BasicUser.Id)
require.Nil(t, appErr)
usersByChannelId, _, err := th.Client.GetUsersByGroupChannelIds([]string{gc1.Id})
@@ -2124,7 +2124,7 @@ func TestPermanentDeleteAllUsers(t *testing.T) {
require.Nil(t, appErr)
require.NotNil(t, rTeam)
rChannel, appErr := th.App.GetChannel(channel.Id)
rChannel, appErr := th.App.GetChannel(th.Context, channel.Id)
require.Nil(t, appErr)
require.NotNil(t, rChannel)
})
@@ -2627,9 +2627,9 @@ func TestGetUsersInChannel(t *testing.T) {
TeamId: th.BasicTeam.Id,
})
require.NoError(t, appErr)
_, aErr := th.App.AddUserToChannel(th.BasicUser, channel, false)
_, aErr := th.App.AddUserToChannel(th.Context, th.BasicUser, channel, false)
require.Nil(t, aErr)
_, aErr = th.App.AddUserToChannel(th.BasicUser2, channel, false)
_, aErr = th.App.AddUserToChannel(th.Context, th.BasicUser2, channel, false)
require.Nil(t, aErr)
th.SystemAdminClient.DeleteChannel(channel.Id)
@@ -5228,7 +5228,7 @@ func TestPromoteGuestToUser(t *testing.T) {
_, err = c.PromoteGuestToUser(user.Id)
require.NoError(t, err)
defer require.Nil(t, th.App.DemoteUserToGuest(user))
defer require.Nil(t, th.App.DemoteUserToGuest(th.Context, user))
}, "promote a guest to user")
t.Run("websocket update user event", func(t *testing.T) {
@@ -5371,11 +5371,11 @@ func TestGetKnownUsers(t *testing.T) {
th.LinkUserToTeam(u3, t2)
th.LinkUserToTeam(u4, t3)
th.App.AddUserToChannel(u1, c1, false)
th.App.AddUserToChannel(u1, c2, false)
th.App.AddUserToChannel(u2, c1, false)
th.App.AddUserToChannel(u3, c2, false)
th.App.AddUserToChannel(u4, c3, false)
th.App.AddUserToChannel(th.Context, u1, c1, false)
th.App.AddUserToChannel(th.Context, u1, c2, false)
th.App.AddUserToChannel(th.Context, u2, c1, false)
th.App.AddUserToChannel(th.Context, u3, c2, false)
th.App.AddUserToChannel(th.Context, u4, c3, false)
t.Run("get know users sharing no channels", func(t *testing.T) {
_, _, _ = th.Client.Login(u4.Email, u4.Password)
@@ -6214,7 +6214,7 @@ func TestFollowThreads(t *testing.T) {
t.Run("No permission to channel", func(t *testing.T) {
// Add user1 to private channel
_, appErr := th.App.AddUserToChannel(th.BasicUser, th.BasicPrivateChannel2, false)
_, appErr := th.App.AddUserToChannel(th.Context, th.BasicUser, th.BasicPrivateChannel2, false)
require.Nil(t, appErr)
defer th.App.RemoveUserFromChannel(th.Context, th.BasicUser.Id, "", th.BasicPrivateChannel2)

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

@@ -34,7 +34,7 @@ func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
channel, err := c.App.GetChannel(hook.ChannelId)
channel, err := c.App.GetChannel(c.AppContext, hook.ChannelId)
if err != nil {
c.Err = err
return
@@ -50,7 +50,7 @@ func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if channel.Type != model.ChannelTypeOpen && !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), channel.Id, model.PermissionReadChannel) {
if channel.Type != model.ChannelTypeOpen && !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), channel.Id, model.PermissionReadChannel) {
c.LogAudit("fail - bad channel permissions")
c.SetPermissionError(model.PermissionReadChannel)
return
@@ -127,7 +127,7 @@ func updateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
channel, err := c.App.GetChannel(updatedHook.ChannelId)
channel, err := c.App.GetChannel(c.AppContext, updatedHook.ChannelId)
if err != nil {
c.Err = err
return
@@ -151,7 +151,7 @@ func updateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if channel.Type != model.ChannelTypeOpen && !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), channel.Id, model.PermissionReadChannel) {
if channel.Type != model.ChannelTypeOpen && !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), channel.Id, model.PermissionReadChannel) {
c.LogAudit("fail - bad channel permissions")
c.SetPermissionError(model.PermissionReadChannel)
return
@@ -244,14 +244,14 @@ func getIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec.AddMeta("team_id", hook.TeamId)
c.LogAudit("attempt")
channel, err = c.App.GetChannel(hook.ChannelId)
channel, err = c.App.GetChannel(c.AppContext, hook.ChannelId)
if err != nil {
c.Err = err
return
}
if !c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), hook.TeamId, model.PermissionManageIncomingWebhooks) ||
(channel.Type != model.ChannelTypeOpen && !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), hook.ChannelId, model.PermissionReadChannel)) {
(channel.Type != model.ChannelTypeOpen && !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), hook.ChannelId, model.PermissionReadChannel)) {
c.LogAudit("fail - bad permissions")
c.SetPermissionError(model.PermissionManageIncomingWebhooks)
return
@@ -289,7 +289,7 @@ func deleteIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
channel, err = c.App.GetChannel(hook.ChannelId)
channel, err = c.App.GetChannel(c.AppContext, hook.ChannelId)
if err != nil {
c.Err = err
return
@@ -304,7 +304,7 @@ func deleteIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec.AddMeta("team_id", hook.TeamId)
if !c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), hook.TeamId, model.PermissionManageIncomingWebhooks) ||
(channel.Type != model.ChannelTypeOpen && !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), hook.ChannelId, model.PermissionReadChannel)) {
(channel.Type != model.ChannelTypeOpen && !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), hook.ChannelId, model.PermissionReadChannel)) {
c.LogAudit("fail - bad permissions")
c.SetPermissionError(model.PermissionManageIncomingWebhooks)
return
@@ -379,7 +379,7 @@ func updateOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
updatedHook.CreatorId = c.AppContext.Session().UserId
rhook, err := c.App.UpdateOutgoingWebhook(oldHook, &updatedHook)
rhook, err := c.App.UpdateOutgoingWebhook(c.AppContext, oldHook, &updatedHook)
if err != nil {
c.Err = err
return
@@ -454,13 +454,13 @@ func getOutgoingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
var err *model.AppError
if channelId != "" {
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), channelId, model.PermissionManageOutgoingWebhooks) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), channelId, model.PermissionManageOutgoingWebhooks) {
c.SetPermissionError(model.PermissionManageOutgoingWebhooks)
return
}
// Remove userId as a filter if they have permission to manage others.
if c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), channelId, model.PermissionManageOthersOutgoingWebhooks) {
if c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), channelId, model.PermissionManageOthersOutgoingWebhooks) {
userId = ""
}

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

@@ -38,7 +38,7 @@ func localCreateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request)
return
}
channel, err := c.App.GetChannel(hook.ChannelId)
channel, err := c.App.GetChannel(c.AppContext, hook.ChannelId)
if err != nil {
c.Err = err
return