From aa67df173fbc19e4a276c9fa71403b3997691419 Mon Sep 17 00:00:00 2001 From: remoterami <142154971+remoterami@users.noreply.github.com> Date: Mon, 6 Jan 2025 16:26:19 +0100 Subject: [PATCH 1/4] fix(api): add vdb archived check to notifications middleware --- backend/pkg/api/router.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/pkg/api/router.go b/backend/pkg/api/router.go index ecaa07c38..918180976 100644 --- a/backend/pkg/api/router.go +++ b/backend/pkg/api/router.go @@ -353,10 +353,10 @@ func addNotificationRoutes(hs *handlers.HandlerService, publicRouter, internalRo publicDashboardNotificationSettingsRouter := publicNotificationRouter.NewRoute().Subrouter() internalDashboardNotificationSettingsRouter := internalNotificationRouter.NewRoute().Subrouter() - // TODO add adb auth middleware to account dashboard endpoints once they are implemented + // TODO add adb auth and archivedCheck middleware to account dashboard endpoints once they are implemented if !debug { - publicDashboardNotificationSettingsRouter.Use(hs.VDBAuthMiddleware) - internalDashboardNotificationSettingsRouter.Use(hs.VDBAuthMiddleware) + publicDashboardNotificationSettingsRouter.Use(hs.VDBAuthMiddleware, hs.VDBArchivedCheckMiddleware) + internalDashboardNotificationSettingsRouter.Use(hs.VDBAuthMiddleware, hs.VDBArchivedCheckMiddleware) } dashboardSettingsEndpoints := []endpoint{ {http.MethodGet, "/validator-dashboards/{dashboard_id}/groups/{group_id}/epochs/{epoch}", hs.PublicGetUserNotificationsValidatorDashboard, hs.InternalGetUserNotificationsValidatorDashboard}, From 12864ad723d2f60200d851ef96b98283d6cd926f Mon Sep 17 00:00:00 2001 From: remoterami <142154971+remoterami@users.noreply.github.com> Date: Mon, 6 Jan 2025 17:18:37 +0100 Subject: [PATCH 2/4] feat(api): indicate archival status in dashboard settings overview --- backend/pkg/api/data_access/notifications.go | 3 +++ backend/pkg/api/types/notifications.go | 1 + frontend/types/api/notifications.ts | 1 + 3 files changed, 5 insertions(+) diff --git a/backend/pkg/api/data_access/notifications.go b/backend/pkg/api/data_access/notifications.go index 2734ce39a..7ddf7b70e 100644 --- a/backend/pkg/api/data_access/notifications.go +++ b/backend/pkg/api/data_access/notifications.go @@ -1564,6 +1564,7 @@ func (d *DataAccessService) GetNotificationSettingsDashboards(ctx context.Contex // Get the validator dashboards valDashboards := []struct { DashboardId uint64 `db:"dashboard_id"` + IsArchived bool `db:"is_archived"` DashboardName string `db:"dashboard_name"` GroupId uint64 `db:"group_id"` GroupName string `db:"group_name"` @@ -1575,6 +1576,7 @@ func (d *DataAccessService) GetNotificationSettingsDashboards(ctx context.Contex err := d.alloyReader.SelectContext(ctx, &valDashboards, ` SELECT d.id AS dashboard_id, + d.is_archived IS NOT NULL AS is_archived, d.name AS dashboard_name, g.id AS group_id, g.name AS group_name, @@ -1731,6 +1733,7 @@ func (d *DataAccessService) GetNotificationSettingsDashboards(ctx context.Contex // Set general info resultMap[key].IsAccountDashboard = false + resultMap[key].IsArchived = valDashboard.IsArchived resultMap[key].DashboardId = valDashboard.DashboardId resultMap[key].DashboardName = valDashboard.DashboardName resultMap[key].GroupId = valDashboard.GroupId diff --git a/backend/pkg/api/types/notifications.go b/backend/pkg/api/types/notifications.go index 9e38715c1..807d6340f 100644 --- a/backend/pkg/api/types/notifications.go +++ b/backend/pkg/api/types/notifications.go @@ -216,6 +216,7 @@ type PutUserNotificationSettingsAccountDashboardResponse ApiDataResponse[Notific type NotificationSettingsDashboardsTableRow struct { IsAccountDashboard bool `json:"is_account_dashboard"` // if false it's a validator dashboard + IsArchived bool `json:"is_archived"` DashboardId uint64 `json:"dashboard_id"` DashboardName string `json:"dashboard_name"` GroupId uint64 `json:"group_id"` diff --git a/frontend/types/api/notifications.ts b/frontend/types/api/notifications.ts index f8b8ec084..7fab1c5dd 100644 --- a/frontend/types/api/notifications.ts +++ b/frontend/types/api/notifications.ts @@ -208,6 +208,7 @@ export interface NotificationSettingsAccountDashboard { export type PutUserNotificationSettingsAccountDashboardResponse = ApiDataResponse; export interface NotificationSettingsDashboardsTableRow { is_account_dashboard: boolean; // if false it's a validator dashboard + is_archived: boolean; dashboard_id: number /* uint64 */; dashboard_name: string; group_id: number /* uint64 */; From 4e33da4fd5721b06b62c573182a3f191f476509a Mon Sep 17 00:00:00 2001 From: remoterami <142154971+remoterami@users.noreply.github.com> Date: Wed, 8 Jan 2025 12:14:48 +0100 Subject: [PATCH 3/4] fix: allow requests for notification event details --- backend/pkg/api/handlers/middlewares.go | 2 +- backend/pkg/api/router.go | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/backend/pkg/api/handlers/middlewares.go b/backend/pkg/api/handlers/middlewares.go index f24ae39a7..1b0b1b069 100644 --- a/backend/pkg/api/handlers/middlewares.go +++ b/backend/pkg/api/handlers/middlewares.go @@ -156,7 +156,7 @@ func (h *HandlerService) VDBArchivedCheckMiddleware(next http.Handler) http.Hand return } if dashboard.IsArchived { - handleErr(w, r, newForbiddenErr("dashboard with id %v is archived", dashboardId)) + handleErr(w, r, newForbiddenErr("dashboard with id %s is archived", mux.Vars(r)["dashboard_id"])) return } next.ServeHTTP(w, r) diff --git a/backend/pkg/api/router.go b/backend/pkg/api/router.go index 918180976..1f1eacd50 100644 --- a/backend/pkg/api/router.go +++ b/backend/pkg/api/router.go @@ -353,7 +353,7 @@ func addNotificationRoutes(hs *handlers.HandlerService, publicRouter, internalRo publicDashboardNotificationSettingsRouter := publicNotificationRouter.NewRoute().Subrouter() internalDashboardNotificationSettingsRouter := internalNotificationRouter.NewRoute().Subrouter() - // TODO add adb auth and archivedCheck middleware to account dashboard endpoints once they are implemented + // TODO add adb auth middleware to account dashboard endpoints once they are implemented if !debug { publicDashboardNotificationSettingsRouter.Use(hs.VDBAuthMiddleware, hs.VDBArchivedCheckMiddleware) internalDashboardNotificationSettingsRouter.Use(hs.VDBAuthMiddleware, hs.VDBArchivedCheckMiddleware) @@ -361,10 +361,21 @@ func addNotificationRoutes(hs *handlers.HandlerService, publicRouter, internalRo dashboardSettingsEndpoints := []endpoint{ {http.MethodGet, "/validator-dashboards/{dashboard_id}/groups/{group_id}/epochs/{epoch}", hs.PublicGetUserNotificationsValidatorDashboard, hs.InternalGetUserNotificationsValidatorDashboard}, {http.MethodGet, "/account-dashboards/{dashboard_id}/groups/{group_id}/epochs/{epoch}", hs.PublicGetUserNotificationsAccountDashboard, hs.InternalGetUserNotificationsAccountDashboard}, + } + addEndpointsToRouters(dashboardSettingsEndpoints, publicDashboardNotificationSettingsRouter, internalDashboardNotificationSettingsRouter) + + publicActiveDashboardNotificationSettingsRouter := publicDashboardNotificationSettingsRouter.NewRoute().Subrouter() + internalActiveDashboardNotificationSettingsRouter := internalDashboardNotificationSettingsRouter.NewRoute().Subrouter() + // TODO add archivedCheck middleware to account dashboard endpoints once they are implemented + if !debug { + publicActiveDashboardNotificationSettingsRouter.Use(hs.VDBArchivedCheckMiddleware) + internalActiveDashboardNotificationSettingsRouter.Use(hs.VDBArchivedCheckMiddleware) + } + activeDashboardSettingsEndpoints := []endpoint{ {http.MethodPut, "/settings/validator-dashboards/{dashboard_id}/groups/{group_id}", hs.PublicPutUserNotificationSettingsValidatorDashboard, hs.InternalPutUserNotificationSettingsValidatorDashboard}, {http.MethodPut, "/settings/account-dashboards/{dashboard_id}/groups/{group_id}", hs.PublicPutUserNotificationSettingsAccountDashboard, hs.InternalPutUserNotificationSettingsAccountDashboard}, } - addEndpointsToRouters(dashboardSettingsEndpoints, publicDashboardNotificationSettingsRouter, internalDashboardNotificationSettingsRouter) + addEndpointsToRouters(activeDashboardSettingsEndpoints, publicActiveDashboardNotificationSettingsRouter, internalActiveDashboardNotificationSettingsRouter) } func addEndpointsToRouters(endpoints []endpoint, publicRouter *mux.Router, internalRouter *mux.Router) { From d39370d82a8d498c9fdc8c20727212b321175e0e Mon Sep 17 00:00:00 2001 From: remoterami <142154971+remoterami@users.noreply.github.com> Date: Thu, 9 Jan 2025 11:14:55 +0100 Subject: [PATCH 4/4] fix: disabled archived check for past notification details --- backend/pkg/api/router.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/pkg/api/router.go b/backend/pkg/api/router.go index 1f1eacd50..89fdb32eb 100644 --- a/backend/pkg/api/router.go +++ b/backend/pkg/api/router.go @@ -355,8 +355,8 @@ func addNotificationRoutes(hs *handlers.HandlerService, publicRouter, internalRo internalDashboardNotificationSettingsRouter := internalNotificationRouter.NewRoute().Subrouter() // TODO add adb auth middleware to account dashboard endpoints once they are implemented if !debug { - publicDashboardNotificationSettingsRouter.Use(hs.VDBAuthMiddleware, hs.VDBArchivedCheckMiddleware) - internalDashboardNotificationSettingsRouter.Use(hs.VDBAuthMiddleware, hs.VDBArchivedCheckMiddleware) + publicDashboardNotificationSettingsRouter.Use(hs.VDBAuthMiddleware) + internalDashboardNotificationSettingsRouter.Use(hs.VDBAuthMiddleware) } dashboardSettingsEndpoints := []endpoint{ {http.MethodGet, "/validator-dashboards/{dashboard_id}/groups/{group_id}/epochs/{epoch}", hs.PublicGetUserNotificationsValidatorDashboard, hs.InternalGetUserNotificationsValidatorDashboard},