Skip to content

Commit 2361e1d

Browse files
committed
feat: add endpoint to delete all validators from a dashboard
1 parent 3b2df71 commit 2361e1d

File tree

4 files changed

+46
-16
lines changed

4 files changed

+46
-16
lines changed

backend/pkg/api/data_access/vdb_management.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,6 @@ func (d *DataAccessService) getAddValidatorsQuery(uniqueValidatorIndexesQuery st
10561056
func (d *DataAccessService) RemoveValidatorDashboardValidators(ctx context.Context, dashboardId t.VDBIdPrimary, validators []t.VDBValidator) error {
10571057
if len(validators) == 0 {
10581058
// Remove all validators for the dashboard
1059-
// This is usually forbidden by API validation
10601059
_, err := d.alloyWriter.ExecContext(ctx, `
10611060
DELETE FROM users_val_dashboards_validators
10621061
WHERE dashboard_id = $1

backend/pkg/api/handlers/internal.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ func (h *HandlerService) InternalPostValidatorDashboardValidators(w http.Respons
368368
h.PublicPostValidatorDashboardValidators(w, r)
369369
}
370370

371+
func (h *HandlerService) InternalDeleteValidatorDashboardValidators(w http.ResponseWriter, r *http.Request) {
372+
h.PublicDeleteValidatorDashboardValidators(w, r)
373+
}
374+
371375
func (h *HandlerService) InternalGetValidatorDashboardValidators(w http.ResponseWriter, r *http.Request) {
372376
h.PublicGetValidatorDashboardValidators(w, r)
373377
}
@@ -400,8 +404,8 @@ func (h *HandlerService) InternalGetValidatorDashboardMobileValidators(w http.Re
400404
returnOk(w, r, response)
401405
}
402406

403-
func (h *HandlerService) InternalDeleteValidatorDashboardValidators(w http.ResponseWriter, r *http.Request) {
404-
h.PublicDeleteValidatorDashboardValidators(w, r)
407+
func (h *HandlerService) InternalPostValidatorDashboardValidatorBulkDeletions(w http.ResponseWriter, r *http.Request) {
408+
h.PublicPostValidatorDashboardValidatorBulkDeletions(w, r)
405409
}
406410

407411
func (h *HandlerService) InternalPostValidatorDashboardPublicIds(w http.ResponseWriter, r *http.Request) {

backend/pkg/api/handlers/public.go

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func (h *HandlerService) PublicGetValidatorDashboard(w http.ResponseWriter, r *h
264264
returnOk(w, r, response)
265265
}
266266

267-
// PublicPutValidatorDashboard godoc
267+
// PublicDeleteValidatorDashboard godoc
268268
//
269269
// @Description Delete a specified validator dashboard.
270270
// @Security ApiKeyInHeader || ApiKeyInQuery
@@ -450,7 +450,6 @@ func (h *HandlerService) PublicPutValidatorDashboardGroups(w http.ResponseWriter
450450
// @Description Delete a group in a specified validator dashboard.
451451
// @Tags Validator Dashboard Management
452452
// @Security ApiKeyInHeader || ApiKeyInQuery
453-
// @Accept json
454453
// @Produce json
455454
// @Param dashboard_id path integer true "The ID of the dashboard."
456455
// @Param group_id path integer true "The ID of the group."
@@ -714,17 +713,44 @@ func (h *HandlerService) PublicGetValidatorDashboardValidators(w http.ResponseWr
714713

715714
// PublicDeleteValidatorDashboardValidators godoc
716715
//
717-
// @Description Remove validators from a specified dashboard.
718-
// @Security ApiKeyInHeader || ApiKeyInQuery
719-
// @Tags Validator Dashboard Management
720-
// @Accept json
721-
// @Produce json
722-
// @Param dashboard_id path integer true "The ID of the dashboard."
723-
// @Param request body handlers.PublicDeleteValidatorDashboardValidators.request true "`validators`: Provide an array of validator indices or public keys that should get removed from the dashboard."
724-
// @Success 204 "Validators removed successfully."
725-
// @Failure 400 {object} types.ApiErrorResponse
726-
// @Router /validator-dashboards/{dashboard_id}/validators/bulk-deletions [post]
716+
// @Description Remove all validators from a specified dashboard.
717+
// @Security ApiKeyInHeader || ApiKeyInQuery
718+
// @Tags Validator Dashboard Management
719+
// @Produce json
720+
// @Param dashboard_id path integer true "The ID of the dashboard."
721+
// @Success 204 "Validators removed successfully."
722+
// @Failure 400 {object} types.ApiErrorResponse
723+
// @Router /validator-dashboards/{dashboard_id}/validators [delete]
727724
func (h *HandlerService) PublicDeleteValidatorDashboardValidators(w http.ResponseWriter, r *http.Request) {
725+
var v validationError
726+
dashboardId := v.checkPrimaryDashboardId(mux.Vars(r)["dashboard_id"])
727+
if v.hasErrors() {
728+
handleErr(w, r, v)
729+
return
730+
}
731+
ctx := r.Context()
732+
err := h.getDataAccessor(r).RemoveValidatorDashboardValidators(ctx, dashboardId, []types.VDBValidator{}) // removes all validators
733+
if err != nil {
734+
handleErr(w, r, err)
735+
return
736+
}
737+
738+
returnNoContent(w, r)
739+
}
740+
741+
// PublicPostValidatorDashboardValidatorBulkDeletions godoc
742+
//
743+
// @Description Remove specific validators from a specified dashboard in bulk.
744+
// @Security ApiKeyInHeader || ApiKeyInQuery
745+
// @Tags Validator Dashboard Management
746+
// @Accept json
747+
// @Produce json
748+
// @Param dashboard_id path integer true "The ID of the dashboard."
749+
// @Param request body handlers.PublicPostValidatorDashboardValidatorBulkDeletions.request true "`validators`: Provide an array of validator indices or public keys that should get removed from the dashboard."
750+
// @Success 204 "Validators removed successfully."
751+
// @Failure 400 {object} types.ApiErrorResponse
752+
// @Router /validator-dashboards/{dashboard_id}/validators/bulk-deletions [post]
753+
func (h *HandlerService) PublicPostValidatorDashboardValidatorBulkDeletions(w http.ResponseWriter, r *http.Request) {
728754
var v validationError
729755
dashboardId := v.checkPrimaryDashboardId(mux.Vars(r)["dashboard_id"])
730756
type request struct {

backend/pkg/api/router.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ func addValidatorDashboardRoutes(hs *handlers.HandlerService, publicRouter, inte
293293
{http.MethodDelete, "/{dashboard_id}/groups/{group_id}/validators", hs.PublicDeleteValidatorDashboardGroupValidators, hs.InternalDeleteValidatorDashboardGroupValidators},
294294
{http.MethodPost, "/{dashboard_id}/validators", hs.PublicPostValidatorDashboardValidators, hs.InternalPostValidatorDashboardValidators},
295295
{http.MethodGet, "/{dashboard_id}/validators", hs.PublicGetValidatorDashboardValidators, hs.InternalGetValidatorDashboardValidators},
296-
{http.MethodPost, "/{dashboard_id}/validators/bulk-deletions", hs.PublicDeleteValidatorDashboardValidators, hs.InternalDeleteValidatorDashboardValidators},
296+
{http.MethodDelete, "/{dashboard_id}/validators", hs.PublicDeleteValidatorDashboardValidators, hs.InternalDeleteValidatorDashboardValidators},
297+
{http.MethodPost, "/{dashboard_id}/validators/bulk-deletions", hs.PublicPostValidatorDashboardValidatorBulkDeletions, hs.InternalPostValidatorDashboardValidatorBulkDeletions},
297298
{http.MethodPost, "/{dashboard_id}/public-ids", hs.PublicPostValidatorDashboardPublicIds, hs.InternalPostValidatorDashboardPublicIds},
298299
{http.MethodPut, "/{dashboard_id}/public-ids/{public_id}", hs.PublicPutValidatorDashboardPublicId, hs.InternalPutValidatorDashboardPublicId},
299300
{http.MethodDelete, "/{dashboard_id}/public-ids/{public_id}", hs.PublicDeleteValidatorDashboardPublicId, hs.InternalDeleteValidatorDashboardPublicId},

0 commit comments

Comments
 (0)