From 9ec99593eb4228a0a0a815e01aef9a782b63aede Mon Sep 17 00:00:00 2001 From: Eli Yukelzon Date: Fri, 14 Jun 2019 18:36:38 +0300 Subject: [PATCH] MM-14721 - Add an identifier for compliance exports when a message is posted by a bot account (#11063) * check from_bot post property to override IsBot --- model/compliance_post.go | 9 +++++++++ model/message_export.go | 1 + store/sqlstore/compliance_store.go | 19 +++++++++++++------ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/model/compliance_post.go b/model/compliance_post.go index 75e8de1f15..ac3cf4e1f5 100644 --- a/model/compliance_post.go +++ b/model/compliance_post.go @@ -37,6 +37,8 @@ type CompliancePost struct { PostProps string PostHashtags string PostFileIds string + + IsBot bool } func CompliancePostHeader() []string { @@ -64,6 +66,7 @@ func CompliancePostHeader() []string { "PostProps", "PostHashtags", "PostFileIds", + "UserType", } } @@ -88,6 +91,11 @@ func (me *CompliancePost) Row() []string { postUpdateAt = time.Unix(0, me.PostUpdateAt*int64(1000*1000)).Format(time.RFC3339) } + userType := "user" + if me.IsBot { + userType = "bot" + } + return []string{ cleanComplianceStrings(me.TeamName), cleanComplianceStrings(me.TeamDisplayName), @@ -99,6 +107,7 @@ func (me *CompliancePost) Row() []string { cleanComplianceStrings(me.UserUsername), cleanComplianceStrings(me.UserEmail), cleanComplianceStrings(me.UserNickname), + userType, me.PostId, time.Unix(0, me.PostCreateAt*int64(1000*1000)).Format(time.RFC3339), diff --git a/model/message_export.go b/model/message_export.go index 56608cdfef..96b78b4b74 100644 --- a/model/message_export.go +++ b/model/message_export.go @@ -23,6 +23,7 @@ type MessageExport struct { PostMessage *string PostType *string PostRootId *string + PostProps *string PostOriginalId *string PostFileIds StringArray } diff --git a/store/sqlstore/compliance_store.go b/store/sqlstore/compliance_store.go index 9ad74ca89f..bb32f5d3b0 100644 --- a/store/sqlstore/compliance_store.go +++ b/store/sqlstore/compliance_store.go @@ -142,12 +142,14 @@ func (s SqlComplianceStore) ComplianceExport(job *model.Compliance) ([]*model.Co Posts.Type AS PostType, Posts.Props AS PostProps, Posts.Hashtags AS PostHashtags, - Posts.FileIds AS PostFileIds + Posts.FileIds AS PostFileIds, + Bots.UserId IS NOT NULL AS IsBot FROM Teams, Channels, Users, Posts + LEFT JOIN Bots ON Bots.UserId = Posts.UserId WHERE Teams.Id = Channels.TeamId AND Posts.ChannelId = Channels.Id @@ -177,11 +179,13 @@ func (s SqlComplianceStore) ComplianceExport(job *model.Compliance) ([]*model.Co Posts.Type AS PostType, Posts.Props AS PostProps, Posts.Hashtags AS PostHashtags, - Posts.FileIds AS PostFileIds + Posts.FileIds AS PostFileIds, + Bots.UserId IS NOT NULL AS IsBot FROM Channels, Users, Posts + LEFT JOIN Bots ON Bots.UserId = Posts.UserId WHERE Channels.TeamId = '' AND Posts.ChannelId = Channels.Id @@ -211,6 +215,7 @@ func (s SqlComplianceStore) MessageExport(after int64, limit int) ([]*model.Mess Posts.Type AS PostType, Posts.OriginalId AS PostOriginalId, Posts.RootId AS PostRootId, + Posts.Props AS PostProps, Posts.FileIds AS PostFileIds, Teams.Id AS TeamId, Teams.Name AS TeamName, @@ -225,12 +230,14 @@ func (s SqlComplianceStore) MessageExport(after int64, limit int) ([]*model.Mess Channels.Type AS ChannelType, Users.Id AS UserId, Users.Email AS UserEmail, - Users.Username + Users.Username, + Bots.UserId IS NOT NULL AS IsBot FROM Posts - LEFT OUTER JOIN Channels ON Posts.ChannelId = Channels.Id - LEFT OUTER JOIN Teams ON Channels.TeamId = Teams.Id - LEFT OUTER JOIN Users ON Posts.UserId = Users.Id + LEFT OUTER JOIN Channels ON Posts.ChannelId = Channels.Id + LEFT OUTER JOIN Teams ON Channels.TeamId = Teams.Id + LEFT OUTER JOIN Users ON Posts.UserId = Users.Id + LEFT JOIN Bots ON Bots.UserId = Posts.UserId WHERE Posts.CreateAt > :StartTime AND Posts.Type = ''