mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Remove user from preferences, stars, orguser, team member * Fix lint * Add Delete user from org and dashboard acl * Delete user from user auth * Add DeleteUser to quota * Add test files and adjust user auth store * Rename package in wire for user auth * Import Quota Service interface in other services * do the same in tests * fix lint tests * Fix tests * Add some tests * Rename InsertUser and DeleteUser to InsertOrgUser and DeleteOrgUser * Rename DeleteUser to DeleteByUser in quota * changing a method name in few additional places * Fix in other places * Fix lint * Fix tests * Chore: Split Delete User method * Add fakes for userauth * Add mock for access control Delete User permossion, use interface * Use interface for ream guardian * Add simple fake for dashboard acl * Add go routines, clean up, use interfaces * fix lint * Update pkg/services/user/userimpl/user_test.go Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com> * Update pkg/services/user/userimpl/user_test.go Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com> * Update pkg/services/user/userimpl/user_test.go Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com> * Split get user by ID * Use new method in api * Add tests * Aplly emthod in auth info service * Fix lint and some tests * Fix get user by ID * Fix lint Remove unused fakes * Use split get user id in admin users * Use GetbyID in cli commands * Clean up after merge * Remove commented out code * Clena up imports * add back ) * Fix wire generation for runner after merge with main Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
99 lines
2.0 KiB
Go
99 lines
2.0 KiB
Go
package user
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type HelpFlags1 uint64
|
|
|
|
// Typed errors
|
|
var (
|
|
ErrCaseInsensitive = errors.New("case insensitive conflict")
|
|
ErrUserNotFound = errors.New("user not found")
|
|
ErrUserAlreadyExists = errors.New("user already exists")
|
|
ErrLastGrafanaAdmin = errors.New("cannot remove last grafana admin")
|
|
ErrProtectedUser = errors.New("cannot adopt protected user")
|
|
)
|
|
|
|
type User struct {
|
|
ID int64 `xorm:"pk autoincr 'id'"`
|
|
Version int
|
|
Email string
|
|
Name string
|
|
Login string
|
|
Password string
|
|
Salt string
|
|
Rands string
|
|
Company string
|
|
EmailVerified bool
|
|
Theme string
|
|
HelpFlags1 HelpFlags1
|
|
IsDisabled bool
|
|
|
|
IsAdmin bool
|
|
IsServiceAccount bool
|
|
OrgID int64 `xorm:"org_id"`
|
|
|
|
Created time.Time
|
|
Updated time.Time
|
|
LastSeenAt time.Time
|
|
}
|
|
|
|
type CreateUserCommand struct {
|
|
Email string
|
|
Login string
|
|
Name string
|
|
Company string
|
|
OrgID int64
|
|
OrgName string
|
|
Password string
|
|
EmailVerified bool
|
|
IsAdmin bool
|
|
IsDisabled bool
|
|
SkipOrgSetup bool
|
|
DefaultOrgRole string
|
|
IsServiceAccount bool
|
|
}
|
|
|
|
func (u *User) NameOrFallback() string {
|
|
if u.Name != "" {
|
|
return u.Name
|
|
}
|
|
if u.Login != "" {
|
|
return u.Login
|
|
}
|
|
return u.Email
|
|
}
|
|
|
|
type DeleteUserCommand struct {
|
|
UserID int64
|
|
}
|
|
|
|
type GetUserByIDQuery struct {
|
|
ID int64
|
|
}
|
|
|
|
type ErrCaseInsensitiveLoginConflict struct {
|
|
Users []User
|
|
}
|
|
|
|
func (e *ErrCaseInsensitiveLoginConflict) Unwrap() error {
|
|
return ErrCaseInsensitive
|
|
}
|
|
|
|
func (e *ErrCaseInsensitiveLoginConflict) Error() string {
|
|
n := len(e.Users)
|
|
|
|
userStrings := make([]string, 0, n)
|
|
for _, v := range e.Users {
|
|
userStrings = append(userStrings, fmt.Sprintf("%s (email:%s, id:%d)", v.Login, v.Email, v.ID))
|
|
}
|
|
|
|
return fmt.Sprintf(
|
|
"Found a conflict in user login information. %d users already exist with either the same login or email: [%s].",
|
|
n, strings.Join(userStrings, ", "))
|
|
}
|