From 7a945c11e36c7096bc5e3a8b66c6268d58f7fd40 Mon Sep 17 00:00:00 2001 From: Philipp Hofer Date: Wed, 11 Dec 2024 21:49:54 +0100 Subject: [PATCH] remove donau linz stuff --- src/model/event.rs | 4 +-- src/model/notification.rs | 14 +++++++++++ src/model/personal/cal.rs | 5 +--- src/tera/admin/mod.rs | 52 +++------------------------------------ templates/base.html.tera | 2 +- 5 files changed, 20 insertions(+), 57 deletions(-) diff --git a/src/model/event.rs b/src/model/event.rs index c8af6ad..036636b 100644 --- a/src/model/event.rs +++ b/src/model/event.rs @@ -232,10 +232,8 @@ WHERE trip_details.id=? } 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( + Notification::create_for_all( 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}")), diff --git a/src/model/notification.rs b/src/model/notification.rs index 6ce2ce9..9aa5030 100644 --- a/src/model/notification.rs +++ b/src/model/notification.rs @@ -89,6 +89,20 @@ impl Notification { tx.commit().await.unwrap(); } + pub async fn create_for_all( + db: &SqlitePool, + message: &str, + category: &str, + link: Option<&str>, + action_after_reading: Option<&str>, + ) { + let users = User::all(db).await; + + for user in users { + Self::create(db, &user, message, category, link, action_after_reading).await; + } + } + pub async fn create_for_steering_people_tx( db: &mut Transaction<'_, Sqlite>, message: &str, diff --git a/src/model/personal/cal.rs b/src/model/personal/cal.rs index f0fc1ef..9aca29f 100644 --- a/src/model/personal/cal.rs +++ b/src/model/personal/cal.rs @@ -7,10 +7,7 @@ use crate::model::{event::Event, trip::Trip, user::User}; pub(crate) async fn get_personal_cal(db: &SqlitePool, user: &User) -> String { let mut calendar = ICalendar::new("2.0", "ics-rs"); - calendar.push(Property::new( - "X-WR-CALNAME", - "Donau Linz - Deine Ausfahrten", - )); + calendar.push(Property::new("X-WR-CALNAME", "ruad.at - Deine Ausfahrten")); let events = Event::all_with_user(db, user).await; for event in events { diff --git a/src/tera/admin/mod.rs b/src/tera/admin/mod.rs index 9348017..688f20a 100644 --- a/src/tera/admin/mod.rs +++ b/src/tera/admin/mod.rs @@ -1,10 +1,8 @@ -use csv::ReaderBuilder; -use rocket::{form::Form, get, post, routes, FromForm, Route, State}; -use rocket_dyn_templates::{context, Template}; +use rocket::{get, routes, Route, State}; use sqlx::SqlitePool; use super::notification; -use crate::model::{log::Log, role::Role, user::AdminUser}; +use crate::model::{log::Log, user::AdminUser}; pub mod event; pub mod user; @@ -14,55 +12,11 @@ async fn log(db: &State, _admin: AdminUser) -> String { Log::show(db).await } -#[get("/list")] -async fn show_list(_admin: AdminUser) -> Template { - Template::render("admin/list/index", context!()) -} - -#[derive(FromForm)] -struct ListForm { - list: String, -} - -#[post("/list", data = "")] -async fn list(db: &State, _admin: AdminUser, list_form: Form) -> Template { - let role = Role::find_by_name(db, "Donau Linz").await.unwrap(); - let acceptable_users = role.names_from_role(db).await; - - let mut rdr = ReaderBuilder::new() - .has_headers(true) - .delimiter(b';') - .from_reader(list_form.list.trim().as_bytes()); - - let mut names_not_in_acceptable_users = Vec::new(); - - for result in rdr.records() { - println!("{result:?}"); - let record = result.unwrap(); - - // Concatenate Vorname and Nachname - let vorname = record.get(2).unwrap_or_default().trim(); - let nachname = record.get(3).unwrap_or_default().trim(); - let full_name = format!("{} {}", vorname, nachname); - - // Check if the concatenated name is not in the acceptable_users vector - if !acceptable_users.contains(&full_name) { - names_not_in_acceptable_users.push(full_name); - } - } - - let context = context! { - result: names_not_in_acceptable_users - }; - - Template::render("admin/list/result", context) -} - pub fn routes() -> Vec { let mut ret = Vec::new(); ret.append(&mut user::routes()); ret.append(&mut notification::routes()); ret.append(&mut event::routes()); - ret.append(&mut routes![log, show_list, list]); + ret.append(&mut routes![log]); ret } diff --git a/templates/base.html.tera b/templates/base.html.tera index f3c4303..69ad351 100644 --- a/templates/base.html.tera +++ b/templates/base.html.tera @@ -20,7 +20,7 @@ - Ruderassistent - ASKÖ Ruderverein Donau Linz + Ruderassistent - ruad.at {% if loggedin_user %}{{ macros::header(loggedin_user=loggedin_user) }}{% endif %}