summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2017-09-04 02:49:40 -0700
committerGeorge Goldberg <george@gberg.me>2017-09-04 10:49:40 +0100
commit9c1f6c9fd5716fece1afaf8a3d6a7dd235744a38 (patch)
treefd41d02f9c938b20f5db81ce31e6b2123f0deace /store
parent670bfbf62686ebe9f2ab332733d851a62b6950b0 (diff)
downloadchat-9c1f6c9fd5716fece1afaf8a3d6a7dd235744a38.tar.gz
chat-9c1f6c9fd5716fece1afaf8a3d6a7dd235744a38.tar.bz2
chat-9c1f6c9fd5716fece1afaf8a3d6a7dd235744a38.zip
PLT-7497 adding DMs to complinace export (#7353)
Diffstat (limited to 'store')
-rw-r--r--store/sql_compliance_store.go39
-rw-r--r--store/sql_compliance_store_test.go90
2 files changed, 126 insertions, 3 deletions
diff --git a/store/sql_compliance_store.go b/store/sql_compliance_store.go
index 4ffbcf113..0a9626eed 100644
--- a/store/sql_compliance_store.go
+++ b/store/sql_compliance_store.go
@@ -180,7 +180,7 @@ func (s SqlComplianceStore) ComplianceExport(job *model.Compliance) StoreChannel
}
query :=
- `SELECT
+ `(SELECT
Teams.Name AS TeamName,
Teams.DisplayName AS TeamDisplayName,
Channels.Name AS ChannelName,
@@ -212,8 +212,41 @@ func (s SqlComplianceStore) ComplianceExport(job *model.Compliance) StoreChannel
AND Posts.CreateAt > :StartTime
AND Posts.CreateAt <= :EndTime
` + emailQuery + `
- ` + keywordQuery + `
- ORDER BY Posts.CreateAt
+ ` + keywordQuery + `)
+ UNION ALL
+ (SELECT
+ "direct-message" AS TeamName,
+ "Direct Message" AS TeamDisplayName,
+ Channels.Name AS ChannelName,
+ Channels.DisplayName AS ChannelDisplayName,
+ Users.Username AS UserUsername,
+ Users.Email AS UserEmail,
+ Users.Nickname AS UserNickname,
+ Posts.Id AS PostId,
+ Posts.CreateAt AS PostCreateAt,
+ Posts.UpdateAt AS PostUpdateAt,
+ Posts.DeleteAt AS PostDeleteAt,
+ Posts.RootId AS PostRootId,
+ Posts.ParentId AS PostParentId,
+ Posts.OriginalId AS PostOriginalId,
+ Posts.Message AS PostMessage,
+ Posts.Type AS PostType,
+ Posts.Props AS PostProps,
+ Posts.Hashtags AS PostHashtags,
+ Posts.FileIds AS PostFileIds
+ FROM
+ Channels,
+ Users,
+ Posts
+ WHERE
+ Channels.TeamId = ''
+ AND Posts.ChannelId = Channels.Id
+ AND Posts.UserId = Users.Id
+ AND Posts.CreateAt > :StartTime
+ AND Posts.CreateAt <= :EndTime
+ ` + emailQuery + `
+ ` + keywordQuery + `)
+ ORDER BY PostCreateAt
LIMIT 30000`
var cposts []*model.CompliancePost
diff --git a/store/sql_compliance_store_test.go b/store/sql_compliance_store_test.go
index ea85a3330..4f4b01012 100644
--- a/store/sql_compliance_store_test.go
+++ b/store/sql_compliance_store_test.go
@@ -224,3 +224,93 @@ func TestComplianceExport(t *testing.T) {
}
}
}
+
+func TestComplianceExportDirectMessages(t *testing.T) {
+ Setup()
+
+ time.Sleep(100 * time.Millisecond)
+
+ t1 := &model.Team{}
+ t1.DisplayName = "DisplayName"
+ t1.Name = "zz" + model.NewId() + "b"
+ t1.Email = model.NewId() + "@nowhere.com"
+ t1.Type = model.TEAM_OPEN
+ t1 = Must(store.Team().Save(t1)).(*model.Team)
+
+ u1 := &model.User{}
+ u1.Email = model.NewId()
+ u1.Username = model.NewId()
+ u1 = Must(store.User().Save(u1)).(*model.User)
+ Must(store.Team().SaveMember(&model.TeamMember{TeamId: t1.Id, UserId: u1.Id}))
+
+ u2 := &model.User{}
+ u2.Email = model.NewId()
+ u2.Username = model.NewId()
+ u2 = Must(store.User().Save(u2)).(*model.User)
+ Must(store.Team().SaveMember(&model.TeamMember{TeamId: t1.Id, UserId: u2.Id}))
+
+ c1 := &model.Channel{}
+ c1.TeamId = t1.Id
+ c1.DisplayName = "Channel2"
+ c1.Name = "zz" + model.NewId() + "b"
+ c1.Type = model.CHANNEL_OPEN
+ c1 = Must(store.Channel().Save(c1)).(*model.Channel)
+
+ cDM := Must(store.Channel().CreateDirectChannel(u1.Id, u2.Id)).(*model.Channel)
+
+ o1 := &model.Post{}
+ o1.ChannelId = c1.Id
+ o1.UserId = u1.Id
+ o1.CreateAt = model.GetMillis()
+ o1.Message = "zz" + model.NewId() + "b"
+ o1 = Must(store.Post().Save(o1)).(*model.Post)
+
+ o1a := &model.Post{}
+ o1a.ChannelId = c1.Id
+ o1a.UserId = u1.Id
+ o1a.CreateAt = o1.CreateAt + 10
+ o1a.Message = "zz" + model.NewId() + "b"
+ o1a = Must(store.Post().Save(o1a)).(*model.Post)
+
+ o2 := &model.Post{}
+ o2.ChannelId = c1.Id
+ o2.UserId = u1.Id
+ o2.CreateAt = o1.CreateAt + 20
+ o2.Message = "zz" + model.NewId() + "b"
+ o2 = Must(store.Post().Save(o2)).(*model.Post)
+
+ o2a := &model.Post{}
+ o2a.ChannelId = c1.Id
+ o2a.UserId = u2.Id
+ o2a.CreateAt = o1.CreateAt + 30
+ o2a.Message = "zz" + model.NewId() + "b"
+ o2a = Must(store.Post().Save(o2a)).(*model.Post)
+
+ o3 := &model.Post{}
+ o3.ChannelId = cDM.Id
+ o3.UserId = u1.Id
+ o3.CreateAt = o1.CreateAt + 40
+ o3.Message = "zz" + model.NewId() + "b"
+ o3 = Must(store.Post().Save(o3)).(*model.Post)
+
+ time.Sleep(100 * time.Millisecond)
+
+ cr1 := &model.Compliance{Desc: "test" + model.NewId(), StartAt: o1.CreateAt - 1, EndAt: o3.CreateAt + 1, Emails: u1.Email}
+ if r1 := <-store.Compliance().ComplianceExport(cr1); r1.Err != nil {
+ t.Fatal(r1.Err)
+ } else {
+ cposts := r1.Data.([]*model.CompliancePost)
+
+ if len(cposts) != 4 {
+ t.Fatal("return wrong results length")
+ }
+
+ if cposts[0].PostId != o1.Id {
+ t.Fatal("Wrong sort")
+ }
+
+ if cposts[len(cposts)-1].PostId != o3.Id {
+ t.Fatal("Wrong sort")
+ }
+ }
+}