forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodel.go
186 lines (155 loc) · 4.71 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
package team
import (
"errors"
"time"
"github.com/grafana/grafana/pkg/apimachinery/identity"
"github.com/grafana/grafana/pkg/services/search/model"
)
// Typed errors
var (
ErrTeamNotFound = errors.New("team not found")
ErrTeamNameTaken = errors.New("team name is taken")
ErrTeamMemberNotFound = errors.New("team member not found")
ErrLastTeamAdmin = errors.New("not allowed to remove last admin")
ErrNotAllowedToUpdateTeam = errors.New("user not allowed to update team")
ErrNotAllowedToUpdateTeamInDifferentOrg = errors.New("user not allowed to update team in another org")
ErrTeamMemberAlreadyAdded = errors.New("user is already added to this team")
)
// Team model
type Team struct {
ID int64 `json:"id" xorm:"pk autoincr 'id'"`
UID string `json:"uid" xorm:"uid"`
OrgID int64 `json:"orgId" xorm:"org_id"`
Name string `json:"name"`
Email string `json:"email"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
}
// ---------------------
// COMMANDS
type CreateTeamCommand struct {
Name string `json:"name" binding:"Required"`
Email string `json:"email"`
OrgID int64 `json:"-"`
}
type UpdateTeamCommand struct {
ID int64
Name string
Email string
OrgID int64 `json:"-"`
}
type DeleteTeamCommand struct {
OrgID int64
ID int64
}
type GetTeamByIDQuery struct {
OrgID int64
ID int64
SignedInUser identity.Requester
HiddenUsers map[string]struct{}
}
// FilterIgnoreUser is used in a get / search teams query when the caller does not want to filter teams by user ID / membership
const FilterIgnoreUser int64 = 0
type GetTeamIDsByUserQuery struct {
OrgID int64
UserID int64 `json:"userId"`
}
type GetTeamsByUserQuery struct {
OrgID int64
UserID int64 `json:"userId"`
SignedInUser identity.Requester
}
type SearchTeamsQuery struct {
Query string
Name string
Limit int
Page int
OrgID int64 `xorm:"org_id"`
SortOpts []model.SortOption
TeamIds []int64
SignedInUser identity.Requester
HiddenUsers map[string]struct{}
}
type TeamDTO struct {
ID int64 `json:"id" xorm:"id"`
UID string `json:"uid" xorm:"uid"`
OrgID int64 `json:"orgId" xorm:"org_id"`
Name string `json:"name"`
Email string `json:"email"`
AvatarURL string `json:"avatarUrl"`
MemberCount int64 `json:"memberCount"`
Permission PermissionType `json:"permission"`
AccessControl map[string]bool `json:"accessControl"`
}
type PermissionType int
const (
PermissionTypeMember PermissionType = 0
PermissionTypeAdmin PermissionType = 4
)
func (p PermissionType) String() string {
if p == PermissionTypeAdmin {
return "Admin"
}
return "Member"
}
type SearchTeamQueryResult struct {
TotalCount int64 `json:"totalCount"`
Teams []*TeamDTO `json:"teams"`
Page int `json:"page"`
PerPage int `json:"perPage"`
}
// TeamMember model
type TeamMember struct {
ID int64 `xorm:"pk autoincr 'id'"`
OrgID int64 `xorm:"org_id"`
TeamID int64 `xorm:"team_id"`
UserID int64 `xorm:"user_id"`
External bool // Signals that the membership has been created by an external systems, such as LDAP
Permission PermissionType
Created time.Time
Updated time.Time
}
// ---------------------
// COMMANDS
type AddTeamMemberCommand struct {
UserID int64 `json:"userId" binding:"Required"`
Permission PermissionType `json:"-"`
}
type UpdateTeamMemberCommand struct {
Permission PermissionType `json:"permission"`
}
type SetTeamMembershipsCommand struct {
Members []string `json:"members"`
Admins []string `json:"admins"`
}
type RemoveTeamMemberCommand struct {
OrgID int64 `json:"-"`
UserID int64
TeamID int64
}
// ----------------------
// QUERIES
type GetTeamMembersQuery struct {
OrgID int64
TeamID int64
TeamUID string
UserID int64
External bool
SignedInUser identity.Requester
}
// ----------------------
// Projections and DTOs
type TeamMemberDTO struct {
OrgID int64 `json:"orgId" xorm:"org_id"`
TeamID int64 `json:"teamId" xorm:"team_id"`
TeamUID string `json:"teamUID" xorm:"uid"`
UserID int64 `json:"userId" xorm:"user_id"`
External bool `json:"-"`
AuthModule string `json:"auth_module"`
Email string `json:"email"`
Name string `json:"name"`
Login string `json:"login"`
AvatarURL string `json:"avatarUrl" xorm:"avatar_url"`
Labels []string `json:"labels"`
Permission PermissionType `json:"permission"`
}