diff --git a/app/command_channel_header.go b/app/command_channel_header.go index db92f68b2d..c63787ee76 100644 --- a/app/command_channel_header.go +++ b/app/command_channel_header.go @@ -62,7 +62,8 @@ func (me *HeaderProvider) DoCommand(a *App, args *model.CommandArgs, message str case model.CHANNEL_GROUP, model.CHANNEL_DIRECT: // Modifying the header is not linked to any specific permission for group/dm channels, so just check for membership. - channelMember, err := a.GetChannelMember(args.ChannelId, args.Session.UserId) + var channelMember *model.ChannelMember + channelMember, err = a.GetChannelMember(args.ChannelId, args.Session.UserId) if err != nil || channelMember == nil { return &model.CommandResponse{ Text: args.T("api.command_channel_header.permission.app_error"), diff --git a/app/export.go b/app/export.go index 18c11cbd52..4cb8c18ea9 100644 --- a/app/export.go +++ b/app/export.go @@ -5,7 +5,6 @@ package app import ( "encoding/json" - "errors" "io" "net/http" "os" @@ -13,6 +12,7 @@ import ( "strings" "github.com/mattermost/mattermost-server/model" + "github.com/pkg/errors" ) func (a *App) BulkExport(writer io.Writer, file string, pathToEmojiDir string, dirNameToExportEmoji string) *model.AppError { @@ -404,8 +404,6 @@ func (a *App) createDirForEmoji(file string, dirName string) string { // Copies emoji files from 'data/emoji' dir to 'exported_emoji' dir func (a *App) copyEmojiImages(emojiId string, emojiImagePath string, pathToDir string) error { - var err error - fromPath, err := os.Open(emojiImagePath) if fromPath == nil || err != nil { return errors.New("Error reading " + emojiImagePath + "file") @@ -414,12 +412,16 @@ func (a *App) copyEmojiImages(emojiId string, emojiImagePath string, pathToDir s emojiDir := pathToDir + "/" + emojiId - if _, err := os.Stat(emojiDir); os.IsNotExist(err) { - os.Mkdir(emojiDir, os.ModePerm) - } - if err != nil { - return errors.New("Error creating directory for the emoji " + err.Error()) + if _, err = os.Stat(emojiDir); err != nil { + if !os.IsNotExist(err) { + return errors.Wrapf(err, "Error fetching file info of emoji directory %v", emojiDir) + } + + if err = os.Mkdir(emojiDir, os.ModePerm); err != nil { + return errors.Wrapf(err, "Error creating emoji directory %v", emojiDir) + } } + toPath, err := os.OpenFile(emojiDir+"/image", os.O_RDWR|os.O_CREATE, 0666) if err != nil { return errors.New("Error creating the image file " + err.Error()) diff --git a/app/login.go b/app/login.go index b7bd07fd13..01385e5429 100644 --- a/app/login.go +++ b/app/login.go @@ -45,8 +45,7 @@ func (a *App) AuthenticateUserForLogin(id, loginId, password, mfaToken string, l }() if len(password) == 0 { - err := model.NewAppError("AuthenticateUserForLogin", "api.user.login.blank_pwd.app_error", nil, "", http.StatusBadRequest) - return nil, err + return nil, model.NewAppError("AuthenticateUserForLogin", "api.user.login.blank_pwd.app_error", nil, "", http.StatusBadRequest) } // Get the MM user we are trying to login diff --git a/app/notification_push.go b/app/notification_push.go index af69452979..efe5970397 100644 --- a/app/notification_push.go +++ b/app/notification_push.go @@ -317,13 +317,14 @@ func ShouldSendPushNotification(user *model.User, channelNotifyProps model.Strin func DoesNotifyPropsAllowPushNotification(user *model.User, channelNotifyProps model.StringMap, post *model.Post, wasMentioned bool) bool { userNotifyProps := user.NotifyProps userNotify := userNotifyProps[model.PUSH_NOTIFY_PROP] - channelNotify, ok := channelNotifyProps[model.PUSH_NOTIFY_PROP] + channelNotify, _ := channelNotifyProps[model.PUSH_NOTIFY_PROP] + if channelNotify == "" { + channelNotify = model.CHANNEL_NOTIFY_DEFAULT + } // If the channel is muted do not send push notifications - if channelMuted, ok := channelNotifyProps[model.MARK_UNREAD_NOTIFY_PROP]; ok { - if channelMuted == model.CHANNEL_MARK_UNREAD_MENTION { - return false - } + if channelNotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_MARK_UNREAD_MENTION { + return false } if post.IsSystemMessage() { @@ -338,7 +339,7 @@ func DoesNotifyPropsAllowPushNotification(user *model.User, channelNotifyProps m return false } - if userNotify == model.USER_NOTIFY_MENTION && (!ok || channelNotify == model.CHANNEL_NOTIFY_DEFAULT) && !wasMentioned { + if userNotify == model.USER_NOTIFY_MENTION && channelNotify == model.CHANNEL_NOTIFY_DEFAULT && !wasMentioned { return false } @@ -348,7 +349,7 @@ func DoesNotifyPropsAllowPushNotification(user *model.User, channelNotifyProps m } if userNotify == model.USER_NOTIFY_NONE && - (!ok || channelNotify == model.CHANNEL_NOTIFY_DEFAULT) { + channelNotify == model.CHANNEL_NOTIFY_DEFAULT { return false }