Skip to content

Commit

Permalink
No-show page permissions filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
Celeo committed Nov 18, 2024
1 parent 59da79f commit 194e8cc
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
32 changes: 29 additions & 3 deletions vzdv-site/src/endpoints/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,9 +983,34 @@ async fn page_no_show_list(
{
return Ok(redirect.into_response());
}
let no_shows: Vec<NoShow> = 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<NoShow> = 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<Controller> = sqlx::query_as(sql::GET_ALL_CONTROLLERS)
.fetch_all(&state.db)
.await?;
Expand Down Expand Up @@ -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())
Expand Down
13 changes: 9 additions & 4 deletions vzdv-site/templates/admin/no_show_list.jinja
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{% extends "_layout.jinja" %}

{% block title %}No show list | {{ super() }}{% endblock %}
{% block title %}No-show list | {{ super() }}{% endblock %}

{% block body %}

<h2 class="pb-3">No show list</h2>
<h2 class="pb-3">No-show list</h2>

<p>
This page lists no-show events from students and event controllers to maintain a record for SOP and facility policy adherence.
Expand All @@ -31,8 +31,12 @@
<label for="entry_type">Type (event or training)</label>
<select name="entry_type" id="entry_type" class="form-control" required>
<option selected disabled>Type</option>
<option value="event">Event</option>
<option value="training">Training</option>
{% if user_info.is_event_staff %}
<option value="event">Event</option>
{% endif %}
{% if user_info.is_training_staff %}
<option value="training">Training</option>
{% endif %}
</select>
</div>
</div>
Expand All @@ -51,6 +55,7 @@

<hr>

<p class="mb-0">Showing: {{ filtering }} no-shows</p>
<table class="table table-striped table-hover sortable">
<thead>
<tr>
Expand Down
1 change: 1 addition & 0 deletions vzdv-site/templates/changelog.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<li>Restore "solo" option in controller certification dropdown for training staff</li>
<li>"Solo" controller certifications are reset to "training" if a solo cert expires</li>
<li>New page for training event and training no-shows</li>
<li>No-show page is now permissions filtered to differentiate between event and training staff</li>
</ul>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion vzdv/src/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub struct SoloCert {
pub expiration_date: DateTime<Utc>,
}

#[derive(Debug, FromRow, Serialize)]
#[derive(Debug, Clone, FromRow, Serialize)]
pub struct NoShow {
pub id: u32,
pub cid: u32,
Expand Down

0 comments on commit 194e8cc

Please sign in to comment.