From f0fd9a9e8b85544089246bde71b6d61ba90eeb0e Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Wed, 26 Aug 2015 12:49:07 -0400 Subject: Adding ability to export data from mattermost --- store/sql_channel_store.go | 22 ++++++++++++++++++++++ store/sql_post_store.go | 24 ++++++++++++++++++++++++ store/sql_team_store.go | 20 ++++++++++++++++++++ store/sql_user_store.go | 27 +++++++++++++++++++++++++++ store/store.go | 4 ++++ 5 files changed, 97 insertions(+) (limited to 'store') diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go index d2e3943df..b58166fd6 100644 --- a/store/sql_channel_store.go +++ b/store/sql_channel_store.go @@ -678,3 +678,25 @@ func (s SqlChannelStore) UpdateNotifyLevel(channelId, userId, notifyLevel string return storeChannel } + +func (s SqlChannelStore) GetForExport(teamId string) StoreChannel { + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + var data []*model.Channel + _, err := s.GetReplica().Select(&data, "SELECT * FROM Channels WHERE TeamId = :TeamId AND DeleteAt = 0 AND Type = 'O'", map[string]interface{}{"TeamId": teamId}) + + if err != nil { + result.Err = model.NewAppError("SqlChannelStore.GetAllChannels", "We couldn't get all the channels", "teamId="+teamId+", err="+err.Error()) + } else { + result.Data = data + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} diff --git a/store/sql_post_store.go b/store/sql_post_store.go index 297d60397..20de23eb7 100644 --- a/store/sql_post_store.go +++ b/store/sql_post_store.go @@ -506,3 +506,27 @@ func (s SqlPostStore) Search(teamId string, userId string, terms string, isHasht return storeChannel } + +func (s SqlPostStore) GetForExport(channelId string) StoreChannel { + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + var posts []*model.Post + _, err := s.GetReplica().Select( + &posts, + "SELECT * FROM Posts WHERE ChannelId = :ChannelId AND DeleteAt = 0", + map[string]interface{}{"ChannelId": channelId}) + if err != nil { + result.Err = model.NewAppError("SqlPostStore.GetForExport", "We couldn't get the posts for the channel", "channelId="+channelId+err.Error()) + } else { + result.Data = posts + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} diff --git a/store/sql_team_store.go b/store/sql_team_store.go index 2784f8630..fcbcaab9f 100644 --- a/store/sql_team_store.go +++ b/store/sql_team_store.go @@ -193,3 +193,23 @@ func (s SqlTeamStore) GetTeamsForEmail(email string) StoreChannel { return storeChannel } + +func (s SqlTeamStore) GetForExport() StoreChannel { + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + var data []*model.Team + if _, err := s.GetReplica().Select(&data, "SELECT * FROM Teams"); err != nil { + result.Err = model.NewAppError("SqlTeamStore.GetForExport", "We could not get all teams", err.Error()) + } + + result.Data = data + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} diff --git a/store/sql_user_store.go b/store/sql_user_store.go index 64a18545a..be1d29df0 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -452,3 +452,30 @@ func (us SqlUserStore) VerifyEmail(userId string) StoreChannel { return storeChannel } + +func (us SqlUserStore) GetForExport(teamId string) StoreChannel { + + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + var users []*model.User + + if _, err := us.GetReplica().Select(&users, "SELECT * FROM Users WHERE TeamId = :TeamId", map[string]interface{}{"TeamId": teamId}); err != nil { + result.Err = model.NewAppError("SqlUserStore.GetProfiles", "We encounted an error while finding user profiles", err.Error()) + } else { + for _, u := range users { + u.Password = "" + u.AuthData = "" + } + + result.Data = users + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} diff --git a/store/store.go b/store/store.go index 271caa366..959e93fa4 100644 --- a/store/store.go +++ b/store/store.go @@ -44,6 +44,7 @@ type TeamStore interface { Get(id string) StoreChannel GetByName(name string) StoreChannel GetTeamsForEmail(domain string) StoreChannel + GetForExport() StoreChannel } type ChannelStore interface { @@ -55,6 +56,7 @@ type ChannelStore interface { GetChannels(teamId string, userId string) StoreChannel GetMoreChannels(teamId string, userId string) StoreChannel GetChannelCounts(teamId string, userId string) StoreChannel + GetForExport(teamId string) StoreChannel SaveMember(member *model.ChannelMember) StoreChannel GetMembers(channelId string) StoreChannel @@ -78,6 +80,7 @@ type PostStore interface { GetPostsSince(channelId string, time int64) StoreChannel GetEtag(channelId string) StoreChannel Search(teamId string, userId string, terms string, isHashtagSearch bool) StoreChannel + GetForExport(channelId string) StoreChannel } type UserStore interface { @@ -96,6 +99,7 @@ type UserStore interface { VerifyEmail(userId string) StoreChannel GetEtagForProfiles(teamId string) StoreChannel UpdateFailedPasswordAttempts(userId string, attempts int) StoreChannel + GetForExport(teamId string) StoreChannel } type SessionStore interface { -- cgit v1.2.3-1-g7c22