From cde862f97f2bf6aad62f56034711d78480fa4b97 Mon Sep 17 00:00:00 2001 From: philipp Date: Thu, 23 Mar 2023 11:13:19 +0100 Subject: [PATCH] always use your own name for registrations; except if the user has the add_different_user permission --- db.sqlite | Bin 40960 -> 32768 bytes db.txt | 2 +- src/models/user.rs | 1 + src/rest/restreg.rs | 4 +-- src/rest/restuser.rs | 2 ++ templates/index.html.tera | 58 ++++++++++++++++++++++----------- templates/user/index.html.tera | 4 +++ 7 files changed, 49 insertions(+), 22 deletions(-) diff --git a/db.sqlite b/db.sqlite index 23949f0ca653b7884e520bed368989114c553b22..ccfb4fa73b5bea57fb28233f8813ca5a3b217b9c 100644 GIT binary patch delta 1313 zcmZXSO=uHA6vt;jlHKiQ_H|QZgjC#wHfx>b8LQ9PJoKJxS<9ApbKemiH0tzuJ_gxMxgAU&5$4`Pq%PLsq zQpujNE3*ZvJKwP8e8Ald?>rB*M%}7Y^y^zX&j{g`7G`-DM2#Og5Ft={op*Q4vXoZkS!V*=1zG=M^%*dxc)$yh0jSuh2s>skKmZy}t@$ zM%J%zQRX03#^(upc~6+;JYf%ux#(e;CMG#}*g)_LzQTLhsH!6`U_{{s6hWdW4onp1 zta4G|Xe>$Mg<_>NV_OQlw@%_Yd!nc??z$+A+$v9$r>2@*>L!9s_yRldn^50?vok5{ zyv#+IJqousrv$c%i|p^l@CUK5jbIyoRMqPrAuTdoh;jd?$dVbo2SJiTlBh#* z)zrz>`Fcs!Z9x}Vo7wA189Aee{!bCc5d4I<@D#@2GrWXVm?kaG!$OOnG#DRVNYY@n uLE{w&6CV!O_;wqoG%}*0i5P!R`AG@X7p{cki249zet+r;jACz)2*z`a^Xb=;Khs{DaxJfCsEe1^x zigGo;o;-Q+;KfAffpFtLF!5kKa8MEtoQwyF@#Mbpxy88I*?lwbH@}(po6RmSv&*~e zT8BS^5b{`da=F$c@#_(E`(aFg--vHXAqc{@FXH-z~;vrT2*L+7Nb&fdI3z*uYsmShvHx0y|EJOH2pMufBHk z2XITyT7Yqj(I``!Y#=MT_PC(V8Z%|BYRnZY%|2^CcJsC+0g;~Q<%*Rnk*dB>B_pHb zWaPo{FgYiSC4yEe6%4&IuWD6^7{#hSqnFRH;XABLydR})rkiW1N^=BTL*?jT1U3Gxs=7)Q&bLlK?_%ws-grEjIss9I zEzqLG;LIsgpQP@nC@8UBRf zAGNnyH=w8_SS8gj%iwYbImFX5N9A}_NrTfK=mUp6kOFKE^a5)SB(1af&yyy$NF64X zw9AKs%xS4Ur_D_{Y;G^Mxk*;Q!Lv3KbbKuABlrpXb${*?tmhmz1=fW+5XWT-+I-&7 z1ctgipL=8!j8ci}&B6hK1Ne2E(h_XJ9n3MD_27;ZETw1Q5W(RQa_#D6j=^mVoi9r_ zQ7b~Q37d7l{0=5Yc_hY950+>sd*%`))}M^^D`_jOn@8vz@**hJ`14TqFYv`G{t>!E SNIX;Rh@7>k{OH`=5`O`7u`3w> diff --git a/db.txt b/db.txt index 0e49bad..5e4e1cc 100644 --- a/db.txt +++ b/db.txt @@ -1,4 +1,4 @@ CREATE TABLE IF NOT EXISTS "day" ( "day" text NOT NULL PRIMARY KEY, "planned_amount_cox" integer NOT NULL DEFAULT 0, "planned_starting_time" text, "open_registration" boolean NOT NULL DEFAULT TRUE ); -CREATE TABLE IF NOT EXISTS "user" ( "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" text NOT NULL UNIQUE, "pw" text, "is_cox" boolean NOT NULL DEFAULT FALSE, "is_admin" boolean NOT NULL DEFAULT FALSE ); +CREATE TABLE IF NOT EXISTS "user" ( "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" text NOT NULL UNIQUE, "pw" text, "is_cox" boolean NOT NULL DEFAULT FALSE, "add_different_user" boolean NOT NULL DEFAULT FALSE, "is_admin" boolean NOT NULL DEFAULT FALSE ); CREATE TABLE IF NOT EXISTS "trip" ( "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "day" text NOT NULL, "user_id" integer NOT NULL, "cox_id" integer, "begin" text, "created" text NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY ("day") REFERENCES "day" ("day"), FOREIGN KEY ("user_id") REFERENCES "user" ("id"), FOREIGN KEY ("cox_id") REFERENCES "trip" ("id") ); create unique index UNIQ_trip on trip("day", "user_id", IFNULL(cox_id, ''), IFNULL(begin,'')); diff --git a/src/models/user.rs b/src/models/user.rs index 52a30ed..b11a8ee 100644 --- a/src/models/user.rs +++ b/src/models/user.rs @@ -16,6 +16,7 @@ pub struct Model { pub name: String, pub pw: Option, pub is_cox: bool, + pub add_different_user: bool, pub is_admin: bool, } diff --git a/src/rest/restreg.rs b/src/rest/restreg.rs index d6c686b..579b9aa 100644 --- a/src/rest/restreg.rs +++ b/src/rest/restreg.rs @@ -38,6 +38,8 @@ async fn register( ); } + let user = user::Model::find_or_create_user(®ister.name, db.inner()).await; + if let Some(cox_id) = register.cox_id { let trip = trip::Entity::find_by_id(cox_id) .one(db.inner()) @@ -57,8 +59,6 @@ async fn register( } } - let user = user::Model::find_or_create_user(®ister.name, db.inner()).await; - let day = format!("{}", day.day.format("%Y-%m-%d")); let trip = trip::ActiveModel { day: Set(day.clone()), diff --git a/src/rest/restuser.rs b/src/rest/restuser.rs index 6c45829..2121bd2 100644 --- a/src/rest/restuser.rs +++ b/src/rest/restuser.rs @@ -16,6 +16,7 @@ async fn index(db: &State, user: user::AdminUser) -> Templat struct UserEditForm { pw: Option, is_cox: bool, + add_different_user: bool, is_admin: bool, } @@ -30,6 +31,7 @@ async fn update( id: Set(id), is_cox: Set(data.is_cox), is_admin: Set(data.is_admin), + add_different_user: Set(data.add_different_user), ..Default::default() }; if let Some(pw) = &data.pw { diff --git a/templates/index.html.tera b/templates/index.html.tera index ff71aa9..81dcd37 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -76,9 +76,11 @@ {% set cox_left = day.planned_amount_cox - amount_cox %}
Es {{ cox_left | pluralize(singular="wird", plural="werden")}} noch {{ cox_left }} Steuerperson{{ cox_left | pluralize(plural="en")}} gesucht!
{% endif %} + {% set_global user_registered = false %} Abfahrtszeit: {{ day.planned_starting_time }} Uhr
{{ default_trips | length }} angemeldete Person{{ default_trips | length | pluralize(plural="en") }}: {{ cox | length }} Steuerperson{{ cox | length | pluralize(plural="en") }} ({% for c in cox %}{{ c.user.name }} {% if c.user.name == user.name %} + {% set_global user_registered = true %}
@@ -91,6 +93,7 @@
  • {{ r.user.name }} (angemeldet seit {{ r.trip.created | date(format="%d.%m. %H:%M", timezone="Europe/Vienna") }}) {% if r.user.name == user.name %} + {% set_global user_registered = true %} @@ -103,31 +106,40 @@ {% if day.open_registration or user.is_cox %} -
    - + - - - -
    -
    - - -
    -
    - -
    -
    - -
    + {% if not user_registered or user.add_different_user %} +
    + + +
    + + +
    +
    + {% if user.add_different_user %} + + + {% else %} + + {% endif %} +
    +
    + +
    +
    +
    +
    + {% else %} + {% endif %} {% else %} Anmeldung an diesem Tag leider nicht möglich (zB bei USI Kursen) {% endif %} {% endif %} {% for trip in indep_trips %} + {% set_global user_registered = false %} {% if trip.trip.begin %} {{trip.user.name}} @ {{trip.trip.begin}} - {% set rowers = indep_trips | filter(attribute="trip.cox_id", value=trip.trip.id) %} + {% set rowers = indep_trips | filter(attribute="trip.cox_id", value=trip.trip.id) | sort(attribute="trip.created")%} {% if trip.user.name == user.name and rowers | length == 0 %} + {% set_global user_registered = true %}
    @@ -140,6 +152,7 @@
  • {{ r.user.name }} (angemeldet seit {{ r.trip.created | date(format="%d.%m. %H:%M", timezone="Europe/Vienna") }}) {% if r.user.name == user.name %} + {% set_global user_registered = true %} @@ -150,6 +163,7 @@
  • {% endfor %} + {% if not user_registered or user.add_different_user %}
    + @@ -158,8 +172,13 @@
    - - + + {% if user.add_different_user %} + + + {% else %} + + {% endif %}
    @@ -167,6 +186,7 @@
    + {% endif %} {% endif %} {% endfor %} diff --git a/templates/user/index.html.tera b/templates/user/index.html.tera index 740621d..39ec0a0 100644 --- a/templates/user/index.html.tera +++ b/templates/user/index.html.tera @@ -6,6 +6,7 @@ Name Pw + Add Different User Cox Admin Action @@ -23,6 +24,9 @@ {% endif %} + +