Chore: Split get user by ID (#52442)
* 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>
This commit is contained in:
co-authored by
Sofia Papagiannaki
parent
64488f6b90
commit
fab6c38c95
@@ -8,15 +8,16 @@ import (
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
|
||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/runner"
|
||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
const AdminUserId = 1
|
||||
|
||||
func resetPasswordCommand(c utils.CommandLine, sqlStore *sqlstore.SQLStore) error {
|
||||
func resetPasswordCommand(c utils.CommandLine, runner runner.Runner) error {
|
||||
newPassword := ""
|
||||
|
||||
if c.Bool("password-from-stdin") {
|
||||
@@ -39,13 +40,14 @@ func resetPasswordCommand(c utils.CommandLine, sqlStore *sqlstore.SQLStore) erro
|
||||
return fmt.Errorf("new password is too short")
|
||||
}
|
||||
|
||||
userQuery := models.GetUserByIdQuery{Id: AdminUserId}
|
||||
userQuery := user.GetUserByIDQuery{ID: AdminUserId}
|
||||
|
||||
if err := sqlStore.GetUserById(context.Background(), &userQuery); err != nil {
|
||||
usr, err := runner.UserService.GetByID(context.Background(), &userQuery)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not read user from database. Error: %v", err)
|
||||
}
|
||||
|
||||
passwordHashed, err := util.EncodePassword(newPassword, userQuery.Result.Salt)
|
||||
passwordHashed, err := util.EncodePassword(newPassword, usr.Salt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -55,7 +57,7 @@ func resetPasswordCommand(c utils.CommandLine, sqlStore *sqlstore.SQLStore) erro
|
||||
NewPassword: passwordHashed,
|
||||
}
|
||||
|
||||
if err := sqlStore.ChangeUserPassword(context.Background(), &cmd); err != nil {
|
||||
if err := runner.SQLStore.ChangeUserPassword(context.Background(), &cmd); err != nil {
|
||||
return fmt.Errorf("failed to update user password: %w", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user