verify, that boat is not on water on adding log entry; Fixes #625 #697

Merged
philipp merged 9 commits from boat-water-check into main 2024-08-21 17:05:42 +02:00
7 changed files with 59 additions and 4 deletions
Showing only changes of commit d0c491430c - Show all commits

View File

@ -11,6 +11,7 @@ INSERT INTO "role" (name) VALUES ('Bootsführer');
INSERT INTO "role" (name) VALUES ('schnupperant'); INSERT INTO "role" (name) VALUES ('schnupperant');
INSERT INTO "role" (name) VALUES ('kassier'); INSERT INTO "role" (name) VALUES ('kassier');
INSERT INTO "role" (name) VALUES ('schriftfuehrer'); INSERT INTO "role" (name) VALUES ('schriftfuehrer');
INSERT INTO "role" (name) VALUES ('no-einschreibgebuehr');
INSERT INTO "user" (name, pw) VALUES('admin', '$argon2id$v=19$m=19456,t=2,p=1$dS/X5/sPEKTj4Rzs/CuvzQ$4P4NCw4Ukhv80/eQYTsarHhnw61JuL1KMx/L9dm82YM'); INSERT INTO "user" (name, pw) VALUES('admin', '$argon2id$v=19$m=19456,t=2,p=1$dS/X5/sPEKTj4Rzs/CuvzQ$4P4NCw4Ukhv80/eQYTsarHhnw61JuL1KMx/L9dm82YM');
INSERT INTO "user_role" (user_id, role_id) VALUES(1,1); INSERT INTO "user_role" (user_id, role_id) VALUES(1,1);
INSERT INTO "user_role" (user_id, role_id) VALUES(1,2); INSERT INTO "user_role" (user_id, role_id) VALUES(1,2);

View File

@ -8,7 +8,10 @@ use ics::{
use serde::Serialize; use serde::Serialize;
use sqlx::{FromRow, Row, SqlitePool}; use sqlx::{FromRow, Row, SqlitePool};
use super::{notification::Notification, tripdetails::TripDetails, triptype::TripType, user::User}; use super::{
notification::Notification, role::Role, tripdetails::TripDetails, triptype::TripType,
user::User,
};
#[derive(Serialize, Clone, FromRow, Debug, PartialEq)] #[derive(Serialize, Clone, FromRow, Debug, PartialEq)]
pub struct Event { pub struct Event {
@ -213,12 +216,35 @@ WHERE trip_details.id=?
.ok() .ok()
} }
async fn advertise(db: &SqlitePool, day: &str, planned_starting_time: &str, name: &str) {
let donau = Role::find_by_name(db, "Donau Linz").await.unwrap();
Notification::create_for_role(
db,
&donau,
&format!("Am {} um {} wurde ein neues Event angelegt: {} Wir freuen uns wenn du dabei mitmachst, die Anmeldung ist ab sofort offen :-)", day, planned_starting_time, name),
"Neues Event",
Some(&format!("/planned#{day}")),
None,
)
.await;
}
pub async fn create( pub async fn create(
db: &SqlitePool, db: &SqlitePool,
name: &str, name: &str,
planned_amount_cox: i32, planned_amount_cox: i32,
trip_details: &TripDetails, trip_details: &TripDetails,
) { ) {
if trip_details.always_show {
Self::advertise(
db,
&trip_details.day,
&trip_details.planned_starting_time,
name,
)
.await;
}
sqlx::query!( sqlx::query!(
"INSERT INTO planned_event(name, planned_amount_cox, trip_details_id) VALUES(?, ?, ?)", "INSERT INTO planned_event(name, planned_amount_cox, trip_details_id) VALUES(?, ?, ?)",
name, name,
@ -258,6 +284,16 @@ WHERE trip_details.id=?
.await .await
.unwrap(); //Okay, as planned_event can only be created with proper DB backing .unwrap(); //Okay, as planned_event can only be created with proper DB backing
if !tripdetails.always_show && update.always_show {
Self::advertise(
db,
&tripdetails.day,
&tripdetails.planned_starting_time,
update.name,
)
.await;
}
if update.max_people == 0 && !was_already_cancelled { if update.max_people == 0 && !was_already_cancelled {
let coxes = Registration::all_cox(db, self.id).await; let coxes = Registration::all_cox(db, self.id).await;
for user in coxes { for user in coxes {

View File

@ -29,6 +29,7 @@ const REGULAR: i32 = 22000;
const UNTERSTUETZEND: i32 = 2500; const UNTERSTUETZEND: i32 = 2500;
const FOERDERND: i32 = 8500; const FOERDERND: i32 = 8500;
pub const SCHECKBUCH: i32 = 3000; pub const SCHECKBUCH: i32 = 3000;
const EINSCHREIBGEBUEHR: i32 = 3000;
#[derive(FromRow, Serialize, Deserialize, Clone, Debug, Eq, Hash, PartialEq)] #[derive(FromRow, Serialize, Deserialize, Clone, Debug, Eq, Hash, PartialEq)]
pub struct User { pub struct User {
@ -361,6 +362,17 @@ ASKÖ Ruderverein Donau Linz", self.name),
); );
} }
if let Some(member_since_date) = &self.member_since_date {
if let Ok(member_since_date) = NaiveDate::parse_from_str(member_since_date, "%Y-%m-%d")
{
if member_since_date.year() == Local::now().year()
&& !self.has_role(db, "no-einschreibgebuehr").await
{
fee.add("Einschreibgebühr".into(), EINSCHREIBGEBUEHR);
}
}
}
let halfprice = if let Some(member_since_date) = &self.member_since_date { let halfprice = if let Some(member_since_date) = &self.member_since_date {
if let Ok(member_since_date) = NaiveDate::parse_from_str(member_since_date, "%Y-%m-%d") if let Ok(member_since_date) = NaiveDate::parse_from_str(member_since_date, "%Y-%m-%d")
{ {

View File

@ -437,6 +437,10 @@ async fn schnupper_to_scheckbuch(
let scheckbuch = Role::find_by_name(db, "scheckbuch").await.unwrap(); let scheckbuch = Role::find_by_name(db, "scheckbuch").await.unwrap();
user.add_role(db, &scheckbuch).await; user.add_role(db, &scheckbuch).await;
if let Some(no_einschreibgebuehr) = Role::find_by_name(db, "no-einschreibgebuehr").await {
user.add_role(db, &no_einschreibgebuehr).await;
}
user.send_welcome_email(db, &config.smtp_pw).await.unwrap(); user.send_welcome_email(db, &config.smtp_pw).await.unwrap();
Log::create( Log::create(

View File

@ -13,7 +13,8 @@
<li class="py-1" <li class="py-1"
{% if "paid" in user.roles %}style="background-color: green;"{% endif %}> {% if "paid" in user.roles %}style="background-color: green;"{% endif %}>
{{ user.name }} ({{ user.mail }} {{ user.name }} ({{ user.mail }}
{%- if user.notes %} | {{ user.notes }}{% endif -%} {%- if user.notes %} | {{ user.notes }}
{% endif -%}
) )
<a class="btn btn-primary" <a class="btn btn-primary"
href="/admin/user/move/schnupperant/{{ user.id }}/to/scheckbuch" href="/admin/user/move/schnupperant/{{ user.id }}/to/scheckbuch"

View File

@ -279,7 +279,8 @@
{% macro home(log) %} {% macro home(log) %}
<form class="grid grid-cols-1 gap-3" <form class="grid grid-cols-1 gap-3"
action="/log/{{ log.id }}" action="/log/{{ log.id }}"
method="post"> method="post"
onsubmit="var distance = parseFloat(document.getElementById('distance_in_km{{ log.id }}js').value); var logtype = document.getElementById('logtype{{ log.id }}js').value; if (distance > 50 && (!logtype || logtype === 'Normal')) { return confirm('Die eingegebene Distanz beträgt mehr als 50 km und es wurde kein Typ (Wanderfahrt, Regatta, ...) ausgewählt. Wenn es eine Wanderfahrt war, stell dies bitte unter \'Details ändern\' ein. Möchtest du das NICHT tun und den Eintrag OHNE Typ speichern?'); } return true;">
{{ macros::input(label='Ankunftszeit', name='arrival', type='datetime-local', required=true, class="change-id-js rounded-md current-date-time") }} {{ macros::input(label='Ankunftszeit', name='arrival', type='datetime-local', required=true, class="change-id-js rounded-md current-date-time") }}
<div> <div>
<label for="destination" class="text-sm text-gray-600 dark:text-gray-100">Ziel</label> <label for="destination" class="text-sm text-gray-600 dark:text-gray-100">Ziel</label>

View File

@ -67,7 +67,7 @@
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
<div class="bg-white dark:bg-primary-900 rounded-md flex justify-between flex-col shadow reset-js" <div id="{{ day.day| date(format="%Y-%m-%d") }}" class="bg-white dark:bg-primary-900 rounded-md flex justify-between flex-col shadow reset-js"
style="min-height: 10rem" style="min-height: 10rem"
data-trips="{{ amount_trips }}" data-trips="{{ amount_trips }}"
data-month="{{ day.day| date(format='%m') }}" data-month="{{ day.day| date(format='%m') }}"