MM-45193 Use context for channel logging (#20575)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
5f4da3f308
Коммит
6dc897b04f
@@ -10,6 +10,7 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app/request"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/services/remotecluster"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
@@ -156,7 +157,7 @@ func (scs *Service) onReceiveUploadCreate(msg model.RemoteClusterMsg, rc *model.
|
||||
us.RemoteId = rc.RemoteId // don't let remotes try to impersonate each other
|
||||
|
||||
// create upload session.
|
||||
usSaved, appErr := scs.app.CreateUploadSession(&us)
|
||||
usSaved, appErr := scs.app.CreateUploadSession(request.EmptyContext(scs.server.GetLogger()), &us)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ func (scs *Service) onReceiveChannelInvite(msg model.RemoteClusterMsg, rc *model
|
||||
}
|
||||
|
||||
if _, err := scs.server.GetStore().SharedChannel().Save(sharedChannel); err != nil {
|
||||
scs.app.PermanentDeleteChannel(channel)
|
||||
scs.app.PermanentDeleteChannel(request.EmptyContext(scs.server.GetLogger()), channel)
|
||||
return fmt.Errorf("cannot create shared channel (channel_id=%s): %w", invite.ChannelId, err)
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ func (scs *Service) onReceiveChannelInvite(msg model.RemoteClusterMsg, rc *model
|
||||
}
|
||||
|
||||
if _, err := scs.server.GetStore().SharedChannel().SaveRemote(sharedChannelRemote); err != nil {
|
||||
scs.app.PermanentDeleteChannel(channel)
|
||||
scs.app.PermanentDeleteChannel(request.EmptyContext(scs.server.GetLogger()), channel)
|
||||
scs.server.GetStore().SharedChannel().Delete(sharedChannel.ChannelId)
|
||||
return fmt.Errorf("cannot create shared channel remote (channel_id=%s): %w", invite.ChannelId, err)
|
||||
}
|
||||
@@ -197,7 +197,7 @@ func (scs *Service) handleChannelCreation(invite channelInviteMsg, rc *model.Rem
|
||||
}
|
||||
|
||||
// check user perms?
|
||||
channel, appErr := scs.app.CreateChannelWithUser(request.EmptyContext(), channelNew, rc.CreatorId)
|
||||
channel, appErr := scs.app.CreateChannelWithUser(request.EmptyContext(scs.server.GetLogger()), channelNew, rc.CreatorId)
|
||||
if appErr != nil {
|
||||
return nil, fmt.Errorf("cannot create channel `%s`: %w", invite.ChannelId, appErr)
|
||||
}
|
||||
@@ -210,7 +210,7 @@ func (scs *Service) createDirectChannel(invite channelInviteMsg) (*model.Channel
|
||||
return nil, fmt.Errorf("cannot create direct channel `%s` insufficient participant count `%d`", invite.ChannelId, len(invite.DirectParticipantIDs))
|
||||
}
|
||||
|
||||
channel, err := scs.app.GetOrCreateDirectChannel(request.EmptyContext(), invite.DirectParticipantIDs[0], invite.DirectParticipantIDs[1], model.WithID(invite.ChannelId))
|
||||
channel, err := scs.app.GetOrCreateDirectChannel(request.EmptyContext(scs.server.GetLogger()), invite.DirectParticipantIDs[0], invite.DirectParticipantIDs[1], model.WithID(invite.ChannelId))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot create direct channel `%s`: %w", invite.ChannelId, err)
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ func TestOnReceiveChannelInvite(t *testing.T) {
|
||||
Roles: &updateMap,
|
||||
},
|
||||
}
|
||||
mockApp.On("PatchChannelModerationsForChannel", channel, readonlyChannelModerations).Return(nil, nil)
|
||||
mockApp.On("PatchChannelModerationsForChannel", mock.Anything, channel, readonlyChannelModerations).Return(nil, nil)
|
||||
defer mockApp.AssertExpectations(t)
|
||||
|
||||
err = scs.onReceiveChannelInvite(msg, remoteCluster, nil)
|
||||
@@ -142,7 +142,7 @@ func TestOnReceiveChannelInvite(t *testing.T) {
|
||||
mockServer.On("GetStore").Return(mockStore)
|
||||
appErr := model.NewAppError("foo", "bar", nil, "boom", http.StatusBadRequest)
|
||||
|
||||
mockApp.On("PatchChannelModerationsForChannel", channel, mock.Anything).Return(nil, appErr)
|
||||
mockApp.On("PatchChannelModerationsForChannel", mock.Anything, channel, mock.Anything).Return(nil, appErr)
|
||||
defer mockApp.AssertExpectations(t)
|
||||
|
||||
err = scs.onReceiveChannelInvite(msg, remoteCluster, nil)
|
||||
|
||||
@@ -18,13 +18,13 @@ type MockAppIface struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
// AddUserToChannel provides a mock function with given fields: user, channel, skipTeamMemberIntegrityCheck
|
||||
func (_m *MockAppIface) AddUserToChannel(user *model.User, channel *model.Channel, skipTeamMemberIntegrityCheck bool) (*model.ChannelMember, *model.AppError) {
|
||||
ret := _m.Called(user, channel, skipTeamMemberIntegrityCheck)
|
||||
// AddUserToChannel provides a mock function with given fields: c, user, channel, skipTeamMemberIntegrityCheck
|
||||
func (_m *MockAppIface) AddUserToChannel(c request.CTX, user *model.User, channel *model.Channel, skipTeamMemberIntegrityCheck bool) (*model.ChannelMember, *model.AppError) {
|
||||
ret := _m.Called(c, user, channel, skipTeamMemberIntegrityCheck)
|
||||
|
||||
var r0 *model.ChannelMember
|
||||
if rf, ok := ret.Get(0).(func(*model.User, *model.Channel, bool) *model.ChannelMember); ok {
|
||||
r0 = rf(user, channel, skipTeamMemberIntegrityCheck)
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, *model.User, *model.Channel, bool) *model.ChannelMember); ok {
|
||||
r0 = rf(c, user, channel, skipTeamMemberIntegrityCheck)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.ChannelMember)
|
||||
@@ -32,8 +32,8 @@ func (_m *MockAppIface) AddUserToChannel(user *model.User, channel *model.Channe
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(*model.User, *model.Channel, bool) *model.AppError); ok {
|
||||
r1 = rf(user, channel, skipTeamMemberIntegrityCheck)
|
||||
if rf, ok := ret.Get(1).(func(request.CTX, *model.User, *model.Channel, bool) *model.AppError); ok {
|
||||
r1 = rf(c, user, channel, skipTeamMemberIntegrityCheck)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
@@ -60,11 +60,11 @@ func (_m *MockAppIface) AddUserToTeamByTeamId(c *request.Context, teamId string,
|
||||
}
|
||||
|
||||
// CreateChannelWithUser provides a mock function with given fields: c, channel, userId
|
||||
func (_m *MockAppIface) CreateChannelWithUser(c *request.Context, channel *model.Channel, userId string) (*model.Channel, *model.AppError) {
|
||||
func (_m *MockAppIface) CreateChannelWithUser(c request.CTX, channel *model.Channel, userId string) (*model.Channel, *model.AppError) {
|
||||
ret := _m.Called(c, channel, userId)
|
||||
|
||||
var r0 *model.Channel
|
||||
if rf, ok := ret.Get(0).(func(*request.Context, *model.Channel, string) *model.Channel); ok {
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, *model.Channel, string) *model.Channel); ok {
|
||||
r0 = rf(c, channel, userId)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
@@ -73,7 +73,7 @@ func (_m *MockAppIface) CreateChannelWithUser(c *request.Context, channel *model
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(*request.Context, *model.Channel, string) *model.AppError); ok {
|
||||
if rf, ok := ret.Get(1).(func(request.CTX, *model.Channel, string) *model.AppError); ok {
|
||||
r1 = rf(c, channel, userId)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
@@ -85,11 +85,11 @@ func (_m *MockAppIface) CreateChannelWithUser(c *request.Context, channel *model
|
||||
}
|
||||
|
||||
// CreatePost provides a mock function with given fields: c, post, channel, triggerWebhooks, setOnline
|
||||
func (_m *MockAppIface) CreatePost(c *request.Context, post *model.Post, channel *model.Channel, triggerWebhooks bool, setOnline bool) (*model.Post, *model.AppError) {
|
||||
func (_m *MockAppIface) CreatePost(c request.CTX, post *model.Post, channel *model.Channel, triggerWebhooks bool, setOnline bool) (*model.Post, *model.AppError) {
|
||||
ret := _m.Called(c, post, channel, triggerWebhooks, setOnline)
|
||||
|
||||
var r0 *model.Post
|
||||
if rf, ok := ret.Get(0).(func(*request.Context, *model.Post, *model.Channel, bool, bool) *model.Post); ok {
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, *model.Post, *model.Channel, bool, bool) *model.Post); ok {
|
||||
r0 = rf(c, post, channel, triggerWebhooks, setOnline)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
@@ -98,7 +98,7 @@ func (_m *MockAppIface) CreatePost(c *request.Context, post *model.Post, channel
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(*request.Context, *model.Post, *model.Channel, bool, bool) *model.AppError); ok {
|
||||
if rf, ok := ret.Get(1).(func(request.CTX, *model.Post, *model.Channel, bool, bool) *model.AppError); ok {
|
||||
r1 = rf(c, post, channel, triggerWebhooks, setOnline)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
@@ -109,13 +109,13 @@ func (_m *MockAppIface) CreatePost(c *request.Context, post *model.Post, channel
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// CreateUploadSession provides a mock function with given fields: us
|
||||
func (_m *MockAppIface) CreateUploadSession(us *model.UploadSession) (*model.UploadSession, *model.AppError) {
|
||||
ret := _m.Called(us)
|
||||
// CreateUploadSession provides a mock function with given fields: c, us
|
||||
func (_m *MockAppIface) CreateUploadSession(c request.CTX, us *model.UploadSession) (*model.UploadSession, *model.AppError) {
|
||||
ret := _m.Called(c, us)
|
||||
|
||||
var r0 *model.UploadSession
|
||||
if rf, ok := ret.Get(0).(func(*model.UploadSession) *model.UploadSession); ok {
|
||||
r0 = rf(us)
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, *model.UploadSession) *model.UploadSession); ok {
|
||||
r0 = rf(c, us)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.UploadSession)
|
||||
@@ -123,8 +123,8 @@ func (_m *MockAppIface) CreateUploadSession(us *model.UploadSession) (*model.Upl
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(*model.UploadSession) *model.AppError); ok {
|
||||
r1 = rf(us)
|
||||
if rf, ok := ret.Get(1).(func(request.CTX, *model.UploadSession) *model.AppError); ok {
|
||||
r1 = rf(c, us)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
@@ -134,13 +134,13 @@ func (_m *MockAppIface) CreateUploadSession(us *model.UploadSession) (*model.Upl
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// DeletePost provides a mock function with given fields: postID, deleteByID
|
||||
func (_m *MockAppIface) DeletePost(postID string, deleteByID string) (*model.Post, *model.AppError) {
|
||||
ret := _m.Called(postID, deleteByID)
|
||||
// DeletePost provides a mock function with given fields: c, postID, deleteByID
|
||||
func (_m *MockAppIface) DeletePost(c request.CTX, postID string, deleteByID string) (*model.Post, *model.AppError) {
|
||||
ret := _m.Called(c, postID, deleteByID)
|
||||
|
||||
var r0 *model.Post
|
||||
if rf, ok := ret.Get(0).(func(string, string) *model.Post); ok {
|
||||
r0 = rf(postID, deleteByID)
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, string, string) *model.Post); ok {
|
||||
r0 = rf(c, postID, deleteByID)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.Post)
|
||||
@@ -148,8 +148,8 @@ func (_m *MockAppIface) DeletePost(postID string, deleteByID string) (*model.Pos
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok {
|
||||
r1 = rf(postID, deleteByID)
|
||||
if rf, ok := ret.Get(1).(func(request.CTX, string, string) *model.AppError); ok {
|
||||
r1 = rf(c, postID, deleteByID)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
@@ -201,7 +201,7 @@ func (_m *MockAppIface) FileReader(path string) (filestore.ReadCloseSeeker, *mod
|
||||
}
|
||||
|
||||
// GetOrCreateDirectChannel provides a mock function with given fields: c, userId, otherUserId, channelOptions
|
||||
func (_m *MockAppIface) GetOrCreateDirectChannel(c *request.Context, userId string, otherUserId string, channelOptions ...model.ChannelOption) (*model.Channel, *model.AppError) {
|
||||
func (_m *MockAppIface) GetOrCreateDirectChannel(c request.CTX, userId string, otherUserId string, channelOptions ...model.ChannelOption) (*model.Channel, *model.AppError) {
|
||||
_va := make([]interface{}, len(channelOptions))
|
||||
for _i := range channelOptions {
|
||||
_va[_i] = channelOptions[_i]
|
||||
@@ -212,7 +212,7 @@ func (_m *MockAppIface) GetOrCreateDirectChannel(c *request.Context, userId stri
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
var r0 *model.Channel
|
||||
if rf, ok := ret.Get(0).(func(*request.Context, string, string, ...model.ChannelOption) *model.Channel); ok {
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, string, string, ...model.ChannelOption) *model.Channel); ok {
|
||||
r0 = rf(c, userId, otherUserId, channelOptions...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
@@ -221,7 +221,7 @@ func (_m *MockAppIface) GetOrCreateDirectChannel(c *request.Context, userId stri
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(*request.Context, string, string, ...model.ChannelOption) *model.AppError); ok {
|
||||
if rf, ok := ret.Get(1).(func(request.CTX, string, string, ...model.ChannelOption) *model.AppError); ok {
|
||||
r1 = rf(c, userId, otherUserId, channelOptions...)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
@@ -290,13 +290,13 @@ func (_m *MockAppIface) NotifySharedChannelUserUpdate(user *model.User) {
|
||||
_m.Called(user)
|
||||
}
|
||||
|
||||
// PatchChannelModerationsForChannel provides a mock function with given fields: channel, channelModerationsPatch
|
||||
func (_m *MockAppIface) PatchChannelModerationsForChannel(channel *model.Channel, channelModerationsPatch []*model.ChannelModerationPatch) ([]*model.ChannelModeration, *model.AppError) {
|
||||
ret := _m.Called(channel, channelModerationsPatch)
|
||||
// PatchChannelModerationsForChannel provides a mock function with given fields: c, channel, channelModerationsPatch
|
||||
func (_m *MockAppIface) PatchChannelModerationsForChannel(c request.CTX, channel *model.Channel, channelModerationsPatch []*model.ChannelModerationPatch) ([]*model.ChannelModeration, *model.AppError) {
|
||||
ret := _m.Called(c, channel, channelModerationsPatch)
|
||||
|
||||
var r0 []*model.ChannelModeration
|
||||
if rf, ok := ret.Get(0).(func(*model.Channel, []*model.ChannelModerationPatch) []*model.ChannelModeration); ok {
|
||||
r0 = rf(channel, channelModerationsPatch)
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, *model.Channel, []*model.ChannelModerationPatch) []*model.ChannelModeration); ok {
|
||||
r0 = rf(c, channel, channelModerationsPatch)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.ChannelModeration)
|
||||
@@ -304,8 +304,8 @@ func (_m *MockAppIface) PatchChannelModerationsForChannel(channel *model.Channel
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(*model.Channel, []*model.ChannelModerationPatch) *model.AppError); ok {
|
||||
r1 = rf(channel, channelModerationsPatch)
|
||||
if rf, ok := ret.Get(1).(func(request.CTX, *model.Channel, []*model.ChannelModerationPatch) *model.AppError); ok {
|
||||
r1 = rf(c, channel, channelModerationsPatch)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
@@ -315,13 +315,13 @@ func (_m *MockAppIface) PatchChannelModerationsForChannel(channel *model.Channel
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PermanentDeleteChannel provides a mock function with given fields: channel
|
||||
func (_m *MockAppIface) PermanentDeleteChannel(channel *model.Channel) *model.AppError {
|
||||
ret := _m.Called(channel)
|
||||
// PermanentDeleteChannel provides a mock function with given fields: c, channel
|
||||
func (_m *MockAppIface) PermanentDeleteChannel(c request.CTX, channel *model.Channel) *model.AppError {
|
||||
ret := _m.Called(c, channel)
|
||||
|
||||
var r0 *model.AppError
|
||||
if rf, ok := ret.Get(0).(func(*model.Channel) *model.AppError); ok {
|
||||
r0 = rf(channel)
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, *model.Channel) *model.AppError); ok {
|
||||
r0 = rf(c, channel)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.AppError)
|
||||
@@ -356,13 +356,13 @@ func (_m *MockAppIface) SaveReactionForPost(c *request.Context, reaction *model.
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// SendEphemeralPost provides a mock function with given fields: userId, post
|
||||
func (_m *MockAppIface) SendEphemeralPost(userId string, post *model.Post) *model.Post {
|
||||
ret := _m.Called(userId, post)
|
||||
// SendEphemeralPost provides a mock function with given fields: c, userId, post
|
||||
func (_m *MockAppIface) SendEphemeralPost(c request.CTX, userId string, post *model.Post) *model.Post {
|
||||
ret := _m.Called(c, userId, post)
|
||||
|
||||
var r0 *model.Post
|
||||
if rf, ok := ret.Get(0).(func(string, *model.Post) *model.Post); ok {
|
||||
r0 = rf(userId, post)
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, string, *model.Post) *model.Post); ok {
|
||||
r0 = rf(c, userId, post)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.Post)
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin/plugintest/mock"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
"github.com/mattermost/mattermost-server/v6/store/storetest/mocks"
|
||||
"github.com/mattermost/mattermost-server/v6/utils"
|
||||
)
|
||||
@@ -33,9 +34,10 @@ func TestProcessPermalinkToRemote(t *testing.T) {
|
||||
|
||||
mockServer := scs.server.(*MockServerIface)
|
||||
mockServer.On("GetStore").Return(mockStore)
|
||||
mockServer.On("GetLogger").Return(mlog.NewLogger())
|
||||
|
||||
mockApp := scs.app.(*MockAppIface)
|
||||
mockApp.On("SendEphemeralPost", "user", mock.AnythingOfType("*model.Post")).Return(&model.Post{}).Times(1)
|
||||
mockApp.On("SendEphemeralPost", mock.Anything, "user", mock.AnythingOfType("*model.Post")).Return(&model.Post{}).Times(1)
|
||||
defer mockApp.AssertExpectations(t)
|
||||
|
||||
t.Run("same channel", func(t *testing.T) {
|
||||
|
||||
@@ -45,19 +45,19 @@ type ServerIface interface {
|
||||
}
|
||||
|
||||
type AppIface interface {
|
||||
SendEphemeralPost(userId string, post *model.Post) *model.Post
|
||||
CreateChannelWithUser(c *request.Context, channel *model.Channel, userId string) (*model.Channel, *model.AppError)
|
||||
GetOrCreateDirectChannel(c *request.Context, userId, otherUserId string, channelOptions ...model.ChannelOption) (*model.Channel, *model.AppError)
|
||||
AddUserToChannel(user *model.User, channel *model.Channel, skipTeamMemberIntegrityCheck bool) (*model.ChannelMember, *model.AppError)
|
||||
SendEphemeralPost(c request.CTX, userId string, post *model.Post) *model.Post
|
||||
CreateChannelWithUser(c request.CTX, channel *model.Channel, userId string) (*model.Channel, *model.AppError)
|
||||
GetOrCreateDirectChannel(c request.CTX, userId, otherUserId string, channelOptions ...model.ChannelOption) (*model.Channel, *model.AppError)
|
||||
AddUserToChannel(c request.CTX, user *model.User, channel *model.Channel, skipTeamMemberIntegrityCheck bool) (*model.ChannelMember, *model.AppError)
|
||||
AddUserToTeamByTeamId(c *request.Context, teamId string, user *model.User) *model.AppError
|
||||
PermanentDeleteChannel(channel *model.Channel) *model.AppError
|
||||
CreatePost(c *request.Context, post *model.Post, channel *model.Channel, triggerWebhooks bool, setOnline bool) (savedPost *model.Post, err *model.AppError)
|
||||
PermanentDeleteChannel(c request.CTX, channel *model.Channel) *model.AppError
|
||||
CreatePost(c request.CTX, post *model.Post, channel *model.Channel, triggerWebhooks bool, setOnline bool) (savedPost *model.Post, err *model.AppError)
|
||||
UpdatePost(c *request.Context, post *model.Post, safeUpdate bool) (*model.Post, *model.AppError)
|
||||
DeletePost(postID, deleteByID string) (*model.Post, *model.AppError)
|
||||
DeletePost(c request.CTX, postID, deleteByID string) (*model.Post, *model.AppError)
|
||||
SaveReactionForPost(c *request.Context, reaction *model.Reaction) (*model.Reaction, *model.AppError)
|
||||
DeleteReactionForPost(c *request.Context, reaction *model.Reaction) *model.AppError
|
||||
PatchChannelModerationsForChannel(channel *model.Channel, channelModerationsPatch []*model.ChannelModerationPatch) ([]*model.ChannelModeration, *model.AppError)
|
||||
CreateUploadSession(us *model.UploadSession) (*model.UploadSession, *model.AppError)
|
||||
PatchChannelModerationsForChannel(c request.CTX, channel *model.Channel, channelModerationsPatch []*model.ChannelModerationPatch) ([]*model.ChannelModeration, *model.AppError)
|
||||
CreateUploadSession(c request.CTX, us *model.UploadSession) (*model.UploadSession, *model.AppError)
|
||||
FileReader(path string) (filestore.ReadCloseSeeker, *model.AppError)
|
||||
MentionsToTeamMembers(message, teamID string) model.UserMentionMap
|
||||
GetProfileImage(user *model.User) ([]byte, bool, *model.AppError)
|
||||
@@ -166,7 +166,7 @@ func (scs *Service) sendEphemeralPost(channelId string, userId string, text stri
|
||||
Message: text,
|
||||
CreateAt: model.GetMillis(),
|
||||
}
|
||||
scs.app.SendEphemeralPost(userId, ephemeral)
|
||||
scs.app.SendEphemeralPost(request.EmptyContext(scs.server.GetLogger()), userId, ephemeral)
|
||||
}
|
||||
|
||||
// onClusterLeaderChange is called whenever the cluster leader may have changed.
|
||||
@@ -229,7 +229,7 @@ func (scs *Service) makeChannelReadOnly(channel *model.Channel) *model.AppError
|
||||
},
|
||||
}
|
||||
|
||||
_, err := scs.app.PatchChannelModerationsForChannel(channel, readonlyChannelModerations)
|
||||
_, err := scs.app.PatchChannelModerationsForChannel(request.EmptyContext(scs.server.GetLogger()), channel, readonlyChannelModerations)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -38,10 +38,10 @@ func (scs *Service) onReceiveSyncMessage(msg model.RemoteClusterMsg, rc *model.R
|
||||
if err := json.Unmarshal(msg.Payload, &sm); err != nil {
|
||||
return fmt.Errorf("invalid sync message: %w", err)
|
||||
}
|
||||
return scs.processSyncMessage(&sm, rc, response)
|
||||
return scs.processSyncMessage(request.EmptyContext(scs.server.GetLogger()), &sm, rc, response)
|
||||
}
|
||||
|
||||
func (scs *Service) processSyncMessage(syncMsg *syncMsg, rc *model.RemoteCluster, response *remotecluster.Response) error {
|
||||
func (scs *Service) processSyncMessage(c request.CTX, syncMsg *syncMsg, rc *model.RemoteCluster, response *remotecluster.Response) error {
|
||||
var channel *model.Channel
|
||||
var team *model.Team
|
||||
|
||||
@@ -68,7 +68,7 @@ func (scs *Service) processSyncMessage(syncMsg *syncMsg, rc *model.RemoteCluster
|
||||
|
||||
// add/update users before posts
|
||||
for _, user := range syncMsg.Users {
|
||||
if userSaved, err := scs.upsertSyncUser(user, channel, rc); err != nil {
|
||||
if userSaved, err := scs.upsertSyncUser(c, user, channel, rc); err != nil {
|
||||
scs.server.GetLogger().Log(mlog.LvlSharedChannelServiceError, "Error upserting sync user",
|
||||
mlog.String("remote", rc.Name),
|
||||
mlog.String("channel_id", syncMsg.ChannelId),
|
||||
@@ -165,7 +165,7 @@ func (scs *Service) processSyncMessage(syncMsg *syncMsg, rc *model.RemoteCluster
|
||||
return nil
|
||||
}
|
||||
|
||||
func (scs *Service) upsertSyncUser(user *model.User, channel *model.Channel, rc *model.RemoteCluster) (*model.User, error) {
|
||||
func (scs *Service) upsertSyncUser(c request.CTX, user *model.User, channel *model.Channel, rc *model.RemoteCluster) (*model.User, error) {
|
||||
var err error
|
||||
if user.RemoteId == nil || *user.RemoteId == "" {
|
||||
user.RemoteId = model.NewString(rc.RemoteId)
|
||||
@@ -208,12 +208,12 @@ func (scs *Service) upsertSyncUser(user *model.User, channel *model.Channel, rc
|
||||
// Instead of undoing what succeeded on any failure we simply do all steps each
|
||||
// time. AddUserToChannel & AddUserToTeamByTeamId do not error if user was already
|
||||
// added and exit quickly.
|
||||
if err := scs.app.AddUserToTeamByTeamId(request.EmptyContext(), channel.TeamId, userSaved); err != nil {
|
||||
if err := scs.app.AddUserToTeamByTeamId(request.EmptyContext(scs.server.GetLogger()), channel.TeamId, userSaved); err != nil {
|
||||
return nil, fmt.Errorf("error adding sync user to Team: %w", err)
|
||||
}
|
||||
|
||||
// add user to channel
|
||||
if _, err := scs.app.AddUserToChannel(userSaved, channel, false); err != nil {
|
||||
if _, err := scs.app.AddUserToChannel(c, userSaved, channel, false); err != nil {
|
||||
return nil, fmt.Errorf("error adding sync user to ChannelMembers: %w", err)
|
||||
}
|
||||
return userSaved, nil
|
||||
@@ -339,7 +339,7 @@ func (scs *Service) upsertSyncPost(post *model.Post, channel *model.Channel, rc
|
||||
|
||||
if rpost == nil {
|
||||
// post doesn't exist; create new one
|
||||
rpost, appErr = scs.app.CreatePost(request.EmptyContext(), post, channel, true, true)
|
||||
rpost, appErr = scs.app.CreatePost(request.EmptyContext(scs.server.GetLogger()), post, channel, true, true)
|
||||
if appErr == nil {
|
||||
scs.server.GetLogger().Log(mlog.LvlSharedChannelServiceDebug, "Created sync post",
|
||||
mlog.String("post_id", post.Id),
|
||||
@@ -348,7 +348,7 @@ func (scs *Service) upsertSyncPost(post *model.Post, channel *model.Channel, rc
|
||||
}
|
||||
} else if post.DeleteAt > 0 {
|
||||
// delete post
|
||||
rpost, appErr = scs.app.DeletePost(post.Id, post.UserId)
|
||||
rpost, appErr = scs.app.DeletePost(request.EmptyContext(scs.server.GetLogger()), post.Id, post.UserId)
|
||||
if appErr == nil {
|
||||
scs.server.GetLogger().Log(mlog.LvlSharedChannelServiceDebug, "Deleted sync post",
|
||||
mlog.String("post_id", post.Id),
|
||||
@@ -357,7 +357,7 @@ func (scs *Service) upsertSyncPost(post *model.Post, channel *model.Channel, rc
|
||||
}
|
||||
} else if post.EditAt > rpost.EditAt || post.Message != rpost.Message {
|
||||
// update post
|
||||
rpost, appErr = scs.app.UpdatePost(request.EmptyContext(), post, false)
|
||||
rpost, appErr = scs.app.UpdatePost(request.EmptyContext(scs.server.GetLogger()), post, false)
|
||||
if appErr == nil {
|
||||
scs.server.GetLogger().Log(mlog.LvlSharedChannelServiceDebug, "Updated sync post",
|
||||
mlog.String("post_id", post.Id),
|
||||
@@ -386,9 +386,9 @@ func (scs *Service) upsertSyncReaction(reaction *model.Reaction, rc *model.Remot
|
||||
reaction.RemoteId = model.NewString(rc.RemoteId)
|
||||
|
||||
if reaction.DeleteAt == 0 {
|
||||
savedReaction, appErr = scs.app.SaveReactionForPost(request.EmptyContext(), reaction)
|
||||
savedReaction, appErr = scs.app.SaveReactionForPost(request.EmptyContext(scs.server.GetLogger()), reaction)
|
||||
} else {
|
||||
appErr = scs.app.DeleteReactionForPost(request.EmptyContext(), reaction)
|
||||
appErr = scs.app.DeleteReactionForPost(request.EmptyContext(scs.server.GetLogger()), reaction)
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app/request"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/services/remotecluster"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/i18n"
|
||||
@@ -330,7 +331,7 @@ func (scs *Service) notifyRemoteOffline(posts []*model.Post, rc *model.RemoteClu
|
||||
Message: T("sharedchannel.cannot_deliver_post", map[string]any{"Remote": rc.DisplayName}),
|
||||
CreateAt: post.CreateAt + 1,
|
||||
}
|
||||
scs.app.SendEphemeralPost(post.UserId, ephemeral)
|
||||
scs.app.SendEphemeralPost(request.EmptyContext(scs.server.GetLogger()), post.UserId, ephemeral)
|
||||
|
||||
notified[post.UserId] = true
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"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"
|
||||
@@ -84,10 +85,10 @@ type slackComment struct {
|
||||
// Actions provides the actions that needs to be used for import slack data
|
||||
type Actions struct {
|
||||
UpdateActive func(*model.User, bool) (*model.User, *model.AppError)
|
||||
AddUserToChannel func(*model.User, *model.Channel, bool) (*model.ChannelMember, *model.AppError)
|
||||
AddUserToChannel func(request.CTX, *model.User, *model.Channel, bool) (*model.ChannelMember, *model.AppError)
|
||||
JoinUserToTeam func(*model.Team, *model.User, string) (*model.TeamMember, *model.AppError)
|
||||
CreateDirectChannel func(string, string, ...model.ChannelOption) (*model.Channel, *model.AppError)
|
||||
CreateGroupChannel func([]string) (*model.Channel, *model.AppError)
|
||||
CreateDirectChannel func(request.CTX, string, string, ...model.ChannelOption) (*model.Channel, *model.AppError)
|
||||
CreateGroupChannel func(request.CTX, []string) (*model.Channel, *model.AppError)
|
||||
CreateChannel func(*model.Channel, bool) (*model.Channel, *model.AppError)
|
||||
DoUploadFile func(time.Time, string, string, string, string, []byte) (*model.FileInfo, *model.AppError)
|
||||
GenerateThumbnailImage func(image.Image, string)
|
||||
@@ -114,7 +115,7 @@ func New(store store.Store, actions Actions, config *model.Config) *SlackImporte
|
||||
}
|
||||
}
|
||||
|
||||
func (si *SlackImporter) SlackImport(fileData multipart.File, fileSize int64, teamID string) (*model.AppError, *bytes.Buffer) {
|
||||
func (si *SlackImporter) SlackImport(c request.CTX, fileData multipart.File, fileSize int64, teamID string) (*model.AppError, *bytes.Buffer) {
|
||||
// Create log file
|
||||
log := bytes.NewBufferString(i18n.T("api.slackimport.slack_import.log"))
|
||||
|
||||
@@ -201,7 +202,7 @@ func (si *SlackImporter) SlackImport(fileData multipart.File, fileSize int64, te
|
||||
addedUsers := si.slackAddUsers(teamID, users, log)
|
||||
botUser := si.slackAddBotUser(teamID, log)
|
||||
|
||||
si.slackAddChannels(teamID, channels, posts, addedUsers, uploads, botUser, log)
|
||||
si.slackAddChannels(c, teamID, channels, posts, addedUsers, uploads, botUser, log)
|
||||
|
||||
if botUser != nil {
|
||||
si.deactivateSlackBotUser(botUser)
|
||||
@@ -549,14 +550,14 @@ func (si *SlackImporter) deactivateSlackBotUser(user *model.User) {
|
||||
}
|
||||
}
|
||||
|
||||
func (si *SlackImporter) addSlackUsersToChannel(members []string, users map[string]*model.User, channel *model.Channel, log *bytes.Buffer) {
|
||||
func (si *SlackImporter) addSlackUsersToChannel(c request.CTX, members []string, users map[string]*model.User, channel *model.Channel, log *bytes.Buffer) {
|
||||
for _, member := range members {
|
||||
user, ok := users[member]
|
||||
if !ok {
|
||||
log.WriteString(i18n.T("api.slackimport.slack_add_channels.failed_to_add_user", map[string]any{"Username": "?"}))
|
||||
continue
|
||||
}
|
||||
if _, err := si.actions.AddUserToChannel(user, channel, false); err != nil {
|
||||
if _, err := si.actions.AddUserToChannel(c, user, channel, false); err != nil {
|
||||
log.WriteString(i18n.T("api.slackimport.slack_add_channels.failed_to_add_user", map[string]any{"Username": user.Username}))
|
||||
}
|
||||
}
|
||||
@@ -586,7 +587,7 @@ func slackSanitiseChannelProperties(channel model.Channel) model.Channel {
|
||||
return channel
|
||||
}
|
||||
|
||||
func (si *SlackImporter) slackAddChannels(teamId string, slackchannels []slackChannel, posts map[string][]slackPost, users map[string]*model.User, uploads map[string]*zip.File, botUser *model.User, importerLog *bytes.Buffer) map[string]*model.Channel {
|
||||
func (si *SlackImporter) slackAddChannels(c request.CTX, teamId string, slackchannels []slackChannel, posts map[string][]slackPost, users map[string]*model.User, uploads map[string]*zip.File, botUser *model.User, importerLog *bytes.Buffer) map[string]*model.Channel {
|
||||
// Write Header
|
||||
importerLog.WriteString(i18n.T("api.slackimport.slack_add_channels.added"))
|
||||
importerLog.WriteString("=================\r\n\r\n")
|
||||
@@ -622,7 +623,7 @@ func (si *SlackImporter) slackAddChannels(teamId string, slackchannels []slackCh
|
||||
|
||||
if mChannel == nil {
|
||||
// Haven't found an existing channel to merge with. Try importing it as a new one.
|
||||
mChannel = si.oldImportChannel(&newChannel, sChannel, users)
|
||||
mChannel = si.oldImportChannel(c, &newChannel, sChannel, users)
|
||||
if mChannel == nil {
|
||||
mlog.Warn("Slack Import: Unable to import Slack channel.", mlog.String("channel_display_name", newChannel.DisplayName))
|
||||
importerLog.WriteString(i18n.T("api.slackimport.slack_add_channels.import_failed", map[string]any{"DisplayName": newChannel.DisplayName}))
|
||||
@@ -632,7 +633,7 @@ func (si *SlackImporter) slackAddChannels(teamId string, slackchannels []slackCh
|
||||
|
||||
// Members for direct and group channels are added during the creation of the channel in the oldImportChannel function
|
||||
if sChannel.Type == model.ChannelTypeOpen || sChannel.Type == model.ChannelTypePrivate {
|
||||
si.addSlackUsersToChannel(sChannel.Members, users, mChannel, importerLog)
|
||||
si.addSlackUsersToChannel(c, sChannel.Members, users, mChannel, importerLog)
|
||||
}
|
||||
importerLog.WriteString(newChannel.DisplayName + "\r\n")
|
||||
addedChannels[sChannel.Id] = mChannel
|
||||
@@ -722,7 +723,7 @@ func (si *SlackImporter) oldImportUser(team *model.Team, user *model.User) *mode
|
||||
return ruser
|
||||
}
|
||||
|
||||
func (si *SlackImporter) oldImportChannel(channel *model.Channel, sChannel slackChannel, users map[string]*model.User) *model.Channel {
|
||||
func (si *SlackImporter) oldImportChannel(c request.CTX, channel *model.Channel, sChannel slackChannel, users map[string]*model.User) *model.Channel {
|
||||
switch {
|
||||
case channel.Type == model.ChannelTypeDirect:
|
||||
if len(sChannel.Members) < 2 {
|
||||
@@ -734,7 +735,7 @@ func (si *SlackImporter) oldImportChannel(channel *model.Channel, sChannel slack
|
||||
mlog.Warn("Either or both of user ids not found in users.json. Ignoring.", mlog.String("id1", sChannel.Members[0]), mlog.String("id2", sChannel.Members[1]))
|
||||
return nil
|
||||
}
|
||||
sc, err := si.actions.CreateDirectChannel(u1.Id, u2.Id)
|
||||
sc, err := si.actions.CreateDirectChannel(c, u1.Id, u2.Id)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
@@ -757,7 +758,7 @@ func (si *SlackImporter) oldImportChannel(channel *model.Channel, sChannel slack
|
||||
if creator == nil {
|
||||
return nil
|
||||
}
|
||||
sc, err := si.actions.CreateGroupChannel(members)
|
||||
sc, err := si.actions.CreateGroupChannel(c, members)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -11,7 +11,9 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"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/storetest/mocks"
|
||||
)
|
||||
|
||||
@@ -325,6 +327,8 @@ func TestOldImportChannel(t *testing.T) {
|
||||
store := &mocks.Store{}
|
||||
config := &model.Config{}
|
||||
config.SetDefaults()
|
||||
ctx := &request.Context{}
|
||||
ctx.SetLogger(mlog.CreateConsoleTestLogger(true, mlog.LvlDebug))
|
||||
|
||||
t.Run("No panic on direct channel", func(t *testing.T) {
|
||||
// ch := th.CreateDmChannel(u1)
|
||||
@@ -344,7 +348,7 @@ func TestOldImportChannel(t *testing.T) {
|
||||
actions := Actions{}
|
||||
|
||||
importer := New(store, actions, config)
|
||||
_ = importer.oldImportChannel(ch, sCh, users)
|
||||
_ = importer.oldImportChannel(ctx, ch, sCh, users)
|
||||
})
|
||||
|
||||
t.Run("No panic on direct channel with 1 member", func(t *testing.T) {
|
||||
@@ -364,7 +368,7 @@ func TestOldImportChannel(t *testing.T) {
|
||||
actions := Actions{}
|
||||
|
||||
importer := New(store, actions, config)
|
||||
_ = importer.oldImportChannel(ch, sCh, users)
|
||||
_ = importer.oldImportChannel(ctx, ch, sCh, users)
|
||||
})
|
||||
|
||||
t.Run("No panic on group channel", func(t *testing.T) {
|
||||
@@ -383,6 +387,6 @@ func TestOldImportChannel(t *testing.T) {
|
||||
actions := Actions{}
|
||||
|
||||
importer := New(store, actions, config)
|
||||
_ = importer.oldImportChannel(ch, sCh, users)
|
||||
_ = importer.oldImportChannel(ctx, ch, sCh, users)
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user