Chore: Replace Command dispatches by explicit calls (#32131)
* Clean up GetProvisionedDashboardDataByIdQuery * Clean up SaveProvisionedDashboardCommand * Clean up & fix AddTeamMemberCommand usages * Clean up & fix UpdateUserPermissionsCommand usages * Lint imports
This commit is contained in:
+11
-7
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/infra/metrics"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
@@ -86,15 +87,11 @@ func AdminUpdateUserPassword(c *models.ReqContext, form dtos.AdminUpdateUserPass
|
||||
}
|
||||
|
||||
// PUT /api/admin/users/:id/permissions
|
||||
func AdminUpdateUserPermissions(c *models.ReqContext, form dtos.AdminUpdateUserPermissionsForm) response.Response {
|
||||
func (hs *HTTPServer) AdminUpdateUserPermissions(c *models.ReqContext, form dtos.AdminUpdateUserPermissionsForm) response.Response {
|
||||
userID := c.ParamsInt64(":id")
|
||||
|
||||
cmd := models.UpdateUserPermissionsCommand{
|
||||
UserId: userID,
|
||||
IsGrafanaAdmin: form.IsGrafanaAdmin,
|
||||
}
|
||||
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
err := updateUserPermissions(hs.SQLStore, userID, form.IsGrafanaAdmin)
|
||||
if err != nil {
|
||||
if errors.Is(err, models.ErrLastGrafanaAdmin) {
|
||||
return response.Error(400, models.ErrLastGrafanaAdmin.Error(), nil)
|
||||
}
|
||||
@@ -189,3 +186,10 @@ func (hs *HTTPServer) AdminRevokeUserAuthToken(c *models.ReqContext, cmd models.
|
||||
userID := c.ParamsInt64(":id")
|
||||
return hs.revokeUserAuthTokenInternal(c, userID, cmd)
|
||||
}
|
||||
|
||||
// updateUserPermissions updates the user's permissions.
|
||||
//
|
||||
// Stubbable by tests.
|
||||
var updateUserPermissions = func(sqlStore *sqlstore.SQLStore, userID int64, isAdmin bool) error {
|
||||
return sqlStore.UpdateUserPermissions(userID, isAdmin)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user