From 09e11dbb2b0df9c573f5ecf4758e809c5dbfc7fa Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 9 Mar 2024 18:16:32 +0100 Subject: [PATCH 01/21] show two rowes of boats for the 3 most left 'aisles' --- src/model/boathouse.rs | 46 ++++++++++++++++++++++++----- templates/board/boathouse.html.tera | 23 +++++++++++++-- 2 files changed, 59 insertions(+), 10 deletions(-) diff --git a/src/model/boathouse.rs b/src/model/boathouse.rs index a3ae022..0e96caf 100644 --- a/src/model/boathouse.rs +++ b/src/model/boathouse.rs @@ -17,22 +17,52 @@ pub struct Boathouse { } impl Boathouse { - pub async fn get(db: &SqlitePool) -> HashMap<&str, HashMap<&str, [Option<(i64, Boat)>; 4]>> { - let mut ret: HashMap<&str, HashMap<&str, [Option<(i64, Boat)>; 4]>> = HashMap::new(); + pub async fn get(db: &SqlitePool) -> HashMap<&str, HashMap<&str, [Option<(i64, Boat)>; 12]>> { + let mut ret: HashMap<&str, HashMap<&str, [Option<(i64, Boat)>; 12]>> = HashMap::new(); let mut mountain = HashMap::new(); - mountain.insert("mountain", [None, None, None, None]); - mountain.insert("water", [None, None, None, None]); + mountain.insert( + "mountain", + [ + None, None, None, None, None, None, None, None, None, None, None, None, + ], + ); + mountain.insert( + "water", + [ + None, None, None, None, None, None, None, None, None, None, None, None, + ], + ); ret.insert("mountain-aisle", mountain); let mut middle = HashMap::new(); - middle.insert("mountain", [None, None, None, None]); - middle.insert("water", [None, None, None, None]); + middle.insert( + "mountain", + [ + None, None, None, None, None, None, None, None, None, None, None, None, + ], + ); + middle.insert( + "water", + [ + None, None, None, None, None, None, None, None, None, None, None, None, + ], + ); ret.insert("middle-aisle", middle); let mut water = HashMap::new(); - water.insert("mountain", [None, None, None, None]); - water.insert("water", [None, None, None, None]); + water.insert( + "mountain", + [ + None, None, None, None, None, None, None, None, None, None, None, None, + ], + ); + water.insert( + "water", + [ + None, None, None, None, None, None, None, None, None, None, None, None, + ], + ); ret.insert("water-aisle", water); let boathouses = sqlx::query_as!( diff --git a/templates/board/boathouse.html.tera b/templates/board/boathouse.html.tera index c8e60b0..4edc2b6 100644 --- a/templates/board/boathouse.html.tera +++ b/templates/board/boathouse.html.tera @@ -7,7 +7,8 @@ {% set aisle = aisle_name ~ "-aisle" %} {% set place = boathouse[aisle][side_name] %} {% if place[level] %} - {{ place[level].1.name }} X + {{ place[level].1.name }} X {% elif boats | length > 0 %}
Kein Boot @@ -33,11 +34,29 @@ {{ self::show_place(aisle_name = aisle_name, side_name = side_name, level = 1) }} {{ self::show_place(aisle_name = aisle_name, side_name = side_name, level = 2) }} {{ self::show_place(aisle_name = aisle_name, side_name = side_name, level = 3) }} + {{ self::show_place(aisle_name = aisle_name, side_name = side_name, level = 4) }} + {{ self::show_place(aisle_name = aisle_name, side_name = side_name, level = 5) }} + {% set show_additional = false %} + {% if aisle_name == "mountain" %} + {% set show_additional = true %} + {% elif aisle_name == "middle" and side_name == "mountain" %} + {% set show_additional = true %} + {% endif %} + {% if show_additional %} +
+ {{ self::show_place(aisle_name = aisle_name, side_name = side_name, level = 6) }} + {{ self::show_place(aisle_name = aisle_name, side_name = side_name, level = 7) }} + {{ self::show_place(aisle_name = aisle_name, side_name = side_name, level = 8) }} + {{ self::show_place(aisle_name = aisle_name, side_name = side_name, level = 9) }} + {{ self::show_place(aisle_name = aisle_name, side_name = side_name, level = 10) }} + {{ self::show_place(aisle_name = aisle_name, side_name = side_name, level = 11) }} + {% endif %} {% endmacro show_side %} {% macro show_aisle(name, last=false) %} -
+
{{ self::show_side(aisle_name = name, side_name = "mountain") }} {{ self::show_side(aisle_name = name, side_name = "water") }}
From f70766e817abd1d2706f92e7adf4c66eaeeebb5e Mon Sep 17 00:00:00 2001 From: philipp Date: Fri, 15 Mar 2024 09:10:56 +0100 Subject: [PATCH 02/21] move to hetzner server --- .gitea/workflows/action.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.gitea/workflows/action.yml b/.gitea/workflows/action.yml index 07996d0..0b6fce8 100644 --- a/.gitea/workflows/action.yml +++ b/.gitea/workflows/action.yml @@ -80,15 +80,15 @@ jobs: echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa - scp target/$CARGO_TARGET/release/rot $SSH_USER@$SSH_HOST:/home/philipp/rowing-staging/rot-updating + scp target/$CARGO_TARGET/release/rot $SSH_USER@$SSH_HOST:/home/rowing-staging/rot-updating - scp staging-diff.sql $SSH_USER@$SSH_HOST:/home/philipp/rowing-staging/ - scp -r static $SSH_USER@$SSH_HOST:/home/philipp/rowing-staging/ - scp -r templates $SSH_USER@$SSH_HOST:/home/philipp/rowing-staging/ - scp -r svelte $SSH_USER@$SSH_HOST:/home/philipp/rowing-staging/ + scp staging-diff.sql $SSH_USER@$SSH_HOST:/home/rowing-staging/ + scp -r static $SSH_USER@$SSH_HOST:/home/rowing-staging/ + scp -r templates $SSH_USER@$SSH_HOST:/home/rowing-staging/ + scp -r svelte $SSH_USER@$SSH_HOST:/home/rowing-staging/ ssh $SSH_USER@$SSH_HOST 'sudo systemctl stop rotstaging' - ssh $SSH_USER@$SSH_HOST 'rm /home/philipp/rowing-staging/db.sqlite && cp /home/philipp/rowing/db.sqlite /home/philipp/rowing-staging/db.sqlite && mkdir -p /home/philipp/rowing-staging/svelte/build && mkdir -p /home/philipp/rowing-staging/data-ergo/thirty && mkdir -p /home/philipp/rowing-staging/data-ergo/dozen && sqlite3 /home/philipp/rowing-staging/db.sqlite < /home/philipp/rowing-staging/staging-diff.sql' - ssh $SSH_USER@$SSH_HOST 'mv /home/philipp/rowing-staging/rot-updating /home/philipp/rowing-staging/rot' + ssh $SSH_USER@$SSH_HOST 'rm /home/rowing-staging/db.sqlite && cp /home/rowing/db.sqlite /home/rowing-staging/db.sqlite && mkdir -p /home/rowing-staging/svelte/build && mkdir -p /home/rowing-staging/data-ergo/thirty && mkdir -p /home/rowing-staging/data-ergo/dozen && sqlite3 /home/rowing-staging/db.sqlite < /home/rowing-staging/staging-diff.sql' + ssh $SSH_USER@$SSH_HOST 'mv /home/rowing-staging/rot-updating /home/rowing-staging/rot' ssh $SSH_USER@$SSH_HOST 'sudo systemctl start rotstaging' env: SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} @@ -132,13 +132,13 @@ jobs: echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa - scp target/$CARGO_TARGET/release/rot $SSH_USER@$SSH_HOST:/home/philipp/rowing/rot-updating - scp -r static $SSH_USER@$SSH_HOST:/home/philipp/rowing/ - scp -r templates $SSH_USER@$SSH_HOST:/home/philipp/rowing/ - scp -r svelte $SSH_USER@$SSH_HOST:/home/philipp/rowing/ - ssh $SSH_USER@$SSH_HOST 'mkdir -p /home/philipp/rowing/svelte/build && mkdir -p /home/philipp/rowing/data-ergo/thirty && mkdir -p /home/philipp/rowing/data-ergo/dozen' + scp target/$CARGO_TARGET/release/rot $SSH_USER@$SSH_HOST:/home/rowing/rot-updating + scp -r static $SSH_USER@$SSH_HOST:/home/rowing/ + scp -r templates $SSH_USER@$SSH_HOST:/home/rowing/ + scp -r svelte $SSH_USER@$SSH_HOST:/home/rowing/ + ssh $SSH_USER@$SSH_HOST 'mkdir -p /home/rowing/svelte/build && mkdir -p /home/rowing/data-ergo/thirty && mkdir -p /home/rowing/data-ergo/dozen' ssh $SSH_USER@$SSH_HOST 'sudo systemctl stop rot' - ssh $SSH_USER@$SSH_HOST 'mv /home/philipp/rowing/rot-updating /home/philipp/rowing/rot' + ssh $SSH_USER@$SSH_HOST 'mv /home/rowing/rot-updating /home/rowing/rot' ssh $SSH_USER@$SSH_HOST 'sudo systemctl start rot' env: SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} From 5e24f9ce04671cd871695d1e06af44d7ad5af35f Mon Sep 17 00:00:00 2001 From: philipp Date: Fri, 15 Mar 2024 09:54:36 +0100 Subject: [PATCH 03/21] update docs --- README.md | 22 ++++++++++++++++++++++ rot.service | 7 +++++-- rotstaging.service | 6 ++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4e61b4d..de2636d 100644 --- a/README.md +++ b/README.md @@ -22,3 +22,25 @@ - Rust: `cargo check` - Tera files: `djlint **.html.tera --profile=jinja --reformat` - Typescript: `prettier -w *.ts` + +# Dependencies +- `sqlite3` +- `rust` + +# Nginx config + +``` +server { + server_name staging.rudernlinz.at; + location / { + proxy_pass http://localhost:7999/; # The / is important! + } +} + +server { + server_name app.rudernlinz.at; + location / { + proxy_pass http://localhost:8001/; # The / is important! + } +} +``` diff --git a/rot.service b/rot.service index b0f3632..bdb2d95 100644 --- a/rot.service +++ b/rot.service @@ -4,12 +4,15 @@ Description=Rot [Service] User=root Group=root -WorkingDirectory=/home/philipp/rowing +WorkingDirectory=/home/rowing Environment="ROCKET_ENV=prod" Environment="ROCKET_ADDRESS=127.0.0.1" Environment="ROCKET_PORT=8001" Environment="RUST_LOG=info" -ExecStart=/home/k004373/rowing/rot +ExecStart=/home/rowing/rot +Restart=always +RestartSec=10 + [Install] WantedBy=multi-user.target diff --git a/rotstaging.service b/rotstaging.service index ed6ee20..5a76e86 100644 --- a/rotstaging.service +++ b/rotstaging.service @@ -4,12 +4,14 @@ Description=Rot Staging [Service] User=root Group=root -WorkingDirectory=/home/philipp/rowing-staging +WorkingDirectory=/home/rowing-staging Environment="ROCKET_ENV=prod" Environment="ROCKET_ADDRESS=127.0.0.1" Environment="ROCKET_PORT=7999" Environment="ROCKET_LOG=info" -ExecStart=/home/philipp/rowing-staging/rot +ExecStart=/home/rowing-staging/rot +Restart=always +RestartSec=10 [Install] WantedBy=multi-user.target From 413d08f538b5b4cbf7acc4f6f7da5a8e49ea5c0d Mon Sep 17 00:00:00 2001 From: philipp Date: Fri, 15 Mar 2024 10:52:13 +0100 Subject: [PATCH 04/21] show which schnupperant already paid --- templates/admin/schnupper/index.html.tera | 7 ++++++- templates/board/boathouse.html.tera | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/templates/admin/schnupper/index.html.tera b/templates/admin/schnupper/index.html.tera index b2520b8..1c3ddc1 100644 --- a/templates/admin/schnupper/index.html.tera +++ b/templates/admin/schnupper/index.html.tera @@ -9,7 +9,12 @@

Angemeldete Personen: {{ schnupperanten | length }}

    - {% for user in schnupperanten %}
  1. {{ user.name }} ({{ user.mail }} | {{ user.notes }})
  2. {% endfor %} + {% for user in schnupperanten %} +
  3. + {{ user.name }} ({{ user.mail }} | {{ user.notes }}) +
  4. + {% endfor %}
diff --git a/templates/board/boathouse.html.tera b/templates/board/boathouse.html.tera index 4edc2b6..67bcad2 100644 --- a/templates/board/boathouse.html.tera +++ b/templates/board/boathouse.html.tera @@ -43,7 +43,7 @@ {% set show_additional = true %} {% endif %} {% if show_additional %} -
+
{{ self::show_place(aisle_name = aisle_name, side_name = side_name, level = 6) }} {{ self::show_place(aisle_name = aisle_name, side_name = side_name, level = 7) }} {{ self::show_place(aisle_name = aisle_name, side_name = side_name, level = 8) }} From c9d10f81a9d6d1ca9ac10a1e212c164fcef589b2 Mon Sep 17 00:00:00 2001 From: philipp Date: Fri, 15 Mar 2024 11:41:03 +0100 Subject: [PATCH 05/21] add mail for requesting fee --- src/model/mail.rs | 113 +++++++++++++++++++++++++++++++++++++++++ src/model/user.rs | 5 +- src/tera/admin/mail.rs | 12 ++++- 3 files changed, 128 insertions(+), 2 deletions(-) diff --git a/src/model/mail.rs b/src/model/mail.rs index e52866e..f7c9325 100644 --- a/src/model/mail.rs +++ b/src/model/mail.rs @@ -182,4 +182,117 @@ Der Vorstand } } } + + pub async fn fees_final(db: &SqlitePool, smtp_pw: String) { + let users = User::all_payer_groups(db).await; + for user in users { + if let Some(fee) = user.fee(db).await { + if !fee.paid { + let mut is_family = false; + let mut send_to = String::new(); + match Family::find_by_opt_id(db, user.family_id).await { + Some(family) => { + is_family = true; + for member in family.members(db).await { + if let Some(mail) = member.mail { + send_to.push_str(&format!("{mail},")) + } + } + } + None => { + if let Some(mail) = &user.mail { + send_to.push_str(mail) + } + } + } + + let fees = user.fee(db).await; + if let Some(fees) = fees { + let mut content = format!( + "Liebes Vereinsmitglied, \n\n\ +wir möchten darauf hinweisen, dass wir deinen Mitgliedsbeitrag für das laufende Jahr bislang nicht verbuchen konnten. Es besteht die Möglichkeit, dass es sich hierbei um ein Versehen unsererseits handelt. Solltest du den Betrag bereits überwiesen haben, bitte kurz auf diese E-Mail antworten, damit wir es richtigstellen können. + +Falls die Zahlung noch nicht erfolgt ist, bitten wir um umgehende Überweisung des ausstehenden Betrags, spätestens jedoch bis zum 31. März, auf unser Bankkonto.\n\n\ +Dein Vereintsbeitrag für das aktuelle Jahr beträgt {}€", + fees.sum_in_cents / 100, + ); + + if fees.parts.len() == 1 { + content.push_str(&format!(" ({}).\n", fees.parts[0].0)) + } else { + content + .push_str(". Dieser setzt sich aus folgenden Teilen zusammen: \n"); + for (desc, fee_in_cents) in fees.parts { + content.push_str(&format!("- {}: {}€\n", desc, fee_in_cents / 100)) + } + } + if is_family { + content.push_str(&format!( + "Dieser gilt für die gesamte Familie ({}).\n", + fees.name + )) + } + content.push_str("\n\ +Gemäß § 7 Abs. 3 lit. c unseres Status behalten wir uns vor, bei ausbleibender Zahlung die Mitgliedschaft zu beenden. Dies möchten wir vermeiden und hoffen auf deine Unterstützung.\n\n\ + +Bei Fragen oder Problemen stehen wir gerne zur Verfügung. + +Bankverbindung: IBAN: AT13 1200 0804 1300 1200 (Unter https://app.rudernlinz.at/planned findest du einen QR Code, den du mit deiner Bankapp scannen kannst um alle Eingaben bereits ausgefüllt zu haben.) + +Mit freundlichen Grüßen,\n\ +Der Vorstand"); + let mut email = Message::builder() + .from( + "ASKÖ Ruderverein Donau Linz " + .parse() + .unwrap(), + ) + .reply_to( + "ASKÖ Ruderverein Donau Linz " + .parse() + .unwrap(), + ) + .to("ASKÖ Ruderverein Donau Linz " + .parse() + .unwrap()); + let splitted = send_to.split(','); + let mut send_mail = false; + for single_rec in splitted { + let single_rec = single_rec.trim(); + match single_rec.parse() { + Ok(val) => { + email = email.bcc(val); + send_mail = true; + } + Err(_) => { + println!("Error in mail: {single_rec}"); + } + } + } + + if send_mail { + let email = email + .subject("Mahnung Vereinsgebühren | ASKÖ Ruderverein Donau Linz") + .header(ContentType::TEXT_PLAIN) + .body(content) + .unwrap(); + + let creds = Credentials::new( + "no-reply@rudernlinz.at".to_owned(), + smtp_pw.clone(), + ); + + let mailer = SmtpTransport::relay("mail.your-server.de") + .unwrap() + .credentials(creds) + .build(); + + // Send the email + mailer.send(&email).unwrap(); + } + } + } + } + } + } } diff --git a/src/model/user.rs b/src/model/user.rs index 11f4af4..a4e662f 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -25,7 +25,7 @@ const REGULAR: i32 = 22000; const UNTERSTUETZEND: i32 = 2500; const FOERDERND: i32 = 8500; -#[derive(FromRow, Debug, Serialize, Deserialize)] +#[derive(FromRow, Debug, Serialize, Deserialize, Clone)] pub struct User { pub id: i64, pub name: String, @@ -106,6 +106,7 @@ pub struct Fee { pub name: String, pub user_ids: String, pub paid: bool, + pub users: Vec, } impl Default for Fee { @@ -121,6 +122,7 @@ impl Fee { name: "".into(), parts: Vec::new(), user_ids: "".into(), + users: Vec::new(), paid: false, } } @@ -139,6 +141,7 @@ impl Fee { self.name.push_str(&user.name); self.user_ids.push_str(&format!("user_ids[]={}", user.id)); + self.users.push(user.clone()); } pub fn paid(&mut self) { diff --git a/src/tera/admin/mail.rs b/src/tera/admin/mail.rs index fee06ab..d1a6263 100644 --- a/src/tera/admin/mail.rs +++ b/src/tera/admin/mail.rs @@ -39,6 +39,16 @@ async fn fee(db: &State, _admin: AdminUser, config: &State) "SUCC" } +#[get("/mail/fee-final")] +async fn fee_final( + db: &State, + _admin: AdminUser, + config: &State, +) -> &'static str { + Mail::fees_final(db, config.smtp_pw.clone()).await; + "SUCC" +} + #[derive(FromForm, Debug)] pub struct MailToSend<'a> { pub(crate) role_id: i32, @@ -63,7 +73,7 @@ async fn update( } pub fn routes() -> Vec { - routes![index, update, fee] + routes![index, update, fee, fee_final] } #[cfg(test)] From 2ab2472e66ed093c4d42b554af63d2b1d7ebe2a3 Mon Sep 17 00:00:00 2001 From: philipp Date: Fri, 15 Mar 2024 11:49:27 +0100 Subject: [PATCH 06/21] fix typo --- src/model/mail.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/model/mail.rs b/src/model/mail.rs index f7c9325..41de809 100644 --- a/src/model/mail.rs +++ b/src/model/mail.rs @@ -213,7 +213,7 @@ Der Vorstand wir möchten darauf hinweisen, dass wir deinen Mitgliedsbeitrag für das laufende Jahr bislang nicht verbuchen konnten. Es besteht die Möglichkeit, dass es sich hierbei um ein Versehen unsererseits handelt. Solltest du den Betrag bereits überwiesen haben, bitte kurz auf diese E-Mail antworten, damit wir es richtigstellen können. Falls die Zahlung noch nicht erfolgt ist, bitten wir um umgehende Überweisung des ausstehenden Betrags, spätestens jedoch bis zum 31. März, auf unser Bankkonto.\n\n\ -Dein Vereintsbeitrag für das aktuelle Jahr beträgt {}€", +Dein Vereinsbeitrag für das aktuelle Jahr beträgt {}€", fees.sum_in_cents / 100, ); From 730559f2f49dff933c95c24bfa2366ba25b79133 Mon Sep 17 00:00:00 2001 From: philipp Date: Fri, 15 Mar 2024 15:29:50 +0100 Subject: [PATCH 07/21] a bit nicer mail sending layout --- src/model/mail.rs | 1 - templates/admin/mail.html.tera | 24 ++++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/model/mail.rs b/src/model/mail.rs index 41de809..1a82ce1 100644 --- a/src/model/mail.rs +++ b/src/model/mail.rs @@ -234,7 +234,6 @@ Dein Vereinsbeitrag für das aktuelle Jahr beträgt {}€", } content.push_str("\n\ Gemäß § 7 Abs. 3 lit. c unseres Status behalten wir uns vor, bei ausbleibender Zahlung die Mitgliedschaft zu beenden. Dies möchten wir vermeiden und hoffen auf deine Unterstützung.\n\n\ - Bei Fragen oder Problemen stehen wir gerne zur Verfügung. Bankverbindung: IBAN: AT13 1200 0804 1300 1200 (Unter https://app.rudernlinz.at/planned findest du einen QR Code, den du mit deiner Bankapp scannen kannst um alle Eingaben bereits ausgefüllt zu haben.) diff --git a/templates/admin/mail.html.tera b/templates/admin/mail.html.tera index 1f80747..1f8436c 100644 --- a/templates/admin/mail.html.tera +++ b/templates/admin/mail.html.tera @@ -2,16 +2,20 @@ {% import "includes/forms/boat" as boat %} {% extends "base" %} {% block content %} -
+

Mail

-
- - - - - -
+
+ +
{% endblock content %} From 09a0354eee648e02cc58938d4b01ea2ee70e2344 Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 16 Mar 2024 09:55:58 +0100 Subject: [PATCH 08/21] fix whitespace --- templates/includes/forms/log.html.tera | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/includes/forms/log.html.tera b/templates/includes/forms/log.html.tera index 203d57d..dda33c0 100644 --- a/templates/includes/forms/log.html.tera +++ b/templates/includes/forms/log.html.tera @@ -137,9 +137,9 @@ {{ rower.name }} {% if rower.id == log.shipmaster or rower.id == log.steering_person %} ( - {% if rower.id == log.shipmaster %}Schiffsführer{% endif %} - {% if rower.id == log.shipmaster and rower.id == log.steering_person %}/{% endif %} - {% if rower.id == log.steering_person %}Steuerperson{% endif %} + {%- if rower.id == log.shipmaster %}Schiffsführer{% endif -%} + {% if rower.id == log.shipmaster and rower.id == log.steering_person %} / {% endif %} + {%- if rower.id == log.steering_person %}Steuerperson{% endif -%} ) {% endif %}

From 4d634ce3138f3abbeb8b4828b20402869a2acc65 Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 16 Mar 2024 10:56:37 +0100 Subject: [PATCH 09/21] spacing again --- templates/planned.html.tera | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/planned.html.tera b/templates/planned.html.tera index 521ec8c..d39f4d2 100644 --- a/templates/planned.html.tera +++ b/templates/planned.html.tera @@ -109,9 +109,9 @@ Uhr ({{ planned_event.name }} - {% if planned_event.trip_type %} + {%- if planned_event.trip_type %} - {{ planned_event.trip_type.icon | safe }} {{ planned_event.trip_type.name }} - {% endif %} + {%- endif -%} )
Result<(), LogbookDeleteError> { Log::create(db, format!("{user:?} deleted trip: {self:?}")).await; - if user.has_role(db, "admin").await || user.id == self.shipmaster { + if user.has_role(db, "admin").await + || user.has_role(db, "Vorstand").await + || user.id == self.shipmaster + { sqlx::query!("DELETE FROM logbook WHERE id=?", self.id) .execute(db) .await diff --git a/templates/includes/forms/log.html.tera b/templates/includes/forms/log.html.tera index dda33c0..f8f0145 100644 --- a/templates/includes/forms/log.html.tera +++ b/templates/includes/forms/log.html.tera @@ -137,9 +137,11 @@ {{ rower.name }} {% if rower.id == log.shipmaster or rower.id == log.steering_person %} ( - {%- if rower.id == log.shipmaster %}Schiffsführer{% endif -%} - {% if rower.id == log.shipmaster and rower.id == log.steering_person %} / {% endif %} - {%- if rower.id == log.steering_person %}Steuerperson{% endif -%} + {%- if rower.id == log.shipmaster %}Schiffsführer + {% endif -%} + {% if rower.id == log.shipmaster and rower.id == log.steering_person %}/{% endif %} + {%- if rower.id == log.steering_person %}Steuerperson + {% endif -%} ) {% endif %}

diff --git a/templates/log.html.tera b/templates/log.html.tera index b37f3e5..d6e2144 100644 --- a/templates/log.html.tera +++ b/templates/log.html.tera @@ -19,6 +19,8 @@ {% for log in on_water %} {% if log.shipmaster == loggedin_user.id %} {{ log::show(log=log, state="on_water", allowed_to_close=true, only_ones="cox" not in loggedin_user.roles) }} + {% elif "Vorstand" in loggedin_user.roles %} + {{ log::show(log=log, state="on_water", allowed_to_close=true, only_ones="cox" not in loggedin_user.roles) }} {% else %} {{ log::show(log=log, state="on_water", only_ones=true) }} {% endif %} From c0687135727734a6267fd084421c70b91dce6cac Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 16 Mar 2024 20:42:41 +0100 Subject: [PATCH 11/21] add more logs --- src/tera/admin/mail.rs | 12 +++++++++--- src/tera/admin/user.rs | 23 ++++++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/tera/admin/mail.rs b/src/tera/admin/mail.rs index d1a6263..2afcd3a 100644 --- a/src/tera/admin/mail.rs +++ b/src/tera/admin/mail.rs @@ -6,6 +6,7 @@ use rocket::{post, FromForm}; use rocket_dyn_templates::{tera::Context, Template}; use sqlx::SqlitePool; +use crate::model::log::Log; use crate::model::mail::Mail; use crate::model::role::Role; use crate::model::user::AdminUser; @@ -34,7 +35,8 @@ async fn index( } #[get("/mail/fee")] -async fn fee(db: &State, _admin: AdminUser, config: &State) -> &'static str { +async fn fee(db: &State, admin: AdminUser, config: &State) -> &'static str { + Log::create(db, format!("{admin:?} trying to send fee")).await; Mail::fees(db, config.smtp_pw.clone()).await; "SUCC" } @@ -42,9 +44,10 @@ async fn fee(db: &State, _admin: AdminUser, config: &State) #[get("/mail/fee-final")] async fn fee_final( db: &State, - _admin: AdminUser, + admin: AdminUser, config: &State, ) -> &'static str { + Log::create(db, format!("{admin:?} trying to send fee_final")).await; Mail::fees_final(db, config.smtp_pw.clone()).await; "SUCC" } @@ -62,12 +65,15 @@ async fn update( db: &State, data: Form>, config: &State, - _admin: AdminUser, + admin: AdminUser, ) -> Flash { let d = data.into_inner(); + Log::create(db, format!("{admin:?} trying to send this mail: {d:?}")).await; if Mail::send(db, d, config.smtp_pw.clone()).await { + Log::create(db, "Mail successfully sent".into()).await; Flash::success(Redirect::to("/admin/mail"), "Mail versendet") } else { + Log::create(db, "Error sending the mail".into()).await; Flash::error(Redirect::to("/admin/mail"), "Fehler") } } diff --git a/src/tera/admin/user.rs b/src/tera/admin/user.rs index 82eb4e3..d505296 100644 --- a/src/tera/admin/user.rs +++ b/src/tera/admin/user.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use crate::model::{ family::Family, + log::Log, logbook::Logbook, role::Role, user::{AdminUser, User, UserWithRoles, VorstandUser}, @@ -163,10 +164,15 @@ async fn scheckbuch( #[get("/user/fees/paid?")] async fn fees_paid( db: &State, - _admin: AdminUser, + admin: AdminUser, user_ids: Vec, referer: Referer, ) -> Flash { + Log::create( + db, + format!("{admin:?} set fees paid for user_ids: {user_ids:?}"), + ) + .await; let mut res = String::new(); for user_id in user_ids { let user = User::find_by_id(db, user_id).await.unwrap(); @@ -204,8 +210,9 @@ async fn resetpw(db: &State, _admin: AdminUser, user: i32) -> Flash< } #[get("/user//delete")] -async fn delete(db: &State, _admin: AdminUser, user: i32) -> Flash { +async fn delete(db: &State, admin: AdminUser, user: i32) -> Flash { let user = User::find_by_id(db, user).await; + Log::create(db, format!("{admin:?} deleted user: {user:?}")).await; match user { Some(user) => { user.delete(db).await; @@ -239,9 +246,14 @@ pub struct UserEditForm { async fn update( db: &State, data: Form, - _admin: AdminUser, + admin: AdminUser, ) -> Flash { let user = User::find_by_id(db, data.id).await; + Log::create( + db, + format!("{admin:?} updated user from {user:?} to {data:?}"), + ) + .await; let Some(user) = user else { return Flash::error( Redirect::to("/admin/user"), @@ -254,7 +266,7 @@ async fn update( Flash::success(Redirect::to("/admin/user"), "Successfully updated user") } -#[derive(FromForm)] +#[derive(FromForm, Debug)] struct UserAddForm<'r> { name: &'r str, } @@ -263,8 +275,9 @@ struct UserAddForm<'r> { async fn create( db: &State, data: Form>, - _admin: AdminUser, + admin: AdminUser, ) -> Flash { + Log::create(db, format!("{admin:?} created new user: {data:?}")).await; if User::create(db, data.name).await { Flash::success(Redirect::to("/admin/user"), "Successfully created user") } else { From 8645612718c36bf2cb06196db94435dce97d73ed Mon Sep 17 00:00:00 2001 From: philipp Date: Sun, 17 Mar 2024 21:08:55 +0100 Subject: [PATCH 12/21] spacing --- templates/includes/forms/log.html.tera | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/includes/forms/log.html.tera b/templates/includes/forms/log.html.tera index f8f0145..1f29201 100644 --- a/templates/includes/forms/log.html.tera +++ b/templates/includes/forms/log.html.tera @@ -141,7 +141,7 @@ {% endif -%} {% if rower.id == log.shipmaster and rower.id == log.steering_person %}/{% endif %} {%- if rower.id == log.steering_person %}Steuerperson - {% endif -%} + {%- endif -%} ) {% endif %}

From 39a8a1563c8592b0c3cbf7beef811007f27dec01 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 19 Mar 2024 09:59:46 +0100 Subject: [PATCH 13/21] bit nicer logs --- src/tera/admin/user.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/tera/admin/user.rs b/src/tera/admin/user.rs index d505296..7a55d85 100644 --- a/src/tera/admin/user.rs +++ b/src/tera/admin/user.rs @@ -168,19 +168,24 @@ async fn fees_paid( user_ids: Vec, referer: Referer, ) -> Flash { - Log::create( - db, - format!("{admin:?} set fees paid for user_ids: {user_ids:?}"), - ) - .await; let mut res = String::new(); for user_id in user_ids { let user = User::find_by_id(db, user_id).await.unwrap(); res.push_str(&format!("{} + ", user.name)); if user.has_role(db, "paid").await { + Log::create( + db, + format!("{} set fees NOT paid for '{}'", admin.user.name, user.name), + ) + .await; user.remove_role(db, &Role::find_by_name(db, "paid").await.unwrap()) .await; } else { + Log::create( + db, + format!("{} set fees paid for '{}'", admin.user.name, user.name), + ) + .await; user.add_role(db, &Role::find_by_name(db, "paid").await.unwrap()) .await; } @@ -212,7 +217,7 @@ async fn resetpw(db: &State, _admin: AdminUser, user: i32) -> Flash< #[get("/user//delete")] async fn delete(db: &State, admin: AdminUser, user: i32) -> Flash { let user = User::find_by_id(db, user).await; - Log::create(db, format!("{admin:?} deleted user: {user:?}")).await; + Log::create(db, format!("{} deleted user: {user:?}", admin.user.name)).await; match user { Some(user) => { user.delete(db).await; @@ -251,7 +256,7 @@ async fn update( let user = User::find_by_id(db, data.id).await; Log::create( db, - format!("{admin:?} updated user from {user:?} to {data:?}"), + format!("{} updated user from {user:?} to {data:?}", admin.user.name), ) .await; let Some(user) = user else { @@ -277,8 +282,12 @@ async fn create( data: Form>, admin: AdminUser, ) -> Flash { - Log::create(db, format!("{admin:?} created new user: {data:?}")).await; if User::create(db, data.name).await { + Log::create( + db, + format!("{} created new user: {data:?}", admin.user.name), + ) + .await; Flash::success(Redirect::to("/admin/user"), "Successfully created user") } else { Flash::error( From 0aa32654b0ec1651c6512f3a6c0fa6ca0daf72e7 Mon Sep 17 00:00:00 2001 From: philipp Date: Wed, 20 Mar 2024 00:11:11 +0100 Subject: [PATCH 14/21] push --- .gitea/workflows/action.yml | 12 ++++++------ src/model/user.rs | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.gitea/workflows/action.yml b/.gitea/workflows/action.yml index 0b6fce8..3279821 100644 --- a/.gitea/workflows/action.yml +++ b/.gitea/workflows/action.yml @@ -26,8 +26,8 @@ jobs: ~/.cargo/registry/cache/ ~/.cargo/git/db/ target/ - key: ${{ runner.os }}-cargo-debug-${{ hashFiles('**/Cargo.lock') }} - restore-keys: ${{ runner.os }}-cargo-debug- + key: ${{ runner.os }}-cargo-debug-rowt-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo-debug-rowt- - name: Build run: | @@ -65,8 +65,8 @@ jobs: ~/.cargo/registry/cache/ ~/.cargo/git/db/ target/ - key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }} - restore-keys: ${{ runner.os }}-cargo-release- + key: ${{ runner.os }}-cargo-release-rowt-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo-release-rowt- - name: Build run: | cargo build --release --target $CARGO_TARGET @@ -116,8 +116,8 @@ jobs: ~/.cargo/registry/cache/ ~/.cargo/git/db/ target/ - key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }} - restore-keys: ${{ runner.os }}-cargo-release- + key: ${{ runner.os }}-cargo-release-rowt-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo-release-rowt- - name: Build run: | diff --git a/src/model/user.rs b/src/model/user.rs index a4e662f..5eab949 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -512,6 +512,8 @@ ORDER BY last_access DESC if ![ "n-sageder", "p-hofer", + "daniel-kortschak" + "rudernlinz", "m-birner", "s-sollberger", "d-kortschak", From 5cedbc078dae49b726b60694d1363f8e751637e1 Mon Sep 17 00:00:00 2001 From: philipp Date: Wed, 20 Mar 2024 00:48:27 +0100 Subject: [PATCH 15/21] fix ci --- src/model/user.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/model/user.rs b/src/model/user.rs index 5eab949..ca6b710 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -512,7 +512,7 @@ ORDER BY last_access DESC if ![ "n-sageder", "p-hofer", - "daniel-kortschak" + "daniel-kortschak", "rudernlinz", "m-birner", "s-sollberger", From 9c1bcbc5f59a8e28df43dc0b6a28b8195fbe7b9b Mon Sep 17 00:00:00 2001 From: philipp Date: Wed, 20 Mar 2024 08:58:51 +0100 Subject: [PATCH 16/21] don't count 'externe steuerkilometer' as guest kms --- src/model/stat.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/model/stat.rs b/src/model/stat.rs index c53c267..165c455 100644 --- a/src/model/stat.rs +++ b/src/model/stat.rs @@ -73,7 +73,8 @@ WHERE u.id NOT IN ( WHERE ro.name = 'Donau Linz' ) AND l.distance_in_km IS NOT NULL -AND l.arrival LIKE '{year}-%'; +AND l.arrival LIKE '{year}-%' +AND u.name != 'Externe Steuerperson'; " )) .fetch_one(db) From c9eecf0a29f89e8395b2d82d20795af097eeec06 Mon Sep 17 00:00:00 2001 From: philipp Date: Wed, 20 Mar 2024 09:14:26 +0100 Subject: [PATCH 17/21] create temporary boat reservation feature --- templates/includes/macros.html.tera | 14 ++++++++++++++ templates/kiosk.html.tera | 1 + templates/log.html.tera | 1 + 3 files changed, 16 insertions(+) diff --git a/templates/includes/macros.html.tera b/templates/includes/macros.html.tera index b54df4d..28f568c 100644 --- a/templates/includes/macros.html.tera +++ b/templates/includes/macros.html.tera @@ -1,3 +1,17 @@ +{% macro boatreservation() %} +
+

Bootsreservierungen

+
+
    +
  • 22.04. | Christian Gusenbauer | Boot: Linz
  • +
+
+
+{% endmacro boatreservation %} {% macro header(loggedin_user) %}
diff --git a/templates/kiosk.html.tera b/templates/kiosk.html.tera index 149d157..e03a452 100644 --- a/templates/kiosk.html.tera +++ b/templates/kiosk.html.tera @@ -9,6 +9,7 @@ {{ macros::alert(message=flash.1, type=flash.0, class="sm:col-span-2 lg:col-span-3") }}
{% endif %} + {{ macros::boatreservation() }}