Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(BEDS-1100) API: Incorporate dashboard archival status into notification endpoints #1233

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/pkg/api/data_access/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion backend/pkg/api/handlers/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
LuccaBitfly marked this conversation as resolved.
Show resolved Hide resolved
return
}
next.ServeHTTP(w, r)
Expand Down
13 changes: 12 additions & 1 deletion backend/pkg/api/router.go
LuccaBitfly marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions backend/pkg/api/types/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
1 change: 1 addition & 0 deletions frontend/types/api/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export interface NotificationSettingsAccountDashboard {
export type PutUserNotificationSettingsAccountDashboardResponse = ApiDataResponse<NotificationSettingsAccountDashboard>;
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 */;
Expand Down
Loading