mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 12:14:08 -06:00
dbb72f2c6e
* fix: create temp user no longer sets ID to 0 for all users The xorm tag added to the tempuser ID field caused xorm to create all temp users with ID 0. Removing that tag allows xorm to set the ID based on the database result instead. I also added a test which was failing before this. Fixes #63995
100 lines
2.3 KiB
Go
100 lines
2.3 KiB
Go
package tempuser
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/grafana/grafana/pkg/services/org"
|
|
)
|
|
|
|
// Typed errors
|
|
var (
|
|
ErrTempUserNotFound = errors.New("user not found")
|
|
)
|
|
|
|
type TempUserStatus string
|
|
|
|
const (
|
|
TmpUserSignUpStarted TempUserStatus = "SignUpStarted"
|
|
TmpUserInvitePending TempUserStatus = "InvitePending"
|
|
TmpUserCompleted TempUserStatus = "Completed"
|
|
TmpUserRevoked TempUserStatus = "Revoked"
|
|
TmpUserExpired TempUserStatus = "Expired"
|
|
)
|
|
|
|
// TempUser holds data for org invites and unconfirmed sign ups
|
|
type TempUser struct {
|
|
ID int64 `xorm:"pk autoincr 'id'"`
|
|
OrgID int64 `xorm:"org_id"`
|
|
Version int
|
|
Email string
|
|
Name string
|
|
Role org.RoleType
|
|
InvitedByUserID int64 `xorm:"invited_by_user_id"`
|
|
Status TempUserStatus
|
|
|
|
EmailSent bool
|
|
EmailSentOn time.Time
|
|
Code string
|
|
RemoteAddr string
|
|
|
|
Created int64
|
|
Updated int64
|
|
}
|
|
|
|
// ---------------------
|
|
// COMMANDS
|
|
|
|
type CreateTempUserCommand struct {
|
|
Email string
|
|
Name string
|
|
OrgID int64 `xorm:"org_id"`
|
|
InvitedByUserID int64 `xorm:"invited_by_user_id"`
|
|
Status TempUserStatus
|
|
Code string
|
|
Role org.RoleType
|
|
RemoteAddr string
|
|
}
|
|
|
|
type UpdateTempUserStatusCommand struct {
|
|
Code string
|
|
Status TempUserStatus
|
|
}
|
|
|
|
type ExpireTempUsersCommand struct {
|
|
OlderThan time.Time
|
|
|
|
NumExpired int64
|
|
}
|
|
|
|
type UpdateTempUserWithEmailSentCommand struct {
|
|
Code string
|
|
}
|
|
|
|
type GetTempUsersQuery struct {
|
|
OrgID int64 `xorm:"org_id"`
|
|
Email string
|
|
Status TempUserStatus
|
|
}
|
|
|
|
type GetTempUserByCodeQuery struct {
|
|
Code string
|
|
}
|
|
|
|
type TempUserDTO struct {
|
|
ID int64 `json:"id" xorm:"id"`
|
|
OrgID int64 `json:"orgId" xorm:"org_id"`
|
|
Name string `json:"name"`
|
|
Email string `json:"email"`
|
|
Role org.RoleType `json:"role"`
|
|
InvitedByLogin string `json:"invitedByLogin"`
|
|
InvitedByEmail string `json:"invitedByEmail"`
|
|
InvitedByName string `json:"invitedByName"`
|
|
Code string `json:"code"`
|
|
Status TempUserStatus `json:"status"`
|
|
URL string `json:"url"`
|
|
EmailSent bool `json:"emailSent"`
|
|
EmailSentOn time.Time `json:"emailSentOn"`
|
|
Created time.Time `json:"createdOn"`
|
|
}
|