summaryrefslogtreecommitdiffstats
path: root/store/store.go
blob: a6162fb07cccad375ecbd3abfb5c4805182a2e6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package store

import (
	"time"

	l4g "github.com/alecthomas/log4go"
	"github.com/mattermost/platform/model"
	goi18n "github.com/nicksnyder/go-i18n/i18n"
)

type StoreResult struct {
	Data interface{}
	Err  *model.AppError
}

type StoreChannel chan StoreResult

func Must(sc StoreChannel) interface{} {
	r := <-sc
	if r.Err != nil {
		l4g.Close()
		time.Sleep(time.Second)
		panic(r.Err)
	}

	return r.Data
}

type Store interface {
	Team() TeamStore
	Channel() ChannelStore
	Post() PostStore
	User() UserStore
	Audit() AuditStore
	Session() SessionStore
	OAuth() OAuthStore
	System() SystemStore
	Webhook() WebhookStore
	Preference() PreferenceStore
	MarkSystemRanUnitTests()
	Close()
}

type TeamStore interface {
	Save(T goi18n.TranslateFunc, team *model.Team) StoreChannel
	Update(T goi18n.TranslateFunc, team *model.Team) StoreChannel
	UpdateDisplayName(T goi18n.TranslateFunc, name string, teamId string) StoreChannel
	Get(T goi18n.TranslateFunc, id string) StoreChannel
	GetByName(T goi18n.TranslateFunc, name string) StoreChannel
	GetTeamsForEmail(T goi18n.TranslateFunc, domain string) StoreChannel
	GetAll(T goi18n.TranslateFunc) StoreChannel
	GetAllTeamListing(T goi18n.TranslateFunc) StoreChannel
	GetByInviteId(T goi18n.TranslateFunc, inviteId string) StoreChannel
	PermanentDelete(T goi18n.TranslateFunc, teamId string) StoreChannel
}

type ChannelStore interface {
	Save(T goi18n.TranslateFunc, channel *model.Channel) StoreChannel
	SaveDirectChannel(T goi18n.TranslateFunc, channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) StoreChannel
	Update(T goi18n.TranslateFunc, channel *model.Channel) StoreChannel
	Get(T goi18n.TranslateFunc, id string) StoreChannel
	GetFromMaster(T goi18n.TranslateFunc, id string) StoreChannel
	Delete(T goi18n.TranslateFunc, channelId string, time int64) StoreChannel
	PermanentDeleteByTeam(T goi18n.TranslateFunc, teamId string) StoreChannel
	GetByName(T goi18n.TranslateFunc, team_id string, domain string) StoreChannel
	GetChannels(T goi18n.TranslateFunc, teamId string, userId string) StoreChannel
	GetMoreChannels(T goi18n.TranslateFunc, teamId string, userId string) StoreChannel
	GetChannelCounts(T goi18n.TranslateFunc, teamId string, userId string) StoreChannel
	GetForExport(T goi18n.TranslateFunc, teamId string) StoreChannel

	SaveMember(T goi18n.TranslateFunc, member *model.ChannelMember) StoreChannel
	UpdateMember(T goi18n.TranslateFunc, member *model.ChannelMember) StoreChannel
	GetMembers(T goi18n.TranslateFunc, channelId string) StoreChannel
	GetMember(T goi18n.TranslateFunc, channelId string, userId string) StoreChannel
	GetMemberCount(T goi18n.TranslateFunc, channelId string) StoreChannel
	RemoveMember(T goi18n.TranslateFunc, channelId string, userId string) StoreChannel
	PermanentDeleteMembersByUser(T goi18n.TranslateFunc, userId string) StoreChannel
	GetExtraMembers(T goi18n.TranslateFunc, channelId string, limit int) StoreChannel
	CheckPermissionsTo(T goi18n.TranslateFunc, teamId string, channelId string, userId string) StoreChannel
	CheckOpenChannelPermissions(T goi18n.TranslateFunc, teamId string, channelId string) StoreChannel
	CheckPermissionsToByName(T goi18n.TranslateFunc, teamId string, channelName string, userId string) StoreChannel
	UpdateLastViewedAt(T goi18n.TranslateFunc, channelId string, userId string) StoreChannel
	IncrementMentionCount(T goi18n.TranslateFunc, channelId string, userId string) StoreChannel
	AnalyticsTypeCount(T goi18n.TranslateFunc, teamId string, channelType string) StoreChannel
}

type PostStore interface {
	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
	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
	GetForExport(channelId string) StoreChannel
	AnalyticsUserCountsWithPostsByDay(teamId string) StoreChannel
	AnalyticsPostCountsByDay(teamId string) StoreChannel
	AnalyticsPostCount(teamId string) StoreChannel
}

type UserStore interface {
	Save(user *model.User) StoreChannel
	Update(user *model.User, allowRoleUpdate bool) StoreChannel
	UpdateLastPictureUpdate(userId string) StoreChannel
	UpdateLastPingAt(userId string, time int64) StoreChannel
	UpdateLastActivityAt(userId string, time int64) StoreChannel
	UpdateUserAndSessionActivity(userId string, sessionId string, time int64) StoreChannel
	UpdatePassword(userId, newPassword string) StoreChannel
	UpdateAuthData(userId, service, authData string) StoreChannel
	Get(id string) StoreChannel
	GetProfiles(teamId string) StoreChannel
	GetByEmail(teamId string, email string) StoreChannel
	GetByAuth(teamId string, authData string, authService string) StoreChannel
	GetByUsername(teamId string, username string) StoreChannel
	VerifyEmail(userId string) StoreChannel
	GetEtagForProfiles(teamId string) StoreChannel
	UpdateFailedPasswordAttempts(userId string, attempts int) StoreChannel
	GetForExport(teamId string) StoreChannel
	GetTotalUsersCount() StoreChannel
	GetTotalActiveUsersCount() StoreChannel
	GetSystemAdminProfiles() StoreChannel
	PermanentDelete(userId string) StoreChannel
}

type SessionStore interface {
	Save(session *model.Session) StoreChannel
	Get(sessionIdOrToken string) StoreChannel
	GetSessions(userId string) StoreChannel
	Remove(sessionIdOrToken string) StoreChannel
	RemoveAllSessionsForTeam(teamId string) StoreChannel
	PermanentDeleteSessionsByUser(teamId string) StoreChannel
	UpdateLastActivityAt(sessionId string, time int64) StoreChannel
	UpdateRoles(userId string, roles string) StoreChannel
}

type AuditStore interface {
	Save(T goi18n.TranslateFunc, audit *model.Audit) StoreChannel
	Get(T goi18n.TranslateFunc, user_id string, limit int) StoreChannel
	PermanentDeleteByUser(T goi18n.TranslateFunc, userId string) StoreChannel
}

type OAuthStore interface {
	SaveApp(T goi18n.TranslateFunc, app *model.OAuthApp) StoreChannel
	UpdateApp(T goi18n.TranslateFunc, app *model.OAuthApp) StoreChannel
	GetApp(T goi18n.TranslateFunc, id string) StoreChannel
	GetAppByUser(T goi18n.TranslateFunc, userId string) StoreChannel
	SaveAuthData(T goi18n.TranslateFunc, authData *model.AuthData) StoreChannel
	GetAuthData(T goi18n.TranslateFunc, code string) StoreChannel
	RemoveAuthData(T goi18n.TranslateFunc, code string) StoreChannel
	PermanentDeleteAuthDataByUser(T goi18n.TranslateFunc, userId string) StoreChannel
	SaveAccessData(T goi18n.TranslateFunc, accessData *model.AccessData) StoreChannel
	GetAccessData(T goi18n.TranslateFunc, token string) StoreChannel
	GetAccessDataByAuthCode(T goi18n.TranslateFunc, authCode string) StoreChannel
	RemoveAccessData(T goi18n.TranslateFunc, token string) StoreChannel
}

type SystemStore interface {
	Save(T goi18n.TranslateFunc, system *model.System) StoreChannel
	Update(T goi18n.TranslateFunc, system *model.System) StoreChannel
	Get(T goi18n.TranslateFunc) StoreChannel
}

type WebhookStore interface {
	SaveIncoming(T goi18n.TranslateFunc, webhook *model.IncomingWebhook) StoreChannel
	GetIncoming(T goi18n.TranslateFunc, id string) StoreChannel
	GetIncomingByUser(T goi18n.TranslateFunc, userId string) StoreChannel
	GetIncomingByChannel(T goi18n.TranslateFunc, channelId string) StoreChannel
	DeleteIncoming(T goi18n.TranslateFunc, webhookId string, time int64) StoreChannel
	PermanentDeleteIncomingByUser(T goi18n.TranslateFunc, userId string) StoreChannel
	SaveOutgoing(T goi18n.TranslateFunc, webhook *model.OutgoingWebhook) StoreChannel
	GetOutgoing(T goi18n.TranslateFunc, id string) StoreChannel
	GetOutgoingByCreator(T goi18n.TranslateFunc, userId string) StoreChannel
	GetOutgoingByChannel(T goi18n.TranslateFunc, channelId string) StoreChannel
	GetOutgoingByTeam(T goi18n.TranslateFunc, teamId string) StoreChannel
	DeleteOutgoing(T goi18n.TranslateFunc, webhookId string, time int64) StoreChannel
	PermanentDeleteOutgoingByUser(T goi18n.TranslateFunc, userId string) StoreChannel
	UpdateOutgoing(T goi18n.TranslateFunc, hook *model.OutgoingWebhook) StoreChannel
}

type PreferenceStore interface {
	Save(T goi18n.TranslateFunc, preferences *model.Preferences) StoreChannel
	Get(T goi18n.TranslateFunc, userId string, category string, name string) StoreChannel
	GetCategory(T goi18n.TranslateFunc, userId string, category string) StoreChannel
	GetAll(T goi18n.TranslateFunc, userId string) StoreChannel
	PermanentDeleteByUser(T goi18n.TranslateFunc, userId string) StoreChannel
	IsFeatureEnabled(T goi18n.TranslateFunc, feature, userId string) StoreChannel
}