forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodel.go
273 lines (229 loc) · 6.69 KB
/
model.go
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
package user
import (
"time"
"github.com/grafana/grafana/pkg/apimachinery/identity"
"github.com/grafana/grafana/pkg/services/search/model"
)
type HelpFlags1 uint64
func (f HelpFlags1) HasFlag(flag HelpFlags1) bool { return f&flag != 0 }
func (f *HelpFlags1) AddFlag(flag HelpFlags1) { *f |= flag }
const (
HelpFlagGettingStartedPanelDismissed HelpFlags1 = 1 << iota
HelpFlagDashboardHelp1
)
type UpdateEmailActionType string
const (
EmailUpdateAction UpdateEmailActionType = "email-update"
LoginUpdateAction UpdateEmailActionType = "login-update"
)
type User struct {
ID int64 `xorm:"pk autoincr 'id'"`
UID string `json:"uid" xorm:"uid"`
Version int
Email string
Name string
Login string
Password Password
Salt string
Rands string
Company string
EmailVerified bool
Theme string
HelpFlags1 HelpFlags1 `xorm:"help_flags1"`
IsDisabled bool
IsAdmin bool
IsServiceAccount bool
OrgID int64 `xorm:"org_id"`
Created time.Time
Updated time.Time
LastSeenAt time.Time
}
type CreateUserCommand struct {
UID string
Email string
Login string
Name string
Company string
OrgID int64
OrgName string
Password Password
EmailVerified bool
IsAdmin bool
IsDisabled bool
SkipOrgSetup bool
DefaultOrgRole string
IsServiceAccount bool
}
type GetUserByLoginQuery struct {
LoginOrEmail string
}
type GetUserByEmailQuery struct {
Email string
}
type UpdateUserCommand struct {
Name string `json:"name"`
Email string `json:"email"`
Login string `json:"login"`
Theme string `json:"theme"`
UserID int64 `json:"-"`
IsDisabled *bool `json:"-"`
EmailVerified *bool `json:"-"`
IsGrafanaAdmin *bool `json:"-"`
// If password is included it will be validated, hashed and updated for user.
Password *Password `json:"-"`
// If old password is included it will be validated against users current password.
OldPassword *Password `json:"-"`
// If OrgID is included update current org for user
OrgID *int64 `json:"-"`
HelpFlags1 *HelpFlags1 `json:"-"`
}
type UpdateUserLastSeenAtCommand struct {
UserID int64
OrgID int64
}
type ListUserResult struct {
Users []*User
ContinueID int64
RV int64
}
type SearchUsersQuery struct {
SignedInUser identity.Requester
OrgID int64 `xorm:"org_id"`
Query string
Page int
Limit int
AuthModule string
SortOpts []model.SortOption
Filters []Filter
IsDisabled *bool
}
type SearchUserQueryResult struct {
TotalCount int64 `json:"totalCount"`
Users []*UserSearchHitDTO `json:"users"`
Page int `json:"page"`
PerPage int `json:"perPage"`
}
type UserSearchHitDTO struct {
ID int64 `json:"id" xorm:"id"`
UID string `json:"uid" xorm:"uid"`
Name string `json:"name"`
Login string `json:"login"`
Email string `json:"email"`
AvatarURL string `json:"avatarUrl" xorm:"avatar_url"`
IsAdmin bool `json:"isAdmin"`
IsDisabled bool `json:"isDisabled"`
LastSeenAt time.Time `json:"lastSeenAt"`
LastSeenAtAge string `json:"lastSeenAtAge"`
AuthLabels []string `json:"authLabels"`
AuthModule AuthModuleConversion `json:"-"`
}
type GetUserProfileQuery struct {
UserID int64
}
type UserProfileDTO struct {
ID int64 `json:"id"`
UID string `json:"uid"`
Email string `json:"email"`
Name string `json:"name"`
Login string `json:"login"`
Theme string `json:"theme"`
OrgID int64 `json:"orgId,omitempty"`
IsGrafanaAdmin bool `json:"isGrafanaAdmin"`
IsDisabled bool `json:"isDisabled"`
IsExternal bool `json:"isExternal"`
IsExternallySynced bool `json:"isExternallySynced"`
IsGrafanaAdminExternallySynced bool `json:"isGrafanaAdminExternallySynced"`
AuthLabels []string `json:"authLabels"`
UpdatedAt time.Time `json:"updatedAt"`
CreatedAt time.Time `json:"createdAt"`
AvatarURL string `json:"avatarUrl"`
AccessControl map[string]bool `json:"accessControl,omitempty"`
}
// implement Conversion interface to define custom field mapping (xorm feature)
type AuthModuleConversion []string
func (auth *AuthModuleConversion) FromDB(data []byte) error {
auth_module := string(data)
*auth = []string{auth_module}
return nil
}
// Just a stub, we don't want to write to database
func (auth *AuthModuleConversion) ToDB() ([]byte, error) {
return []byte{}, nil
}
type BatchDisableUsersCommand struct {
UserIDs []int64 `xorm:"user_ids"`
IsDisabled bool
}
type GetSignedInUserQuery struct {
UserID int64 `xorm:"user_id"`
Login string
Email string
OrgID int64 `xorm:"org_id"`
}
type AnalyticsSettings struct {
Identifier string
IntercomIdentifier string
}
func (u *User) NameOrFallback() string {
if u.Name != "" {
return u.Name
}
if u.Login != "" {
return u.Login
}
return u.Email
}
type DeleteUserCommand struct {
UserID int64
}
type GetUserByIDQuery struct {
ID int64
}
type GetUserByUIDQuery struct {
OrgID int64
UID string
}
type StartVerifyEmailCommand struct {
User User
Email string
Action UpdateEmailActionType
}
type CompleteEmailVerifyCommand struct {
User identity.Requester
Code string
}
type Filter interface {
WhereCondition() *WhereCondition
InCondition() *InCondition
JoinCondition() *JoinCondition
}
type WhereCondition struct {
Condition string
Params any
}
type InCondition struct {
Condition string
Params any
}
type JoinCondition struct {
Operator string
Table string
Params string
}
type SearchUserFilter interface {
GetFilter(filterName string, params []string) Filter
GetFilterList() map[string]FilterHandler
}
type FilterHandler func(params []string) (Filter, error)
const (
QuotaTargetSrv string = "user"
QuotaTarget string = "user"
)
type AdminCreateUserResponse struct {
ID int64 `json:"id"`
Message string `json:"message"`
}
type ChangeUserPasswordCommand struct {
OldPassword Password `json:"oldPassword"`
NewPassword Password `json:"newPassword"`
}