mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
unparam lint (#16771)
* fixed: `identifier` is unused lint error * make saveMultipleMembersT method saveMultipleMembers Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
This commit is contained in:
12
api4/bot.go
12
api4/bot.go
@@ -183,15 +183,15 @@ func getBots(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write(bots.ToJson())
|
||||
}
|
||||
|
||||
func disableBot(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
updateBotActive(c, w, r, false)
|
||||
func disableBot(c *Context, w http.ResponseWriter, _ *http.Request) {
|
||||
updateBotActive(c, w, false)
|
||||
}
|
||||
|
||||
func enableBot(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
updateBotActive(c, w, r, true)
|
||||
func enableBot(c *Context, w http.ResponseWriter, _ *http.Request) {
|
||||
updateBotActive(c, w, true)
|
||||
}
|
||||
|
||||
func updateBotActive(c *Context, w http.ResponseWriter, r *http.Request, active bool) {
|
||||
func updateBotActive(c *Context, w http.ResponseWriter, active bool) {
|
||||
c.RequireBotUserId()
|
||||
if c.Err != nil {
|
||||
return
|
||||
@@ -220,7 +220,7 @@ func updateBotActive(c *Context, w http.ResponseWriter, r *http.Request, active
|
||||
w.Write(bot.ToJson())
|
||||
}
|
||||
|
||||
func assignBot(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
func assignBot(c *Context, w http.ResponseWriter, _ *http.Request) {
|
||||
c.RequireUserId()
|
||||
c.RequireBotUserId()
|
||||
if c.Err != nil {
|
||||
|
||||
14
api4/post.go
14
api4/post.go
@@ -372,7 +372,7 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(post.ToJson()))
|
||||
}
|
||||
|
||||
func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
func deletePost(c *Context, w http.ResponseWriter, _ *http.Request) {
|
||||
c.RequirePostId()
|
||||
if c.Err != nil {
|
||||
return
|
||||
@@ -639,7 +639,7 @@ func patchPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(patchedPost.ToJson()))
|
||||
}
|
||||
|
||||
func setPostUnread(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
func setPostUnread(c *Context, w http.ResponseWriter, _ *http.Request) {
|
||||
c.RequirePostId().RequireUserId()
|
||||
if c.Err != nil {
|
||||
return
|
||||
@@ -661,7 +661,7 @@ func setPostUnread(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(state.ToJson()))
|
||||
}
|
||||
|
||||
func saveIsPinnedPost(c *Context, w http.ResponseWriter, r *http.Request, isPinned bool) {
|
||||
func saveIsPinnedPost(c *Context, w http.ResponseWriter, isPinned bool) {
|
||||
c.RequirePostId()
|
||||
if c.Err != nil {
|
||||
return
|
||||
@@ -717,12 +717,12 @@ func saveIsPinnedPost(c *Context, w http.ResponseWriter, r *http.Request, isPinn
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
func pinPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
saveIsPinnedPost(c, w, r, true)
|
||||
func pinPost(c *Context, w http.ResponseWriter, _ *http.Request) {
|
||||
saveIsPinnedPost(c, w, true)
|
||||
}
|
||||
|
||||
func unpinPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
saveIsPinnedPost(c, w, r, false)
|
||||
func unpinPost(c *Context, w http.ResponseWriter, _ *http.Request) {
|
||||
saveIsPinnedPost(c, w, false)
|
||||
}
|
||||
|
||||
func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -5754,7 +5754,8 @@ func TestMaintainUnreadMentionsInThread(t *testing.T) {
|
||||
*cfg.ServiceSettings.ThreadAutoFollow = true
|
||||
*cfg.ServiceSettings.CollapsedThreads = model.COLLAPSED_THREADS_DEFAULT_ON
|
||||
})
|
||||
checkThreadList := func(client *model.Client4, userId string, expectedMentions, expectedThreads int) (*model.Threads, *model.Response) {
|
||||
|
||||
checkThreadList := func(client *model.Client4, userId string, expectedThreads int) (*model.Threads, *model.Response) {
|
||||
uss, resp := client.GetUserThreads(userId, th.BasicTeam.Id, model.GetUserThreadsOpts{
|
||||
Deleted: false,
|
||||
})
|
||||
@@ -5776,34 +5777,33 @@ func TestMaintainUnreadMentionsInThread(t *testing.T) {
|
||||
defer th.App.Srv().Store.Post().PermanentDeleteByUser(th.SystemAdminUser.Id)
|
||||
|
||||
// basic user 1 was mentioned 1 time
|
||||
checkThreadList(th.Client, th.BasicUser.Id, 1, 1)
|
||||
checkThreadList(th.Client, th.BasicUser.Id, 1)
|
||||
// basic user 2 was mentioned 1 time
|
||||
checkThreadList(th.SystemAdminClient, th.BasicUser2.Id, 1, 1)
|
||||
checkThreadList(th.SystemAdminClient, th.BasicUser2.Id, 1)
|
||||
|
||||
// test self mention, shouldn't increase mention count
|
||||
postAndCheck(t, Client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testReply @" + th.BasicUser.Username, RootId: rpost.Id})
|
||||
// count should increase
|
||||
checkThreadList(th.Client, th.BasicUser.Id, 1, 1)
|
||||
checkThreadList(th.Client, th.BasicUser.Id, 1)
|
||||
|
||||
// test DM
|
||||
dm := th.CreateDmChannel(th.SystemAdminUser)
|
||||
dm_root_post, _ := postAndCheck(t, Client, &model.Post{ChannelId: dm.Id, Message: "hi @" + th.SystemAdminUser.Username})
|
||||
|
||||
// no changes
|
||||
checkThreadList(th.Client, th.BasicUser.Id, 1, 1)
|
||||
checkThreadList(th.Client, th.BasicUser.Id, 1)
|
||||
|
||||
// post reply by the same user
|
||||
postAndCheck(t, Client, &model.Post{ChannelId: dm.Id, Message: "how are you", RootId: dm_root_post.Id})
|
||||
|
||||
// thread created
|
||||
checkThreadList(th.Client, th.BasicUser.Id, 1, 2)
|
||||
checkThreadList(th.Client, th.BasicUser.Id, 2)
|
||||
|
||||
// post two replies by another user, without mentions. mention count should still increase since this is a DM
|
||||
postAndCheck(t, th.SystemAdminClient, &model.Post{ChannelId: dm.Id, Message: "msg1", RootId: dm_root_post.Id})
|
||||
postAndCheck(t, th.SystemAdminClient, &model.Post{ChannelId: dm.Id, Message: "msg2", RootId: dm_root_post.Id})
|
||||
// expect increment by two mentions
|
||||
checkThreadList(th.Client, th.BasicUser.Id, 3, 2)
|
||||
|
||||
checkThreadList(th.Client, th.BasicUser.Id, 2)
|
||||
}
|
||||
|
||||
func TestReadThreads(t *testing.T) {
|
||||
|
||||
@@ -459,7 +459,7 @@ func (a *App) WaitForChannelMembership(channelId string, userId string) {
|
||||
}
|
||||
|
||||
func (a *App) CreateGroupChannel(userIds []string, creatorId string) (*model.Channel, *model.AppError) {
|
||||
channel, err := a.createGroupChannel(userIds, creatorId)
|
||||
channel, err := a.createGroupChannel(userIds)
|
||||
if err != nil {
|
||||
if err.Id == store.ChannelExistsError {
|
||||
return channel, nil
|
||||
@@ -482,7 +482,7 @@ func (a *App) CreateGroupChannel(userIds []string, creatorId string) (*model.Cha
|
||||
return channel, nil
|
||||
}
|
||||
|
||||
func (a *App) createGroupChannel(userIds []string, creatorId string) (*model.Channel, *model.AppError) {
|
||||
func (a *App) createGroupChannel(userIds []string) (*model.Channel, *model.AppError) {
|
||||
if len(userIds) > model.CHANNEL_GROUP_MAX_USERS || len(userIds) < model.CHANNEL_GROUP_MIN_USERS {
|
||||
return nil, model.NewAppError("CreateGroupChannel", "api.channel.create_group.bad_size.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
@@ -1285,7 +1285,7 @@ func (a *App) DeleteChannel(channel *model.Channel, userId string) *model.AppErr
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) addUserToChannel(user *model.User, channel *model.Channel, teamMember *model.TeamMember) (*model.ChannelMember, *model.AppError) {
|
||||
func (a *App) addUserToChannel(user *model.User, channel *model.Channel) (*model.ChannelMember, *model.AppError) {
|
||||
if channel.Type != model.CHANNEL_OPEN && channel.Type != model.CHANNEL_PRIVATE {
|
||||
return nil, model.NewAppError("AddUserToChannel", "api.channel.add_user_to_channel.type.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
@@ -1359,7 +1359,7 @@ func (a *App) AddUserToChannel(user *model.User, channel *model.Channel) (*model
|
||||
return nil, model.NewAppError("AddUserToChannel", "api.channel.add_user.to.channel.failed.deleted.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
newMember, err := a.addUserToChannel(user, channel, teamMember)
|
||||
newMember, err := a.addUserToChannel(user, channel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ func (es *EmailService) setupInviteEmailRateLimiting() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (es *EmailService) sendChangeUsernameEmail(oldUsername, newUsername, email, locale, siteURL string) *model.AppError {
|
||||
func (es *EmailService) sendChangeUsernameEmail(newUsername, email, locale, siteURL string) *model.AppError {
|
||||
T := utils.GetUserTranslations(locale)
|
||||
|
||||
subject := T("api.templates.username_change_subject",
|
||||
|
||||
@@ -808,7 +808,7 @@ func (a *App) importUserTeams(user *model.User, data *[]UserTeamImportData) *mod
|
||||
}
|
||||
}
|
||||
channelsToImport := channels[team.Id]
|
||||
if err := a.importUserChannels(user, team, teamMemberByTeamID[team.Id], &channelsToImport); err != nil {
|
||||
if err := a.importUserChannels(user, team, &channelsToImport); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -816,7 +816,7 @@ func (a *App) importUserTeams(user *model.User, data *[]UserTeamImportData) *mod
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) importUserChannels(user *model.User, team *model.Team, teamMember *model.TeamMember, data *[]UserChannelImportData) *model.AppError {
|
||||
func (a *App) importUserChannels(user *model.User, team *model.Team, data *[]UserChannelImportData) *model.AppError {
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -986,7 +986,7 @@ func (a *App) importUserChannels(user *model.User, team *model.Team, teamMember
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) importReaction(data *ReactionImportData, post *model.Post, dryRun bool) *model.AppError {
|
||||
func (a *App) importReaction(data *ReactionImportData, post *model.Post) *model.AppError {
|
||||
if err := validateReactionImportData(data, post.CreateAt); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1016,7 +1016,7 @@ func (a *App) importReaction(data *ReactionImportData, post *model.Post, dryRun
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) importReplies(data []ReplyImportData, post *model.Post, teamId string, dryRun bool) *model.AppError {
|
||||
func (a *App) importReplies(data []ReplyImportData, post *model.Post, teamId string) *model.AppError {
|
||||
var err *model.AppError
|
||||
usernames := []string{}
|
||||
for _, replyData := range data {
|
||||
@@ -1064,7 +1064,7 @@ func (a *App) importReplies(data []ReplyImportData, post *model.Post, teamId str
|
||||
reply.Message = *replyData.Message
|
||||
reply.CreateAt = *replyData.CreateAt
|
||||
|
||||
fileIds, err := a.uploadAttachments(replyData.Attachments, reply, teamId, dryRun)
|
||||
fileIds, err := a.uploadAttachments(replyData.Attachments, reply, teamId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1112,7 +1112,7 @@ func (a *App) importReplies(data []ReplyImportData, post *model.Post, teamId str
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) importAttachment(data *AttachmentImportData, post *model.Post, teamId string, dryRun bool) (*model.FileInfo, *model.AppError) {
|
||||
func (a *App) importAttachment(data *AttachmentImportData, post *model.Post, teamId string) (*model.FileInfo, *model.AppError) {
|
||||
file, err := os.Open(*data.Path)
|
||||
if file == nil || err != nil {
|
||||
return nil, model.NewAppError("BulkImport", "app.import.attachment.bad_file.error", map[string]interface{}{"FilePath": *data.Path}, "", http.StatusBadRequest)
|
||||
@@ -1319,7 +1319,7 @@ func (a *App) importMultiplePostLines(lines []LineImportWorkerData, dryRun bool)
|
||||
post.Props = *line.Post.Props
|
||||
}
|
||||
|
||||
fileIds, appErr := a.uploadAttachments(line.Post.Attachments, post, team.Id, dryRun)
|
||||
fileIds, appErr := a.uploadAttachments(line.Post.Attachments, post, team.Id)
|
||||
if appErr != nil {
|
||||
return line.LineNumber, appErr
|
||||
}
|
||||
@@ -1403,14 +1403,14 @@ func (a *App) importMultiplePostLines(lines []LineImportWorkerData, dryRun bool)
|
||||
if postWithData.postData.Reactions != nil {
|
||||
for _, reaction := range *postWithData.postData.Reactions {
|
||||
reaction := reaction
|
||||
if err := a.importReaction(&reaction, postWithData.post, dryRun); err != nil {
|
||||
if err := a.importReaction(&reaction, postWithData.post); err != nil {
|
||||
return postWithData.lineNumber, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if postWithData.postData.Replies != nil && len(*postWithData.postData.Replies) > 0 {
|
||||
err := a.importReplies(*postWithData.postData.Replies, postWithData.post, postWithData.team.Id, dryRun)
|
||||
err := a.importReplies(*postWithData.postData.Replies, postWithData.post, postWithData.team.Id)
|
||||
if err != nil {
|
||||
return postWithData.lineNumber, err
|
||||
}
|
||||
@@ -1421,14 +1421,14 @@ func (a *App) importMultiplePostLines(lines []LineImportWorkerData, dryRun bool)
|
||||
}
|
||||
|
||||
// uploadAttachments imports new attachments and returns current attachments of the post as a map
|
||||
func (a *App) uploadAttachments(attachments *[]AttachmentImportData, post *model.Post, teamId string, dryRun bool) (map[string]bool, *model.AppError) {
|
||||
func (a *App) uploadAttachments(attachments *[]AttachmentImportData, post *model.Post, teamId string) (map[string]bool, *model.AppError) {
|
||||
if attachments == nil {
|
||||
return nil, nil
|
||||
}
|
||||
fileIds := make(map[string]bool)
|
||||
for _, attachment := range *attachments {
|
||||
attachment := attachment
|
||||
fileInfo, err := a.importAttachment(&attachment, post, teamId, dryRun)
|
||||
fileInfo, err := a.importAttachment(&attachment, post, teamId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1473,7 +1473,7 @@ func (a *App) importDirectChannel(data *DirectChannelImportData, dryRun bool) *m
|
||||
}
|
||||
channel = ch
|
||||
} else {
|
||||
ch, err := a.createGroupChannel(userIds, userIds[0])
|
||||
ch, err := a.createGroupChannel(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)
|
||||
}
|
||||
@@ -1578,7 +1578,7 @@ func (a *App) importMultipleDirectPostLines(lines []LineImportWorkerData, dryRun
|
||||
}
|
||||
channel = ch
|
||||
} else {
|
||||
ch, err = a.createGroupChannel(userIds, userIds[0])
|
||||
ch, err = a.createGroupChannel(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)
|
||||
}
|
||||
@@ -1615,7 +1615,7 @@ func (a *App) importMultipleDirectPostLines(lines []LineImportWorkerData, dryRun
|
||||
post.Props = *line.DirectPost.Props
|
||||
}
|
||||
|
||||
fileIds, err := a.uploadAttachments(line.DirectPost.Attachments, post, "noteam", dryRun)
|
||||
fileIds, err := a.uploadAttachments(line.DirectPost.Attachments, post, "noteam")
|
||||
if err != nil {
|
||||
return line.LineNumber, err
|
||||
}
|
||||
@@ -1697,14 +1697,14 @@ func (a *App) importMultipleDirectPostLines(lines []LineImportWorkerData, dryRun
|
||||
if postWithData.directPostData.Reactions != nil {
|
||||
for _, reaction := range *postWithData.directPostData.Reactions {
|
||||
reaction := reaction
|
||||
if err := a.importReaction(&reaction, postWithData.post, dryRun); err != nil {
|
||||
if err := a.importReaction(&reaction, postWithData.post); err != nil {
|
||||
return postWithData.lineNumber, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if postWithData.directPostData.Replies != nil {
|
||||
if err := a.importReplies(*postWithData.directPostData.Replies, postWithData.post, "noteam", dryRun); err != nil {
|
||||
if err := a.importReplies(*postWithData.directPostData.Replies, postWithData.post, "noteam"); err != nil {
|
||||
return postWithData.lineNumber, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1856,16 +1856,14 @@ func TestImportUserChannels(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
user := th.CreateUser()
|
||||
th.App.joinUserToTeam(th.BasicTeam, user)
|
||||
teamMember, err := th.App.GetTeamMember(th.BasicTeam.Id, user.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
// Two times import must end with the same results
|
||||
for x := 0; x < 2; x++ {
|
||||
err = th.App.importUserChannels(user, th.BasicTeam, teamMember, tc.data)
|
||||
appErr := th.App.importUserChannels(user, th.BasicTeam, tc.data)
|
||||
if tc.expectedError {
|
||||
require.NotNil(t, err)
|
||||
require.NotNil(t, appErr)
|
||||
} else {
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, appErr)
|
||||
}
|
||||
channelMembers, err := th.App.Srv().Store.Channel().GetMembersForUser(th.BasicTeam.Id, user.Id)
|
||||
require.Nil(t, err)
|
||||
@@ -3101,7 +3099,7 @@ func TestImportImportDirectChannel(t *testing.T) {
|
||||
th.BasicUser2.Id,
|
||||
user3.Id,
|
||||
}
|
||||
channel, appErr := th.App.createGroupChannel(userIds, th.BasicUser.Id)
|
||||
channel, appErr := th.App.createGroupChannel(userIds)
|
||||
require.Equal(t, appErr.Id, store.ChannelExistsError)
|
||||
require.Equal(t, channel.Header, *data.Header)
|
||||
|
||||
@@ -3402,7 +3400,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
th.BasicUser2.Id,
|
||||
user3.Id,
|
||||
}
|
||||
channel, appErr = th.App.createGroupChannel(userIds, th.BasicUser.Id)
|
||||
channel, appErr = th.App.createGroupChannel(userIds)
|
||||
require.Equal(t, appErr.Id, store.ChannelExistsError)
|
||||
groupChannel = channel
|
||||
|
||||
@@ -3893,14 +3891,14 @@ func TestImportAttachment(t *testing.T) {
|
||||
|
||||
userId := model.NewId()
|
||||
data := AttachmentImportData{Path: &testImage}
|
||||
_, err := th.App.importAttachment(&data, &model.Post{UserId: userId, ChannelId: "some-channel"}, "some-team", true)
|
||||
_, err := th.App.importAttachment(&data, &model.Post{UserId: userId, ChannelId: "some-channel"}, "some-team")
|
||||
assert.Nil(t, err, "sample run without errors")
|
||||
|
||||
attachments := GetAttachments(userId, th, t)
|
||||
assert.Len(t, attachments, 1)
|
||||
|
||||
data = AttachmentImportData{Path: &invalidPath}
|
||||
_, err = th.App.importAttachment(&data, &model.Post{UserId: model.NewId(), ChannelId: "some-channel"}, "some-team", true)
|
||||
_, err = th.App.importAttachment(&data, &model.Post{UserId: model.NewId(), ChannelId: "some-channel"}, "some-team")
|
||||
assert.NotNil(t, err, "should have failed when opening the file")
|
||||
assert.Equal(t, err.Id, "app.import.attachment.bad_file.error")
|
||||
}
|
||||
|
||||
@@ -160,8 +160,8 @@ func (a *App) sendPushNotification(notification *PostNotification, user *model.U
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) getPushNotificationMessage(contentsConfig, postMessage string, explicitMention, channelWideMention, hasFiles bool,
|
||||
senderName, channelName, channelType, replyToThreadType string, userLocale i18n.TranslateFunc) string {
|
||||
func (a *App) getPushNotificationMessage(contentsConfig, postMessage string, explicitMention, channelWideMention,
|
||||
hasFiles bool, senderName, channelType, replyToThreadType string, userLocale i18n.TranslateFunc) string {
|
||||
|
||||
// If the post only has images then push an appropriate message
|
||||
if postMessage == "" && hasFiles {
|
||||
@@ -591,7 +591,17 @@ func (a *App) buildFullPushNotificationMessage(contentsConfig string, post *mode
|
||||
userLocale := utils.GetUserTranslations(user.Locale)
|
||||
hasFiles := post.FileIds != nil && len(post.FileIds) > 0
|
||||
|
||||
msg.Message = a.getPushNotificationMessage(contentsConfig, post.Message, explicitMention, channelWideMention, hasFiles, msg.SenderName, channelName, channel.Type, replyToThreadType, userLocale)
|
||||
msg.Message = a.getPushNotificationMessage(
|
||||
contentsConfig,
|
||||
post.Message,
|
||||
explicitMention,
|
||||
channelWideMention,
|
||||
hasFiles,
|
||||
msg.SenderName,
|
||||
channel.Type,
|
||||
replyToThreadType,
|
||||
userLocale,
|
||||
)
|
||||
|
||||
return msg
|
||||
}
|
||||
|
||||
@@ -912,7 +912,6 @@ func TestGetPushNotificationMessage(t *testing.T) {
|
||||
tc.channelWideMention,
|
||||
tc.HasFiles,
|
||||
"user",
|
||||
"channel",
|
||||
tc.ChannelType,
|
||||
tc.replyToThreadType,
|
||||
utils.GetUserTranslations(locale),
|
||||
|
||||
@@ -175,7 +175,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
return token
|
||||
}
|
||||
|
||||
makeRequest := func(t *testing.T, cookie string) *http.Request {
|
||||
makeRequest := func(cookie string) *http.Request {
|
||||
request, _ := http.NewRequest(http.MethodGet, "https://mattermost.example.com", nil)
|
||||
|
||||
if cookie != "" {
|
||||
@@ -264,7 +264,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
cookie := model.NewId()
|
||||
request := makeRequest(t, "")
|
||||
request := makeRequest("")
|
||||
state := makeState(makeToken(th, cookie))
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(nil, request, model.SERVICE_GITLAB, "", state, "")
|
||||
@@ -281,7 +281,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
token, err := th.App.CreateOAuthStateToken(model.NewId())
|
||||
require.Nil(t, err)
|
||||
|
||||
request := makeRequest(t, cookie)
|
||||
request := makeRequest(cookie)
|
||||
state := makeState(token)
|
||||
|
||||
_, _, _, _, err = th.App.AuthorizeOAuthUser(nil, request, model.SERVICE_GITLAB, "", state, "")
|
||||
@@ -294,7 +294,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
cookie := model.NewId()
|
||||
request := makeRequest(t, cookie)
|
||||
request := makeRequest(cookie)
|
||||
state := makeState(makeToken(th, cookie))
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.SERVICE_GITLAB, "", state, "")
|
||||
@@ -312,7 +312,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
cookie := model.NewId()
|
||||
request := makeRequest(t, cookie)
|
||||
request := makeRequest(cookie)
|
||||
state := makeState(makeToken(th, cookie))
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.SERVICE_GITLAB, "", state, "")
|
||||
@@ -331,7 +331,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
cookie := model.NewId()
|
||||
request := makeRequest(t, cookie)
|
||||
request := makeRequest(cookie)
|
||||
state := makeState(makeToken(th, cookie))
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.SERVICE_GITLAB, "", state, "")
|
||||
@@ -353,7 +353,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
cookie := model.NewId()
|
||||
request := makeRequest(t, cookie)
|
||||
request := makeRequest(cookie)
|
||||
state := makeState(makeToken(th, cookie))
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.SERVICE_GITLAB, "", state, "")
|
||||
@@ -374,7 +374,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
cookie := model.NewId()
|
||||
request := makeRequest(t, cookie)
|
||||
request := makeRequest(cookie)
|
||||
state := makeState(makeToken(th, cookie))
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.SERVICE_GITLAB, "", state, "")
|
||||
@@ -395,7 +395,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
cookie := model.NewId()
|
||||
request := makeRequest(t, cookie)
|
||||
request := makeRequest(cookie)
|
||||
state := makeState(makeToken(th, cookie))
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.SERVICE_GITLAB, "", state, "")
|
||||
@@ -423,7 +423,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
cookie := model.NewId()
|
||||
request := makeRequest(t, cookie)
|
||||
request := makeRequest(cookie)
|
||||
state := makeState(makeToken(th, cookie))
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.SERVICE_GITLAB, "", state, "")
|
||||
@@ -452,7 +452,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
cookie := model.NewId()
|
||||
request := makeRequest(t, cookie)
|
||||
request := makeRequest(cookie)
|
||||
state := makeState(makeToken(th, cookie))
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.SERVICE_GITLAB, "", state, "")
|
||||
@@ -496,7 +496,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
})
|
||||
|
||||
cookie := model.NewId()
|
||||
request := makeRequest(t, cookie)
|
||||
request := makeRequest(cookie)
|
||||
|
||||
stateProps := map[string]string{
|
||||
"team_id": model.NewId(),
|
||||
|
||||
@@ -69,10 +69,10 @@ func TestExportPermissions(t *testing.T) {
|
||||
}
|
||||
|
||||
expectations := map[string]func(str string) string{
|
||||
scheme.DisplayName: func(str string) string { return row["display_name"].(string) },
|
||||
scheme.Name: func(str string) string { return row["name"].(string) },
|
||||
scheme.Description: func(str string) string { return row["description"].(string) },
|
||||
scheme.Scope: func(str string) string { return row["scope"].(string) },
|
||||
scheme.DisplayName: func(_ string) string { return row["display_name"].(string) },
|
||||
scheme.Name: func(_ string) string { return row["name"].(string) },
|
||||
scheme.Description: func(_ string) string { return row["description"].(string) },
|
||||
scheme.Scope: func(_ string) string { return row["scope"].(string) },
|
||||
scheme.DefaultTeamAdminRole: func(str string) string { return getRoleByName(str) },
|
||||
scheme.DefaultTeamUserRole: func(str string) string { return getRoleByName(str) },
|
||||
scheme.DefaultTeamGuestRole: func(str string) string { return getRoleByName(str) },
|
||||
|
||||
@@ -13,7 +13,7 @@ type Plugin struct {
|
||||
plugin.MattermostPlugin
|
||||
}
|
||||
|
||||
func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
|
||||
func (p *Plugin) ServeHTTP(_ *plugin.Context, w http.ResponseWriter, _ *http.Request) {
|
||||
hj, ok := w.(http.Hijacker)
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
|
||||
@@ -17,7 +17,7 @@ type Plugin struct {
|
||||
plugin.MattermostPlugin
|
||||
}
|
||||
|
||||
func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
|
||||
func (p *Plugin) ServeHTTP(_ *plugin.Context, w http.ResponseWriter, r *http.Request) {
|
||||
upgrader := websocket.Upgrader{}
|
||||
|
||||
ws, err := upgrader.Upgrade(w, r, nil)
|
||||
|
||||
@@ -30,7 +30,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
if p.configuration.MyStringSetting != "override" {
|
||||
return nil, "MyStringSetting has invalid value"
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
if p.configuration.MyStringSetting != "str" {
|
||||
return nil, "MyStringSetting has invalid value"
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
createdBot, err := p.API.CreateBot(&model.Bot{
|
||||
Username: "bot",
|
||||
Description: "a plugin bot",
|
||||
|
||||
@@ -22,7 +22,7 @@ func main() {
|
||||
plugin.ClientMain(&PluginUsingLogAPI{})
|
||||
}
|
||||
|
||||
func (p *PluginUsingLogAPI) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
|
||||
func (p *PluginUsingLogAPI) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
p.API.LogDebug("LogDebug", "one", 1, "two", "two", "foo", Foo{bar: 3.1416})
|
||||
p.API.LogInfo("LogInfo", "one", 1, "two", "two", "foo", Foo{bar: 3.1416})
|
||||
p.API.LogWarn("LogWarn", "one", 1, "two", "two", "foo", Foo{bar: 3.1416})
|
||||
|
||||
@@ -24,7 +24,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
bundlePath, err := p.API.GetBundlePath()
|
||||
if err != nil {
|
||||
return nil, err.Error() + "failed get bundle path"
|
||||
|
||||
@@ -21,7 +21,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
|
||||
channels, err := p.API.GetChannelsForTeamForUser(p.configuration.BasicTeamId, p.configuration.BasicUserId, false)
|
||||
if err != nil {
|
||||
|
||||
@@ -21,7 +21,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
dm1, err := p.API.GetDirectChannel(p.configuration.BasicUserId, p.configuration.BasicUser2Id)
|
||||
if err != nil {
|
||||
return nil, err.Error()
|
||||
|
||||
@@ -21,7 +21,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
status, err := p.API.GetPluginStatus("test_get_plugin_status_plugin")
|
||||
if err != nil {
|
||||
return nil, err.Error()
|
||||
|
||||
@@ -21,7 +21,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
|
||||
// check existing user first
|
||||
data, err := p.API.GetProfileImage(p.configuration.BasicUserId)
|
||||
|
||||
@@ -21,7 +21,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
channelMembers, err := p.API.GetChannelMembersForUser(p.configuration.BasicTeamId, p.configuration.BasicUserId, 0, 10)
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -21,7 +21,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
teamMembers, err := p.API.GetTeamMembersForUser(p.configuration.BasicUserId, 0, 10)
|
||||
if err != nil {
|
||||
return nil, err.Error() + "failed to get team members"
|
||||
|
||||
@@ -21,7 +21,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
|
||||
channels, err := p.API.SearchChannels(p.configuration.BasicTeamId, p.configuration.BasicChannelName)
|
||||
if err != nil {
|
||||
|
||||
@@ -23,7 +23,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
testCases := []struct {
|
||||
description string
|
||||
teamID string
|
||||
|
||||
@@ -23,7 +23,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
teams, err := p.API.SearchTeams(p.configuration.BasicTeamName)
|
||||
if err != nil {
|
||||
return nil, "search failed: " + err.Message
|
||||
|
||||
@@ -25,7 +25,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
to := p.configuration.BasicUserEmail
|
||||
subject := "testing plugin api sending email"
|
||||
body := "this is a test."
|
||||
|
||||
@@ -27,7 +27,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
|
||||
// Create an 128 x 128 image
|
||||
img := image.NewRGBA(image.Rect(0, 0, 128, 128))
|
||||
|
||||
@@ -21,7 +21,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
uid := p.configuration.BasicUserId
|
||||
if err := p.API.UpdateUserActive(uid, true); err != nil {
|
||||
return nil, err.Error()
|
||||
|
||||
@@ -23,7 +23,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
uid := p.configuration.BasicUserId
|
||||
|
||||
statuses := []string{model.STATUS_ONLINE, model.STATUS_AWAY, model.STATUS_DND, model.STATUS_OFFLINE}
|
||||
|
||||
@@ -50,7 +50,9 @@ func cleanupVersion(originalVersion string) string {
|
||||
return strings.Join(versionPartsOut, ".")
|
||||
}
|
||||
|
||||
func noticeMatchesConditions(config *model.Config, preferences store.PreferenceStore, userId string, client model.NoticeClientType, clientVersion, locale string, postCount, userCount int64, isSystemAdmin, isTeamAdmin bool, isCloud bool, sku string, notice *model.ProductNotice) (bool, error) {
|
||||
func noticeMatchesConditions(config *model.Config, preferences store.PreferenceStore, userId string,
|
||||
client model.NoticeClientType, clientVersion string, postCount int64, userCount int64, isSystemAdmin bool,
|
||||
isTeamAdmin bool, isCloud bool, sku string, notice *model.ProductNotice) (bool, error) {
|
||||
cnd := notice.Conditions
|
||||
|
||||
// check client type
|
||||
@@ -248,11 +250,12 @@ func (a *App) GetProductNotices(userId, teamId string, client model.NoticeClient
|
||||
continue
|
||||
}
|
||||
}
|
||||
result, err := noticeMatchesConditions(a.Config(), a.Srv().Store.Preference(),
|
||||
result, err := noticeMatchesConditions(
|
||||
a.Config(),
|
||||
a.Srv().Store.Preference(),
|
||||
userId,
|
||||
client,
|
||||
clientVersion,
|
||||
locale,
|
||||
cachedPostCount,
|
||||
cachedUserCount,
|
||||
isSystemAdmin,
|
||||
|
||||
@@ -53,7 +53,6 @@ func TestNoticeValidation(t *testing.T) {
|
||||
type args struct {
|
||||
client model.NoticeClientType
|
||||
clientVersion string
|
||||
locale string
|
||||
sku string
|
||||
postCount, userCount int64
|
||||
cloud bool
|
||||
@@ -550,7 +549,20 @@ func TestNoticeValidation(t *testing.T) {
|
||||
if model.BuildNumber == "" {
|
||||
model.BuildNumber = "5.26.1"
|
||||
}
|
||||
if ok, err := noticeMatchesConditions(th.App.Config(), th.App.Srv().Store.Preference(), "test", tt.args.client, clientVersion, tt.args.locale, tt.args.postCount, tt.args.userCount, tt.args.systemAdmin, tt.args.teamAdmin, tt.args.cloud, tt.args.sku, tt.args.notice); (err != nil) != tt.wantErr {
|
||||
if ok, err := noticeMatchesConditions(
|
||||
th.App.Config(),
|
||||
th.App.Srv().Store.Preference(),
|
||||
"test",
|
||||
tt.args.client,
|
||||
clientVersion,
|
||||
tt.args.postCount,
|
||||
tt.args.userCount,
|
||||
tt.args.systemAdmin,
|
||||
tt.args.teamAdmin,
|
||||
tt.args.cloud,
|
||||
tt.args.sku,
|
||||
tt.args.notice,
|
||||
); (err != nil) != tt.wantErr {
|
||||
t.Errorf("noticeMatchesConditions() error = %v, wantErr %v", err, tt.wantErr)
|
||||
} else if ok != tt.wantOk {
|
||||
t.Errorf("noticeMatchesConditions() result = %v, wantOk %v", ok, tt.wantOk)
|
||||
|
||||
@@ -63,7 +63,7 @@ func (a *App) SaveReactionForPost(reaction *model.Reaction) (*model.Reaction, *m
|
||||
}
|
||||
|
||||
a.Srv().Go(func() {
|
||||
a.sendReactionEvent(model.WEBSOCKET_EVENT_REACTION_ADDED, reaction, post, true)
|
||||
a.sendReactionEvent(model.WEBSOCKET_EVENT_REACTION_ADDED, reaction, post)
|
||||
})
|
||||
|
||||
return reaction, nil
|
||||
@@ -131,11 +131,6 @@ func (a *App) DeleteReactionForPost(reaction *model.Reaction) *model.AppError {
|
||||
}
|
||||
}
|
||||
|
||||
hasReactions := true
|
||||
if reactions, _ := a.GetReactionsForPost(post.Id); len(reactions) <= 1 {
|
||||
hasReactions = false
|
||||
}
|
||||
|
||||
if _, err := a.Srv().Store.Reaction().Delete(reaction); err != nil {
|
||||
return model.NewAppError("DeleteReactionForPost", "app.reaction.delete_all_with_emoji_name.get_reactions.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
@@ -154,13 +149,13 @@ func (a *App) DeleteReactionForPost(reaction *model.Reaction) *model.AppError {
|
||||
}
|
||||
|
||||
a.Srv().Go(func() {
|
||||
a.sendReactionEvent(model.WEBSOCKET_EVENT_REACTION_REMOVED, reaction, post, hasReactions)
|
||||
a.sendReactionEvent(model.WEBSOCKET_EVENT_REACTION_REMOVED, reaction, post)
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) sendReactionEvent(event string, reaction *model.Reaction, post *model.Post, hasReactions bool) {
|
||||
func (a *App) sendReactionEvent(event string, reaction *model.Reaction, post *model.Post) {
|
||||
// send out that a reaction has been added/removed
|
||||
message := model.NewWebSocketEvent(event, "", post.ChannelId, "", nil)
|
||||
message.Add("reaction", reaction.ToJson())
|
||||
|
||||
@@ -1302,7 +1302,7 @@ func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User,
|
||||
|
||||
if userUpdate.New.Username != userUpdate.Old.Username {
|
||||
a.Srv().Go(func() {
|
||||
if err := a.Srv().EmailService.sendChangeUsernameEmail(userUpdate.Old.Username, userUpdate.New.Username, userUpdate.New.Email, userUpdate.New.Locale, a.GetSiteURL()); err != nil {
|
||||
if err := a.Srv().EmailService.sendChangeUsernameEmail(userUpdate.New.Username, userUpdate.New.Email, userUpdate.New.Locale, a.GetSiteURL()); err != nil {
|
||||
mlog.Error("Failed to send change username email", mlog.Err(err))
|
||||
}
|
||||
})
|
||||
|
||||
@@ -588,7 +588,7 @@ func TestTriggerOutGoingWebhookWithUsernameAndIconURL(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
waitUntilWebhookResposeIsCreatedAsPost := func(channel *model.Channel, th *TestHelper, t *testing.T, createdPost chan *model.Post) {
|
||||
waitUntilWebhookResposeIsCreatedAsPost := func(channel *model.Channel, th *TestHelper, createdPost chan *model.Post) {
|
||||
go func() {
|
||||
for i := 0; i < 5; i++ {
|
||||
time.Sleep(time.Second)
|
||||
@@ -686,7 +686,7 @@ func TestTriggerOutGoingWebhookWithUsernameAndIconURL(t *testing.T) {
|
||||
|
||||
th.App.TriggerWebhook(payload, hook, th.BasicPost, channel)
|
||||
|
||||
waitUntilWebhookResposeIsCreatedAsPost(channel, th, t, createdPost)
|
||||
waitUntilWebhookResposeIsCreatedAsPost(channel, th, createdPost)
|
||||
|
||||
select {
|
||||
case webhookPost := <-createdPost:
|
||||
|
||||
@@ -334,6 +334,7 @@ func userDeactivateCmdF(command *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//nolint:unparam
|
||||
func userCreateCmdF(command *cobra.Command, args []string) error {
|
||||
a, err := InitDBCommandContextCobra(command)
|
||||
if err != nil {
|
||||
@@ -426,7 +427,7 @@ func usersToBots(args []string, a *app.App) {
|
||||
}
|
||||
}
|
||||
|
||||
func getUpdatedPassword(command *cobra.Command, a *app.App, user *model.User) (string, error) {
|
||||
func getUpdatedPassword(command *cobra.Command) (string, error) {
|
||||
password, err := command.Flags().GetString("password")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Unable to read password. Error: %s", err.Error())
|
||||
@@ -500,7 +501,7 @@ func botToUser(command *cobra.Command, args []string, a *app.App) error {
|
||||
return fmt.Errorf("Unable to find bot. Error: %s", appErr.Error())
|
||||
}
|
||||
|
||||
password, err := getUpdatedPassword(command, a, user)
|
||||
password, err := getUpdatedPassword(command)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/mattermost/mattermost-server/v5/app"
|
||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -33,10 +32,11 @@ func (scheduler *Scheduler) JobType() string {
|
||||
return model.JOB_TYPE_MIGRATIONS
|
||||
}
|
||||
|
||||
func (scheduler *Scheduler) Enabled(cfg *model.Config) bool {
|
||||
func (scheduler *Scheduler) Enabled(_ *model.Config) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
//nolint:unparam
|
||||
func (scheduler *Scheduler) NextScheduleTime(cfg *model.Config, now time.Time, pendingJobs bool, lastSuccessfulJob *model.Job) *time.Time {
|
||||
if scheduler.allMigrationsCompleted {
|
||||
return nil
|
||||
@@ -46,6 +46,7 @@ func (scheduler *Scheduler) NextScheduleTime(cfg *model.Config, now time.Time, p
|
||||
return &nextTime
|
||||
}
|
||||
|
||||
//nolint:unparam
|
||||
func (scheduler *Scheduler) ScheduleJob(cfg *model.Config, pendingJobs bool, lastSuccessfulJob *model.Job) (*model.Job, *model.AppError) {
|
||||
mlog.Debug("Scheduling Job", mlog.String("scheduler", scheduler.Name()))
|
||||
|
||||
@@ -64,7 +65,7 @@ func (scheduler *Scheduler) ScheduleJob(cfg *model.Config, pendingJobs bool, las
|
||||
if err := scheduler.srv.Jobs.SetJobError(job, nil); err != nil {
|
||||
mlog.Error("Worker: Failed to set job error", mlog.String("scheduler", scheduler.Name()), mlog.String("job_id", job.Id), mlog.String("error", err.Error()))
|
||||
}
|
||||
return scheduler.createJob(key, job, scheduler.srv.Store)
|
||||
return scheduler.createJob(key, job)
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
@@ -77,7 +78,7 @@ func (scheduler *Scheduler) ScheduleJob(cfg *model.Config, pendingJobs bool, las
|
||||
|
||||
if state == MigrationStateUnscheduled {
|
||||
mlog.Debug("Scheduling a new job for migration.", mlog.String("scheduler", scheduler.Name()), mlog.String("migration_key", key))
|
||||
return scheduler.createJob(key, job, scheduler.srv.Store)
|
||||
return scheduler.createJob(key, job)
|
||||
}
|
||||
|
||||
mlog.Error("Unknown migration state. Not doing anything.", mlog.String("migration_state", state))
|
||||
@@ -91,7 +92,7 @@ func (scheduler *Scheduler) ScheduleJob(cfg *model.Config, pendingJobs bool, las
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (scheduler *Scheduler) createJob(migrationKey string, lastJob *model.Job, store store.Store) (*model.Job, *model.AppError) {
|
||||
func (scheduler *Scheduler) createJob(migrationKey string, lastJob *model.Job) (*model.Job, *model.AppError) {
|
||||
var lastDone string
|
||||
if lastJob != nil {
|
||||
lastDone = lastJob.Data[JobDataKeyMigration_LAST_DONE]
|
||||
|
||||
@@ -75,7 +75,7 @@ func NewLogrTarget(name string, t *LogTarget) (logr.Target, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
filter, err := newFilter(name, t.Levels)
|
||||
filter, err := newFilter(t.Levels)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -99,7 +99,7 @@ func NewLogrTarget(name string, t *LogTarget) (logr.Target, error) {
|
||||
return nil, fmt.Errorf("invalid type '%s' for target %s", t.Type, name)
|
||||
}
|
||||
|
||||
func newFilter(name string, levels []LogLevel) (logr.Filter, error) {
|
||||
func newFilter(levels []LogLevel) (logr.Filter, error) {
|
||||
filter := &logr.CustomFilter{}
|
||||
for _, lvl := range levels {
|
||||
filter.Add(logr.Level(lvl))
|
||||
|
||||
@@ -90,7 +90,7 @@ func (tcp *Tcp) getConn() (net.Conn, error) {
|
||||
tcp.monitor = make(chan struct{})
|
||||
go monitor(tcp.conn, tcp.monitor)
|
||||
}
|
||||
connChan <- result{conn: conn, err: err}
|
||||
ch <- result{conn: conn, err: err}
|
||||
}(ctx, connChan)
|
||||
|
||||
select {
|
||||
|
||||
@@ -3188,7 +3188,7 @@ func (o *Config) IsValid() *AppError {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := o.MessageExportSettings.isValid(o.FileSettings); err != nil {
|
||||
if err := o.MessageExportSettings.isValid(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -3631,7 +3631,7 @@ func (s *LocalizationSettings) isValid() *AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *MessageExportSettings) isValid(fs FileSettings) *AppError {
|
||||
func (s *MessageExportSettings) isValid() *AppError {
|
||||
if s.EnableExport == nil {
|
||||
return NewAppError("Config.IsValid", "model.config.is_valid.message_export.enable.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
@@ -388,63 +388,56 @@ func TestTeamSettingsIsValidSiteNameEmpty(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMessageExportSettingsIsValidEnableExportNotSet(t *testing.T) {
|
||||
fs := &FileSettings{}
|
||||
mes := &MessageExportSettings{}
|
||||
|
||||
// should fail fast because mes.EnableExport is not set
|
||||
require.Error(t, mes.isValid(*fs))
|
||||
require.Error(t, mes.isValid())
|
||||
}
|
||||
|
||||
func TestMessageExportSettingsIsValidEnableExportFalse(t *testing.T) {
|
||||
fs := &FileSettings{}
|
||||
mes := &MessageExportSettings{
|
||||
EnableExport: NewBool(false),
|
||||
}
|
||||
|
||||
// should fail fast because message export isn't enabled
|
||||
require.Nil(t, mes.isValid(*fs))
|
||||
require.Nil(t, mes.isValid())
|
||||
}
|
||||
|
||||
func TestMessageExportSettingsIsValidExportFromTimestampInvalid(t *testing.T) {
|
||||
fs := &FileSettings{}
|
||||
mes := &MessageExportSettings{
|
||||
EnableExport: NewBool(true),
|
||||
}
|
||||
|
||||
// should fail fast because export from timestamp isn't set
|
||||
require.Error(t, mes.isValid(*fs))
|
||||
require.Error(t, mes.isValid())
|
||||
|
||||
mes.ExportFromTimestamp = NewInt64(-1)
|
||||
|
||||
// should fail fast because export from timestamp isn't valid
|
||||
require.Error(t, mes.isValid(*fs))
|
||||
require.Error(t, mes.isValid())
|
||||
|
||||
mes.ExportFromTimestamp = NewInt64(GetMillis() + 10000)
|
||||
|
||||
// should fail fast because export from timestamp is greater than current time
|
||||
require.Error(t, mes.isValid(*fs))
|
||||
require.Error(t, mes.isValid())
|
||||
}
|
||||
|
||||
func TestMessageExportSettingsIsValidDailyRunTimeInvalid(t *testing.T) {
|
||||
fs := &FileSettings{}
|
||||
mes := &MessageExportSettings{
|
||||
EnableExport: NewBool(true),
|
||||
ExportFromTimestamp: NewInt64(0),
|
||||
}
|
||||
|
||||
// should fail fast because daily runtime isn't set
|
||||
require.Error(t, mes.isValid(*fs))
|
||||
require.Error(t, mes.isValid())
|
||||
|
||||
mes.DailyRunTime = NewString("33:33:33")
|
||||
|
||||
// should fail fast because daily runtime is invalid format
|
||||
require.Error(t, mes.isValid(*fs))
|
||||
require.Error(t, mes.isValid())
|
||||
}
|
||||
|
||||
func TestMessageExportSettingsIsValidBatchSizeInvalid(t *testing.T) {
|
||||
fs := &FileSettings{
|
||||
DriverName: NewString("foo"), // bypass file location check
|
||||
}
|
||||
mes := &MessageExportSettings{
|
||||
EnableExport: NewBool(true),
|
||||
ExportFromTimestamp: NewInt64(0),
|
||||
@@ -452,13 +445,10 @@ func TestMessageExportSettingsIsValidBatchSizeInvalid(t *testing.T) {
|
||||
}
|
||||
|
||||
// should fail fast because batch size isn't set
|
||||
require.Error(t, mes.isValid(*fs))
|
||||
require.Error(t, mes.isValid())
|
||||
}
|
||||
|
||||
func TestMessageExportSettingsIsValidExportFormatInvalid(t *testing.T) {
|
||||
fs := &FileSettings{
|
||||
DriverName: NewString("foo"), // bypass file location check
|
||||
}
|
||||
mes := &MessageExportSettings{
|
||||
EnableExport: NewBool(true),
|
||||
ExportFromTimestamp: NewInt64(0),
|
||||
@@ -467,13 +457,10 @@ func TestMessageExportSettingsIsValidExportFormatInvalid(t *testing.T) {
|
||||
}
|
||||
|
||||
// should fail fast because export format isn't set
|
||||
require.Error(t, mes.isValid(*fs))
|
||||
require.Error(t, mes.isValid())
|
||||
}
|
||||
|
||||
func TestMessageExportSettingsIsValidGlobalRelayEmailAddressInvalid(t *testing.T) {
|
||||
fs := &FileSettings{
|
||||
DriverName: NewString("foo"), // bypass file location check
|
||||
}
|
||||
mes := &MessageExportSettings{
|
||||
EnableExport: NewBool(true),
|
||||
ExportFormat: NewString(COMPLIANCE_EXPORT_TYPE_GLOBALRELAY),
|
||||
@@ -483,13 +470,10 @@ func TestMessageExportSettingsIsValidGlobalRelayEmailAddressInvalid(t *testing.T
|
||||
}
|
||||
|
||||
// should fail fast because global relay email address isn't set
|
||||
require.Error(t, mes.isValid(*fs))
|
||||
require.Error(t, mes.isValid())
|
||||
}
|
||||
|
||||
func TestMessageExportSettingsIsValidActiance(t *testing.T) {
|
||||
fs := &FileSettings{
|
||||
DriverName: NewString("foo"), // bypass file location check
|
||||
}
|
||||
mes := &MessageExportSettings{
|
||||
EnableExport: NewBool(true),
|
||||
ExportFormat: NewString(COMPLIANCE_EXPORT_TYPE_ACTIANCE),
|
||||
@@ -499,13 +483,10 @@ func TestMessageExportSettingsIsValidActiance(t *testing.T) {
|
||||
}
|
||||
|
||||
// should pass because everything is valid
|
||||
require.Nil(t, mes.isValid(*fs))
|
||||
require.Nil(t, mes.isValid())
|
||||
}
|
||||
|
||||
func TestMessageExportSettingsIsValidGlobalRelaySettingsMissing(t *testing.T) {
|
||||
fs := &FileSettings{
|
||||
DriverName: NewString("foo"), // bypass file location check
|
||||
}
|
||||
mes := &MessageExportSettings{
|
||||
EnableExport: NewBool(true),
|
||||
ExportFormat: NewString(COMPLIANCE_EXPORT_TYPE_GLOBALRELAY),
|
||||
@@ -515,13 +496,10 @@ func TestMessageExportSettingsIsValidGlobalRelaySettingsMissing(t *testing.T) {
|
||||
}
|
||||
|
||||
// should fail because globalrelay settings are missing
|
||||
require.Error(t, mes.isValid(*fs))
|
||||
require.Error(t, mes.isValid())
|
||||
}
|
||||
|
||||
func TestMessageExportSettingsIsValidGlobalRelaySettingsInvalidCustomerType(t *testing.T) {
|
||||
fs := &FileSettings{
|
||||
DriverName: NewString("foo"), // bypass file location check
|
||||
}
|
||||
mes := &MessageExportSettings{
|
||||
EnableExport: NewBool(true),
|
||||
ExportFormat: NewString(COMPLIANCE_EXPORT_TYPE_GLOBALRELAY),
|
||||
@@ -537,14 +515,11 @@ func TestMessageExportSettingsIsValidGlobalRelaySettingsInvalidCustomerType(t *t
|
||||
}
|
||||
|
||||
// should fail because customer type is invalid
|
||||
require.Error(t, mes.isValid(*fs))
|
||||
require.Error(t, mes.isValid())
|
||||
}
|
||||
|
||||
// func TestMessageExportSettingsIsValidGlobalRelaySettingsInvalidEmailAddress(t *testing.T) {
|
||||
func TestMessageExportSettingsGlobalRelaySettings(t *testing.T) {
|
||||
fs := &FileSettings{
|
||||
DriverName: NewString("foo"), // bypass file location check
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
value *GlobalRelayMessageExportSettings
|
||||
@@ -613,9 +588,9 @@ func TestMessageExportSettingsGlobalRelaySettings(t *testing.T) {
|
||||
}
|
||||
|
||||
if tt.success {
|
||||
require.Nil(t, mes.isValid(*fs))
|
||||
require.Nil(t, mes.isValid())
|
||||
} else {
|
||||
require.Error(t, mes.isValid(*fs))
|
||||
require.Error(t, mes.isValid())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ func FieldListToFuncList(fieldList *ast.FieldList, fileset *token.FileSet) strin
|
||||
return "(" + strings.Join(result, ", ") + ")"
|
||||
}
|
||||
|
||||
func FieldListToNames(fieldList *ast.FieldList, fileset *token.FileSet, variadicForm bool) string {
|
||||
func FieldListToNames(fieldList *ast.FieldList, variadicForm bool) string {
|
||||
result := []string{}
|
||||
if fieldList == nil || len(fieldList.List) == 0 {
|
||||
return ""
|
||||
@@ -141,7 +141,7 @@ func FieldListDestruct(structPrefix string, fieldList *ast.FieldList, fileset *t
|
||||
return strings.Join(result, ", ")
|
||||
}
|
||||
|
||||
func FieldListToRecordSuccess(structPrefix string, fieldList *ast.FieldList, fileset *token.FileSet) string {
|
||||
func FieldListToRecordSuccess(structPrefix string, fieldList *ast.FieldList) string {
|
||||
if fieldList == nil || len(fieldList.List) == 0 {
|
||||
return "true"
|
||||
}
|
||||
@@ -458,7 +458,7 @@ func generateHooksGlue(info *PluginInterfaceInfo) {
|
||||
templateFunctions := map[string]interface{}{
|
||||
"funcStyle": func(fields *ast.FieldList) string { return FieldListToFuncList(fields, info.FileSet) },
|
||||
"structStyle": func(fields *ast.FieldList) string { return FieldListToStructList(fields, info.FileSet) },
|
||||
"valuesOnly": func(fields *ast.FieldList) string { return FieldListToNames(fields, info.FileSet, false) },
|
||||
"valuesOnly": func(fields *ast.FieldList) string { return FieldListToNames(fields, false) },
|
||||
"encodeErrors": func(structPrefix string, fields *ast.FieldList) string {
|
||||
return FieldListToEncodedErrors(structPrefix, fields, info.FileSet)
|
||||
},
|
||||
@@ -466,7 +466,7 @@ func generateHooksGlue(info *PluginInterfaceInfo) {
|
||||
return FieldListDestruct(structPrefix, fields, info.FileSet)
|
||||
},
|
||||
"shouldRecordSuccess": func(structPrefix string, fields *ast.FieldList) string {
|
||||
return FieldListToRecordSuccess(structPrefix, fields, info.FileSet)
|
||||
return FieldListToRecordSuccess(structPrefix, fields)
|
||||
},
|
||||
"obscure": func(name string) string {
|
||||
return "Z_" + name
|
||||
@@ -510,12 +510,12 @@ func generatePluginTimerLayer(info *PluginInterfaceInfo) {
|
||||
templateFunctions := map[string]interface{}{
|
||||
"funcStyle": func(fields *ast.FieldList) string { return FieldListToFuncList(fields, info.FileSet) },
|
||||
"structStyle": func(fields *ast.FieldList) string { return FieldListToStructList(fields, info.FileSet) },
|
||||
"valuesOnly": func(fields *ast.FieldList) string { return FieldListToNames(fields, info.FileSet, true) },
|
||||
"valuesOnly": func(fields *ast.FieldList) string { return FieldListToNames(fields, true) },
|
||||
"destruct": func(structPrefix string, fields *ast.FieldList) string {
|
||||
return FieldListDestruct(structPrefix, fields, info.FileSet)
|
||||
},
|
||||
"shouldRecordSuccess": func(structPrefix string, fields *ast.FieldList) string {
|
||||
return FieldListToRecordSuccess(structPrefix, fields, info.FileSet)
|
||||
return FieldListToRecordSuccess(structPrefix, fields)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ type Actions struct {
|
||||
AddUserToChannel func(*model.User, *model.Channel) (*model.ChannelMember, *model.AppError)
|
||||
JoinUserToTeam func(*model.Team, *model.User, string) *model.AppError
|
||||
CreateDirectChannel func(string, string) (*model.Channel, *model.AppError)
|
||||
CreateGroupChannel func([]string, string) (*model.Channel, *model.AppError)
|
||||
CreateGroupChannel func([]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)
|
||||
@@ -736,7 +736,7 @@ func (si *SlackImporter) oldImportChannel(channel *model.Channel, sChannel slack
|
||||
if creator == nil {
|
||||
return nil
|
||||
}
|
||||
sc, err := si.actions.CreateGroupChannel(members, creator.Id)
|
||||
sc, err := si.actions.CreateGroupChannel(members)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -109,7 +109,8 @@ func channelMemberToSlice(member *model.ChannelMember) []interface{} {
|
||||
|
||||
type channelMemberWithSchemeRolesList []channelMemberWithSchemeRoles
|
||||
|
||||
func getChannelRoles(schemeGuest, schemeUser, schemeAdmin bool, defaultTeamGuestRole, defaultTeamUserRole, defaultTeamAdminRole, defaultChannelGuestRole, defaultChannelUserRole, defaultChannelAdminRole string, roles []string) rolesInfo {
|
||||
func getChannelRoles(schemeGuest, schemeUser, schemeAdmin bool, defaultTeamGuestRole, defaultTeamUserRole, defaultTeamAdminRole, defaultChannelGuestRole, defaultChannelUserRole, defaultChannelAdminRole string,
|
||||
roles []string) rolesInfo {
|
||||
result := rolesInfo{
|
||||
roles: []string{},
|
||||
explicitRoles: []string{},
|
||||
@@ -606,9 +607,9 @@ func (s SqlChannelStore) SaveDirectChannel(directchannel *model.Channel, member1
|
||||
member2.ChannelId = newChannel.Id
|
||||
|
||||
if member1.UserId != member2.UserId {
|
||||
_, err = s.saveMultipleMembersT(transaction, []*model.ChannelMember{member1, member2})
|
||||
_, err = s.saveMultipleMembers([]*model.ChannelMember{member1, member2})
|
||||
} else {
|
||||
_, err = s.saveMemberT(transaction, member2)
|
||||
_, err = s.saveMemberT(member2)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -729,6 +730,7 @@ func (s SqlChannelStore) GetChannelUnread(channelId, userId string) (*model.Chan
|
||||
return &unreadChannel, nil
|
||||
}
|
||||
|
||||
//nolint:unparam
|
||||
func (s SqlChannelStore) InvalidateChannel(id string) {
|
||||
}
|
||||
|
||||
@@ -739,8 +741,9 @@ func (s SqlChannelStore) InvalidateChannelByName(teamId, name string) {
|
||||
}
|
||||
}
|
||||
|
||||
//nolint:unparam
|
||||
func (s SqlChannelStore) Get(id string, allowFromCache bool) (*model.Channel, error) {
|
||||
return s.get(id, false, allowFromCache)
|
||||
return s.get(id, false)
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetPinnedPosts(channelId string) (*model.PostList, error) {
|
||||
@@ -758,10 +761,10 @@ func (s SqlChannelStore) GetPinnedPosts(channelId string) (*model.PostList, erro
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetFromMaster(id string) (*model.Channel, error) {
|
||||
return s.get(id, true, false)
|
||||
return s.get(id, true)
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) get(id string, master bool, allowFromCache bool) (*model.Channel, error) {
|
||||
func (s SqlChannelStore) get(id string, master bool) (*model.Channel, error) {
|
||||
var db *gorp.DbMap
|
||||
|
||||
if master {
|
||||
@@ -1392,7 +1395,7 @@ func (s SqlChannelStore) SaveMultipleMembers(members []*model.ChannelMember) ([]
|
||||
}
|
||||
defer finalizeTransaction(transaction)
|
||||
|
||||
newMembers, err := s.saveMultipleMembersT(transaction, members)
|
||||
newMembers, err := s.saveMultipleMembers(members)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1412,7 +1415,7 @@ func (s SqlChannelStore) SaveMember(member *model.ChannelMember) (*model.Channel
|
||||
return newMembers[0], nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) saveMultipleMembersT(transaction *gorp.Transaction, members []*model.ChannelMember) ([]*model.ChannelMember, error) {
|
||||
func (s SqlChannelStore) saveMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, error) {
|
||||
newChannelMembers := map[string]int{}
|
||||
users := map[string]bool{}
|
||||
for _, member := range members {
|
||||
@@ -1553,8 +1556,8 @@ func (s SqlChannelStore) saveMultipleMembersT(transaction *gorp.Transaction, mem
|
||||
return newMembers, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) saveMemberT(transaction *gorp.Transaction, member *model.ChannelMember) (*model.ChannelMember, error) {
|
||||
members, err := s.saveMultipleMembersT(transaction, []*model.ChannelMember{member})
|
||||
func (s SqlChannelStore) saveMemberT(member *model.ChannelMember) (*model.ChannelMember, error) {
|
||||
members, err := s.saveMultipleMembers([]*model.ChannelMember{member})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1843,6 +1846,7 @@ func (s SqlChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId str
|
||||
return props, nil
|
||||
}
|
||||
|
||||
//nolint:unparam
|
||||
func (s SqlChannelStore) InvalidateMemberCount(channelId string) {
|
||||
}
|
||||
|
||||
@@ -1851,6 +1855,7 @@ func (s SqlChannelStore) GetMemberCountFromCache(channelId string) int64 {
|
||||
return count
|
||||
}
|
||||
|
||||
//nolint:unparam
|
||||
func (s SqlChannelStore) GetMemberCount(channelId string, allowFromCache bool) (int64, error) {
|
||||
count, err := s.GetReplica().SelectInt(`
|
||||
SELECT
|
||||
@@ -1939,9 +1944,11 @@ func (s SqlChannelStore) GetMemberCountsByGroup(channelID string, includeTimezon
|
||||
return data, nil
|
||||
}
|
||||
|
||||
//nolint:unparam
|
||||
func (s SqlChannelStore) InvalidatePinnedPostCount(channelId string) {
|
||||
}
|
||||
|
||||
//nolint:unparam
|
||||
func (s SqlChannelStore) GetPinnedPostCount(channelId string, allowFromCache bool) (int64, error) {
|
||||
count, err := s.GetReplica().SelectInt(`
|
||||
SELECT count(*)
|
||||
@@ -1958,9 +1965,11 @@ func (s SqlChannelStore) GetPinnedPostCount(channelId string, allowFromCache boo
|
||||
return count, nil
|
||||
}
|
||||
|
||||
//nolint:unparam
|
||||
func (s SqlChannelStore) InvalidateGuestCount(channelId string) {
|
||||
}
|
||||
|
||||
//nolint:unparam
|
||||
func (s SqlChannelStore) GetGuestCount(channelId string, allowFromCache bool) (int64, error) {
|
||||
count, err := s.GetReplica().SelectInt(`
|
||||
SELECT
|
||||
|
||||
@@ -324,7 +324,7 @@ func (s SqlChannelStore) CreateSidebarCategory(userId, teamId string, newCategor
|
||||
}
|
||||
|
||||
// now we re-order the categories according to the new order
|
||||
if err = s.updateSidebarCategoryOrderT(transaction, userId, teamId, newOrder); err != nil {
|
||||
if err = s.updateSidebarCategoryOrderT(transaction, newOrder); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -541,7 +541,7 @@ func (s SqlChannelStore) GetSidebarCategoryOrder(userId, teamId string) ([]strin
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) updateSidebarCategoryOrderT(transaction *gorp.Transaction, userId, teamId string, categoryOrder []string) error {
|
||||
func (s SqlChannelStore) updateSidebarCategoryOrderT(transaction *gorp.Transaction, categoryOrder []string) error {
|
||||
var newOrder []interface{}
|
||||
runningOrder := 0
|
||||
for _, categoryId := range categoryOrder {
|
||||
@@ -595,7 +595,7 @@ func (s SqlChannelStore) UpdateSidebarCategoryOrder(userId, teamId string, categ
|
||||
}
|
||||
}
|
||||
|
||||
if err = s.updateSidebarCategoryOrderT(transaction, userId, teamId, categoryOrder); err != nil {
|
||||
if err = s.updateSidebarCategoryOrderT(transaction, categoryOrder); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -606,6 +606,7 @@ func (s SqlChannelStore) UpdateSidebarCategoryOrder(userId, teamId string, categ
|
||||
return nil
|
||||
}
|
||||
|
||||
//nolint:unparam
|
||||
func (s SqlChannelStore) UpdateSidebarCategories(userId, teamId string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, []*model.SidebarCategoryWithChannels, error) {
|
||||
transaction, err := s.GetMaster().Begin()
|
||||
if err != nil {
|
||||
@@ -943,6 +944,7 @@ func (s SqlChannelStore) DeleteSidebarChannelsByPreferences(preferences *model.P
|
||||
return nil
|
||||
}
|
||||
|
||||
//nolint:unparam
|
||||
func (s SqlChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) error {
|
||||
// if channel is being moved, remove it from the categories, since it's possible that there's no matching category in the new team
|
||||
if _, err := s.GetMaster().Exec("DELETE FROM SidebarChannels WHERE ChannelId=:ChannelId", map[string]interface{}{"ChannelId": channel.Id}); err != nil {
|
||||
|
||||
@@ -58,11 +58,11 @@ func (es SqlEmojiStore) Save(emoji *model.Emoji) (*model.Emoji, error) {
|
||||
}
|
||||
|
||||
func (es SqlEmojiStore) Get(id string, allowFromCache bool) (*model.Emoji, error) {
|
||||
return es.getBy("Id", id, allowFromCache)
|
||||
return es.getBy("Id", id)
|
||||
}
|
||||
|
||||
func (es SqlEmojiStore) GetByName(name string, allowFromCache bool) (*model.Emoji, error) {
|
||||
return es.getBy("Name", name, allowFromCache)
|
||||
return es.getBy("Name", name)
|
||||
}
|
||||
|
||||
func (es SqlEmojiStore) GetMultipleByName(names []string) ([]*model.Emoji, error) {
|
||||
@@ -146,7 +146,7 @@ func (es SqlEmojiStore) Search(name string, prefixOnly bool, limit int) ([]*mode
|
||||
}
|
||||
|
||||
// getBy returns one active (not deleted) emoji, found by any one column (what/key).
|
||||
func (es SqlEmojiStore) getBy(what, key string, addToCache bool) (*model.Emoji, error) {
|
||||
func (es SqlEmojiStore) getBy(what, key string) (*model.Emoji, error) {
|
||||
var emoji *model.Emoji
|
||||
|
||||
err := es.GetReplica().SelectOne(&emoji,
|
||||
|
||||
@@ -998,7 +998,7 @@ func (s *SqlGroupStore) groupsBySyncableBaseQuery(st model.GroupSyncableType, t
|
||||
return query
|
||||
}
|
||||
|
||||
func (s *SqlGroupStore) getGroupsAssociatedToChannelsByTeam(st model.GroupSyncableType, teamID string, opts model.GroupSearchOpts) sq.SelectBuilder {
|
||||
func (s *SqlGroupStore) getGroupsAssociatedToChannelsByTeam(teamID string, opts model.GroupSearchOpts) sq.SelectBuilder {
|
||||
query := s.getQueryBuilder().
|
||||
Select("gc.ChannelId, ug.*, gc.SchemeAdmin AS SyncableSchemeAdmin").
|
||||
From("UserGroups ug").
|
||||
@@ -1103,7 +1103,7 @@ func (s *SqlGroupStore) GetGroupsByTeam(teamId string, opts model.GroupSearchOpt
|
||||
}
|
||||
|
||||
func (s *SqlGroupStore) GetGroupsAssociatedToChannelsByTeam(teamId string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, error) {
|
||||
query := s.getGroupsAssociatedToChannelsByTeam(model.GroupSyncableTypeTeam, teamId, opts)
|
||||
query := s.getGroupsAssociatedToChannelsByTeam(teamId, opts)
|
||||
|
||||
if opts.PageOpts != nil {
|
||||
offset := uint64(opts.PageOpts.Page * opts.PageOpts.PerPage)
|
||||
|
||||
@@ -297,7 +297,7 @@ func createStatus(ss store.Store, userId string) *model.Status {
|
||||
return &m
|
||||
}
|
||||
|
||||
func createTeam(ss store.Store, userId string) *model.Team {
|
||||
func createTeam(ss store.Store) *model.Team {
|
||||
m := model.Team{}
|
||||
m.DisplayName = "DisplayName"
|
||||
m.Type = model.TEAM_OPEN
|
||||
@@ -972,7 +972,7 @@ func TestCheckTeamsTeamMembersIntegrity(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("should generate a report with one record", func(t *testing.T) {
|
||||
team := createTeam(ss, model.NewId())
|
||||
team := createTeam(ss)
|
||||
member := createTeamMember(ss, team.Id, model.NewId())
|
||||
dbmap.Delete(team)
|
||||
result := checkTeamsTeamMembersIntegrity(store)
|
||||
@@ -1569,7 +1569,7 @@ func TestCheckUsersTeamMembersIntegrity(t *testing.T) {
|
||||
|
||||
t.Run("should generate a report with one record", func(t *testing.T) {
|
||||
user := createUser(ss)
|
||||
team := createTeam(ss, user.Id)
|
||||
team := createTeam(ss)
|
||||
member := createTeamMember(ss, team.Id, user.Id)
|
||||
dbmap.Delete(user)
|
||||
result := checkUsersTeamMembersIntegrity(store)
|
||||
|
||||
@@ -519,15 +519,18 @@ type etagPosts struct {
|
||||
UpdateAt int64
|
||||
}
|
||||
|
||||
//nolint:unparam
|
||||
func (s *SqlPostStore) InvalidateLastPostTimeCache(channelId string) {
|
||||
}
|
||||
|
||||
//nolint:unparam
|
||||
func (s *SqlPostStore) GetEtag(channelId string, allowFromCache, collapsedThreads bool) string {
|
||||
q := s.getQueryBuilder().Select("Id", "UpdateAt").From("Posts").Where(sq.Eq{"ChannelId": channelId}).OrderBy("UpdateAt DESC").Limit(1)
|
||||
if collapsedThreads {
|
||||
q.Where(sq.Eq{"RootId": ""})
|
||||
}
|
||||
sql, args, _ := q.ToSql()
|
||||
|
||||
var et etagPosts
|
||||
err := s.GetReplica().SelectOne(&et, sql, args...)
|
||||
var result string
|
||||
@@ -558,7 +561,7 @@ func (s *SqlPostStore) Delete(postId string, time int64, deleteByID string) erro
|
||||
return errors.Wrap(err, "failed to update Posts")
|
||||
}
|
||||
|
||||
return s.cleanupThreads(post.Id, post.RootId, post.UserId, false)
|
||||
return s.cleanupThreads(post.Id, post.RootId, false)
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) permanentDelete(postId string) error {
|
||||
@@ -567,7 +570,7 @@ func (s *SqlPostStore) permanentDelete(postId string) error {
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return errors.Wrapf(err, "failed to get Post with id=%s", postId)
|
||||
}
|
||||
if err = s.cleanupThreads(post.Id, post.RootId, post.UserId, true); err != nil {
|
||||
if err = s.cleanupThreads(post.Id, post.RootId, true); err != nil {
|
||||
return errors.Wrapf(err, "failed to cleanup threads for Post with id=%s", postId)
|
||||
}
|
||||
|
||||
@@ -592,7 +595,7 @@ func (s *SqlPostStore) permanentDeleteAllCommentByUser(userId string) error {
|
||||
}
|
||||
|
||||
for _, ids := range results {
|
||||
if err = s.cleanupThreads(ids.Id, ids.RootId, userId, true); err != nil {
|
||||
if err = s.cleanupThreads(ids.Id, ids.RootId, true); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -648,7 +651,7 @@ func (s *SqlPostStore) PermanentDeleteByChannel(channelId string) error {
|
||||
}
|
||||
|
||||
for _, ids := range results {
|
||||
if err = s.cleanupThreads(ids.Id, ids.RootId, ids.UserId, true); err != nil {
|
||||
if err = s.cleanupThreads(ids.Id, ids.RootId, true); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -825,10 +828,12 @@ func (s *SqlPostStore) getPostsSinceCollapsedThreads(options model.GetPostsSince
|
||||
return s.prepareThreadedResponse(posts, options.CollapsedThreadsExtended, false)
|
||||
}
|
||||
|
||||
//nolint:unparam
|
||||
func (s *SqlPostStore) GetPostsSince(options model.GetPostsSinceOptions, allowFromCache bool) (*model.PostList, error) {
|
||||
if options.CollapsedThreads {
|
||||
return s.getPostsSinceCollapsedThreads(options)
|
||||
}
|
||||
|
||||
var posts []*model.Post
|
||||
|
||||
replyCountQuery1 := ""
|
||||
@@ -2026,6 +2031,7 @@ func (s *SqlPostStore) GetDirectPostParentsForExportAfter(limit int, afterId str
|
||||
return posts, nil
|
||||
}
|
||||
|
||||
//nolint:unparam
|
||||
func (s *SqlPostStore) SearchPostsInTeamForUser(paramsList []*model.SearchParams, userId, teamId string, page, perPage int) (*model.PostSearchResults, error) {
|
||||
// Since we don't support paging for DB search, we just return nothing for later pages
|
||||
if page > 0 {
|
||||
@@ -2093,7 +2099,7 @@ func (s *SqlPostStore) GetOldestEntityCreationTime() (int64, error) {
|
||||
return oldest, nil
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) cleanupThreads(postId, rootId, userId string, permanent bool) error {
|
||||
func (s *SqlPostStore) cleanupThreads(postId, rootId string, permanent bool) error {
|
||||
if permanent {
|
||||
if _, err := s.GetMaster().Exec("DELETE FROM Threads WHERE PostId = :Id", map[string]interface{}{"Id": postId}); err != nil {
|
||||
return errors.Wrap(err, "failed to delete Threads")
|
||||
|
||||
@@ -1055,7 +1055,7 @@ func (s SqlTeamStore) GetMembers(teamId string, offset int, limit int, teamMembe
|
||||
query = query.OrderBy(model.USERNAME)
|
||||
}
|
||||
|
||||
query = applyTeamMemberViewRestrictionsFilter(query, teamId, teamMembersGetOptions.ViewRestrictions)
|
||||
query = applyTeamMemberViewRestrictionsFilter(query, teamMembersGetOptions.ViewRestrictions)
|
||||
}
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
@@ -1082,7 +1082,7 @@ func (s SqlTeamStore) GetTotalMemberCount(teamId string, restrictions *model.Vie
|
||||
Where("TeamMembers.UserId = Users.Id").
|
||||
Where(sq.Eq{"TeamMembers.TeamId": teamId})
|
||||
|
||||
query = applyTeamMemberViewRestrictionsFilterForStats(query, teamId, restrictions)
|
||||
query = applyTeamMemberViewRestrictionsFilterForStats(query, restrictions)
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return int64(0), errors.Wrap(err, "team_tosql")
|
||||
@@ -1106,7 +1106,7 @@ func (s SqlTeamStore) GetActiveMemberCount(teamId string, restrictions *model.Vi
|
||||
Where("Users.DeleteAt = 0").
|
||||
Where(sq.Eq{"TeamMembers.TeamId": teamId})
|
||||
|
||||
query = applyTeamMemberViewRestrictionsFilterForStats(query, teamId, restrictions)
|
||||
query = applyTeamMemberViewRestrictionsFilterForStats(query, restrictions)
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "team_tosql")
|
||||
@@ -1132,7 +1132,7 @@ func (s SqlTeamStore) GetMembersByIds(teamId string, userIds []string, restricti
|
||||
Where(sq.Eq{"TeamMembers.UserId": userIds}).
|
||||
Where(sq.Eq{"TeamMembers.DeleteAt": 0})
|
||||
|
||||
query = applyTeamMemberViewRestrictionsFilter(query, teamId, restrictions)
|
||||
query = applyTeamMemberViewRestrictionsFilter(query, restrictions)
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
@@ -1408,6 +1408,7 @@ func (s SqlTeamStore) ResetAllTeamSchemes() error {
|
||||
func (s SqlTeamStore) ClearCaches() {}
|
||||
|
||||
// InvalidateAllTeamIdsForUser does not execute anything because the store does not handle the cache.
|
||||
//nolint:unparam
|
||||
func (s SqlTeamStore) InvalidateAllTeamIdsForUser(userId string) {}
|
||||
|
||||
// ClearAllCustomRoleAssignments removes all custom role assignments from TeamMembers.
|
||||
@@ -1505,6 +1506,7 @@ func (s SqlTeamStore) GetAllForExportAfter(limit int, afterId string) ([]*model.
|
||||
}
|
||||
|
||||
// GetUserTeamIds get the team ids to which the user belongs to. allowFromCache parameter does not have any effect in this Store
|
||||
//nolint:unparam
|
||||
func (s SqlTeamStore) GetUserTeamIds(userId string, allowFromCache bool) ([]string, error) {
|
||||
var teamIds []string
|
||||
query, args, err := s.getQueryBuilder().
|
||||
@@ -1585,7 +1587,7 @@ func (s SqlTeamStore) UpdateMembersRole(teamID string, userIDs []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func applyTeamMemberViewRestrictionsFilter(query sq.SelectBuilder, teamId string, restrictions *model.ViewUsersRestrictions) sq.SelectBuilder {
|
||||
func applyTeamMemberViewRestrictionsFilter(query sq.SelectBuilder, restrictions *model.ViewUsersRestrictions) sq.SelectBuilder {
|
||||
if restrictions == nil {
|
||||
return query
|
||||
}
|
||||
@@ -1615,7 +1617,7 @@ func applyTeamMemberViewRestrictionsFilter(query sq.SelectBuilder, teamId string
|
||||
return resultQuery.Distinct()
|
||||
}
|
||||
|
||||
func applyTeamMemberViewRestrictionsFilterForStats(query sq.SelectBuilder, teamId string, restrictions *model.ViewUsersRestrictions) sq.SelectBuilder {
|
||||
func applyTeamMemberViewRestrictionsFilterForStats(query sq.SelectBuilder, restrictions *model.ViewUsersRestrictions) sq.SelectBuilder {
|
||||
if restrictions == nil {
|
||||
return query
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func cleanupChannels(t *testing.T, ss store.Store) {
|
||||
}
|
||||
|
||||
func TestChannelStore(t *testing.T, ss store.Store, s SqlStore) {
|
||||
createDefaultRoles(t, ss)
|
||||
createDefaultRoles(ss)
|
||||
|
||||
t.Run("Save", func(t *testing.T) { testChannelStoreSave(t, ss) })
|
||||
t.Run("SaveDirectChannel", func(t *testing.T) { testChannelStoreSaveDirectChannel(t, ss, s) })
|
||||
@@ -79,7 +79,7 @@ func TestChannelStore(t *testing.T, ss store.Store, s SqlStore) {
|
||||
t.Run("GetMemberCountsByGroup", func(t *testing.T) { testGetMemberCountsByGroup(t, ss) })
|
||||
t.Run("GetGuestCount", func(t *testing.T) { testGetGuestCount(t, ss) })
|
||||
t.Run("SearchMore", func(t *testing.T) { testChannelStoreSearchMore(t, ss) })
|
||||
t.Run("SearchInTeam", func(t *testing.T) { testChannelStoreSearchInTeam(t, ss, s) })
|
||||
t.Run("SearchInTeam", func(t *testing.T) { testChannelStoreSearchInTeam(t, ss) })
|
||||
t.Run("SearchArchivedInTeam", func(t *testing.T) { testChannelStoreSearchArchivedInTeam(t, ss, s) })
|
||||
t.Run("SearchForUserInTeam", func(t *testing.T) { testChannelStoreSearchForUserInTeam(t, ss) })
|
||||
t.Run("SearchAllChannels", func(t *testing.T) { testChannelStoreSearchAllChannels(t, ss) })
|
||||
@@ -107,7 +107,7 @@ func TestChannelStore(t *testing.T, ss store.Store, s SqlStore) {
|
||||
t.Run("CreateSidebarCategory", func(t *testing.T) { testCreateSidebarCategory(t, ss) })
|
||||
t.Run("GetSidebarCategory", func(t *testing.T) { testGetSidebarCategory(t, ss, s) })
|
||||
t.Run("GetSidebarCategories", func(t *testing.T) { testGetSidebarCategories(t, ss) })
|
||||
t.Run("UpdateSidebarCategories", func(t *testing.T) { testUpdateSidebarCategories(t, ss, s) })
|
||||
t.Run("UpdateSidebarCategories", func(t *testing.T) { testUpdateSidebarCategories(t, ss) })
|
||||
t.Run("DeleteSidebarCategory", func(t *testing.T) { testDeleteSidebarCategory(t, ss, s) })
|
||||
t.Run("UpdateSidebarChannelsByPreferences", func(t *testing.T) { testUpdateSidebarChannelsByPreferences(t, ss) })
|
||||
}
|
||||
@@ -4971,7 +4971,7 @@ func testChannelStoreSearchArchivedInTeam(t *testing.T, ss store.Store, s SqlSto
|
||||
})
|
||||
}
|
||||
|
||||
func testChannelStoreSearchInTeam(t *testing.T, ss store.Store, s SqlStore) {
|
||||
func testChannelStoreSearchInTeam(t *testing.T, ss store.Store) {
|
||||
teamId := model.NewId()
|
||||
otherTeamId := model.NewId()
|
||||
|
||||
|
||||
@@ -21,8 +21,9 @@ func TestChannelStoreCategories(t *testing.T, ss store.Store, s SqlStore) {
|
||||
t.Run("CreateSidebarCategory", func(t *testing.T) { testCreateSidebarCategory(t, ss) })
|
||||
t.Run("GetSidebarCategory", func(t *testing.T) { testGetSidebarCategory(t, ss, s) })
|
||||
t.Run("GetSidebarCategories", func(t *testing.T) { testGetSidebarCategories(t, ss) })
|
||||
t.Run("UpdateSidebarCategories", func(t *testing.T) { testUpdateSidebarCategories(t, ss, s) })
|
||||
t.Run("UpdateSidebarCategories", func(t *testing.T) { testUpdateSidebarCategories(t, ss) })
|
||||
t.Run("ClearSidebarOnTeamLeave", func(t *testing.T) { testClearSidebarOnTeamLeave(t, ss, s) })
|
||||
t.Run("UpdateSidebarCategories", func(t *testing.T) { testUpdateSidebarCategories(t, ss) })
|
||||
t.Run("DeleteSidebarCategory", func(t *testing.T) { testDeleteSidebarCategory(t, ss, s) })
|
||||
t.Run("UpdateSidebarChannelsByPreferences", func(t *testing.T) { testUpdateSidebarChannelsByPreferences(t, ss) })
|
||||
}
|
||||
@@ -869,7 +870,7 @@ func testGetSidebarCategories(t *testing.T, ss store.Store) {
|
||||
})
|
||||
}
|
||||
|
||||
func testUpdateSidebarCategories(t *testing.T, ss store.Store, s SqlStore) {
|
||||
func testUpdateSidebarCategories(t *testing.T, ss store.Store) {
|
||||
t.Run("ensure the query to update SidebarCategories hasn't been polluted by UpdateSidebarCategoryOrder", func(t *testing.T) {
|
||||
userId := model.NewId()
|
||||
teamId := model.NewId()
|
||||
|
||||
@@ -15,10 +15,10 @@ import (
|
||||
)
|
||||
|
||||
func TestPluginStore(t *testing.T, ss store.Store, s SqlStore) {
|
||||
t.Run("SaveOrUpdate", func(t *testing.T) { testPluginSaveOrUpdate(t, ss, s) })
|
||||
t.Run("CompareAndSet", func(t *testing.T) { testPluginCompareAndSet(t, ss, s) })
|
||||
t.Run("CompareAndDelete", func(t *testing.T) { testPluginCompareAndDelete(t, ss, s) })
|
||||
t.Run("SetWithOptions", func(t *testing.T) { testPluginSetWithOptions(t, ss, s) })
|
||||
t.Run("SaveOrUpdate", func(t *testing.T) { testPluginSaveOrUpdate(t, ss) })
|
||||
t.Run("CompareAndSet", func(t *testing.T) { testPluginCompareAndSet(t, ss) })
|
||||
t.Run("CompareAndDelete", func(t *testing.T) { testPluginCompareAndDelete(t, ss) })
|
||||
t.Run("SetWithOptions", func(t *testing.T) { testPluginSetWithOptions(t, ss) })
|
||||
t.Run("Get", func(t *testing.T) { testPluginGet(t, ss) })
|
||||
t.Run("Delete", func(t *testing.T) { testPluginDelete(t, ss) })
|
||||
t.Run("DeleteAllForPlugin", func(t *testing.T) { testPluginDeleteAllForPlugin(t, ss) })
|
||||
@@ -63,7 +63,7 @@ func setupKVs(t *testing.T, ss store.Store) (string, func()) {
|
||||
}
|
||||
}
|
||||
|
||||
func doTestPluginSaveOrUpdate(t *testing.T, ss store.Store, s SqlStore, doer func(kv *model.PluginKeyValue) (*model.PluginKeyValue, error)) {
|
||||
func doTestPluginSaveOrUpdate(t *testing.T, ss store.Store, doer func(kv *model.PluginKeyValue) (*model.PluginKeyValue, error)) {
|
||||
t.Run("invalid kv", func(t *testing.T) {
|
||||
_, tearDown := setupKVs(t, ss)
|
||||
defer tearDown()
|
||||
@@ -219,15 +219,15 @@ func doTestPluginSaveOrUpdate(t *testing.T, ss store.Store, s SqlStore, doer fun
|
||||
})
|
||||
}
|
||||
|
||||
func testPluginSaveOrUpdate(t *testing.T, ss store.Store, s SqlStore) {
|
||||
doTestPluginSaveOrUpdate(t, ss, s, func(kv *model.PluginKeyValue) (*model.PluginKeyValue, error) {
|
||||
func testPluginSaveOrUpdate(t *testing.T, ss store.Store) {
|
||||
doTestPluginSaveOrUpdate(t, ss, func(kv *model.PluginKeyValue) (*model.PluginKeyValue, error) {
|
||||
return ss.Plugin().SaveOrUpdate(kv)
|
||||
})
|
||||
}
|
||||
|
||||
// doTestPluginCompareAndSet exercises the CompareAndSet functionality, but abstracts the actual
|
||||
// call to same to allow reuse with SetWithOptions
|
||||
func doTestPluginCompareAndSet(t *testing.T, ss store.Store, s SqlStore, compareAndSet func(kv *model.PluginKeyValue, oldValue []byte) (bool, error)) {
|
||||
func doTestPluginCompareAndSet(t *testing.T, ss store.Store, compareAndSet func(kv *model.PluginKeyValue, oldValue []byte) (bool, error)) {
|
||||
t.Run("invalid kv", func(t *testing.T) {
|
||||
_, tearDown := setupKVs(t, ss)
|
||||
defer tearDown()
|
||||
@@ -419,7 +419,7 @@ func doTestPluginCompareAndSet(t *testing.T, ss store.Store, s SqlStore, compare
|
||||
}
|
||||
|
||||
for description, setToSameValue := range testCases {
|
||||
makeKV := func(t *testing.T, existingKV *model.PluginKeyValue) *model.PluginKeyValue {
|
||||
makeKV := func(existingKV *model.PluginKeyValue) *model.PluginKeyValue {
|
||||
kv := &model.PluginKeyValue{
|
||||
PluginId: existingKV.PluginId,
|
||||
Key: existingKV.Key,
|
||||
@@ -446,7 +446,7 @@ func doTestPluginCompareAndSet(t *testing.T, ss store.Store, s SqlStore, compare
|
||||
existingKV, tearDown := setup(t)
|
||||
defer tearDown()
|
||||
|
||||
kv := makeKV(t, existingKV)
|
||||
kv := makeKV(existingKV)
|
||||
assertUnchanged(t, kv, existingKV, oldValue)
|
||||
})
|
||||
}
|
||||
@@ -456,7 +456,7 @@ func doTestPluginCompareAndSet(t *testing.T, ss store.Store, s SqlStore, compare
|
||||
existingKV, tearDown := setup(t)
|
||||
defer tearDown()
|
||||
|
||||
kv := makeKV(t, existingKV)
|
||||
kv := makeKV(existingKV)
|
||||
|
||||
assertChanged(t, kv, existingKV.Value)
|
||||
})
|
||||
@@ -465,7 +465,7 @@ func doTestPluginCompareAndSet(t *testing.T, ss store.Store, s SqlStore, compare
|
||||
existingKV, tearDown := setup(t)
|
||||
defer tearDown()
|
||||
|
||||
kv := makeKV(t, existingKV)
|
||||
kv := makeKV(existingKV)
|
||||
kv.ExpireAt = model.GetMillis() + 15*1000
|
||||
|
||||
assertChanged(t, kv, existingKV.Value)
|
||||
@@ -475,7 +475,7 @@ func doTestPluginCompareAndSet(t *testing.T, ss store.Store, s SqlStore, compare
|
||||
existingKV, tearDown := setup(t)
|
||||
defer tearDown()
|
||||
|
||||
kv := makeKV(t, existingKV)
|
||||
kv := makeKV(existingKV)
|
||||
kv.ExpireAt = model.GetMillis() - 15*1000
|
||||
|
||||
assertRemoved(t, kv, existingKV.Value)
|
||||
@@ -484,7 +484,7 @@ func doTestPluginCompareAndSet(t *testing.T, ss store.Store, s SqlStore, compare
|
||||
}
|
||||
|
||||
t.Run("setting a nil value", func(t *testing.T) {
|
||||
makeKV := func(t *testing.T, existingKV *model.PluginKeyValue) *model.PluginKeyValue {
|
||||
makeKV := func(existingKV *model.PluginKeyValue) *model.PluginKeyValue {
|
||||
kv := &model.PluginKeyValue{
|
||||
PluginId: existingKV.PluginId,
|
||||
Key: existingKV.Key,
|
||||
@@ -507,7 +507,7 @@ func doTestPluginCompareAndSet(t *testing.T, ss store.Store, s SqlStore, compare
|
||||
existingKV, tearDown := setup(t)
|
||||
defer tearDown()
|
||||
|
||||
kv := makeKV(t, existingKV)
|
||||
kv := makeKV(existingKV)
|
||||
assertUnchanged(t, kv, existingKV, oldValue)
|
||||
})
|
||||
}
|
||||
@@ -517,20 +517,20 @@ func doTestPluginCompareAndSet(t *testing.T, ss store.Store, s SqlStore, compare
|
||||
existingKV, tearDown := setup(t)
|
||||
defer tearDown()
|
||||
|
||||
kv := makeKV(t, existingKV)
|
||||
kv := makeKV(existingKV)
|
||||
assertRemoved(t, kv, existingKV.Value)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func testPluginCompareAndSet(t *testing.T, ss store.Store, s SqlStore) {
|
||||
doTestPluginCompareAndSet(t, ss, s, func(kv *model.PluginKeyValue, oldValue []byte) (bool, error) {
|
||||
func testPluginCompareAndSet(t *testing.T, ss store.Store) {
|
||||
doTestPluginCompareAndSet(t, ss, func(kv *model.PluginKeyValue, oldValue []byte) (bool, error) {
|
||||
return ss.Plugin().CompareAndSet(kv, oldValue)
|
||||
})
|
||||
}
|
||||
|
||||
func testPluginCompareAndDelete(t *testing.T, ss store.Store, s SqlStore) {
|
||||
func testPluginCompareAndDelete(t *testing.T, ss store.Store) {
|
||||
t.Run("invalid kv", func(t *testing.T) {
|
||||
_, tearDown := setupKVs(t, ss)
|
||||
defer tearDown()
|
||||
@@ -660,7 +660,7 @@ func testPluginCompareAndDelete(t *testing.T, ss store.Store, s SqlStore) {
|
||||
})
|
||||
}
|
||||
|
||||
func testPluginSetWithOptions(t *testing.T, ss store.Store, s SqlStore) {
|
||||
func testPluginSetWithOptions(t *testing.T, ss store.Store) {
|
||||
t.Run("invalid options", func(t *testing.T) {
|
||||
_, tearDown := setupKVs(t, ss)
|
||||
defer tearDown()
|
||||
@@ -699,7 +699,7 @@ func testPluginSetWithOptions(t *testing.T, ss store.Store, s SqlStore) {
|
||||
})
|
||||
|
||||
t.Run("atomic", func(t *testing.T) {
|
||||
doTestPluginCompareAndSet(t, ss, s, func(kv *model.PluginKeyValue, oldValue []byte) (bool, error) {
|
||||
doTestPluginCompareAndSet(t, ss, func(kv *model.PluginKeyValue, oldValue []byte) (bool, error) {
|
||||
now := model.GetMillis()
|
||||
options := model.PluginKVSetOptions{
|
||||
Atomic: true,
|
||||
@@ -715,7 +715,7 @@ func testPluginSetWithOptions(t *testing.T, ss store.Store, s SqlStore) {
|
||||
})
|
||||
|
||||
t.Run("non-atomic", func(t *testing.T) {
|
||||
doTestPluginSaveOrUpdate(t, ss, s, func(kv *model.PluginKeyValue) (*model.PluginKeyValue, error) {
|
||||
doTestPluginSaveOrUpdate(t, ss, func(kv *model.PluginKeyValue) (*model.PluginKeyValue, error) {
|
||||
now := model.GetMillis()
|
||||
options := model.PluginKVSetOptions{
|
||||
Atomic: false,
|
||||
|
||||
@@ -361,7 +361,7 @@ func testRoleStorePermanentDeleteAll(t *testing.T, ss store.Store) {
|
||||
}
|
||||
|
||||
func testRoleStoreLowerScopedChannelSchemeRoles(t *testing.T, ss store.Store) {
|
||||
createDefaultRoles(t, ss)
|
||||
createDefaultRoles(ss)
|
||||
|
||||
teamScheme1 := &model.Scheme{
|
||||
DisplayName: model.NewId(),
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
func TestSchemeStore(t *testing.T, ss store.Store) {
|
||||
createDefaultRoles(t, ss)
|
||||
createDefaultRoles(ss)
|
||||
|
||||
t.Run("Save", func(t *testing.T) { testSchemeStoreSave(t, ss) })
|
||||
t.Run("Get", func(t *testing.T) { testSchemeStoreGet(t, ss) })
|
||||
@@ -26,7 +26,7 @@ func TestSchemeStore(t *testing.T, ss store.Store) {
|
||||
t.Run("CountWithoutPermission", func(t *testing.T) { testCountWithoutPermission(t, ss) })
|
||||
}
|
||||
|
||||
func createDefaultRoles(t *testing.T, ss store.Store) {
|
||||
func createDefaultRoles(ss store.Store) {
|
||||
ss.Role().Save(&model.Role{
|
||||
Name: model.TEAM_ADMIN_ROLE_ID,
|
||||
DisplayName: model.TEAM_ADMIN_ROLE_ID,
|
||||
|
||||
@@ -26,7 +26,7 @@ func cleanupTeamStore(t *testing.T, ss store.Store) {
|
||||
}
|
||||
|
||||
func TestTeamStore(t *testing.T, ss store.Store) {
|
||||
createDefaultRoles(t, ss)
|
||||
createDefaultRoles(ss)
|
||||
|
||||
t.Run("Save", func(t *testing.T) { testTeamStoreSave(t, ss) })
|
||||
t.Run("Update", func(t *testing.T) { testTeamStoreUpdate(t, ss) })
|
||||
|
||||
@@ -214,7 +214,7 @@ func (b *blockReader) close() error {
|
||||
}
|
||||
|
||||
// decode reads a GIF image from r and stores the result in d.
|
||||
func (d *decoder) decode(r io.Reader, configOnly, keepAllFrames bool) error {
|
||||
func (d *decoder) decode(r io.Reader, configOnly bool) error {
|
||||
// Add buffering if r does not provide ReadByte.
|
||||
if rr, ok := r.(reader); ok {
|
||||
d.r = rr
|
||||
@@ -244,7 +244,7 @@ func (d *decoder) decode(r io.Reader, configOnly, keepAllFrames bool) error {
|
||||
}
|
||||
|
||||
case sImageDescriptor:
|
||||
if err = d.readImageDescriptor(keepAllFrames); err != nil {
|
||||
if err = d.readImageDescriptor(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -370,7 +370,7 @@ func (d *decoder) readGraphicControl() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *decoder) readImageDescriptor(keepAllFrames bool) error {
|
||||
func (d *decoder) readImageDescriptor() error {
|
||||
m, err := d.newImageFromDescriptor()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -503,7 +503,7 @@ func (d *decoder) readBlock() (int, error) {
|
||||
|
||||
func CountFrames(r io.Reader) (int, error) {
|
||||
var d decoder
|
||||
if err := d.decode(r, false, true); err != nil {
|
||||
if err := d.decode(r, false); err != nil {
|
||||
return -1, err
|
||||
}
|
||||
return d.imageCount, nil
|
||||
|
||||
@@ -34,7 +34,7 @@ func (b *BlockQuote) AddChild(openBlocks []Block) []Block {
|
||||
return openBlocks
|
||||
}
|
||||
|
||||
func blockQuoteStart(markdown string, indent int, r Range, matchedBlocks, unmatchedBlocks []Block) []Block {
|
||||
func blockQuoteStart(markdown string, indent int, r Range) []Block {
|
||||
if indent > 3 {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -130,13 +130,13 @@ func blockStart(markdown string, indentation int, r Range, matchedBlocks, unmatc
|
||||
return nil
|
||||
}
|
||||
|
||||
if start := blockQuoteStart(markdown, indentation, r, matchedBlocks, unmatchedBlocks); start != nil {
|
||||
if start := blockQuoteStart(markdown, indentation, r); start != nil {
|
||||
return start
|
||||
} else if start := listStart(markdown, indentation, r, matchedBlocks, unmatchedBlocks); start != nil {
|
||||
return start
|
||||
} else if start := indentedCodeStart(markdown, indentation, r, matchedBlocks, unmatchedBlocks); start != nil {
|
||||
return start
|
||||
} else if start := fencedCodeStart(markdown, indentation, r, matchedBlocks, unmatchedBlocks); start != nil {
|
||||
} else if start := fencedCodeStart(markdown, indentation, r); start != nil {
|
||||
return start
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ func (b *FencedCode) AllowsBlockStarts() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func fencedCodeStart(markdown string, indentation int, r Range, matchedBlocks, unmatchedBlocks []Block) []Block {
|
||||
func fencedCodeStart(markdown string, indentation int, r Range) []Block {
|
||||
s := markdown[r.Position:r.End]
|
||||
|
||||
if !strings.HasPrefix(s, "```") && !strings.HasPrefix(s, "~~~") {
|
||||
|
||||
@@ -21,10 +21,8 @@ import (
|
||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/plugin"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
"github.com/mattermost/mattermost-server/v5/store/localcachelayer"
|
||||
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
|
||||
"github.com/mattermost/mattermost-server/v5/testlib"
|
||||
"github.com/mattermost/mattermost-server/v5/utils"
|
||||
)
|
||||
|
||||
@@ -51,8 +49,8 @@ func SetupWithStoreMock(tb testing.TB) *TestHelper {
|
||||
if testing.Short() {
|
||||
tb.SkipNow()
|
||||
}
|
||||
store := testlib.GetMockStoreForSetupFunctions()
|
||||
th := setupTestHelper(tb, store, false)
|
||||
|
||||
th := setupTestHelper(false)
|
||||
emptyMockStore := mocks.Store{}
|
||||
emptyMockStore.On("Close").Return(nil)
|
||||
th.App.Srv().Store = &emptyMockStore
|
||||
@@ -65,10 +63,10 @@ func Setup(tb testing.TB) *TestHelper {
|
||||
}
|
||||
store := mainHelper.GetStore()
|
||||
store.DropAllTables()
|
||||
return setupTestHelper(tb, store, true)
|
||||
return setupTestHelper(true)
|
||||
}
|
||||
|
||||
func setupTestHelper(t testing.TB, store store.Store, includeCacheLayer bool) *TestHelper {
|
||||
func setupTestHelper(includeCacheLayer bool) *TestHelper {
|
||||
memoryStore := config.NewTestMemoryStore()
|
||||
newConfig := memoryStore.Get().Clone()
|
||||
*newConfig.AnnouncementSettings.AdminNoticesEnabled = false
|
||||
|
||||
Reference in New Issue
Block a user