2018-02-09 06:13:58 +08:00
|
|
|
package models
|
|
|
|
|
|
2018-03-20 05:09:49 +08:00
|
|
|
import (
|
2022-10-26 19:46:50 +08:00
|
|
|
"fmt"
|
2018-03-20 05:09:49 +08:00
|
|
|
"time"
|
2019-02-02 08:40:57 +08:00
|
|
|
|
2023-01-27 15:50:36 +08:00
|
|
|
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
2022-08-10 17:56:48 +08:00
|
|
|
"github.com/grafana/grafana/pkg/services/org"
|
2022-06-28 20:32:25 +08:00
|
|
|
"github.com/grafana/grafana/pkg/services/user"
|
2020-12-11 18:44:44 +08:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2022-06-28 20:32:25 +08:00
|
|
|
|
2019-02-02 08:40:57 +08:00
|
|
|
"golang.org/x/oauth2"
|
2018-03-20 05:09:49 +08:00
|
|
|
)
|
|
|
|
|
|
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
|
2021-12-14 22:22:10 +08:00
|
|
|
OAuthIdToken string
|
2019-02-02 08:40:57 +08:00
|
|
|
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
|
2022-08-10 17:56:48 +08:00
|
|
|
OrgRoles map[int64]org.RoleType
|
2018-07-16 22:56:42 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2022-10-26 19:46:50 +08:00
|
|
|
func (e *ExternalUserInfo) String() string {
|
|
|
|
|
return fmt.Sprintf("%+v", *e)
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-06 17:01:13 +08:00
|
|
|
type LoginInfo struct {
|
|
|
|
|
AuthModule string
|
2022-06-28 20:32:25 +08:00
|
|
|
User *user.User
|
2020-11-06 17:01:13 +08:00
|
|
|
ExternalUser ExternalUserInfo
|
|
|
|
|
LoginUsername string
|
|
|
|
|
HTTPStatus int
|
|
|
|
|
Error error
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-20 00:55:53 +08:00
|
|
|
// RequestURIKey is used as key to save request URI in contexts
|
|
|
|
|
// (used for the Enterprise auditing feature)
|
|
|
|
|
type RequestURIKey struct{}
|
|
|
|
|
|
2018-02-09 06:13:58 +08:00
|
|
|
// ---------------------
|
|
|
|
|
// COMMANDS
|
|
|
|
|
|
|
|
|
|
type UpsertUserCommand struct {
|
2023-01-27 15:50:36 +08:00
|
|
|
ReqContext *contextmodel.ReqContext
|
2022-07-15 17:21:09 +08:00
|
|
|
ExternalUser *ExternalUserInfo
|
|
|
|
|
UserLookupParams
|
2018-02-09 06:13:58 +08:00
|
|
|
SignupAllowed bool
|
|
|
|
|
|
2022-06-28 20:32:25 +08:00
|
|
|
Result *user.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 {
|
2023-01-27 15:50:36 +08:00
|
|
|
ReqContext *contextmodel.ReqContext
|
2018-03-24 03:50:07 +08:00
|
|
|
Username string
|
|
|
|
|
Password string
|
2022-06-28 20:32:25 +08:00
|
|
|
User *user.User
|
2018-03-24 03:50:07 +08:00
|
|
|
IpAddress string
|
2020-09-04 20:54:59 +08:00
|
|
|
AuthModule string
|
2020-12-11 18:44:44 +08:00
|
|
|
Cfg *setting.Cfg
|
2018-02-09 06:13:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type GetUserByAuthInfoQuery struct {
|
|
|
|
|
AuthModule string
|
|
|
|
|
AuthId string
|
2022-07-15 17:21:09 +08:00
|
|
|
UserLookupParams
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type UserLookupParams struct {
|
|
|
|
|
// Describes lookup order as well
|
|
|
|
|
UserID *int64 // if set, will try to find the user by id
|
|
|
|
|
Email *string // if set, will try to find the user by email
|
|
|
|
|
Login *string // if set, will try to find the user by login
|
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
|
|
|
|
2022-11-29 22:20:28 +08:00
|
|
|
type GetUserLabelsQuery struct {
|
|
|
|
|
UserIDs []int64
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-08 18:48:47 +08:00
|
|
|
type TeamOrgGroupDTO struct {
|
|
|
|
|
TeamName string `json:"teamName"`
|
|
|
|
|
OrgName string `json:"orgName"`
|
|
|
|
|
GroupDN string `json:"groupDN"`
|
|
|
|
|
}
|