summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2016-02-03 10:45:58 -0800
committer=Corey Hulen <corey@hulen.com>2016-02-03 10:45:58 -0800
commitbdfa4715d65ed4b4e903a1eb4c83eba6c95455d1 (patch)
tree1626d089802a92ee208b6e7fa056378e40568a92 /store
parent581785f5044eecdc7cf664e4c7fc59efc6babc96 (diff)
parent9bba6c79882d1f5d14b98052caf59a11fc2388d5 (diff)
downloadchat-bdfa4715d65ed4b4e903a1eb4c83eba6c95455d1.tar.gz
chat-bdfa4715d65ed4b4e903a1eb4c83eba6c95455d1.tar.bz2
chat-bdfa4715d65ed4b4e903a1eb4c83eba6c95455d1.zip
Merge branch 'master' into PLT-1429
Diffstat (limited to 'store')
-rw-r--r--store/sql_audit_store.go13
-rw-r--r--store/sql_audit_store_test.go8
-rw-r--r--store/sql_post_store.go17
-rw-r--r--store/sql_post_store_test.go2
-rw-r--r--store/sql_webhook_store.go62
-rw-r--r--store/sql_webhook_store_test.go39
-rw-r--r--store/store.go4
7 files changed, 135 insertions, 10 deletions
diff --git a/store/sql_audit_store.go b/store/sql_audit_store.go
index 97df5f7e7..dbcb9a616 100644
--- a/store/sql_audit_store.go
+++ b/store/sql_audit_store.go
@@ -1,4 +1,4 @@
-// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
+// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package store
@@ -72,9 +72,16 @@ func (s SqlAuditStore) Get(user_id string, limit int) StoreChannel {
return
}
+ query := "SELECT * FROM Audits"
+
+ if len(user_id) != 0 {
+ query += " WHERE UserId = :user_id"
+ }
+
+ query += " ORDER BY CreateAt DESC LIMIT :limit"
+
var audits model.Audits
- if _, err := s.GetReplica().Select(&audits, "SELECT * FROM Audits WHERE UserId = :user_id ORDER BY CreateAt DESC LIMIT :limit",
- map[string]interface{}{"user_id": user_id, "limit": limit}); err != nil {
+ if _, err := s.GetReplica().Select(&audits, query, map[string]interface{}{"user_id": user_id, "limit": limit}); err != nil {
result.Err = model.NewLocAppError("SqlAuditStore.Get", "store.sql_audit.get.finding.app_error", nil, "user_id="+user_id)
} else {
result.Data = audits
diff --git a/store/sql_audit_store_test.go b/store/sql_audit_store_test.go
index b395631f1..841b79627 100644
--- a/store/sql_audit_store_test.go
+++ b/store/sql_audit_store_test.go
@@ -45,6 +45,14 @@ func TestSqlAuditStore(t *testing.T) {
t.Fatal("Should have returned empty because user_id is missing")
}
+ c = store.Audit().Get("", 100)
+ result = <-c
+ audits = result.Data.(model.Audits)
+
+ if len(audits) <= 4 {
+ t.Fatal("Failed to save and retrieve 4 audit logs")
+ }
+
if r2 := <-store.Audit().PermanentDeleteByUser(audit.UserId); r2.Err != nil {
t.Fatal(r2.Err)
}
diff --git a/store/sql_post_store.go b/store/sql_post_store.go
index aeaa5922c..dfb9563eb 100644
--- a/store/sql_post_store.go
+++ b/store/sql_post_store.go
@@ -629,7 +629,7 @@ func (s SqlPostStore) Search(teamId string, userId string, params *model.SearchP
if params.IsHashtag {
searchType = "Hashtags"
for _, term := range strings.Split(terms, " ") {
- termMap[term] = true
+ termMap[strings.ToUpper(term)] = true
}
}
@@ -748,7 +748,7 @@ func (s SqlPostStore) Search(teamId string, userId string, params *model.SearchP
if searchType == "Hashtags" {
exactMatch := false
for _, tag := range strings.Split(p.Hashtags, " ") {
- if termMap[tag] {
+ if termMap[strings.ToUpper(tag)] {
exactMatch = true
}
}
@@ -940,7 +940,7 @@ func (s SqlPostStore) AnalyticsPostCountsByDay(teamId string) StoreChannel {
return storeChannel
}
-func (s SqlPostStore) AnalyticsPostCount(teamId string) StoreChannel {
+func (s SqlPostStore) AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -959,8 +959,15 @@ func (s SqlPostStore) AnalyticsPostCount(teamId string) StoreChannel {
query += " AND Channels.TeamId = :TeamId"
}
- v, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId})
- if err != nil {
+ if mustHaveFile {
+ query += " AND Posts.Filenames != '[]'"
+ }
+
+ if mustHaveHashtag {
+ query += " AND Posts.Hashtags != ''"
+ }
+
+ if v, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId}); err != nil {
result.Err = model.NewLocAppError("SqlPostStore.AnalyticsPostCount", "store.sql_post.analytics_posts_count.app_error", nil, err.Error())
} else {
result.Data = v
diff --git a/store/sql_post_store_test.go b/store/sql_post_store_test.go
index 46b8d7678..d69f7906c 100644
--- a/store/sql_post_store_test.go
+++ b/store/sql_post_store_test.go
@@ -887,7 +887,7 @@ func TestPostCountsByDay(t *testing.T) {
}
}
- if r1 := <-store.Post().AnalyticsPostCount(t1.Id); r1.Err != nil {
+ if r1 := <-store.Post().AnalyticsPostCount(t1.Id, false, false); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(int64) != 4 {
diff --git a/store/sql_webhook_store.go b/store/sql_webhook_store.go
index 939574b9f..740c9a33f 100644
--- a/store/sql_webhook_store.go
+++ b/store/sql_webhook_store.go
@@ -329,3 +329,65 @@ func (s SqlWebhookStore) UpdateOutgoing(hook *model.OutgoingWebhook) StoreChanne
return storeChannel
}
+
+func (s SqlWebhookStore) AnalyticsIncomingCount(teamId string) StoreChannel {
+ storeChannel := make(StoreChannel)
+
+ go func() {
+ result := StoreResult{}
+
+ query :=
+ `SELECT
+ COUNT(*)
+ FROM
+ IncomingWebhooks
+ WHERE
+ DeleteAt = 0`
+
+ if len(teamId) > 0 {
+ query += " AND TeamId = :TeamId"
+ }
+
+ if v, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId}); err != nil {
+ result.Err = model.NewLocAppError("SqlWebhookStore.AnalyticsIncomingCount", "store.sql_webhooks.analytics_incoming_count.app_error", nil, "team_id="+teamId+", err="+err.Error())
+ } else {
+ result.Data = v
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
+func (s SqlWebhookStore) AnalyticsOutgoingCount(teamId string) StoreChannel {
+ storeChannel := make(StoreChannel)
+
+ go func() {
+ result := StoreResult{}
+
+ query :=
+ `SELECT
+ COUNT(*)
+ FROM
+ OutgoingWebhooks
+ WHERE
+ DeleteAt = 0`
+
+ if len(teamId) > 0 {
+ query += " AND TeamId = :TeamId"
+ }
+
+ if v, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId}); err != nil {
+ result.Err = model.NewLocAppError("SqlWebhookStore.AnalyticsOutgoingCount", "store.sql_webhooks.analytics_outgoing_count.app_error", nil, "team_id="+teamId+", err="+err.Error())
+ } else {
+ result.Data = v
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
diff --git a/store/sql_webhook_store_test.go b/store/sql_webhook_store_test.go
index 5b43d0730..251ecf597 100644
--- a/store/sql_webhook_store_test.go
+++ b/store/sql_webhook_store_test.go
@@ -304,3 +304,42 @@ func TestWebhookStoreUpdateOutgoing(t *testing.T) {
t.Fatal(r2.Err)
}
}
+
+func TestWebhookStoreCountIncoming(t *testing.T) {
+ Setup()
+
+ o1 := &model.IncomingWebhook{}
+ o1.ChannelId = model.NewId()
+ o1.UserId = model.NewId()
+ o1.TeamId = model.NewId()
+
+ o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook)
+
+ if r := <-store.Webhook().AnalyticsIncomingCount(""); r.Err != nil {
+ t.Fatal(r.Err)
+ } else {
+ if r.Data.(int64) == 0 {
+ t.Fatal("should have at least 1 incoming hook")
+ }
+ }
+}
+
+func TestWebhookStoreCountOutgoing(t *testing.T) {
+ Setup()
+
+ o1 := &model.OutgoingWebhook{}
+ o1.ChannelId = model.NewId()
+ o1.CreatorId = model.NewId()
+ o1.TeamId = model.NewId()
+ o1.CallbackURLs = []string{"http://nowhere.com/"}
+
+ o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook)
+
+ if r := <-store.Webhook().AnalyticsOutgoingCount(""); r.Err != nil {
+ t.Fatal(r.Err)
+ } else {
+ if r.Data.(int64) == 0 {
+ t.Fatal("should have at least 1 outgoing hook")
+ }
+ }
+}
diff --git a/store/store.go b/store/store.go
index a25d8b204..95df368ed 100644
--- a/store/store.go
+++ b/store/store.go
@@ -101,7 +101,7 @@ type PostStore interface {
GetForExport(channelId string) StoreChannel
AnalyticsUserCountsWithPostsByDay(teamId string) StoreChannel
AnalyticsPostCountsByDay(teamId string) StoreChannel
- AnalyticsPostCount(teamId string) StoreChannel
+ AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) StoreChannel
}
type UserStore interface {
@@ -182,6 +182,8 @@ type WebhookStore interface {
DeleteOutgoing(webhookId string, time int64) StoreChannel
PermanentDeleteOutgoingByUser(userId string) StoreChannel
UpdateOutgoing(hook *model.OutgoingWebhook) StoreChannel
+ AnalyticsIncomingCount(teamId string) StoreChannel
+ AnalyticsOutgoingCount(teamId string) StoreChannel
}
type CommandStore interface {