From e52ab9737ed4043b5c6236561939d50a8588b349 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Tue, 9 May 2017 15:17:06 -0400 Subject: Fixing session error (#6370) --- app/session.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/session.go b/app/session.go index 273ab2dd5..89244d780 100644 --- a/app/session.go +++ b/app/session.go @@ -49,7 +49,7 @@ func GetSession(token string) (*model.Session, *model.AppError) { session = sessionResult.Data.(*model.Session) if session == nil || session.IsExpired() || session.Token != token { - return nil, model.NewLocAppError("GetSession", "api.context.invalid_token.error", map[string]interface{}{"Token": token, "Error": sessionResult.Err.DetailedError}, "") + return nil, model.NewLocAppError("GetSession", "api.context.invalid_token.error", map[string]interface{}{"Token": token, "Error": ""}, "") } else { AddSessionToCache(session) return session, nil -- cgit v1.2.3-1-g7c22 From 8c8d9dbf8fa3b4ebf640bf5e1a71f9c04b57e111 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Tue, 9 May 2017 16:01:06 -0400 Subject: Forward port 3.8.1 changes that missed master (#6362) --- app/channel.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/channel.go b/app/channel.go index ee53ace45..3e794a0c9 100644 --- a/app/channel.go +++ b/app/channel.go @@ -218,7 +218,7 @@ func WaitForChannelMembership(channelId string, userId string) { } } -func CreateGroupChannel(userIds []string) (*model.Channel, *model.AppError) { +func CreateGroupChannel(userIds []string, creatorId 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) } @@ -261,6 +261,10 @@ func CreateGroupChannel(userIds []string) (*model.Channel, *model.AppError) { return nil, result.Err } + if user.Id == creatorId { + WaitForChannelMembership(group.Id, creatorId) + } + InvalidateCacheForUser(user.Id) } -- cgit v1.2.3-1-g7c22 From 535eb14eeb344a64667ad18d514a93fa738b07b7 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Tue, 9 May 2017 16:01:16 -0400 Subject: Get protocol correctly if using SSL direct to Mattermost (#6361) --- app/login.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/login.go b/app/login.go index 4f9284140..2528f9367 100644 --- a/app/login.go +++ b/app/login.go @@ -138,7 +138,7 @@ func DoLogin(w http.ResponseWriter, r *http.Request, user *model.User, deviceId } func GetProtocol(r *http.Request) string { - if r.Header.Get(model.HEADER_FORWARDED_PROTO) == "https" { + if r.Header.Get(model.HEADER_FORWARDED_PROTO) == "https" || r.TLS != nil { return "https" } else { return "http" -- cgit v1.2.3-1-g7c22 From 0ae68865138458f2f8fd36bbbba07728c88609d7 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Wed, 10 May 2017 09:48:50 -0400 Subject: Detach session activity update from statuses (#6379) --- app/session.go | 14 ++++++++++++++ app/status.go | 5 ----- app/web_conn.go | 5 ++++- app/websocket_router.go | 5 ++++- 4 files changed, 22 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/session.go b/app/session.go index 89244d780..7290bfd88 100644 --- a/app/session.go +++ b/app/session.go @@ -181,3 +181,17 @@ func AttachDeviceId(sessionId string, deviceId string, expiresAt int64) *model.A return nil } + +func UpdateLastActivityAtIfNeeded(session model.Session) { + now := model.GetMillis() + if now-session.LastActivityAt < model.SESSION_ACTIVITY_TIMEOUT { + return + } + + if result := <-Srv.Store.Session().UpdateLastActivityAt(session.Id, now); result.Err != nil { + l4g.Error(utils.T("api.status.last_activity.error", session.UserId, session.Id)) + } + + session.LastActivityAt = now + AddSessionToCache(&session) +} diff --git a/app/status.go b/app/status.go index dd57b82b2..f0a26e6eb 100644 --- a/app/status.go +++ b/app/status.go @@ -195,7 +195,6 @@ func SetStatusOnline(userId string, sessionId string, manual bool) { // Only update the database if the status has changed, the status has been manually set, // or enough time has passed since the previous action if status.Status != oldStatus || status.Manual != oldManual || status.LastActivityAt-oldTime > model.STATUS_MIN_UPDATE_TIME { - achan := Srv.Store.Session().UpdateLastActivityAt(sessionId, status.LastActivityAt) var schan store.StoreChannel if broadcast { @@ -204,10 +203,6 @@ func SetStatusOnline(userId string, sessionId string, manual bool) { schan = Srv.Store.Status().UpdateLastActivityAt(status.UserId, status.LastActivityAt) } - if result := <-achan; result.Err != nil { - l4g.Error(utils.T("api.status.last_activity.error"), userId, sessionId, result.Err) - } - if result := <-schan; result.Err != nil { l4g.Error(utils.T("api.status.save_status.error"), userId, result.Err) } diff --git a/app/web_conn.go b/app/web_conn.go index 2c1913e2b..1ebed9fa5 100644 --- a/app/web_conn.go +++ b/app/web_conn.go @@ -43,7 +43,10 @@ type WebConn struct { func NewWebConn(ws *websocket.Conn, session model.Session, t goi18n.TranslateFunc, locale string) *WebConn { if len(session.UserId) > 0 { - go SetStatusOnline(session.UserId, session.Id, false) + go func() { + SetStatusOnline(session.UserId, session.Id, false) + UpdateLastActivityAtIfNeeded(session) + }() } return &WebConn{ diff --git a/app/websocket_router.go b/app/websocket_router.go index 84806b5cf..80773eb9d 100644 --- a/app/websocket_router.go +++ b/app/websocket_router.go @@ -53,7 +53,10 @@ func (wr *WebSocketRouter) ServeWebSocket(conn *WebConn, r *model.WebSocketReque if err != nil { conn.WebSocket.Close() } else { - go SetStatusOnline(session.UserId, session.Id, false) + go func() { + SetStatusOnline(session.UserId, session.Id, false) + UpdateLastActivityAtIfNeeded(*session) + }() conn.SessionToken = session.Token conn.UserId = session.UserId -- cgit v1.2.3-1-g7c22 From 6026ed9d537cc2f41a263694a06b56cd645081b7 Mon Sep 17 00:00:00 2001 From: George Goldberg Date: Thu, 11 May 2017 00:16:45 +0100 Subject: PLT-6523: Don't crash when replying to a post whose poster has left the channel. (#6388) --- app/notification.go | 2 +- app/post_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 app/post_test.go (limited to 'app') diff --git a/app/notification.go b/app/notification.go index c48465003..0f59fae21 100644 --- a/app/notification.go +++ b/app/notification.go @@ -83,7 +83,7 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe for _, threadPost := range list.Posts { profile := profileMap[threadPost.UserId] - if profile.NotifyProps["comments"] == "any" || (profile.NotifyProps["comments"] == "root" && threadPost.Id == list.Order[0]) { + if profile != nil && (profile.NotifyProps["comments"] == "any" || (profile.NotifyProps["comments"] == "root" && threadPost.Id == list.Order[0])) { mentionedUserIds[threadPost.UserId] = true } } diff --git a/app/post_test.go b/app/post_test.go new file mode 100644 index 000000000..9bc5ee742 --- /dev/null +++ b/app/post_test.go @@ -0,0 +1,44 @@ +// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package app + +import ( + "testing" + + "github.com/mattermost/platform/model" + "fmt" +) + +func TestPostReplyToPostWhereRootPosterLeftChannel(t *testing.T) { + // This test ensures that when replying to a root post made by a user who has since left the channel, the reply + // post completes successfully. This is a regression test for PLT-6523. + th := Setup().InitBasic() + + channel := th.BasicChannel + userInChannel := th.BasicUser2 + userNotInChannel := th.BasicUser + rootPost := th.BasicPost + + if _, err := AddUserToChannel(userInChannel, channel); err != nil { + t.Fatal(err) + } + + if err := RemoveUserFromChannel(userNotInChannel.Id, "", channel); err != nil { + t.Fatal(err) + } + + replyPost := model.Post{ + Message: "asd", + ChannelId: channel.Id, + RootId: rootPost.Id, + ParentId: rootPost.Id, + PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()), + UserId: userInChannel.Id, + CreateAt: 0, + } + + if _, err := CreatePostAsUser(&replyPost); err != nil { + t.Fatal(err) + } +} -- cgit v1.2.3-1-g7c22 From be7c53ec7fffaa1751a162f4a34760f94e941bc6 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Thu, 11 May 2017 08:10:59 -0400 Subject: Send status change event if status changes on channel view (#6389) --- app/channel.go | 8 ++++++++ app/status.go | 12 ++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/channel.go b/app/channel.go index 3e794a0c9..a1a70560d 100644 --- a/app/channel.go +++ b/app/channel.go @@ -1016,9 +1016,13 @@ func GetNumberOfChannelsOnTeam(teamId string) (int, *model.AppError) { func SetActiveChannel(userId string, channelId string) *model.AppError { status, err := GetStatus(userId) + + oldStatus := model.STATUS_OFFLINE + if err != nil { status = &model.Status{UserId: userId, Status: model.STATUS_ONLINE, Manual: false, LastActivityAt: model.GetMillis(), ActiveChannel: channelId} } else { + oldStatus = status.Status status.ActiveChannel = channelId if !status.Manual { status.Status = model.STATUS_ONLINE @@ -1028,6 +1032,10 @@ func SetActiveChannel(userId string, channelId string) *model.AppError { AddStatusCache(status) + if status.Status != oldStatus { + BroadcastStatus(status) + } + return nil } diff --git a/app/status.go b/app/status.go index f0a26e6eb..868e57563 100644 --- a/app/status.go +++ b/app/status.go @@ -209,13 +209,17 @@ func SetStatusOnline(userId string, sessionId string, manual bool) { } if broadcast { - event := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_STATUS_CHANGE, "", "", status.UserId, nil) - event.Add("status", model.STATUS_ONLINE) - event.Add("user_id", status.UserId) - go Publish(event) + BroadcastStatus(status) } } +func BroadcastStatus(status *model.Status) { + event := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_STATUS_CHANGE, "", "", status.UserId, nil) + event.Add("status", status.Status) + event.Add("user_id", status.UserId) + go Publish(event) +} + func SetStatusOffline(userId string, manual bool) { if !*utils.Cfg.ServiceSettings.EnableUserStatuses { return -- cgit v1.2.3-1-g7c22