mirror of
https://github.com/mattermost/mattermost.git
synced 2026-09-19 10:12:47 +08:00
MM-45193 Use context for channel logging (#20575)
This commit is contained in:
+11
-10
@@ -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)
|
||||
}
|
||||
|
||||
+136
-134
File diff suppressed because it is too large
Load Diff
+19
-19
@@ -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
|
||||
|
||||
+17
-17
@@ -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, "")
|
||||
}
|
||||
|
||||
+41
-41
@@ -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)
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
+3
-3
@@ -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
|
||||
}
|
||||
|
||||
+6
-6
@@ -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
-9
@@ -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
|
||||
}
|
||||
|
||||
+14
-14
@@ -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
|
||||
}
|
||||
|
||||
+30
-30
@@ -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
|
||||
|
||||
+27
-27
@@ -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)
|
||||
|
||||
+1
-1
@@ -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
|
||||
}
|
||||
|
||||
+8
-6
@@ -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
|
||||
|
||||
+1
-1
@@ -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
|
||||
}
|
||||
|
||||
+1
-1
@@ -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)
|
||||
}
|
||||
|
||||
+1
-1
@@ -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)
|
||||
}
|
||||
|
||||
+3
-3
@@ -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
|
||||
}
|
||||
|
||||
+4
-4
@@ -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))
|
||||
|
||||
+11
-11
@@ -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
|
||||
|
||||
+12
-12
@@ -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)
|
||||
|
||||
|
||||
+11
-11
@@ -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
|
||||
|
||||
+133
-133
@@ -44,7 +44,7 @@ type AppIface interface {
|
||||
// @openTracingParams teamID, skipSlackParsing
|
||||
CreateCommandPost(c *request.Context, post *model.Post, teamID string, response *model.CommandResponse, skipSlackParsing bool) (*model.Post, *model.AppError)
|
||||
// AddChannelMember adds a user to a channel. It is a wrapper over AddUserToChannel.
|
||||
AddChannelMember(c *request.Context, userID string, channel *model.Channel, opts ChannelMemberOpts) (*model.ChannelMember, *model.AppError)
|
||||
AddChannelMember(c request.CTX, userID string, channel *model.Channel, opts ChannelMemberOpts) (*model.ChannelMember, *model.AppError)
|
||||
// AddCursorIdsForPostList adds NextPostId and PrevPostId as cursor to the PostList.
|
||||
// The conditional blocks ensure that it sets those cursor IDs immediately as afterPost, beforePost or empty,
|
||||
// and only query to database whenever necessary.
|
||||
@@ -52,7 +52,7 @@ type AppIface interface {
|
||||
// AddPublicKey will add plugin public key to the config. Overwrites the previous file
|
||||
AddPublicKey(name string, key io.Reader) *model.AppError
|
||||
// AddUserToChannel adds a user to a given channel.
|
||||
AddUserToChannel(user *model.User, channel *model.Channel, skipTeamMemberIntegrityCheck bool) (*model.ChannelMember, *model.AppError)
|
||||
AddUserToChannel(c request.CTX, user *model.User, channel *model.Channel, skipTeamMemberIntegrityCheck bool) (*model.ChannelMember, *model.AppError)
|
||||
// Caller must close the first return value
|
||||
FileReader(path string) (filestore.ReadCloseSeeker, *model.AppError)
|
||||
// ChannelMembersMinusGroupMembers returns the set of users in the given channel minus the set of users in the given
|
||||
@@ -86,7 +86,7 @@ type AppIface interface {
|
||||
// CreateBot creates the given bot and corresponding user.
|
||||
CreateBot(c *request.Context, bot *model.Bot) (*model.Bot, *model.AppError)
|
||||
// CreateChannelScheme creates a new Scheme of scope channel and assigns it to the channel.
|
||||
CreateChannelScheme(channel *model.Channel) (*model.Scheme, *model.AppError)
|
||||
CreateChannelScheme(c request.CTX, channel *model.Channel) (*model.Scheme, *model.AppError)
|
||||
// CreateDefaultMemberships adds users to teams and channels based on their group memberships and how those groups
|
||||
// are configured to sync with teams and channels for group members on or after the given timestamp.
|
||||
// If includeRemovedMembers is true, then members who left or were removed from a team/channel will
|
||||
@@ -108,9 +108,9 @@ type AppIface interface {
|
||||
// 'off-topic' and be included in the return results in addition to 'town-square'. For example:
|
||||
// ['town-square', 'game-of-thrones', 'wow']
|
||||
//
|
||||
DefaultChannelNames() []string
|
||||
DefaultChannelNames(c request.CTX) []string
|
||||
// DeleteChannelScheme deletes a channels scheme and sets its SchemeId to nil.
|
||||
DeleteChannelScheme(channel *model.Channel) (*model.Channel, *model.AppError)
|
||||
DeleteChannelScheme(c request.CTX, channel *model.Channel) (*model.Channel, *model.AppError)
|
||||
// DeleteGroupConstrainedMemberships deletes team and channel memberships of users who aren't members of the allowed
|
||||
// groups of all group-constrained teams and channels.
|
||||
DeleteGroupConstrainedMemberships(c *request.Context) error
|
||||
@@ -118,7 +118,7 @@ type AppIface interface {
|
||||
DeletePublicKey(name string) *model.AppError
|
||||
// DemoteUserToGuest Convert user's roles and all his membership's roles from
|
||||
// regular user roles to guest roles.
|
||||
DemoteUserToGuest(user *model.User) *model.AppError
|
||||
DemoteUserToGuest(c request.CTX, user *model.User) *model.AppError
|
||||
// DisablePlugin will set the config for an installed plugin to disabled, triggering deactivation if active.
|
||||
// Notifies cluster peers through config change.
|
||||
DisablePlugin(id string) *model.AppError
|
||||
@@ -146,7 +146,7 @@ type AppIface interface {
|
||||
// channel_mentions.
|
||||
//
|
||||
// If channel is nil, FillInPostProps will look up the channel corresponding to the post.
|
||||
FillInPostProps(post *model.Post, channel *model.Channel) *model.AppError
|
||||
FillInPostProps(c request.CTX, post *model.Post, channel *model.Channel) *model.AppError
|
||||
// FilterNonGroupChannelMembers returns the subset of the given user IDs of the users who are not members of groups
|
||||
// associated to the channel excluding bots
|
||||
FilterNonGroupChannelMembers(userIDs []string, channel *model.Channel) ([]string, error)
|
||||
@@ -163,7 +163,7 @@ type AppIface interface {
|
||||
// GetChannelGroupUsers returns the users who are associated to the channel via GroupChannels and GroupMembers.
|
||||
GetChannelGroupUsers(channelID string) ([]*model.User, *model.AppError)
|
||||
// GetChannelModerationsForChannel Gets a channels ChannelModerations from either the higherScoped roles or from the channel scheme roles.
|
||||
GetChannelModerationsForChannel(channel *model.Channel) ([]*model.ChannelModeration, *model.AppError)
|
||||
GetChannelModerationsForChannel(c request.CTX, channel *model.Channel) ([]*model.ChannelModeration, *model.AppError)
|
||||
// GetClusterPluginStatuses returns the status for plugins installed anywhere in the cluster.
|
||||
GetClusterPluginStatuses() (model.PluginStatuses, *model.AppError)
|
||||
// GetConfigFile proxies access to the given configuration file to the underlying config store.
|
||||
@@ -213,7 +213,7 @@ type AppIface interface {
|
||||
// GetSanitizedConfig gets the configuration for a system admin without any secrets.
|
||||
GetSanitizedConfig() *model.Config
|
||||
// GetSchemeRolesForChannel Checks if a channel or its team has an override scheme for channel roles and returns the scheme roles or default channel roles.
|
||||
GetSchemeRolesForChannel(channelID string) (guestRoleName string, userRoleName string, adminRoleName string, err *model.AppError)
|
||||
GetSchemeRolesForChannel(c request.CTX, channelID string) (guestRoleName string, userRoleName string, adminRoleName string, err *model.AppError)
|
||||
// GetSessionLengthInMillis returns the session length, in milliseconds,
|
||||
// based on the type of session (Mobile, SSO, Web/LDAP).
|
||||
GetSessionLengthInMillis(session *model.Session) int64
|
||||
@@ -224,7 +224,7 @@ type AppIface interface {
|
||||
// GetTeamGroupUsers returns the users who are associated to the team via GroupTeams and GroupMembers.
|
||||
GetTeamGroupUsers(teamID string) ([]*model.User, *model.AppError)
|
||||
// GetTeamSchemeChannelRoles Checks if a team has an override scheme and returns the scheme channel role names or default channel role names.
|
||||
GetTeamSchemeChannelRoles(teamID string) (guestRoleName string, userRoleName string, adminRoleName string, err *model.AppError)
|
||||
GetTeamSchemeChannelRoles(c request.CTX, teamID string) (guestRoleName string, userRoleName string, adminRoleName string, err *model.AppError)
|
||||
// GetTotalUsersStats is used for the DM list total
|
||||
GetTotalUsersStats(viewRestrictions *model.ViewUsersRestrictions) (*model.UsersStats, *model.AppError)
|
||||
// HasRemote returns whether a given channelID is present in the channel remotes or not.
|
||||
@@ -244,16 +244,16 @@ type AppIface interface {
|
||||
// MakeAuditRecord creates a audit record pre-populated with defaults.
|
||||
MakeAuditRecord(event string, initialStatus string) *audit.Record
|
||||
// MarkChanelAsUnreadFromPost will take a post and set the channel as unread from that one.
|
||||
MarkChannelAsUnreadFromPost(postID string, userID string, collapsedThreadsSupported bool) (*model.ChannelUnreadAt, *model.AppError)
|
||||
MarkChannelAsUnreadFromPost(c request.CTX, postID string, userID string, collapsedThreadsSupported bool) (*model.ChannelUnreadAt, *model.AppError)
|
||||
// MentionsToPublicChannels returns all the mentions to public channels,
|
||||
// linking them to their channels
|
||||
MentionsToPublicChannels(message, teamID string) model.ChannelMentionMap
|
||||
MentionsToPublicChannels(c request.CTX, message, teamID string) model.ChannelMentionMap
|
||||
// MentionsToTeamMembers returns all the @ mentions found in message that
|
||||
// belong to users in the specified team, linking them to their users
|
||||
MentionsToTeamMembers(message, teamID string) model.UserMentionMap
|
||||
// MoveChannel method is prone to data races if someone joins to channel during the move process. However this
|
||||
// function is only exposed to sysadmins and the possibility of this edge case is relatively small.
|
||||
MoveChannel(c *request.Context, team *model.Team, channel *model.Channel, user *model.User) *model.AppError
|
||||
MoveChannel(c request.CTX, team *model.Team, channel *model.Channel, user *model.User) *model.AppError
|
||||
// NewWebConn returns a new WebConn instance.
|
||||
NewWebConn(cfg *WebConnConfig) *WebConn
|
||||
// NotifySessionsExpired is called periodically from the job server to notify any mobile sessions that have expired.
|
||||
@@ -264,7 +264,7 @@ type AppIface interface {
|
||||
// PatchBot applies the given patch to the bot and corresponding user.
|
||||
PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot, *model.AppError)
|
||||
// PatchChannelModerationsForChannel Updates a channels scheme roles based on a given ChannelModerationPatch, if the permissions match the higher scoped role the scheme is deleted.
|
||||
PatchChannelModerationsForChannel(channel *model.Channel, channelModerationsPatch []*model.ChannelModerationPatch) ([]*model.ChannelModeration, *model.AppError)
|
||||
PatchChannelModerationsForChannel(c request.CTX, channel *model.Channel, channelModerationsPatch []*model.ChannelModerationPatch) ([]*model.ChannelModeration, *model.AppError)
|
||||
// Perform an HTTP POST request to an integration's action endpoint.
|
||||
// Caller must consume and close returned http.Response as necessary.
|
||||
// For internal requests, requests are routed directly to a plugin ServerHTTP hook
|
||||
@@ -279,12 +279,12 @@ type AppIface interface {
|
||||
// use a sinceUnixMillis parameter value as returned by model.GetStartOfDayMillis.
|
||||
//
|
||||
// WARNING: PostCountsByDuration PERFORMS NO AUTHORIZATION CHECKS ON THE GIVEN CHANNELS.
|
||||
PostCountsByDuration(channelIDs []string, sinceUnixMillis int64, userID *string, grouping model.PostCountGrouping, groupingLocation *time.Location) ([]*model.DurationPostCount, *model.AppError)
|
||||
PostCountsByDuration(c request.CTX, channelIDs []string, sinceUnixMillis int64, userID *string, grouping model.PostCountGrouping, groupingLocation *time.Location) ([]*model.DurationPostCount, *model.AppError)
|
||||
// PromoteGuestToUser Convert user's roles and all his membership's roles from
|
||||
// guest roles to regular user roles.
|
||||
PromoteGuestToUser(c *request.Context, user *model.User, requestorId string) *model.AppError
|
||||
// RenameChannel is used to rename the channel Name and the DisplayName fields
|
||||
RenameChannel(channel *model.Channel, newChannelName string, newDisplayName string) (*model.Channel, *model.AppError)
|
||||
RenameChannel(c request.CTX, channel *model.Channel, newChannelName string, newDisplayName string) (*model.Channel, *model.AppError)
|
||||
// RenameTeam is used to rename the team Name and the DisplayName fields
|
||||
RenameTeam(team *model.Team, newTeamName string, newDisplayName string) (*model.Team, *model.AppError)
|
||||
// RevokeSessionsFromAllUsers will go through all the sessions active
|
||||
@@ -293,19 +293,19 @@ type AppIface interface {
|
||||
// SaveConfig replaces the active configuration, optionally notifying cluster peers.
|
||||
SaveConfig(newCfg *model.Config, sendConfigChangeClusterMessage bool) (*model.Config, *model.Config, *model.AppError)
|
||||
// SearchAllChannels returns a list of channels, the total count of the results of the search (if the paginate search option is true), and an error.
|
||||
SearchAllChannels(term string, opts model.ChannelSearchOpts) (model.ChannelListWithTeamData, int64, *model.AppError)
|
||||
SearchAllChannels(c request.CTX, term string, opts model.ChannelSearchOpts) (model.ChannelListWithTeamData, int64, *model.AppError)
|
||||
// SearchAllTeams returns a team list and the total count of the results
|
||||
SearchAllTeams(searchOpts *model.TeamSearch) ([]*model.Team, int64, *model.AppError)
|
||||
// SendNoCardPaymentFailedEmail
|
||||
SendNoCardPaymentFailedEmail() *model.AppError
|
||||
// SessionHasPermissionToChannels returns true only if user has access to all channels.
|
||||
SessionHasPermissionToChannels(session model.Session, channelIDs []string, permission *model.Permission) bool
|
||||
SessionHasPermissionToChannels(c request.CTX, session model.Session, channelIDs []string, permission *model.Permission) bool
|
||||
// SessionHasPermissionToManageBot returns nil if the session has access to manage the given bot.
|
||||
// This function deviates from other authorization checks in returning an error instead of just
|
||||
// a boolean, allowing the permission failure to be exposed with more granularity.
|
||||
SessionHasPermissionToManageBot(session model.Session, botUserId string) *model.AppError
|
||||
// SessionHasPermissionToTeams returns true only if user has access to all teams.
|
||||
SessionHasPermissionToTeams(session model.Session, teamIDs []string, permission *model.Permission) bool
|
||||
SessionHasPermissionToTeams(c request.CTX, session model.Session, teamIDs []string, permission *model.Permission) bool
|
||||
// SessionIsRegistered determines if a specific session has been registered
|
||||
SessionIsRegistered(session model.Session) bool
|
||||
// SetSessionExpireInHours sets the session's expiry the specified number of hours
|
||||
@@ -358,9 +358,9 @@ type AppIface interface {
|
||||
// UpdateBotOwner changes a bot's owner to the given value.
|
||||
UpdateBotOwner(botUserId, newOwnerId string) (*model.Bot, *model.AppError)
|
||||
// UpdateChannel updates a given channel by its Id. It also publishes the CHANNEL_UPDATED event.
|
||||
UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError)
|
||||
UpdateChannel(c request.CTX, channel *model.Channel) (*model.Channel, *model.AppError)
|
||||
// UpdateChannelScheme saves the new SchemeId of the channel passed.
|
||||
UpdateChannelScheme(channel *model.Channel) (*model.Channel, *model.AppError)
|
||||
UpdateChannelScheme(c request.CTX, channel *model.Channel) (*model.Channel, *model.AppError)
|
||||
// UpdateDNDStatusOfUsers is a recurring task which is started when server starts
|
||||
// which unsets dnd status of users if needed and saves and broadcasts it
|
||||
UpdateDNDStatusOfUsers()
|
||||
@@ -396,7 +396,7 @@ type AppIface interface {
|
||||
ActivateMfa(userID, token string) *model.AppError
|
||||
AddChannelsToRetentionPolicy(policyID string, channelIDs []string) *model.AppError
|
||||
AddConfigListener(listener func(*model.Config, *model.Config)) string
|
||||
AddDirectChannels(teamID string, user *model.User) *model.AppError
|
||||
AddDirectChannels(c request.CTX, teamID string, user *model.User) *model.AppError
|
||||
AddLdapPrivateCertificate(fileData *multipart.FileHeader) *model.AppError
|
||||
AddLdapPublicCertificate(fileData *multipart.FileHeader) *model.AppError
|
||||
AddRemoteCluster(rc *model.RemoteCluster) (*model.RemoteCluster, *model.AppError)
|
||||
@@ -426,14 +426,14 @@ type AppIface interface {
|
||||
AttachSessionCookies(c *request.Context, w http.ResponseWriter, r *http.Request)
|
||||
AuthenticateUserForLogin(c *request.Context, id, loginId, password, mfaToken, cwsToken string, ldapOnly bool) (user *model.User, err *model.AppError)
|
||||
AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service, code, state, redirectURI string) (io.ReadCloser, string, map[string]string, *model.User, *model.AppError)
|
||||
AutocompleteChannels(userID, term string) (model.ChannelListWithTeamData, *model.AppError)
|
||||
AutocompleteChannelsForSearch(teamID string, userID string, term string) (model.ChannelList, *model.AppError)
|
||||
AutocompleteChannelsForTeam(teamID, userID, term string) (model.ChannelList, *model.AppError)
|
||||
AutocompleteChannels(c request.CTX, userID, term string) (model.ChannelListWithTeamData, *model.AppError)
|
||||
AutocompleteChannelsForSearch(c request.CTX, teamID string, userID string, term string) (model.ChannelList, *model.AppError)
|
||||
AutocompleteChannelsForTeam(c request.CTX, teamID, userID, term string) (model.ChannelList, *model.AppError)
|
||||
AutocompleteUsersInChannel(teamID string, channelID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, *model.AppError)
|
||||
AutocompleteUsersInTeam(teamID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInTeam, *model.AppError)
|
||||
BroadcastStatus(status *model.Status)
|
||||
BuildPostReactions(postID string) (*[]ReactionImportData, *model.AppError)
|
||||
BuildPushNotificationMessage(contentsConfig string, post *model.Post, user *model.User, channel *model.Channel, channelName string, senderName string, explicitMention bool, channelWideMention bool, replyToThreadType string) (*model.PushNotification, *model.AppError)
|
||||
BuildPushNotificationMessage(c request.CTX, contentsConfig string, post *model.Post, user *model.User, channel *model.Channel, channelName string, senderName string, explicitMention bool, channelWideMention bool, replyToThreadType string) (*model.PushNotification, *model.AppError)
|
||||
BuildSamlMetadataObject(idpMetadata []byte) (*model.SamlMetadataResponse, *model.AppError)
|
||||
BulkExport(writer io.Writer, outPath string, opts model.BulkExportOpts) *model.AppError
|
||||
BulkImport(c *request.Context, jsonlReader io.Reader, attachmentsReader *zip.Reader, dryRun bool, workers int) (*model.AppError, int)
|
||||
@@ -452,7 +452,7 @@ type AppIface interface {
|
||||
CheckUserPostflightAuthenticationCriteria(user *model.User) *model.AppError
|
||||
CheckUserPreflightAuthenticationCriteria(user *model.User, mfaToken string) *model.AppError
|
||||
CheckWebConn(userID, connectionID string) *CheckConnResult
|
||||
ClearChannelMembersCache(channelID string)
|
||||
ClearChannelMembersCache(c request.CTX, channelID string)
|
||||
ClearLatestVersionCache()
|
||||
ClearSessionCacheForAllUsers()
|
||||
ClearSessionCacheForAllUsersSkipClusterSend()
|
||||
@@ -471,13 +471,13 @@ type AppIface interface {
|
||||
Compliance() einterfaces.ComplianceInterface
|
||||
Config() *model.Config
|
||||
CopyFileInfos(userID string, fileIDs []string) ([]string, *model.AppError)
|
||||
CreateChannel(c *request.Context, channel *model.Channel, addMember bool) (*model.Channel, *model.AppError)
|
||||
CreateChannelWithUser(c *request.Context, channel *model.Channel, userID string) (*model.Channel, *model.AppError)
|
||||
CreateChannel(c request.CTX, channel *model.Channel, addMember bool) (*model.Channel, *model.AppError)
|
||||
CreateChannelWithUser(c request.CTX, channel *model.Channel, userID string) (*model.Channel, *model.AppError)
|
||||
CreateCommand(cmd *model.Command) (*model.Command, *model.AppError)
|
||||
CreateCommandWebhook(commandID string, args *model.CommandArgs) (*model.CommandWebhook, *model.AppError)
|
||||
CreateEmoji(sessionUserId string, emoji *model.Emoji, multiPartImageData *multipart.Form) (*model.Emoji, *model.AppError)
|
||||
CreateGroup(group *model.Group) (*model.Group, *model.AppError)
|
||||
CreateGroupChannel(userIDs []string, creatorId string) (*model.Channel, *model.AppError)
|
||||
CreateGroupChannel(c request.CTX, userIDs []string, creatorId string) (*model.Channel, *model.AppError)
|
||||
CreateGroupWithUserIds(group *model.GroupWithUserIds) (*model.Group, *model.AppError)
|
||||
CreateIncomingWebhookForChannel(creatorId string, channel *model.Channel, hook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError)
|
||||
CreateJob(job *model.Job) (*model.Job, *model.AppError)
|
||||
@@ -486,24 +486,24 @@ type AppIface interface {
|
||||
CreateOAuthUser(c *request.Context, service string, userData io.Reader, teamID string, tokenUser *model.User) (*model.User, *model.AppError)
|
||||
CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError)
|
||||
CreatePasswordRecoveryToken(userID, email string) (*model.Token, *model.AppError)
|
||||
CreatePost(c *request.Context, post *model.Post, channel *model.Channel, triggerWebhooks, setOnline bool) (savedPost *model.Post, err *model.AppError)
|
||||
CreatePost(c request.CTX, post *model.Post, channel *model.Channel, triggerWebhooks, setOnline bool) (savedPost *model.Post, err *model.AppError)
|
||||
CreatePostAsUser(c *request.Context, post *model.Post, currentSessionId string, setOnline bool) (*model.Post, *model.AppError)
|
||||
CreatePostMissingChannel(c *request.Context, post *model.Post, triggerWebhooks bool) (*model.Post, *model.AppError)
|
||||
CreatePostMissingChannel(c request.CTX, post *model.Post, triggerWebhooks bool) (*model.Post, *model.AppError)
|
||||
CreateRetentionPolicy(policy *model.RetentionPolicyWithTeamAndChannelIDs) (*model.RetentionPolicyWithTeamAndChannelCounts, *model.AppError)
|
||||
CreateRole(role *model.Role) (*model.Role, *model.AppError)
|
||||
CreateScheme(scheme *model.Scheme) (*model.Scheme, *model.AppError)
|
||||
CreateSession(session *model.Session) (*model.Session, *model.AppError)
|
||||
CreateSidebarCategory(userID, teamID string, newCategory *model.SidebarCategoryWithChannels) (*model.SidebarCategoryWithChannels, *model.AppError)
|
||||
CreateSidebarCategory(c request.CTX, userID, teamID string, newCategory *model.SidebarCategoryWithChannels) (*model.SidebarCategoryWithChannels, *model.AppError)
|
||||
CreateTeam(c *request.Context, team *model.Team) (*model.Team, *model.AppError)
|
||||
CreateTeamWithUser(c *request.Context, team *model.Team, userID string) (*model.Team, *model.AppError)
|
||||
CreateTermsOfService(text, userID string) (*model.TermsOfService, *model.AppError)
|
||||
CreateUploadSession(us *model.UploadSession) (*model.UploadSession, *model.AppError)
|
||||
CreateUploadSession(c request.CTX, us *model.UploadSession) (*model.UploadSession, *model.AppError)
|
||||
CreateUserAccessToken(token *model.UserAccessToken) (*model.UserAccessToken, *model.AppError)
|
||||
CreateUserAsAdmin(c *request.Context, user *model.User, redirect string) (*model.User, *model.AppError)
|
||||
CreateUserFromSignup(c *request.Context, user *model.User, redirect string) (*model.User, *model.AppError)
|
||||
CreateUserWithInviteId(c *request.Context, user *model.User, inviteId, redirect string) (*model.User, *model.AppError)
|
||||
CreateUserWithToken(c *request.Context, user *model.User, token *model.Token) (*model.User, *model.AppError)
|
||||
CreateWebhookPost(c *request.Context, userID string, channel *model.Channel, text, overrideUsername, overrideIconURL, overrideIconEmoji string, props model.StringInterface, postType string, postRootId string) (*model.Post, *model.AppError)
|
||||
CreateWebhookPost(c request.CTX, userID string, channel *model.Channel, text, overrideUsername, overrideIconURL, overrideIconEmoji string, props model.StringInterface, postType string, postRootId string) (*model.Post, *model.AppError)
|
||||
DBHealthCheckDelete() error
|
||||
DBHealthCheckWrite() error
|
||||
DataRetention() einterfaces.DataRetentionInterface
|
||||
@@ -513,7 +513,7 @@ type AppIface interface {
|
||||
DeleteAllExpiredPluginKeys() *model.AppError
|
||||
DeleteAllKeysForPlugin(pluginID string) *model.AppError
|
||||
DeleteBrandImage() *model.AppError
|
||||
DeleteChannel(c *request.Context, channel *model.Channel, userID string) *model.AppError
|
||||
DeleteChannel(c request.CTX, channel *model.Channel, userID string) *model.AppError
|
||||
DeleteCommand(commandID string) *model.AppError
|
||||
DeleteEmoji(emoji *model.Emoji) *model.AppError
|
||||
DeleteEphemeralPost(userID, postID string)
|
||||
@@ -526,7 +526,7 @@ type AppIface interface {
|
||||
DeleteOAuthApp(appID string) *model.AppError
|
||||
DeleteOutgoingWebhook(hookID string) *model.AppError
|
||||
DeletePluginKey(pluginID string, key string) *model.AppError
|
||||
DeletePost(postID, deleteByID string) (*model.Post, *model.AppError)
|
||||
DeletePost(c request.CTX, postID, deleteByID string) (*model.Post, *model.AppError)
|
||||
DeletePreferences(userID string, preferences model.Preferences) *model.AppError
|
||||
DeleteReactionForPost(c *request.Context, reaction *model.Reaction) *model.AppError
|
||||
DeleteRemoteCluster(remoteClusterId string) (bool, *model.AppError)
|
||||
@@ -534,7 +534,7 @@ type AppIface interface {
|
||||
DeleteScheme(schemeId string) (*model.Scheme, *model.AppError)
|
||||
DeleteSharedChannel(channelID string) (bool, error)
|
||||
DeleteSharedChannelRemote(id string) (bool, error)
|
||||
DeleteSidebarCategory(userID, teamID, categoryId string) *model.AppError
|
||||
DeleteSidebarCategory(c request.CTX, userID, teamID, categoryId string) *model.AppError
|
||||
DeleteToken(token *model.Token) *model.AppError
|
||||
DisableAutoResponder(userID string, asAdmin bool) *model.AppError
|
||||
DisableUserAccessToken(token *model.UserAccessToken) *model.AppError
|
||||
@@ -559,16 +559,16 @@ type AppIface interface {
|
||||
FileExists(path string) (bool, *model.AppError)
|
||||
FileModTime(path string) (time.Time, *model.AppError)
|
||||
FileSize(path string) (int64, *model.AppError)
|
||||
FillInChannelProps(channel *model.Channel) *model.AppError
|
||||
FillInChannelsProps(channelList model.ChannelList) *model.AppError
|
||||
FillInChannelProps(c request.CTX, channel *model.Channel) *model.AppError
|
||||
FillInChannelsProps(c request.CTX, channelList model.ChannelList) *model.AppError
|
||||
FilterUsersByVisible(viewer *model.User, otherUsers []*model.User) ([]*model.User, *model.AppError)
|
||||
FindTeamByName(name string) bool
|
||||
GenerateMfaSecret(userID string) (*model.MfaSecret, *model.AppError)
|
||||
GeneratePublicLink(siteURL string, info *model.FileInfo) string
|
||||
GenerateSupportPacket() []model.FileData
|
||||
GetActivePluginManifests() ([]*model.Manifest, *model.AppError)
|
||||
GetAllChannels(page, perPage int, opts model.ChannelSearchOpts) (model.ChannelListWithTeamData, *model.AppError)
|
||||
GetAllChannelsCount(opts model.ChannelSearchOpts) (int64, *model.AppError)
|
||||
GetAllChannels(c request.CTX, page, perPage int, opts model.ChannelSearchOpts) (model.ChannelListWithTeamData, *model.AppError)
|
||||
GetAllChannelsCount(c request.CTX, opts model.ChannelSearchOpts) (int64, *model.AppError)
|
||||
GetAllPrivateTeams() ([]*model.Team, *model.AppError)
|
||||
GetAllPublicTeams() ([]*model.Team, *model.AppError)
|
||||
GetAllRemoteClusters(filter model.RemoteClusterQueryFilter) ([]*model.RemoteCluster, *model.AppError)
|
||||
@@ -585,32 +585,32 @@ type AppIface interface {
|
||||
GetAuthorizedAppsForUser(userID string, page, perPage int) ([]*model.OAuthApp, *model.AppError)
|
||||
GetBrandImage() ([]byte, *model.AppError)
|
||||
GetBulkReactionsForPosts(postIDs []string) (map[string][]*model.Reaction, *model.AppError)
|
||||
GetChannel(channelID string) (*model.Channel, *model.AppError)
|
||||
GetChannelByName(channelName, teamID string, includeDeleted bool) (*model.Channel, *model.AppError)
|
||||
GetChannelByNameForTeamName(channelName, teamName string, includeDeleted bool) (*model.Channel, *model.AppError)
|
||||
GetChannelCounts(teamID string, userID string) (*model.ChannelCounts, *model.AppError)
|
||||
GetChannelFileCount(channelID string) (int64, *model.AppError)
|
||||
GetChannelGuestCount(channelID string) (int64, *model.AppError)
|
||||
GetChannelMember(ctx context.Context, channelID string, userID string) (*model.ChannelMember, *model.AppError)
|
||||
GetChannelMemberCount(channelID string) (int64, *model.AppError)
|
||||
GetChannelMembersByIds(channelID string, userIDs []string) (model.ChannelMembers, *model.AppError)
|
||||
GetChannelMembersForUser(teamID string, userID string) (model.ChannelMembers, *model.AppError)
|
||||
GetChannelMembersForUserWithPagination(userID string, page, perPage int) ([]*model.ChannelMember, *model.AppError)
|
||||
GetChannelMembersPage(channelID string, page, perPage int) (model.ChannelMembers, *model.AppError)
|
||||
GetChannelMembersTimezones(channelID string) ([]string, *model.AppError)
|
||||
GetChannelMembersWithTeamDataForUserWithPagination(userID string, page, perPage int) (model.ChannelMembersWithTeamData, *model.AppError)
|
||||
GetChannelPinnedPostCount(channelID string) (int64, *model.AppError)
|
||||
GetChannel(c request.CTX, channelID string) (*model.Channel, *model.AppError)
|
||||
GetChannelByName(c request.CTX, channelName, teamID string, includeDeleted bool) (*model.Channel, *model.AppError)
|
||||
GetChannelByNameForTeamName(c request.CTX, channelName, teamName string, includeDeleted bool) (*model.Channel, *model.AppError)
|
||||
GetChannelCounts(c request.CTX, teamID string, userID string) (*model.ChannelCounts, *model.AppError)
|
||||
GetChannelFileCount(c request.CTX, channelID string) (int64, *model.AppError)
|
||||
GetChannelGuestCount(c request.CTX, channelID string) (int64, *model.AppError)
|
||||
GetChannelMember(c request.CTX, channelID string, userID string) (*model.ChannelMember, *model.AppError)
|
||||
GetChannelMemberCount(c request.CTX, channelID string) (int64, *model.AppError)
|
||||
GetChannelMembersByIds(c request.CTX, channelID string, userIDs []string) (model.ChannelMembers, *model.AppError)
|
||||
GetChannelMembersForUser(c request.CTX, teamID string, userID string) (model.ChannelMembers, *model.AppError)
|
||||
GetChannelMembersForUserWithPagination(c request.CTX, userID string, page, perPage int) ([]*model.ChannelMember, *model.AppError)
|
||||
GetChannelMembersPage(c request.CTX, channelID string, page, perPage int) (model.ChannelMembers, *model.AppError)
|
||||
GetChannelMembersTimezones(c request.CTX, channelID string) ([]string, *model.AppError)
|
||||
GetChannelMembersWithTeamDataForUserWithPagination(c request.CTX, userID string, page, perPage int) (model.ChannelMembersWithTeamData, *model.AppError)
|
||||
GetChannelPinnedPostCount(c request.CTX, channelID string) (int64, *model.AppError)
|
||||
GetChannelPoliciesForUser(userID string, offset, limit int) (*model.RetentionPolicyForChannelList, *model.AppError)
|
||||
GetChannelUnread(channelID, userID string) (*model.ChannelUnread, *model.AppError)
|
||||
GetChannels(channelIDs []string) ([]*model.Channel, *model.AppError)
|
||||
GetChannelsByNames(channelNames []string, teamID string) ([]*model.Channel, *model.AppError)
|
||||
GetChannelUnread(c request.CTX, channelID, userID string) (*model.ChannelUnread, *model.AppError)
|
||||
GetChannels(c request.CTX, channelIDs []string) ([]*model.Channel, *model.AppError)
|
||||
GetChannelsByNames(c request.CTX, channelNames []string, teamID string) ([]*model.Channel, *model.AppError)
|
||||
GetChannelsForRetentionPolicy(policyID string, offset, limit int) (*model.ChannelsWithCount, *model.AppError)
|
||||
GetChannelsForScheme(scheme *model.Scheme, offset int, limit int) (model.ChannelList, *model.AppError)
|
||||
GetChannelsForSchemePage(scheme *model.Scheme, page int, perPage int) (model.ChannelList, *model.AppError)
|
||||
GetChannelsForTeamForUser(teamID string, userID string, opts *model.ChannelSearchOpts) (model.ChannelList, *model.AppError)
|
||||
GetChannelsForTeamForUserWithCursor(teamID string, userID string, opts *model.ChannelSearchOpts, afterChannelID string) (model.ChannelList, *model.AppError)
|
||||
GetChannelsForUser(userID string, includeDeleted bool, lastDeleteAt, pageSize int, fromChannelID string) (model.ChannelList, *model.AppError)
|
||||
GetChannelsUserNotIn(teamID string, userID string, offset int, limit int) (model.ChannelList, *model.AppError)
|
||||
GetChannelsForTeamForUser(c request.CTX, teamID string, userID string, opts *model.ChannelSearchOpts) (model.ChannelList, *model.AppError)
|
||||
GetChannelsForTeamForUserWithCursor(c request.CTX, teamID string, userID string, opts *model.ChannelSearchOpts, afterChannelID string) (model.ChannelList, *model.AppError)
|
||||
GetChannelsForUser(c request.CTX, userID string, includeDeleted bool, lastDeleteAt, pageSize int, fromChannelID string) (model.ChannelList, *model.AppError)
|
||||
GetChannelsUserNotIn(c request.CTX, teamID string, userID string, offset int, limit int) (model.ChannelList, *model.AppError)
|
||||
GetCloudSession(token string) (*model.Session, *model.AppError)
|
||||
GetClusterId() string
|
||||
GetClusterStatus() []*model.ClusterInfo
|
||||
@@ -622,7 +622,7 @@ type AppIface interface {
|
||||
GetCookieDomain() string
|
||||
GetCustomStatus(userID string) (*model.CustomStatus, *model.AppError)
|
||||
GetDefaultProfileImage(user *model.User) ([]byte, *model.AppError)
|
||||
GetDeletedChannels(teamID string, offset int, limit int, userID string) (model.ChannelList, *model.AppError)
|
||||
GetDeletedChannels(c request.CTX, teamID string, offset int, limit int, userID string) (model.ChannelList, *model.AppError)
|
||||
GetEmoji(emojiId string) (*model.Emoji, *model.AppError)
|
||||
GetEmojiByName(emojiName string) (*model.Emoji, *model.AppError)
|
||||
GetEmojiImage(emojiId string) ([]byte, string, *model.AppError)
|
||||
@@ -639,7 +639,7 @@ type AppIface interface {
|
||||
GetGroup(id string, opts *model.GetGroupOpts) (*model.Group, *model.AppError)
|
||||
GetGroupByName(name string, opts model.GroupSearchOpts) (*model.Group, *model.AppError)
|
||||
GetGroupByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, *model.AppError)
|
||||
GetGroupChannel(userIDs []string) (*model.Channel, *model.AppError)
|
||||
GetGroupChannel(c request.CTX, userIDs []string) (*model.Channel, *model.AppError)
|
||||
GetGroupMemberCount(groupID string) (int64, *model.AppError)
|
||||
GetGroupMemberUsers(groupID string) ([]*model.User, *model.AppError)
|
||||
GetGroupMemberUsersPage(groupID string, page int, perPage int) ([]*model.User, int, *model.AppError)
|
||||
@@ -674,7 +674,7 @@ type AppIface interface {
|
||||
GetNewUsersForTeamPage(teamID string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||
GetNextPostIdFromPostList(postList *model.PostList, collapsedThreads bool) string
|
||||
GetNotificationNameFormat(user *model.User) string
|
||||
GetNumberOfChannelsOnTeam(teamID string) (int, *model.AppError)
|
||||
GetNumberOfChannelsOnTeam(c request.CTX, teamID string) (int, *model.AppError)
|
||||
GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectURI, code, secret, refreshToken string) (*model.AccessResponse, *model.AppError)
|
||||
GetOAuthAccessTokenForImplicitFlow(userID string, authRequest *model.AuthorizeRequest) (*model.Session, *model.AppError)
|
||||
GetOAuthApp(appID string) (*model.OAuthApp, *model.AppError)
|
||||
@@ -687,7 +687,7 @@ type AppIface interface {
|
||||
GetOAuthStateToken(token string) (*model.Token, *model.AppError)
|
||||
GetOnboarding() (*model.System, *model.AppError)
|
||||
GetOpenGraphMetadata(requestURL string) ([]byte, error)
|
||||
GetOrCreateDirectChannel(c *request.Context, userID, otherUserID string, channelOptions ...model.ChannelOption) (*model.Channel, *model.AppError)
|
||||
GetOrCreateDirectChannel(c request.CTX, userID, otherUserID string, channelOptions ...model.ChannelOption) (*model.Channel, *model.AppError)
|
||||
GetOutgoingWebhook(hookID string) (*model.OutgoingWebhook, *model.AppError)
|
||||
GetOutgoingWebhooksForChannelPageByUser(channelID string, userID string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError)
|
||||
GetOutgoingWebhooksForTeamPage(teamID string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError)
|
||||
@@ -695,31 +695,31 @@ type AppIface interface {
|
||||
GetOutgoingWebhooksPage(page, perPage int) ([]*model.OutgoingWebhook, *model.AppError)
|
||||
GetOutgoingWebhooksPageByUser(userID string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError)
|
||||
GetPasswordRecoveryToken(token string) (*model.Token, *model.AppError)
|
||||
GetPermalinkPost(c *request.Context, postID string, userID string) (*model.PostList, *model.AppError)
|
||||
GetPinnedPosts(channelID string) (*model.PostList, *model.AppError)
|
||||
GetPermalinkPost(c request.CTX, postID string, userID string) (*model.PostList, *model.AppError)
|
||||
GetPinnedPosts(c request.CTX, channelID string) (*model.PostList, *model.AppError)
|
||||
GetPluginKey(pluginID string, key string) ([]byte, *model.AppError)
|
||||
GetPlugins() (*model.PluginsResponse, *model.AppError)
|
||||
GetPostAfterTime(channelID string, time int64, collapsedThreads bool) (*model.Post, *model.AppError)
|
||||
GetPostIdAfterTime(channelID string, time int64, collapsedThreads bool) (string, *model.AppError)
|
||||
GetPostIdBeforeTime(channelID string, time int64, collapsedThreads bool) (string, *model.AppError)
|
||||
GetPostIfAuthorized(postID string, session *model.Session, includeDeleted bool) (*model.Post, *model.AppError)
|
||||
GetPostIfAuthorized(c request.CTX, postID string, session *model.Session, includeDeleted bool) (*model.Post, *model.AppError)
|
||||
GetPostThread(postID string, opts model.GetPostsOptions, userID string) (*model.PostList, *model.AppError)
|
||||
GetPosts(channelID string, offset int, limit int) (*model.PostList, *model.AppError)
|
||||
GetPostsAfterPost(options model.GetPostsOptions) (*model.PostList, *model.AppError)
|
||||
GetPostsAroundPost(before bool, options model.GetPostsOptions) (*model.PostList, *model.AppError)
|
||||
GetPostsBeforePost(options model.GetPostsOptions) (*model.PostList, *model.AppError)
|
||||
GetPostsEtag(channelID string, collapsedThreads bool) string
|
||||
GetPostsForChannelAroundLastUnread(channelID, userID string, limitBefore, limitAfter int, skipFetchThreads bool, collapsedThreads, collapsedThreadsExtended bool) (*model.PostList, *model.AppError)
|
||||
GetPostsForChannelAroundLastUnread(c request.CTX, channelID, userID string, limitBefore, limitAfter int, skipFetchThreads bool, collapsedThreads, collapsedThreadsExtended bool) (*model.PostList, *model.AppError)
|
||||
GetPostsPage(options model.GetPostsOptions) (*model.PostList, *model.AppError)
|
||||
GetPostsSince(options model.GetPostsSinceOptions) (*model.PostList, *model.AppError)
|
||||
GetPreferenceByCategoryAndNameForUser(userID string, category string, preferenceName string) (*model.Preference, *model.AppError)
|
||||
GetPreferenceByCategoryForUser(userID string, category string) (model.Preferences, *model.AppError)
|
||||
GetPreferencesForUser(userID string) (model.Preferences, *model.AppError)
|
||||
GetPrevPostIdFromPostList(postList *model.PostList, collapsedThreads bool) string
|
||||
GetPrivateChannelsForTeam(teamID string, offset int, limit int) (model.ChannelList, *model.AppError)
|
||||
GetPrivateChannelsForTeam(c request.CTX, teamID string, offset int, limit int) (model.ChannelList, *model.AppError)
|
||||
GetProfileImage(user *model.User) ([]byte, bool, *model.AppError)
|
||||
GetPublicChannelsByIdsForTeam(teamID string, channelIDs []string) (model.ChannelList, *model.AppError)
|
||||
GetPublicChannelsForTeam(teamID string, offset int, limit int) (model.ChannelList, *model.AppError)
|
||||
GetPublicChannelsByIdsForTeam(c request.CTX, teamID string, channelIDs []string) (model.ChannelList, *model.AppError)
|
||||
GetPublicChannelsForTeam(c request.CTX, teamID string, offset int, limit int) (model.ChannelList, *model.AppError)
|
||||
GetReactionsForPost(postID string) ([]*model.Reaction, *model.AppError)
|
||||
GetRecentSearchesForUser(userID string) ([]*model.SearchParams, *model.AppError)
|
||||
GetRecentlyActiveUsersForTeam(teamID string) (map[string]*model.User, *model.AppError)
|
||||
@@ -753,10 +753,10 @@ type AppIface interface {
|
||||
GetSharedChannelRemotesStatus(channelID string) ([]*model.SharedChannelRemoteStatus, error)
|
||||
GetSharedChannels(page int, perPage int, opts model.SharedChannelFilterOpts) ([]*model.SharedChannel, *model.AppError)
|
||||
GetSharedChannelsCount(opts model.SharedChannelFilterOpts) (int64, error)
|
||||
GetSidebarCategories(userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, *model.AppError)
|
||||
GetSidebarCategoriesForTeamForUser(userID, teamID string) (*model.OrderedSidebarCategories, *model.AppError)
|
||||
GetSidebarCategory(categoryId string) (*model.SidebarCategoryWithChannels, *model.AppError)
|
||||
GetSidebarCategoryOrder(userID, teamID string) ([]string, *model.AppError)
|
||||
GetSidebarCategories(c request.CTX, userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, *model.AppError)
|
||||
GetSidebarCategoriesForTeamForUser(c request.CTX, userID, teamID string) (*model.OrderedSidebarCategories, *model.AppError)
|
||||
GetSidebarCategory(c request.CTX, categoryId string) (*model.SidebarCategoryWithChannels, *model.AppError)
|
||||
GetSidebarCategoryOrder(c request.CTX, userID, teamID string) ([]string, *model.AppError)
|
||||
GetSinglePost(postID string, includeDeleted bool) (*model.Post, *model.AppError)
|
||||
GetSiteURL() string
|
||||
GetStatus(userID string) (*model.Status, *model.AppError)
|
||||
@@ -789,12 +789,12 @@ type AppIface interface {
|
||||
GetThreadMembershipsForUser(userID, teamID string) ([]*model.ThreadMembership, error)
|
||||
GetThreadsForUser(userID, teamID string, options model.GetUserThreadsOpts) (*model.Threads, *model.AppError)
|
||||
GetTokenById(token string) (*model.Token, *model.AppError)
|
||||
GetTopChannelsForTeamSince(teamID, userID string, opts *model.InsightsOpts) (*model.TopChannelList, *model.AppError)
|
||||
GetTopChannelsForUserSince(userID, teamID string, opts *model.InsightsOpts) (*model.TopChannelList, *model.AppError)
|
||||
GetTopChannelsForTeamSince(c request.CTX, teamID, userID string, opts *model.InsightsOpts) (*model.TopChannelList, *model.AppError)
|
||||
GetTopChannelsForUserSince(c request.CTX, userID, teamID string, opts *model.InsightsOpts) (*model.TopChannelList, *model.AppError)
|
||||
GetTopReactionsForTeamSince(teamID string, userID string, opts *model.InsightsOpts) (*model.TopReactionList, *model.AppError)
|
||||
GetTopReactionsForUserSince(userID string, teamID string, opts *model.InsightsOpts) (*model.TopReactionList, *model.AppError)
|
||||
GetTopThreadsForTeamSince(teamID, userID string, opts *model.InsightsOpts) (*model.TopThreadList, *model.AppError)
|
||||
GetTopThreadsForUserSince(teamID, userID string, opts *model.InsightsOpts) (*model.TopThreadList, *model.AppError)
|
||||
GetTopThreadsForTeamSince(c request.CTX, teamID, userID string, opts *model.InsightsOpts) (*model.TopThreadList, *model.AppError)
|
||||
GetTopThreadsForUserSince(c request.CTX, teamID, userID string, opts *model.InsightsOpts) (*model.TopThreadList, *model.AppError)
|
||||
GetUploadSession(uploadId string) (*model.UploadSession, *model.AppError)
|
||||
GetUploadSessionsForUser(userID string) ([]*model.UploadSession, *model.AppError)
|
||||
GetUser(userID string) (*model.User, *model.AppError)
|
||||
@@ -846,9 +846,9 @@ type AppIface interface {
|
||||
HandleIncomingWebhook(c *request.Context, hookID string, req *model.IncomingWebhookRequest) *model.AppError
|
||||
HandleMessageExportConfig(cfg *model.Config, appCfg *model.Config)
|
||||
HasPermissionTo(askingUserId string, permission *model.Permission) bool
|
||||
HasPermissionToChannel(askingUserId string, channelID string, permission *model.Permission) bool
|
||||
HasPermissionToChannel(c request.CTX, askingUserId string, channelID string, permission *model.Permission) bool
|
||||
HasPermissionToChannelByPost(askingUserId string, postID string, permission *model.Permission) bool
|
||||
HasPermissionToReadChannel(userID string, channel *model.Channel) bool
|
||||
HasPermissionToReadChannel(c request.CTX, userID string, channel *model.Channel) bool
|
||||
HasPermissionToTeam(askingUserId string, teamID string, permission *model.Permission) bool
|
||||
HasPermissionToUser(askingUserId string, userID string) bool
|
||||
HasSharedChannel(channelID string) (bool, error)
|
||||
@@ -864,18 +864,18 @@ type AppIface interface {
|
||||
InviteGuestsToChannelsGracefully(teamID string, guestsInvite *model.GuestsInvite, senderId string) ([]*model.EmailInviteWithError, *model.AppError)
|
||||
InviteNewUsersToTeam(emailList []string, teamID, senderId string) *model.AppError
|
||||
InviteNewUsersToTeamGracefully(memberInvite *model.MemberInvite, teamID, senderId string, reminderInterval string) ([]*model.EmailInviteWithError, *model.AppError)
|
||||
IsCRTEnabledForUser(userID string) bool
|
||||
IsCRTEnabledForUser(c request.CTX, userID string) bool
|
||||
IsFirstUserAccount() bool
|
||||
IsLeader() bool
|
||||
IsPasswordValid(password string) *model.AppError
|
||||
IsPhase2MigrationCompleted() *model.AppError
|
||||
IsUserAway(lastActivityAt int64) bool
|
||||
IsUserSignUpAllowed() *model.AppError
|
||||
JoinChannel(c *request.Context, channel *model.Channel, userID string) *model.AppError
|
||||
JoinDefaultChannels(c *request.Context, teamID string, user *model.User, shouldBeAdmin bool, userRequestorId string) *model.AppError
|
||||
JoinChannel(c request.CTX, channel *model.Channel, userID string) *model.AppError
|
||||
JoinDefaultChannels(c request.CTX, teamID string, user *model.User, shouldBeAdmin bool, userRequestorId string) *model.AppError
|
||||
JoinUserToTeam(c *request.Context, team *model.Team, user *model.User, userRequestorId string) (*model.TeamMember, *model.AppError)
|
||||
Ldap() einterfaces.LdapInterface
|
||||
LeaveChannel(c *request.Context, channelID string, userID string) *model.AppError
|
||||
LeaveChannel(c request.CTX, channelID string, userID string) *model.AppError
|
||||
LeaveTeam(c *request.Context, team *model.Team, user *model.User, requestorId string) *model.AppError
|
||||
License() *model.License
|
||||
LimitedClientConfig() map[string]string
|
||||
@@ -889,7 +889,7 @@ type AppIface interface {
|
||||
Log() *mlog.Logger
|
||||
LoginByOAuth(c *request.Context, service string, userData io.Reader, teamID string, tokenUser *model.User) (*model.User, *model.AppError)
|
||||
MakePermissionError(s *model.Session, permissions []*model.Permission) *model.AppError
|
||||
MarkChannelsAsViewed(channelIDs []string, userID string, currentSessionId string, collapsedThreadsSupported bool) (map[string]int64, *model.AppError)
|
||||
MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID string, currentSessionId string, collapsedThreadsSupported bool) (map[string]int64, *model.AppError)
|
||||
MaxPostSize() int
|
||||
MessageExport() einterfaces.MessageExportInterface
|
||||
Metrics() einterfaces.MetricsInterface
|
||||
@@ -905,7 +905,7 @@ type AppIface interface {
|
||||
NotifySystemAdminsToUpgrade(c *request.Context, currentUserTeamID string) *model.AppError
|
||||
OpenInteractiveDialog(request model.OpenDialogRequest) *model.AppError
|
||||
OriginChecker() func(*http.Request) bool
|
||||
PatchChannel(c *request.Context, channel *model.Channel, patch *model.ChannelPatch, userID string) (*model.Channel, *model.AppError)
|
||||
PatchChannel(c request.CTX, channel *model.Channel, patch *model.ChannelPatch, userID string) (*model.Channel, *model.AppError)
|
||||
PatchPost(c *request.Context, postID string, patch *model.PostPatch) (*model.Post, *model.AppError)
|
||||
PatchRetentionPolicy(patch *model.RetentionPolicyWithTeamAndChannelIDs) (*model.RetentionPolicyWithTeamAndChannelCounts, *model.AppError)
|
||||
PatchRole(role *model.Role, patch *model.RolePatch) (*model.Role, *model.AppError)
|
||||
@@ -913,22 +913,22 @@ type AppIface interface {
|
||||
PatchTeam(teamID string, patch *model.TeamPatch) (*model.Team, *model.AppError)
|
||||
PatchUser(userID string, patch *model.UserPatch, asAdmin bool) (*model.User, *model.AppError)
|
||||
PermanentDeleteAllUsers(c *request.Context) *model.AppError
|
||||
PermanentDeleteChannel(channel *model.Channel) *model.AppError
|
||||
PermanentDeleteTeam(team *model.Team) *model.AppError
|
||||
PermanentDeleteTeamId(teamID string) *model.AppError
|
||||
PermanentDeleteChannel(c request.CTX, channel *model.Channel) *model.AppError
|
||||
PermanentDeleteTeam(c request.CTX, team *model.Team) *model.AppError
|
||||
PermanentDeleteTeamId(c request.CTX, teamID string) *model.AppError
|
||||
PermanentDeleteUser(c *request.Context, user *model.User) *model.AppError
|
||||
PluginCommandsForTeam(teamID string) []*model.Command
|
||||
PostActionCookieSecret() []byte
|
||||
PostAddToChannelMessage(c *request.Context, user *model.User, addedUser *model.User, channel *model.Channel, postRootId string) *model.AppError
|
||||
PostAddToChannelMessage(c request.CTX, user *model.User, addedUser *model.User, channel *model.Channel, postRootId string) *model.AppError
|
||||
PostPatchWithProxyRemovedFromImageURLs(patch *model.PostPatch) *model.PostPatch
|
||||
PostUpdateChannelDisplayNameMessage(c *request.Context, userID string, channel *model.Channel, oldChannelDisplayName, newChannelDisplayName string) *model.AppError
|
||||
PostUpdateChannelHeaderMessage(c *request.Context, userID string, channel *model.Channel, oldChannelHeader, newChannelHeader string) *model.AppError
|
||||
PostUpdateChannelPurposeMessage(c *request.Context, userID string, channel *model.Channel, oldChannelPurpose string, newChannelPurpose string) *model.AppError
|
||||
PostUpdateChannelDisplayNameMessage(c request.CTX, userID string, channel *model.Channel, oldChannelDisplayName, newChannelDisplayName string) *model.AppError
|
||||
PostUpdateChannelHeaderMessage(c request.CTX, userID string, channel *model.Channel, oldChannelHeader, newChannelHeader string) *model.AppError
|
||||
PostUpdateChannelPurposeMessage(c request.CTX, userID string, channel *model.Channel, oldChannelPurpose string, newChannelPurpose string) *model.AppError
|
||||
PostWithProxyAddedToImageURLs(post *model.Post) *model.Post
|
||||
PostWithProxyRemovedFromImageURLs(post *model.Post) *model.Post
|
||||
PreparePostForClient(originalPost *model.Post, isNewPost, isEditPost bool) *model.Post
|
||||
PreparePostForClientWithEmbedsAndImages(originalPost *model.Post, isNewPost, isEditPost bool) *model.Post
|
||||
PreparePostListForClient(originalList *model.PostList) *model.PostList
|
||||
PreparePostForClientWithEmbedsAndImages(c request.CTX, originalPost *model.Post, isNewPost, isEditPost bool) *model.Post
|
||||
PreparePostListForClient(c request.CTX, originalList *model.PostList) *model.PostList
|
||||
ProcessSlackText(text string) string
|
||||
Publish(message *model.WebSocketEvent)
|
||||
PublishUserTyping(userID, channelID, parentId string) *model.AppError
|
||||
@@ -942,7 +942,7 @@ type AppIface interface {
|
||||
RegenerateTeamInviteId(teamID string) (*model.Team, *model.AppError)
|
||||
RegisterPluginCommand(pluginID string, command *model.Command) error
|
||||
ReloadConfig() error
|
||||
RemoveAllDeactivatedMembersFromChannel(channel *model.Channel) *model.AppError
|
||||
RemoveAllDeactivatedMembersFromChannel(c request.CTX, channel *model.Channel) *model.AppError
|
||||
RemoveChannelsFromRetentionPolicy(policyID string, channelIDs []string) *model.AppError
|
||||
RemoveConfigListener(id string)
|
||||
RemoveCustomStatus(userID string) *model.AppError
|
||||
@@ -956,14 +956,14 @@ type AppIface interface {
|
||||
RemoveSamlPublicCertificate() *model.AppError
|
||||
RemoveTeamIcon(teamID string) *model.AppError
|
||||
RemoveTeamsFromRetentionPolicy(policyID string, teamIDs []string) *model.AppError
|
||||
RemoveUserFromChannel(c *request.Context, userIDToRemove string, removerUserId string, channel *model.Channel) *model.AppError
|
||||
RemoveUserFromChannel(c request.CTX, userIDToRemove string, removerUserId string, channel *model.Channel) *model.AppError
|
||||
RemoveUserFromTeam(c *request.Context, teamID string, userID string, requestorId string) *model.AppError
|
||||
RemoveUsersFromChannelNotMemberOfTeam(c *request.Context, remover *model.User, channel *model.Channel, team *model.Team) *model.AppError
|
||||
RemoveUsersFromChannelNotMemberOfTeam(c request.CTX, remover *model.User, channel *model.Channel, team *model.Team) *model.AppError
|
||||
RequestLicenseAndAckWarnMetric(c *request.Context, warnMetricId string, isBot bool) *model.AppError
|
||||
ResetPasswordFromToken(userSuppliedTokenString, newPassword string) *model.AppError
|
||||
ResetPermissionsSystem() *model.AppError
|
||||
ResetSamlAuthDataToEmail(includeDeleted bool, dryRun bool, userIDs []string) (numAffected int, appErr *model.AppError)
|
||||
RestoreChannel(c *request.Context, channel *model.Channel, userID string) (*model.Channel, *model.AppError)
|
||||
RestoreChannel(c request.CTX, channel *model.Channel, userID string) (*model.Channel, *model.AppError)
|
||||
RestoreTeam(teamID string) *model.AppError
|
||||
RestrictUsersGetByPermissions(userID string, options *model.UserGetOptions) (*model.UserGetOptions, *model.AppError)
|
||||
RestrictUsersSearchByPermissions(userID string, options *model.UserSearchOptions) (*model.UserSearchOptions, *model.AppError)
|
||||
@@ -976,8 +976,8 @@ type AppIface interface {
|
||||
RevokeUserAccessToken(token *model.UserAccessToken) *model.AppError
|
||||
RolesGrantPermission(roleNames []string, permissionId string) bool
|
||||
Saml() einterfaces.SamlInterface
|
||||
SanitizePostListMetadataForUser(postList *model.PostList, userID string) (*model.PostList, *model.AppError)
|
||||
SanitizePostMetadataForUser(post *model.Post, userID string) (*model.Post, *model.AppError)
|
||||
SanitizePostListMetadataForUser(c request.CTX, postList *model.PostList, userID string) (*model.PostList, *model.AppError)
|
||||
SanitizePostMetadataForUser(c request.CTX, post *model.Post, userID string) (*model.Post, *model.AppError)
|
||||
SanitizeProfile(user *model.User, asAdmin bool)
|
||||
SanitizeTeam(session model.Session, team *model.Team) *model.Team
|
||||
SanitizeTeams(session model.Session, teams []*model.Team) []*model.Team
|
||||
@@ -985,18 +985,18 @@ type AppIface interface {
|
||||
SaveBrandImage(imageData *multipart.FileHeader) *model.AppError
|
||||
SaveComplianceReport(job *model.Compliance) (*model.Compliance, *model.AppError)
|
||||
SaveReactionForPost(c *request.Context, reaction *model.Reaction) (*model.Reaction, *model.AppError)
|
||||
SaveSharedChannel(sc *model.SharedChannel) (*model.SharedChannel, error)
|
||||
SaveSharedChannel(c request.CTX, sc *model.SharedChannel) (*model.SharedChannel, error)
|
||||
SaveSharedChannelRemote(remote *model.SharedChannelRemote) (*model.SharedChannelRemote, error)
|
||||
SaveUserTermsOfService(userID, termsOfServiceId string, accepted bool) *model.AppError
|
||||
SchemesIterator(scope string, batchSize int) func() []*model.Scheme
|
||||
SearchArchivedChannels(teamID string, term string, userID string) (model.ChannelList, *model.AppError)
|
||||
SearchChannels(teamID string, term string) (model.ChannelList, *model.AppError)
|
||||
SearchChannelsForUser(userID, teamID, term string) (model.ChannelList, *model.AppError)
|
||||
SearchChannelsUserNotIn(teamID string, userID string, term string) (model.ChannelList, *model.AppError)
|
||||
SearchArchivedChannels(c request.CTX, teamID string, term string, userID string) (model.ChannelList, *model.AppError)
|
||||
SearchChannels(c request.CTX, teamID string, term string) (model.ChannelList, *model.AppError)
|
||||
SearchChannelsForUser(c request.CTX, userID, teamID, term string) (model.ChannelList, *model.AppError)
|
||||
SearchChannelsUserNotIn(c request.CTX, teamID string, userID string, term string) (model.ChannelList, *model.AppError)
|
||||
SearchEmoji(name string, prefixOnly bool, limit int) ([]*model.Emoji, *model.AppError)
|
||||
SearchEngine() *searchengine.Broker
|
||||
SearchFilesInTeamForUser(c *request.Context, terms string, userId string, teamId string, isOrSearch bool, includeDeletedChannels bool, timeZoneOffset int, page, perPage int, modifier string) (*model.FileInfoList, *model.AppError)
|
||||
SearchGroupChannels(userID, term string) (model.ChannelList, *model.AppError)
|
||||
SearchGroupChannels(c request.CTX, userID, term string) (model.ChannelList, *model.AppError)
|
||||
SearchPostsForUser(c *request.Context, terms string, userID string, teamID string, isOrSearch bool, includeDeletedChannels bool, timeZoneOffset int, page, perPage int, modifier string) (*model.PostSearchResults, *model.AppError)
|
||||
SearchPostsInTeam(teamID string, paramsList []*model.SearchParams) (*model.PostList, *model.AppError)
|
||||
SearchPrivateTeams(searchOpts *model.TeamSearch) ([]*model.Team, *model.AppError)
|
||||
@@ -1011,11 +1011,11 @@ type AppIface interface {
|
||||
SearchUsersNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||
SearchUsersWithoutTeam(term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||
SendAckToPushProxy(ack *model.PushNotificationAck) error
|
||||
SendAutoResponse(c *request.Context, channel *model.Channel, receiver *model.User, post *model.Post) (bool, *model.AppError)
|
||||
SendAutoResponseIfNecessary(c *request.Context, channel *model.Channel, sender *model.User, post *model.Post) (bool, *model.AppError)
|
||||
SendAutoResponse(c request.CTX, channel *model.Channel, receiver *model.User, post *model.Post) (bool, *model.AppError)
|
||||
SendAutoResponseIfNecessary(c request.CTX, channel *model.Channel, sender *model.User, post *model.Post) (bool, *model.AppError)
|
||||
SendEmailVerification(user *model.User, newEmail, redirect string) *model.AppError
|
||||
SendEphemeralPost(userID string, post *model.Post) *model.Post
|
||||
SendNotifications(post *model.Post, team *model.Team, channel *model.Channel, sender *model.User, parentPostList *model.PostList, setOnline bool) ([]string, error)
|
||||
SendEphemeralPost(c request.CTX, userID string, post *model.Post) *model.Post
|
||||
SendNotifications(c request.CTX, post *model.Post, team *model.Team, channel *model.Channel, sender *model.User, parentPostList *model.PostList, setOnline bool) ([]string, error)
|
||||
SendPasswordReset(email string, siteURL string) (bool, *model.AppError)
|
||||
SendPaymentFailedEmail(failedPayment *model.FailedPayment) *model.AppError
|
||||
SendTestPushNotification(deviceID string) string
|
||||
@@ -1023,8 +1023,8 @@ type AppIface interface {
|
||||
ServeInterPluginRequest(w http.ResponseWriter, r *http.Request, sourcePluginId, destinationPluginId string)
|
||||
SessionHasPermissionTo(session model.Session, permission *model.Permission) bool
|
||||
SessionHasPermissionToAny(session model.Session, permissions []*model.Permission) bool
|
||||
SessionHasPermissionToCategory(session model.Session, userID, teamID, categoryId string) bool
|
||||
SessionHasPermissionToChannel(session model.Session, channelID string, permission *model.Permission) bool
|
||||
SessionHasPermissionToCategory(c request.CTX, session model.Session, userID, teamID, categoryId string) bool
|
||||
SessionHasPermissionToChannel(c request.CTX, session model.Session, channelID string, permission *model.Permission) bool
|
||||
SessionHasPermissionToChannelByPost(session model.Session, postID string, permission *model.Permission) bool
|
||||
SessionHasPermissionToCreateJob(session model.Session, job *model.Job) (bool, *model.Permission)
|
||||
SessionHasPermissionToGroup(session model.Session, groupID string, permission *model.Permission) bool
|
||||
@@ -1032,7 +1032,7 @@ type AppIface interface {
|
||||
SessionHasPermissionToTeam(session model.Session, teamID string, permission *model.Permission) bool
|
||||
SessionHasPermissionToUser(session model.Session, userID string) bool
|
||||
SessionHasPermissionToUserOrBot(session model.Session, userID string) bool
|
||||
SetActiveChannel(userID string, channelID string) *model.AppError
|
||||
SetActiveChannel(c request.CTX, userID string, channelID string) *model.AppError
|
||||
SetAutoResponderStatus(user *model.User, oldNotifyProps model.StringMap)
|
||||
SetChannels(ch *Channels)
|
||||
SetCustomStatus(userID string, cs *model.CustomStatus) *model.AppError
|
||||
@@ -1074,18 +1074,18 @@ type AppIface interface {
|
||||
TestLdap() *model.AppError
|
||||
TestSiteURL(siteURL string) *model.AppError
|
||||
Timezones() *timezones.Timezones
|
||||
ToggleMuteChannel(channelID, userID string) (*model.ChannelMember, *model.AppError)
|
||||
ToggleMuteChannel(c request.CTX, channelID, userID string) (*model.ChannelMember, *model.AppError)
|
||||
TotalWebsocketConnections() int
|
||||
TriggerWebhook(c *request.Context, payload *model.OutgoingWebhookPayload, hook *model.OutgoingWebhook, post *model.Post, channel *model.Channel)
|
||||
TriggerWebhook(c request.CTX, payload *model.OutgoingWebhookPayload, hook *model.OutgoingWebhook, post *model.Post, channel *model.Channel)
|
||||
UnregisterPluginCommand(pluginID, teamID, trigger string)
|
||||
UpdateActive(c *request.Context, user *model.User, active bool) (*model.User, *model.AppError)
|
||||
UpdateChannelMemberNotifyProps(data map[string]string, channelID string, userID string) (*model.ChannelMember, *model.AppError)
|
||||
UpdateChannelMemberRoles(channelID string, userID string, newRoles string) (*model.ChannelMember, *model.AppError)
|
||||
UpdateChannelMemberSchemeRoles(channelID string, userID string, isSchemeGuest bool, isSchemeUser bool, isSchemeAdmin bool) (*model.ChannelMember, *model.AppError)
|
||||
UpdateChannelPrivacy(c *request.Context, oldChannel *model.Channel, user *model.User) (*model.Channel, *model.AppError)
|
||||
UpdateChannelMemberNotifyProps(c request.CTX, data map[string]string, channelID string, userID string) (*model.ChannelMember, *model.AppError)
|
||||
UpdateChannelMemberRoles(c request.CTX, channelID string, userID string, newRoles string) (*model.ChannelMember, *model.AppError)
|
||||
UpdateChannelMemberSchemeRoles(c request.CTX, channelID string, userID string, isSchemeGuest bool, isSchemeUser bool, isSchemeAdmin bool) (*model.ChannelMember, *model.AppError)
|
||||
UpdateChannelPrivacy(c request.CTX, oldChannel *model.Channel, user *model.User) (*model.Channel, *model.AppError)
|
||||
UpdateCommand(oldCmd, updatedCmd *model.Command) (*model.Command, *model.AppError)
|
||||
UpdateConfig(f func(*model.Config))
|
||||
UpdateEphemeralPost(userID string, post *model.Post) *model.Post
|
||||
UpdateEphemeralPost(c request.CTX, userID string, post *model.Post) *model.Post
|
||||
UpdateExpiredDNDStatuses() ([]*model.Status, error)
|
||||
UpdateGroup(group *model.Group) (*model.Group, *model.AppError)
|
||||
UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError)
|
||||
@@ -1097,7 +1097,7 @@ type AppIface interface {
|
||||
UpdateMobileAppBadge(userID string)
|
||||
UpdateOAuthApp(oldApp, updatedApp *model.OAuthApp) (*model.OAuthApp, *model.AppError)
|
||||
UpdateOAuthUserAttrs(userData io.Reader, user *model.User, provider einterfaces.OAuthProvider, service string, tokenUser *model.User) *model.AppError
|
||||
UpdateOutgoingWebhook(oldHook, updatedHook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError)
|
||||
UpdateOutgoingWebhook(c request.CTX, oldHook, updatedHook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError)
|
||||
UpdatePassword(user *model.User, newPassword string) *model.AppError
|
||||
UpdatePasswordAsUser(userID, currentPassword, newPassword string) *model.AppError
|
||||
UpdatePasswordByUserIdSendEmail(userID, newPassword, method string) *model.AppError
|
||||
@@ -1110,17 +1110,17 @@ type AppIface interface {
|
||||
UpdateScheme(scheme *model.Scheme) (*model.Scheme, *model.AppError)
|
||||
UpdateSharedChannel(sc *model.SharedChannel) (*model.SharedChannel, error)
|
||||
UpdateSharedChannelRemoteCursor(id string, cursor model.GetPostsSinceForSyncCursor) error
|
||||
UpdateSidebarCategories(userID, teamID string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, *model.AppError)
|
||||
UpdateSidebarCategoryOrder(userID, teamID string, categoryOrder []string) *model.AppError
|
||||
UpdateSidebarCategories(c request.CTX, userID, teamID string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, *model.AppError)
|
||||
UpdateSidebarCategoryOrder(c request.CTX, userID, teamID string, categoryOrder []string) *model.AppError
|
||||
UpdateTeam(team *model.Team) (*model.Team, *model.AppError)
|
||||
UpdateTeamMemberRoles(teamID string, userID string, newRoles string) (*model.TeamMember, *model.AppError)
|
||||
UpdateTeamMemberSchemeRoles(teamID string, userID string, isSchemeGuest bool, isSchemeUser bool, isSchemeAdmin bool) (*model.TeamMember, *model.AppError)
|
||||
UpdateTeamPrivacy(teamID string, teamType string, allowOpenInvite bool) *model.AppError
|
||||
UpdateTeamScheme(team *model.Team) (*model.Team, *model.AppError)
|
||||
UpdateThreadFollowForUser(userID, teamID, threadID string, state bool) *model.AppError
|
||||
UpdateThreadFollowForUserFromChannelAdd(userID, teamID, threadID string) *model.AppError
|
||||
UpdateThreadReadForUser(currentSessionId, userID, teamID, threadID string, timestamp int64) (*model.ThreadResponse, *model.AppError)
|
||||
UpdateThreadReadForUserByPost(currentSessionId, userID, teamID, threadID, postID string) (*model.ThreadResponse, *model.AppError)
|
||||
UpdateThreadFollowForUserFromChannelAdd(c request.CTX, userID, teamID, threadID string) *model.AppError
|
||||
UpdateThreadReadForUser(c request.CTX, currentSessionId, userID, teamID, threadID string, timestamp int64) (*model.ThreadResponse, *model.AppError)
|
||||
UpdateThreadReadForUserByPost(c request.CTX, currentSessionId, userID, teamID, threadID, postID string) (*model.ThreadResponse, *model.AppError)
|
||||
UpdateThreadsReadForUser(userID, teamID string) *model.AppError
|
||||
UpdateUser(user *model.User, sendNotifications bool) (*model.User, *model.AppError)
|
||||
UpdateUserActive(c *request.Context, userID string, active bool) *model.AppError
|
||||
@@ -1137,6 +1137,6 @@ type AppIface interface {
|
||||
UserCanSeeOtherUser(userID string, otherUserId string) (bool, *model.AppError)
|
||||
VerifyEmailFromToken(userSuppliedTokenString string) *model.AppError
|
||||
VerifyUserEmail(userID, email string) *model.AppError
|
||||
ViewChannel(view *model.ChannelView, userID string, currentSessionId string, collapsedThreadsSupported bool) (map[string]int64, *model.AppError)
|
||||
ViewChannel(c request.CTX, view *model.ChannelView, userID string, currentSessionId string, collapsedThreadsSupported bool) (map[string]int64, *model.AppError)
|
||||
WriteFile(fr io.Reader, path string) (int64, *model.AppError)
|
||||
}
|
||||
|
||||
+14
-14
@@ -4,12 +4,12 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app/request"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
@@ -58,7 +58,7 @@ func (a *App) SessionHasPermissionToTeam(session model.Session, teamID string, p
|
||||
}
|
||||
|
||||
// SessionHasPermissionToTeams returns true only if user has access to all teams.
|
||||
func (a *App) SessionHasPermissionToTeams(session model.Session, teamIDs []string, permission *model.Permission) bool {
|
||||
func (a *App) SessionHasPermissionToTeams(c request.CTX, session model.Session, teamIDs []string, permission *model.Permission) bool {
|
||||
for _, teamID := range teamIDs {
|
||||
if teamID == "" {
|
||||
return false
|
||||
@@ -91,7 +91,7 @@ func (a *App) SessionHasPermissionToTeams(session model.Session, teamIDs []strin
|
||||
return a.RolesGrantPermission(session.GetUserRoles(), permission.Id)
|
||||
}
|
||||
|
||||
func (a *App) SessionHasPermissionToChannel(session model.Session, channelID string, permission *model.Permission) bool {
|
||||
func (a *App) SessionHasPermissionToChannel(c request.CTX, session model.Session, channelID string, permission *model.Permission) bool {
|
||||
if channelID == "" {
|
||||
return false
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func (a *App) SessionHasPermissionToChannel(session model.Session, channelID str
|
||||
}
|
||||
}
|
||||
|
||||
channel, appErr := a.GetChannel(channelID)
|
||||
channel, appErr := a.GetChannel(c, channelID)
|
||||
if appErr != nil && appErr.StatusCode == http.StatusNotFound {
|
||||
return false
|
||||
}
|
||||
@@ -125,7 +125,7 @@ func (a *App) SessionHasPermissionToChannel(session model.Session, channelID str
|
||||
}
|
||||
|
||||
// SessionHasPermissionToChannels returns true only if user has access to all channels.
|
||||
func (a *App) SessionHasPermissionToChannels(session model.Session, channelIDs []string, permission *model.Permission) bool {
|
||||
func (a *App) SessionHasPermissionToChannels(c request.CTX, session model.Session, channelIDs []string, permission *model.Permission) bool {
|
||||
for _, channelID := range channelIDs {
|
||||
if channelID == "" {
|
||||
return false
|
||||
@@ -158,7 +158,7 @@ func (a *App) SessionHasPermissionToChannels(session model.Session, channelIDs [
|
||||
return true
|
||||
}
|
||||
|
||||
channels, appErr := a.GetChannels(channelIDs)
|
||||
channels, appErr := a.GetChannels(c, channelIDs)
|
||||
if appErr != nil && appErr.StatusCode == http.StatusNotFound {
|
||||
return false
|
||||
}
|
||||
@@ -177,7 +177,7 @@ func (a *App) SessionHasPermissionToChannels(session model.Session, channelIDs [
|
||||
}
|
||||
|
||||
if appErr == nil && len(teamIDs) > 0 {
|
||||
return a.SessionHasPermissionToTeams(session, teamIDs, permission)
|
||||
return a.SessionHasPermissionToTeams(c, session, teamIDs, permission)
|
||||
}
|
||||
|
||||
return a.SessionHasPermissionTo(session, permission)
|
||||
@@ -219,11 +219,11 @@ func (a *App) SessionHasPermissionToChannelByPost(session model.Session, postID
|
||||
return a.SessionHasPermissionTo(session, permission)
|
||||
}
|
||||
|
||||
func (a *App) SessionHasPermissionToCategory(session model.Session, userID, teamID, categoryId string) bool {
|
||||
func (a *App) SessionHasPermissionToCategory(c request.CTX, session model.Session, userID, teamID, categoryId string) bool {
|
||||
if a.SessionHasPermissionTo(session, model.PermissionEditOtherUsers) {
|
||||
return true
|
||||
}
|
||||
category, err := a.GetSidebarCategory(categoryId)
|
||||
category, err := a.GetSidebarCategory(c, categoryId)
|
||||
return err == nil && category != nil && category.UserId == session.UserId && category.UserId == userID && category.TeamId == teamID
|
||||
}
|
||||
|
||||
@@ -285,12 +285,12 @@ func (a *App) HasPermissionToTeam(askingUserId string, teamID string, permission
|
||||
return a.HasPermissionTo(askingUserId, permission)
|
||||
}
|
||||
|
||||
func (a *App) HasPermissionToChannel(askingUserId string, channelID string, permission *model.Permission) bool {
|
||||
func (a *App) HasPermissionToChannel(c request.CTX, askingUserId string, channelID string, permission *model.Permission) bool {
|
||||
if channelID == "" || askingUserId == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
channelMember, err := a.GetChannelMember(context.Background(), channelID, askingUserId)
|
||||
channelMember, err := a.GetChannelMember(c, channelID, askingUserId)
|
||||
if err == nil {
|
||||
roles := channelMember.GetRoles()
|
||||
if a.RolesGrantPermission(roles, permission.Id) {
|
||||
@@ -299,7 +299,7 @@ func (a *App) HasPermissionToChannel(askingUserId string, channelID string, perm
|
||||
}
|
||||
|
||||
var channel *model.Channel
|
||||
channel, err = a.GetChannel(channelID)
|
||||
channel, err = a.GetChannel(c, channelID)
|
||||
if err == nil {
|
||||
return a.HasPermissionToTeam(askingUserId, channel.TeamId, permission)
|
||||
}
|
||||
@@ -393,6 +393,6 @@ func (a *App) SessionHasPermissionToManageBot(session model.Session, botUserId s
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) HasPermissionToReadChannel(userID string, channel *model.Channel) bool {
|
||||
return a.HasPermissionToChannel(userID, channel.Id, model.PermissionReadChannel) || (channel.Type == model.ChannelTypeOpen && a.HasPermissionToTeam(userID, channel.TeamId, model.PermissionReadPublicChannel))
|
||||
func (a *App) HasPermissionToReadChannel(c request.CTX, userID string, channel *model.Channel) bool {
|
||||
return a.HasPermissionToChannel(c, userID, channel.Id, model.PermissionReadChannel) || (channel.Type == model.ChannelTypeOpen && a.HasPermissionToTeam(userID, channel.TeamId, model.PermissionReadPublicChannel))
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ func TestSessionHasPermissionToChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("basic user can access basic channel", func(t *testing.T) {
|
||||
assert.True(t, th.App.SessionHasPermissionToChannel(session, th.BasicChannel.Id, model.PermissionAddReaction))
|
||||
assert.True(t, th.App.SessionHasPermissionToChannel(th.Context, session, th.BasicChannel.Id, model.PermissionAddReaction))
|
||||
})
|
||||
|
||||
t.Run("does not panic if fetching channel causes an error", func(t *testing.T) {
|
||||
@@ -103,7 +103,7 @@ func TestSessionHasPermissionToChannel(t *testing.T) {
|
||||
|
||||
// If there's an error returned from the GetChannel call the code should continue to cascade and since there
|
||||
// are no session level permissions in this test case, the permission should be denied.
|
||||
assert.False(t, th.App.SessionHasPermissionToChannel(session, th.BasicUser.Id, model.PermissionAddReaction))
|
||||
assert.False(t, th.App.SessionHasPermissionToChannel(th.Context, session, th.BasicUser.Id, model.PermissionAddReaction))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -113,16 +113,16 @@ func TestHasPermissionToCategory(t *testing.T) {
|
||||
session, err := th.App.CreateSession(&model.Session{UserId: th.BasicUser.Id, Props: model.StringMap{}})
|
||||
require.Nil(t, err)
|
||||
|
||||
categories, err := th.App.GetSidebarCategoriesForTeamForUser(th.BasicUser.Id, th.BasicTeam.Id)
|
||||
categories, err := th.App.GetSidebarCategoriesForTeamForUser(th.Context, th.BasicUser.Id, th.BasicTeam.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = th.App.GetSession(session.Token)
|
||||
require.Nil(t, err)
|
||||
require.True(t, th.App.SessionHasPermissionToCategory(*session, th.BasicUser.Id, th.BasicTeam.Id, categories.Order[0]))
|
||||
require.True(t, th.App.SessionHasPermissionToCategory(th.Context, *session, th.BasicUser.Id, th.BasicTeam.Id, categories.Order[0]))
|
||||
|
||||
categories2, err := th.App.GetSidebarCategoriesForTeamForUser(th.BasicUser2.Id, th.BasicTeam.Id)
|
||||
categories2, err := th.App.GetSidebarCategoriesForTeamForUser(th.Context, th.BasicUser2.Id, th.BasicTeam.Id)
|
||||
require.Nil(t, err)
|
||||
require.False(t, th.App.SessionHasPermissionToCategory(*session, th.BasicUser.Id, th.BasicTeam.Id, categories2.Order[0]))
|
||||
require.False(t, th.App.SessionHasPermissionToCategory(th.Context, *session, th.BasicUser.Id, th.BasicTeam.Id, categories2.Order[0]))
|
||||
}
|
||||
|
||||
func TestSessionHasPermissionToGroup(t *testing.T) {
|
||||
|
||||
@@ -21,7 +21,7 @@ func (a *App) checkIfRespondedToday(createdAt int64, channelId, userId string) (
|
||||
)
|
||||
}
|
||||
|
||||
func (a *App) SendAutoResponseIfNecessary(c *request.Context, channel *model.Channel, sender *model.User, post *model.Post) (bool, *model.AppError) {
|
||||
func (a *App) SendAutoResponseIfNecessary(c request.CTX, channel *model.Channel, sender *model.User, post *model.Post) (bool, *model.AppError) {
|
||||
if channel.Type != model.ChannelTypeDirect {
|
||||
return false, nil
|
||||
}
|
||||
@@ -52,7 +52,7 @@ func (a *App) SendAutoResponseIfNecessary(c *request.Context, channel *model.Cha
|
||||
return a.SendAutoResponse(c, channel, receiver, post)
|
||||
}
|
||||
|
||||
func (a *App) SendAutoResponse(c *request.Context, channel *model.Channel, receiver *model.User, post *model.Post) (bool, *model.AppError) {
|
||||
func (a *App) SendAutoResponse(c request.CTX, channel *model.Channel, receiver *model.User, post *model.Post) (bool, *model.AppError) {
|
||||
if receiver == nil || receiver.NotifyProps == nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
+222
-222
File diff suppressed because it is too large
Load Diff
+16
-15
@@ -8,6 +8,7 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app/request"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
"github.com/mattermost/mattermost-server/v6/store"
|
||||
@@ -22,7 +23,7 @@ func (a *App) createInitialSidebarCategories(userID string, opts *store.SidebarC
|
||||
return categories, nil
|
||||
}
|
||||
|
||||
func (a *App) GetSidebarCategoriesForTeamForUser(userID, teamID string) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
func (a *App) GetSidebarCategoriesForTeamForUser(c request.CTX, userID, teamID string) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
var appErr *model.AppError
|
||||
categories, err := a.Srv().Store.Channel().GetSidebarCategoriesForTeamForUser(userID, teamID)
|
||||
if err == nil && len(categories.Categories) == 0 {
|
||||
@@ -49,7 +50,7 @@ func (a *App) GetSidebarCategoriesForTeamForUser(userID, teamID string) (*model.
|
||||
return categories, nil
|
||||
}
|
||||
|
||||
func (a *App) GetSidebarCategories(userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
func (a *App) GetSidebarCategories(c request.CTX, userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
var appErr *model.AppError
|
||||
categories, err := a.Srv().Store.Channel().GetSidebarCategories(userID, opts)
|
||||
if err == nil && len(categories.Categories) == 0 {
|
||||
@@ -73,7 +74,7 @@ func (a *App) GetSidebarCategories(userID string, opts *store.SidebarCategorySea
|
||||
return categories, nil
|
||||
}
|
||||
|
||||
func (a *App) GetSidebarCategoryOrder(userID, teamID string) ([]string, *model.AppError) {
|
||||
func (a *App) GetSidebarCategoryOrder(c request.CTX, userID, teamID string) ([]string, *model.AppError) {
|
||||
categories, err := a.Srv().Store.Channel().GetSidebarCategoryOrder(userID, teamID)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
@@ -88,7 +89,7 @@ func (a *App) GetSidebarCategoryOrder(userID, teamID string) ([]string, *model.A
|
||||
return categories, nil
|
||||
}
|
||||
|
||||
func (a *App) GetSidebarCategory(categoryId string) (*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
func (a *App) GetSidebarCategory(c request.CTX, categoryId string) (*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
category, err := a.Srv().Store.Channel().GetSidebarCategory(categoryId)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
@@ -103,7 +104,7 @@ func (a *App) GetSidebarCategory(categoryId string) (*model.SidebarCategoryWithC
|
||||
return category, nil
|
||||
}
|
||||
|
||||
func (a *App) CreateSidebarCategory(userID, teamID string, newCategory *model.SidebarCategoryWithChannels) (*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
func (a *App) CreateSidebarCategory(c request.CTX, userID, teamID string, newCategory *model.SidebarCategoryWithChannels) (*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
category, err := a.Srv().Store.Channel().CreateSidebarCategory(userID, teamID, newCategory)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
@@ -120,7 +121,7 @@ func (a *App) CreateSidebarCategory(userID, teamID string, newCategory *model.Si
|
||||
return category, nil
|
||||
}
|
||||
|
||||
func (a *App) UpdateSidebarCategoryOrder(userID, teamID string, categoryOrder []string) *model.AppError {
|
||||
func (a *App) UpdateSidebarCategoryOrder(c request.CTX, userID, teamID string, categoryOrder []string) *model.AppError {
|
||||
err := a.Srv().Store.Channel().UpdateSidebarCategoryOrder(userID, teamID, categoryOrder)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
@@ -140,7 +141,7 @@ func (a *App) UpdateSidebarCategoryOrder(userID, teamID string, categoryOrder []
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) UpdateSidebarCategories(userID, teamID string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
func (a *App) UpdateSidebarCategories(c request.CTX, userID, teamID string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
updatedCategories, originalCategories, err := a.Srv().Store.Channel().UpdateSidebarCategories(userID, teamID, categories)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("UpdateSidebarCategories", "app.channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
@@ -150,19 +151,19 @@ func (a *App) UpdateSidebarCategories(userID, teamID string, categories []*model
|
||||
|
||||
updatedCategoriesJSON, jsonErr := json.Marshal(updatedCategories)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode original categories to JSON", mlog.Err(jsonErr))
|
||||
c.Logger().Warn("Failed to encode original categories to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
|
||||
message.Add("updatedCategories", string(updatedCategoriesJSON))
|
||||
|
||||
a.Publish(message)
|
||||
|
||||
a.muteChannelsForUpdatedCategories(userID, updatedCategories, originalCategories)
|
||||
a.muteChannelsForUpdatedCategories(c, userID, updatedCategories, originalCategories)
|
||||
|
||||
return updatedCategories, nil
|
||||
}
|
||||
|
||||
func (a *App) muteChannelsForUpdatedCategories(userID string, updatedCategories []*model.SidebarCategoryWithChannels, originalCategories []*model.SidebarCategoryWithChannels) {
|
||||
func (a *App) muteChannelsForUpdatedCategories(c request.CTX, userID string, updatedCategories []*model.SidebarCategoryWithChannels, originalCategories []*model.SidebarCategoryWithChannels) {
|
||||
var channelsToMute []string
|
||||
var channelsToUnmute []string
|
||||
|
||||
@@ -210,9 +211,9 @@ func (a *App) muteChannelsForUpdatedCategories(userID string, updatedCategories
|
||||
}
|
||||
|
||||
if len(channelsToMute) > 0 {
|
||||
_, err := a.setChannelsMuted(channelsToMute, userID, true)
|
||||
_, err := a.setChannelsMuted(c, channelsToMute, userID, true)
|
||||
if err != nil {
|
||||
mlog.Error(
|
||||
c.Logger().Error(
|
||||
"Failed to mute channels to match category",
|
||||
mlog.String("user_id", userID),
|
||||
mlog.Err(err),
|
||||
@@ -221,9 +222,9 @@ func (a *App) muteChannelsForUpdatedCategories(userID string, updatedCategories
|
||||
}
|
||||
|
||||
if len(channelsToUnmute) > 0 {
|
||||
_, err := a.setChannelsMuted(channelsToUnmute, userID, false)
|
||||
_, err := a.setChannelsMuted(c, channelsToUnmute, userID, false)
|
||||
if err != nil {
|
||||
mlog.Error(
|
||||
c.Logger().Error(
|
||||
"Failed to unmute channels to match category",
|
||||
mlog.String("user_id", userID),
|
||||
mlog.Err(err),
|
||||
@@ -267,7 +268,7 @@ func diffChannelsBetweenCategories(updatedCategories []*model.SidebarCategoryWit
|
||||
return channelsDiff
|
||||
}
|
||||
|
||||
func (a *App) DeleteSidebarCategory(userID, teamID, categoryId string) *model.AppError {
|
||||
func (a *App) DeleteSidebarCategory(c request.CTX, userID, teamID, categoryId string) *model.AppError {
|
||||
err := a.Srv().Store.Channel().DeleteSidebarCategory(categoryId)
|
||||
if err != nil {
|
||||
var invErr *store.ErrInvalidInput
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -17,8 +16,8 @@ func TestSidebarCategory(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
basicChannel2 := th.CreateChannel(th.BasicTeam)
|
||||
defer th.App.PermanentDeleteChannel(basicChannel2)
|
||||
basicChannel2 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
defer th.App.PermanentDeleteChannel(th.Context, basicChannel2)
|
||||
user := th.CreateUser()
|
||||
defer th.App.Srv().Store.User().PermanentDelete(user.Id)
|
||||
th.LinkUserToTeam(user, th.BasicTeam)
|
||||
@@ -32,10 +31,10 @@ func TestSidebarCategory(t *testing.T) {
|
||||
},
|
||||
Channels: []string{th.BasicChannel.Id, basicChannel2.Id, basicChannel2.Id},
|
||||
}
|
||||
_, err := th.App.CreateSidebarCategory(user.Id, th.BasicTeam.Id, &catData)
|
||||
_, err := th.App.CreateSidebarCategory(th.Context, user.Id, th.BasicTeam.Id, &catData)
|
||||
require.NotNil(t, err, "Should return error due to duplicate IDs")
|
||||
catData.Channels = []string{th.BasicChannel.Id, basicChannel2.Id}
|
||||
cat, err := th.App.CreateSidebarCategory(user.Id, th.BasicTeam.Id, &catData)
|
||||
cat, err := th.App.CreateSidebarCategory(th.Context, user.Id, th.BasicTeam.Id, &catData)
|
||||
require.Nil(t, err, "Expected no error")
|
||||
require.NotNil(t, cat, "Expected category object, got nil")
|
||||
createdCategory = cat
|
||||
@@ -44,7 +43,7 @@ func TestSidebarCategory(t *testing.T) {
|
||||
t.Run("UpdateSidebarCategories", func(t *testing.T) {
|
||||
require.NotNil(t, createdCategory)
|
||||
createdCategory.Channels = []string{th.BasicChannel.Id}
|
||||
updatedCat, err := th.App.UpdateSidebarCategories(user.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{createdCategory})
|
||||
updatedCat, err := th.App.UpdateSidebarCategories(th.Context, user.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{createdCategory})
|
||||
require.Nil(t, err, "Expected no error")
|
||||
require.NotNil(t, updatedCat, "Expected category object, got nil")
|
||||
require.Len(t, updatedCat, 1)
|
||||
@@ -53,14 +52,14 @@ func TestSidebarCategory(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("UpdateSidebarCategoryOrder", func(t *testing.T) {
|
||||
err := th.App.UpdateSidebarCategoryOrder(user.Id, th.BasicTeam.Id, []string{th.BasicChannel.Id, basicChannel2.Id})
|
||||
err := th.App.UpdateSidebarCategoryOrder(th.Context, user.Id, th.BasicTeam.Id, []string{th.BasicChannel.Id, basicChannel2.Id})
|
||||
require.NotNil(t, err, "Should return error due to invalid order")
|
||||
|
||||
actualOrder, err := th.App.GetSidebarCategoryOrder(user.Id, th.BasicTeam.Id)
|
||||
actualOrder, err := th.App.GetSidebarCategoryOrder(th.Context, user.Id, th.BasicTeam.Id)
|
||||
require.Nil(t, err, "Should fetch order successfully")
|
||||
|
||||
actualOrder[2], actualOrder[3] = actualOrder[3], actualOrder[2]
|
||||
err = th.App.UpdateSidebarCategoryOrder(user.Id, th.BasicTeam.Id, actualOrder)
|
||||
err = th.App.UpdateSidebarCategoryOrder(th.Context, user.Id, th.BasicTeam.Id, actualOrder)
|
||||
require.Nil(t, err, "Should update order successfully")
|
||||
|
||||
// We create a copy of actualOrder to prevent racy read
|
||||
@@ -68,12 +67,12 @@ func TestSidebarCategory(t *testing.T) {
|
||||
newOrder := make([]string, len(actualOrder))
|
||||
copy(newOrder, actualOrder)
|
||||
newOrder[2] = "asd"
|
||||
err = th.App.UpdateSidebarCategoryOrder(user.Id, th.BasicTeam.Id, newOrder)
|
||||
err = th.App.UpdateSidebarCategoryOrder(th.Context, user.Id, th.BasicTeam.Id, newOrder)
|
||||
require.NotNil(t, err, "Should return error due to invalid id")
|
||||
})
|
||||
|
||||
t.Run("GetSidebarCategoryOrder", func(t *testing.T) {
|
||||
catOrder, err := th.App.GetSidebarCategoryOrder(user.Id, th.BasicTeam.Id)
|
||||
catOrder, err := th.App.GetSidebarCategoryOrder(th.Context, user.Id, th.BasicTeam.Id)
|
||||
require.Nil(t, err, "Expected no error")
|
||||
require.Len(t, catOrder, 4)
|
||||
require.Equal(t, catOrder[1], createdCategory.Id, "the newly created category should be after favorites")
|
||||
@@ -85,7 +84,7 @@ func TestGetSidebarCategories(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
_, err := th.App.CreateSidebarCategory(th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
_, err := th.App.CreateSidebarCategory(th.Context, th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
UserId: th.BasicUser.Id,
|
||||
TeamId: th.BasicTeam.Id,
|
||||
@@ -94,7 +93,7 @@ func TestGetSidebarCategories(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
categories, err := th.App.GetSidebarCategoriesForTeamForUser(th.BasicUser.Id, th.BasicTeam.Id)
|
||||
categories, err := th.App.GetSidebarCategoriesForTeamForUser(th.Context, th.BasicUser.Id, th.BasicTeam.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.Len(t, categories.Categories, 4)
|
||||
})
|
||||
@@ -113,7 +112,7 @@ func TestGetSidebarCategories(t *testing.T) {
|
||||
}, 100)
|
||||
require.NoError(t, err)
|
||||
|
||||
categories, appErr := th.App.GetSidebarCategoriesForTeamForUser(th.BasicUser.Id, team.Id)
|
||||
categories, appErr := th.App.GetSidebarCategoriesForTeamForUser(th.Context, th.BasicUser.Id, team.Id)
|
||||
assert.Nil(t, appErr)
|
||||
assert.Len(t, categories.Categories, 3)
|
||||
})
|
||||
@@ -131,7 +130,7 @@ func TestGetSidebarCategories(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
}()
|
||||
|
||||
categories, appErr := th.App.GetSidebarCategoriesForTeamForUser(th.BasicUser.Id, th.BasicTeam.Id)
|
||||
categories, appErr := th.App.GetSidebarCategoriesForTeamForUser(th.Context, th.BasicUser.Id, th.BasicTeam.Id)
|
||||
assert.Nil(t, categories)
|
||||
assert.NotNil(t, appErr)
|
||||
assert.Equal(t, "app.channel.sidebar_categories.app_error", appErr.Id)
|
||||
@@ -143,20 +142,20 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
categories, err := th.App.GetSidebarCategoriesForTeamForUser(th.BasicUser.Id, th.BasicTeam.Id)
|
||||
categories, err := th.App.GetSidebarCategoriesForTeamForUser(th.Context, th.BasicUser.Id, th.BasicTeam.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
channelsCategory := categories.Categories[1]
|
||||
|
||||
// Create some channels to be part of the channels category
|
||||
channel1 := th.CreateChannel(th.BasicTeam)
|
||||
channel1 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(th.BasicUser, channel1)
|
||||
|
||||
channel2 := th.CreateChannel(th.BasicTeam)
|
||||
channel2 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(th.BasicUser, channel2)
|
||||
|
||||
// Mute the category
|
||||
updated, err := th.App.UpdateSidebarCategories(th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
updated, err := th.App.UpdateSidebarCategories(th.Context, th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: channelsCategory.Id,
|
||||
@@ -169,15 +168,15 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
assert.True(t, updated[0].Muted)
|
||||
|
||||
// Confirm that the channels are now muted
|
||||
member1, err := th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
member1, err := th.App.GetChannelMember(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member1.IsChannelMuted())
|
||||
member2, err := th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
member2, err := th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member2.IsChannelMuted())
|
||||
|
||||
// Unmute the category
|
||||
updated, err = th.App.UpdateSidebarCategories(th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
updated, err = th.App.UpdateSidebarCategories(th.Context, th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: channelsCategory.Id,
|
||||
@@ -190,10 +189,10 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
assert.False(t, updated[0].Muted)
|
||||
|
||||
// Confirm that the channels are now unmuted
|
||||
member1, err = th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
member1, err = th.App.GetChannelMember(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member1.IsChannelMuted())
|
||||
member2, err = th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
member2, err = th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member2.IsChannelMuted())
|
||||
})
|
||||
@@ -203,14 +202,14 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
// Create some channels
|
||||
channel1 := th.CreateChannel(th.BasicTeam)
|
||||
channel1 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(th.BasicUser, channel1)
|
||||
|
||||
channel2 := th.CreateChannel(th.BasicTeam)
|
||||
channel2 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(th.BasicUser, channel2)
|
||||
|
||||
// And some categories
|
||||
mutedCategory, err := th.App.CreateSidebarCategory(th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
mutedCategory, err := th.App.CreateSidebarCategory(th.Context, th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
DisplayName: "muted",
|
||||
Muted: true,
|
||||
@@ -219,7 +218,7 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
require.True(t, mutedCategory.Muted)
|
||||
|
||||
unmutedCategory, err := th.App.CreateSidebarCategory(th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
unmutedCategory, err := th.App.CreateSidebarCategory(th.Context, th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
DisplayName: "unmuted",
|
||||
Muted: false,
|
||||
@@ -230,7 +229,7 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
require.False(t, unmutedCategory.Muted)
|
||||
|
||||
// Move the channels
|
||||
_, err = th.App.UpdateSidebarCategories(th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
_, err = th.App.UpdateSidebarCategories(th.Context, th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: mutedCategory.Id,
|
||||
@@ -251,15 +250,15 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// Confirm that the channels are now muted
|
||||
member1, err := th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
member1, err := th.App.GetChannelMember(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member1.IsChannelMuted())
|
||||
member2, err := th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
member2, err := th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member2.IsChannelMuted())
|
||||
|
||||
// Move the channels back
|
||||
_, err = th.App.UpdateSidebarCategories(th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
_, err = th.App.UpdateSidebarCategories(th.Context, th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: mutedCategory.Id,
|
||||
@@ -280,10 +279,10 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// Confirm that the channels are now unmuted
|
||||
member1, err = th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
member1, err = th.App.GetChannelMember(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member1.IsChannelMuted())
|
||||
member2, err = th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
member2, err = th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member2.IsChannelMuted())
|
||||
})
|
||||
@@ -293,14 +292,14 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
// Create some channels
|
||||
channel1 := th.CreateChannel(th.BasicTeam)
|
||||
channel1 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(th.BasicUser, channel1)
|
||||
|
||||
channel2 := th.CreateChannel(th.BasicTeam)
|
||||
channel2 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(th.BasicUser, channel2)
|
||||
|
||||
// And some categories
|
||||
category1, err := th.App.CreateSidebarCategory(th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
category1, err := th.App.CreateSidebarCategory(th.Context, th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
DisplayName: "category1",
|
||||
Muted: true,
|
||||
@@ -309,7 +308,7 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
require.True(t, category1.Muted)
|
||||
|
||||
category2, err := th.App.CreateSidebarCategory(th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
category2, err := th.App.CreateSidebarCategory(th.Context, th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
DisplayName: "category2",
|
||||
Muted: true,
|
||||
@@ -320,7 +319,7 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
require.True(t, category2.Muted)
|
||||
|
||||
// Move the unmuted channels
|
||||
_, err = th.App.UpdateSidebarCategories(th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
_, err = th.App.UpdateSidebarCategories(th.Context, th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: category1.Id,
|
||||
@@ -341,21 +340,21 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// Confirm that the channels are still unmuted
|
||||
member1, err := th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
member1, err := th.App.GetChannelMember(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member1.IsChannelMuted())
|
||||
member2, err := th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
member2, err := th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member2.IsChannelMuted())
|
||||
|
||||
// Mute the channels manually
|
||||
_, err = th.App.ToggleMuteChannel(channel1.Id, th.BasicUser.Id)
|
||||
_, err = th.App.ToggleMuteChannel(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.ToggleMuteChannel(channel2.Id, th.BasicUser.Id)
|
||||
_, err = th.App.ToggleMuteChannel(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
// Move the muted channels back
|
||||
_, err = th.App.UpdateSidebarCategories(th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
_, err = th.App.UpdateSidebarCategories(th.Context, th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: category1.Id,
|
||||
@@ -376,10 +375,10 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// Confirm that the channels are still muted
|
||||
member1, err = th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
member1, err = th.App.GetChannelMember(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member1.IsChannelMuted())
|
||||
member2, err = th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
member2, err = th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member2.IsChannelMuted())
|
||||
})
|
||||
@@ -389,14 +388,14 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
// Create some channels
|
||||
channel1 := th.CreateChannel(th.BasicTeam)
|
||||
channel1 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(th.BasicUser, channel1)
|
||||
|
||||
channel2 := th.CreateChannel(th.BasicTeam)
|
||||
channel2 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(th.BasicUser, channel2)
|
||||
|
||||
// And some categories
|
||||
category1, err := th.App.CreateSidebarCategory(th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
category1, err := th.App.CreateSidebarCategory(th.Context, th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
DisplayName: "category1",
|
||||
Muted: false,
|
||||
@@ -405,7 +404,7 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
require.False(t, category1.Muted)
|
||||
|
||||
category2, err := th.App.CreateSidebarCategory(th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
category2, err := th.App.CreateSidebarCategory(th.Context, th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
DisplayName: "category2",
|
||||
Muted: false,
|
||||
@@ -416,7 +415,7 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
require.False(t, category2.Muted)
|
||||
|
||||
// Move the unmuted channels
|
||||
_, err = th.App.UpdateSidebarCategories(th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
_, err = th.App.UpdateSidebarCategories(th.Context, th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: category1.Id,
|
||||
@@ -437,21 +436,21 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// Confirm that the channels are still unmuted
|
||||
member1, err := th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
member1, err := th.App.GetChannelMember(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member1.IsChannelMuted())
|
||||
member2, err := th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
member2, err := th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member2.IsChannelMuted())
|
||||
|
||||
// Mute the channels manually
|
||||
_, err = th.App.ToggleMuteChannel(channel1.Id, th.BasicUser.Id)
|
||||
_, err = th.App.ToggleMuteChannel(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.ToggleMuteChannel(channel2.Id, th.BasicUser.Id)
|
||||
_, err = th.App.ToggleMuteChannel(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
// Move the muted channels back
|
||||
_, err = th.App.UpdateSidebarCategories(th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
_, err = th.App.UpdateSidebarCategories(th.Context, th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: category1.Id,
|
||||
@@ -472,10 +471,10 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// Confirm that the channels are still muted
|
||||
member1, err = th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
member1, err = th.App.GetChannelMember(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member1.IsChannelMuted())
|
||||
member2, err = th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
member2, err = th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member2.IsChannelMuted())
|
||||
})
|
||||
|
||||
+189
-189
File diff suppressed because it is too large
Load Diff
+4
-4
@@ -178,12 +178,12 @@ func NewChannels(s *Server, services map[ServiceKey]any) (*Channels, error) {
|
||||
if samlInterfaceNew != nil {
|
||||
ch.Saml = samlInterfaceNew(New(ServerConnector(ch)))
|
||||
if err := ch.Saml.ConfigureSP(); err != nil {
|
||||
mlog.Error("An error occurred while configuring SAML Service Provider", mlog.Err(err))
|
||||
s.Log.Error("An error occurred while configuring SAML Service Provider", mlog.Err(err))
|
||||
}
|
||||
|
||||
ch.AddConfigListener(func(_, _ *model.Config) {
|
||||
if err := ch.Saml.ConfigureSP(); err != nil {
|
||||
mlog.Error("An error occurred while configuring SAML Service Provider", mlog.Err(err))
|
||||
s.Log.Error("An error occurred while configuring SAML Service Provider", mlog.Err(err))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -240,7 +240,7 @@ func NewChannels(s *Server, services map[ServiceKey]any) (*Channels, error) {
|
||||
|
||||
func (ch *Channels) Start() error {
|
||||
// Start plugins
|
||||
ctx := request.EmptyContext()
|
||||
ctx := request.EmptyContext(ch.srv.GetLogger())
|
||||
ch.initPlugins(ctx, *ch.cfgSvc.Config().PluginSettings.Directory, *ch.cfgSvc.Config().PluginSettings.ClientDirectory)
|
||||
|
||||
ch.AddConfigListener(func(prevCfg, cfg *model.Config) {
|
||||
@@ -248,7 +248,7 @@ func (ch *Channels) Start() error {
|
||||
// to ensure we don't re-init plugins unnecessarily.
|
||||
diffs, err := config.Diff(prevCfg, cfg)
|
||||
if err != nil {
|
||||
mlog.Warn("Error in comparing configs", mlog.Err(err))
|
||||
ch.srv.Log.Warn("Error in comparing configs", mlog.Err(err))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -75,7 +75,7 @@ func (a *App) CreateCommandPost(c *request.Context, post *model.Post, teamID str
|
||||
}
|
||||
|
||||
if (response.ResponseType == "" || response.ResponseType == model.CommandResponseTypeEphemeral) && (response.Text != "" || response.Attachments != nil) {
|
||||
a.SendEphemeralPost(post.UserId, post)
|
||||
a.SendEphemeralPost(c, post.UserId, post)
|
||||
}
|
||||
|
||||
return post, nil
|
||||
@@ -213,7 +213,7 @@ func (a *App) ExecuteCommand(c *request.Context, args *model.CommandArgs) (*mode
|
||||
}
|
||||
|
||||
// Custom commands can override built ins
|
||||
cmd, response, appErr = a.tryExecuteCustomCommand(args, trigger, message)
|
||||
cmd, response, appErr = a.tryExecuteCustomCommand(c, args, trigger, message)
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
} else if cmd != nil && response != nil {
|
||||
@@ -307,7 +307,7 @@ func (a *App) MentionsToTeamMembers(message, teamID string) model.UserMentionMap
|
||||
|
||||
// MentionsToPublicChannels returns all the mentions to public channels,
|
||||
// linking them to their channels
|
||||
func (a *App) MentionsToPublicChannels(message, teamID string) model.ChannelMentionMap {
|
||||
func (a *App) MentionsToPublicChannels(c request.CTX, message, teamID string) model.ChannelMentionMap {
|
||||
type mentionMapItem struct {
|
||||
Name string
|
||||
Id string
|
||||
@@ -321,7 +321,7 @@ func (a *App) MentionsToPublicChannels(message, teamID string) model.ChannelMent
|
||||
wg.Add(1)
|
||||
go func(channelName string) {
|
||||
defer wg.Done()
|
||||
channel, err := a.GetChannelByName(channelName, teamID, false)
|
||||
channel, err := a.GetChannelByName(c, channelName, teamID, false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -363,7 +363,7 @@ func (a *App) tryExecuteBuiltInCommand(c *request.Context, args *model.CommandAr
|
||||
|
||||
// tryExecuteCustomCommand attempts to run a custom command based on the given arguments. If no such command can be
|
||||
// found, returns nil for all arguments.
|
||||
func (a *App) tryExecuteCustomCommand(args *model.CommandArgs, trigger string, message string) (*model.Command, *model.CommandResponse, *model.AppError) {
|
||||
func (a *App) tryExecuteCustomCommand(c request.CTX, args *model.CommandArgs, trigger string, message string) (*model.Command, *model.CommandResponse, *model.AppError) {
|
||||
// Handle custom commands
|
||||
if !*a.Config().ServiceSettings.EnableCommands {
|
||||
return nil, nil, model.NewAppError("ExecuteCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
@@ -467,7 +467,7 @@ func (a *App) tryExecuteCustomCommand(args *model.CommandArgs, trigger string, m
|
||||
p[key] = values
|
||||
}
|
||||
|
||||
channelMentionMap := a.MentionsToPublicChannels(message, team.Id)
|
||||
channelMentionMap := a.MentionsToPublicChannels(c, message, team.Id)
|
||||
for key, values := range channelMentionMap.ToURLValues() {
|
||||
p[key] = values
|
||||
}
|
||||
@@ -579,7 +579,7 @@ func (a *App) HandleCommandResponsePost(c *request.Context, command *model.Comma
|
||||
post.SetProps(response.Props)
|
||||
|
||||
if response.ChannelId != "" {
|
||||
_, err := a.GetChannelMember(context.Background(), response.ChannelId, args.UserId)
|
||||
_, err := a.GetChannelMember(c, response.ChannelId, args.UserId)
|
||||
if err != nil {
|
||||
err = model.NewAppError("HandleCommandResponsePost", "api.command.command_post.forbidden.app_error", nil, err.Error(), http.StatusForbidden)
|
||||
return nil, err
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ func WithMaster(ctx context.Context) context.Context {
|
||||
return sqlstore.WithMaster(ctx)
|
||||
}
|
||||
|
||||
func pluginContext(c *request.Context) *plugin.Context {
|
||||
func pluginContext(c request.CTX) *plugin.Context {
|
||||
context := &plugin.Context{
|
||||
RequestId: c.RequestId(),
|
||||
SessionId: c.Session().Id,
|
||||
|
||||
+8
-8
@@ -97,7 +97,7 @@ func TestExportUserChannels(t *testing.T) {
|
||||
err := th.App.Srv().Store.Preference().Save(preferences)
|
||||
require.NoError(t, err)
|
||||
|
||||
th.App.UpdateChannelMemberNotifyProps(notifyProps, channel.Id, user.Id)
|
||||
th.App.UpdateChannelMemberNotifyProps(th.Context, notifyProps, channel.Id, user.Id)
|
||||
exportData, appErr := th.App.buildUserChannelMemberships(user.Id, team.Id)
|
||||
require.Nil(t, appErr)
|
||||
assert.Equal(t, len(*exportData), 3)
|
||||
@@ -327,7 +327,7 @@ func TestExportGMChannel(t *testing.T) {
|
||||
th1.LinkUserToTeam(user2, th1.BasicTeam)
|
||||
|
||||
// GM Channel
|
||||
th1.CreateGroupChannel(user1, user2)
|
||||
th1.CreateGroupChannel(th1.Context, user1, user2)
|
||||
|
||||
var b bytes.Buffer
|
||||
err := th1.App.BulkExport(&b, "somePath", model.BulkExportOpts{})
|
||||
@@ -359,7 +359,7 @@ func TestExportGMandDMChannels(t *testing.T) {
|
||||
th1.LinkUserToTeam(user2, th1.BasicTeam)
|
||||
|
||||
// GM Channel
|
||||
th1.CreateGroupChannel(user1, user2)
|
||||
th1.CreateGroupChannel(th1.Context, user1, user2)
|
||||
|
||||
var b bytes.Buffer
|
||||
err := th1.App.BulkExport(&b, "somePath", model.BulkExportOpts{})
|
||||
@@ -407,7 +407,7 @@ func TestExportDMandGMPost(t *testing.T) {
|
||||
th1.LinkUserToTeam(user2, th1.BasicTeam)
|
||||
|
||||
// GM Channel
|
||||
gmChannel := th1.CreateGroupChannel(user1, user2)
|
||||
gmChannel := th1.CreateGroupChannel(th1.Context, user1, user2)
|
||||
gmMembers := []string{th1.BasicUser.Username, user1.Username, user2.Username}
|
||||
|
||||
// DM posts
|
||||
@@ -489,7 +489,7 @@ func TestExportPostWithProps(t *testing.T) {
|
||||
th1.LinkUserToTeam(user2, th1.BasicTeam)
|
||||
|
||||
// GM Channel
|
||||
gmChannel := th1.CreateGroupChannel(user1, user2)
|
||||
gmChannel := th1.CreateGroupChannel(th1.Context, user1, user2)
|
||||
gmMembers := []string{th1.BasicUser.Username, user1.Username, user2.Username}
|
||||
|
||||
// DM posts
|
||||
@@ -709,7 +709,7 @@ func TestExportDeletedTeams(t *testing.T) {
|
||||
defer th1.TearDown()
|
||||
|
||||
team1 := th1.CreateTeam()
|
||||
channel1 := th1.CreateChannel(team1)
|
||||
channel1 := th1.CreateChannel(th1.Context, team1)
|
||||
th1.CreatePost(channel1)
|
||||
|
||||
// Delete the team to check that this is handled correctly on import.
|
||||
@@ -733,9 +733,9 @@ func TestExportDeletedTeams(t *testing.T) {
|
||||
assert.Equal(t, len(teams1), len(teams2))
|
||||
assert.ElementsMatch(t, teams1, teams2)
|
||||
|
||||
channels1, err := th1.App.GetAllChannels(0, 10, model.ChannelSearchOpts{})
|
||||
channels1, err := th1.App.GetAllChannels(th1.Context, 0, 10, model.ChannelSearchOpts{})
|
||||
assert.Nil(t, err)
|
||||
channels2, err := th2.App.GetAllChannels(0, 10, model.ChannelSearchOpts{})
|
||||
channels2, err := th2.App.GetAllChannels(th1.Context, 0, 10, model.ChannelSearchOpts{})
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, len(channels1), len(channels2))
|
||||
assert.ElementsMatch(t, channels1, channels2)
|
||||
|
||||
+1
-1
@@ -520,7 +520,7 @@ func (a *App) UploadFiles(c *request.Context, teamID string, channelID string, u
|
||||
|
||||
// UploadFile uploads a single file in form of a completely constructed byte array for a channel.
|
||||
func (a *App) UploadFile(c *request.Context, data []byte, channelID string, filename string) (*model.FileInfo, *model.AppError) {
|
||||
_, err := a.GetChannel(channelID)
|
||||
_, err := a.GetChannel(c, channelID)
|
||||
if err != nil && channelID != "" {
|
||||
return nil, model.NewAppError("UploadFile", "api.file.upload_file.incorrect_channelId.app_error",
|
||||
map[string]any{"channelId": channelID}, "", http.StatusBadRequest)
|
||||
|
||||
+1
-1
@@ -200,7 +200,7 @@ func TestUpsertGroupSyncableTeamGroupConstrained(t *testing.T) {
|
||||
_, err = th.App.UpsertGroupSyncable(model.NewGroupTeam(group1.Id, team.Id, false))
|
||||
require.Nil(t, err)
|
||||
|
||||
channel := th.CreateChannel(team)
|
||||
channel := th.CreateChannel(th.Context, team)
|
||||
|
||||
_, err = th.App.UpsertGroupSyncable(model.NewGroupChannel(group2.Id, channel.Id, false))
|
||||
require.NotNil(t, err)
|
||||
|
||||
+12
-11
@@ -99,12 +99,13 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo
|
||||
|
||||
th := &TestHelper{
|
||||
App: New(ServerConnector(s.Channels())),
|
||||
Context: &request.Context{},
|
||||
Context: request.EmptyContext(testLogger),
|
||||
Server: s,
|
||||
LogBuffer: buffer,
|
||||
TestLogger: testLogger,
|
||||
IncludeCacheLayer: includeCacheLayer,
|
||||
}
|
||||
th.Context.SetLogger(testLogger)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.MaxUsersPerTeam = 50 })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.RateLimitSettings.Enable = false })
|
||||
@@ -245,7 +246,7 @@ func (th *TestHelper) InitBasic() *TestHelper {
|
||||
|
||||
th.LinkUserToTeam(th.BasicUser, th.BasicTeam)
|
||||
th.LinkUserToTeam(th.BasicUser2, th.BasicTeam)
|
||||
th.BasicChannel = th.CreateChannel(th.BasicTeam)
|
||||
th.BasicChannel = th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.BasicPost = th.CreatePost(th.BasicChannel)
|
||||
return th
|
||||
}
|
||||
@@ -327,15 +328,15 @@ func WithShared(v bool) ChannelOption {
|
||||
}
|
||||
}
|
||||
|
||||
func (th *TestHelper) CreateChannel(team *model.Team, options ...ChannelOption) *model.Channel {
|
||||
return th.createChannel(team, model.ChannelTypeOpen, options...)
|
||||
func (th *TestHelper) CreateChannel(c request.CTX, team *model.Team, options ...ChannelOption) *model.Channel {
|
||||
return th.createChannel(c, team, model.ChannelTypeOpen, options...)
|
||||
}
|
||||
|
||||
func (th *TestHelper) CreatePrivateChannel(team *model.Team) *model.Channel {
|
||||
return th.createChannel(team, model.ChannelTypePrivate)
|
||||
func (th *TestHelper) CreatePrivateChannel(c request.CTX, team *model.Team) *model.Channel {
|
||||
return th.createChannel(c, team, model.ChannelTypePrivate)
|
||||
}
|
||||
|
||||
func (th *TestHelper) createChannel(team *model.Team, channelType model.ChannelType, options ...ChannelOption) *model.Channel {
|
||||
func (th *TestHelper) createChannel(c request.CTX, team *model.Team, channelType model.ChannelType, options ...ChannelOption) *model.Channel {
|
||||
id := model.NewId()
|
||||
|
||||
channel := &model.Channel{
|
||||
@@ -357,7 +358,7 @@ func (th *TestHelper) createChannel(team *model.Team, channelType model.ChannelT
|
||||
|
||||
if channel.IsShared() {
|
||||
id := model.NewId()
|
||||
_, err := th.App.SaveSharedChannel(&model.SharedChannel{
|
||||
_, err := th.App.SaveSharedChannel(c, &model.SharedChannel{
|
||||
ChannelId: channel.Id,
|
||||
TeamId: channel.TeamId,
|
||||
Home: false,
|
||||
@@ -383,10 +384,10 @@ func (th *TestHelper) CreateDmChannel(user *model.User) *model.Channel {
|
||||
return channel
|
||||
}
|
||||
|
||||
func (th *TestHelper) CreateGroupChannel(user1 *model.User, user2 *model.User) *model.Channel {
|
||||
func (th *TestHelper) CreateGroupChannel(c request.CTX, user1 *model.User, user2 *model.User) *model.Channel {
|
||||
var err *model.AppError
|
||||
var channel *model.Channel
|
||||
if channel, err = th.App.CreateGroupChannel([]string{th.BasicUser.Id, user1.Id, user2.Id}, th.BasicUser.Id); err != nil {
|
||||
if channel, err = th.App.CreateGroupChannel(c, []string{th.BasicUser.Id, user1.Id, user2.Id}, th.BasicUser.Id); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return channel
|
||||
@@ -439,7 +440,7 @@ func (th *TestHelper) RemoveUserFromTeam(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)
|
||||
}
|
||||
|
||||
+2
-2
@@ -302,12 +302,12 @@ func (a *App) importLine(c *request.Context, line LineImportData, dryRun bool) *
|
||||
if line.User == nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_line.null_user.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
return a.importUser(line.User, dryRun)
|
||||
return a.importUser(c, line.User, dryRun)
|
||||
case line.Type == "direct_channel":
|
||||
if line.DirectChannel == nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_line.null_direct_channel.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
return a.importDirectChannel(line.DirectChannel, dryRun)
|
||||
return a.importDirectChannel(c, line.DirectChannel, dryRun)
|
||||
case line.Type == "emoji":
|
||||
if line.Emoji == nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_line.null_emoji.error", nil, "", http.StatusBadRequest)
|
||||
|
||||
+12
-12
@@ -284,7 +284,7 @@ func (a *App) importChannel(c *request.Context, data *ChannelImportData, dryRun
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if _, err := a.UpdateChannel(channel); err != nil {
|
||||
if _, err := a.UpdateChannel(c, channel); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -292,7 +292,7 @@ func (a *App) importChannel(c *request.Context, data *ChannelImportData, dryRun
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) importUser(data *UserImportData, dryRun bool) *model.AppError {
|
||||
func (a *App) importUser(c request.CTX, data *UserImportData, dryRun bool) *model.AppError {
|
||||
if err := validateUserImportData(data); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -728,10 +728,10 @@ func (a *App) importUser(data *UserImportData, dryRun bool) *model.AppError {
|
||||
}
|
||||
}
|
||||
|
||||
return a.importUserTeams(savedUser, data.Teams)
|
||||
return a.importUserTeams(c, savedUser, data.Teams)
|
||||
}
|
||||
|
||||
func (a *App) importUserTeams(user *model.User, data *[]UserTeamImportData) *model.AppError {
|
||||
func (a *App) importUserTeams(c request.CTX, user *model.User, data *[]UserTeamImportData) *model.AppError {
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -882,7 +882,7 @@ func (a *App) importUserTeams(user *model.User, data *[]UserTeamImportData) *mod
|
||||
}
|
||||
}
|
||||
channelsToImport := channels[team.Id]
|
||||
if err := a.importUserChannels(user, team, &channelsToImport); err != nil {
|
||||
if err := a.importUserChannels(c, user, team, &channelsToImport); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -890,7 +890,7 @@ func (a *App) importUserTeams(user *model.User, data *[]UserTeamImportData) *mod
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) importUserChannels(user *model.User, team *model.Team, data *[]UserChannelImportData) *model.AppError {
|
||||
func (a *App) importUserChannels(c request.CTX, user *model.User, team *model.Team, data *[]UserChannelImportData) *model.AppError {
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -1040,12 +1040,12 @@ func (a *App) importUserChannels(user *model.User, team *model.Team, data *[]Use
|
||||
|
||||
for _, member := range append(newMembers, oldMembers...) {
|
||||
if member.ExplicitRoles != rolesByChannelId[member.ChannelId] {
|
||||
if _, err = a.UpdateChannelMemberRoles(member.ChannelId, user.Id, rolesByChannelId[member.ChannelId]); err != nil {
|
||||
if _, err = a.UpdateChannelMemberRoles(c, member.ChannelId, user.Id, rolesByChannelId[member.ChannelId]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
a.UpdateChannelMemberSchemeRoles(member.ChannelId, user.Id, isGuestByChannelId[member.ChannelId], isUserByChannelId[member.ChannelId], isAdminByChannelId[member.ChannelId])
|
||||
a.UpdateChannelMemberSchemeRoles(c, member.ChannelId, user.Id, isGuestByChannelId[member.ChannelId], isUserByChannelId[member.ChannelId], isAdminByChannelId[member.ChannelId])
|
||||
}
|
||||
|
||||
for _, channel := range allChannels {
|
||||
@@ -1564,7 +1564,7 @@ func (a *App) updateFileInfoWithPostId(post *model.Post) {
|
||||
}
|
||||
}
|
||||
}
|
||||
func (a *App) importDirectChannel(data *DirectChannelImportData, dryRun bool) *model.AppError {
|
||||
func (a *App) importDirectChannel(c request.CTX, data *DirectChannelImportData, dryRun bool) *model.AppError {
|
||||
var err *model.AppError
|
||||
if err = validateDirectChannelImportData(data); err != nil {
|
||||
return err
|
||||
@@ -1587,13 +1587,13 @@ func (a *App) importDirectChannel(data *DirectChannelImportData, dryRun bool) *m
|
||||
var channel *model.Channel
|
||||
|
||||
if len(userIDs) == 2 {
|
||||
ch, err := a.createDirectChannel(userIDs[0], userIDs[1])
|
||||
ch, err := a.createDirectChannel(c, userIDs[0], userIDs[1])
|
||||
if err != nil && err.Id != store.ChannelExistsError {
|
||||
return model.NewAppError("BulkImport", "app.import.import_direct_channel.create_direct_channel.error", nil, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
channel = ch
|
||||
} else {
|
||||
ch, err := a.createGroupChannel(userIDs)
|
||||
ch, err := a.createGroupChannel(c, userIDs)
|
||||
if err != nil && err.Id != store.ChannelExistsError {
|
||||
return model.NewAppError("BulkImport", "app.import.import_direct_channel.create_group_channel.error", nil, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
@@ -1698,7 +1698,7 @@ func (a *App) importMultipleDirectPostLines(c *request.Context, lines []LineImpo
|
||||
}
|
||||
channel = ch
|
||||
} else {
|
||||
ch, err = a.createGroupChannel(userIDs)
|
||||
ch, err = a.createGroupChannel(c, userIDs)
|
||||
if err != nil && err.Id != store.ChannelExistsError {
|
||||
return line.LineNumber, model.NewAppError("BulkImport", "app.import.import_direct_post.create_group_channel.error", nil, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
@@ -671,7 +671,7 @@ func TestImportImportChannel(t *testing.T) {
|
||||
th.CheckChannelsCount(t, channelCount+1)
|
||||
|
||||
// Get the Channel and check all the fields are correct.
|
||||
channel, err := th.App.GetChannelByName(*data.Name, team.Id, false)
|
||||
channel, err := th.App.GetChannelByName(th.Context, *data.Name, team.Id, false)
|
||||
require.Nil(t, err, "Failed to get channel from database.")
|
||||
|
||||
assert.Equal(t, *data.Name, channel.Name)
|
||||
@@ -695,7 +695,7 @@ func TestImportImportChannel(t *testing.T) {
|
||||
th.CheckChannelsCount(t, channelCount)
|
||||
|
||||
// Get the Channel and check all the fields are correct.
|
||||
channel, err = th.App.GetChannelByName(*data.Name, team.Id, false)
|
||||
channel, err = th.App.GetChannelByName(th.Context, *data.Name, team.Id, false)
|
||||
require.Nil(t, err, "Failed to get channel from database.")
|
||||
|
||||
assert.Equal(t, *data.Name, channel.Name)
|
||||
@@ -722,7 +722,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
data := UserImportData{
|
||||
Username: ptrStr(model.NewId()),
|
||||
}
|
||||
err = th.App.importUser(&data, true)
|
||||
err = th.App.importUser(th.Context, &data, true)
|
||||
require.Error(t, err, "Should have failed to import invalid user.")
|
||||
|
||||
// Check that no more users are in the DB.
|
||||
@@ -738,7 +738,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
Username: ptrStr(model.NewId()),
|
||||
Email: ptrStr(model.NewId() + "@example.com"),
|
||||
}
|
||||
appErr := th.App.importUser(&data, true)
|
||||
appErr := th.App.importUser(th.Context, &data, true)
|
||||
require.Nil(t, appErr, "Should have succeeded to import valid user.")
|
||||
|
||||
// Check that no more users are in the DB.
|
||||
@@ -753,7 +753,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
data = UserImportData{
|
||||
Username: ptrStr(model.NewId()),
|
||||
}
|
||||
err = th.App.importUser(&data, false)
|
||||
err = th.App.importUser(th.Context, &data, false)
|
||||
require.Error(t, err, "Should have failed to import invalid user.")
|
||||
|
||||
// Check that no more users are in the DB.
|
||||
@@ -776,7 +776,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
LastName: ptrStr(model.NewId()),
|
||||
Position: ptrStr(model.NewId()),
|
||||
}
|
||||
appErr = th.App.importUser(&data, false)
|
||||
appErr = th.App.importUser(th.Context, &data, false)
|
||||
require.Nil(t, appErr, "Should have succeeded to import valid user.")
|
||||
|
||||
// Check that one more user is in the DB.
|
||||
@@ -819,7 +819,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
data.Roles = ptrStr("system_admin system_user")
|
||||
data.Locale = ptrStr("zh_CN")
|
||||
|
||||
appErr = th.App.importUser(&data, false)
|
||||
appErr = th.App.importUser(th.Context, &data, false)
|
||||
require.Nil(t, appErr, "Should have succeeded to update valid user %v", err)
|
||||
|
||||
// Check user count the same.
|
||||
@@ -851,20 +851,20 @@ func TestImportImportUser(t *testing.T) {
|
||||
|
||||
// Check Password and AuthData together.
|
||||
data.Password = ptrStr("PasswordTest")
|
||||
appErr = th.App.importUser(&data, false)
|
||||
appErr = th.App.importUser(th.Context, &data, false)
|
||||
require.NotNil(t, appErr, "Should have failed to import invalid user.")
|
||||
|
||||
data.AuthData = nil
|
||||
data.AuthService = nil
|
||||
appErr = th.App.importUser(&data, false)
|
||||
appErr = th.App.importUser(th.Context, &data, false)
|
||||
require.Nil(t, appErr, "Should have succeeded to update valid user %v", err)
|
||||
|
||||
data.Password = ptrStr("")
|
||||
appErr = th.App.importUser(&data, false)
|
||||
appErr = th.App.importUser(th.Context, &data, false)
|
||||
require.NotNil(t, appErr, "Should have failed to import invalid user.")
|
||||
|
||||
data.Password = ptrStr(strings.Repeat("0123456789", 10))
|
||||
appErr = th.App.importUser(&data, false)
|
||||
appErr = th.App.importUser(th.Context, &data, false)
|
||||
require.NotNil(t, appErr, "Should have failed to import invalid user.")
|
||||
|
||||
data.Password = ptrStr("TestPassword")
|
||||
@@ -887,7 +887,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
DisplayName: ptrStr("Display Name"),
|
||||
Type: &chanTypeOpen,
|
||||
}, false)
|
||||
channel, appErr := th.App.GetChannelByName(channelName, team.Id, false)
|
||||
channel, appErr := th.App.GetChannelByName(th.Context, channelName, team.Id, false)
|
||||
require.Nil(t, appErr, "Failed to get channel from database.")
|
||||
|
||||
username = model.NewId()
|
||||
@@ -904,7 +904,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
require.Nil(t, appErr, "Failed to get team member count")
|
||||
teamMemberCount := len(teamMembers)
|
||||
|
||||
channelMemberCount, appErr := th.App.GetChannelMemberCount(channel.Id)
|
||||
channelMemberCount, appErr := th.App.GetChannelMemberCount(th.Context, channel.Id)
|
||||
require.Nil(t, appErr, "Failed to get channel member count")
|
||||
|
||||
// Test with an invalid team & channel membership in dry-run mode.
|
||||
@@ -918,7 +918,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
appErr = th.App.importUser(&data, true)
|
||||
appErr = th.App.importUser(th.Context, &data, true)
|
||||
assert.NotNil(t, appErr)
|
||||
|
||||
// Test with an unknown team name & invalid channel membership in dry-run mode.
|
||||
@@ -932,7 +932,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
appErr = th.App.importUser(&data, true)
|
||||
appErr = th.App.importUser(th.Context, &data, true)
|
||||
assert.NotNil(t, appErr)
|
||||
|
||||
// Test with a valid team & invalid channel membership in dry-run mode.
|
||||
@@ -946,7 +946,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
appErr = th.App.importUser(&data, true)
|
||||
appErr = th.App.importUser(th.Context, &data, true)
|
||||
assert.NotNil(t, appErr)
|
||||
|
||||
// Test with a valid team & unknown channel name in dry-run mode.
|
||||
@@ -960,7 +960,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
appErr = th.App.importUser(&data, true)
|
||||
appErr = th.App.importUser(th.Context, &data, true)
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
// Test with a valid team & valid channel name in dry-run mode.
|
||||
@@ -974,7 +974,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
appErr = th.App.importUser(&data, true)
|
||||
appErr = th.App.importUser(th.Context, &data, true)
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
// Check no new member objects were created because dry run mode.
|
||||
@@ -982,7 +982,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
require.Nil(t, appErr, "Failed to get Team Member Count")
|
||||
require.Len(t, tmc, teamMemberCount, "Number of team members not as expected")
|
||||
|
||||
cmc, appErr := th.App.GetChannelMemberCount(channel.Id)
|
||||
cmc, appErr := th.App.GetChannelMemberCount(th.Context, channel.Id)
|
||||
require.Nil(t, appErr, "Failed to get Channel Member Count")
|
||||
require.Equal(t, channelMemberCount, cmc, "Number of channel members not as expected")
|
||||
|
||||
@@ -997,7 +997,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
appErr = th.App.importUser(&data, false)
|
||||
appErr = th.App.importUser(th.Context, &data, false)
|
||||
assert.NotNil(t, appErr)
|
||||
|
||||
// Test with an unknown team name & invalid channel membership in apply mode.
|
||||
@@ -1011,7 +1011,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
appErr = th.App.importUser(&data, false)
|
||||
appErr = th.App.importUser(th.Context, &data, false)
|
||||
assert.NotNil(t, appErr)
|
||||
|
||||
// Test with a valid team & invalid channel membership in apply mode.
|
||||
@@ -1025,7 +1025,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
appErr = th.App.importUser(&data, false)
|
||||
appErr = th.App.importUser(th.Context, &data, false)
|
||||
assert.NotNil(t, appErr)
|
||||
|
||||
// Check no new member objects were created because all tests should have failed so far.
|
||||
@@ -1033,7 +1033,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
require.Nil(t, appErr, "Failed to get Team Member Count")
|
||||
require.Len(t, tmc, teamMemberCount)
|
||||
|
||||
cmc, appErr = th.App.GetChannelMemberCount(channel.Id)
|
||||
cmc, appErr = th.App.GetChannelMemberCount(th.Context, channel.Id)
|
||||
require.Nil(t, appErr, "Failed to get Channel Member Count")
|
||||
require.Equal(t, channelMemberCount, cmc)
|
||||
|
||||
@@ -1048,7 +1048,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
appErr = th.App.importUser(&data, false)
|
||||
appErr = th.App.importUser(th.Context, &data, false)
|
||||
assert.NotNil(t, appErr)
|
||||
|
||||
// Check only new team member object created because dry run mode.
|
||||
@@ -1056,7 +1056,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
require.Nil(t, appErr, "Failed to get Team Member Count")
|
||||
require.Len(t, tmc, teamMemberCount+1)
|
||||
|
||||
cmc, appErr = th.App.GetChannelMemberCount(channel.Id)
|
||||
cmc, appErr = th.App.GetChannelMemberCount(th.Context, channel.Id)
|
||||
require.Nil(t, appErr, "Failed to get Channel Member Count")
|
||||
require.Equal(t, channelMemberCount, cmc)
|
||||
|
||||
@@ -1079,7 +1079,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
appErr = th.App.importUser(&data, false)
|
||||
appErr = th.App.importUser(th.Context, &data, false)
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
// Check only new channel member object created because dry run mode.
|
||||
@@ -1087,12 +1087,12 @@ func TestImportImportUser(t *testing.T) {
|
||||
require.Nil(t, appErr, "Failed to get Team Member Count")
|
||||
require.Len(t, tmc, teamMemberCount+1, "Number of team members not as expected")
|
||||
|
||||
cmc, appErr = th.App.GetChannelMemberCount(channel.Id)
|
||||
cmc, appErr = th.App.GetChannelMemberCount(th.Context, channel.Id)
|
||||
require.Nil(t, appErr, "Failed to get Channel Member Count")
|
||||
require.Equal(t, channelMemberCount+1, cmc, "Number of channel members not as expected")
|
||||
|
||||
// Check channel member properties.
|
||||
channelMember, appErr := th.App.GetChannelMember(context.Background(), channel.Id, user.Id)
|
||||
channelMember, appErr := th.App.GetChannelMember(th.Context, channel.Id, user.Id)
|
||||
require.Nil(t, appErr, "Failed to get channel member from database.")
|
||||
assert.Equal(t, "channel_user", channelMember.Roles)
|
||||
assert.Equal(t, "default", channelMember.NotifyProps[model.DesktopNotifyProp])
|
||||
@@ -1119,7 +1119,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
appErr = th.App.importUser(&data, false)
|
||||
appErr = th.App.importUser(th.Context, &data, false)
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
// Check both member properties.
|
||||
@@ -1127,7 +1127,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
require.Nil(t, appErr, "Failed to get team member from database.")
|
||||
require.Equal(t, "team_user team_admin", teamMember.Roles)
|
||||
|
||||
channelMember, appErr = th.App.GetChannelMember(context.Background(), channel.Id, user.Id)
|
||||
channelMember, appErr = th.App.GetChannelMember(th.Context, channel.Id, user.Id)
|
||||
require.Nil(t, appErr, "Failed to get channel member Desktop from database.")
|
||||
assert.Equal(t, "channel_user channel_admin", channelMember.Roles)
|
||||
assert.Equal(t, model.UserNotifyMention, channelMember.NotifyProps[model.DesktopNotifyProp])
|
||||
@@ -1142,7 +1142,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
require.Nil(t, appErr, "Failed to get Team Member Count")
|
||||
require.Len(t, tmc, teamMemberCount+1, "Number of team members not as expected")
|
||||
|
||||
cmc, appErr = th.App.GetChannelMemberCount(channel.Id)
|
||||
cmc, appErr = th.App.GetChannelMemberCount(th.Context, channel.Id)
|
||||
require.Nil(t, appErr, "Failed to get Channel Member Count")
|
||||
require.Equal(t, channelMemberCount+1, cmc, "Number of channel members not as expected")
|
||||
|
||||
@@ -1163,7 +1163,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
ShowUnreadSection: ptrStr("true"),
|
||||
EmailInterval: ptrStr("immediately"),
|
||||
}
|
||||
appErr = th.App.importUser(&data, false)
|
||||
appErr = th.App.importUser(th.Context, &data, false)
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
// Check their values.
|
||||
@@ -1195,7 +1195,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
TutorialStep: ptrStr("2"),
|
||||
EmailInterval: ptrStr("hour"),
|
||||
}
|
||||
appErr = th.App.importUser(&data, false)
|
||||
appErr = th.App.importUser(th.Context, &data, false)
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
// Check their values again.
|
||||
@@ -1218,7 +1218,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
ChannelTrigger: ptrStr("true"),
|
||||
CommentsTrigger: ptrStr(model.CommentsNotifyRoot),
|
||||
}
|
||||
appErr = th.App.importUser(&data, false)
|
||||
appErr = th.App.importUser(th.Context, &data, false)
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
user, appErr = th.App.GetUserByUsername(username)
|
||||
@@ -1244,7 +1244,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
CommentsTrigger: ptrStr(model.CommentsNotifyRoot),
|
||||
MentionKeys: ptrStr("valid,misc"),
|
||||
}
|
||||
appErr = th.App.importUser(&data, false)
|
||||
appErr = th.App.importUser(th.Context, &data, false)
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
user, appErr = th.App.GetUserByUsername(username)
|
||||
@@ -1270,7 +1270,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
CommentsTrigger: ptrStr(model.CommentsNotifyAny),
|
||||
MentionKeys: ptrStr("misc"),
|
||||
}
|
||||
appErr = th.App.importUser(&data, false)
|
||||
appErr = th.App.importUser(th.Context, &data, false)
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
user, appErr = th.App.GetUserByUsername(username)
|
||||
@@ -1295,7 +1295,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
ChannelTrigger: ptrStr("false"),
|
||||
CommentsTrigger: ptrStr(model.CommentsNotifyAny),
|
||||
}
|
||||
appErr = th.App.importUser(&data, false)
|
||||
appErr = th.App.importUser(th.Context, &data, false)
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
user, appErr = th.App.GetUserByUsername(username)
|
||||
@@ -1327,7 +1327,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
MentionKeys: ptrStr("misc"),
|
||||
}
|
||||
|
||||
appErr = th.App.importUser(&data, false)
|
||||
appErr = th.App.importUser(th.Context, &data, false)
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
user, appErr = th.App.GetUserByUsername(username)
|
||||
@@ -1413,7 +1413,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
}
|
||||
appErr = th.App.importChannel(th.Context, channelData, false)
|
||||
assert.Nil(t, appErr)
|
||||
channel, appErr = th.App.GetChannelByName(*channelData.Name, team.Id, false)
|
||||
channel, appErr = th.App.GetChannelByName(th.Context, *channelData.Name, team.Id, false)
|
||||
require.Nil(t, appErr, "Failed to get channel from database")
|
||||
|
||||
// Test with a valid team & valid channel name in apply mode.
|
||||
@@ -1433,7 +1433,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
appErr = th.App.importUser(userData, false)
|
||||
appErr = th.App.importUser(th.Context, userData, false)
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
user, appErr = th.App.GetUserByUsername(*userData.Username)
|
||||
@@ -1447,7 +1447,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
assert.False(t, teamMember.SchemeGuest)
|
||||
assert.Equal(t, "", teamMember.ExplicitRoles)
|
||||
|
||||
channelMember, appErr = th.App.GetChannelMember(context.Background(), channel.Id, user.Id)
|
||||
channelMember, appErr = th.App.GetChannelMember(th.Context, channel.Id, user.Id)
|
||||
require.Nil(t, appErr, "Failed to get the channel member")
|
||||
|
||||
assert.True(t, channelMember.SchemeAdmin)
|
||||
@@ -1475,7 +1475,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
appErr = th.App.importUser(deletedUserData, false)
|
||||
appErr = th.App.importUser(th.Context, deletedUserData, false)
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
user, appErr = th.App.GetUserByUsername(*deletedUserData.Username)
|
||||
@@ -1489,7 +1489,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
assert.False(t, teamMember.SchemeGuest)
|
||||
assert.Equal(t, "", teamMember.ExplicitRoles)
|
||||
|
||||
channelMember, appErr = th.App.GetChannelMember(context.Background(), channel.Id, user.Id)
|
||||
channelMember, appErr = th.App.GetChannelMember(th.Context, channel.Id, user.Id)
|
||||
require.Nil(t, appErr, "Failed to get the channel member")
|
||||
|
||||
assert.False(t, teamMember.SchemeAdmin)
|
||||
@@ -1517,7 +1517,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
appErr = th.App.importUser(deletedGuestData, false)
|
||||
appErr = th.App.importUser(th.Context, deletedGuestData, false)
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
user, appErr = th.App.GetUserByUsername(*deletedGuestData.Username)
|
||||
@@ -1531,7 +1531,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
assert.True(t, teamMember.SchemeGuest)
|
||||
assert.Equal(t, "", teamMember.ExplicitRoles)
|
||||
|
||||
channelMember, appErr = th.App.GetChannelMember(context.Background(), channel.Id, user.Id)
|
||||
channelMember, appErr = th.App.GetChannelMember(th.Context, channel.Id, user.Id)
|
||||
require.Nil(t, appErr, "Failed to get the channel member")
|
||||
|
||||
assert.False(t, teamMember.SchemeAdmin)
|
||||
@@ -1544,8 +1544,8 @@ func TestImportUserTeams(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
team2 := th.CreateTeam()
|
||||
channel2 := th.CreateChannel(th.BasicTeam)
|
||||
channel3 := th.CreateChannel(team2)
|
||||
channel2 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
channel3 := th.CreateChannel(th.Context, team2)
|
||||
customRole := th.CreateRole("test_custom_role")
|
||||
sampleTheme := "{\"test\":\"#abcdef\"}"
|
||||
|
||||
@@ -1718,7 +1718,7 @@ func TestImportUserTeams(t *testing.T) {
|
||||
|
||||
// Two times import must end with the same results
|
||||
for x := 0; x < 2; x++ {
|
||||
err := th.App.importUserTeams(user, tc.data)
|
||||
err := th.App.importUserTeams(th.Context, user, tc.data)
|
||||
if tc.expectedError {
|
||||
require.NotNil(t, err)
|
||||
} else {
|
||||
@@ -1757,7 +1757,7 @@ func TestImportUserTeams(t *testing.T) {
|
||||
}
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.MaxUsersPerTeam = 1 })
|
||||
defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.MaxUsersPerTeam = 100 })
|
||||
err := th.App.importUserTeams(user, data)
|
||||
err := th.App.importUserTeams(th.Context, user, data)
|
||||
require.NotNil(t, err)
|
||||
})
|
||||
}
|
||||
@@ -1765,7 +1765,7 @@ func TestImportUserTeams(t *testing.T) {
|
||||
func TestImportUserChannels(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
channel2 := th.CreateChannel(th.BasicTeam)
|
||||
channel2 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
customRole := th.CreateRole("test_custom_role")
|
||||
sampleNotifyProps := UserChannelNotifyPropsImportData{
|
||||
Desktop: model.NewString("all"),
|
||||
@@ -1872,7 +1872,7 @@ func TestImportUserChannels(t *testing.T) {
|
||||
|
||||
// Two times import must end with the same results
|
||||
for x := 0; x < 2; x++ {
|
||||
appErr := th.App.importUserChannels(user, th.BasicTeam, tc.data)
|
||||
appErr := th.App.importUserChannels(th.Context, user, th.BasicTeam, tc.data)
|
||||
if tc.expectedError {
|
||||
require.NotNil(t, appErr)
|
||||
} else {
|
||||
@@ -1910,7 +1910,7 @@ func TestImportUserDefaultNotifyProps(t *testing.T) {
|
||||
MentionKeys: ptrStr(""),
|
||||
},
|
||||
}
|
||||
require.Nil(t, th.App.importUser(&data, false))
|
||||
require.Nil(t, th.App.importUser(th.Context, &data, false))
|
||||
|
||||
user, err := th.App.GetUserByUsername(username)
|
||||
require.Nil(t, err)
|
||||
@@ -1958,12 +1958,12 @@ func TestImportimportMultiplePostLines(t *testing.T) {
|
||||
DisplayName: ptrStr("Display Name"),
|
||||
Type: &chanTypeOpen,
|
||||
}, false)
|
||||
channel, err := th.App.GetChannelByName(channelName, team.Id, false)
|
||||
channel, err := th.App.GetChannelByName(th.Context, channelName, team.Id, false)
|
||||
require.Nil(t, err, "Failed to get channel from database.")
|
||||
|
||||
// Create a user.
|
||||
username := model.NewId()
|
||||
th.App.importUser(&UserImportData{
|
||||
th.App.importUser(th.Context, &UserImportData{
|
||||
Username: &username,
|
||||
Email: ptrStr(model.NewId() + "@example.com"),
|
||||
}, false)
|
||||
@@ -2211,7 +2211,7 @@ func TestImportimportMultiplePostLines(t *testing.T) {
|
||||
|
||||
// Post with flags.
|
||||
username2 := model.NewId()
|
||||
th.App.importUser(&UserImportData{
|
||||
th.App.importUser(th.Context, &UserImportData{
|
||||
Username: &username2,
|
||||
Email: ptrStr(model.NewId() + "@example.com"),
|
||||
}, false)
|
||||
@@ -2473,7 +2473,7 @@ func TestImportimportMultiplePostLines(t *testing.T) {
|
||||
DisplayName: ptrStr("Display Name"),
|
||||
Type: &chanTypeOpen,
|
||||
}, false)
|
||||
_, err = th.App.GetChannelByName(channelName, team2.Id, false)
|
||||
_, err = th.App.GetChannelByName(th.Context, channelName, team2.Id, false)
|
||||
require.Nil(t, err, "Failed to get channel from database.")
|
||||
|
||||
// Count the number of posts in the team2.
|
||||
@@ -2562,12 +2562,12 @@ func TestImportImportPost(t *testing.T) {
|
||||
DisplayName: ptrStr("Display Name"),
|
||||
Type: &chanTypeOpen,
|
||||
}, false)
|
||||
channel, appErr := th.App.GetChannelByName(channelName, team.Id, false)
|
||||
channel, appErr := th.App.GetChannelByName(th.Context, channelName, team.Id, false)
|
||||
require.Nil(t, appErr, "Failed to get channel from database.")
|
||||
|
||||
// Create a user.
|
||||
username := model.NewId()
|
||||
th.App.importUser(&UserImportData{
|
||||
th.App.importUser(th.Context, &UserImportData{
|
||||
Username: &username,
|
||||
Email: ptrStr(model.NewId() + "@example.com"),
|
||||
}, false)
|
||||
@@ -2575,7 +2575,7 @@ func TestImportImportPost(t *testing.T) {
|
||||
require.Nil(t, appErr, "Failed to get user from database.")
|
||||
|
||||
username2 := model.NewId()
|
||||
th.App.importUser(&UserImportData{
|
||||
th.App.importUser(th.Context, &UserImportData{
|
||||
Username: &username2,
|
||||
Email: ptrStr(model.NewId() + "@example.com"),
|
||||
}, false)
|
||||
@@ -3159,7 +3159,7 @@ func TestImportImportDirectChannel(t *testing.T) {
|
||||
},
|
||||
Header: ptrStr("Channel Header"),
|
||||
}
|
||||
err = th.App.importDirectChannel(&data, true)
|
||||
err = th.App.importDirectChannel(th.Context, &data, true)
|
||||
require.Error(t, err)
|
||||
|
||||
// Check that no more channels are in the DB.
|
||||
@@ -3171,7 +3171,7 @@ func TestImportImportDirectChannel(t *testing.T) {
|
||||
model.NewId(),
|
||||
model.NewId(),
|
||||
}
|
||||
appErr := th.App.importDirectChannel(&data, true)
|
||||
appErr := th.App.importDirectChannel(th.Context, &data, true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// Check that no more channels are in the DB.
|
||||
@@ -3184,7 +3184,7 @@ func TestImportImportDirectChannel(t *testing.T) {
|
||||
model.NewId(),
|
||||
model.NewId(),
|
||||
}
|
||||
appErr = th.App.importDirectChannel(&data, true)
|
||||
appErr = th.App.importDirectChannel(th.Context, &data, true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// Check that no more channels are in the DB.
|
||||
@@ -3195,7 +3195,7 @@ func TestImportImportDirectChannel(t *testing.T) {
|
||||
data.Members = &[]string{
|
||||
model.NewId(),
|
||||
}
|
||||
err = th.App.importDirectChannel(&data, false)
|
||||
err = th.App.importDirectChannel(th.Context, &data, false)
|
||||
require.Error(t, err)
|
||||
|
||||
// Check that no more channels are in the DB.
|
||||
@@ -3207,7 +3207,7 @@ func TestImportImportDirectChannel(t *testing.T) {
|
||||
th.BasicUser.Username,
|
||||
th.BasicUser2.Username,
|
||||
}
|
||||
appErr = th.App.importDirectChannel(&data, false)
|
||||
appErr = th.App.importDirectChannel(th.Context, &data, false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// Check that one more DIRECT channel is in the DB.
|
||||
@@ -3215,7 +3215,7 @@ func TestImportImportDirectChannel(t *testing.T) {
|
||||
AssertChannelCount(t, th.App, model.ChannelTypeGroup, groupChannelCount)
|
||||
|
||||
// Do the same DIRECT channel again.
|
||||
appErr = th.App.importDirectChannel(&data, false)
|
||||
appErr = th.App.importDirectChannel(th.Context, &data, false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// Check that no more channels are in the DB.
|
||||
@@ -3224,7 +3224,7 @@ func TestImportImportDirectChannel(t *testing.T) {
|
||||
|
||||
// Update the channel's HEADER
|
||||
data.Header = ptrStr("New Channel Header 2")
|
||||
appErr = th.App.importDirectChannel(&data, false)
|
||||
appErr = th.App.importDirectChannel(th.Context, &data, false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// Check that no more channels are in the DB.
|
||||
@@ -3244,7 +3244,7 @@ func TestImportImportDirectChannel(t *testing.T) {
|
||||
user3.Username,
|
||||
model.NewId(),
|
||||
}
|
||||
appErr = th.App.importDirectChannel(&data, false)
|
||||
appErr = th.App.importDirectChannel(th.Context, &data, false)
|
||||
require.NotNil(t, appErr)
|
||||
|
||||
// Check that no more channels are in the DB.
|
||||
@@ -3257,7 +3257,7 @@ func TestImportImportDirectChannel(t *testing.T) {
|
||||
th.BasicUser2.Username,
|
||||
user3.Username,
|
||||
}
|
||||
appErr = th.App.importDirectChannel(&data, false)
|
||||
appErr = th.App.importDirectChannel(th.Context, &data, false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// Check that one more GROUP channel is in the DB.
|
||||
@@ -3265,7 +3265,7 @@ func TestImportImportDirectChannel(t *testing.T) {
|
||||
AssertChannelCount(t, th.App, model.ChannelTypeGroup, groupChannelCount+1)
|
||||
|
||||
// Do the same DIRECT channel again.
|
||||
appErr = th.App.importDirectChannel(&data, false)
|
||||
appErr = th.App.importDirectChannel(th.Context, &data, false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// Check that no more channels are in the DB.
|
||||
@@ -3274,7 +3274,7 @@ func TestImportImportDirectChannel(t *testing.T) {
|
||||
|
||||
// Update the channel's HEADER
|
||||
data.Header = ptrStr("New Channel Header 3")
|
||||
appErr = th.App.importDirectChannel(&data, false)
|
||||
appErr = th.App.importDirectChannel(th.Context, &data, false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// Check that no more channels are in the DB.
|
||||
@@ -3287,7 +3287,7 @@ func TestImportImportDirectChannel(t *testing.T) {
|
||||
th.BasicUser2.Id,
|
||||
user3.Id,
|
||||
}
|
||||
channel, appErr = th.App.createGroupChannel(userIDs)
|
||||
channel, appErr = th.App.createGroupChannel(th.Context, userIDs)
|
||||
require.Equal(t, appErr.Id, store.ChannelExistsError)
|
||||
require.Equal(t, channel.Header, *data.Header)
|
||||
|
||||
@@ -3300,7 +3300,7 @@ func TestImportImportDirectChannel(t *testing.T) {
|
||||
th.BasicUser.Username,
|
||||
th.BasicUser2.Username,
|
||||
}
|
||||
appErr = th.App.importDirectChannel(&data, false)
|
||||
appErr = th.App.importDirectChannel(th.Context, &data, false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
channel, appErr = th.App.GetOrCreateDirectChannel(th.Context, th.BasicUser.Id, th.BasicUser2.Id)
|
||||
@@ -3320,7 +3320,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
th.BasicUser2.Username,
|
||||
},
|
||||
}
|
||||
appErr := th.App.importDirectChannel(&channelData, false)
|
||||
appErr := th.App.importDirectChannel(th.Context, &channelData, false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// Get the channel.
|
||||
@@ -3677,7 +3677,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
user3.Username,
|
||||
},
|
||||
}
|
||||
appErr = th.App.importDirectChannel(&channelData, false)
|
||||
appErr = th.App.importDirectChannel(th.Context, &channelData, false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// Get the channel.
|
||||
@@ -3687,7 +3687,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
th.BasicUser2.Id,
|
||||
user3.Id,
|
||||
}
|
||||
channel, appErr = th.App.createGroupChannel(userIDs)
|
||||
channel, appErr = th.App.createGroupChannel(th.Context, userIDs)
|
||||
require.Equal(t, appErr.Id, store.ChannelExistsError)
|
||||
groupChannel = channel
|
||||
|
||||
@@ -4237,12 +4237,12 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) {
|
||||
DisplayName: ptrStr("Display Name"),
|
||||
Type: &chanTypeOpen,
|
||||
}, false)
|
||||
_, appErr = th.App.GetChannelByName(channelName, team.Id, false)
|
||||
_, appErr = th.App.GetChannelByName(th.Context, channelName, team.Id, false)
|
||||
require.Nil(t, appErr, "Failed to get channel from database.")
|
||||
|
||||
// Create a user3.
|
||||
username := model.NewId()
|
||||
th.App.importUser(&UserImportData{
|
||||
th.App.importUser(th.Context, &UserImportData{
|
||||
Username: &username,
|
||||
Email: ptrStr(model.NewId() + "@example.com"),
|
||||
}, false)
|
||||
@@ -4251,7 +4251,7 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) {
|
||||
require.NotNil(t, user3)
|
||||
|
||||
username2 := model.NewId()
|
||||
th.App.importUser(&UserImportData{
|
||||
th.App.importUser(th.Context, &UserImportData{
|
||||
Username: &username2,
|
||||
Email: ptrStr(model.NewId() + "@example.com"),
|
||||
}, false)
|
||||
@@ -4260,7 +4260,7 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) {
|
||||
|
||||
// Create direct post users.
|
||||
username3 := model.NewId()
|
||||
th.App.importUser(&UserImportData{
|
||||
th.App.importUser(th.Context, &UserImportData{
|
||||
Username: &username3,
|
||||
Email: ptrStr(model.NewId() + "@example.com"),
|
||||
}, false)
|
||||
@@ -4268,7 +4268,7 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) {
|
||||
require.Nil(t, appErr, "Failed to get user3 from database.")
|
||||
|
||||
username4 := model.NewId()
|
||||
th.App.importUser(&UserImportData{
|
||||
th.App.importUser(th.Context, &UserImportData{
|
||||
Username: &username4,
|
||||
Email: ptrStr(model.NewId() + "@example.com"),
|
||||
}, false)
|
||||
@@ -4387,7 +4387,7 @@ func TestImportDirectPostWithAttachments(t *testing.T) {
|
||||
|
||||
// Create a user.
|
||||
username := model.NewId()
|
||||
th.App.importUser(&UserImportData{
|
||||
th.App.importUser(th.Context, &UserImportData{
|
||||
Username: &username,
|
||||
Email: ptrStr(model.NewId() + "@example.com"),
|
||||
}, false)
|
||||
@@ -4395,7 +4395,7 @@ func TestImportDirectPostWithAttachments(t *testing.T) {
|
||||
require.Nil(t, appErr, "Failed to get user1 from database.")
|
||||
|
||||
username2 := model.NewId()
|
||||
th.App.importUser(&UserImportData{
|
||||
th.App.importUser(th.Context, &UserImportData{
|
||||
Username: &username2,
|
||||
Email: ptrStr(model.NewId() + "@example.com"),
|
||||
}, false)
|
||||
@@ -4513,12 +4513,12 @@ func TestZippedImportPostAndRepliesWithAttachments(t *testing.T) {
|
||||
DisplayName: ptrStr("Display Name"),
|
||||
Type: &chanTypeOpen,
|
||||
}, false)
|
||||
_, appErr = th.App.GetChannelByName(channelName, team.Id, false)
|
||||
_, appErr = th.App.GetChannelByName(th.Context, channelName, team.Id, false)
|
||||
require.Nil(t, appErr, "Failed to get channel from database.")
|
||||
|
||||
// Create users
|
||||
username2 := model.NewId()
|
||||
th.App.importUser(&UserImportData{
|
||||
th.App.importUser(th.Context, &UserImportData{
|
||||
Username: &username2,
|
||||
Email: ptrStr(model.NewId() + "@example.com"),
|
||||
}, false)
|
||||
@@ -4527,7 +4527,7 @@ func TestZippedImportPostAndRepliesWithAttachments(t *testing.T) {
|
||||
|
||||
// Create direct post users.
|
||||
username3 := model.NewId()
|
||||
th.App.importUser(&UserImportData{
|
||||
th.App.importUser(th.Context, &UserImportData{
|
||||
Username: &username3,
|
||||
Email: ptrStr(model.NewId() + "@example.com"),
|
||||
}, false)
|
||||
@@ -4535,7 +4535,7 @@ func TestZippedImportPostAndRepliesWithAttachments(t *testing.T) {
|
||||
require.Nil(t, appErr, "Failed to get user3 from database.")
|
||||
|
||||
username4 := model.NewId()
|
||||
th.App.importUser(&UserImportData{
|
||||
th.App.importUser(th.Context, &UserImportData{
|
||||
Username: &username4,
|
||||
Email: ptrStr(model.NewId() + "@example.com"),
|
||||
}, false)
|
||||
|
||||
@@ -301,7 +301,7 @@ func (a *App) DoPostActionWithCookie(c *request.Context, postID, actionId, userI
|
||||
for key, value := range retain {
|
||||
ephemeralPost.AddProp(key, value)
|
||||
}
|
||||
a.SendEphemeralPost(userID, ephemeralPost)
|
||||
a.SendEphemeralPost(c, userID, ephemeralPost)
|
||||
}
|
||||
|
||||
return clientTriggerId, nil
|
||||
|
||||
@@ -140,7 +140,7 @@ func TestPostAction(t *testing.T) {
|
||||
user1 := th.CreateUser()
|
||||
user2 := th.CreateUser()
|
||||
|
||||
return th.CreateGroupChannel(user1, user2)
|
||||
return th.CreateGroupChannel(th.Context, user1, user2)
|
||||
}},
|
||||
}
|
||||
|
||||
|
||||
+27
-23
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app/request"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/i18n"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/markdown"
|
||||
@@ -36,7 +37,7 @@ func (a *App) canSendPushNotifications() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *model.Channel, sender *model.User, parentPostList *model.PostList, setOnline bool) ([]string, error) {
|
||||
func (a *App) SendNotifications(c request.CTX, post *model.Post, team *model.Team, channel *model.Channel, sender *model.User, parentPostList *model.PostList, setOnline bool) ([]string, error) {
|
||||
// Do not send notifications in archived channels
|
||||
if channel.DeleteAt > 0 {
|
||||
return []string{}, nil
|
||||
@@ -59,7 +60,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
}()
|
||||
|
||||
var gchan chan store.StoreResult
|
||||
if a.allowGroupMentions(post) {
|
||||
if a.allowGroupMentions(c, post) {
|
||||
gchan = make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
groupsMap, err := a.getGroupsAllowedForReferenceInChannel(channel, team)
|
||||
@@ -134,7 +135,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
mentions.addMention(post.UserId, DMMention)
|
||||
}
|
||||
} else {
|
||||
allowChannelMentions = a.allowChannelMentions(post, len(profileMap))
|
||||
allowChannelMentions = a.allowChannelMentions(c, post, len(profileMap))
|
||||
keywords = a.getMentionKeywordsInChannel(profileMap, allowChannelMentions, channelMemberNotifyPropsMap)
|
||||
|
||||
mentions = getExplicitMentions(post, keywords, groups)
|
||||
@@ -155,7 +156,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
}
|
||||
|
||||
if !anyUsersMentionedByGroup {
|
||||
a.sendNoUsersNotifiedByGroupInChannel(sender, post, channel, group)
|
||||
a.sendNoUsersNotifiedByGroupInChannel(c, sender, post, channel, group)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +171,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
if threadPost.Id == parentPostList.Order[0] && threadPost.IsFromOAuthBot() {
|
||||
continue
|
||||
}
|
||||
if a.IsCRTEnabledForUser(profile.Id) {
|
||||
if a.IsCRTEnabledForUser(c, profile.Id) {
|
||||
continue
|
||||
}
|
||||
if profile.NotifyProps[model.CommentsNotifyProp] == model.CommentsNotifyAny || (profile.NotifyProps[model.CommentsNotifyProp] == model.CommentsNotifyRoot && threadPost.Id == parentPostList.Order[0]) {
|
||||
@@ -190,7 +191,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
}
|
||||
|
||||
go func() {
|
||||
_, err := a.sendOutOfChannelMentions(sender, post, channel, mentions.OtherPotentialMentions)
|
||||
_, err := a.sendOutOfChannelMentions(c, sender, post, channel, mentions.OtherPotentialMentions)
|
||||
if err != nil {
|
||||
mlog.Error("Failed to send warning for out of channel mentions", mlog.String("user_id", sender.Id), mlog.String("post_id", post.Id), mlog.Err(err))
|
||||
}
|
||||
@@ -203,7 +204,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
channelMemberNotifyPropsMap[profile.Id][model.PushNotifyProp] == model.ChannelNotifyAll) &&
|
||||
(post.UserId != profile.Id || post.GetProp("from_webhook") == "true") &&
|
||||
!post.IsSystemMessage() &&
|
||||
!(a.IsCRTEnabledForUser(profile.Id) && post.RootId != "") {
|
||||
!(a.IsCRTEnabledForUser(c, profile.Id) && post.RootId != "") {
|
||||
allActivityPushUserIds = append(allActivityPushUserIds, profile.Id)
|
||||
}
|
||||
}
|
||||
@@ -330,7 +331,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
if isCRTAllowed && post.RootId != "" {
|
||||
for _, uid := range followers {
|
||||
profile := profileMap[uid]
|
||||
if profile == nil || !a.IsCRTEnabledForUser(uid) {
|
||||
if profile == nil || !a.IsCRTEnabledForUser(c, uid) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -365,12 +366,12 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
continue
|
||||
}
|
||||
|
||||
if a.userAllowsEmail(profileMap[id], channelMemberNotifyPropsMap[id], post) {
|
||||
if a.userAllowsEmail(c, profileMap[id], channelMemberNotifyPropsMap[id], post) {
|
||||
senderProfileImage, _, err := a.GetProfileImage(sender)
|
||||
if err != nil {
|
||||
a.Log().Warn("Unable to get the sender user profile image.", mlog.String("user_id", sender.Id), mlog.Err(err))
|
||||
}
|
||||
if err := a.sendNotificationEmail(notification, profileMap[id], team, senderProfileImage); err != nil {
|
||||
if err := a.sendNotificationEmail(c, notification, profileMap[id], team, senderProfileImage); err != nil {
|
||||
mlog.Warn("Unable to send notification email.", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
@@ -383,6 +384,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
|
||||
if mentions.HereMentioned {
|
||||
a.SendEphemeralPost(
|
||||
c,
|
||||
post.UserId,
|
||||
&model.Post{
|
||||
ChannelId: post.ChannelId,
|
||||
@@ -394,6 +396,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
|
||||
if mentions.ChannelMentioned {
|
||||
a.SendEphemeralPost(
|
||||
c,
|
||||
post.UserId,
|
||||
&model.Post{
|
||||
ChannelId: post.ChannelId,
|
||||
@@ -405,6 +408,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
|
||||
if mentions.AllMentioned {
|
||||
a.SendEphemeralPost(
|
||||
c,
|
||||
post.UserId,
|
||||
&model.Post{
|
||||
ChannelId: post.ChannelId,
|
||||
@@ -563,7 +567,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
message.Add("followers", model.ArrayToJSON(notificationsForCRT.Desktop))
|
||||
}
|
||||
|
||||
published, err := a.publishWebsocketEventForPermalinkPost(post, message)
|
||||
published, err := a.publishWebsocketEventForPermalinkPost(c, post, message)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -579,7 +583,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
if profileMap[uid] == nil {
|
||||
continue
|
||||
}
|
||||
if a.IsCRTEnabledForUser(uid) {
|
||||
if a.IsCRTEnabledForUser(c, uid) {
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventThreadUpdated, team.Id, "", uid, nil)
|
||||
threadMembership := participantMemberships[uid]
|
||||
if threadMembership == nil {
|
||||
@@ -626,7 +630,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
a.sanitizeProfiles(userThread.Participants, false)
|
||||
userThread.Post.SanitizeProps()
|
||||
|
||||
sanitizedPost, err := a.SanitizePostMetadataForUser(userThread.Post, uid)
|
||||
sanitizedPost, err := a.SanitizePostMetadataForUser(c, userThread.Post, uid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -655,7 +659,7 @@ func max(a, b int64) int64 {
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *App) userAllowsEmail(user *model.User, channelMemberNotificationProps model.StringMap, post *model.Post) bool {
|
||||
func (a *App) userAllowsEmail(c request.CTX, user *model.User, channelMemberNotificationProps model.StringMap, post *model.Post) bool {
|
||||
// if user is a bot account, then we do not send email
|
||||
if user.IsBot {
|
||||
return false
|
||||
@@ -664,7 +668,7 @@ func (a *App) userAllowsEmail(user *model.User, channelMemberNotificationProps m
|
||||
userAllowsEmails := user.NotifyProps[model.EmailNotifyProp] != "false"
|
||||
|
||||
// if CRT is ON for user and the post is a reply disregard the channelEmail setting
|
||||
if channelEmail, ok := channelMemberNotificationProps[model.EmailNotifyProp]; ok && !(a.IsCRTEnabledForUser(user.Id) && post.RootId != "") {
|
||||
if channelEmail, ok := channelMemberNotificationProps[model.EmailNotifyProp]; ok && !(a.IsCRTEnabledForUser(c, user.Id) && post.RootId != "") {
|
||||
if channelEmail != model.ChannelNotifyDefault {
|
||||
userAllowsEmails = channelEmail != "false"
|
||||
}
|
||||
@@ -696,7 +700,7 @@ func (a *App) userAllowsEmail(user *model.User, channelMemberNotificationProps m
|
||||
return userAllowsEmails && emailNotificationsAllowedForStatus && user.DeleteAt == 0 && !autoResponderRelated
|
||||
}
|
||||
|
||||
func (a *App) sendNoUsersNotifiedByGroupInChannel(sender *model.User, post *model.Post, channel *model.Channel, group *model.Group) {
|
||||
func (a *App) sendNoUsersNotifiedByGroupInChannel(c request.CTX, sender *model.User, post *model.Post, channel *model.Channel, group *model.Group) {
|
||||
T := i18n.GetUserTranslations(sender.Locale)
|
||||
ephemeralPost := &model.Post{
|
||||
UserId: sender.Id,
|
||||
@@ -704,12 +708,12 @@ func (a *App) sendNoUsersNotifiedByGroupInChannel(sender *model.User, post *mode
|
||||
ChannelId: channel.Id,
|
||||
Message: T("api.post.check_for_out_of_channel_group_users.message.none", model.StringInterface{"GroupName": group.Name}),
|
||||
}
|
||||
a.SendEphemeralPost(post.UserId, ephemeralPost)
|
||||
a.SendEphemeralPost(c, post.UserId, ephemeralPost)
|
||||
}
|
||||
|
||||
// sendOutOfChannelMentions sends an ephemeral post to the sender of a post if any of the given potential mentions
|
||||
// are outside of the post's channel. Returns whether or not an ephemeral post was sent.
|
||||
func (a *App) sendOutOfChannelMentions(sender *model.User, post *model.Post, channel *model.Channel, potentialMentions []string) (bool, error) {
|
||||
func (a *App) sendOutOfChannelMentions(c request.CTX, sender *model.User, post *model.Post, channel *model.Channel, potentialMentions []string) (bool, error) {
|
||||
outOfChannelUsers, outOfGroupsUsers, err := a.filterOutOfChannelMentions(sender, post, channel, potentialMentions)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@@ -719,7 +723,7 @@ func (a *App) sendOutOfChannelMentions(sender *model.User, post *model.Post, cha
|
||||
return false, nil
|
||||
}
|
||||
|
||||
a.SendEphemeralPost(post.UserId, makeOutOfChannelMentionPost(sender, post, outOfChannelUsers, outOfGroupsUsers))
|
||||
a.SendEphemeralPost(c, post.UserId, makeOutOfChannelMentionPost(sender, post, outOfChannelUsers, outOfGroupsUsers))
|
||||
|
||||
return true, nil
|
||||
}
|
||||
@@ -1021,8 +1025,8 @@ func getMentionsEnabledFields(post *model.Post) model.StringArray {
|
||||
}
|
||||
|
||||
// allowChannelMentions returns whether or not the channel mentions are allowed for the given post.
|
||||
func (a *App) allowChannelMentions(post *model.Post, numProfiles int) bool {
|
||||
if !a.HasPermissionToChannel(post.UserId, post.ChannelId, model.PermissionUseChannelMentions) {
|
||||
func (a *App) allowChannelMentions(c request.CTX, post *model.Post, numProfiles int) bool {
|
||||
if !a.HasPermissionToChannel(c, post.UserId, post.ChannelId, model.PermissionUseChannelMentions) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1038,12 +1042,12 @@ func (a *App) allowChannelMentions(post *model.Post, numProfiles int) bool {
|
||||
}
|
||||
|
||||
// allowGroupMentions returns whether or not the group mentions are allowed for the given post.
|
||||
func (a *App) allowGroupMentions(post *model.Post) bool {
|
||||
func (a *App) allowGroupMentions(c request.CTX, post *model.Post) bool {
|
||||
if license := a.Srv().License(); license == nil || (license.SkuShortName != model.LicenseShortSkuProfessional && license.SkuShortName != model.LicenseShortSkuEnterprise) {
|
||||
return false
|
||||
}
|
||||
|
||||
if !a.HasPermissionToChannel(post.UserId, post.ChannelId, model.PermissionUseGroupMentions) {
|
||||
if !a.HasPermissionToChannel(c, post.UserId, post.ChannelId, model.PermissionUseGroupMentions) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app/request"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/i18n"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
@@ -19,7 +20,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func (a *App) sendNotificationEmail(notification *PostNotification, user *model.User, team *model.Team, senderProfileImage []byte) error {
|
||||
func (a *App) sendNotificationEmail(c request.CTX, notification *PostNotification, user *model.User, team *model.Team, senderProfileImage []byte) error {
|
||||
channel := notification.Channel
|
||||
post := notification.Post
|
||||
|
||||
@@ -107,7 +108,7 @@ func (a *App) sendNotificationEmail(notification *PostNotification, user *model.
|
||||
|
||||
landingURL := a.GetSiteURL() + "/landing#/" + team.Name
|
||||
|
||||
var bodyText, err = a.getNotificationEmailBody(user, post, channel, channelName, senderName, team.Name, landingURL, emailNotificationContentsType, useMilitaryTime, translateFunc, senderPhoto)
|
||||
var bodyText, err = a.getNotificationEmailBody(c, user, post, channel, channelName, senderName, team.Name, landingURL, emailNotificationContentsType, useMilitaryTime, translateFunc, senderPhoto)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unable to render the email notification template")
|
||||
}
|
||||
@@ -215,7 +216,7 @@ type postData struct {
|
||||
/**
|
||||
* Computes the email body for notification messages
|
||||
*/
|
||||
func (a *App) getNotificationEmailBody(recipient *model.User, post *model.Post, channel *model.Channel, channelName string, senderName string, teamName string, landingURL string, emailNotificationContentsType string, useMilitaryTime bool, translateFunc i18n.TranslateFunc, senderPhoto string) (string, error) {
|
||||
func (a *App) getNotificationEmailBody(c request.CTX, recipient *model.User, post *model.Post, channel *model.Channel, channelName string, senderName string, teamName string, landingURL string, emailNotificationContentsType string, useMilitaryTime bool, translateFunc i18n.TranslateFunc, senderPhoto string) (string, error) {
|
||||
pData := postData{
|
||||
SenderName: truncateUserNames(senderName, 22),
|
||||
SenderPhoto: senderPhoto,
|
||||
@@ -237,7 +238,7 @@ func (a *App) getNotificationEmailBody(recipient *model.User, post *model.Post,
|
||||
mdPostMessage = postMessage
|
||||
}
|
||||
|
||||
normalizedPostMessage, err := a.generateHyperlinkForChannels(mdPostMessage, teamName, landingURL)
|
||||
normalizedPostMessage, err := a.generateHyperlinkForChannels(c, mdPostMessage, teamName, landingURL)
|
||||
if err != nil {
|
||||
mlog.Warn("Encountered error while generating hyperlink for channels", mlog.String("team_name", teamName), mlog.Err(err))
|
||||
normalizedPostMessage = mdPostMessage
|
||||
@@ -276,7 +277,7 @@ func (a *App) getNotificationEmailBody(recipient *model.User, post *model.Post,
|
||||
}
|
||||
|
||||
// Override title and subtile for replies with CRT enabled
|
||||
if a.IsCRTEnabledForUser(recipient.Id) && post.RootId != "" {
|
||||
if a.IsCRTEnabledForUser(c, recipient.Id) && post.RootId != "" {
|
||||
// Title is the same in all cases
|
||||
data.Props["Title"] = translateFunc("app.notification.body.thread.title", map[string]any{"SenderName": senderName})
|
||||
|
||||
@@ -347,7 +348,7 @@ func getFormattedPostTime(user *model.User, post *model.Post, useMilitaryTime bo
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) generateHyperlinkForChannels(postMessage, teamName, teamURL string) (string, *model.AppError) {
|
||||
func (a *App) generateHyperlinkForChannels(c request.CTX, postMessage, teamName, teamURL string) (string, *model.AppError) {
|
||||
team, err := a.GetTeamByName(teamName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -358,7 +359,7 @@ func (a *App) generateHyperlinkForChannels(postMessage, teamName, teamURL string
|
||||
return postMessage, nil
|
||||
}
|
||||
|
||||
channels, err := a.GetChannelsByNames(channelNames, team.Id)
|
||||
channels, err := a.GetChannelsByNames(c, channelNames, team.Id)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ func TestGetNotificationEmailBodyFullNotificationPublicChannel(t *testing.T) {
|
||||
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
|
||||
storeMock.On("Team").Return(&teamStoreMock)
|
||||
|
||||
body, err := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
body, err := th.App.getNotificationEmailBody(th.Context, recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, body, "mentioned you in a message", fmt.Sprintf("Expected email text 'mentioned you in a message. Got %s", body))
|
||||
require.Contains(t, body, post.Message, fmt.Sprintf("Expected email text '%s'. Got %s", post.Message, body))
|
||||
@@ -121,7 +121,7 @@ func TestGetNotificationEmailBodyFullNotificationGroupChannel(t *testing.T) {
|
||||
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
|
||||
storeMock.On("Team").Return(&teamStoreMock)
|
||||
|
||||
body, err := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
body, err := th.App.getNotificationEmailBody(th.Context, recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, body, "sent you a new message", fmt.Sprintf("Expected email text 'sent you a new message. Got "+body))
|
||||
require.Contains(t, body, post.Message, fmt.Sprintf("Expected email text '%s'. Got %s", post.Message, body))
|
||||
@@ -152,7 +152,7 @@ func TestGetNotificationEmailBodyFullNotificationPrivateChannel(t *testing.T) {
|
||||
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
|
||||
storeMock.On("Team").Return(&teamStoreMock)
|
||||
|
||||
body, err := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
body, err := th.App.getNotificationEmailBody(th.Context, recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, body, "mentioned you in a message", fmt.Sprintf("Expected email text 'mentioned you in a message. Got "+body))
|
||||
require.Contains(t, body, post.Message, fmt.Sprintf("Expected email text '%s'. Got %s", post.Message, body))
|
||||
@@ -183,7 +183,7 @@ func TestGetNotificationEmailBodyFullNotificationDirectChannel(t *testing.T) {
|
||||
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
|
||||
storeMock.On("Team").Return(&teamStoreMock)
|
||||
|
||||
body, err := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
body, err := th.App.getNotificationEmailBody(th.Context, recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, body, "sent you a new message", fmt.Sprintf("Expected email text 'sent you a new message. Got "+body))
|
||||
require.Contains(t, body, post.Message, fmt.Sprintf("Expected email text '%s'. Got %s", post.Message, body))
|
||||
@@ -218,7 +218,7 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTimeWithTimezone(t *testi
|
||||
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
|
||||
storeMock.On("Team").Return(&teamStoreMock)
|
||||
|
||||
body, err := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, false, translateFunc, "user-avatar.png")
|
||||
body, err := th.App.getNotificationEmailBody(th.Context, recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, false, translateFunc, "user-avatar.png")
|
||||
require.NoError(t, err)
|
||||
r, _ := regexp.Compile("E([S|D]+)T")
|
||||
zone := r.FindString(body)
|
||||
@@ -267,7 +267,7 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTimeNoTimezone(t *testing
|
||||
err = tmp.Execute(&text, fmt.Sprintf("%s:%s %s", formattedTime.Hour, formattedTime.Minute, formattedTime.TimeZone))
|
||||
require.NoError(t, err)
|
||||
|
||||
body, err := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
body, err := th.App.getNotificationEmailBody(th.Context, recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
require.NoError(t, err)
|
||||
postTimeLine := text.String()
|
||||
require.Contains(t, body, postTimeLine, fmt.Sprintf("Expected email text '%s'. Got %s", postTimeLine, body))
|
||||
@@ -301,7 +301,7 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTime12Hour(t *testing.T)
|
||||
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
|
||||
storeMock.On("Team").Return(&teamStoreMock)
|
||||
|
||||
body, err := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, false, translateFunc, "user-avatar.png")
|
||||
body, err := th.App.getNotificationEmailBody(th.Context, recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, false, translateFunc, "user-avatar.png")
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, body, "2:30 PM", fmt.Sprintf("Expected email text '2:30 PM'. Got %s", body))
|
||||
}
|
||||
@@ -334,7 +334,7 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTime24Hour(t *testing.T)
|
||||
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
|
||||
storeMock.On("Team").Return(&teamStoreMock)
|
||||
|
||||
body, err := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
body, err := th.App.getNotificationEmailBody(th.Context, recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, body, "14:30", fmt.Sprintf("Expected email text '14:30'. Got %s", body))
|
||||
}
|
||||
@@ -364,7 +364,7 @@ func TestGetNotificationEmailBodyGenericNotificationPublicChannel(t *testing.T)
|
||||
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
|
||||
storeMock.On("Team").Return(&teamStoreMock)
|
||||
|
||||
body, err := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
body, err := th.App.getNotificationEmailBody(th.Context, recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, body, "mentioned you in a message", fmt.Sprintf("Expected email text 'mentioned you in a message. Got %s", body))
|
||||
require.Contains(t, body, teamURL, fmt.Sprintf("Expected email text '%s'. Got %s", teamURL, body))
|
||||
@@ -394,7 +394,7 @@ func TestGetNotificationEmailBodyGenericNotificationGroupChannel(t *testing.T) {
|
||||
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
|
||||
storeMock.On("Team").Return(&teamStoreMock)
|
||||
|
||||
body, err := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
body, err := th.App.getNotificationEmailBody(th.Context, recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, body, "sent you a new message", fmt.Sprintf("Expected email text 'sent you a new message. Got "+body))
|
||||
require.Contains(t, body, teamURL, fmt.Sprintf("Expected email text '%s'. Got %s", teamURL, body))
|
||||
@@ -424,7 +424,7 @@ func TestGetNotificationEmailBodyGenericNotificationPrivateChannel(t *testing.T)
|
||||
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
|
||||
storeMock.On("Team").Return(&teamStoreMock)
|
||||
|
||||
body, err := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
body, err := th.App.getNotificationEmailBody(th.Context, recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, body, "mentioned you in a message", fmt.Sprintf("Expected email text 'mentioned you in a message. Got %s", body))
|
||||
require.Contains(t, body, teamURL, fmt.Sprintf("Expected email text '%s'. Got %s", teamURL, body))
|
||||
@@ -454,7 +454,7 @@ func TestGetNotificationEmailBodyGenericNotificationDirectChannel(t *testing.T)
|
||||
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
|
||||
storeMock.On("Team").Return(&teamStoreMock)
|
||||
|
||||
body, err := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
body, err := th.App.getNotificationEmailBody(th.Context, recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, body, "sent you a new message", fmt.Sprintf("Expected email text 'sent you a new message. Got "+body))
|
||||
require.Contains(t, body, teamURL, fmt.Sprintf("Expected email text '%s'. Got %s", teamURL, body))
|
||||
@@ -486,7 +486,7 @@ func TestGetNotificationEmailEscapingChars(t *testing.T) {
|
||||
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
|
||||
storeMock.On("Team").Return(&teamStoreMock)
|
||||
|
||||
body, err := th.App.getNotificationEmailBody(recipient, post, ch,
|
||||
body, err := th.App.getNotificationEmailBody(th.Context, recipient, post, ch,
|
||||
channelName, senderName, teamName, teamURL,
|
||||
emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
require.NoError(t, err)
|
||||
@@ -530,7 +530,7 @@ func TestGetNotificationEmailBodyPublicChannelMention(t *testing.T) {
|
||||
channelStoreMock.On("GetByNames", "test", []string{ch.Name}, true).Return([]*model.Channel{ch}, nil)
|
||||
storeMock.On("Channel").Return(&channelStoreMock)
|
||||
|
||||
body, err := th.App.getNotificationEmailBody(recipient, post, ch,
|
||||
body, err := th.App.getNotificationEmailBody(th.Context, recipient, post, ch,
|
||||
ch.Name, senderName, teamName, teamURL,
|
||||
emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
require.NoError(t, err)
|
||||
@@ -596,7 +596,7 @@ func TestGetNotificationEmailBodyMultiPublicChannelMention(t *testing.T) {
|
||||
channelStoreMock.On("GetByNames", "test", []string{ch.Name, ch2.Name, ch3.Name}, true).Return([]*model.Channel{ch, ch2, ch3}, nil)
|
||||
storeMock.On("Channel").Return(&channelStoreMock)
|
||||
|
||||
body, err := th.App.getNotificationEmailBody(recipient, post, ch,
|
||||
body, err := th.App.getNotificationEmailBody(th.Context, recipient, post, ch,
|
||||
ch.Name, senderName, teamName, teamURL,
|
||||
emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
require.NoError(t, err)
|
||||
@@ -645,7 +645,7 @@ func TestGetNotificationEmailBodyPrivateChannelMention(t *testing.T) {
|
||||
channelStoreMock.On("GetByNames", "test", []string{ch.Name}, true).Return([]*model.Channel{ch}, nil)
|
||||
storeMock.On("Channel").Return(&channelStoreMock)
|
||||
|
||||
body, err := th.App.getNotificationEmailBody(recipient, post, ch,
|
||||
body, err := th.App.getNotificationEmailBody(th.Context, recipient, post, ch,
|
||||
ch.Name, senderName, teamName, teamURL,
|
||||
emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
require.NoError(t, err)
|
||||
@@ -678,7 +678,7 @@ func TestGenerateHyperlinkForChannelsPublic(t *testing.T) {
|
||||
channelStoreMock.On("GetByNames", "test", []string{ch.Name}, true).Return([]*model.Channel{ch}, nil)
|
||||
storeMock.On("Channel").Return(&channelStoreMock)
|
||||
|
||||
outMessage, err := th.App.generateHyperlinkForChannels(message+mention, teamName, teamURL)
|
||||
outMessage, err := th.App.generateHyperlinkForChannels(th.Context, message+mention, teamName, teamURL)
|
||||
require.Nil(t, err)
|
||||
channelURL := teamURL + "/channels/" + ch.Name
|
||||
assert.Equal(t, message+"<a href='"+channelURL+"'>"+mention+"</a>", outMessage)
|
||||
@@ -728,7 +728,7 @@ func TestGenerateHyperlinkForChannelsMultiPublic(t *testing.T) {
|
||||
channelStoreMock.On("GetByNames", "test", []string{ch.Name, ch2.Name, ch3.Name}, true).Return([]*model.Channel{ch, ch2, ch3}, nil)
|
||||
storeMock.On("Channel").Return(&channelStoreMock)
|
||||
|
||||
outMessage, err := th.App.generateHyperlinkForChannels(message, teamName, teamURL)
|
||||
outMessage, err := th.App.generateHyperlinkForChannels(th.Context, message, teamName, teamURL)
|
||||
require.Nil(t, err)
|
||||
channelURL := teamURL + "/channels/" + ch.Name
|
||||
channelURL2 := teamURL + "/channels/" + ch2.Name
|
||||
@@ -762,7 +762,7 @@ func TestGenerateHyperlinkForChannelsPrivate(t *testing.T) {
|
||||
channelStoreMock.On("GetByNames", "test", []string{ch.Name}, true).Return([]*model.Channel{ch}, nil)
|
||||
storeMock.On("Channel").Return(&channelStoreMock)
|
||||
|
||||
outMessage, err := th.App.generateHyperlinkForChannels(message, teamName, teamURL)
|
||||
outMessage, err := th.App.generateHyperlinkForChannels(th.Context, message, teamName, teamURL)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, message, outMessage)
|
||||
}
|
||||
@@ -791,7 +791,7 @@ func TestLandingLink(t *testing.T) {
|
||||
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
|
||||
storeMock.On("Team").Return(&teamStoreMock)
|
||||
|
||||
body, err := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
body, err := th.App.getNotificationEmailBody(th.Context, recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, body, teamURL, fmt.Sprintf("Expected email text '%s'. Got %s", teamURL, body))
|
||||
}
|
||||
@@ -821,7 +821,7 @@ func TestLandingLinkPermalink(t *testing.T) {
|
||||
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
|
||||
storeMock.On("Team").Return(&teamStoreMock)
|
||||
|
||||
body, err := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
body, err := th.App.getNotificationEmailBody(th.Context, recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc, "user-avatar.png")
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, body, teamURL+"/pl/"+post.Id, fmt.Sprintf("Expected email text '%s'. Got %s", teamURL, body))
|
||||
}
|
||||
@@ -928,7 +928,7 @@ func TestMarkdownConversion(t *testing.T) {
|
||||
Id: "Test_id",
|
||||
Message: tt.args,
|
||||
}
|
||||
got, err := th.App.getNotificationEmailBody(recipient, post, channel, "ChannelName", "sender", "testteam", "http://localhost:8065/landing#/testteam", model.EmailNotificationContentsFull, true, i18n.GetUserTranslations("en"), "user-avatar.png")
|
||||
got, err := th.App.getNotificationEmailBody(th.Context, recipient, post, channel, "ChannelName", "sender", "testteam", "http://localhost:8065/landing#/testteam", model.EmailNotificationContentsFull, true, i18n.GetUserTranslations("en"), "user-avatar.png")
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, got, tt.want)
|
||||
})
|
||||
|
||||
+17
-14
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app/request"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/i18n"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
@@ -56,10 +57,11 @@ type PushNotification struct {
|
||||
replyToThreadType string
|
||||
}
|
||||
|
||||
func (a *App) sendPushNotificationSync(post *model.Post, user *model.User, channel *model.Channel, channelName string, senderName string,
|
||||
func (a *App) sendPushNotificationSync(c request.CTX, post *model.Post, user *model.User, channel *model.Channel, channelName string, senderName string,
|
||||
explicitMention bool, channelWideMention bool, replyToThreadType string) *model.AppError {
|
||||
cfg := a.Config()
|
||||
msg, appErr := a.BuildPushNotificationMessage(
|
||||
c,
|
||||
*cfg.EmailSettings.PushNotificationContents,
|
||||
post,
|
||||
user,
|
||||
@@ -218,7 +220,7 @@ func (a *App) getPushNotificationMessage(contentsConfig, postMessage string, exp
|
||||
return senderName + userLocale("api.post.send_notifications_and_forget.push_general_message")
|
||||
}
|
||||
|
||||
func (a *App) clearPushNotificationSync(currentSessionId, userID, channelID, rootID string) *model.AppError {
|
||||
func (a *App) clearPushNotificationSync(c request.CTX, currentSessionId, userID, channelID, rootID string) *model.AppError {
|
||||
msg := &model.PushNotification{
|
||||
Type: model.PushTypeClear,
|
||||
Version: model.PushMessageV2,
|
||||
@@ -226,7 +228,7 @@ func (a *App) clearPushNotificationSync(currentSessionId, userID, channelID, roo
|
||||
RootId: rootID,
|
||||
ContentAvailable: 1,
|
||||
Badge: 0,
|
||||
IsCRTEnabled: a.IsCRTEnabledForUser(userID),
|
||||
IsCRTEnabled: a.IsCRTEnabledForUser(c, userID),
|
||||
}
|
||||
|
||||
unreadCount, err := a.Srv().Store.User().GetUnreadCount(userID)
|
||||
@@ -288,7 +290,7 @@ func (a *App) UpdateMobileAppBadge(userID string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) createPushNotificationsHub() {
|
||||
func (s *Server) createPushNotificationsHub(c request.CTX) {
|
||||
buffer := *s.Config().EmailSettings.PushNotificationBuffer
|
||||
hub := PushNotificationsHub{
|
||||
notificationsChan: make(chan PushNotification, buffer),
|
||||
@@ -299,11 +301,11 @@ func (s *Server) createPushNotificationsHub() {
|
||||
stopChan: make(chan struct{}),
|
||||
buffer: buffer,
|
||||
}
|
||||
go hub.start()
|
||||
go hub.start(c)
|
||||
s.PushNotificationsHub = hub
|
||||
}
|
||||
|
||||
func (hub *PushNotificationsHub) start() {
|
||||
func (hub *PushNotificationsHub) start(c request.CTX) {
|
||||
hub.wg.Add(1)
|
||||
defer hub.wg.Done()
|
||||
for {
|
||||
@@ -330,9 +332,10 @@ func (hub *PushNotificationsHub) start() {
|
||||
var err *model.AppError
|
||||
switch notification.notificationType {
|
||||
case notificationTypeClear:
|
||||
err = hub.app.clearPushNotificationSync(notification.currentSessionId, notification.userID, notification.channelID, notification.rootID)
|
||||
err = hub.app.clearPushNotificationSync(c, notification.currentSessionId, notification.userID, notification.channelID, notification.rootID)
|
||||
case notificationTypeMessage:
|
||||
err = hub.app.sendPushNotificationSync(
|
||||
c,
|
||||
notification.post,
|
||||
notification.user,
|
||||
notification.channel,
|
||||
@@ -552,7 +555,7 @@ func DoesStatusAllowPushNotification(userNotifyProps model.StringMap, status *mo
|
||||
return false
|
||||
}
|
||||
|
||||
func (a *App) BuildPushNotificationMessage(contentsConfig string, post *model.Post, user *model.User, channel *model.Channel, channelName string, senderName string,
|
||||
func (a *App) BuildPushNotificationMessage(c request.CTX, contentsConfig string, post *model.Post, user *model.User, channel *model.Channel, channelName string, senderName string,
|
||||
explicitMention bool, channelWideMention bool, replyToThreadType string) (*model.PushNotification, *model.AppError) {
|
||||
|
||||
var msg *model.PushNotification
|
||||
@@ -563,9 +566,9 @@ func (a *App) BuildPushNotificationMessage(contentsConfig string, post *model.Po
|
||||
}
|
||||
|
||||
if contentsConfig == model.IdLoadedNotification {
|
||||
msg = a.buildIdLoadedPushNotificationMessage(channel, post, user)
|
||||
msg = a.buildIdLoadedPushNotificationMessage(c, channel, post, user)
|
||||
} else {
|
||||
msg = a.buildFullPushNotificationMessage(contentsConfig, post, user, channel, channelName, senderName, explicitMention, channelWideMention, replyToThreadType)
|
||||
msg = a.buildFullPushNotificationMessage(c, contentsConfig, post, user, channel, channelName, senderName, explicitMention, channelWideMention, replyToThreadType)
|
||||
}
|
||||
|
||||
unreadCount, err := a.Srv().Store.User().GetUnreadCount(user.Id)
|
||||
@@ -615,13 +618,13 @@ func (a *App) SendTestPushNotification(deviceID string) string {
|
||||
return "true"
|
||||
}
|
||||
|
||||
func (a *App) buildIdLoadedPushNotificationMessage(channel *model.Channel, post *model.Post, user *model.User) *model.PushNotification {
|
||||
func (a *App) buildIdLoadedPushNotificationMessage(c request.CTX, channel *model.Channel, post *model.Post, user *model.User) *model.PushNotification {
|
||||
userLocale := i18n.GetUserTranslations(user.Locale)
|
||||
msg := &model.PushNotification{
|
||||
PostId: post.Id,
|
||||
ChannelId: post.ChannelId,
|
||||
RootId: post.RootId,
|
||||
IsCRTEnabled: a.IsCRTEnabledForUser(user.Id),
|
||||
IsCRTEnabled: a.IsCRTEnabledForUser(c, user.Id),
|
||||
Category: model.CategoryCanReply,
|
||||
Version: model.PushMessageV2,
|
||||
TeamId: channel.TeamId,
|
||||
@@ -634,7 +637,7 @@ func (a *App) buildIdLoadedPushNotificationMessage(channel *model.Channel, post
|
||||
return msg
|
||||
}
|
||||
|
||||
func (a *App) buildFullPushNotificationMessage(contentsConfig string, post *model.Post, user *model.User, channel *model.Channel, channelName string, senderName string,
|
||||
func (a *App) buildFullPushNotificationMessage(c request.CTX, contentsConfig string, post *model.Post, user *model.User, channel *model.Channel, channelName string, senderName string,
|
||||
explicitMention bool, channelWideMention bool, replyToThreadType string) *model.PushNotification {
|
||||
|
||||
msg := &model.PushNotification{
|
||||
@@ -656,7 +659,7 @@ func (a *App) buildFullPushNotificationMessage(contentsConfig string, post *mode
|
||||
msg.ChannelName = channelName
|
||||
}
|
||||
|
||||
if a.IsCRTEnabledForUser(user.Id) {
|
||||
if a.IsCRTEnabledForUser(c, user.Id) {
|
||||
msg.IsCRTEnabled = true
|
||||
if post.RootId != "" {
|
||||
if contentsConfig != model.GenericNoChannelNotification {
|
||||
|
||||
@@ -941,11 +941,11 @@ func TestBuildPushNotificationMessageMentions(t *testing.T) {
|
||||
receiver := th.CreateUser()
|
||||
th.LinkUserToTeam(sender, team)
|
||||
th.LinkUserToTeam(receiver, team)
|
||||
channel1 := th.CreateChannel(team)
|
||||
channel1 := th.CreateChannel(th.Context, team)
|
||||
th.AddUserToChannel(sender, channel1)
|
||||
th.AddUserToChannel(receiver, channel1)
|
||||
|
||||
channel2 := th.CreateChannel(team)
|
||||
channel2 := th.CreateChannel(th.Context, team)
|
||||
th.AddUserToChannel(sender, channel2)
|
||||
th.AddUserToChannel(receiver, channel2)
|
||||
|
||||
@@ -981,7 +981,7 @@ func TestBuildPushNotificationMessageMentions(t *testing.T) {
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
receiver.NotifyProps["push"] = tc.pushNotifyProps
|
||||
msg, err := th.App.BuildPushNotificationMessage(model.FullNotification, post, receiver, channel1, channel1.Name, sender.Username, tc.explicitMention, tc.channelWideMention, tc.replyToThreadType)
|
||||
msg, err := th.App.BuildPushNotificationMessage(th.Context, model.FullNotification, post, receiver, channel1, channel1.Name, sender.Username, tc.explicitMention, tc.channelWideMention, tc.replyToThreadType)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, tc.expectedBadge, msg.Badge)
|
||||
})
|
||||
@@ -1158,7 +1158,7 @@ func TestClearPushNotificationSync(t *testing.T) {
|
||||
*cfg.ServiceSettings.CollapsedThreads = model.CollapsedThreadsDisabled
|
||||
})
|
||||
|
||||
err := th.App.clearPushNotificationSync(sess1.Id, "user1", "channel1", "")
|
||||
err := th.App.clearPushNotificationSync(th.Context, sess1.Id, "user1", "channel1", "")
|
||||
require.Nil(t, err)
|
||||
// Server side verification.
|
||||
// We verify that 1 request has been sent, and also check the message contents.
|
||||
@@ -1180,7 +1180,7 @@ func TestClearPushNotificationSync(t *testing.T) {
|
||||
mockThreadStore.On("GetTotalUnreadMentions", mock.AnythingOfType("string"), mock.AnythingOfType("string"), mock.Anything).Return(int64(3), nil)
|
||||
mockStore.On("Thread").Return(&mockThreadStore)
|
||||
|
||||
err = th.App.clearPushNotificationSync(sess1.Id, "user1", "channel1", "")
|
||||
err = th.App.clearPushNotificationSync(th.Context, sess1.Id, "user1", "channel1", "")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, handler.notifications()[1].Badge, 4)
|
||||
}
|
||||
@@ -1425,6 +1425,9 @@ func TestAllPushNotifications(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPushNotificationRace(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
memoryStore := config.NewTestMemoryStore()
|
||||
mockStore := testlib.GetMockStoreForSetupFunctions()
|
||||
mockPreferenceStore := mocks.PreferenceStore{}
|
||||
@@ -1452,7 +1455,7 @@ func TestPushNotificationRace(t *testing.T) {
|
||||
|
||||
app := New(ServerConnector(s.Channels()))
|
||||
require.NotPanics(t, func() {
|
||||
s.createPushNotificationsHub()
|
||||
s.createPushNotificationsHub(th.Context)
|
||||
|
||||
s.StopPushNotificationsHubWorkers()
|
||||
|
||||
@@ -1495,7 +1498,7 @@ func TestPushNotificationAttachment(t *testing.T) {
|
||||
ch := &model.Channel{}
|
||||
|
||||
t.Run("The notification should contain the fallback message from the attachment", func(t *testing.T) {
|
||||
pn := th.App.buildFullPushNotificationMessage("full", post, user, ch, ch.Name, "test", false, false, "")
|
||||
pn := th.App.buildFullPushNotificationMessage(th.Context, "full", post, user, ch, ch.Name, "test", false, false, "")
|
||||
assert.Equal(t, "test: hello world\nfallback text", pn.Message)
|
||||
})
|
||||
|
||||
|
||||
+41
-41
@@ -34,7 +34,7 @@ func TestSendNotifications(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.AddUserToChannel(th.BasicUser2, th.BasicChannel, false)
|
||||
th.App.AddUserToChannel(th.Context, th.BasicUser2, th.BasicChannel, false)
|
||||
|
||||
post1, appErr := th.App.CreatePostMissingChannel(th.Context, &model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
@@ -45,7 +45,7 @@ func TestSendNotifications(t *testing.T) {
|
||||
}, true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
mentions, err := th.App.SendNotifications(post1, th.BasicTeam, th.BasicChannel, th.BasicUser, nil, true)
|
||||
mentions, err := th.App.SendNotifications(th.Context, post1, th.BasicTeam, th.BasicChannel, th.BasicUser, nil, true)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, mentions)
|
||||
require.True(t, utils.StringInSlice(th.BasicUser2.Id, mentions), "mentions", mentions)
|
||||
@@ -68,14 +68,14 @@ func TestSendNotifications(t *testing.T) {
|
||||
groupMentionPost, createPostErr := th.App.CreatePost(th.Context, groupMentionPost, th.BasicChannel, false, true)
|
||||
require.Nil(t, createPostErr)
|
||||
|
||||
mentions, err = th.App.SendNotifications(groupMentionPost, th.BasicTeam, th.BasicChannel, th.BasicUser, nil, true)
|
||||
mentions, err = th.App.SendNotifications(th.Context, groupMentionPost, th.BasicTeam, th.BasicChannel, th.BasicUser, nil, true)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, mentions)
|
||||
require.Len(t, mentions, 0)
|
||||
|
||||
th.App.Srv().SetLicense(getLicWithSkuShortName(model.LicenseShortSkuProfessional))
|
||||
|
||||
mentions, err = th.App.SendNotifications(groupMentionPost, th.BasicTeam, th.BasicChannel, th.BasicUser, nil, true)
|
||||
mentions, err = th.App.SendNotifications(th.Context, groupMentionPost, th.BasicTeam, th.BasicChannel, th.BasicUser, nil, true)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, mentions)
|
||||
require.Len(t, mentions, 1)
|
||||
@@ -91,7 +91,7 @@ func TestSendNotifications(t *testing.T) {
|
||||
}, true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
mentions, err = th.App.SendNotifications(post2, th.BasicTeam, dm, th.BasicUser, nil, true)
|
||||
mentions, err = th.App.SendNotifications(th.Context, post2, th.BasicTeam, dm, th.BasicUser, nil, true)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, mentions)
|
||||
|
||||
@@ -107,12 +107,12 @@ func TestSendNotifications(t *testing.T) {
|
||||
}, true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
mentions, err = th.App.SendNotifications(post3, th.BasicTeam, dm, th.BasicUser, nil, true)
|
||||
mentions, err = th.App.SendNotifications(th.Context, post3, th.BasicTeam, dm, th.BasicUser, nil, true)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, mentions)
|
||||
|
||||
th.BasicChannel.DeleteAt = 1
|
||||
mentions, err = th.App.SendNotifications(post1, th.BasicTeam, th.BasicChannel, th.BasicUser, nil, true)
|
||||
mentions, err = th.App.SendNotifications(th.Context, post1, th.BasicTeam, th.BasicChannel, th.BasicUser, nil, true)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, mentions)
|
||||
|
||||
@@ -143,7 +143,7 @@ func TestSendNotifications(t *testing.T) {
|
||||
Order: []string{rootPost.Id, childPost.Id},
|
||||
Posts: map[string]*model.Post{rootPost.Id: rootPost, childPost.Id: childPost},
|
||||
}
|
||||
mentions, err = th.App.SendNotifications(childPost, th.BasicTeam, th.BasicChannel, th.BasicUser2, &postList, true)
|
||||
mentions, err = th.App.SendNotifications(th.Context, childPost, th.BasicTeam, th.BasicChannel, th.BasicUser2, &postList, true)
|
||||
require.NoError(t, err)
|
||||
require.False(t, utils.StringInSlice(user.Id, mentions))
|
||||
}
|
||||
@@ -172,7 +172,7 @@ func TestSendNotificationsWithManyUsers(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
user := th.CreateUser()
|
||||
th.LinkUserToTeam(user, th.BasicTeam)
|
||||
th.App.AddUserToChannel(user, th.BasicChannel, false)
|
||||
th.App.AddUserToChannel(th.Context, user, th.BasicChannel, false)
|
||||
users = append(users, user)
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ func TestSendOutOfChannelMentions(t *testing.T) {
|
||||
post := &model.Post{}
|
||||
potentialMentions := []string{user2.Username}
|
||||
|
||||
sent, err := th.App.sendOutOfChannelMentions(user1, post, channel, potentialMentions)
|
||||
sent, err := th.App.sendOutOfChannelMentions(th.Context, user1, post, channel, potentialMentions)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, sent)
|
||||
@@ -240,7 +240,7 @@ func TestSendOutOfChannelMentions(t *testing.T) {
|
||||
post := &model.Post{}
|
||||
potentialMentions := []string{"not a user"}
|
||||
|
||||
sent, err := th.App.sendOutOfChannelMentions(user1, post, channel, potentialMentions)
|
||||
sent, err := th.App.sendOutOfChannelMentions(th.Context, user1, post, channel, potentialMentions)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.False(t, sent)
|
||||
@@ -258,14 +258,14 @@ func TestFilterOutOfChannelMentions(t *testing.T) {
|
||||
user3 := th.CreateUser()
|
||||
guest := th.CreateGuest()
|
||||
user4 := th.CreateUser()
|
||||
guestAndUser4Channel := th.CreateChannel(th.BasicTeam)
|
||||
guestAndUser4Channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
defer th.App.PermanentDeleteUser(th.Context, guest)
|
||||
th.LinkUserToTeam(user3, th.BasicTeam)
|
||||
th.LinkUserToTeam(user4, th.BasicTeam)
|
||||
th.LinkUserToTeam(guest, th.BasicTeam)
|
||||
th.App.AddUserToChannel(guest, channel, false)
|
||||
th.App.AddUserToChannel(user4, guestAndUser4Channel, false)
|
||||
th.App.AddUserToChannel(guest, guestAndUser4Channel, false)
|
||||
th.App.AddUserToChannel(th.Context, guest, channel, false)
|
||||
th.App.AddUserToChannel(th.Context, user4, guestAndUser4Channel, false)
|
||||
th.App.AddUserToChannel(th.Context, guest, guestAndUser4Channel, false)
|
||||
|
||||
t.Run("should return users not in the channel", func(t *testing.T) {
|
||||
post := &model.Post{}
|
||||
@@ -385,9 +385,9 @@ func TestFilterOutOfChannelMentions(t *testing.T) {
|
||||
_, appErr = th.App.UpsertGroupMember(group.Id, nonChannelMember.Id)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
constrainedChannel := th.CreateChannel(th.BasicTeam)
|
||||
constrainedChannel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
constrainedChannel.GroupConstrained = model.NewBool(true)
|
||||
constrainedChannel, appErr = th.App.UpdateChannel(constrainedChannel)
|
||||
constrainedChannel, appErr = th.App.UpdateChannel(th.Context, constrainedChannel)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
_, appErr = th.App.UpsertGroupSyncable(&model.GroupSyncable{
|
||||
@@ -1056,24 +1056,24 @@ func TestAllowChannelMentions(t *testing.T) {
|
||||
post := &model.Post{ChannelId: th.BasicChannel.Id, UserId: th.BasicUser.Id}
|
||||
|
||||
t.Run("should return true for a regular post with few channel members", func(t *testing.T) {
|
||||
allowChannelMentions := th.App.allowChannelMentions(post, 5)
|
||||
allowChannelMentions := th.App.allowChannelMentions(th.Context, post, 5)
|
||||
assert.True(t, allowChannelMentions)
|
||||
})
|
||||
|
||||
t.Run("should return false for a channel header post", func(t *testing.T) {
|
||||
headerChangePost := &model.Post{ChannelId: th.BasicChannel.Id, UserId: th.BasicUser.Id, Type: model.PostTypeHeaderChange}
|
||||
allowChannelMentions := th.App.allowChannelMentions(headerChangePost, 5)
|
||||
allowChannelMentions := th.App.allowChannelMentions(th.Context, headerChangePost, 5)
|
||||
assert.False(t, allowChannelMentions)
|
||||
})
|
||||
|
||||
t.Run("should return false for a channel purpose post", func(t *testing.T) {
|
||||
purposeChangePost := &model.Post{ChannelId: th.BasicChannel.Id, UserId: th.BasicUser.Id, Type: model.PostTypePurposeChange}
|
||||
allowChannelMentions := th.App.allowChannelMentions(purposeChangePost, 5)
|
||||
allowChannelMentions := th.App.allowChannelMentions(th.Context, purposeChangePost, 5)
|
||||
assert.False(t, allowChannelMentions)
|
||||
})
|
||||
|
||||
t.Run("should return false for a regular post with many channel members", func(t *testing.T) {
|
||||
allowChannelMentions := th.App.allowChannelMentions(post, int(*th.App.Config().TeamSettings.MaxNotificationsPerChannel)+1)
|
||||
allowChannelMentions := th.App.allowChannelMentions(th.Context, post, int(*th.App.Config().TeamSettings.MaxNotificationsPerChannel)+1)
|
||||
assert.False(t, allowChannelMentions)
|
||||
})
|
||||
|
||||
@@ -1082,7 +1082,7 @@ func TestAllowChannelMentions(t *testing.T) {
|
||||
defer th.AddPermissionToRole(model.PermissionUseChannelMentions.Id, model.ChannelAdminRoleId)
|
||||
th.RemovePermissionFromRole(model.PermissionUseChannelMentions.Id, model.ChannelUserRoleId)
|
||||
th.RemovePermissionFromRole(model.PermissionUseChannelMentions.Id, model.ChannelAdminRoleId)
|
||||
allowChannelMentions := th.App.allowChannelMentions(post, 5)
|
||||
allowChannelMentions := th.App.allowChannelMentions(th.Context, post, 5)
|
||||
assert.False(t, allowChannelMentions)
|
||||
})
|
||||
}
|
||||
@@ -1108,26 +1108,26 @@ func TestAllowGroupMentions(t *testing.T) {
|
||||
for name, tc := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
th.App.Srv().SetLicense(tc.license)
|
||||
got := th.App.allowGroupMentions(post)
|
||||
got := th.App.allowGroupMentions(th.Context, post)
|
||||
assert.Equal(t, tc.want, got)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("should return true for a regular post with few channel members", func(t *testing.T) {
|
||||
allowGroupMentions := th.App.allowGroupMentions(post)
|
||||
allowGroupMentions := th.App.allowGroupMentions(th.Context, post)
|
||||
assert.True(t, allowGroupMentions)
|
||||
})
|
||||
|
||||
t.Run("should return false for a channel header post", func(t *testing.T) {
|
||||
headerChangePost := &model.Post{ChannelId: th.BasicChannel.Id, UserId: th.BasicUser.Id, Type: model.PostTypeHeaderChange}
|
||||
allowGroupMentions := th.App.allowGroupMentions(headerChangePost)
|
||||
allowGroupMentions := th.App.allowGroupMentions(th.Context, headerChangePost)
|
||||
assert.False(t, allowGroupMentions)
|
||||
})
|
||||
|
||||
t.Run("should return false for a channel purpose post", func(t *testing.T) {
|
||||
purposeChangePost := &model.Post{ChannelId: th.BasicChannel.Id, UserId: th.BasicUser.Id, Type: model.PostTypePurposeChange}
|
||||
allowGroupMentions := th.App.allowGroupMentions(purposeChangePost)
|
||||
allowGroupMentions := th.App.allowGroupMentions(th.Context, purposeChangePost)
|
||||
assert.False(t, allowGroupMentions)
|
||||
})
|
||||
|
||||
@@ -1138,7 +1138,7 @@ func TestAllowGroupMentions(t *testing.T) {
|
||||
}()
|
||||
th.RemovePermissionFromRole(model.PermissionUseGroupMentions.Id, model.ChannelUserRoleId)
|
||||
th.RemovePermissionFromRole(model.PermissionUseGroupMentions.Id, model.ChannelAdminRoleId)
|
||||
allowGroupMentions := th.App.allowGroupMentions(post)
|
||||
allowGroupMentions := th.App.allowGroupMentions(th.Context, post)
|
||||
assert.False(t, allowGroupMentions)
|
||||
})
|
||||
}
|
||||
@@ -2407,7 +2407,7 @@ func TestUserAllowsEmail(t *testing.T) {
|
||||
model.MarkUnreadNotifyProp: model.ChannelMarkUnreadAll,
|
||||
}
|
||||
|
||||
assert.True(t, th.App.userAllowsEmail(user, channelMemberNotificationProps, &model.Post{Type: "some-post-type"}))
|
||||
assert.True(t, th.App.userAllowsEmail(th.Context, user, channelMemberNotificationProps, &model.Post{Type: "some-post-type"}))
|
||||
})
|
||||
|
||||
t.Run("should return false in case the status is ONLINE", func(t *testing.T) {
|
||||
@@ -2420,7 +2420,7 @@ func TestUserAllowsEmail(t *testing.T) {
|
||||
model.MarkUnreadNotifyProp: model.ChannelMarkUnreadAll,
|
||||
}
|
||||
|
||||
assert.False(t, th.App.userAllowsEmail(user, channelMemberNotificationProps, &model.Post{Type: "some-post-type"}))
|
||||
assert.False(t, th.App.userAllowsEmail(th.Context, user, channelMemberNotificationProps, &model.Post{Type: "some-post-type"}))
|
||||
})
|
||||
|
||||
t.Run("should return false in case the EMAIL_NOTIFY_PROP is false", func(t *testing.T) {
|
||||
@@ -2433,7 +2433,7 @@ func TestUserAllowsEmail(t *testing.T) {
|
||||
model.MarkUnreadNotifyProp: model.ChannelMarkUnreadAll,
|
||||
}
|
||||
|
||||
assert.False(t, th.App.userAllowsEmail(user, channelMemberNotificationProps, &model.Post{Type: "some-post-type"}))
|
||||
assert.False(t, th.App.userAllowsEmail(th.Context, user, channelMemberNotificationProps, &model.Post{Type: "some-post-type"}))
|
||||
})
|
||||
|
||||
t.Run("should return false in case the MARK_UNREAD_NOTIFY_PROP is CHANNEL_MARK_UNREAD_MENTION", func(t *testing.T) {
|
||||
@@ -2446,7 +2446,7 @@ func TestUserAllowsEmail(t *testing.T) {
|
||||
model.MarkUnreadNotifyProp: model.ChannelMarkUnreadMention,
|
||||
}
|
||||
|
||||
assert.False(t, th.App.userAllowsEmail(user, channelMemberNotificationProps, &model.Post{Type: "some-post-type"}))
|
||||
assert.False(t, th.App.userAllowsEmail(th.Context, user, channelMemberNotificationProps, &model.Post{Type: "some-post-type"}))
|
||||
})
|
||||
|
||||
t.Run("should return false in case the Post type is POST_AUTO_RESPONDER", func(t *testing.T) {
|
||||
@@ -2459,7 +2459,7 @@ func TestUserAllowsEmail(t *testing.T) {
|
||||
model.MarkUnreadNotifyProp: model.ChannelMarkUnreadAll,
|
||||
}
|
||||
|
||||
assert.False(t, th.App.userAllowsEmail(user, channelMemberNotificationProps, &model.Post{Type: model.PostTypeAutoResponder}))
|
||||
assert.False(t, th.App.userAllowsEmail(th.Context, user, channelMemberNotificationProps, &model.Post{Type: model.PostTypeAutoResponder}))
|
||||
})
|
||||
|
||||
t.Run("should return false in case the status is STATUS_OUT_OF_OFFICE", func(t *testing.T) {
|
||||
@@ -2472,7 +2472,7 @@ func TestUserAllowsEmail(t *testing.T) {
|
||||
model.MarkUnreadNotifyProp: model.ChannelMarkUnreadAll,
|
||||
}
|
||||
|
||||
assert.False(t, th.App.userAllowsEmail(user, channelMemberNotificationProps, &model.Post{Type: model.PostTypeAutoResponder}))
|
||||
assert.False(t, th.App.userAllowsEmail(th.Context, user, channelMemberNotificationProps, &model.Post{Type: model.PostTypeAutoResponder}))
|
||||
})
|
||||
|
||||
t.Run("should return false in case the status is STATUS_ONLINE", func(t *testing.T) {
|
||||
@@ -2485,7 +2485,7 @@ func TestUserAllowsEmail(t *testing.T) {
|
||||
model.MarkUnreadNotifyProp: model.ChannelMarkUnreadAll,
|
||||
}
|
||||
|
||||
assert.False(t, th.App.userAllowsEmail(user, channelMemberNotificationProps, &model.Post{Type: model.PostTypeAutoResponder}))
|
||||
assert.False(t, th.App.userAllowsEmail(th.Context, user, channelMemberNotificationProps, &model.Post{Type: model.PostTypeAutoResponder}))
|
||||
})
|
||||
|
||||
t.Run("should return false in the case user is a bot", func(t *testing.T) {
|
||||
@@ -2498,7 +2498,7 @@ func TestUserAllowsEmail(t *testing.T) {
|
||||
model.MarkUnreadNotifyProp: model.ChannelMarkUnreadAll,
|
||||
}
|
||||
|
||||
assert.False(t, th.App.userAllowsEmail(user, channelMemberNotifcationProps, &model.Post{Type: model.PostTypeAutoResponder}))
|
||||
assert.False(t, th.App.userAllowsEmail(th.Context, user, channelMemberNotifcationProps, &model.Post{Type: model.PostTypeAutoResponder}))
|
||||
})
|
||||
|
||||
}
|
||||
@@ -2517,13 +2517,13 @@ func TestInsertGroupMentions(t *testing.T) {
|
||||
|
||||
groupChannelMember := th.CreateUser()
|
||||
th.LinkUserToTeam(groupChannelMember, team)
|
||||
th.App.AddUserToChannel(groupChannelMember, channel, false)
|
||||
th.App.AddUserToChannel(th.Context, groupChannelMember, channel, false)
|
||||
_, err = th.App.UpsertGroupMember(group.Id, groupChannelMember.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
nonGroupChannelMember := th.CreateUser()
|
||||
th.LinkUserToTeam(nonGroupChannelMember, team)
|
||||
th.App.AddUserToChannel(nonGroupChannelMember, channel, false)
|
||||
th.App.AddUserToChannel(th.Context, nonGroupChannelMember, channel, false)
|
||||
|
||||
nonChannelGroupMember := th.CreateUser()
|
||||
th.LinkUserToTeam(nonChannelGroupMember, team)
|
||||
@@ -2593,7 +2593,7 @@ func TestInsertGroupMentions(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("should add mentions for members while in group channel", func(t *testing.T) {
|
||||
groupChannel, err := th.App.CreateGroupChannel([]string{groupChannelMember.Id, nonGroupChannelMember.Id, th.BasicUser.Id}, groupChannelMember.Id)
|
||||
groupChannel, err := th.App.CreateGroupChannel(th.Context, []string{groupChannelMember.Id, nonGroupChannelMember.Id, th.BasicUser.Id}, groupChannelMember.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
mentions := &ExplicitMentions{}
|
||||
@@ -2639,9 +2639,9 @@ func TestGetGroupsAllowedForReferenceInChannel(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// Sync first group to constrained channel
|
||||
constrainedChannel := th.CreateChannel(th.BasicTeam)
|
||||
constrainedChannel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
constrainedChannel.GroupConstrained = model.NewBool(true)
|
||||
constrainedChannel, err = th.App.UpdateChannel(constrainedChannel)
|
||||
constrainedChannel, err = th.App.UpdateChannel(th.Context, constrainedChannel)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.UpsertGroupSyncable(&model.GroupSyncable{
|
||||
GroupId: group1.Id,
|
||||
@@ -2812,7 +2812,7 @@ func TestReplyPostNotificationsWithCRT(t *testing.T) {
|
||||
Order: []string{rootPost.Id, childPost.Id},
|
||||
Posts: map[string]*model.Post{rootPost.Id: rootPost, childPost.Id: childPost},
|
||||
}
|
||||
mentions, err := th.App.SendNotifications(childPost, th.BasicTeam, th.BasicChannel, th.BasicUser2, &postList, true)
|
||||
mentions, err := th.App.SendNotifications(th.Context, childPost, th.BasicTeam, th.BasicChannel, th.BasicUser2, &postList, true)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, utils.StringInSlice(user.Id, mentions))
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+3
-2
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app/request"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
)
|
||||
|
||||
@@ -27,8 +28,8 @@ func (s *permissionsServiceWrapper) HasPermissionToTeam(userID string, teamID st
|
||||
return s.app.HasPermissionToTeam(userID, teamID, permission)
|
||||
}
|
||||
|
||||
func (s *permissionsServiceWrapper) HasPermissionToChannel(askingUserID string, channelID string, permission *model.Permission) bool {
|
||||
return s.app.HasPermissionToChannel(askingUserID, channelID, permission)
|
||||
func (s *permissionsServiceWrapper) HasPermissionToChannel(c request.CTX, askingUserID string, channelID string, permission *model.Permission) bool {
|
||||
return s.app.HasPermissionToChannel(c, askingUserID, channelID, permission)
|
||||
}
|
||||
|
||||
func (a *App) ResetPermissionsSystem() *model.AppError {
|
||||
|
||||
+24
-25
@@ -5,7 +5,6 @@ package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -418,7 +417,7 @@ func (api *PluginAPI) CreateChannel(channel *model.Channel) (*model.Channel, *mo
|
||||
}
|
||||
|
||||
func (api *PluginAPI) DeleteChannel(channelID string) *model.AppError {
|
||||
channel, err := api.app.GetChannel(channelID)
|
||||
channel, err := api.app.GetChannel(api.ctx, channelID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -426,7 +425,7 @@ func (api *PluginAPI) DeleteChannel(channelID string) *model.AppError {
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetPublicChannelsForTeam(teamID string, page, perPage int) ([]*model.Channel, *model.AppError) {
|
||||
channels, err := api.app.GetPublicChannelsForTeam(teamID, page*perPage, perPage)
|
||||
channels, err := api.app.GetPublicChannelsForTeam(api.ctx, teamID, page*perPage, perPage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -434,19 +433,19 @@ func (api *PluginAPI) GetPublicChannelsForTeam(teamID string, page, perPage int)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetChannel(channelID string) (*model.Channel, *model.AppError) {
|
||||
return api.app.GetChannel(channelID)
|
||||
return api.app.GetChannel(api.ctx, channelID)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetChannelByName(teamID, name string, includeDeleted bool) (*model.Channel, *model.AppError) {
|
||||
return api.app.GetChannelByName(name, teamID, includeDeleted)
|
||||
return api.app.GetChannelByName(api.ctx, name, teamID, includeDeleted)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetChannelByNameForTeamName(teamName, channelName string, includeDeleted bool) (*model.Channel, *model.AppError) {
|
||||
return api.app.GetChannelByNameForTeamName(channelName, teamName, includeDeleted)
|
||||
return api.app.GetChannelByNameForTeamName(api.ctx, channelName, teamName, includeDeleted)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetChannelsForTeamForUser(teamID, userID string, includeDeleted bool) ([]*model.Channel, *model.AppError) {
|
||||
channels, err := api.app.GetChannelsForTeamForUser(teamID, userID, &model.ChannelSearchOpts{
|
||||
channels, err := api.app.GetChannelsForTeamForUser(api.ctx, teamID, userID, &model.ChannelSearchOpts{
|
||||
IncludeDeleted: includeDeleted,
|
||||
LastDeleteAt: 0,
|
||||
})
|
||||
@@ -457,11 +456,11 @@ func (api *PluginAPI) GetChannelsForTeamForUser(teamID, userID string, includeDe
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetChannelStats(channelID string) (*model.ChannelStats, *model.AppError) {
|
||||
memberCount, err := api.app.GetChannelMemberCount(channelID)
|
||||
memberCount, err := api.app.GetChannelMemberCount(api.ctx, channelID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
guestCount, err := api.app.GetChannelMemberCount(channelID)
|
||||
guestCount, err := api.app.GetChannelMemberCount(api.ctx, channelID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -473,15 +472,15 @@ func (api *PluginAPI) GetDirectChannel(userID1, userID2 string) (*model.Channel,
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetGroupChannel(userIDs []string) (*model.Channel, *model.AppError) {
|
||||
return api.app.CreateGroupChannel(userIDs, "")
|
||||
return api.app.CreateGroupChannel(api.ctx, userIDs, "")
|
||||
}
|
||||
|
||||
func (api *PluginAPI) UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError) {
|
||||
return api.app.UpdateChannel(channel)
|
||||
return api.app.UpdateChannel(api.ctx, channel)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) SearchChannels(teamID string, term string) ([]*model.Channel, *model.AppError) {
|
||||
channels, err := api.app.SearchChannels(teamID, term)
|
||||
channels, err := api.app.SearchChannels(api.ctx, teamID, term)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -489,15 +488,15 @@ func (api *PluginAPI) SearchChannels(teamID string, term string) ([]*model.Chann
|
||||
}
|
||||
|
||||
func (api *PluginAPI) CreateChannelSidebarCategory(userID, teamID string, newCategory *model.SidebarCategoryWithChannels) (*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
return api.app.CreateSidebarCategory(userID, teamID, newCategory)
|
||||
return api.app.CreateSidebarCategory(api.ctx, userID, teamID, newCategory)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetChannelSidebarCategories(userID, teamID string) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
return api.app.GetSidebarCategoriesForTeamForUser(userID, teamID)
|
||||
return api.app.GetSidebarCategoriesForTeamForUser(api.ctx, userID, teamID)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) UpdateChannelSidebarCategories(userID, teamID string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
return api.app.UpdateSidebarCategories(userID, teamID, categories)
|
||||
return api.app.UpdateSidebarCategories(api.ctx, userID, teamID, categories)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) SearchUsers(search *model.UserSearch) ([]*model.User, *model.AppError) {
|
||||
@@ -576,29 +575,29 @@ func (api *PluginAPI) AddUserToChannel(channelID, userID, asUserID string) (*mod
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetChannelMember(channelID, userID string) (*model.ChannelMember, *model.AppError) {
|
||||
return api.app.GetChannelMember(context.Background(), channelID, userID)
|
||||
return api.app.GetChannelMember(api.ctx, channelID, userID)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetChannelMembers(channelID string, page, perPage int) (model.ChannelMembers, *model.AppError) {
|
||||
return api.app.GetChannelMembersPage(channelID, page, perPage)
|
||||
return api.app.GetChannelMembersPage(api.ctx, channelID, page, perPage)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetChannelMembersByIds(channelID string, userIDs []string) (model.ChannelMembers, *model.AppError) {
|
||||
return api.app.GetChannelMembersByIds(channelID, userIDs)
|
||||
return api.app.GetChannelMembersByIds(api.ctx, channelID, userIDs)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetChannelMembersForUser(_, userID string, page, perPage int) ([]*model.ChannelMember, *model.AppError) {
|
||||
// The team ID parameter was never used in the SQL query.
|
||||
// But we keep this to maintain compatibility.
|
||||
return api.app.GetChannelMembersForUserWithPagination(userID, page, perPage)
|
||||
return api.app.GetChannelMembersForUserWithPagination(api.ctx, userID, page, perPage)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) UpdateChannelMemberRoles(channelID, userID, newRoles string) (*model.ChannelMember, *model.AppError) {
|
||||
return api.app.UpdateChannelMemberRoles(channelID, userID, newRoles)
|
||||
return api.app.UpdateChannelMemberRoles(api.ctx, channelID, userID, newRoles)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) UpdateChannelMemberNotifications(channelID, userID string, notifications map[string]string) (*model.ChannelMember, *model.AppError) {
|
||||
return api.app.UpdateChannelMemberNotifyProps(notifications, channelID, userID)
|
||||
return api.app.UpdateChannelMemberNotifyProps(api.ctx, notifications, channelID, userID)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) DeleteChannelMember(channelID, userID string) *model.AppError {
|
||||
@@ -644,11 +643,11 @@ func (api *PluginAPI) GetReactions(postID string) ([]*model.Reaction, *model.App
|
||||
}
|
||||
|
||||
func (api *PluginAPI) SendEphemeralPost(userID string, post *model.Post) *model.Post {
|
||||
return api.app.SendEphemeralPost(userID, post)
|
||||
return api.app.SendEphemeralPost(api.ctx, userID, post)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) UpdateEphemeralPost(userID string, post *model.Post) *model.Post {
|
||||
return api.app.UpdateEphemeralPost(userID, post)
|
||||
return api.app.UpdateEphemeralPost(api.ctx, userID, post)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) DeleteEphemeralPost(userID, postID string) {
|
||||
@@ -656,7 +655,7 @@ func (api *PluginAPI) DeleteEphemeralPost(userID, postID string) {
|
||||
}
|
||||
|
||||
func (api *PluginAPI) DeletePost(postID string) *model.AppError {
|
||||
_, err := api.app.DeletePost(postID, api.id)
|
||||
_, err := api.app.DeletePost(api.ctx, postID, api.id)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -923,7 +922,7 @@ func (api *PluginAPI) HasPermissionToTeam(userID, teamID string, permission *mod
|
||||
}
|
||||
|
||||
func (api *PluginAPI) HasPermissionToChannel(userID, channelID string, permission *model.Permission) bool {
|
||||
return api.app.HasPermissionToChannel(userID, channelID, permission)
|
||||
return api.app.HasPermissionToChannel(api.ctx, userID, channelID, permission)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) RolesGrantPermission(roleNames []string, permissionId string) bool {
|
||||
|
||||
@@ -154,7 +154,7 @@ func (a *App) tryExecutePluginCommand(c *request.Context, args *model.CommandArg
|
||||
args.AddUserMention(username, userID)
|
||||
}
|
||||
|
||||
for channelName, channelID := range a.MentionsToPublicChannels(args.Command, args.TeamId) {
|
||||
for channelName, channelID := range a.MentionsToPublicChannels(c, args.Command, args.TeamId) {
|
||||
args.AddChannelMention(channelName, channelID)
|
||||
}
|
||||
|
||||
|
||||
@@ -912,6 +912,7 @@ func TestHookContext(t *testing.T) {
|
||||
|
||||
// We don't actually have a session, we are faking it so just set something arbitrarily
|
||||
ctx := request.NewContext(context.Background(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.Session{}, nil)
|
||||
ctx.SetLogger(th.TestLogger)
|
||||
ctx.Session().Id = model.NewId()
|
||||
|
||||
var mockAPI plugintest.API
|
||||
|
||||
+1
-1
@@ -638,7 +638,7 @@ func TestChannelsPluginsInit(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
runNoPanicTest := func(t *testing.T) {
|
||||
ctx := request.EmptyContext()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
path, _ := fileutils.FindDir("tests")
|
||||
|
||||
require.NotPanics(t, func() {
|
||||
|
||||
+51
-51
@@ -75,9 +75,9 @@ func (a *App) CreatePostAsUser(c *request.Context, post *model.Post, currentSess
|
||||
// the post is NOT a reply post with CRT enabled
|
||||
_, fromWebhook := post.GetProps()["from_webhook"]
|
||||
_, fromBot := post.GetProps()["from_bot"]
|
||||
isCRTReply := post.RootId != "" && a.IsCRTEnabledForUser(post.UserId)
|
||||
isCRTReply := post.RootId != "" && a.IsCRTEnabledForUser(c, post.UserId)
|
||||
if !fromWebhook && !fromBot && !isCRTReply {
|
||||
if _, err := a.MarkChannelsAsViewed([]string{post.ChannelId}, post.UserId, currentSessionId, true); err != nil {
|
||||
if _, err := a.MarkChannelsAsViewed(c, []string{post.ChannelId}, post.UserId, currentSessionId, true); err != nil {
|
||||
mlog.Warn(
|
||||
"Encountered error updating last viewed",
|
||||
mlog.String("channel_id", post.ChannelId),
|
||||
@@ -90,7 +90,7 @@ func (a *App) CreatePostAsUser(c *request.Context, post *model.Post, currentSess
|
||||
return rp, nil
|
||||
}
|
||||
|
||||
func (a *App) CreatePostMissingChannel(c *request.Context, post *model.Post, triggerWebhooks bool) (*model.Post, *model.AppError) {
|
||||
func (a *App) CreatePostMissingChannel(c request.CTX, post *model.Post, triggerWebhooks bool) (*model.Post, *model.AppError) {
|
||||
channel, err := a.Srv().Store.Channel().Get(post.ChannelId, true)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
@@ -147,7 +147,7 @@ func (a *App) deduplicateCreatePost(post *model.Post) (foundPost *model.Post, er
|
||||
return actualPost, nil
|
||||
}
|
||||
|
||||
func (a *App) CreatePost(c *request.Context, post *model.Post, channel *model.Channel, triggerWebhooks, setOnline bool) (savedPost *model.Post, err *model.AppError) {
|
||||
func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel, triggerWebhooks, setOnline bool) (savedPost *model.Post, err *model.AppError) {
|
||||
foundPost, err := a.deduplicateCreatePost(post)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -199,7 +199,7 @@ func (a *App) CreatePost(c *request.Context, post *model.Post, channel *model.Ch
|
||||
}
|
||||
|
||||
var ephemeralPost *model.Post
|
||||
if post.Type == "" && !a.HasPermissionToChannel(user.Id, channel.Id, model.PermissionUseChannelMentions) {
|
||||
if post.Type == "" && !a.HasPermissionToChannel(c, user.Id, channel.Id, model.PermissionUseChannelMentions) {
|
||||
mention := post.DisableMentionHighlights()
|
||||
if mention != "" {
|
||||
T := i18n.GetUserTranslations(user.Locale)
|
||||
@@ -233,7 +233,7 @@ func (a *App) CreatePost(c *request.Context, post *model.Post, channel *model.Ch
|
||||
|
||||
post.Hashtags, _ = model.ParseHashtags(post.Message)
|
||||
|
||||
if err = a.FillInPostProps(post, channel); err != nil {
|
||||
if err = a.FillInPostProps(c, post, channel); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ func (a *App) CreatePost(c *request.Context, post *model.Post, channel *model.Ch
|
||||
post.CreateAt = model.GetMillis()
|
||||
}
|
||||
|
||||
post = a.getEmbedsAndImages(post, true)
|
||||
post = a.getEmbedsAndImages(c, post, true)
|
||||
previewPost := post.GetPreviewPost()
|
||||
if previewPost != nil {
|
||||
post.AddProp(model.PostPropsPreviewedPost, previewPost.PostID)
|
||||
@@ -359,10 +359,10 @@ func (a *App) CreatePost(c *request.Context, post *model.Post, channel *model.Ch
|
||||
|
||||
// Send any ephemeral posts after the post is created to ensure it shows up after the latest post created
|
||||
if ephemeralPost != nil {
|
||||
a.SendEphemeralPost(post.UserId, ephemeralPost)
|
||||
a.SendEphemeralPost(c, post.UserId, ephemeralPost)
|
||||
}
|
||||
|
||||
rpost, err = a.SanitizePostMetadataForUser(rpost, c.Session().UserId)
|
||||
rpost, err = a.SanitizePostMetadataForUser(c, rpost, c.Session().UserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -409,7 +409,7 @@ func (a *App) attachFilesToPost(post *model.Post) *model.AppError {
|
||||
// channel_mentions.
|
||||
//
|
||||
// If channel is nil, FillInPostProps will look up the channel corresponding to the post.
|
||||
func (a *App) FillInPostProps(post *model.Post, channel *model.Channel) *model.AppError {
|
||||
func (a *App) FillInPostProps(c request.CTX, post *model.Post, channel *model.Channel) *model.AppError {
|
||||
channelMentions := post.ChannelMentions()
|
||||
channelMentionsProp := make(map[string]any)
|
||||
|
||||
@@ -422,7 +422,7 @@ func (a *App) FillInPostProps(post *model.Post, channel *model.Channel) *model.A
|
||||
channel = postChannel
|
||||
}
|
||||
|
||||
mentionedChannels, err := a.GetChannelsByNames(channelMentions, channel.TeamId)
|
||||
mentionedChannels, err := a.GetChannelsByNames(c, channelMentions, channel.TeamId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -449,14 +449,14 @@ func (a *App) FillInPostProps(post *model.Post, channel *model.Channel) *model.A
|
||||
}
|
||||
|
||||
matched := atMentionPattern.MatchString(post.Message)
|
||||
if a.Srv().License() != nil && *a.Srv().License().Features.LDAPGroups && matched && !a.HasPermissionToChannel(post.UserId, post.ChannelId, model.PermissionUseGroupMentions) {
|
||||
if a.Srv().License() != nil && *a.Srv().License().Features.LDAPGroups && matched && !a.HasPermissionToChannel(c, post.UserId, post.ChannelId, model.PermissionUseGroupMentions) {
|
||||
post.AddProp(model.PostPropsGroupHighlightDisabled, true)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) handlePostEvents(c *request.Context, post *model.Post, user *model.User, channel *model.Channel, triggerWebhooks bool, parentPostList *model.PostList, setOnline bool) error {
|
||||
func (a *App) handlePostEvents(c request.CTX, post *model.Post, user *model.User, channel *model.Channel, triggerWebhooks bool, parentPostList *model.PostList, setOnline bool) error {
|
||||
var team *model.Team
|
||||
if channel.TeamId != "" {
|
||||
t, err := a.Srv().Store.Team().Get(channel.TeamId)
|
||||
@@ -472,7 +472,7 @@ func (a *App) handlePostEvents(c *request.Context, post *model.Post, user *model
|
||||
a.invalidateCacheForChannel(channel)
|
||||
a.invalidateCacheForChannelPosts(channel.Id)
|
||||
|
||||
if _, err := a.SendNotifications(post, team, channel, user, parentPostList, setOnline); err != nil {
|
||||
if _, err := a.SendNotifications(c, post, team, channel, user, parentPostList, setOnline); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -496,7 +496,7 @@ func (a *App) handlePostEvents(c *request.Context, post *model.Post, user *model
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) SendEphemeralPost(userID string, post *model.Post) *model.Post {
|
||||
func (a *App) SendEphemeralPost(c request.CTX, userID string, post *model.Post) *model.Post {
|
||||
post.Type = model.PostTypeEphemeral
|
||||
|
||||
// fill in fields which haven't been specified which have sensible defaults
|
||||
@@ -512,7 +512,7 @@ func (a *App) SendEphemeralPost(userID string, post *model.Post) *model.Post {
|
||||
|
||||
post.GenerateActionIds()
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventEphemeralMessage, "", post.ChannelId, userID, nil)
|
||||
post = a.PreparePostForClientWithEmbedsAndImages(post, true, false)
|
||||
post = a.PreparePostForClientWithEmbedsAndImages(c, post, true, false)
|
||||
post = model.AddPostActionCookies(post, a.PostActionCookieSecret())
|
||||
|
||||
postJSON, jsonErr := post.ToJSON()
|
||||
@@ -525,7 +525,7 @@ func (a *App) SendEphemeralPost(userID string, post *model.Post) *model.Post {
|
||||
return post
|
||||
}
|
||||
|
||||
func (a *App) UpdateEphemeralPost(userID string, post *model.Post) *model.Post {
|
||||
func (a *App) UpdateEphemeralPost(c request.CTX, userID string, post *model.Post) *model.Post {
|
||||
post.Type = model.PostTypeEphemeral
|
||||
|
||||
post.UpdateAt = model.GetMillis()
|
||||
@@ -535,7 +535,7 @@ func (a *App) UpdateEphemeralPost(userID string, post *model.Post) *model.Post {
|
||||
|
||||
post.GenerateActionIds()
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventPostEdited, "", post.ChannelId, userID, nil)
|
||||
post = a.PreparePostForClientWithEmbedsAndImages(post, true, false)
|
||||
post = a.PreparePostForClientWithEmbedsAndImages(c, post, true, false)
|
||||
post = model.AddPostActionCookies(post, a.PostActionCookieSecret())
|
||||
postJSON, jsonErr := post.ToJSON()
|
||||
if jsonErr != nil {
|
||||
@@ -604,7 +604,7 @@ func (a *App) UpdatePost(c *request.Context, post *model.Post, safeUpdate bool)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
channel, err := a.GetChannel(oldPost.ChannelId)
|
||||
channel, err := a.GetChannel(c, oldPost.ChannelId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -633,7 +633,7 @@ func (a *App) UpdatePost(c *request.Context, post *model.Post, safeUpdate bool)
|
||||
newPost.EditAt = model.GetMillis()
|
||||
}
|
||||
|
||||
if err = a.FillInPostProps(post, nil); err != nil {
|
||||
if err = a.FillInPostProps(c, post, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -674,7 +674,7 @@ func (a *App) UpdatePost(c *request.Context, post *model.Post, safeUpdate bool)
|
||||
})
|
||||
}
|
||||
|
||||
rpost = a.PreparePostForClientWithEmbedsAndImages(rpost, false, true)
|
||||
rpost = a.PreparePostForClientWithEmbedsAndImages(c, rpost, false, true)
|
||||
|
||||
// Ensure IsFollowing is nil since this updated post will be broadcast to all users
|
||||
// and we don't want to have to populate it for every single user and broadcast to each
|
||||
@@ -693,7 +693,7 @@ func (a *App) UpdatePost(c *request.Context, post *model.Post, safeUpdate bool)
|
||||
}
|
||||
message.Add("post", postJSON)
|
||||
|
||||
published, err := a.publishWebsocketEventForPermalinkPost(rpost, message)
|
||||
published, err := a.publishWebsocketEventForPermalinkPost(c, rpost, message)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -706,7 +706,7 @@ func (a *App) UpdatePost(c *request.Context, post *model.Post, safeUpdate bool)
|
||||
return rpost, nil
|
||||
}
|
||||
|
||||
func (a *App) publishWebsocketEventForPermalinkPost(post *model.Post, message *model.WebSocketEvent) (published bool, err *model.AppError) {
|
||||
func (a *App) publishWebsocketEventForPermalinkPost(c request.CTX, post *model.Post, message *model.WebSocketEvent) (published bool, err *model.AppError) {
|
||||
var previewedPostID string
|
||||
if val, ok := post.GetProp(model.PostPropsPreviewedPost).(string); ok {
|
||||
previewedPostID = val
|
||||
@@ -728,12 +728,12 @@ func (a *App) publishWebsocketEventForPermalinkPost(post *model.Post, message *m
|
||||
return false, err
|
||||
}
|
||||
|
||||
channelMembers, err := a.GetChannelMembersPage(post.ChannelId, 0, 10000000)
|
||||
channelMembers, err := a.GetChannelMembersPage(c, post.ChannelId, 0, 10000000)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
permalinkPreviewedChannel, err := a.GetChannel(previewedPost.ChannelId)
|
||||
permalinkPreviewedChannel, err := a.GetChannel(c, previewedPost.ChannelId)
|
||||
if err != nil {
|
||||
if err.StatusCode == http.StatusNotFound {
|
||||
mlog.Warn("channel containing permalinked post not found", mlog.String("referenced_channel_id", previewedPost.ChannelId))
|
||||
@@ -748,7 +748,7 @@ func (a *App) publishWebsocketEventForPermalinkPost(post *model.Post, message *m
|
||||
post.Metadata.Embeds[0].Data = permalinkPreviewedPost
|
||||
}
|
||||
|
||||
postForUser := a.sanitizePostMetadataForUserAndChannel(post, permalinkPreviewedPost, permalinkPreviewedChannel, cm.UserId)
|
||||
postForUser := a.sanitizePostMetadataForUserAndChannel(c, post, permalinkPreviewedPost, permalinkPreviewedChannel, cm.UserId)
|
||||
|
||||
// Using DeepCopy here to avoid a race condition
|
||||
// between publishing the event and setting the "post" data value below.
|
||||
@@ -774,7 +774,7 @@ func (a *App) PatchPost(c *request.Context, postID string, patch *model.PostPatc
|
||||
return nil, err
|
||||
}
|
||||
|
||||
channel, err := a.GetChannel(post.ChannelId)
|
||||
channel, err := a.GetChannel(c, post.ChannelId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -784,7 +784,7 @@ func (a *App) PatchPost(c *request.Context, postID string, patch *model.PostPatc
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !a.HasPermissionToChannel(post.UserId, post.ChannelId, model.PermissionUseChannelMentions) {
|
||||
if !a.HasPermissionToChannel(c, post.UserId, post.ChannelId, model.PermissionUseChannelMentions) {
|
||||
patch.DisableMentionHighlights()
|
||||
}
|
||||
|
||||
@@ -946,7 +946,7 @@ func (a *App) GetFlaggedPostsForChannel(userID, channelID string, offset int, li
|
||||
return postList, nil
|
||||
}
|
||||
|
||||
func (a *App) GetPermalinkPost(c *request.Context, postID string, userID string) (*model.PostList, *model.AppError) {
|
||||
func (a *App) GetPermalinkPost(c request.CTX, postID string, userID string) (*model.PostList, *model.AppError) {
|
||||
list, nErr := a.Srv().Store.Post().Get(context.Background(), postID, model.GetPostsOptions{}, userID, a.Config().GetSanitizeOptions())
|
||||
if nErr != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
@@ -966,7 +966,7 @@ func (a *App) GetPermalinkPost(c *request.Context, postID string, userID string)
|
||||
}
|
||||
post := list.Posts[list.Order[0]]
|
||||
|
||||
channel, err := a.GetChannel(post.ChannelId)
|
||||
channel, err := a.GetChannel(c, post.ChannelId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1174,10 +1174,10 @@ func (a *App) AddCursorIdsForPostList(originalList *model.PostList, afterPost, b
|
||||
originalList.NextPostId = nextPostId
|
||||
originalList.PrevPostId = prevPostId
|
||||
}
|
||||
func (a *App) GetPostsForChannelAroundLastUnread(channelID, userID string, limitBefore, limitAfter int, skipFetchThreads bool, collapsedThreads, collapsedThreadsExtended bool) (*model.PostList, *model.AppError) {
|
||||
func (a *App) GetPostsForChannelAroundLastUnread(c request.CTX, channelID, userID string, limitBefore, limitAfter int, skipFetchThreads bool, collapsedThreads, collapsedThreadsExtended bool) (*model.PostList, *model.AppError) {
|
||||
var member *model.ChannelMember
|
||||
var err *model.AppError
|
||||
if member, err = a.GetChannelMember(context.Background(), channelID, userID); err != nil {
|
||||
if member, err = a.GetChannelMember(c, channelID, userID); err != nil {
|
||||
return nil, err
|
||||
} else if member.LastViewedAt == 0 {
|
||||
return model.NewPostList(), nil
|
||||
@@ -1219,13 +1219,13 @@ func (a *App) GetPostsForChannelAroundLastUnread(channelID, userID string, limit
|
||||
return postList, nil
|
||||
}
|
||||
|
||||
func (a *App) DeletePost(postID, deleteByID string) (*model.Post, *model.AppError) {
|
||||
func (a *App) DeletePost(c request.CTX, postID, deleteByID string) (*model.Post, *model.AppError) {
|
||||
post, nErr := a.Srv().Store.Post().GetSingle(postID, false)
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("DeletePost", "app.post.get.app_error", nil, nErr.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
channel, err := a.GetChannel(post.ChannelId)
|
||||
channel, err := a.GetChannel(c, post.ChannelId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1299,7 +1299,7 @@ func (a *App) parseAndFetchChannelIdByNameFromInFilter(c *request.Context, chann
|
||||
userIDs = append(userIDs, user.Id)
|
||||
}
|
||||
|
||||
channel, err := a.GetGroupChannel(userIDs)
|
||||
channel, err := a.GetGroupChannel(c, userIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1318,7 +1318,7 @@ func (a *App) parseAndFetchChannelIdByNameFromInFilter(c *request.Context, chann
|
||||
return channel, nil
|
||||
}
|
||||
|
||||
channel, err := a.GetChannelByName(channelName, teamID, includeDeleted)
|
||||
channel, err := a.GetChannelByName(c, channelName, teamID, includeDeleted)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1642,8 +1642,8 @@ func (a *App) MaxPostSize() int {
|
||||
}
|
||||
|
||||
// countThreadMentions returns the number of times the user is mentioned in a specified thread after the timestamp.
|
||||
func (a *App) countThreadMentions(user *model.User, post *model.Post, teamID string, timestamp int64) (int64, *model.AppError) {
|
||||
channel, err := a.GetChannel(post.ChannelId)
|
||||
func (a *App) countThreadMentions(c request.CTX, user *model.User, post *model.Post, teamID string, timestamp int64) (int64, *model.AppError) {
|
||||
channel, err := a.GetChannel(c, post.ChannelId)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -1702,8 +1702,8 @@ func (a *App) countThreadMentions(user *model.User, post *model.Post, teamID str
|
||||
|
||||
// countMentionsFromPost returns the number of posts in the post's channel that mention the user after and including the
|
||||
// given post.
|
||||
func (a *App) countMentionsFromPost(user *model.User, post *model.Post) (int, int, *model.AppError) {
|
||||
channel, err := a.GetChannel(post.ChannelId)
|
||||
func (a *App) countMentionsFromPost(c request.CTX, user *model.User, post *model.Post) (int, int, *model.AppError) {
|
||||
channel, err := a.GetChannel(c, post.ChannelId)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
@@ -1718,7 +1718,7 @@ func (a *App) countMentionsFromPost(user *model.User, post *model.Post) (int, in
|
||||
return count, countRoot, nil
|
||||
}
|
||||
|
||||
channelMember, err := a.GetChannelMember(context.Background(), channel.Id, user.Id)
|
||||
channelMember, err := a.GetChannelMember(c, channel.Id, user.Id)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
@@ -1850,18 +1850,18 @@ func (a *App) GetThreadMembershipsForUser(userID, teamID string) ([]*model.Threa
|
||||
return a.Srv().Store.Thread().GetMembershipsForUser(userID, teamID)
|
||||
}
|
||||
|
||||
func (a *App) GetPostIfAuthorized(postID string, session *model.Session, includeDeleted bool) (*model.Post, *model.AppError) {
|
||||
func (a *App) GetPostIfAuthorized(c request.CTX, postID string, session *model.Session, includeDeleted bool) (*model.Post, *model.AppError) {
|
||||
post, err := a.GetSinglePost(postID, includeDeleted)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
channel, err := a.GetChannel(post.ChannelId)
|
||||
channel, err := a.GetChannel(c, post.ChannelId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !a.SessionHasPermissionToChannel(*session, channel.Id, model.PermissionReadChannel) {
|
||||
if !a.SessionHasPermissionToChannel(c, *session, channel.Id, model.PermissionReadChannel) {
|
||||
if channel.Type == model.ChannelTypeOpen {
|
||||
if !a.SessionHasPermissionToTeam(*session, channel.TeamId, model.PermissionReadPublicChannel) {
|
||||
return nil, a.MakePermissionError(session, []*model.Permission{model.PermissionReadPublicChannel})
|
||||
@@ -1895,7 +1895,7 @@ func (a *App) GetPostsByIds(postIDs []string) ([]*model.Post, bool, *model.AppEr
|
||||
return posts, hasInaccessiblePosts, nil
|
||||
}
|
||||
|
||||
func (a *App) GetTopThreadsForTeamSince(teamID, userID string, opts *model.InsightsOpts) (*model.TopThreadList, *model.AppError) {
|
||||
func (a *App) GetTopThreadsForTeamSince(c request.CTX, teamID, userID string, opts *model.InsightsOpts) (*model.TopThreadList, *model.AppError) {
|
||||
if !a.Config().FeatureFlags.InsightsEnabled {
|
||||
return nil, model.NewAppError("GetTopChannelsForTeamSince", "app.insights.feature_disabled", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
@@ -1904,14 +1904,14 @@ func (a *App) GetTopThreadsForTeamSince(teamID, userID string, opts *model.Insig
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetTopChannelsForTeamSince", "app.post.get_top_threads_for_team_since.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
topThreadsWithEmbedAndImage, err := includeEmbedsAndImages(a, topThreads, userID)
|
||||
topThreadsWithEmbedAndImage, err := includeEmbedsAndImages(a, c, topThreads, userID)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetTopChannelsForTeamSince", "app.post.get_top_threads_for_team_since.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return topThreadsWithEmbedAndImage, nil
|
||||
}
|
||||
|
||||
func (a *App) GetTopThreadsForUserSince(teamID, userID string, opts *model.InsightsOpts) (*model.TopThreadList, *model.AppError) {
|
||||
func (a *App) GetTopThreadsForUserSince(c request.CTX, teamID, userID string, opts *model.InsightsOpts) (*model.TopThreadList, *model.AppError) {
|
||||
if !a.Config().FeatureFlags.InsightsEnabled {
|
||||
return nil, model.NewAppError("GetTopChannelsForTeamSince", "app.insights.feature_disabled", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
@@ -1920,17 +1920,17 @@ func (a *App) GetTopThreadsForUserSince(teamID, userID string, opts *model.Insig
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetTopChannelsForTeamSince", "app.post.get_top_threads_for_team_since.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
topThreadsWithEmbedAndImage, err := includeEmbedsAndImages(a, topThreads, userID)
|
||||
topThreadsWithEmbedAndImage, err := includeEmbedsAndImages(a, c, topThreads, userID)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetTopChannelsForUserSince", "app.post.get_top_threads_for_user_since.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return topThreadsWithEmbedAndImage, nil
|
||||
}
|
||||
|
||||
func includeEmbedsAndImages(a *App, topThreadList *model.TopThreadList, userID string) (*model.TopThreadList, error) {
|
||||
func includeEmbedsAndImages(a *App, c request.CTX, topThreadList *model.TopThreadList, userID string) (*model.TopThreadList, error) {
|
||||
for _, topThread := range topThreadList.Items {
|
||||
topThread.Post = a.PreparePostForClientWithEmbedsAndImages(topThread.Post, false, false)
|
||||
sanitizedPost, err := a.SanitizePostMetadataForUser(topThread.Post, userID)
|
||||
topThread.Post = a.PreparePostForClientWithEmbedsAndImages(c, topThread.Post, false, false)
|
||||
sanitizedPost, err := a.SanitizePostMetadataForUser(c, topThread.Post, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+22
-21
@@ -18,6 +18,7 @@ import (
|
||||
|
||||
"github.com/dyatlov/go-opengraph/opengraph"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app/request"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/services/cache"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/markdown"
|
||||
@@ -51,7 +52,7 @@ func (s *Server) initPostMetadata() {
|
||||
})
|
||||
}
|
||||
|
||||
func (a *App) PreparePostListForClient(originalList *model.PostList) *model.PostList {
|
||||
func (a *App) PreparePostListForClient(c request.CTX, originalList *model.PostList) *model.PostList {
|
||||
list := &model.PostList{
|
||||
Posts: make(map[string]*model.Post, len(originalList.Posts)),
|
||||
Order: originalList.Order,
|
||||
@@ -62,7 +63,7 @@ func (a *App) PreparePostListForClient(originalList *model.PostList) *model.Post
|
||||
}
|
||||
|
||||
for id, originalPost := range originalList.Posts {
|
||||
post := a.PreparePostForClientWithEmbedsAndImages(originalPost, false, false)
|
||||
post := a.PreparePostForClientWithEmbedsAndImages(c, originalPost, false, false)
|
||||
|
||||
list.Posts[id] = post
|
||||
}
|
||||
@@ -132,13 +133,13 @@ func (a *App) PreparePostForClient(originalPost *model.Post, isNewPost, isEditPo
|
||||
return post
|
||||
}
|
||||
|
||||
func (a *App) PreparePostForClientWithEmbedsAndImages(originalPost *model.Post, isNewPost, isEditPost bool) *model.Post {
|
||||
func (a *App) PreparePostForClientWithEmbedsAndImages(c request.CTX, originalPost *model.Post, isNewPost, isEditPost bool) *model.Post {
|
||||
post := a.PreparePostForClient(originalPost, isNewPost, isEditPost)
|
||||
post = a.getEmbedsAndImages(post, isNewPost)
|
||||
post = a.getEmbedsAndImages(c, post, isNewPost)
|
||||
return post
|
||||
}
|
||||
|
||||
func (a *App) getEmbedsAndImages(post *model.Post, isNewPost bool) *model.Post {
|
||||
func (a *App) getEmbedsAndImages(c request.CTX, post *model.Post, isNewPost bool) *model.Post {
|
||||
if post.Metadata == nil {
|
||||
post.Metadata = &model.PostMetadata{}
|
||||
}
|
||||
@@ -150,7 +151,7 @@ func (a *App) getEmbedsAndImages(post *model.Post, isNewPost bool) *model.Post {
|
||||
post.Metadata.Embeds = []*model.PostEmbed{}
|
||||
}
|
||||
|
||||
if embed, err := a.getEmbedForPost(post, firstLink, isNewPost); err != nil {
|
||||
if embed, err := a.getEmbedForPost(c, post, firstLink, isNewPost); err != nil {
|
||||
appErr, ok := err.(*model.AppError)
|
||||
isNotFound := ok && appErr.StatusCode == http.StatusNotFound
|
||||
// Ignore NotFound errors.
|
||||
@@ -160,23 +161,23 @@ func (a *App) getEmbedsAndImages(post *model.Post, isNewPost bool) *model.Post {
|
||||
} else if embed != nil {
|
||||
post.Metadata.Embeds = append(post.Metadata.Embeds, embed)
|
||||
}
|
||||
post.Metadata.Images = a.getImagesForPost(post, images, isNewPost)
|
||||
post.Metadata.Images = a.getImagesForPost(c, post, images, isNewPost)
|
||||
return post
|
||||
}
|
||||
|
||||
func (a *App) sanitizePostMetadataForUserAndChannel(post *model.Post, previewedPost *model.PreviewPost, previewedChannel *model.Channel, userID string) *model.Post {
|
||||
func (a *App) sanitizePostMetadataForUserAndChannel(c request.CTX, post *model.Post, previewedPost *model.PreviewPost, previewedChannel *model.Channel, userID string) *model.Post {
|
||||
if post.Metadata == nil || len(post.Metadata.Embeds) == 0 || previewedPost == nil {
|
||||
return post
|
||||
}
|
||||
|
||||
if previewedChannel != nil && !a.HasPermissionToReadChannel(userID, previewedChannel) {
|
||||
if previewedChannel != nil && !a.HasPermissionToReadChannel(c, userID, previewedChannel) {
|
||||
post.Metadata.Embeds[0].Data = nil
|
||||
}
|
||||
|
||||
return post
|
||||
}
|
||||
|
||||
func (a *App) SanitizePostMetadataForUser(post *model.Post, userID string) (*model.Post, *model.AppError) {
|
||||
func (a *App) SanitizePostMetadataForUser(c request.CTX, post *model.Post, userID string) (*model.Post, *model.AppError) {
|
||||
if post.Metadata == nil || len(post.Metadata.Embeds) == 0 {
|
||||
return post, nil
|
||||
}
|
||||
@@ -186,22 +187,22 @@ func (a *App) SanitizePostMetadataForUser(post *model.Post, userID string) (*mod
|
||||
return post, nil
|
||||
}
|
||||
|
||||
previewedChannel, err := a.GetChannel(previewPost.Post.ChannelId)
|
||||
previewedChannel, err := a.GetChannel(c, previewPost.Post.ChannelId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if previewedChannel != nil && !a.HasPermissionToReadChannel(userID, previewedChannel) {
|
||||
if previewedChannel != nil && !a.HasPermissionToReadChannel(c, userID, previewedChannel) {
|
||||
post.Metadata.Embeds[0].Data = nil
|
||||
}
|
||||
|
||||
return post, nil
|
||||
}
|
||||
|
||||
func (a *App) SanitizePostListMetadataForUser(postList *model.PostList, userID string) (*model.PostList, *model.AppError) {
|
||||
func (a *App) SanitizePostListMetadataForUser(c request.CTX, postList *model.PostList, userID string) (*model.PostList, *model.AppError) {
|
||||
clonedPostList := postList.Clone()
|
||||
for postID, post := range clonedPostList.Posts {
|
||||
sanitizedPost, err := a.SanitizePostMetadataForUser(post, userID)
|
||||
sanitizedPost, err := a.SanitizePostMetadataForUser(c, post, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -236,7 +237,7 @@ func (a *App) getEmojisAndReactionsForPost(post *model.Post) ([]*model.Emoji, []
|
||||
return emojis, reactions, nil
|
||||
}
|
||||
|
||||
func (a *App) getEmbedForPost(post *model.Post, firstLink string, isNewPost bool) (*model.PostEmbed, error) {
|
||||
func (a *App) getEmbedForPost(c request.CTX, post *model.Post, firstLink string, isNewPost bool) (*model.PostEmbed, error) {
|
||||
if _, ok := post.GetProps()["attachments"]; ok {
|
||||
return &model.PostEmbed{
|
||||
Type: model.PostEmbedMessageAttachment,
|
||||
@@ -259,7 +260,7 @@ func (a *App) getEmbedForPost(post *model.Post, firstLink string, isNewPost bool
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
og, image, permalink, err := a.getLinkMetadata(firstLink, post.CreateAt, isNewPost, post.GetPreviewedPostProp())
|
||||
og, image, permalink, err := a.getLinkMetadata(c, firstLink, post.CreateAt, isNewPost, post.GetPreviewedPostProp())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -294,7 +295,7 @@ func (a *App) getEmbedForPost(post *model.Post, firstLink string, isNewPost bool
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *App) getImagesForPost(post *model.Post, imageURLs []string, isNewPost bool) map[string]*model.PostImage {
|
||||
func (a *App) getImagesForPost(c request.CTX, post *model.Post, imageURLs []string, isNewPost bool) map[string]*model.PostImage {
|
||||
images := map[string]*model.PostImage{}
|
||||
|
||||
for _, embed := range post.Metadata.Embeds {
|
||||
@@ -336,7 +337,7 @@ func (a *App) getImagesForPost(post *model.Post, imageURLs []string, isNewPost b
|
||||
}
|
||||
|
||||
for _, imageURL := range imageURLs {
|
||||
if _, image, _, err := a.getLinkMetadata(imageURL, post.CreateAt, isNewPost, post.GetPreviewedPostProp()); err != nil {
|
||||
if _, image, _, err := a.getLinkMetadata(c, imageURL, post.CreateAt, isNewPost, post.GetPreviewedPostProp()); err != nil {
|
||||
appErr, ok := err.(*model.AppError)
|
||||
isNotFound := ok && appErr.StatusCode == http.StatusNotFound
|
||||
// Ignore NotFound errors.
|
||||
@@ -513,7 +514,7 @@ func (a *App) containsPermalink(post *model.Post) bool {
|
||||
return looksLikeAPermalink(link, a.GetSiteURL())
|
||||
}
|
||||
|
||||
func (a *App) getLinkMetadata(requestURL string, timestamp int64, isNewPost bool, previewedPostPropVal string) (*opengraph.OpenGraph, *model.PostImage, *model.Permalink, error) {
|
||||
func (a *App) getLinkMetadata(c request.CTX, requestURL string, timestamp int64, isNewPost bool, previewedPostPropVal string) (*opengraph.OpenGraph, *model.PostImage, *model.Permalink, error) {
|
||||
requestURL = resolveMetadataURL(requestURL, a.GetSiteURL())
|
||||
|
||||
timestamp = model.FloorToNearestHour(timestamp)
|
||||
@@ -547,7 +548,7 @@ func (a *App) getLinkMetadata(requestURL string, timestamp int64, isNewPost bool
|
||||
return nil, nil, nil, appErr
|
||||
}
|
||||
|
||||
referencedChannel, appErr := a.GetChannel(referencedPost.ChannelId)
|
||||
referencedChannel, appErr := a.GetChannel(c, referencedPost.ChannelId)
|
||||
if appErr != nil {
|
||||
return nil, nil, nil, appErr
|
||||
}
|
||||
@@ -568,7 +569,7 @@ func (a *App) getLinkMetadata(requestURL string, timestamp int64, isNewPost bool
|
||||
permalink = &model.Permalink{PreviewPost: model.NewPreviewPost(referencedPost, referencedTeam, referencedChannel)}
|
||||
} else {
|
||||
// referencedPost does not contain a permalink: we get its metadata
|
||||
referencedPostWithMetadata := a.PreparePostForClientWithEmbedsAndImages(referencedPost, false, false)
|
||||
referencedPostWithMetadata := a.PreparePostForClientWithEmbedsAndImages(c, referencedPost, false, false)
|
||||
permalink = &model.Permalink{PreviewPost: model.NewPreviewPost(referencedPostWithMetadata, referencedTeam, referencedChannel)}
|
||||
}
|
||||
} else {
|
||||
|
||||
+52
-52
@@ -39,7 +39,7 @@ func TestPreparePostListForClient(t *testing.T) {
|
||||
postList.AddPost(&model.Post{})
|
||||
}
|
||||
|
||||
clientPostList := th.App.PreparePostListForClient(postList)
|
||||
clientPostList := th.App.PreparePostListForClient(th.Context, postList)
|
||||
|
||||
t.Run("doesn't mutate provided post list", func(t *testing.T) {
|
||||
assert.NotEqual(t, clientPostList, postList, "should've returned a new post list")
|
||||
@@ -422,7 +422,7 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
}, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
post.Metadata.Embeds = nil
|
||||
clientPost := th.App.PreparePostForClientWithEmbedsAndImages(post, false, false)
|
||||
clientPost := th.App.PreparePostForClientWithEmbedsAndImages(th.Context, post, false, false)
|
||||
|
||||
// Reminder that only the first link gets an embed and dimensions
|
||||
|
||||
@@ -500,7 +500,7 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
}, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
post.Metadata.Embeds = nil
|
||||
clientPost := th.App.PreparePostForClientWithEmbedsAndImages(post, false, false)
|
||||
clientPost := th.App.PreparePostForClientWithEmbedsAndImages(th.Context, post, false, false)
|
||||
|
||||
t.Run("populates embeds", func(t *testing.T) {
|
||||
assert.ElementsMatch(t, []*model.PostEmbed{
|
||||
@@ -539,7 +539,7 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
|
||||
th.AddReactionToPost(post, th.BasicUser, "taco")
|
||||
|
||||
post, err = th.App.DeletePost(post.Id, th.BasicUser.Id)
|
||||
post, err = th.App.DeletePost(th.Context, post.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
// DeleteAt isn't set on the post returned by App.DeletePost
|
||||
@@ -580,7 +580,7 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
}, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
previewPost.Metadata.Embeds = nil
|
||||
clientPost := th.App.PreparePostForClientWithEmbedsAndImages(previewPost, false, false)
|
||||
clientPost := th.App.PreparePostForClientWithEmbedsAndImages(th.Context, previewPost, false, false)
|
||||
firstEmbed := clientPost.Metadata.Embeds[0]
|
||||
preview := firstEmbed.Data.(*model.PreviewPost)
|
||||
require.Equal(t, referencedPost.Id, preview.PostID)
|
||||
@@ -596,10 +596,10 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
|
||||
th.Context.Session().UserId = th.BasicUser.Id
|
||||
|
||||
directChannel, err := th.App.createDirectChannel(th.BasicUser.Id, th.BasicUser2.Id)
|
||||
directChannel, err := th.App.createDirectChannel(th.Context, th.BasicUser.Id, th.BasicUser2.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
groupChannel, err := th.App.createGroupChannel([]string{th.BasicUser.Id, th.BasicUser2.Id, th.CreateUser().Id})
|
||||
groupChannel, err := th.App.createGroupChannel(th.Context, []string{th.BasicUser.Id, th.BasicUser2.Id, th.CreateUser().Id})
|
||||
require.Nil(t, err)
|
||||
|
||||
testCases := []struct {
|
||||
@@ -639,7 +639,7 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
previewPost.Metadata.Embeds = nil
|
||||
|
||||
clientPost := th.App.PreparePostForClientWithEmbedsAndImages(previewPost, false, false)
|
||||
clientPost := th.App.PreparePostForClientWithEmbedsAndImages(th.Context, previewPost, false, false)
|
||||
firstEmbed := clientPost.Metadata.Embeds[0]
|
||||
preview := firstEmbed.Data.(*model.PreviewPost)
|
||||
|
||||
@@ -677,7 +677,7 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
previewPost.Metadata.Embeds = nil
|
||||
|
||||
clientPost := th.App.PreparePostForClientWithEmbedsAndImages(previewPost, false, false)
|
||||
clientPost := th.App.PreparePostForClientWithEmbedsAndImages(th.Context, previewPost, false, false)
|
||||
firstEmbed := clientPost.Metadata.Embeds[0]
|
||||
preview := firstEmbed.Data.(*model.PreviewPost)
|
||||
referencedPostFirstEmbed := preview.Post.Metadata.Embeds[0]
|
||||
@@ -724,7 +724,7 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
previewPost.Metadata.Embeds = nil
|
||||
|
||||
clientPost := th.App.PreparePostForClientWithEmbedsAndImages(previewPost, false, false)
|
||||
clientPost := th.App.PreparePostForClientWithEmbedsAndImages(th.Context, previewPost, false, false)
|
||||
firstEmbed := clientPost.Metadata.Embeds[0]
|
||||
preview := firstEmbed.Data.(*model.PreviewPost)
|
||||
referencedPostMetadata := preview.Post.Metadata
|
||||
@@ -874,7 +874,7 @@ func testProxyOpenGraphImage(t *testing.T, th *TestHelper, shouldProxy bool) {
|
||||
require.Nil(t, err)
|
||||
|
||||
post.Metadata.Embeds = nil
|
||||
embeds := th.App.PreparePostForClientWithEmbedsAndImages(post, false, false).Metadata.Embeds
|
||||
embeds := th.App.PreparePostForClientWithEmbedsAndImages(th.Context, post, false, false).Metadata.Embeds
|
||||
require.Len(t, embeds, 1, "should have one embed")
|
||||
|
||||
embed := embeds[0]
|
||||
@@ -953,7 +953,7 @@ func TestGetEmbedForPost(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("should return a message attachment when the post has one", func(t *testing.T) {
|
||||
embed, err := th.App.getEmbedForPost(&model.Post{
|
||||
embed, err := th.App.getEmbedForPost(th.Context, &model.Post{
|
||||
Props: model.StringInterface{
|
||||
"attachments": []*model.SlackAttachment{
|
||||
{
|
||||
@@ -970,7 +970,7 @@ func TestGetEmbedForPost(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("should return an image embed when the first link is an image", func(t *testing.T) {
|
||||
embed, err := th.App.getEmbedForPost(&model.Post{}, imageURL, false)
|
||||
embed, err := th.App.getEmbedForPost(th.Context, &model.Post{}, imageURL, false)
|
||||
|
||||
assert.Equal(t, &model.PostEmbed{
|
||||
Type: model.PostEmbedImage,
|
||||
@@ -980,7 +980,7 @@ func TestGetEmbedForPost(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("should return an opengraph embed", func(t *testing.T) {
|
||||
embed, err := th.App.getEmbedForPost(&model.Post{}, ogURL, false)
|
||||
embed, err := th.App.getEmbedForPost(th.Context, &model.Post{}, ogURL, false)
|
||||
|
||||
assert.Equal(t, &model.PostEmbed{
|
||||
Type: model.PostEmbedOpengraph,
|
||||
@@ -997,7 +997,7 @@ func TestGetEmbedForPost(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.LocalizationSettings.DefaultServerLocale = "fr"
|
||||
})
|
||||
embed, err := th.App.getEmbedForPost(&model.Post{}, ogURL, false)
|
||||
embed, err := th.App.getEmbedForPost(th.Context, &model.Post{}, ogURL, false)
|
||||
|
||||
assert.Equal(t, &model.PostEmbed{
|
||||
Type: model.PostEmbedOpengraph,
|
||||
@@ -1011,7 +1011,7 @@ func TestGetEmbedForPost(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("should return a link embed", func(t *testing.T) {
|
||||
embed, err := th.App.getEmbedForPost(&model.Post{}, otherURL, false)
|
||||
embed, err := th.App.getEmbedForPost(th.Context, &model.Post{}, otherURL, false)
|
||||
|
||||
assert.Equal(t, &model.PostEmbed{
|
||||
Type: model.PostEmbedLink,
|
||||
@@ -1031,7 +1031,7 @@ func TestGetEmbedForPost(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("should return an embedded message attachment", func(t *testing.T) {
|
||||
embed, err := th.App.getEmbedForPost(&model.Post{
|
||||
embed, err := th.App.getEmbedForPost(th.Context, &model.Post{
|
||||
Props: model.StringInterface{
|
||||
"attachments": []*model.SlackAttachment{
|
||||
{
|
||||
@@ -1048,21 +1048,21 @@ func TestGetEmbedForPost(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("should not return an opengraph embed", func(t *testing.T) {
|
||||
embed, err := th.App.getEmbedForPost(&model.Post{}, ogURL, false)
|
||||
embed, err := th.App.getEmbedForPost(th.Context, &model.Post{}, ogURL, false)
|
||||
|
||||
assert.Nil(t, embed)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("should not return an image embed", func(t *testing.T) {
|
||||
embed, err := th.App.getEmbedForPost(&model.Post{}, imageURL, false)
|
||||
embed, err := th.App.getEmbedForPost(th.Context, &model.Post{}, imageURL, false)
|
||||
|
||||
assert.Nil(t, embed)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("should not return a link embed", func(t *testing.T) {
|
||||
embed, err := th.App.getEmbedForPost(&model.Post{}, otherURL, false)
|
||||
embed, err := th.App.getEmbedForPost(th.Context, &model.Post{}, otherURL, false)
|
||||
|
||||
assert.Nil(t, embed)
|
||||
assert.NoError(t, err)
|
||||
@@ -1092,7 +1092,7 @@ func TestGetImagesForPost(t *testing.T) {
|
||||
}
|
||||
imageURL := server.URL + "/image.png"
|
||||
|
||||
images := th.App.getImagesForPost(post, []string{imageURL}, false)
|
||||
images := th.App.getImagesForPost(th.Context, post, []string{imageURL}, false)
|
||||
|
||||
assert.Equal(t, images, map[string]*model.PostImage{
|
||||
imageURL: {
|
||||
@@ -1120,7 +1120,7 @@ func TestGetImagesForPost(t *testing.T) {
|
||||
}
|
||||
imageURL := server.URL + "/bad_image.png"
|
||||
|
||||
images := th.App.getImagesForPost(post, []string{imageURL}, false)
|
||||
images := th.App.getImagesForPost(th.Context, post, []string{imageURL}, false)
|
||||
|
||||
assert.Equal(t, images, map[string]*model.PostImage{})
|
||||
})
|
||||
@@ -1168,7 +1168,7 @@ func TestGetImagesForPost(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
images := th.App.getImagesForPost(post, []string{}, false)
|
||||
images := th.App.getImagesForPost(th.Context, post, []string{}, false)
|
||||
|
||||
assert.Equal(t, images, map[string]*model.PostImage{
|
||||
imageURL: {
|
||||
@@ -1222,7 +1222,7 @@ func TestGetImagesForPost(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
images := th.App.getImagesForPost(post, []string{}, false)
|
||||
images := th.App.getImagesForPost(th.Context, post, []string{}, false)
|
||||
|
||||
assert.Equal(t, images, map[string]*model.PostImage{
|
||||
imageURL: {
|
||||
@@ -1276,7 +1276,7 @@ func TestGetImagesForPost(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
images := th.App.getImagesForPost(post, []string{}, false)
|
||||
images := th.App.getImagesForPost(th.Context, post, []string{}, false)
|
||||
|
||||
assert.Equal(t, images, map[string]*model.PostImage{
|
||||
imageURL: {
|
||||
@@ -1306,7 +1306,7 @@ func TestGetImagesForPost(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
images := th.App.getImagesForPost(post, []string{}, false)
|
||||
images := th.App.getImagesForPost(th.Context, post, []string{}, false)
|
||||
assert.Equal(t, images, map[string]*model.PostImage{})
|
||||
})
|
||||
}
|
||||
@@ -1980,7 +1980,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
_, _, ok = th.App.getLinkMetadataFromDatabase(requestURL, timestamp)
|
||||
require.False(t, ok, "data should not exist in database")
|
||||
|
||||
og, img, _, err := th.App.getLinkMetadata(requestURL, timestamp, false, "")
|
||||
og, img, _, err := th.App.getLinkMetadata(th.Context, requestURL, timestamp, false, "")
|
||||
|
||||
require.NotNil(t, og)
|
||||
assert.Nil(t, img)
|
||||
@@ -1995,7 +1995,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
_, _, ok = th.App.getLinkMetadataFromDatabase(requestURL, timestamp)
|
||||
require.False(t, ok, "data should not exist in database")
|
||||
|
||||
og, img, _, err := th.App.getLinkMetadata(requestURL, timestamp+60*1000, false, "")
|
||||
og, img, _, err := th.App.getLinkMetadata(th.Context, requestURL, timestamp+60*1000, false, "")
|
||||
|
||||
require.NotNil(t, og)
|
||||
assert.Nil(t, img)
|
||||
@@ -2012,7 +2012,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
_, _, ok = th.App.getLinkMetadataFromDatabase(differentURL, timestamp)
|
||||
require.False(t, ok, "data should not exist in database")
|
||||
|
||||
og, img, _, err := th.App.getLinkMetadata(differentURL, timestamp, false, "")
|
||||
og, img, _, err := th.App.getLinkMetadata(th.Context, differentURL, timestamp, false, "")
|
||||
|
||||
assert.Nil(t, og)
|
||||
assert.Nil(t, img)
|
||||
@@ -2028,7 +2028,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
_, _, ok = th.App.getLinkMetadataFromDatabase(requestURL, differentTimestamp)
|
||||
require.False(t, ok, "data should not exist in database")
|
||||
|
||||
og, img, _, err := th.App.getLinkMetadata(requestURL, differentTimestamp, false, "")
|
||||
og, img, _, err := th.App.getLinkMetadata(th.Context, requestURL, differentTimestamp, false, "")
|
||||
|
||||
assert.Nil(t, og)
|
||||
assert.Nil(t, img)
|
||||
@@ -2055,7 +2055,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
_, _, ok = th.App.getLinkMetadataFromDatabase(requestURL, timestamp)
|
||||
require.True(t, ok, "data should already exist in database")
|
||||
|
||||
og, img, _, err := th.App.getLinkMetadata(requestURL, timestamp, false, "")
|
||||
og, img, _, err := th.App.getLinkMetadata(th.Context, requestURL, timestamp, false, "")
|
||||
|
||||
require.NotNil(t, og)
|
||||
assert.Nil(t, img)
|
||||
@@ -2072,7 +2072,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
_, _, ok = th.App.getLinkMetadataFromDatabase(requestURL, timestamp)
|
||||
require.True(t, ok, "data should already exist in database")
|
||||
|
||||
og, img, _, err := th.App.getLinkMetadata(requestURL, timestamp+60*1000, false, "")
|
||||
og, img, _, err := th.App.getLinkMetadata(th.Context, requestURL, timestamp+60*1000, false, "")
|
||||
|
||||
require.NotNil(t, og)
|
||||
assert.Nil(t, img)
|
||||
@@ -2091,7 +2091,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
_, _, ok = th.App.getLinkMetadataFromDatabase(differentURL, timestamp)
|
||||
require.False(t, ok, "data should not exist in database")
|
||||
|
||||
og, img, _, err := th.App.getLinkMetadata(differentURL, timestamp, false, "")
|
||||
og, img, _, err := th.App.getLinkMetadata(th.Context, differentURL, timestamp, false, "")
|
||||
|
||||
assert.Nil(t, og)
|
||||
assert.Nil(t, img)
|
||||
@@ -2109,7 +2109,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
_, _, ok = th.App.getLinkMetadataFromDatabase(requestURL, differentTimestamp)
|
||||
require.False(t, ok, "data should not exist in database")
|
||||
|
||||
og, img, _, err := th.App.getLinkMetadata(requestURL, differentTimestamp, false, "")
|
||||
og, img, _, err := th.App.getLinkMetadata(th.Context, requestURL, differentTimestamp, false, "")
|
||||
|
||||
assert.Nil(t, og)
|
||||
assert.Nil(t, img)
|
||||
@@ -2130,7 +2130,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
_, _, ok = th.App.getLinkMetadataFromDatabase(requestURL, timestamp)
|
||||
require.False(t, ok, "data should not exist in database")
|
||||
|
||||
og, img, _, err := th.App.getLinkMetadata(requestURL, timestamp, false, "")
|
||||
og, img, _, err := th.App.getLinkMetadata(th.Context, requestURL, timestamp, false, "")
|
||||
|
||||
assert.NotNil(t, og)
|
||||
assert.Nil(t, img)
|
||||
@@ -2150,7 +2150,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
_, _, ok = th.App.getLinkMetadataFromDatabase(requestURL, timestamp)
|
||||
require.False(t, ok, "data should not exist in database")
|
||||
|
||||
og, img, _, err := th.App.getLinkMetadata(requestURL, timestamp, false, "")
|
||||
og, img, _, err := th.App.getLinkMetadata(th.Context, requestURL, timestamp, false, "")
|
||||
|
||||
assert.NotNil(t, og)
|
||||
assert.Nil(t, img)
|
||||
@@ -2178,7 +2178,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
_, _, ok = th.App.getLinkMetadataFromDatabase(requestURL, timestamp)
|
||||
require.False(t, ok, "data should not exist in database")
|
||||
|
||||
og, img, _, err := th.App.getLinkMetadata(requestURL, timestamp, false, "")
|
||||
og, img, _, err := th.App.getLinkMetadata(th.Context, requestURL, timestamp, false, "")
|
||||
|
||||
assert.Nil(t, og)
|
||||
assert.NotNil(t, img)
|
||||
@@ -2206,7 +2206,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
_, _, ok = th.App.getLinkMetadataFromDatabase(requestURL, timestamp)
|
||||
require.False(t, ok, "data should not exist in database")
|
||||
|
||||
og, img, _, err := th.App.getLinkMetadata(requestURL, timestamp, false, "")
|
||||
og, img, _, err := th.App.getLinkMetadata(th.Context, requestURL, timestamp, false, "")
|
||||
|
||||
assert.Nil(t, og)
|
||||
assert.Nil(t, img)
|
||||
@@ -2236,7 +2236,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
_, _, ok = th.App.getLinkMetadataFromDatabase(requestURL, timestamp)
|
||||
require.False(t, ok, "data should not exist in database")
|
||||
|
||||
og, img, _, err := th.App.getLinkMetadata(requestURL, timestamp, false, "")
|
||||
og, img, _, err := th.App.getLinkMetadata(th.Context, requestURL, timestamp, false, "")
|
||||
|
||||
assert.Nil(t, og)
|
||||
assert.Nil(t, img)
|
||||
@@ -2270,7 +2270,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
_, _, ok = th.App.getLinkMetadataFromDatabase(requestURL, timestamp)
|
||||
require.False(t, ok, "data should not exist in database")
|
||||
|
||||
og, img, _, err := th.App.getLinkMetadata(requestURL, timestamp, false, "")
|
||||
og, img, _, err := th.App.getLinkMetadata(th.Context, requestURL, timestamp, false, "")
|
||||
|
||||
assert.Nil(t, og)
|
||||
assert.Nil(t, img)
|
||||
@@ -2301,7 +2301,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
_, _, ok = th.App.getLinkMetadataFromDatabase(requestURL, timestamp)
|
||||
require.False(t, ok, "data should not exist in database")
|
||||
|
||||
_, img, _, err := th.App.getLinkMetadata(requestURL, timestamp, false, "")
|
||||
_, img, _, err := th.App.getLinkMetadata(th.Context, requestURL, timestamp, false, "")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, _, ok = getLinkMetadataFromCache(requestURL, timestamp)
|
||||
@@ -2323,7 +2323,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
requestURL := server.URL + "/json?name=" + t.Name()
|
||||
timestamp := int64(1547510400000)
|
||||
|
||||
og, img, _, err := th.App.getLinkMetadata(requestURL, timestamp, false, "")
|
||||
og, img, _, err := th.App.getLinkMetadata(th.Context, requestURL, timestamp, false, "")
|
||||
assert.Nil(t, og)
|
||||
assert.Nil(t, img)
|
||||
assert.NoError(t, err)
|
||||
@@ -2338,7 +2338,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
|
||||
cacheLinkMetadata(requestURL, timestamp, &opengraph.OpenGraph{Title: "cached"}, nil, nil)
|
||||
|
||||
og, img, _, err := th.App.getLinkMetadata(requestURL, timestamp, true, "")
|
||||
og, img, _, err := th.App.getLinkMetadata(th.Context, requestURL, timestamp, true, "")
|
||||
assert.NotNil(t, og)
|
||||
assert.Nil(t, img)
|
||||
assert.NoError(t, err)
|
||||
@@ -2353,7 +2353,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
|
||||
th.App.saveLinkMetadataToDatabase(requestURL, timestamp, &opengraph.OpenGraph{Title: "cached"}, nil)
|
||||
|
||||
og, img, _, err := th.App.getLinkMetadata(requestURL, timestamp, true, "")
|
||||
og, img, _, err := th.App.getLinkMetadata(th.Context, requestURL, timestamp, true, "")
|
||||
assert.Nil(t, og)
|
||||
assert.Nil(t, img)
|
||||
assert.NoError(t, err)
|
||||
@@ -2376,7 +2376,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
requestURL := "/image?height=200&width=300&name=" + t.Name()
|
||||
timestamp := int64(1547510400000)
|
||||
|
||||
og, img, _, err := th.App.getLinkMetadata(requestURL, timestamp, false, "")
|
||||
og, img, _, err := th.App.getLinkMetadata(th.Context, requestURL, timestamp, false, "")
|
||||
assert.Nil(t, og)
|
||||
assert.NotNil(t, img)
|
||||
assert.NoError(t, err)
|
||||
@@ -2404,7 +2404,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
requestURL := server.URL + "/image?height=200&width=300&name=" + t.Name()
|
||||
timestamp := int64(1547510400000)
|
||||
|
||||
og, img, _, err := th.App.getLinkMetadata(requestURL, timestamp, false, "")
|
||||
og, img, _, err := th.App.getLinkMetadata(th.Context, requestURL, timestamp, false, "")
|
||||
assert.Nil(t, og)
|
||||
assert.Nil(t, img)
|
||||
assert.Error(t, err)
|
||||
@@ -2414,7 +2414,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
requestURL = th.App.GetSiteURL() + "/api/v4/image?url=" + url.QueryEscape(requestURL)
|
||||
|
||||
// Note that this request still fails while testing because the request made by the image proxy is blocked
|
||||
og, img, _, err = th.App.getLinkMetadata(requestURL, timestamp, false, "")
|
||||
og, img, _, err = th.App.getLinkMetadata(th.Context, requestURL, timestamp, false, "")
|
||||
assert.Nil(t, og)
|
||||
assert.Nil(t, img)
|
||||
assert.Error(t, err)
|
||||
@@ -2428,7 +2428,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
requestURL := server.URL + "/mixed?name=" + t.Name()
|
||||
timestamp := int64(1547510400000)
|
||||
|
||||
og, img, _, err := th.App.getLinkMetadata(requestURL, timestamp, true, "")
|
||||
og, img, _, err := th.App.getLinkMetadata(th.Context, requestURL, timestamp, true, "")
|
||||
assert.Nil(t, og)
|
||||
assert.NotNil(t, img)
|
||||
assert.NoError(t, err)
|
||||
@@ -2447,7 +2447,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
requestURL := server.URL + "/pl/5rpoy4o3nbgwjm7gs4cm71h6ho"
|
||||
timestamp := int64(1547510400000)
|
||||
|
||||
_, _, _, err := th.App.getLinkMetadata(requestURL, timestamp, true, "")
|
||||
_, _, _, err := th.App.getLinkMetadata(th.Context, requestURL, timestamp, true, "")
|
||||
assert.Error(t, err)
|
||||
})
|
||||
}
|
||||
@@ -2699,7 +2699,7 @@ func TestSanitizePostMetadataForUserAndChannel(t *testing.T) {
|
||||
*cfg.ServiceSettings.SiteURL = "http://mymattermost.com"
|
||||
})
|
||||
|
||||
directChannel, err := th.App.createDirectChannel(th.BasicUser.Id, th.BasicUser2.Id)
|
||||
directChannel, err := th.App.createDirectChannel(th.Context, th.BasicUser.Id, th.BasicUser2.Id)
|
||||
assert.Nil(t, err)
|
||||
|
||||
userID := model.NewId()
|
||||
@@ -2724,7 +2724,7 @@ func TestSanitizePostMetadataForUserAndChannel(t *testing.T) {
|
||||
|
||||
previewedPost := model.NewPreviewPost(post, th.BasicTeam, directChannel)
|
||||
|
||||
actual := th.App.sanitizePostMetadataForUserAndChannel(post, previewedPost, directChannel, th.BasicUser2.Id)
|
||||
actual := th.App.sanitizePostMetadataForUserAndChannel(th.Context, post, previewedPost, directChannel, th.BasicUser2.Id)
|
||||
assert.NotNil(t, actual.Metadata.Embeds[0].Data)
|
||||
|
||||
guestID := model.NewId()
|
||||
@@ -2738,6 +2738,6 @@ func TestSanitizePostMetadataForUserAndChannel(t *testing.T) {
|
||||
guest, appErr := th.App.CreateGuest(th.Context, guest)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
actual = th.App.sanitizePostMetadataForUserAndChannel(post, previewedPost, directChannel, guest.Id)
|
||||
actual = th.App.sanitizePostMetadataForUserAndChannel(th.Context, post, previewedPost, directChannel, guest.Id)
|
||||
assert.Nil(t, actual.Metadata.Embeds[0].Data)
|
||||
}
|
||||
|
||||
+81
-81
@@ -319,7 +319,7 @@ func TestUpdatePostInArchivedChannel(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
archivedChannel := th.CreateChannel(th.BasicTeam)
|
||||
archivedChannel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
post := th.CreatePost(archivedChannel)
|
||||
th.App.DeleteChannel(th.Context, archivedChannel, "")
|
||||
|
||||
@@ -339,7 +339,7 @@ func TestPostReplyToPostWhereRootPosterLeftChannel(t *testing.T) {
|
||||
userNotInChannel := th.BasicUser
|
||||
rootPost := th.BasicPost
|
||||
|
||||
_, err := th.App.AddUserToChannel(userInChannel, channel, false)
|
||||
_, err := th.App.AddUserToChannel(th.Context, userInChannel, channel, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
err = th.App.RemoveUserFromChannel(th.Context, userNotInChannel.Id, "", channel)
|
||||
@@ -416,9 +416,9 @@ func TestPostChannelMentions(t *testing.T) {
|
||||
TeamId: th.BasicTeam.Id,
|
||||
}, false)
|
||||
require.Nil(t, err)
|
||||
defer th.App.PermanentDeleteChannel(channelToMention)
|
||||
defer th.App.PermanentDeleteChannel(th.Context, channelToMention)
|
||||
|
||||
_, err = th.App.AddUserToChannel(user, channel, false)
|
||||
_, err = th.App.AddUserToChannel(th.Context, user, channel, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
post := &model.Post{
|
||||
@@ -649,7 +649,7 @@ func TestDeletePostWithFileAttachments(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
|
||||
// Delete the post.
|
||||
_, err = th.App.DeletePost(post.Id, userID)
|
||||
_, err = th.App.DeletePost(th.Context, post.Id, userID)
|
||||
assert.Nil(t, err)
|
||||
|
||||
// Wait for the cleanup routine to finish.
|
||||
@@ -664,11 +664,11 @@ func TestDeletePostInArchivedChannel(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
archivedChannel := th.CreateChannel(th.BasicTeam)
|
||||
archivedChannel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
post := th.CreatePost(archivedChannel)
|
||||
th.App.DeleteChannel(th.Context, archivedChannel, "")
|
||||
|
||||
_, err := th.App.DeletePost(post.Id, "")
|
||||
_, err := th.App.DeletePost(th.Context, post.Id, "")
|
||||
require.NotNil(t, err)
|
||||
require.Equal(t, "api.post.delete_post.can_not_delete_post_in_deleted.error", err.Id)
|
||||
}
|
||||
@@ -776,7 +776,7 @@ func TestCreatePost(t *testing.T) {
|
||||
|
||||
permalink := fmt.Sprintf("%s/%s/pl/%s", *th.App.Config().ServiceSettings.SiteURL, th.BasicTeam.Name, referencedPost.Id)
|
||||
|
||||
channelForPreview := th.CreateChannel(th.BasicTeam)
|
||||
channelForPreview := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
previewPost := &model.Post{
|
||||
ChannelId: channelForPreview.Id,
|
||||
Message: permalink,
|
||||
@@ -793,7 +793,7 @@ func TestCreatePost(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
channelForPreview := th.CreateChannel(th.BasicTeam)
|
||||
channelForPreview := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
|
||||
referencedPost := &model.Post{
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
@@ -840,7 +840,7 @@ func TestCreatePost(t *testing.T) {
|
||||
|
||||
user1 := th.CreateUser()
|
||||
user2 := th.CreateUser()
|
||||
directChannel, err := th.App.createDirectChannel(user1.Id, user2.Id)
|
||||
directChannel, err := th.App.createDirectChannel(th.Context, user1.Id, user2.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
referencedPost := &model.Post{
|
||||
@@ -896,7 +896,7 @@ func TestCreatePost(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
channelForPreview := th.CreateChannel(th.BasicTeam)
|
||||
channelForPreview := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
|
||||
for i := 0; i < 20; i++ {
|
||||
user := th.CreateUser()
|
||||
@@ -1230,7 +1230,7 @@ func TestPatchPostInArchivedChannel(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
archivedChannel := th.CreateChannel(th.BasicTeam)
|
||||
archivedChannel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
post := th.CreatePost(archivedChannel)
|
||||
th.App.DeleteChannel(th.Context, archivedChannel, "")
|
||||
|
||||
@@ -1297,7 +1297,7 @@ func TestUpdatePost(t *testing.T) {
|
||||
|
||||
permalink := fmt.Sprintf("%s/%s/pl/%s", *th.App.Config().ServiceSettings.SiteURL, th.BasicTeam.Name, referencedPost.Id)
|
||||
|
||||
channelForTestPost := th.CreateChannel(th.BasicTeam)
|
||||
channelForTestPost := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
testPost := &model.Post{
|
||||
ChannelId: channelForTestPost.Id,
|
||||
Message: "hello world",
|
||||
@@ -1327,7 +1327,7 @@ func TestUpdatePost(t *testing.T) {
|
||||
|
||||
user1 := th.CreateUser()
|
||||
user2 := th.CreateUser()
|
||||
directChannel, err := th.App.createDirectChannel(user1.Id, user2.Id)
|
||||
directChannel, err := th.App.createDirectChannel(th.Context, user1.Id, user2.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
referencedPost := &model.Post{
|
||||
@@ -1573,7 +1573,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
user1 := th.BasicUser
|
||||
user2 := th.BasicUser2
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
@@ -1595,7 +1595,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
count, _, err := th.App.countMentionsFromPost(user2, post1)
|
||||
count, _, err := th.App.countMentionsFromPost(th.Context, user2, post1)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 0, count)
|
||||
@@ -1608,7 +1608,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
user1 := th.BasicUser
|
||||
user2 := th.BasicUser2
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
user2.NotifyProps[model.MentionKeysNotifyProp] = "apple"
|
||||
@@ -1634,7 +1634,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
|
||||
// post1 and post3 should mention the user
|
||||
|
||||
count, _, err := th.App.countMentionsFromPost(user2, post1)
|
||||
count, _, err := th.App.countMentionsFromPost(th.Context, user2, post1)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 2, count)
|
||||
@@ -1647,7 +1647,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
user1 := th.BasicUser
|
||||
user2 := th.BasicUser2
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
user2.NotifyProps[model.ChannelMentionsNotifyProp] = "true"
|
||||
@@ -1673,7 +1673,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
|
||||
// post2 and post3 should mention the user
|
||||
|
||||
count, _, err := th.App.countMentionsFromPost(user2, post1)
|
||||
count, _, err := th.App.countMentionsFromPost(th.Context, user2, post1)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 2, count)
|
||||
@@ -1686,7 +1686,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
user1 := th.BasicUser
|
||||
user2 := th.BasicUser2
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
user2.NotifyProps[model.ChannelMentionsNotifyProp] = "false"
|
||||
@@ -1710,7 +1710,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
count, _, err := th.App.countMentionsFromPost(user2, post1)
|
||||
count, _, err := th.App.countMentionsFromPost(th.Context, user2, post1)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 0, count)
|
||||
@@ -1723,12 +1723,12 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
user1 := th.BasicUser
|
||||
user2 := th.BasicUser2
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
user2.NotifyProps[model.ChannelMentionsNotifyProp] = "true"
|
||||
|
||||
_, err := th.App.UpdateChannelMemberNotifyProps(map[string]string{
|
||||
_, err := th.App.UpdateChannelMemberNotifyProps(th.Context, map[string]string{
|
||||
model.IgnoreChannelMentionsNotifyProp: model.IgnoreChannelMentionsOn,
|
||||
}, channel.Id, user2.Id)
|
||||
require.Nil(t, err)
|
||||
@@ -1752,7 +1752,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
count, _, err := th.App.countMentionsFromPost(user2, post1)
|
||||
count, _, err := th.App.countMentionsFromPost(th.Context, user2, post1)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 0, count)
|
||||
@@ -1765,7 +1765,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
user1 := th.BasicUser
|
||||
user2 := th.BasicUser2
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
user2.NotifyProps[model.CommentsNotifyProp] = model.CommentsNotifyRoot
|
||||
@@ -1806,7 +1806,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
|
||||
// post2 should mention the user
|
||||
|
||||
count, _, err := th.App.countMentionsFromPost(user2, post1)
|
||||
count, _, err := th.App.countMentionsFromPost(th.Context, user2, post1)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 1, count)
|
||||
@@ -1819,7 +1819,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
user1 := th.BasicUser
|
||||
user2 := th.BasicUser2
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
user2.NotifyProps[model.CommentsNotifyProp] = model.CommentsNotifyAny
|
||||
@@ -1860,7 +1860,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
|
||||
// post2 and post5 should mention the user
|
||||
|
||||
count, _, err := th.App.countMentionsFromPost(user2, post1)
|
||||
count, _, err := th.App.countMentionsFromPost(th.Context, user2, post1)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 2, count)
|
||||
@@ -1873,7 +1873,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
user1 := th.BasicUser
|
||||
user2 := th.BasicUser2
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
@@ -1909,7 +1909,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
|
||||
// should be mentioned by post2 and post3
|
||||
|
||||
count, _, err := th.App.countMentionsFromPost(user2, post1)
|
||||
count, _, err := th.App.countMentionsFromPost(th.Context, user2, post1)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 2, count)
|
||||
@@ -1922,7 +1922,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
user1 := th.BasicUser
|
||||
user2 := th.BasicUser2
|
||||
|
||||
channel, err := th.App.createDirectChannel(user1.Id, user2.Id)
|
||||
channel, err := th.App.createDirectChannel(th.Context, user1.Id, user2.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
@@ -1939,12 +1939,12 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
count, _, err := th.App.countMentionsFromPost(user2, post1)
|
||||
count, _, err := th.App.countMentionsFromPost(th.Context, user2, post1)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 2, count)
|
||||
|
||||
count, _, err = th.App.countMentionsFromPost(user1, post1)
|
||||
count, _, err = th.App.countMentionsFromPost(th.Context, user1, post1)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 0, count)
|
||||
@@ -1957,7 +1957,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
user1 := th.BasicUser
|
||||
user2 := th.BasicUser2
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
_, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
@@ -1981,7 +1981,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
|
||||
// post1 and post3 should mention the user, but we only count post3
|
||||
|
||||
count, _, err := th.App.countMentionsFromPost(user2, post2)
|
||||
count, _, err := th.App.countMentionsFromPost(th.Context, user2, post2)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 1, count)
|
||||
@@ -1994,7 +1994,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
user1 := th.BasicUser
|
||||
user2 := th.BasicUser2
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
@@ -2012,7 +2012,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
|
||||
// post2 should mention the user
|
||||
|
||||
count, _, err := th.App.countMentionsFromPost(user2, post1)
|
||||
count, _, err := th.App.countMentionsFromPost(th.Context, user2, post1)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 1, count)
|
||||
@@ -2025,7 +2025,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
user1 := th.BasicUser
|
||||
user2 := th.BasicUser2
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
user2.NotifyProps[model.CommentsNotifyProp] = model.CommentsNotifyAny
|
||||
@@ -2059,7 +2059,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
|
||||
// post4 should mention the user
|
||||
|
||||
count, _, err := th.App.countMentionsFromPost(user2, post3)
|
||||
count, _, err := th.App.countMentionsFromPost(th.Context, user2, post3)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 1, count)
|
||||
@@ -2072,7 +2072,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
user1 := th.BasicUser
|
||||
user2 := th.BasicUser2
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
@@ -2099,7 +2099,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
|
||||
// post3 should mention the user
|
||||
|
||||
count, _, err := th.App.countMentionsFromPost(user2, post1)
|
||||
count, _, err := th.App.countMentionsFromPost(th.Context, user2, post1)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 1, count)
|
||||
@@ -2112,7 +2112,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
user1 := th.BasicUser
|
||||
user2 := th.BasicUser2
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
numPosts := 215
|
||||
@@ -2135,7 +2135,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
|
||||
// Every post should mention the user
|
||||
|
||||
count, _, err := th.App.countMentionsFromPost(user2, post1)
|
||||
count, _, err := th.App.countMentionsFromPost(th.Context, user2, post1)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, numPosts, count)
|
||||
@@ -2150,7 +2150,7 @@ func TestFillInPostProps(t *testing.T) {
|
||||
|
||||
user1 := th.BasicUser
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
@@ -2159,7 +2159,7 @@ func TestFillInPostProps(t *testing.T) {
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
err = th.App.FillInPostProps(post1, channel)
|
||||
err = th.App.FillInPostProps(th.Context, post1, channel)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, post1.Props, model.StringInterface{})
|
||||
@@ -2181,7 +2181,7 @@ func TestFillInPostProps(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
th.LinkUserToTeam(guest, th.BasicTeam)
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(guest, channel)
|
||||
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
@@ -2191,7 +2191,7 @@ func TestFillInPostProps(t *testing.T) {
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
err = th.App.FillInPostProps(post1, channel)
|
||||
err = th.App.FillInPostProps(th.Context, post1, channel)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, post1.Props, model.StringInterface{})
|
||||
@@ -2214,7 +2214,7 @@ func TestFillInPostProps(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
th.LinkUserToTeam(guest, th.BasicTeam)
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(guest, channel)
|
||||
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
@@ -2224,7 +2224,7 @@ func TestFillInPostProps(t *testing.T) {
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
err = th.App.FillInPostProps(post1, channel)
|
||||
err = th.App.FillInPostProps(th.Context, post1, channel)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, post1.Props, model.StringInterface{"disable_group_highlight": true})
|
||||
@@ -2243,7 +2243,7 @@ func TestThreadMembership(t *testing.T) {
|
||||
user1 := th.BasicUser
|
||||
user2 := th.BasicUser2
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
postRoot, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
@@ -2405,7 +2405,7 @@ func TestViewChannelShouldNotUpdateThreads(t *testing.T) {
|
||||
m, e := th.App.GetThreadMembershipsForUser(user2.Id, th.BasicTeam.Id)
|
||||
require.NoError(t, e)
|
||||
|
||||
th.App.ViewChannel(&model.ChannelView{
|
||||
th.App.ViewChannel(th.Context, &model.ChannelView{
|
||||
ChannelId: channel.Id,
|
||||
PrevChannelId: "",
|
||||
}, user2.Id, "", true)
|
||||
@@ -2427,7 +2427,7 @@ func TestCollapsedThreadFetch(t *testing.T) {
|
||||
user2 := th.BasicUser2
|
||||
|
||||
t.Run("should only return root posts, enriched", func(t *testing.T) {
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
defer th.App.DeleteChannel(th.Context, channel, user1.Id)
|
||||
|
||||
@@ -2448,8 +2448,8 @@ func TestCollapsedThreadFetch(t *testing.T) {
|
||||
thread, nErr := th.App.Srv().Store.Thread().Get(postRoot.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.Len(t, thread.Participants, 1)
|
||||
th.App.MarkChannelAsUnreadFromPost(postRoot.Id, user1.Id, true)
|
||||
l, err := th.App.GetPostsForChannelAroundLastUnread(channel.Id, user1.Id, 10, 10, true, true, false)
|
||||
th.App.MarkChannelAsUnreadFromPost(th.Context, postRoot.Id, user1.Id, true)
|
||||
l, err := th.App.GetPostsForChannelAroundLastUnread(th.Context, channel.Id, user1.Id, 10, 10, true, true, false)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, l.Order, 1)
|
||||
require.EqualValues(t, 1, l.Posts[postRoot.Id].ReplyCount)
|
||||
@@ -2459,7 +2459,7 @@ func TestCollapsedThreadFetch(t *testing.T) {
|
||||
require.True(t, *l.Posts[postRoot.Id].IsFollowing)
|
||||
|
||||
// try extended fetch
|
||||
l, err = th.App.GetPostsForChannelAroundLastUnread(channel.Id, user1.Id, 10, 10, true, true, true)
|
||||
l, err = th.App.GetPostsForChannelAroundLastUnread(th.Context, channel.Id, user1.Id, 10, 10, true, true, true)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, l.Order, 1)
|
||||
require.NotEmpty(t, l.Posts[postRoot.Id].Participants[0].Email)
|
||||
@@ -2472,7 +2472,7 @@ func TestCollapsedThreadFetch(t *testing.T) {
|
||||
cfg.FeatureFlags.CollapsedThreads = true
|
||||
})
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
defer th.App.DeleteChannel(th.Context, channel, user1.Id)
|
||||
|
||||
@@ -2515,7 +2515,7 @@ func TestCollapsedThreadFetch(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.LinkUserToTeam(user3, th.BasicTeam)
|
||||
th.AddUserToChannel(user3, channel)
|
||||
defer th.App.DeleteChannel(th.Context, channel, user1.Id)
|
||||
@@ -2553,10 +2553,10 @@ func TestCollapsedThreadFetch(t *testing.T) {
|
||||
require.NotEmpty(t, l.Posts[postRoot.Id].Participants[0].Email)
|
||||
require.Empty(t, l.Posts[postRoot.Id].Participants[0].AuthData)
|
||||
|
||||
th.App.MarkChannelAsUnreadFromPost(postRoot.Id, user1.Id, true)
|
||||
th.App.MarkChannelAsUnreadFromPost(th.Context, postRoot.Id, user1.Id, true)
|
||||
|
||||
// extended fetch posts around
|
||||
l, err = th.App.GetPostsForChannelAroundLastUnread(channel.Id, user1.Id, 10, 10, true, true, true)
|
||||
l, err = th.App.GetPostsForChannelAroundLastUnread(th.Context, channel.Id, user1.Id, 10, 10, true, true, true)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, l.Order, 1)
|
||||
require.NotEmpty(t, l.Posts[postRoot.Id].Participants[0].Email)
|
||||
@@ -2628,7 +2628,7 @@ func TestSharedChannelSyncForPostActions(t *testing.T) {
|
||||
|
||||
user := th.BasicUser
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam, WithShared(true))
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam, WithShared(true))
|
||||
|
||||
_, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user.Id,
|
||||
@@ -2652,7 +2652,7 @@ func TestSharedChannelSyncForPostActions(t *testing.T) {
|
||||
|
||||
user := th.BasicUser
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam, WithShared(true))
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam, WithShared(true))
|
||||
|
||||
post, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user.Id,
|
||||
@@ -2680,7 +2680,7 @@ func TestSharedChannelSyncForPostActions(t *testing.T) {
|
||||
|
||||
user := th.BasicUser
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam, WithShared(true))
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam, WithShared(true))
|
||||
|
||||
post, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user.Id,
|
||||
@@ -2689,7 +2689,7 @@ func TestSharedChannelSyncForPostActions(t *testing.T) {
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err, "Creating a post should not error")
|
||||
|
||||
_, err = th.App.DeletePost(post.Id, user.Id)
|
||||
_, err = th.App.DeletePost(th.Context, post.Id, user.Id)
|
||||
require.Nil(t, err, "Deleting a post should not error")
|
||||
|
||||
// one creation and two deletes
|
||||
@@ -2747,7 +2747,7 @@ func TestGetPostIfAuthorized(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
privateChannel := th.CreatePrivateChannel(th.BasicTeam)
|
||||
privateChannel := th.CreatePrivateChannel(th.Context, th.BasicTeam)
|
||||
post, err := th.App.CreatePost(th.Context, &model.Post{UserId: th.BasicUser.Id, ChannelId: privateChannel.Id, Message: "Hello"}, privateChannel, false, false)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, post)
|
||||
@@ -2761,11 +2761,11 @@ func TestGetPostIfAuthorized(t *testing.T) {
|
||||
require.NotNil(t, session2)
|
||||
|
||||
// User is not authorized to get post
|
||||
_, err = th.App.GetPostIfAuthorized(post.Id, session2, false)
|
||||
_, err = th.App.GetPostIfAuthorized(th.Context, post.Id, session2, false)
|
||||
require.NotNil(t, err)
|
||||
|
||||
// User is authorized to get post
|
||||
_, err = th.App.GetPostIfAuthorized(post.Id, session1, false)
|
||||
_, err = th.App.GetPostIfAuthorized(th.Context, post.Id, session1, false)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
@@ -2887,8 +2887,8 @@ func TestGetTopThreadsForTeamSince(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
// create a public channel, a private channel
|
||||
channelPublic := th.CreateChannel(th.BasicTeam)
|
||||
channelPrivate := th.CreatePrivateChannel(th.BasicTeam)
|
||||
channelPublic := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
channelPrivate := th.CreatePrivateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(th.BasicUser, channelPublic)
|
||||
th.AddUserToChannel(th.BasicUser, channelPrivate)
|
||||
th.AddUserToChannel(th.BasicUser2, channelPublic)
|
||||
@@ -2937,20 +2937,20 @@ func TestGetTopThreadsForTeamSince(t *testing.T) {
|
||||
// get top threads for team, as user 1 and user 2
|
||||
// user 1 should see both threads, while user 2 should see only thread in public channel.
|
||||
|
||||
topTeamThreadsByUser1, appErr := th.App.GetTopThreadsForTeamSince(th.BasicTeam.Id, th.BasicUser.Id, &model.InsightsOpts{StartUnixMilli: 200, PerPage: 100})
|
||||
topTeamThreadsByUser1, appErr := th.App.GetTopThreadsForTeamSince(th.Context, th.BasicTeam.Id, th.BasicUser.Id, &model.InsightsOpts{StartUnixMilli: 200, PerPage: 100})
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, topTeamThreadsByUser1.Items, 2)
|
||||
require.Equal(t, topTeamThreadsByUser1.Items[0].Post.Id, rootPostPrivateChannel.Id)
|
||||
require.Equal(t, topTeamThreadsByUser1.Items[1].Post.Id, rootPostPublicChannel.Id)
|
||||
|
||||
topTeamThreadsByUser2, appErr := th.App.GetTopThreadsForTeamSince(th.BasicTeam.Id, th.BasicUser2.Id, &model.InsightsOpts{StartUnixMilli: 200, PerPage: 100})
|
||||
topTeamThreadsByUser2, appErr := th.App.GetTopThreadsForTeamSince(th.Context, th.BasicTeam.Id, th.BasicUser2.Id, &model.InsightsOpts{StartUnixMilli: 200, PerPage: 100})
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, topTeamThreadsByUser2.Items, 1)
|
||||
require.Equal(t, topTeamThreadsByUser2.Items[0].Post.Id, rootPostPublicChannel.Id)
|
||||
|
||||
// add user2 to private channel and it can see 2 top threads.
|
||||
th.AddUserToChannel(th.BasicUser2, channelPrivate)
|
||||
topTeamThreadsByUser2IncludingPrivate, appErr := th.App.GetTopThreadsForTeamSince(th.BasicTeam.Id, th.BasicUser2.Id, &model.InsightsOpts{StartUnixMilli: 200, PerPage: 100})
|
||||
topTeamThreadsByUser2IncludingPrivate, appErr := th.App.GetTopThreadsForTeamSince(th.Context, th.BasicTeam.Id, th.BasicUser2.Id, &model.InsightsOpts{StartUnixMilli: 200, PerPage: 100})
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, topTeamThreadsByUser2IncludingPrivate.Items, 2)
|
||||
}
|
||||
@@ -2959,8 +2959,8 @@ func TestGetTopThreadsForUserSince(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
// create a public channel, a private channel
|
||||
channelPublic := th.CreateChannel(th.BasicTeam)
|
||||
channelPrivate := th.CreatePrivateChannel(th.BasicTeam)
|
||||
channelPublic := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
channelPrivate := th.CreatePrivateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(th.BasicUser, channelPublic)
|
||||
th.AddUserToChannel(th.BasicUser, channelPrivate)
|
||||
th.AddUserToChannel(th.BasicUser2, channelPublic)
|
||||
@@ -3012,7 +3012,7 @@ func TestGetTopThreadsForUserSince(t *testing.T) {
|
||||
// user 1 should see both threads, while user 2 should see only thread in public channel
|
||||
// (even if user2 is in the private channel it hasn't interacted with the thread there.)
|
||||
|
||||
topUser1Threads, appErr := th.App.GetTopThreadsForUserSince(th.BasicTeam.Id, th.BasicUser.Id, &model.InsightsOpts{StartUnixMilli: 200, PerPage: 100})
|
||||
topUser1Threads, appErr := th.App.GetTopThreadsForUserSince(th.Context, th.BasicTeam.Id, th.BasicUser.Id, &model.InsightsOpts{StartUnixMilli: 200, PerPage: 100})
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, topUser1Threads.Items, 2)
|
||||
require.Equal(t, topUser1Threads.Items[0].Post.Id, rootPostPrivateChannel.Id)
|
||||
@@ -3021,17 +3021,17 @@ func TestGetTopThreadsForUserSince(t *testing.T) {
|
||||
require.Contains(t, topUser1Threads.Items[1].Participants, th.BasicUser2.Id)
|
||||
require.Equal(t, topUser1Threads.Items[1].ReplyCount, int64(1))
|
||||
|
||||
topUser2Threads, appErr := th.App.GetTopThreadsForUserSince(th.BasicTeam.Id, th.BasicUser2.Id, &model.InsightsOpts{StartUnixMilli: 200, PerPage: 100})
|
||||
topUser2Threads, appErr := th.App.GetTopThreadsForUserSince(th.Context, th.BasicTeam.Id, th.BasicUser2.Id, &model.InsightsOpts{StartUnixMilli: 200, PerPage: 100})
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, topUser2Threads.Items, 1)
|
||||
require.Equal(t, topUser2Threads.Items[0].Post.Id, rootPostPublicChannel.Id)
|
||||
require.Equal(t, topUser2Threads.Items[0].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)
|
||||
|
||||
topUser1ThreadsAfterPost1Delete, appErr := th.App.GetTopThreadsForUserSince(th.BasicTeam.Id, th.BasicUser.Id, &model.InsightsOpts{StartUnixMilli: 200, PerPage: 100})
|
||||
topUser1ThreadsAfterPost1Delete, appErr := th.App.GetTopThreadsForUserSince(th.Context, th.BasicTeam.Id, th.BasicUser.Id, &model.InsightsOpts{StartUnixMilli: 200, PerPage: 100})
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, topUser1ThreadsAfterPost1Delete.Items, 1)
|
||||
|
||||
@@ -3044,12 +3044,12 @@ func TestGetTopThreadsForUserSince(t *testing.T) {
|
||||
}, channelPrivate, false, true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
topUser2ThreadsAfterPrivateReply, appErr := th.App.GetTopThreadsForUserSince(th.BasicTeam.Id, th.BasicUser2.Id, &model.InsightsOpts{StartUnixMilli: 200, PerPage: 100})
|
||||
topUser2ThreadsAfterPrivateReply, appErr := th.App.GetTopThreadsForUserSince(th.Context, th.BasicTeam.Id, th.BasicUser2.Id, &model.InsightsOpts{StartUnixMilli: 200, PerPage: 100})
|
||||
require.Nil(t, appErr)
|
||||
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{
|
||||
@@ -3058,7 +3058,7 @@ func TestGetTopThreadsForUserSince(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
topUser2ThreadsAfterPrivateReplyDelete, appErr := th.App.GetTopThreadsForUserSince(th.BasicTeam.Id, th.BasicUser2.Id, &model.InsightsOpts{StartUnixMilli: 200, PerPage: 100})
|
||||
topUser2ThreadsAfterPrivateReplyDelete, appErr := th.App.GetTopThreadsForUserSince(th.Context, th.BasicTeam.Id, th.BasicUser2.Id, &model.InsightsOpts{StartUnixMilli: 200, PerPage: 100})
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, topUser2ThreadsAfterPrivateReplyDelete.Items, 0)
|
||||
}
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ func (a *App) SaveReactionForPost(c *request.Context, reaction *model.Reaction)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
channel, err := a.GetChannel(post.ChannelId)
|
||||
channel, err := a.GetChannel(c, post.ChannelId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -126,7 +126,7 @@ func (a *App) DeleteReactionForPost(c *request.Context, reaction *model.Reaction
|
||||
return err
|
||||
}
|
||||
|
||||
channel, err := a.GetChannel(post.ChannelId)
|
||||
channel, err := a.GetChannel(c, post.ChannelId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func TestSharedChannelSyncForReactionActions(t *testing.T) {
|
||||
|
||||
user := th.BasicUser
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam, WithShared(true))
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam, WithShared(true))
|
||||
|
||||
post, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user.Id,
|
||||
@@ -60,7 +60,7 @@ func TestSharedChannelSyncForReactionActions(t *testing.T) {
|
||||
|
||||
user := th.BasicUser
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam, WithShared(true))
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam, WithShared(true))
|
||||
|
||||
post, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user.Id,
|
||||
|
||||
+26
-1
@@ -38,9 +38,10 @@ func NewContext(ctx context.Context, requestId, ipAddress, path, userAgent, acce
|
||||
}
|
||||
}
|
||||
|
||||
func EmptyContext() *Context {
|
||||
func EmptyContext(logger mlog.LoggerIFace) *Context {
|
||||
return &Context{
|
||||
t: i18n.T,
|
||||
logger: logger,
|
||||
context: context.Background(),
|
||||
}
|
||||
}
|
||||
@@ -116,3 +117,27 @@ func (c *Context) SetAppError(err *model.AppError) {
|
||||
func (c *Context) AppError() *model.AppError {
|
||||
return c.err
|
||||
}
|
||||
|
||||
type CTX interface {
|
||||
T(string, ...interface{}) string
|
||||
Session() *model.Session
|
||||
RequestId() string
|
||||
IPAddress() string
|
||||
Path() string
|
||||
UserAgent() string
|
||||
AcceptLanguage() string
|
||||
Context() context.Context
|
||||
SetSession(s *model.Session)
|
||||
SetT(i18n.TranslateFunc)
|
||||
SetRequestId(string)
|
||||
SetIPAddress(string)
|
||||
SetUserAgent(string)
|
||||
SetAcceptLanguage(string)
|
||||
SetPath(string)
|
||||
SetContext(ctx context.Context)
|
||||
GetT() i18n.TranslateFunc
|
||||
SetLogger(mlog.LoggerIFace)
|
||||
Logger() mlog.LoggerIFace
|
||||
SetAppError(*model.AppError)
|
||||
AppError() *model.AppError
|
||||
}
|
||||
|
||||
+4
-4
@@ -114,15 +114,15 @@ func testPermissionInheritance(t *testing.T, testCallback func(t *testing.T, th
|
||||
defer th.App.DeleteScheme(channelScheme.Id)
|
||||
|
||||
team := th.CreateTeam()
|
||||
defer th.App.PermanentDeleteTeamId(team.Id)
|
||||
defer th.App.PermanentDeleteTeamId(th.Context, team.Id)
|
||||
|
||||
// Make a channel
|
||||
channel := th.CreateChannel(team)
|
||||
defer th.App.PermanentDeleteChannel(channel)
|
||||
channel := th.CreateChannel(th.Context, team)
|
||||
defer th.App.PermanentDeleteChannel(th.Context, channel)
|
||||
|
||||
// Set the channel scheme
|
||||
channel.SchemeId = &channelScheme.Id
|
||||
channel, err = th.App.UpdateChannelScheme(channel)
|
||||
channel, err = th.App.UpdateChannelScheme(th.Context, channel)
|
||||
require.Nil(t, err)
|
||||
|
||||
// Get the truth table from CSV
|
||||
|
||||
+5
-3
@@ -480,7 +480,7 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
return nil, errors.Wrap(err, "Unable to create opengraphdata cache")
|
||||
}
|
||||
|
||||
s.createPushNotificationsHub()
|
||||
s.createPushNotificationsHub(request.EmptyContext(s.GetLogger()))
|
||||
|
||||
if err2 := i18n.InitTranslations(*s.Config().LocalizationSettings.DefaultServerLocale, *s.Config().LocalizationSettings.DefaultClientLocale); err2 != nil {
|
||||
return nil, errors.Wrapf(err2, "unable to load Mattermost translation files")
|
||||
@@ -653,7 +653,8 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
s.AddConfigListener(func(old, new *model.Config) {
|
||||
appInstance := New(ServerConnector(s.Channels()))
|
||||
if *old.GuestAccountsSettings.Enable && !*new.GuestAccountsSettings.Enable {
|
||||
if appErr := appInstance.DeactivateGuests(request.EmptyContext()); appErr != nil {
|
||||
c := request.EmptyContext(s.GetLogger())
|
||||
if appErr := appInstance.DeactivateGuests(c); appErr != nil {
|
||||
mlog.Error("Unable to deactivate guest accounts", mlog.Err(appErr))
|
||||
}
|
||||
}
|
||||
@@ -662,7 +663,8 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
// Disable active guest accounts on first run if guest accounts are disabled
|
||||
if !*s.Config().GuestAccountsSettings.Enable {
|
||||
appInstance := New(ServerConnector(s.Channels()))
|
||||
if appErr := appInstance.DeactivateGuests(request.EmptyContext()); appErr != nil {
|
||||
c := request.EmptyContext(s.GetLogger())
|
||||
if appErr := appInstance.DeactivateGuests(c); appErr != nil {
|
||||
mlog.Error("Unable to deactivate guest accounts", mlog.Err(appErr))
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -134,7 +134,7 @@ func TestUpdateSessionOnPromoteDemote(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "false", rsession.Props[model.SessionPropIsGuest])
|
||||
|
||||
err = th.App.DemoteUserToGuest(user)
|
||||
err = th.App.DemoteUserToGuest(th.Context, user)
|
||||
require.Nil(t, err)
|
||||
|
||||
rsession, err = th.App.GetSession(session.Token)
|
||||
|
||||
@@ -8,13 +8,14 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app/request"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/store"
|
||||
)
|
||||
|
||||
func (a *App) checkChannelNotShared(channelId string) error {
|
||||
func (a *App) checkChannelNotShared(c request.CTX, channelId string) error {
|
||||
// check that channel exists.
|
||||
if _, err := a.GetChannel(channelId); err != nil {
|
||||
if _, err := a.GetChannel(c, channelId); err != nil {
|
||||
return fmt.Errorf("cannot share this channel: %w", err)
|
||||
}
|
||||
|
||||
@@ -58,8 +59,8 @@ func (a *App) CheckCanInviteToSharedChannel(channelId string) error {
|
||||
|
||||
// SharedChannels
|
||||
|
||||
func (a *App) SaveSharedChannel(sc *model.SharedChannel) (*model.SharedChannel, error) {
|
||||
if err := a.checkChannelNotShared(sc.ChannelId); err != nil {
|
||||
func (a *App) SaveSharedChannel(c request.CTX, sc *model.SharedChannel) (*model.SharedChannel, error) {
|
||||
if err := a.checkChannelNotShared(c, sc.ChannelId); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return a.Srv().Store.SharedChannel().Save(sc)
|
||||
|
||||
@@ -31,7 +31,7 @@ func TestServerSyncSharedChannelHandler(t *testing.T) {
|
||||
mockService := NewMockSharedChannelService(nil)
|
||||
mockService.active = true
|
||||
th.App.ch.srv.SetSharedChannelSyncService(mockService)
|
||||
channel := th.CreateChannel(th.BasicTeam, WithShared(true))
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam, WithShared(true))
|
||||
|
||||
websocketEvent := model.NewWebSocketEvent(model.WebsocketEventAddedToTeam, model.NewId(), channel.Id, "", nil)
|
||||
|
||||
@@ -61,7 +61,7 @@ func TestServerSyncSharedChannelHandler(t *testing.T) {
|
||||
mockService.active = true
|
||||
th.App.ch.srv.SetSharedChannelSyncService(mockService)
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam, WithShared(true))
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam, WithShared(true))
|
||||
websocketEvent := model.NewWebSocketEvent(model.WebsocketEventPosted, model.NewId(), channel.Id, "", nil)
|
||||
|
||||
th.App.ch.srv.SharedChannelSyncHandler(websocketEvent)
|
||||
|
||||
@@ -15,9 +15,9 @@ import (
|
||||
func TestApp_CheckCanInviteToSharedChannel(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
|
||||
channel1 := th.CreateChannel(th.BasicTeam)
|
||||
channel2 := th.CreateChannel(th.BasicTeam)
|
||||
channel3 := th.CreateChannel(th.BasicTeam)
|
||||
channel1 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
channel2 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
channel3 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
|
||||
data := []struct {
|
||||
channelId string
|
||||
@@ -38,22 +38,22 @@ func TestApp_CheckCanInviteToSharedChannel(t *testing.T) {
|
||||
CreatorId: th.BasicUser.Id,
|
||||
RemoteId: d.remoteId,
|
||||
}
|
||||
_, err := th.App.SaveSharedChannel(sc)
|
||||
_, err := th.App.SaveSharedChannel(th.Context, sc)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
t.Run("Test checkChannelNotShared: not yet shared channel", func(t *testing.T) {
|
||||
err := th.App.checkChannelNotShared(channel3.Id)
|
||||
err := th.App.checkChannelNotShared(th.Context, channel3.Id)
|
||||
assert.NoError(t, err, "unshared channel should not error")
|
||||
})
|
||||
|
||||
t.Run("Test checkChannelNotShared: already shared channel", func(t *testing.T) {
|
||||
err := th.App.checkChannelNotShared(channel1.Id)
|
||||
err := th.App.checkChannelNotShared(th.Context, channel1.Id)
|
||||
assert.Error(t, err, "already shared channel should error")
|
||||
})
|
||||
|
||||
t.Run("Test checkChannelNotShared: invalid channel", func(t *testing.T) {
|
||||
err := th.App.checkChannelNotShared(model.NewId())
|
||||
err := th.App.checkChannelNotShared(th.Context, model.NewId())
|
||||
assert.Error(t, err, "invalid channel should error")
|
||||
})
|
||||
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ func (a *App) SlackImport(c *request.Context, fileData multipart.File, fileSize
|
||||
}
|
||||
|
||||
importer := slackimport.New(a.ch.srv.Store, actions, a.Config())
|
||||
return importer.SlackImport(fileData, fileSize, teamID)
|
||||
return importer.SlackImport(c, fileData, fileSize, teamID)
|
||||
}
|
||||
|
||||
func (a *App) ProcessSlackText(text string) string {
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
package slashcommands
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app"
|
||||
"github.com/mattermost/mattermost-server/v6/app/request"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
@@ -38,7 +36,7 @@ func (*HeaderProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comma
|
||||
}
|
||||
|
||||
func (*HeaderProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
channel, err := a.GetChannel(args.ChannelId)
|
||||
channel, err := a.GetChannel(c, args.ChannelId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_channel_header.channel.app_error"),
|
||||
@@ -48,7 +46,7 @@ func (*HeaderProvider) DoCommand(a *app.App, c *request.Context, args *model.Com
|
||||
|
||||
switch channel.Type {
|
||||
case model.ChannelTypeOpen:
|
||||
if !a.HasPermissionToChannel(args.UserId, args.ChannelId, model.PermissionManagePublicChannelProperties) {
|
||||
if !a.HasPermissionToChannel(c, args.UserId, args.ChannelId, model.PermissionManagePublicChannelProperties) {
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_channel_header.permission.app_error"),
|
||||
ResponseType: model.CommandResponseTypeEphemeral,
|
||||
@@ -56,7 +54,7 @@ func (*HeaderProvider) DoCommand(a *app.App, c *request.Context, args *model.Com
|
||||
}
|
||||
|
||||
case model.ChannelTypePrivate:
|
||||
if !a.HasPermissionToChannel(args.UserId, args.ChannelId, model.PermissionManagePrivateChannelProperties) {
|
||||
if !a.HasPermissionToChannel(c, args.UserId, args.ChannelId, model.PermissionManagePrivateChannelProperties) {
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_channel_header.permission.app_error"),
|
||||
ResponseType: model.CommandResponseTypeEphemeral,
|
||||
@@ -66,7 +64,7 @@ func (*HeaderProvider) DoCommand(a *app.App, c *request.Context, args *model.Com
|
||||
case model.ChannelTypeGroup, model.ChannelTypeDirect:
|
||||
// Modifying the header is not linked to any specific permission for group/dm channels, so just check for membership.
|
||||
var channelMember *model.ChannelMember
|
||||
channelMember, err = a.GetChannelMember(context.Background(), args.ChannelId, args.UserId)
|
||||
channelMember, err = a.GetChannelMember(c, args.ChannelId, args.UserId)
|
||||
if err != nil || channelMember == nil {
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_channel_header.permission.app_error"),
|
||||
|
||||
@@ -36,7 +36,7 @@ func (*PurposeProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comm
|
||||
}
|
||||
|
||||
func (*PurposeProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
channel, err := a.GetChannel(args.ChannelId)
|
||||
channel, err := a.GetChannel(c, args.ChannelId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_channel_purpose.channel.app_error"),
|
||||
@@ -46,14 +46,14 @@ func (*PurposeProvider) DoCommand(a *app.App, c *request.Context, args *model.Co
|
||||
|
||||
switch channel.Type {
|
||||
case model.ChannelTypeOpen:
|
||||
if !a.HasPermissionToChannel(args.UserId, args.ChannelId, model.PermissionManagePublicChannelProperties) {
|
||||
if !a.HasPermissionToChannel(c, args.UserId, args.ChannelId, model.PermissionManagePublicChannelProperties) {
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_channel_purpose.permission.app_error"),
|
||||
ResponseType: model.CommandResponseTypeEphemeral,
|
||||
}
|
||||
}
|
||||
case model.ChannelTypePrivate:
|
||||
if !a.HasPermissionToChannel(args.UserId, args.ChannelId, model.PermissionManagePrivateChannelProperties) {
|
||||
if !a.HasPermissionToChannel(c, args.UserId, args.ChannelId, model.PermissionManagePrivateChannelProperties) {
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_channel_purpose.permission.app_error"),
|
||||
ResponseType: model.CommandResponseTypeEphemeral,
|
||||
|
||||
@@ -39,7 +39,7 @@ func (*RenameProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comma
|
||||
}
|
||||
|
||||
func (*RenameProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
channel, err := a.GetChannel(args.ChannelId)
|
||||
channel, err := a.GetChannel(c, args.ChannelId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_channel_rename.channel.app_error"),
|
||||
@@ -49,14 +49,14 @@ func (*RenameProvider) DoCommand(a *app.App, c *request.Context, args *model.Com
|
||||
|
||||
switch channel.Type {
|
||||
case model.ChannelTypeOpen:
|
||||
if !a.HasPermissionToChannel(args.UserId, args.ChannelId, model.PermissionManagePublicChannelProperties) {
|
||||
if !a.HasPermissionToChannel(c, args.UserId, args.ChannelId, model.PermissionManagePublicChannelProperties) {
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_channel_rename.permission.app_error"),
|
||||
ResponseType: model.CommandResponseTypeEphemeral,
|
||||
}
|
||||
}
|
||||
case model.ChannelTypePrivate:
|
||||
if !a.HasPermissionToChannel(args.UserId, args.ChannelId, model.PermissionManagePrivateChannelProperties) {
|
||||
if !a.HasPermissionToChannel(c, args.UserId, args.ChannelId, model.PermissionManagePrivateChannelProperties) {
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_channel_rename.permission.app_error"),
|
||||
ResponseType: model.CommandResponseTypeEphemeral,
|
||||
|
||||
@@ -110,13 +110,13 @@ func (*groupmsgProvider) DoCommand(a *app.App, c *request.Context, args *model.C
|
||||
var channelErr *model.AppError
|
||||
|
||||
if a.HasPermissionTo(args.UserId, model.PermissionCreateGroupChannel) {
|
||||
groupChannel, channelErr = a.CreateGroupChannel(targetUsersSlice, args.UserId)
|
||||
groupChannel, channelErr = a.CreateGroupChannel(c, targetUsersSlice, args.UserId)
|
||||
if channelErr != nil {
|
||||
mlog.Error(channelErr.Error())
|
||||
return &model.CommandResponse{Text: args.T("api.command_groupmsg.group_fail.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
|
||||
}
|
||||
} else {
|
||||
groupChannel, channelErr = a.GetGroupChannel(targetUsersSlice)
|
||||
groupChannel, channelErr = a.GetGroupChannel(c, targetUsersSlice)
|
||||
if channelErr != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_groupmsg.permission.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
package slashcommands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app"
|
||||
@@ -73,7 +72,7 @@ func (*InviteProvider) DoCommand(a *app.App, c *request.Context, args *model.Com
|
||||
if len(splitMessage) > 1 && splitMessage[1] != "" {
|
||||
targetChannelName := strings.TrimPrefix(strings.TrimSpace(splitMessage[1]), "~")
|
||||
|
||||
if channelToJoin, err = a.GetChannelByName(targetChannelName, args.TeamId, false); err != nil {
|
||||
if channelToJoin, err = a.GetChannelByName(c, targetChannelName, args.TeamId, false); err != nil {
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_invite.channel.error", map[string]any{
|
||||
"Channel": targetChannelName,
|
||||
@@ -82,7 +81,7 @@ func (*InviteProvider) DoCommand(a *app.App, c *request.Context, args *model.Com
|
||||
}
|
||||
}
|
||||
} else {
|
||||
channelToJoin, err = a.GetChannel(args.ChannelId)
|
||||
channelToJoin, err = a.GetChannel(c, args.ChannelId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_invite.channel.app_error"),
|
||||
@@ -94,7 +93,7 @@ func (*InviteProvider) DoCommand(a *app.App, c *request.Context, args *model.Com
|
||||
// Permissions Check
|
||||
switch channelToJoin.Type {
|
||||
case model.ChannelTypeOpen:
|
||||
if !a.HasPermissionToChannel(args.UserId, channelToJoin.Id, model.PermissionManagePublicChannelMembers) {
|
||||
if !a.HasPermissionToChannel(c, args.UserId, channelToJoin.Id, model.PermissionManagePublicChannelMembers) {
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_invite.permission.app_error", map[string]any{
|
||||
"User": userProfile.Username,
|
||||
@@ -104,8 +103,8 @@ func (*InviteProvider) DoCommand(a *app.App, c *request.Context, args *model.Com
|
||||
}
|
||||
}
|
||||
case model.ChannelTypePrivate:
|
||||
if !a.HasPermissionToChannel(args.UserId, channelToJoin.Id, model.PermissionManagePrivateChannelMembers) {
|
||||
if _, err = a.GetChannelMember(context.Background(), channelToJoin.Id, args.UserId); err == nil {
|
||||
if !a.HasPermissionToChannel(c, args.UserId, channelToJoin.Id, model.PermissionManagePrivateChannelMembers) {
|
||||
if _, err = a.GetChannelMember(c, channelToJoin.Id, args.UserId); err == nil {
|
||||
// User doing the inviting is a member of the channel.
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_invite.permission.app_error", map[string]any{
|
||||
@@ -131,7 +130,7 @@ func (*InviteProvider) DoCommand(a *app.App, c *request.Context, args *model.Com
|
||||
}
|
||||
|
||||
// Check if user is already in the channel
|
||||
_, err = a.GetChannelMember(context.Background(), channelToJoin.Id, userProfile.Id)
|
||||
_, err = a.GetChannelMember(c, channelToJoin.Id, userProfile.Id)
|
||||
if err == nil {
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_invite.user_already_in_channel.app_error", map[string]any{
|
||||
|
||||
@@ -76,7 +76,7 @@ func TestInviteProvider(t *testing.T) {
|
||||
_, err = th.App.AddChannelMember(th.Context, th.BasicUser.Id, groupChannel, app.ChannelMemberOpts{})
|
||||
require.Nil(t, err)
|
||||
groupChannel.GroupConstrained = model.NewBool(true)
|
||||
groupChannel, _ = th.App.UpdateChannel(groupChannel)
|
||||
groupChannel, _ = th.App.UpdateChannel(th.Context, groupChannel)
|
||||
|
||||
groupChannelNonUser := "@" + th.BasicUser2.Username + " ~" + groupChannel.Name
|
||||
|
||||
|
||||
@@ -55,11 +55,11 @@ func (*JoinProvider) DoCommand(a *app.App, c *request.Context, args *model.Comma
|
||||
|
||||
switch channel.Type {
|
||||
case model.ChannelTypeOpen:
|
||||
if !a.HasPermissionToChannel(args.UserId, channel.Id, model.PermissionJoinPublicChannels) {
|
||||
if !a.HasPermissionToChannel(c, args.UserId, channel.Id, model.PermissionJoinPublicChannels) {
|
||||
return &model.CommandResponse{Text: args.T("api.command_join.fail.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
|
||||
}
|
||||
case model.ChannelTypePrivate:
|
||||
if !a.HasPermissionToChannel(args.UserId, channel.Id, model.PermissionReadChannel) {
|
||||
if !a.HasPermissionToChannel(c, args.UserId, channel.Id, model.PermissionReadChannel) {
|
||||
return &model.CommandResponse{Text: args.T("api.command_join.fail.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -37,7 +37,7 @@ func (*LeaveProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comman
|
||||
func (*LeaveProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
var channel *model.Channel
|
||||
var noChannelErr *model.AppError
|
||||
if channel, noChannelErr = a.GetChannel(args.ChannelId); noChannelErr != nil {
|
||||
if channel, noChannelErr = a.GetChannel(c, args.ChannelId); noChannelErr != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_leave.fail.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
|
||||
}
|
||||
|
||||
@@ -65,11 +65,11 @@ func (*LeaveProvider) DoCommand(a *app.App, c *request.Context, args *model.Comm
|
||||
}
|
||||
|
||||
if user.IsGuest() {
|
||||
members, err := a.GetChannelMembersForUser(team.Id, args.UserId)
|
||||
members, err := a.GetChannelMembersForUser(c, team.Id, args.UserId)
|
||||
if err != nil || len(members) == 0 {
|
||||
return &model.CommandResponse{Text: args.T("api.command_leave.fail.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
|
||||
}
|
||||
channel, err := a.GetChannel(members[0].ChannelId)
|
||||
channel, err := a.GetChannel(c, members[0].ChannelId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_leave.fail.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
package slashcommands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -35,17 +34,17 @@ func TestLeaveProviderDoCommand(t *testing.T) {
|
||||
CreatorId: th.BasicUser.Id,
|
||||
}, false)
|
||||
|
||||
defaultChannel, err := th.App.GetChannelByName(model.DefaultChannelName, th.BasicTeam.Id, false)
|
||||
defaultChannel, err := th.App.GetChannelByName(th.Context, model.DefaultChannelName, th.BasicTeam.Id, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
guest := th.createGuest()
|
||||
|
||||
th.App.AddUserToTeam(th.Context, th.BasicTeam.Id, th.BasicUser.Id, th.BasicUser.Id)
|
||||
th.App.AddUserToChannel(th.BasicUser, publicChannel, false)
|
||||
th.App.AddUserToChannel(th.BasicUser, privateChannel, false)
|
||||
th.App.AddUserToChannel(th.Context, th.BasicUser, publicChannel, false)
|
||||
th.App.AddUserToChannel(th.Context, th.BasicUser, privateChannel, false)
|
||||
th.App.AddUserToTeam(th.Context, th.BasicTeam.Id, guest.Id, guest.Id)
|
||||
th.App.AddUserToChannel(guest, publicChannel, false)
|
||||
th.App.AddUserToChannel(guest, defaultChannel, false)
|
||||
th.App.AddUserToChannel(th.Context, guest, publicChannel, false)
|
||||
th.App.AddUserToChannel(th.Context, guest, defaultChannel, false)
|
||||
|
||||
t.Run("Should error when no Channel ID in args", func(t *testing.T) {
|
||||
args := &model.CommandArgs{
|
||||
@@ -81,7 +80,7 @@ func TestLeaveProviderDoCommand(t *testing.T) {
|
||||
assert.Equal(t, args.SiteURL+"/"+th.BasicTeam.Name+"/channels/"+model.DefaultChannelName, actual.GotoLocation)
|
||||
assert.Equal(t, "", actual.ResponseType)
|
||||
|
||||
_, err = th.App.GetChannelMember(context.Background(), publicChannel.Id, th.BasicUser.Id)
|
||||
_, err = th.App.GetChannelMember(th.Context, publicChannel.Id, th.BasicUser.Id)
|
||||
assert.NotNil(t, err)
|
||||
assert.NotNil(t, err.Id, "app.channel.get_member.missing.app_error")
|
||||
})
|
||||
@@ -123,7 +122,7 @@ func TestLeaveProviderDoCommand(t *testing.T) {
|
||||
assert.Equal(t, args.SiteURL+"/"+th.BasicTeam.Name+"/channels/"+publicChannel.Name, actual.GotoLocation)
|
||||
assert.Equal(t, "", actual.ResponseType)
|
||||
|
||||
_, err = th.App.GetChannelMember(context.Background(), defaultChannel.Id, guest.Id)
|
||||
_, err = th.App.GetChannelMember(th.Context, defaultChannel.Id, guest.Id)
|
||||
assert.NotNil(t, err)
|
||||
assert.NotNil(t, err.Id, "app.channel.get_member.missing.app_error")
|
||||
})
|
||||
@@ -141,7 +140,7 @@ func TestLeaveProviderDoCommand(t *testing.T) {
|
||||
assert.Equal(t, args.SiteURL+"/", actual.GotoLocation)
|
||||
assert.Equal(t, "", actual.ResponseType)
|
||||
|
||||
_, err = th.App.GetChannelMember(context.Background(), publicChannel.Id, guest.Id)
|
||||
_, err = th.App.GetChannelMember(th.Context, publicChannel.Id, guest.Id)
|
||||
assert.NotNil(t, err)
|
||||
assert.NotNil(t, err.Id, "app.channel.get_member.missing.app_error")
|
||||
})
|
||||
|
||||
@@ -160,7 +160,7 @@ func (lt *LoadTestProvider) doCommand(a *app.App, c *request.Context, args *mode
|
||||
}
|
||||
|
||||
if strings.HasPrefix(message, "post") {
|
||||
return lt.PostCommand(a, args, message)
|
||||
return lt.PostCommand(a, c, args, message)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(message, "threaded_post") {
|
||||
@@ -444,7 +444,7 @@ func getMatch(re *regexp.Regexp, text string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (*LoadTestProvider) PostCommand(a *app.App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
|
||||
func (*LoadTestProvider) PostCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
|
||||
textMessage := getMatch(messageRE, message)
|
||||
if textMessage == "" {
|
||||
return &model.CommandResponse{Text: "No message to post", ResponseType: model.CommandResponseTypeEphemeral}, nil
|
||||
@@ -457,7 +457,7 @@ func (*LoadTestProvider) PostCommand(a *app.App, args *model.CommandArgs, messag
|
||||
}
|
||||
|
||||
channelName := getMatch(channelRE, message)
|
||||
channel, err := a.GetChannelByName(channelName, team.Id, true)
|
||||
channel, err := a.GetChannelByName(c, channelName, team.Id, true)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{Text: "Failed to get a channel", ResponseType: model.CommandResponseTypeEphemeral}, err
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func (*MuteProvider) DoCommand(a *app.App, c *request.Context, args *model.Comma
|
||||
var channel *model.Channel
|
||||
var noChannelErr *model.AppError
|
||||
|
||||
if channel, noChannelErr = a.GetChannel(args.ChannelId); noChannelErr != nil {
|
||||
if channel, noChannelErr = a.GetChannel(c, args.ChannelId); noChannelErr != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_mute.no_channel.error"), ResponseType: model.CommandResponseTypeEphemeral}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func (*MuteProvider) DoCommand(a *app.App, c *request.Context, args *model.Comma
|
||||
}
|
||||
}
|
||||
|
||||
channelMember, err := a.ToggleMuteChannel(channel.Id, args.UserId)
|
||||
channelMember, err := a.ToggleMuteChannel(c, channel.Id, args.UserId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_mute.not_member.error", map[string]any{"Channel": channelName}), ResponseType: model.CommandResponseTypeEphemeral}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
package slashcommands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -23,7 +22,7 @@ func TestMuteCommandNoChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
channel1 := th.BasicChannel
|
||||
channel1M, channel1MError := th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
channel1M, channel1MError := th.App.GetChannelMember(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
|
||||
assert.Nil(t, channel1MError, "User is not a member of channel 1")
|
||||
assert.NotEqual(
|
||||
@@ -46,7 +45,7 @@ func TestMuteCommandNoArgs(t *testing.T) {
|
||||
defer th.tearDown()
|
||||
|
||||
channel1 := th.BasicChannel
|
||||
channel1M, _ := th.App.GetChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
channel1M, _ := th.App.GetChannelMember(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
|
||||
assert.Equal(t, model.ChannelNotifyAll, channel1M.NotifyProps[model.MarkUnreadNotifyProp])
|
||||
|
||||
@@ -88,7 +87,7 @@ func TestMuteCommandSpecificChannel(t *testing.T) {
|
||||
CreatorId: th.BasicUser.Id,
|
||||
}, true)
|
||||
|
||||
channel2M, _ := th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
channel2M, _ := th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
|
||||
assert.Equal(t, model.ChannelNotifyAll, channel2M.NotifyProps[model.MarkUnreadNotifyProp])
|
||||
|
||||
@@ -101,7 +100,7 @@ func TestMuteCommandSpecificChannel(t *testing.T) {
|
||||
UserId: th.BasicUser.Id,
|
||||
}, channel2.Name)
|
||||
assert.Equal(t, "api.command_mute.success_mute", resp.Text)
|
||||
channel2M, _ = th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
channel2M, _ = th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
assert.Equal(t, model.ChannelNotifyMention, channel2M.NotifyProps[model.MarkUnreadNotifyProp])
|
||||
|
||||
// Now unmute the channel
|
||||
@@ -112,7 +111,7 @@ func TestMuteCommandSpecificChannel(t *testing.T) {
|
||||
}, "~"+channel2.Name)
|
||||
|
||||
assert.Equal(t, "api.command_mute.success_unmute", resp.Text)
|
||||
channel2M, _ = th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
channel2M, _ = th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
assert.Equal(t, model.ChannelNotifyAll, channel2M.NotifyProps[model.MarkUnreadNotifyProp])
|
||||
}
|
||||
|
||||
@@ -174,7 +173,7 @@ func TestMuteCommandDMChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
channel2, _ := th.App.GetOrCreateDirectChannel(th.Context, th.BasicUser.Id, th.BasicUser2.Id)
|
||||
channel2M, _ := th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
channel2M, _ := th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
|
||||
assert.Equal(t, model.ChannelNotifyAll, channel2M.NotifyProps[model.MarkUnreadNotifyProp])
|
||||
|
||||
@@ -188,7 +187,7 @@ func TestMuteCommandDMChannel(t *testing.T) {
|
||||
}, "")
|
||||
assert.Equal(t, "api.command_mute.success_mute_direct_msg", resp.Text)
|
||||
time.Sleep(time.Millisecond)
|
||||
channel2M, _ = th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
channel2M, _ = th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
assert.Equal(t, model.ChannelNotifyMention, channel2M.NotifyProps[model.MarkUnreadNotifyProp])
|
||||
|
||||
// Now unmute the channel
|
||||
@@ -200,6 +199,6 @@ func TestMuteCommandDMChannel(t *testing.T) {
|
||||
|
||||
assert.Equal(t, "api.command_mute.success_unmute_direct_msg", resp.Text)
|
||||
time.Sleep(time.Millisecond)
|
||||
channel2M, _ = th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
channel2M, _ = th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
assert.Equal(t, model.ChannelNotifyAll, channel2M.NotifyProps[model.MarkUnreadNotifyProp])
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
package slashcommands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app"
|
||||
@@ -67,7 +66,7 @@ func (*KickProvider) DoCommand(a *app.App, c *request.Context, args *model.Comma
|
||||
}
|
||||
|
||||
func doCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
channel, err := a.GetChannel(args.ChannelId)
|
||||
channel, err := a.GetChannel(c, args.ChannelId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_channel_remove.channel.app_error"),
|
||||
@@ -77,14 +76,14 @@ func doCommand(a *app.App, c *request.Context, args *model.CommandArgs, message
|
||||
|
||||
switch channel.Type {
|
||||
case model.ChannelTypeOpen:
|
||||
if !a.HasPermissionToChannel(args.UserId, args.ChannelId, model.PermissionManagePublicChannelMembers) {
|
||||
if !a.HasPermissionToChannel(c, args.UserId, args.ChannelId, model.PermissionManagePublicChannelMembers) {
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_remove.permission.app_error"),
|
||||
ResponseType: model.CommandResponseTypeEphemeral,
|
||||
}
|
||||
}
|
||||
case model.ChannelTypePrivate:
|
||||
if !a.HasPermissionToChannel(args.UserId, args.ChannelId, model.PermissionManagePrivateChannelMembers) {
|
||||
if !a.HasPermissionToChannel(c, args.UserId, args.ChannelId, model.PermissionManagePrivateChannelMembers) {
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_remove.permission.app_error"),
|
||||
ResponseType: model.CommandResponseTypeEphemeral,
|
||||
@@ -124,7 +123,7 @@ func doCommand(a *app.App, c *request.Context, args *model.CommandArgs, message
|
||||
}
|
||||
}
|
||||
|
||||
_, err = a.GetChannelMember(context.Background(), args.ChannelId, userProfile.Id)
|
||||
_, err = a.GetChannelMember(c, args.ChannelId, userProfile.Id)
|
||||
if err != nil {
|
||||
nameFormat := *a.Config().TeamSettings.TeammateNameDisplay
|
||||
return &model.CommandResponse{
|
||||
|
||||
@@ -35,8 +35,8 @@ func TestRemoveProviderDoCommand(t *testing.T) {
|
||||
|
||||
targetUser := th.createUser()
|
||||
th.App.AddUserToTeam(th.Context, th.BasicTeam.Id, targetUser.Id, targetUser.Id)
|
||||
th.App.AddUserToChannel(targetUser, publicChannel, false)
|
||||
th.App.AddUserToChannel(targetUser, privateChannel, false)
|
||||
th.App.AddUserToChannel(th.Context, targetUser, publicChannel, false)
|
||||
th.App.AddUserToChannel(th.Context, targetUser, privateChannel, false)
|
||||
|
||||
// Try a public channel *without* permission.
|
||||
args := &model.CommandArgs{
|
||||
@@ -49,7 +49,7 @@ func TestRemoveProviderDoCommand(t *testing.T) {
|
||||
assert.Equal(t, "api.command_remove.permission.app_error", actual)
|
||||
|
||||
// Try a public channel *with* permission.
|
||||
th.App.AddUserToChannel(th.BasicUser, publicChannel, false)
|
||||
th.App.AddUserToChannel(th.Context, th.BasicUser, publicChannel, false)
|
||||
args = &model.CommandArgs{
|
||||
T: func(s string, args ...any) string { return s },
|
||||
ChannelId: publicChannel.Id,
|
||||
@@ -70,7 +70,7 @@ func TestRemoveProviderDoCommand(t *testing.T) {
|
||||
assert.Equal(t, "api.command_remove.permission.app_error", actual)
|
||||
|
||||
// Try a private channel *with* permission.
|
||||
th.App.AddUserToChannel(th.BasicUser, privateChannel, false)
|
||||
th.App.AddUserToChannel(th.Context, th.BasicUser, privateChannel, false)
|
||||
args = &model.CommandArgs{
|
||||
T: func(s string, args ...any) string { return s },
|
||||
ChannelId: privateChannel.Id,
|
||||
@@ -110,7 +110,7 @@ func TestRemoveProviderDoCommand(t *testing.T) {
|
||||
// Try a public channel with a deactivated user.
|
||||
deactivatedUser := th.createUser()
|
||||
th.App.AddUserToTeam(th.Context, th.BasicTeam.Id, deactivatedUser.Id, deactivatedUser.Id)
|
||||
th.App.AddUserToChannel(deactivatedUser, publicChannel, false)
|
||||
th.App.AddUserToChannel(th.Context, deactivatedUser, publicChannel, false)
|
||||
th.App.UpdateActive(th.Context, deactivatedUser, false)
|
||||
|
||||
args = &model.CommandArgs{
|
||||
|
||||
@@ -59,11 +59,11 @@ func (sp *ShareProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Com
|
||||
}
|
||||
}
|
||||
|
||||
func (sp *ShareProvider) GetAutoCompleteListItems(a *app.App, commandArgs *model.CommandArgs, arg *model.AutocompleteArg, parsed, toBeParsed string) ([]model.AutocompleteListItem, error) {
|
||||
func (sp *ShareProvider) GetAutoCompleteListItems(c request.CTX, a *app.App, commandArgs *model.CommandArgs, arg *model.AutocompleteArg, parsed, toBeParsed string) ([]model.AutocompleteListItem, error) {
|
||||
switch {
|
||||
case strings.Contains(parsed, " share "):
|
||||
|
||||
return sp.getAutoCompleteShareChannel(a, commandArgs, arg)
|
||||
return sp.getAutoCompleteShareChannel(c, a, commandArgs, arg)
|
||||
|
||||
case strings.Contains(parsed, " invite "):
|
||||
|
||||
@@ -77,8 +77,8 @@ func (sp *ShareProvider) GetAutoCompleteListItems(a *app.App, commandArgs *model
|
||||
return nil, errors.New("invalid action")
|
||||
}
|
||||
|
||||
func (sp *ShareProvider) getAutoCompleteShareChannel(a *app.App, commandArgs *model.CommandArgs, arg *model.AutocompleteArg) ([]model.AutocompleteListItem, error) {
|
||||
channel, err := a.GetChannel(commandArgs.ChannelId)
|
||||
func (sp *ShareProvider) getAutoCompleteShareChannel(c request.CTX, a *app.App, commandArgs *model.CommandArgs, arg *model.AutocompleteArg) ([]model.AutocompleteListItem, error) {
|
||||
channel, err := a.GetChannel(c, commandArgs.ChannelId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -141,11 +141,11 @@ func (sp *ShareProvider) DoCommand(a *app.App, c *request.Context, args *model.C
|
||||
|
||||
switch action {
|
||||
case "share":
|
||||
return sp.doShareChannel(a, args, margs)
|
||||
return sp.doShareChannel(a, c, args, margs)
|
||||
case "unshare":
|
||||
return sp.doUnshareChannel(a, args, margs)
|
||||
case "invite":
|
||||
return sp.doInviteRemote(a, args, margs)
|
||||
return sp.doInviteRemote(a, c, args, margs)
|
||||
case "uninvite":
|
||||
return sp.doUninviteRemote(a, args, margs)
|
||||
case "status":
|
||||
@@ -154,9 +154,9 @@ func (sp *ShareProvider) DoCommand(a *app.App, c *request.Context, args *model.C
|
||||
return responsef(args.T("api.command_share.unknown_action", map[string]any{"Action": action, "Actions": AvailableShareActions}))
|
||||
}
|
||||
|
||||
func (sp *ShareProvider) doShareChannel(a *app.App, args *model.CommandArgs, margs map[string]string) *model.CommandResponse {
|
||||
func (sp *ShareProvider) doShareChannel(a *app.App, c request.CTX, args *model.CommandArgs, margs map[string]string) *model.CommandResponse {
|
||||
// check that channel exists.
|
||||
channel, errApp := a.GetChannel(args.ChannelId)
|
||||
channel, errApp := a.GetChannel(c, args.ChannelId)
|
||||
if errApp != nil {
|
||||
return responsef(args.T("api.command_share.share_channel.error", map[string]any{"Error": errApp.Error()}))
|
||||
}
|
||||
@@ -194,7 +194,7 @@ func (sp *ShareProvider) doShareChannel(a *app.App, args *model.CommandArgs, mar
|
||||
CreatorId: args.UserId,
|
||||
}
|
||||
|
||||
if _, err := a.SaveSharedChannel(sc); err != nil {
|
||||
if _, err := a.SaveSharedChannel(c, sc); err != nil {
|
||||
return responsef(args.T("api.command_share.share_channel.error", map[string]any{"Error": err.Error()}))
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ func (sp *ShareProvider) doUnshareChannel(a *app.App, args *model.CommandArgs, m
|
||||
return responsef("##### " + args.T("api.command_share.shared_channel_unavailable"))
|
||||
}
|
||||
|
||||
func (sp *ShareProvider) doInviteRemote(a *app.App, args *model.CommandArgs, margs map[string]string) (resp *model.CommandResponse) {
|
||||
func (sp *ShareProvider) doInviteRemote(a *app.App, c request.CTX, args *model.CommandArgs, margs map[string]string) (resp *model.CommandResponse) {
|
||||
remoteId, ok := margs["connectionID"]
|
||||
if !ok || remoteId == "" {
|
||||
return responsef(args.T("api.command_share.must_specify_valid_remote"))
|
||||
@@ -243,7 +243,7 @@ func (sp *ShareProvider) doInviteRemote(a *app.App, args *model.CommandArgs, mar
|
||||
}
|
||||
if !hasChan {
|
||||
// If it doesn't exist, then create it.
|
||||
resp2 := sp.doShareChannel(a, args, margs)
|
||||
resp2 := sp.doShareChannel(a, c, args, margs)
|
||||
// We modify the outgoing response by prepending the text
|
||||
// from the shareChannel response.
|
||||
defer func() {
|
||||
@@ -262,7 +262,7 @@ func (sp *ShareProvider) doInviteRemote(a *app.App, args *model.CommandArgs, mar
|
||||
return responsef(args.T("api.command_share.remote_id_invalid.error", map[string]any{"Error": appErr.Error()}))
|
||||
}
|
||||
|
||||
channel, errApp := a.GetChannel(args.ChannelId)
|
||||
channel, errApp := a.GetChannel(c, args.ChannelId)
|
||||
if errApp != nil {
|
||||
return responsef(args.T("api.command_share.channel_invite.error", map[string]any{"Name": rc.DisplayName, "Error": errApp.Error()}))
|
||||
}
|
||||
|
||||
@@ -50,8 +50,8 @@ func TestMoveCommand(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
|
||||
defer func() {
|
||||
th.App.PermanentDeleteTeam(sourceTeam)
|
||||
th.App.PermanentDeleteTeam(targetTeam)
|
||||
th.App.PermanentDeleteTeam(th.Context, sourceTeam)
|
||||
th.App.PermanentDeleteTeam(th.Context, targetTeam)
|
||||
}()
|
||||
|
||||
// Move a command and check the team is updated.
|
||||
@@ -610,7 +610,7 @@ func TestMentionsToPublicChannels(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, data := range fixture {
|
||||
actualMap := th.App.MentionsToPublicChannels(data.message, data.inTeam)
|
||||
actualMap := th.App.MentionsToPublicChannels(th.Context, data.message, data.inTeam)
|
||||
require.Equal(t, actualMap, data.expectedMap)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo
|
||||
|
||||
th := &TestHelper{
|
||||
App: app.New(app.ServerConnector(s.Channels())),
|
||||
Context: &request.Context{},
|
||||
Context: request.EmptyContext(testLogger),
|
||||
Server: s,
|
||||
LogBuffer: buffer,
|
||||
TestLogger: testLogger,
|
||||
@@ -280,7 +280,7 @@ func (th *TestHelper) createChannel(team *model.Team, channelType model.ChannelT
|
||||
|
||||
if channel.IsShared() {
|
||||
id := model.NewId()
|
||||
_, err := th.App.SaveSharedChannel(&model.SharedChannel{
|
||||
_, err := th.App.SaveSharedChannel(th.Context, &model.SharedChannel{
|
||||
ChannelId: channel.Id,
|
||||
TeamId: channel.TeamId,
|
||||
Home: false,
|
||||
@@ -327,7 +327,7 @@ func (th *TestHelper) createDmChannel(user *model.User) *model.Channel {
|
||||
func (th *TestHelper) createGroupChannel(user1 *model.User, user2 *model.User) *model.Channel {
|
||||
var err *model.AppError
|
||||
var channel *model.Channel
|
||||
if channel, err = th.App.CreateGroupChannel([]string{th.BasicUser.Id, user1.Id, user2.Id}, th.BasicUser.Id); err != nil {
|
||||
if channel, err = th.App.CreateGroupChannel(th.Context, []string{th.BasicUser.Id, user1.Id, user2.Id}, th.BasicUser.Id); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return channel
|
||||
@@ -358,7 +358,7 @@ func (th *TestHelper) linkUserToTeam(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)
|
||||
}
|
||||
|
||||
+3
-3
@@ -25,7 +25,7 @@ func (a *App) createDefaultChannelMemberships(c *request.Context, since int64, c
|
||||
}
|
||||
|
||||
for _, userChannel := range channelMembers {
|
||||
channel, err := a.GetChannel(userChannel.ChannelID)
|
||||
channel, err := a.GetChannel(c, userChannel.ChannelID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -179,7 +179,7 @@ func (a *App) deleteGroupConstrainedChannelMemberships(c *request.Context, chann
|
||||
}
|
||||
|
||||
for _, userChannel := range channelMembers {
|
||||
channel, err := a.GetChannel(userChannel.ChannelId)
|
||||
channel, err := a.GetChannel(c, userChannel.ChannelId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -250,6 +250,6 @@ func (a *App) SyncRolesAndMembership(c *request.Context, syncableID string, sync
|
||||
case model.GroupSyncableTypeChannel:
|
||||
a.createDefaultChannelMemberships(c, since, &syncableID, includeRemovedMembers)
|
||||
a.deleteGroupConstrainedChannelMemberships(c, &syncableID)
|
||||
a.ClearChannelMembersCache(syncableID)
|
||||
a.ClearChannelMembersCache(c, syncableID)
|
||||
}
|
||||
}
|
||||
|
||||
+17
-18
@@ -4,7 +4,6 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -114,7 +113,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("error retrieving team member: %s", err.Error())
|
||||
}
|
||||
_, err = th.App.GetChannelMember(context.Background(), practiceChannel.Id, singer1.Id)
|
||||
_, err = th.App.GetChannelMember(th.Context, practiceChannel.Id, singer1.Id)
|
||||
if err != nil {
|
||||
t.Errorf("error retrieving channel member: %s", err.Error())
|
||||
}
|
||||
@@ -129,7 +128,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
t.Errorf("expected %d team members but got %d", expected, actual)
|
||||
}
|
||||
|
||||
cMembersCount, err := th.App.GetChannelMemberCount(practiceChannel.Id)
|
||||
cMembersCount, err := th.App.GetChannelMemberCount(th.Context, practiceChannel.Id)
|
||||
if err != nil {
|
||||
t.Errorf("error retrieving team members: %s", err.Error())
|
||||
}
|
||||
@@ -143,7 +142,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
t.Errorf("wrong error: %s", err.Id)
|
||||
}
|
||||
|
||||
_, err = th.App.GetChannelMember(context.Background(), experimentsChannel.Id, scientist1.Id)
|
||||
_, err = th.App.GetChannelMember(th.Context, experimentsChannel.Id, scientist1.Id)
|
||||
if err.Id != "app.channel.get_member.missing.app_error" {
|
||||
t.Errorf("wrong error: %s", err.Id)
|
||||
}
|
||||
@@ -158,7 +157,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
t.Errorf("expected %d team members but got %d", expected, actual)
|
||||
}
|
||||
|
||||
cMembersCount, err = th.App.GetChannelMemberCount(experimentsChannel.Id)
|
||||
cMembersCount, err = th.App.GetChannelMemberCount(th.Context, experimentsChannel.Id)
|
||||
if err != nil {
|
||||
t.Errorf("error retrieving team members: %s", err.Error())
|
||||
}
|
||||
@@ -185,7 +184,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
t.Errorf("error retrieving team member: %s", err.Error())
|
||||
}
|
||||
|
||||
_, err = th.App.GetChannelMember(context.Background(), experimentsChannel.Id, scientist1.Id)
|
||||
_, err = th.App.GetChannelMember(th.Context, experimentsChannel.Id, scientist1.Id)
|
||||
if err.Id != "app.channel.get_member.missing.app_error" {
|
||||
t.Errorf("wrong error: %s", err.Id)
|
||||
}
|
||||
@@ -201,7 +200,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
}
|
||||
|
||||
expected = 0
|
||||
cMembersCount, err = th.App.GetChannelMemberCount(experimentsChannel.Id)
|
||||
cMembersCount, err = th.App.GetChannelMemberCount(th.Context, experimentsChannel.Id)
|
||||
if err != nil {
|
||||
t.Errorf("error retrieving team members: %s", err.Error())
|
||||
}
|
||||
@@ -223,7 +222,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
}
|
||||
|
||||
expected = 1
|
||||
cMembersCount, err = th.App.GetChannelMemberCount(experimentsChannel.Id)
|
||||
cMembersCount, err = th.App.GetChannelMemberCount(th.Context, experimentsChannel.Id)
|
||||
if err != nil {
|
||||
t.Errorf("error retrieving team members: %s", err.Error())
|
||||
}
|
||||
@@ -256,7 +255,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
t.Error("expected team member to remain deleted")
|
||||
}
|
||||
|
||||
_, err = th.App.GetChannelMember(context.Background(), practiceChannel.Id, singer1.Id)
|
||||
_, err = th.App.GetChannelMember(th.Context, practiceChannel.Id, singer1.Id)
|
||||
if err == nil {
|
||||
t.Error("Expected channel member to remain deleted")
|
||||
}
|
||||
@@ -311,7 +310,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
t.Errorf("failed to populate syncables: %s", pErr.Error())
|
||||
}
|
||||
|
||||
_, err = th.App.GetChannelMember(context.Background(), experimentsChannel.Id, scientist1.Id)
|
||||
_, err = th.App.GetChannelMember(th.Context, experimentsChannel.Id, scientist1.Id)
|
||||
if err == nil {
|
||||
t.Error("Expected channel member to remain deleted")
|
||||
}
|
||||
@@ -330,7 +329,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
}
|
||||
|
||||
// Channel member is re-added.
|
||||
_, err = th.App.GetChannelMember(context.Background(), experimentsChannel.Id, scientist1.Id)
|
||||
_, err = th.App.GetChannelMember(th.Context, experimentsChannel.Id, scientist1.Id)
|
||||
if err != nil {
|
||||
t.Errorf("expected channel member: %s", err.Error())
|
||||
}
|
||||
@@ -368,7 +367,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
require.NoError(t, pErr)
|
||||
|
||||
// Ensure only the restricted user was added to both the team and channel
|
||||
cMembersCount, err = th.App.GetChannelMemberCount(restrictedChannel.Id)
|
||||
cMembersCount, err = th.App.GetChannelMemberCount(th.Context, restrictedChannel.Id)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, cMembersCount, int64(1))
|
||||
tmembers, err := th.App.GetTeamMembers(restrictedTeam.Id, 0, 100, nil)
|
||||
@@ -406,7 +405,7 @@ func TestDeleteGroupMemberships(t *testing.T) {
|
||||
// make channel group-constrained
|
||||
channel := th.BasicChannel
|
||||
channel.GroupConstrained = model.NewBool(true)
|
||||
channel, err = th.App.UpdateChannel(channel)
|
||||
channel, err = th.App.UpdateChannel(th.Context, channel)
|
||||
require.Nil(t, err)
|
||||
require.True(t, *channel.GroupConstrained)
|
||||
|
||||
@@ -421,7 +420,7 @@ func TestDeleteGroupMemberships(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
require.Len(t, tmembers, 3)
|
||||
|
||||
cmemberCount, err := th.App.GetChannelMemberCount(th.BasicChannel.Id)
|
||||
cmemberCount, err := th.App.GetChannelMemberCount(th.Context, th.BasicChannel.Id)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, 3, int(cmemberCount))
|
||||
|
||||
@@ -439,7 +438,7 @@ func TestDeleteGroupMemberships(t *testing.T) {
|
||||
require.Len(t, tmembers, 1)
|
||||
require.Equal(t, th.SystemAdminUser.Id, tmembers[0].UserId)
|
||||
|
||||
cmembers, err := th.App.GetChannelMembersPage(channel.Id, 0, 99)
|
||||
cmembers, err := th.App.GetChannelMembersPage(th.Context, channel.Id, 0, 99)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, cmembers, 1)
|
||||
require.Equal(t, th.SystemAdminUser.Id, cmembers[0].UserId)
|
||||
@@ -451,9 +450,9 @@ func TestSyncSyncableRoles(t *testing.T) {
|
||||
|
||||
team := th.CreateTeam()
|
||||
|
||||
channel := th.CreateChannel(team)
|
||||
channel := th.CreateChannel(th.Context, team)
|
||||
channel.GroupConstrained = model.NewBool(true)
|
||||
channel, err := th.App.UpdateChannel(channel)
|
||||
channel, err := th.App.UpdateChannel(th.Context, channel)
|
||||
require.Nil(t, err)
|
||||
|
||||
user1 := th.CreateUser()
|
||||
@@ -506,7 +505,7 @@ func TestSyncSyncableRoles(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
require.True(t, tm.SchemeAdmin)
|
||||
|
||||
cm, err := th.App.GetChannelMember(context.Background(), channel.Id, user.Id)
|
||||
cm, err := th.App.GetChannelMember(th.Context, channel.Id, user.Id)
|
||||
require.Nil(t, err)
|
||||
require.True(t, cm.SchemeAdmin)
|
||||
}
|
||||
|
||||
+7
-7
@@ -697,7 +697,7 @@ func (a *App) AddUserToTeamByToken(c *request.Context, userID string, tokenID st
|
||||
}
|
||||
|
||||
for _, channel := range channels {
|
||||
_, err := a.AddUserToChannel(user, channel, false)
|
||||
_, err := a.AddUserToChannel(c, user, channel, false)
|
||||
if err != nil {
|
||||
mlog.Warn("Error adding user to channel", mlog.Err(err))
|
||||
}
|
||||
@@ -1193,7 +1193,7 @@ func (a *App) RemoveUserFromTeam(c *request.Context, teamID string, userID strin
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) postProcessTeamMemberLeave(c *request.Context, teamMember *model.TeamMember, requestorId string) *model.AppError {
|
||||
func (a *App) postProcessTeamMemberLeave(c request.CTX, teamMember *model.TeamMember, requestorId string) *model.AppError {
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
var actor *model.User
|
||||
if requestorId != "" {
|
||||
@@ -1745,16 +1745,16 @@ func (a *App) GetTeamsUnreadForUser(excludeTeamId string, userID string, include
|
||||
return members, nil
|
||||
}
|
||||
|
||||
func (a *App) PermanentDeleteTeamId(teamID string) *model.AppError {
|
||||
func (a *App) PermanentDeleteTeamId(c request.CTX, teamID string) *model.AppError {
|
||||
team, err := a.GetTeam(teamID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return a.PermanentDeleteTeam(team)
|
||||
return a.PermanentDeleteTeam(c, team)
|
||||
}
|
||||
|
||||
func (a *App) PermanentDeleteTeam(team *model.Team) *model.AppError {
|
||||
func (a *App) PermanentDeleteTeam(c request.CTX, team *model.Team) *model.AppError {
|
||||
team.DeleteAt = model.GetMillis()
|
||||
if _, err := a.Srv().Store.Team().Update(team); err != nil {
|
||||
var invErr *store.ErrInvalidInput
|
||||
@@ -1775,8 +1775,8 @@ func (a *App) PermanentDeleteTeam(team *model.Team) *model.AppError {
|
||||
return model.NewAppError("PermanentDeleteTeam", "app.channel.get_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
} else {
|
||||
for _, c := range channels {
|
||||
a.PermanentDeleteChannel(c)
|
||||
for _, ch := range channels {
|
||||
a.PermanentDeleteChannel(c, ch)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-12
@@ -185,7 +185,7 @@ func TestAddUserToTeam(t *testing.T) {
|
||||
_, _, err := th.App.AddUserToTeam(th.Context, team.Id, user.Id, "")
|
||||
require.Nil(t, err)
|
||||
|
||||
res, err := th.App.GetSidebarCategoriesForTeamForUser(user.Id, team.Id)
|
||||
res, err := th.App.GetSidebarCategoriesForTeamForUser(th.Context, user.Id, team.Id)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, res.Categories, 3)
|
||||
assert.Equal(t, model.SidebarCategoryFavorites, res.Categories[0].Type)
|
||||
@@ -270,7 +270,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
||||
_, nErr := th.App.Srv().Store.Token().GetByToken(token.Token)
|
||||
require.Error(t, nErr, "The token must be deleted after be used")
|
||||
|
||||
members, err := th.App.GetChannelMembersForUser(th.BasicTeam.Id, ruser.Id)
|
||||
members, err := th.App.GetChannelMembersForUser(th.Context, th.BasicTeam.Id, ruser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, members, 2)
|
||||
})
|
||||
@@ -370,7 +370,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
||||
_, nErr := th.App.Srv().Store.Token().GetByToken(token.Token)
|
||||
require.Error(t, nErr, "The token must be deleted after be used")
|
||||
|
||||
members, err := th.App.GetChannelMembersForUser(th.BasicTeam.Id, rguest.Id)
|
||||
members, err := th.App.GetChannelMembersForUser(th.Context, th.BasicTeam.Id, rguest.Id)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, members, 1)
|
||||
assert.Equal(t, members[0].ChannelId, th.BasicChannel.Id)
|
||||
@@ -429,7 +429,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
||||
_, _, err := th.App.AddUserToTeamByToken(th.Context, user.Id, token.Token)
|
||||
require.Nil(t, err)
|
||||
|
||||
res, err := th.App.GetSidebarCategoriesForTeamForUser(user.Id, team.Id)
|
||||
res, err := th.App.GetSidebarCategoriesForTeamForUser(th.Context, user.Id, team.Id)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, res.Categories, 3)
|
||||
assert.Equal(t, model.SidebarCategoryFavorites, res.Categories[0].Type)
|
||||
@@ -670,7 +670,7 @@ func TestPermanentDeleteTeam(t *testing.T) {
|
||||
require.Nil(t, err, "Should create a team")
|
||||
|
||||
defer func() {
|
||||
th.App.PermanentDeleteTeam(team)
|
||||
th.App.PermanentDeleteTeam(th.Context, team)
|
||||
}()
|
||||
|
||||
command, err := th.App.CreateCommand(&model.Command{
|
||||
@@ -687,7 +687,7 @@ func TestPermanentDeleteTeam(t *testing.T) {
|
||||
require.NotNil(t, command, "command should not be nil")
|
||||
require.Nil(t, err, "unable to get new command")
|
||||
|
||||
err = th.App.PermanentDeleteTeam(team)
|
||||
err = th.App.PermanentDeleteTeam(th.Context, team)
|
||||
require.Nil(t, err)
|
||||
|
||||
command, err = th.App.GetCommand(command.Id)
|
||||
@@ -697,18 +697,18 @@ func TestPermanentDeleteTeam(t *testing.T) {
|
||||
// Test deleting a team with no channels.
|
||||
team = th.CreateTeam()
|
||||
defer func() {
|
||||
th.App.PermanentDeleteTeam(team)
|
||||
th.App.PermanentDeleteTeam(th.Context, team)
|
||||
}()
|
||||
|
||||
channels, err := th.App.GetPublicChannelsForTeam(team.Id, 0, 1000)
|
||||
channels, err := th.App.GetPublicChannelsForTeam(th.Context, team.Id, 0, 1000)
|
||||
require.Nil(t, err)
|
||||
|
||||
for _, channel := range channels {
|
||||
err2 := th.App.PermanentDeleteChannel(channel)
|
||||
err2 := th.App.PermanentDeleteChannel(th.Context, channel)
|
||||
require.Nil(t, err2)
|
||||
}
|
||||
|
||||
err = th.App.PermanentDeleteTeam(team)
|
||||
err = th.App.PermanentDeleteTeam(th.Context, team)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
@@ -929,7 +929,7 @@ func TestJoinUserToTeam(t *testing.T) {
|
||||
maxUsersPerTeam := th.App.Config().TeamSettings.MaxUsersPerTeam
|
||||
defer func() {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.MaxUsersPerTeam = maxUsersPerTeam })
|
||||
th.App.PermanentDeleteTeam(team)
|
||||
th.App.PermanentDeleteTeam(th.Context, team)
|
||||
}()
|
||||
one := 1
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.MaxUsersPerTeam = &one })
|
||||
@@ -1250,7 +1250,7 @@ func TestGetTeamStats(t *testing.T) {
|
||||
teamStats, err := th.App.GetTeamStats(th.BasicTeam.Id, restrictions)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, teamStats)
|
||||
members, err := th.App.GetChannelMembersPage(th.BasicChannel.Id, 0, 5)
|
||||
members, err := th.App.GetChannelMembersPage(th.Context, th.BasicChannel.Id, 0, 5)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, int64(len(members)), teamStats.TotalMemberCount)
|
||||
assert.Equal(t, int64(len(members)), teamStats.ActiveMemberCount)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user