summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
Diffstat (limited to 'store')
-rw-r--r--store/sql_channel_store.go31
-rw-r--r--store/sql_channel_store_test.go43
-rw-r--r--store/sql_post_store.go21
-rw-r--r--store/sql_post_store_test.go23
-rw-r--r--store/sql_preference_store.go22
-rw-r--r--store/sql_preference_store_test.go45
-rw-r--r--store/sql_team_store.go4
-rw-r--r--store/sql_team_store_test.go2
-rw-r--r--store/sql_upgrade.go10
-rw-r--r--store/sql_user_store.go25
-rw-r--r--store/store.go4
11 files changed, 218 insertions, 12 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go
index 2ab9d87c1..e3df07f74 100644
--- a/store/sql_channel_store.go
+++ b/store/sql_channel_store.go
@@ -579,6 +579,31 @@ func (s SqlChannelStore) getByName(teamId string, name string, includeDeleted bo
return storeChannel
}
+func (s SqlChannelStore) GetDeletedByName(teamId string, name string) StoreChannel {
+ storeChannel := make(StoreChannel, 1)
+
+ go func() {
+ result := StoreResult{}
+
+ channel := model.Channel{}
+
+ if err := s.GetReplica().SelectOne(&channel, "SELECT * FROM Channels WHERE (TeamId = :TeamId OR TeamId = '') AND Name = :Name AND DeleteAt != 0", map[string]interface{}{"TeamId": teamId, "Name": name}); err != nil {
+ if err == sql.ErrNoRows {
+ result.Err = model.NewLocAppError("SqlChannelStore.GetDeletedByName", "store.sql_channel.get_deleted_by_name.missing.app_error", nil, "teamId="+teamId+", "+"name="+name+", "+err.Error())
+ } else {
+ result.Err = model.NewLocAppError("SqlChannelStore.GetDeletedByName", "store.sql_channel.get_deleted_by_name.existing.app_error", nil, "teamId="+teamId+", "+"name="+name+", "+err.Error())
+ }
+ } else {
+ result.Data = &channel
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
func (s SqlChannelStore) SaveMember(member *model.ChannelMember) StoreChannel {
storeChannel := make(StoreChannel, 1)
@@ -702,7 +727,7 @@ func (s SqlChannelStore) GetMember(channelId string, userId string) StoreChannel
result.Err = model.NewLocAppError("SqlChannelStore.GetMember", "store.sql_channel.get_member.app_error", nil, "channel_id="+channelId+"user_id="+userId+","+err.Error())
}
} else {
- result.Data = member
+ result.Data = &member
}
storeChannel <- result
@@ -1292,7 +1317,7 @@ func (s SqlChannelStore) performSearch(searchQuery string, term string, paramete
result := StoreResult{}
// these chars have special meaning and can be treated as spaces
- for _, c := range specialSearchChar {
+ for _, c := range specialUserSearchChar {
term = strings.Replace(term, c, " ", -1)
}
@@ -1361,7 +1386,7 @@ func (s SqlChannelStore) GetMembersByIds(channelId string, userIds []string) Sto
if _, err := s.GetReplica().Select(&members, "SELECT * FROM ChannelMembers WHERE ChannelId = :ChannelId AND UserId IN ("+idQuery+")", props); err != nil {
result.Err = model.NewLocAppError("SqlChannelStore.GetMembersByIds", "store.sql_channel.get_members_by_ids.app_error", nil, "channelId="+channelId+" "+err.Error())
} else {
- result.Data = members
+ result.Data = &members
}
storeChannel <- result
diff --git a/store/sql_channel_store_test.go b/store/sql_channel_store_test.go
index 6186a242c..5202a7c29 100644
--- a/store/sql_channel_store_test.go
+++ b/store/sql_channel_store_test.go
@@ -352,7 +352,8 @@ func TestChannelStoreGetByName(t *testing.T) {
o1.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(&o1))
- if r1 := <-store.Channel().GetByName(o1.TeamId, o1.Name); r1.Err != nil {
+ r1 := <-store.Channel().GetByName(o1.TeamId, o1.Name)
+ if r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.Channel).ToJson() != o1.ToJson() {
@@ -363,6 +364,36 @@ func TestChannelStoreGetByName(t *testing.T) {
if err := (<-store.Channel().GetByName(o1.TeamId, "")).Err; err == nil {
t.Fatal("Missing id should have failed")
}
+
+ Must(store.Channel().Delete(r1.Data.(*model.Channel).Id, model.GetMillis()))
+
+ if err := (<-store.Channel().GetByName(o1.TeamId, "")).Err; err == nil {
+ t.Fatal("Deleted channel should not be returned by GetByName()")
+ }
+}
+
+func TestChannelStoreGetDeletedByName(t *testing.T) {
+ Setup()
+
+ o1 := model.Channel{}
+ o1.TeamId = model.NewId()
+ o1.DisplayName = "Name"
+ o1.Name = "a" + model.NewId() + "b"
+ o1.Type = model.CHANNEL_OPEN
+ o1.DeleteAt = model.GetMillis()
+ Must(store.Channel().Save(&o1))
+
+ if r1 := <-store.Channel().GetDeletedByName(o1.TeamId, o1.Name); r1.Err != nil {
+ t.Fatal(r1.Err)
+ } else {
+ if r1.Data.(*model.Channel).ToJson() != o1.ToJson() {
+ t.Fatal("invalid returned channel")
+ }
+ }
+
+ if err := (<-store.Channel().GetDeletedByName(o1.TeamId, "")).Err; err == nil {
+ t.Fatal("Missing id should have failed")
+ }
}
func TestChannelMemberStore(t *testing.T) {
@@ -446,7 +477,7 @@ func TestChannelMemberStore(t *testing.T) {
t.Fatal("Member update time incorrect on delete")
}
- member := (<-store.Channel().GetMember(o1.ChannelId, o1.UserId)).Data.(model.ChannelMember)
+ member := (<-store.Channel().GetMember(o1.ChannelId, o1.UserId)).Data.(*model.ChannelMember)
if member.ChannelId != o1.ChannelId {
t.Fatal("should have go member")
}
@@ -918,7 +949,7 @@ func TestGetMember(t *testing.T) {
if result := <-store.Channel().GetMember(c1.Id, userId); result.Err != nil {
t.Fatal("shouldn't have errored when getting member", result.Err)
- } else if member := result.Data.(model.ChannelMember); member.ChannelId != c1.Id {
+ } else if member := result.Data.(*model.ChannelMember); member.ChannelId != c1.Id {
t.Fatal("should've gotten member of channel 1")
} else if member.UserId != userId {
t.Fatal("should've gotten member for user")
@@ -926,7 +957,7 @@ func TestGetMember(t *testing.T) {
if result := <-store.Channel().GetMember(c2.Id, userId); result.Err != nil {
t.Fatal("shouldn't have errored when getting member", result.Err)
- } else if member := result.Data.(model.ChannelMember); member.ChannelId != c2.Id {
+ } else if member := result.Data.(*model.ChannelMember); member.ChannelId != c2.Id {
t.Fatal("should've gotten member of channel 2")
} else if member.UserId != userId {
t.Fatal("should've gotten member for user")
@@ -1313,7 +1344,7 @@ func TestChannelStoreGetMembersByIds(t *testing.T) {
if r := <-store.Channel().GetMembersByIds(m1.ChannelId, []string{m1.UserId}); r.Err != nil {
t.Fatal(r.Err)
} else {
- rm1 := r.Data.(model.ChannelMembers)[0]
+ rm1 := (*r.Data.(*model.ChannelMembers))[0]
if rm1.ChannelId != m1.ChannelId {
t.Fatal("bad team id")
@@ -1330,7 +1361,7 @@ func TestChannelStoreGetMembersByIds(t *testing.T) {
if r := <-store.Channel().GetMembersByIds(m1.ChannelId, []string{m1.UserId, m2.UserId, model.NewId()}); r.Err != nil {
t.Fatal(r.Err)
} else {
- rm := r.Data.(model.ChannelMembers)
+ rm := (*r.Data.(*model.ChannelMembers))
if len(rm) != 2 {
t.Fatal("return wrong number of results")
diff --git a/store/sql_post_store.go b/store/sql_post_store.go
index c1aaee3e6..ed87b01f7 100644
--- a/store/sql_post_store.go
+++ b/store/sql_post_store.go
@@ -222,6 +222,27 @@ func (s SqlPostStore) Get(id string) StoreChannel {
return storeChannel
}
+func (s SqlPostStore) GetSingle(id string) StoreChannel {
+ storeChannel := make(StoreChannel, 1)
+
+ go func() {
+ result := StoreResult{}
+
+ var post model.Post
+ err := s.GetReplica().SelectOne(&post, "SELECT * FROM Posts WHERE Id = :Id AND DeleteAt = 0", map[string]interface{}{"Id": id})
+ if err != nil {
+ result.Err = model.NewLocAppError("SqlPostStore.GetSingle", "store.sql_post.get.app_error", nil, "id="+id+err.Error())
+ }
+
+ result.Data = &post
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
type etagPosts struct {
Id string
UpdateAt int64
diff --git a/store/sql_post_store_test.go b/store/sql_post_store_test.go
index eb22979db..e3886c6bc 100644
--- a/store/sql_post_store_test.go
+++ b/store/sql_post_store_test.go
@@ -63,6 +63,29 @@ func TestPostStoreGet(t *testing.T) {
}
}
+func TestPostStoreGetSingle(t *testing.T) {
+ Setup()
+
+ o1 := &model.Post{}
+ o1.ChannelId = model.NewId()
+ o1.UserId = model.NewId()
+ o1.Message = "a" + model.NewId() + "b"
+
+ o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
+
+ if r1 := <-store.Post().GetSingle(o1.Id); r1.Err != nil {
+ t.Fatal(r1.Err)
+ } else {
+ if r1.Data.(*model.Post).CreateAt != o1.CreateAt {
+ t.Fatal("invalid returned post")
+ }
+ }
+
+ if err := (<-store.Post().GetSingle("123")).Err; err == nil {
+ t.Fatal("Missing id should have failed")
+ }
+}
+
func TestGetEtagCache(t *testing.T) {
Setup()
o1 := &model.Post{}
diff --git a/store/sql_preference_store.go b/store/sql_preference_store.go
index 5c46d1328..14a9ff48b 100644
--- a/store/sql_preference_store.go
+++ b/store/sql_preference_store.go
@@ -348,3 +348,25 @@ func (s SqlPreferenceStore) DeleteCategory(userId string, category string) Store
return storeChannel
}
+
+func (s SqlPreferenceStore) DeleteCategoryAndName(category string, name string) StoreChannel {
+ storeChannel := make(StoreChannel, 1)
+
+ go func() {
+ result := StoreResult{}
+
+ if _, err := s.GetMaster().Exec(
+ `DELETE FROM
+ Preferences
+ WHERE
+ Name = :Name
+ AND Category = :Category`, map[string]interface{}{"Name": name, "Category": category}); err != nil {
+ result.Err = model.NewLocAppError("SqlPreferenceStore.DeleteCategoryAndName", "store.sql_preference.delete.app_error", nil, err.Error())
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
diff --git a/store/sql_preference_store_test.go b/store/sql_preference_store_test.go
index fc1cf5f5b..adcaa8d89 100644
--- a/store/sql_preference_store_test.go
+++ b/store/sql_preference_store_test.go
@@ -427,3 +427,48 @@ func TestPreferenceDeleteCategory(t *testing.T) {
t.Fatal("should've returned no preferences")
}
}
+
+func TestPreferenceDeleteCategoryAndName(t *testing.T) {
+ Setup()
+
+ category := model.NewId()
+ name := model.NewId()
+ userId := model.NewId()
+ userId2 := model.NewId()
+
+ preference1 := model.Preference{
+ UserId: userId,
+ Category: category,
+ Name: name,
+ Value: "value1a",
+ }
+
+ preference2 := model.Preference{
+ UserId: userId2,
+ Category: category,
+ Name: name,
+ Value: "value1a",
+ }
+
+ Must(store.Preference().Save(&model.Preferences{preference1, preference2}))
+
+ if prefs := Must(store.Preference().GetAll(userId)).(model.Preferences); len([]model.Preference(prefs)) != 1 {
+ t.Fatal("should've returned 1 preference")
+ }
+
+ if prefs := Must(store.Preference().GetAll(userId2)).(model.Preferences); len([]model.Preference(prefs)) != 1 {
+ t.Fatal("should've returned 1 preference")
+ }
+
+ if result := <-store.Preference().DeleteCategoryAndName(category, name); result.Err != nil {
+ t.Fatal(result.Err)
+ }
+
+ if prefs := Must(store.Preference().GetAll(userId)).(model.Preferences); len([]model.Preference(prefs)) != 0 {
+ t.Fatal("should've returned no preferences")
+ }
+
+ if prefs := Must(store.Preference().GetAll(userId2)).(model.Preferences); len([]model.Preference(prefs)) != 0 {
+ t.Fatal("should've returned no preferences")
+ }
+}
diff --git a/store/sql_team_store.go b/store/sql_team_store.go
index 85a2d995e..6c1cdcad7 100644
--- a/store/sql_team_store.go
+++ b/store/sql_team_store.go
@@ -301,7 +301,7 @@ func (s SqlTeamStore) GetAllTeamListing() StoreChannel {
var data []*model.Team
if _, err := s.GetReplica().Select(&data, query); err != nil {
- result.Err = model.NewLocAppError("SqlTeamStore.GetAllTeams", "store.sql_team.get_all_team_listing.app_error", nil, err.Error())
+ result.Err = model.NewLocAppError("SqlTeamStore.GetAllTeamListing", "store.sql_team.get_all_team_listing.app_error", nil, err.Error())
}
for _, team := range data {
@@ -438,7 +438,7 @@ func (s SqlTeamStore) GetMember(teamId string, userId string) StoreChannel {
result.Err = model.NewLocAppError("SqlTeamStore.GetMember", "store.sql_team.get_member.app_error", nil, "teamId="+teamId+" userId="+userId+" "+err.Error())
}
} else {
- result.Data = member
+ result.Data = &member
}
storeChannel <- result
diff --git a/store/sql_team_store_test.go b/store/sql_team_store_test.go
index 8a302a9e2..0ea499d7e 100644
--- a/store/sql_team_store_test.go
+++ b/store/sql_team_store_test.go
@@ -415,7 +415,7 @@ func TestGetTeamMember(t *testing.T) {
if r := <-store.Team().GetMember(m1.TeamId, m1.UserId); r.Err != nil {
t.Fatal(r.Err)
} else {
- rm1 := r.Data.(model.TeamMember)
+ rm1 := r.Data.(*model.TeamMember)
if rm1.TeamId != m1.TeamId {
t.Fatal("bad team id")
diff --git a/store/sql_upgrade.go b/store/sql_upgrade.go
index d69404baa..9ee8f08e2 100644
--- a/store/sql_upgrade.go
+++ b/store/sql_upgrade.go
@@ -15,6 +15,7 @@ import (
)
const (
+ VERIONS_3_7_0 = "3.7.0"
VERSION_3_6_0 = "3.6.0"
VERSION_3_5_0 = "3.5.0"
VERSION_3_4_0 = "3.4.0"
@@ -39,6 +40,7 @@ func UpgradeDatabase(sqlStore *SqlStore) {
UpgradeDatabaseToVersion34(sqlStore)
UpgradeDatabaseToVersion35(sqlStore)
UpgradeDatabaseToVersion36(sqlStore)
+ UpgradeDatabaseToVersion37(sqlStore)
// If the SchemaVersion is empty this this is the first time it has ran
// so lets set it to the current version.
@@ -229,3 +231,11 @@ func UpgradeDatabaseToVersion36(sqlStore *SqlStore) {
saveSchemaVersion(sqlStore, VERSION_3_6_0)
}
}
+
+func UpgradeDatabaseToVersion37(sqlStore *SqlStore) {
+ // TODO: Uncomment following condition when version 3.7.0 is released
+ // if shouldPerformUpgrade(sqlStore, VERSION_3_6_0, VERSION_3_7_0) {
+ // Add EditAt column to Posts
+ sqlStore.CreateColumnIfNotExists("Posts", "EditAt", " bigint", " bigint", "0")
+ // }
+}
diff --git a/store/sql_user_store.go b/store/sql_user_store.go
index 533757479..09742a4f4 100644
--- a/store/sql_user_store.go
+++ b/store/sql_user_store.go
@@ -1129,6 +1129,31 @@ func (us SqlUserStore) AnalyticsUniqueUserCount(teamId string) StoreChannel {
return storeChannel
}
+func (us SqlUserStore) AnalyticsActiveCount(timePeriod int64) StoreChannel {
+
+ storeChannel := make(StoreChannel, 1)
+
+ go func() {
+ result := StoreResult{}
+
+ time := model.GetMillis() - timePeriod
+
+ query := "SELECT COUNT(*) FROM Status WHERE LastActivityAt > :Time"
+
+ v, err := us.GetReplica().SelectInt(query, map[string]interface{}{"Time": time})
+ if err != nil {
+ result.Err = model.NewLocAppError("SqlUserStore.AnalyticsDailyActiveUsers", "store.sql_user.analytics_daily_active_users.app_error", nil, err.Error())
+ } else {
+ result.Data = v
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
func (us SqlUserStore) GetUnreadCount(userId string) StoreChannel {
storeChannel := make(StoreChannel, 1)
diff --git a/store/store.go b/store/store.go
index 88a553b7c..cd918c033 100644
--- a/store/store.go
+++ b/store/store.go
@@ -93,6 +93,7 @@ type ChannelStore interface {
PermanentDeleteByTeam(teamId string) StoreChannel
GetByName(team_id string, name string) StoreChannel
GetByNameIncludeDeleted(team_id string, name string) StoreChannel
+ GetDeletedByName(team_id string, name string) StoreChannel
GetChannels(teamId string, userId string) StoreChannel
GetMoreChannels(teamId string, userId string, offset int, limit int) StoreChannel
GetChannelCounts(teamId string, userId string) StoreChannel
@@ -127,6 +128,7 @@ type PostStore interface {
Save(post *model.Post) StoreChannel
Update(newPost *model.Post, oldPost *model.Post) StoreChannel
Get(id string) StoreChannel
+ GetSingle(id string) StoreChannel
Delete(postId string, time int64) StoreChannel
PermanentDeleteByUser(userId string) StoreChannel
GetPosts(channelId string, offset int, limit int, allowFromCache bool) StoreChannel
@@ -175,6 +177,7 @@ type UserStore interface {
GetSystemAdminProfiles() StoreChannel
PermanentDelete(userId string) StoreChannel
AnalyticsUniqueUserCount(teamId string) StoreChannel
+ AnalyticsActiveCount(time int64) StoreChannel
GetUnreadCount(userId string) StoreChannel
GetUnreadCountForChannel(userId string, channelId string) StoreChannel
GetRecentlyActiveUsersForTeam(teamId string) StoreChannel
@@ -275,6 +278,7 @@ type PreferenceStore interface {
GetAll(userId string) StoreChannel
Delete(userId, category, name string) StoreChannel
DeleteCategory(userId string, category string) StoreChannel
+ DeleteCategoryAndName(category string, name string) StoreChannel
PermanentDeleteByUser(userId string) StoreChannel
IsFeatureEnabled(feature, userId string) StoreChannel
}