From 194e8cc32e084266a9d049ed6b0a15a511a8f2fd Mon Sep 17 00:00:00 2001 From: Celeo Date: Sun, 17 Nov 2024 20:33:59 -0800 Subject: [PATCH] No-show page permissions filtering --- vzdv-site/src/endpoints/admin.rs | 32 ++++++++++++++++++-- vzdv-site/templates/admin/no_show_list.jinja | 13 +++++--- vzdv-site/templates/changelog.jinja | 1 + vzdv/src/sql.rs | 2 +- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/vzdv-site/src/endpoints/admin.rs b/vzdv-site/src/endpoints/admin.rs index b4a9015..7ba79ce 100644 --- a/vzdv-site/src/endpoints/admin.rs +++ b/vzdv-site/src/endpoints/admin.rs @@ -983,9 +983,34 @@ async fn page_no_show_list( { return Ok(redirect.into_response()); } - let no_shows: Vec = sqlx::query_as(sql::GET_ALL_NO_SHOW) - .fetch_all(&state.db) - .await?; + let user_info = user_info.unwrap(); + + let (filtering, no_shows) = { + let no_shows: Vec = sqlx::query_as(sql::GET_ALL_NO_SHOW) + .fetch_all(&state.db) + .await?; + + if user_info.is_admin || (user_info.is_event_staff && user_info.is_training_staff) { + ("all", no_shows) + } else { + let filter = if user_info.is_event_staff { + "event" + } else if user_info.is_training_staff { + "training" + } else { + "none" + }; + ( + filter, + no_shows + .iter() + .filter(|ns| ns.entry_type == filter) + .map(|ns| ns.to_owned()) + .collect(), + ) + } + }; + let all_controllers: Vec = sqlx::query_as(sql::GET_ALL_CONTROLLERS) .fetch_all(&state.db) .await?; @@ -1022,6 +1047,7 @@ async fn page_no_show_list( flashed_messages, all_controllers, cid_name_name, + filtering, no_shows })?; Ok(Html(rendered).into_response()) diff --git a/vzdv-site/templates/admin/no_show_list.jinja b/vzdv-site/templates/admin/no_show_list.jinja index 92163a2..87287ab 100644 --- a/vzdv-site/templates/admin/no_show_list.jinja +++ b/vzdv-site/templates/admin/no_show_list.jinja @@ -1,10 +1,10 @@ {% extends "_layout.jinja" %} -{% block title %}No show list | {{ super() }}{% endblock %} +{% block title %}No-show list | {{ super() }}{% endblock %} {% block body %} -

No show list

+

No-show list

This page lists no-show events from students and event controllers to maintain a record for SOP and facility policy adherence. @@ -31,8 +31,12 @@ @@ -51,6 +55,7 @@


+

Showing: {{ filtering }} no-shows

diff --git a/vzdv-site/templates/changelog.jinja b/vzdv-site/templates/changelog.jinja index dcbeadc..d255e1a 100644 --- a/vzdv-site/templates/changelog.jinja +++ b/vzdv-site/templates/changelog.jinja @@ -24,6 +24,7 @@
  • Restore "solo" option in controller certification dropdown for training staff
  • "Solo" controller certifications are reset to "training" if a solo cert expires
  • New page for training event and training no-shows
  • +
  • No-show page is now permissions filtered to differentiate between event and training staff
  • diff --git a/vzdv/src/sql.rs b/vzdv/src/sql.rs index 0c14a9a..42753ad 100644 --- a/vzdv/src/sql.rs +++ b/vzdv/src/sql.rs @@ -156,7 +156,7 @@ pub struct SoloCert { pub expiration_date: DateTime, } -#[derive(Debug, FromRow, Serialize)] +#[derive(Debug, Clone, FromRow, Serialize)] pub struct NoShow { pub id: u32, pub cid: u32,