2016-02-04 13:00:03 -05:00
|
|
|
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
2015-06-14 23:53:32 -08:00
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
|
|
|
|
package store
|
|
|
|
|
|
|
|
|
|
import (
|
2016-09-06 18:51:27 -04:00
|
|
|
"time"
|
|
|
|
|
|
2016-01-11 09:12:51 -06:00
|
|
|
l4g "github.com/alecthomas/log4go"
|
2015-06-14 23:53:32 -08:00
|
|
|
"github.com/mattermost/platform/model"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type StoreResult struct {
|
|
|
|
|
Data interface{}
|
|
|
|
|
Err *model.AppError
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type StoreChannel chan StoreResult
|
|
|
|
|
|
2015-07-06 00:50:42 -08:00
|
|
|
func Must(sc StoreChannel) interface{} {
|
|
|
|
|
r := <-sc
|
|
|
|
|
if r.Err != nil {
|
2015-08-20 14:20:39 -07:00
|
|
|
l4g.Close()
|
|
|
|
|
time.Sleep(time.Second)
|
2015-07-06 00:50:42 -08:00
|
|
|
panic(r.Err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return r.Data
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-14 23:53:32 -08:00
|
|
|
type Store interface {
|
|
|
|
|
Team() TeamStore
|
|
|
|
|
Channel() ChannelStore
|
|
|
|
|
Post() PostStore
|
|
|
|
|
User() UserStore
|
|
|
|
|
Audit() AuditStore
|
2016-03-14 16:07:58 -07:00
|
|
|
Compliance() ComplianceStore
|
2015-06-14 23:53:32 -08:00
|
|
|
Session() SessionStore
|
2015-09-16 15:49:12 -04:00
|
|
|
OAuth() OAuthStore
|
2015-09-16 19:59:57 -07:00
|
|
|
System() SystemStore
|
2015-09-21 14:22:23 -04:00
|
|
|
Webhook() WebhookStore
|
2016-01-06 21:09:05 -06:00
|
|
|
Command() CommandStore
|
2015-10-01 10:56:07 -04:00
|
|
|
Preference() PreferenceStore
|
2016-02-04 13:00:03 -05:00
|
|
|
License() LicenseStore
|
2016-04-21 22:37:01 -07:00
|
|
|
PasswordRecovery() PasswordRecoveryStore
|
2016-06-14 09:38:19 -04:00
|
|
|
Emoji() EmojiStore
|
2016-07-18 11:10:03 -04:00
|
|
|
Status() StatusStore
|
2015-10-15 11:16:26 -07:00
|
|
|
MarkSystemRanUnitTests()
|
2015-06-14 23:53:32 -08:00
|
|
|
Close()
|
2016-04-21 22:37:01 -07:00
|
|
|
DropAllTables()
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type TeamStore interface {
|
2016-01-20 13:36:16 -06:00
|
|
|
Save(team *model.Team) StoreChannel
|
|
|
|
|
Update(team *model.Team) StoreChannel
|
|
|
|
|
UpdateDisplayName(name string, teamId string) StoreChannel
|
|
|
|
|
Get(id string) StoreChannel
|
|
|
|
|
GetByName(name string) StoreChannel
|
|
|
|
|
GetAll() StoreChannel
|
|
|
|
|
GetAllTeamListing() StoreChannel
|
2016-04-21 22:37:01 -07:00
|
|
|
GetTeamsByUserId(userId string) StoreChannel
|
2016-01-20 13:36:16 -06:00
|
|
|
GetByInviteId(inviteId string) StoreChannel
|
|
|
|
|
PermanentDelete(teamId string) StoreChannel
|
2016-02-25 12:32:46 -05:00
|
|
|
AnalyticsTeamCount() StoreChannel
|
2016-04-21 22:37:01 -07:00
|
|
|
SaveMember(member *model.TeamMember) StoreChannel
|
|
|
|
|
UpdateMember(member *model.TeamMember) StoreChannel
|
2016-05-16 12:55:22 -04:00
|
|
|
GetMember(teamId string, userId string) StoreChannel
|
2016-04-21 22:37:01 -07:00
|
|
|
GetMembers(teamId string) StoreChannel
|
|
|
|
|
GetTeamsForUser(userId string) StoreChannel
|
|
|
|
|
RemoveMember(teamId string, userId string) StoreChannel
|
|
|
|
|
RemoveAllMembersByTeam(teamId string) StoreChannel
|
|
|
|
|
RemoveAllMembersByUser(userId string) StoreChannel
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ChannelStore interface {
|
2016-01-20 13:36:16 -06:00
|
|
|
Save(channel *model.Channel) StoreChannel
|
|
|
|
|
SaveDirectChannel(channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) StoreChannel
|
|
|
|
|
Update(channel *model.Channel) StoreChannel
|
|
|
|
|
Get(id string) StoreChannel
|
|
|
|
|
GetFromMaster(id string) StoreChannel
|
|
|
|
|
Delete(channelId string, time int64) StoreChannel
|
2016-07-06 10:11:21 -08:00
|
|
|
SetDeleteAt(channelId string, deleteAt int64, updateAt int64) StoreChannel
|
2016-01-20 13:36:16 -06:00
|
|
|
PermanentDeleteByTeam(teamId string) StoreChannel
|
|
|
|
|
GetByName(team_id string, domain string) StoreChannel
|
|
|
|
|
GetChannels(teamId string, userId string) StoreChannel
|
|
|
|
|
GetMoreChannels(teamId string, userId string) StoreChannel
|
|
|
|
|
GetChannelCounts(teamId string, userId string) StoreChannel
|
2016-07-06 10:11:21 -08:00
|
|
|
GetAll(teamId string) StoreChannel
|
2016-01-20 13:36:16 -06:00
|
|
|
|
|
|
|
|
SaveMember(member *model.ChannelMember) StoreChannel
|
|
|
|
|
UpdateMember(member *model.ChannelMember) StoreChannel
|
|
|
|
|
GetMembers(channelId string) StoreChannel
|
|
|
|
|
GetMember(channelId string, userId string) StoreChannel
|
|
|
|
|
GetMemberCount(channelId string) StoreChannel
|
|
|
|
|
RemoveMember(channelId string, userId string) StoreChannel
|
|
|
|
|
PermanentDeleteMembersByUser(userId string) StoreChannel
|
|
|
|
|
GetExtraMembers(channelId string, limit int) StoreChannel
|
|
|
|
|
UpdateLastViewedAt(channelId string, userId string) StoreChannel
|
2016-07-14 15:19:27 +03:00
|
|
|
SetLastViewedAt(channelId string, userId string, newLastViewedAt int64) StoreChannel
|
2016-01-20 13:36:16 -06:00
|
|
|
IncrementMentionCount(channelId string, userId string) StoreChannel
|
|
|
|
|
AnalyticsTypeCount(teamId string, channelType string) StoreChannel
|
2016-02-25 04:24:03 -03:00
|
|
|
ExtraUpdateByUser(userId string, time int64) StoreChannel
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PostStore interface {
|
2016-01-20 13:36:16 -06:00
|
|
|
Save(post *model.Post) StoreChannel
|
|
|
|
|
Update(post *model.Post, newMessage string, newHashtags string) StoreChannel
|
|
|
|
|
Get(id string) StoreChannel
|
|
|
|
|
Delete(postId string, time int64) StoreChannel
|
|
|
|
|
PermanentDeleteByUser(userId string) StoreChannel
|
|
|
|
|
GetPosts(channelId string, offset int, limit int) StoreChannel
|
2016-08-04 11:38:09 -04:00
|
|
|
GetFlaggedPosts(userId string, offset int, limit int) StoreChannel
|
2016-01-20 13:36:16 -06:00
|
|
|
GetPostsBefore(channelId string, postId string, numPosts int, offset int) StoreChannel
|
|
|
|
|
GetPostsAfter(channelId string, postId string, numPosts int, offset int) StoreChannel
|
|
|
|
|
GetPostsSince(channelId string, time int64) StoreChannel
|
|
|
|
|
GetEtag(channelId string) StoreChannel
|
|
|
|
|
Search(teamId string, userId string, params *model.SearchParams) StoreChannel
|
|
|
|
|
AnalyticsUserCountsWithPostsByDay(teamId string) StoreChannel
|
|
|
|
|
AnalyticsPostCountsByDay(teamId string) StoreChannel
|
2016-02-02 08:41:02 -05:00
|
|
|
AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) StoreChannel
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type UserStore interface {
|
2016-01-20 13:36:16 -06:00
|
|
|
Save(user *model.User) StoreChannel
|
|
|
|
|
Update(user *model.User, allowRoleUpdate bool) StoreChannel
|
|
|
|
|
UpdateLastPictureUpdate(userId string) StoreChannel
|
2016-05-12 18:36:30 -07:00
|
|
|
UpdateUpdateAt(userId string) StoreChannel
|
2016-01-20 13:36:16 -06:00
|
|
|
UpdatePassword(userId, newPassword string) StoreChannel
|
2016-05-11 11:04:30 -07:00
|
|
|
UpdateAuthData(userId string, service string, authData *string, email string) StoreChannel
|
2016-03-30 12:49:29 -04:00
|
|
|
UpdateMfaSecret(userId, secret string) StoreChannel
|
|
|
|
|
UpdateMfaActive(userId string, active bool) StoreChannel
|
2016-01-20 13:36:16 -06:00
|
|
|
Get(id string) StoreChannel
|
2016-04-21 22:37:01 -07:00
|
|
|
GetAll() StoreChannel
|
2016-05-04 06:31:42 -07:00
|
|
|
GetAllProfiles() StoreChannel
|
2016-01-20 13:36:16 -06:00
|
|
|
GetProfiles(teamId string) StoreChannel
|
2016-04-21 22:37:01 -07:00
|
|
|
GetDirectProfiles(userId string) StoreChannel
|
|
|
|
|
GetProfileByIds(userId []string) StoreChannel
|
|
|
|
|
GetByEmail(email string) StoreChannel
|
2016-05-11 11:04:30 -07:00
|
|
|
GetByAuth(authData *string, authService string) StoreChannel
|
2016-06-03 09:33:59 -04:00
|
|
|
GetAllUsingAuthService(authService string) StoreChannel
|
2016-04-21 22:37:01 -07:00
|
|
|
GetByUsername(username string) StoreChannel
|
2016-05-03 14:10:36 -04:00
|
|
|
GetForLogin(loginId string, allowSignInWithUsername, allowSignInWithEmail, ldapEnabled bool) StoreChannel
|
2016-01-20 13:36:16 -06:00
|
|
|
VerifyEmail(userId string) StoreChannel
|
2016-05-04 06:31:42 -07:00
|
|
|
GetEtagForAllProfiles() StoreChannel
|
2016-01-20 13:36:16 -06:00
|
|
|
GetEtagForProfiles(teamId string) StoreChannel
|
2016-04-21 22:37:01 -07:00
|
|
|
GetEtagForDirectProfiles(userId string) StoreChannel
|
2016-01-20 13:36:16 -06:00
|
|
|
UpdateFailedPasswordAttempts(userId string, attempts int) StoreChannel
|
|
|
|
|
GetTotalUsersCount() StoreChannel
|
|
|
|
|
GetSystemAdminProfiles() StoreChannel
|
|
|
|
|
PermanentDelete(userId string) StoreChannel
|
2016-01-21 12:14:17 -05:00
|
|
|
AnalyticsUniqueUserCount(teamId string) StoreChannel
|
2016-03-11 00:14:55 -03:00
|
|
|
GetUnreadCount(userId string) StoreChannel
|
2016-08-31 12:52:14 -04:00
|
|
|
GetUnreadCountForChannel(userId string, channelId string) StoreChannel
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type SessionStore interface {
|
2016-01-20 13:36:16 -06:00
|
|
|
Save(session *model.Session) StoreChannel
|
|
|
|
|
Get(sessionIdOrToken string) StoreChannel
|
|
|
|
|
GetSessions(userId string) StoreChannel
|
|
|
|
|
Remove(sessionIdOrToken string) StoreChannel
|
2016-04-21 22:37:01 -07:00
|
|
|
RemoveAllSessions() StoreChannel
|
2016-01-20 13:36:16 -06:00
|
|
|
PermanentDeleteSessionsByUser(teamId string) StoreChannel
|
|
|
|
|
UpdateLastActivityAt(sessionId string, time int64) StoreChannel
|
|
|
|
|
UpdateRoles(userId string, roles string) StoreChannel
|
2016-07-21 08:36:11 -08:00
|
|
|
UpdateDeviceId(id string, deviceId string, expiresAt int64) StoreChannel
|
2016-04-21 22:37:01 -07:00
|
|
|
AnalyticsSessionCount() StoreChannel
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type AuditStore interface {
|
2016-01-20 13:36:16 -06:00
|
|
|
Save(audit *model.Audit) StoreChannel
|
|
|
|
|
Get(user_id string, limit int) StoreChannel
|
|
|
|
|
PermanentDeleteByUser(userId string) StoreChannel
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
2015-09-16 15:49:12 -04:00
|
|
|
|
2016-03-14 16:07:58 -07:00
|
|
|
type ComplianceStore interface {
|
|
|
|
|
Save(compliance *model.Compliance) StoreChannel
|
|
|
|
|
Update(compliance *model.Compliance) StoreChannel
|
|
|
|
|
Get(id string) StoreChannel
|
|
|
|
|
GetAll() StoreChannel
|
|
|
|
|
ComplianceExport(compliance *model.Compliance) StoreChannel
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-16 15:49:12 -04:00
|
|
|
type OAuthStore interface {
|
2016-01-20 13:36:16 -06:00
|
|
|
SaveApp(app *model.OAuthApp) StoreChannel
|
|
|
|
|
UpdateApp(app *model.OAuthApp) StoreChannel
|
|
|
|
|
GetApp(id string) StoreChannel
|
|
|
|
|
GetAppByUser(userId string) StoreChannel
|
2016-08-03 12:19:27 -05:00
|
|
|
GetApps() StoreChannel
|
2016-08-23 19:06:17 -03:00
|
|
|
GetAuthorizedApps(userId string) StoreChannel
|
2016-08-03 12:19:27 -05:00
|
|
|
DeleteApp(id string) StoreChannel
|
2016-01-20 13:36:16 -06:00
|
|
|
SaveAuthData(authData *model.AuthData) StoreChannel
|
|
|
|
|
GetAuthData(code string) StoreChannel
|
|
|
|
|
RemoveAuthData(code string) StoreChannel
|
|
|
|
|
PermanentDeleteAuthDataByUser(userId string) StoreChannel
|
|
|
|
|
SaveAccessData(accessData *model.AccessData) StoreChannel
|
2016-08-03 12:19:27 -05:00
|
|
|
UpdateAccessData(accessData *model.AccessData) StoreChannel
|
2016-01-20 13:36:16 -06:00
|
|
|
GetAccessData(token string) StoreChannel
|
2016-08-23 19:06:17 -03:00
|
|
|
GetAccessDataByUserForApp(userId, clientId string) StoreChannel
|
2016-08-03 12:19:27 -05:00
|
|
|
GetAccessDataByRefreshToken(token string) StoreChannel
|
|
|
|
|
GetPreviousAccessData(userId, clientId string) StoreChannel
|
2016-01-20 13:36:16 -06:00
|
|
|
RemoveAccessData(token string) StoreChannel
|
2015-09-16 15:49:12 -04:00
|
|
|
}
|
2015-09-16 19:59:57 -07:00
|
|
|
|
|
|
|
|
type SystemStore interface {
|
2016-01-20 13:36:16 -06:00
|
|
|
Save(system *model.System) StoreChannel
|
2016-02-04 13:00:03 -05:00
|
|
|
SaveOrUpdate(system *model.System) StoreChannel
|
2016-01-20 13:36:16 -06:00
|
|
|
Update(system *model.System) StoreChannel
|
|
|
|
|
Get() StoreChannel
|
2016-04-11 13:45:03 -04:00
|
|
|
GetByName(name string) StoreChannel
|
2015-09-16 19:59:57 -07:00
|
|
|
}
|
2015-09-21 14:22:23 -04:00
|
|
|
|
|
|
|
|
type WebhookStore interface {
|
2016-01-20 13:36:16 -06:00
|
|
|
SaveIncoming(webhook *model.IncomingWebhook) StoreChannel
|
|
|
|
|
GetIncoming(id string) StoreChannel
|
2016-01-11 10:04:01 -06:00
|
|
|
GetIncomingByTeam(teamId string) StoreChannel
|
2016-01-20 13:36:16 -06:00
|
|
|
GetIncomingByChannel(channelId string) StoreChannel
|
|
|
|
|
DeleteIncoming(webhookId string, time int64) StoreChannel
|
|
|
|
|
PermanentDeleteIncomingByUser(userId string) StoreChannel
|
|
|
|
|
SaveOutgoing(webhook *model.OutgoingWebhook) StoreChannel
|
|
|
|
|
GetOutgoing(id string) StoreChannel
|
|
|
|
|
GetOutgoingByChannel(channelId string) StoreChannel
|
|
|
|
|
GetOutgoingByTeam(teamId string) StoreChannel
|
|
|
|
|
DeleteOutgoing(webhookId string, time int64) StoreChannel
|
|
|
|
|
PermanentDeleteOutgoingByUser(userId string) StoreChannel
|
|
|
|
|
UpdateOutgoing(hook *model.OutgoingWebhook) StoreChannel
|
2016-02-02 08:41:02 -05:00
|
|
|
AnalyticsIncomingCount(teamId string) StoreChannel
|
|
|
|
|
AnalyticsOutgoingCount(teamId string) StoreChannel
|
2015-09-21 14:22:23 -04:00
|
|
|
}
|
2015-10-01 10:56:07 -04:00
|
|
|
|
2016-01-06 21:09:05 -06:00
|
|
|
type CommandStore interface {
|
|
|
|
|
Save(webhook *model.Command) StoreChannel
|
|
|
|
|
Get(id string) StoreChannel
|
|
|
|
|
GetByTeam(teamId string) StoreChannel
|
|
|
|
|
Delete(commandId string, time int64) StoreChannel
|
|
|
|
|
PermanentDeleteByUser(userId string) StoreChannel
|
|
|
|
|
Update(hook *model.Command) StoreChannel
|
2016-02-25 12:32:46 -05:00
|
|
|
AnalyticsCommandCount(teamId string) StoreChannel
|
2016-01-06 21:09:05 -06:00
|
|
|
}
|
|
|
|
|
|
2015-10-01 10:56:07 -04:00
|
|
|
type PreferenceStore interface {
|
2016-01-20 13:36:16 -06:00
|
|
|
Save(preferences *model.Preferences) StoreChannel
|
|
|
|
|
Get(userId string, category string, name string) StoreChannel
|
|
|
|
|
GetCategory(userId string, category string) StoreChannel
|
|
|
|
|
GetAll(userId string) StoreChannel
|
2016-07-14 10:08:36 -04:00
|
|
|
Delete(userId, category, name string) StoreChannel
|
2016-01-20 13:36:16 -06:00
|
|
|
PermanentDeleteByUser(userId string) StoreChannel
|
|
|
|
|
IsFeatureEnabled(feature, userId string) StoreChannel
|
2015-11-19 17:54:01 +01:00
|
|
|
}
|
2016-02-04 13:00:03 -05:00
|
|
|
|
|
|
|
|
type LicenseStore interface {
|
|
|
|
|
Save(license *model.LicenseRecord) StoreChannel
|
|
|
|
|
Get(id string) StoreChannel
|
|
|
|
|
}
|
2016-04-21 22:37:01 -07:00
|
|
|
|
|
|
|
|
type PasswordRecoveryStore interface {
|
|
|
|
|
SaveOrUpdate(recovery *model.PasswordRecovery) StoreChannel
|
|
|
|
|
Delete(userId string) StoreChannel
|
|
|
|
|
Get(userId string) StoreChannel
|
|
|
|
|
GetByCode(code string) StoreChannel
|
|
|
|
|
}
|
2016-06-14 09:38:19 -04:00
|
|
|
|
|
|
|
|
type EmojiStore interface {
|
|
|
|
|
Save(emoji *model.Emoji) StoreChannel
|
|
|
|
|
Get(id string) StoreChannel
|
|
|
|
|
GetByName(name string) StoreChannel
|
|
|
|
|
GetAll() StoreChannel
|
|
|
|
|
Delete(id string, time int64) StoreChannel
|
|
|
|
|
}
|
2016-07-18 11:10:03 -04:00
|
|
|
|
|
|
|
|
type StatusStore interface {
|
|
|
|
|
SaveOrUpdate(status *model.Status) StoreChannel
|
|
|
|
|
Get(userId string) StoreChannel
|
|
|
|
|
GetOnlineAway() StoreChannel
|
2016-07-21 10:00:09 -04:00
|
|
|
GetOnline() StoreChannel
|
2016-09-06 15:48:43 -03:00
|
|
|
GetAllFromTeam(teamId string) StoreChannel
|
2016-07-18 11:10:03 -04:00
|
|
|
ResetAll() StoreChannel
|
|
|
|
|
GetTotalActiveUsersCount() StoreChannel
|
|
|
|
|
UpdateLastActivityAt(userId string, lastActivityAt int64) StoreChannel
|
|
|
|
|
}
|