grafana/pkg/models/user.go
2015-02-23 20:07:49 +01:00

135 lines
2.2 KiB
Go

package models
import (
"errors"
"time"
)
// Typed errors
var (
ErrUserNotFound = errors.New("User not found")
)
type User struct {
Id int64
Version int
Email string
Name string
Login string
Password string
Salt string
Rands string
Company string
EmailVerified bool
Theme string
IsAdmin bool
OrgId int64
Created time.Time
Updated time.Time
}
// ---------------------
// COMMANDS
type CreateUserCommand struct {
Email string `json:"email" binding:"Required"`
Login string `json:"login"`
Name string `json:"name"`
Company string `json:"compay"`
Password string `json:"password" binding:"Required"`
IsAdmin bool `json:"-"`
Result User `json:"-"`
}
type UpdateUserCommand struct {
Name string `json:"name"`
Email string `json:"email"`
Login string `json:"login"`
UserId int64 `json:"-"`
}
type ChangeUserPasswordCommand struct {
OldPassword string `json:"oldPassword"`
NewPassword string `json:"newPassword"`
UserId int64 `json:"-"`
}
type DeleteUserCommand struct {
UserId int64
}
type SetUsingOrgCommand struct {
UserId int64
OrgId int64
}
// ----------------------
// QUERIES
type GetUserByLoginQuery struct {
LoginOrEmail string
Result *User
}
type GetUserByIdQuery struct {
Id int64
Result *User
}
type GetSignedInUserQuery struct {
UserId int64
Result *SignedInUser
}
type GetUserInfoQuery struct {
UserId int64
Result UserDTO
}
type SearchUsersQuery struct {
Query string
Page int
Limit int
Result []*UserSearchHitDTO
}
type GetUserOrgListQuery struct {
UserId int64
Result []*UserOrgDTO
}
// ------------------------
// DTO & Projections
type SignedInUser struct {
UserId int64
OrgId int64
OrgName string
OrgRole RoleType
Login string
Name string
Email string
ApiKeyId int64
IsGrafanaAdmin bool
}
type UserDTO struct {
Email string `json:"email"`
Name string `json:"name"`
Login string `json:"login"`
}
type UserSearchHitDTO struct {
Id int64 `json:"id"`
Name string `json:"name"`
Login string `json:"login"`
Email string `json:"email"`
IsAdmin bool `json:"isAdmin"`
}