1package models
2
3import (
4	"time"
5
6	"github.com/grafana/grafana/pkg/setting"
7	"golang.org/x/oauth2"
8)
9
10const (
11	AuthModuleLDAP = "ldap"
12)
13
14type UserAuth struct {
15	Id                int64
16	UserId            int64
17	AuthModule        string
18	AuthId            string
19	Created           time.Time
20	OAuthAccessToken  string
21	OAuthRefreshToken string
22	OAuthTokenType    string
23	OAuthExpiry       time.Time
24}
25
26type ExternalUserInfo struct {
27	OAuthToken     *oauth2.Token
28	AuthModule     string
29	AuthId         string
30	UserId         int64
31	Email          string
32	Login          string
33	Name           string
34	Groups         []string
35	OrgRoles       map[int64]RoleType
36	IsGrafanaAdmin *bool // This is a pointer to know if we should sync this or not (nil = ignore sync)
37	IsDisabled     bool
38}
39
40type LoginInfo struct {
41	AuthModule    string
42	User          *User
43	ExternalUser  ExternalUserInfo
44	LoginUsername string
45	HTTPStatus    int
46	Error         error
47}
48
49// RequestURIKey is used as key to save request URI in contexts
50// (used for the Enterprise auditing feature)
51type RequestURIKey struct{}
52
53// ---------------------
54// COMMANDS
55
56type UpsertUserCommand struct {
57	ReqContext    *ReqContext
58	ExternalUser  *ExternalUserInfo
59	SignupAllowed bool
60
61	Result *User
62}
63
64type SetAuthInfoCommand struct {
65	AuthModule string
66	AuthId     string
67	UserId     int64
68	OAuthToken *oauth2.Token
69}
70
71type UpdateAuthInfoCommand struct {
72	AuthModule string
73	AuthId     string
74	UserId     int64
75	OAuthToken *oauth2.Token
76}
77
78type DeleteAuthInfoCommand struct {
79	UserAuth *UserAuth
80}
81
82// ----------------------
83// QUERIES
84
85type LoginUserQuery struct {
86	ReqContext *ReqContext
87	Username   string
88	Password   string
89	User       *User
90	IpAddress  string
91	AuthModule string
92	Cfg        *setting.Cfg
93}
94
95type GetUserByAuthInfoQuery struct {
96	AuthModule string
97	AuthId     string
98	UserId     int64
99	Email      string
100	Login      string
101}
102
103type GetExternalUserInfoByLoginQuery struct {
104	LoginOrEmail string
105
106	Result *ExternalUserInfo
107}
108
109type GetAuthInfoQuery struct {
110	UserId     int64
111	AuthModule string
112	AuthId     string
113
114	Result *UserAuth
115}
116
117type TeamOrgGroupDTO struct {
118	TeamName string `json:"teamName"`
119	OrgName  string `json:"orgName"`
120	GroupDN  string `json:"groupDN"`
121}
122
123type GetTeamsForLDAPGroupCommand struct {
124	Groups []string
125	Result []TeamOrgGroupDTO
126}
127