| 
									
										
										
										
											2018-02-09 06:13:58 +08:00
										 |  |  | package models | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-20 05:09:49 +08:00
										 |  |  | import ( | 
					
						
							|  |  |  | 	"time" | 
					
						
							| 
									
										
										
										
											2019-02-02 08:40:57 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"golang.org/x/oauth2" | 
					
						
							| 
									
										
										
										
											2018-03-20 05:09:49 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-21 19:52:49 +08:00
										 |  |  | const ( | 
					
						
							|  |  |  | 	AuthModuleLDAP = "ldap" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-09 06:13:58 +08:00
										 |  |  | type UserAuth struct { | 
					
						
							| 
									
										
										
										
											2019-02-02 08:40:57 +08:00
										 |  |  | 	Id                int64 | 
					
						
							|  |  |  | 	UserId            int64 | 
					
						
							|  |  |  | 	AuthModule        string | 
					
						
							|  |  |  | 	AuthId            string | 
					
						
							|  |  |  | 	Created           time.Time | 
					
						
							|  |  |  | 	OAuthAccessToken  string | 
					
						
							|  |  |  | 	OAuthRefreshToken string | 
					
						
							|  |  |  | 	OAuthTokenType    string | 
					
						
							|  |  |  | 	OAuthExpiry       time.Time | 
					
						
							| 
									
										
										
										
											2018-02-09 06:13:58 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type ExternalUserInfo struct { | 
					
						
							| 
									
										
										
										
											2019-02-02 08:40:57 +08:00
										 |  |  | 	OAuthToken     *oauth2.Token | 
					
						
							| 
									
										
										
										
											2018-07-16 22:56:42 +08:00
										 |  |  | 	AuthModule     string | 
					
						
							|  |  |  | 	AuthId         string | 
					
						
							|  |  |  | 	UserId         int64 | 
					
						
							|  |  |  | 	Email          string | 
					
						
							|  |  |  | 	Login          string | 
					
						
							|  |  |  | 	Name           string | 
					
						
							|  |  |  | 	Groups         []string | 
					
						
							|  |  |  | 	OrgRoles       map[int64]RoleType | 
					
						
							|  |  |  | 	IsGrafanaAdmin *bool // This is a pointer to know if we should sync this or not (nil = ignore sync)
 | 
					
						
							| 
									
										
										
										
											2019-05-21 19:52:49 +08:00
										 |  |  | 	IsDisabled     bool | 
					
						
							| 
									
										
										
										
											2018-02-09 06:13:58 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-06 17:01:13 +08:00
										 |  |  | type LoginInfo struct { | 
					
						
							|  |  |  | 	AuthModule    string | 
					
						
							|  |  |  | 	User          *User | 
					
						
							|  |  |  | 	ExternalUser  ExternalUserInfo | 
					
						
							|  |  |  | 	LoginUsername string | 
					
						
							|  |  |  | 	HTTPStatus    int | 
					
						
							|  |  |  | 	Error         error | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-09 06:13:58 +08:00
										 |  |  | // ---------------------
 | 
					
						
							|  |  |  | // COMMANDS
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type UpsertUserCommand struct { | 
					
						
							| 
									
										
										
										
											2018-03-24 03:50:07 +08:00
										 |  |  | 	ReqContext    *ReqContext | 
					
						
							| 
									
										
										
										
											2018-02-09 06:13:58 +08:00
										 |  |  | 	ExternalUser  *ExternalUserInfo | 
					
						
							|  |  |  | 	SignupAllowed bool | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-23 23:16:11 +08:00
										 |  |  | 	Result *User | 
					
						
							| 
									
										
										
										
											2018-02-09 06:13:58 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type SetAuthInfoCommand struct { | 
					
						
							|  |  |  | 	AuthModule string | 
					
						
							|  |  |  | 	AuthId     string | 
					
						
							|  |  |  | 	UserId     int64 | 
					
						
							| 
									
										
										
										
											2019-02-02 08:40:57 +08:00
										 |  |  | 	OAuthToken *oauth2.Token | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type UpdateAuthInfoCommand struct { | 
					
						
							|  |  |  | 	AuthModule string | 
					
						
							|  |  |  | 	AuthId     string | 
					
						
							|  |  |  | 	UserId     int64 | 
					
						
							|  |  |  | 	OAuthToken *oauth2.Token | 
					
						
							| 
									
										
										
										
											2018-02-09 06:13:58 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type DeleteAuthInfoCommand struct { | 
					
						
							|  |  |  | 	UserAuth *UserAuth | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // ----------------------
 | 
					
						
							|  |  |  | // QUERIES
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type LoginUserQuery struct { | 
					
						
							| 
									
										
										
										
											2018-03-24 03:50:07 +08:00
										 |  |  | 	ReqContext *ReqContext | 
					
						
							|  |  |  | 	Username   string | 
					
						
							|  |  |  | 	Password   string | 
					
						
							|  |  |  | 	User       *User | 
					
						
							|  |  |  | 	IpAddress  string | 
					
						
							| 
									
										
										
										
											2020-09-04 20:54:59 +08:00
										 |  |  | 	AuthModule string | 
					
						
							| 
									
										
										
										
											2018-02-09 06:13:58 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type GetUserByAuthInfoQuery struct { | 
					
						
							|  |  |  | 	AuthModule string | 
					
						
							|  |  |  | 	AuthId     string | 
					
						
							|  |  |  | 	UserId     int64 | 
					
						
							|  |  |  | 	Email      string | 
					
						
							|  |  |  | 	Login      string | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-29 09:26:35 +08:00
										 |  |  | 	Result *User | 
					
						
							| 
									
										
										
										
											2018-02-09 06:13:58 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-21 19:52:49 +08:00
										 |  |  | type GetExternalUserInfoByLoginQuery struct { | 
					
						
							|  |  |  | 	LoginOrEmail string | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Result *ExternalUserInfo | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-09 06:13:58 +08:00
										 |  |  | type GetAuthInfoQuery struct { | 
					
						
							| 
									
										
										
										
											2019-02-02 08:40:57 +08:00
										 |  |  | 	UserId     int64 | 
					
						
							| 
									
										
										
										
											2018-02-09 06:13:58 +08:00
										 |  |  | 	AuthModule string | 
					
						
							|  |  |  | 	AuthId     string | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-29 06:06:22 +08:00
										 |  |  | 	Result *UserAuth | 
					
						
							| 
									
										
										
										
											2018-02-09 06:13:58 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-07-01 22:01:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-08 18:48:47 +08:00
										 |  |  | type TeamOrgGroupDTO struct { | 
					
						
							|  |  |  | 	TeamName string `json:"teamName"` | 
					
						
							|  |  |  | 	OrgName  string `json:"orgName"` | 
					
						
							|  |  |  | 	GroupDN  string `json:"groupDN"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type GetTeamsForLDAPGroupCommand struct { | 
					
						
							|  |  |  | 	Groups []string | 
					
						
							|  |  |  | 	Result []TeamOrgGroupDTO | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-01 22:01:43 +08:00
										 |  |  | type SyncTeamsCommand struct { | 
					
						
							|  |  |  | 	ExternalUser *ExternalUserInfo | 
					
						
							|  |  |  | 	User         *User | 
					
						
							|  |  |  | } |