2015-02-23 13:07:49 -06:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"time"
|
2022-08-10 04:56:48 -05:00
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/org"
|
|
|
|
"github.com/grafana/grafana/pkg/services/user"
|
2015-02-23 13:07:49 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
// Typed errors
|
|
|
|
var (
|
2020-11-05 06:07:06 -06:00
|
|
|
ErrLastOrgAdmin = errors.New("cannot remove last organization admin")
|
|
|
|
ErrOrgUserNotFound = errors.New("cannot find the organization user")
|
|
|
|
ErrOrgUserAlreadyAdded = errors.New("user is already added to organization")
|
2015-02-23 13:07:49 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
type OrgUser struct {
|
2015-05-01 02:48:07 -05:00
|
|
|
Id int64
|
2015-02-23 13:07:49 -06:00
|
|
|
OrgId int64
|
|
|
|
UserId int64
|
2022-08-10 04:56:48 -05:00
|
|
|
Role org.RoleType
|
2015-02-23 13:07:49 -06:00
|
|
|
Created time.Time
|
|
|
|
Updated time.Time
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------
|
|
|
|
// COMMANDS
|
|
|
|
|
|
|
|
type RemoveOrgUserCommand struct {
|
2018-10-11 00:48:35 -05:00
|
|
|
UserId int64
|
|
|
|
OrgId int64
|
|
|
|
ShouldDeleteOrphanedUser bool
|
2018-10-11 14:20:53 -05:00
|
|
|
UserWasDeleted bool
|
2015-02-23 13:07:49 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
type AddOrgUserCommand struct {
|
2022-08-10 04:56:48 -05:00
|
|
|
LoginOrEmail string `json:"loginOrEmail" binding:"Required"`
|
|
|
|
Role org.RoleType `json:"role" binding:"Required"`
|
2015-02-23 13:07:49 -06:00
|
|
|
|
|
|
|
OrgId int64 `json:"-"`
|
|
|
|
UserId int64 `json:"-"`
|
2022-07-07 07:50:38 -05:00
|
|
|
|
|
|
|
// internal use: avoid adding service accounts to orgs via user routes
|
|
|
|
AllowAddingServiceAccount bool `json:"-"`
|
2015-02-23 13:07:49 -06:00
|
|
|
}
|
|
|
|
|
2015-05-01 02:48:07 -05:00
|
|
|
type UpdateOrgUserCommand struct {
|
2022-08-10 04:56:48 -05:00
|
|
|
Role org.RoleType `json:"role" binding:"Required"`
|
2015-05-01 02:48:07 -05:00
|
|
|
|
|
|
|
OrgId int64 `json:"-"`
|
|
|
|
UserId int64 `json:"-"`
|
|
|
|
}
|
|
|
|
|
2015-02-23 13:07:49 -06:00
|
|
|
// ----------------------
|
|
|
|
// QUERIES
|
|
|
|
|
|
|
|
type GetOrgUsersQuery struct {
|
2022-03-14 12:24:07 -05:00
|
|
|
UserID int64
|
|
|
|
OrgId int64
|
|
|
|
Query string
|
|
|
|
Limit int
|
2022-05-25 13:40:41 -05:00
|
|
|
// Flag used to allow oss edition to query users without access control
|
|
|
|
DontEnforceAccessControl bool
|
2018-02-09 03:42:37 -06:00
|
|
|
|
2022-08-10 04:56:48 -05:00
|
|
|
User *user.SignedInUser
|
2015-02-23 13:07:49 -06:00
|
|
|
Result []*OrgUserDTO
|
|
|
|
}
|
|
|
|
|
2021-05-12 07:10:35 -05:00
|
|
|
type SearchOrgUsersQuery struct {
|
2022-03-14 12:24:07 -05:00
|
|
|
OrgID int64
|
|
|
|
Query string
|
|
|
|
Page int
|
|
|
|
Limit int
|
2021-05-12 07:10:35 -05:00
|
|
|
|
2022-08-10 04:56:48 -05:00
|
|
|
User *user.SignedInUser
|
2021-05-12 07:10:35 -05:00
|
|
|
Result SearchOrgUsersQueryResult
|
|
|
|
}
|
|
|
|
|
|
|
|
type SearchOrgUsersQueryResult struct {
|
|
|
|
TotalCount int64 `json:"totalCount"`
|
|
|
|
OrgUsers []*OrgUserDTO `json:"OrgUsers"`
|
|
|
|
Page int `json:"page"`
|
|
|
|
PerPage int `json:"perPage"`
|
|
|
|
}
|
|
|
|
|
2015-02-23 13:07:49 -06:00
|
|
|
// ----------------------
|
|
|
|
// Projections and DTOs
|
|
|
|
|
|
|
|
type OrgUserDTO struct {
|
2021-12-22 11:46:33 -06:00
|
|
|
OrgId int64 `json:"orgId"`
|
|
|
|
UserId int64 `json:"userId"`
|
|
|
|
Email string `json:"email"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
AvatarUrl string `json:"avatarUrl"`
|
|
|
|
Login string `json:"login"`
|
|
|
|
Role string `json:"role"`
|
|
|
|
LastSeenAt time.Time `json:"lastSeenAt"`
|
2022-02-22 07:58:42 -06:00
|
|
|
Updated time.Time `json:"-"`
|
|
|
|
Created time.Time `json:"-"`
|
2021-12-22 11:46:33 -06:00
|
|
|
LastSeenAtAge string `json:"lastSeenAtAge"`
|
|
|
|
AccessControl map[string]bool `json:"accessControl,omitempty"`
|
2022-08-15 03:58:58 -05:00
|
|
|
IsDisabled bool `json:"isDisabled"`
|
2015-02-23 13:07:49 -06:00
|
|
|
}
|