From ba98c3be841b0188f970753e18f16000af49ef03 Mon Sep 17 00:00:00 2001 From: trotFunky Date: Fri, 26 Jul 2024 17:55:39 +0100 Subject: [PATCH 1/5] index: Remove the form if all votes were cast Currently, if all votes are cast and the week is locked the selections are disabled but the form and button still exist and might cause confusion. Remove them if all votes are cast and we are not on the last week anymore. --- templates/index.html.tera | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/templates/index.html.tera b/templates/index.html.tera index c2f3afa..d6edfa3 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -36,6 +36,9 @@ {% set next_arrow_chara = '⟹' %} {% endif %} +{# Remove the form if all votes are locked, to reduce confusion. #} +{% set lock_truth_form = user.votes | length + 1 == truths | length and week_data.is_last_week != true %} +

{{ title }}

@@ -76,7 +79,7 @@ {% endif %}
- {% if user.logged_in == true and user.is_admin == false %} + {% if user.logged_in == true and user.is_admin == false and not lock_truth_form %}
{% endif %} @@ -101,7 +104,7 @@ {% endif %} {% endfor %} - {% if user.logged_in == true and user.is_admin == false %} + {% if user.logged_in == true and user.is_admin == false and not lock_truth_form %}
+
{% else %}
From 0c162d3b423f68579f803df1d456e126940612b6 Mon Sep 17 00:00:00 2001 From: trotFunky Date: Fri, 26 Jul 2024 23:46:35 +0100 Subject: [PATCH 5/5] vote: Always display graph for the admin --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/vote.rs | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index df623d8..65b8c9d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -578,7 +578,7 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" [[package]] name = "fabula_votes_server" -version = "1.2.1" +version = "1.3.0" dependencies = [ "argon2", "blake2", diff --git a/Cargo.toml b/Cargo.toml index 2ec545f..d20f8c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "fabula_votes_server" license = "MPL-2.0" readme = "README.md" authors = ["trotFunky"] -version = "1.2.1" +version = "1.3.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/vote.rs b/src/vote.rs index ca78136..7bd400f 100644 --- a/src/vote.rs +++ b/src/vote.rs @@ -96,7 +96,8 @@ pub struct VoteData { // TODO: Cache vote count ? Maintain in state ? #[get("//votes", format = "application/json")] -pub async fn fetch_vote_data(week: u8, mut db: Connection) -> Option> { +pub async fn fetch_vote_data(week: u8, mut db: Connection, cookies: &CookieJar<'_>) -> Option> { + let user = auth::get_user(week, &mut db, cookies).await; let raw_votes: Vec = sqlx::query_as(" SELECT Players.name as votes_for, Truths.number as truth_number, count(*) as votes FROM Votes JOIN Players ON Votes.voted_id == Players.id @@ -124,11 +125,11 @@ pub async fn fetch_vote_data(week: u8, mut db: Connection) -> Opti let vote_count = raw_votes.iter().fold(0, |count, votes| {count + votes.votes}); // Only show the graph if we have all the votes and this is not the last week. - if max_vote_count == 0 + if !user.is_admin && (max_vote_count == 0 || vote_count < max_vote_count || week == sqlx::query_scalar("SELECT number from Weeks WHERE is_last_week == 1;") .fetch_optional(&mut **db) - .await.unwrap_or(Some(0)).unwrap_or(0) { + .await.unwrap_or(Some(0)).unwrap_or(0)) { return None; }