mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 13:07:36 +03:00
User management improvements (#1101)
* Show more descriptive success messages for User actions * Check username uniqueness when creating/updating User * Adjust translations * Add tests for `validateUsernameUnique()` Co-authored-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
666c006579
commit
e60f2bfa3d
8 changed files with 137 additions and 28 deletions
|
@ -7,35 +7,48 @@ import (
|
|||
"github.com/navidrome/navidrome/model"
|
||||
)
|
||||
|
||||
type mockedUserRepo struct {
|
||||
func CreateMockUserRepo() *MockedUserRepo {
|
||||
return &MockedUserRepo{
|
||||
Data: map[string]*model.User{},
|
||||
}
|
||||
}
|
||||
|
||||
type MockedUserRepo struct {
|
||||
model.UserRepository
|
||||
data map[string]*model.User
|
||||
Err error
|
||||
Data map[string]*model.User
|
||||
}
|
||||
|
||||
func (u *mockedUserRepo) CountAll(qo ...model.QueryOptions) (int64, error) {
|
||||
return int64(len(u.data)), nil
|
||||
func (u *MockedUserRepo) CountAll(qo ...model.QueryOptions) (int64, error) {
|
||||
if u.Err != nil {
|
||||
return 0, u.Err
|
||||
}
|
||||
return int64(len(u.Data)), nil
|
||||
}
|
||||
|
||||
func (u *mockedUserRepo) Put(usr *model.User) error {
|
||||
if u.data == nil {
|
||||
u.data = make(map[string]*model.User)
|
||||
func (u *MockedUserRepo) Put(usr *model.User) error {
|
||||
if u.Err != nil {
|
||||
return u.Err
|
||||
}
|
||||
if usr.ID == "" {
|
||||
usr.ID = base64.StdEncoding.EncodeToString([]byte(usr.UserName))
|
||||
}
|
||||
usr.Password = usr.NewPassword
|
||||
u.data[strings.ToLower(usr.UserName)] = usr
|
||||
u.Data[strings.ToLower(usr.UserName)] = usr
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *mockedUserRepo) FindByUsername(username string) (*model.User, error) {
|
||||
usr, ok := u.data[strings.ToLower(username)]
|
||||
func (u *MockedUserRepo) FindByUsername(username string) (*model.User, error) {
|
||||
if u.Err != nil {
|
||||
return nil, u.Err
|
||||
}
|
||||
usr, ok := u.Data[strings.ToLower(username)]
|
||||
if !ok {
|
||||
return nil, model.ErrNotFound
|
||||
}
|
||||
return usr, nil
|
||||
}
|
||||
|
||||
func (u *mockedUserRepo) UpdateLastLoginAt(id string) error {
|
||||
return nil
|
||||
func (u *MockedUserRepo) UpdateLastLoginAt(id string) error {
|
||||
return u.Err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue