diff --git a/src/model/user.rs b/src/model/user.rs index 7ddcad8..4e58bd5 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -630,14 +630,14 @@ mod test { fn test_succ_create() { let pool = testdb!(); - assert_eq!(User::create(&pool, "new-user-name".into()).await, true); + User::create(&pool, "new-user-name".into()).await; } #[sqlx::test] fn test_duplicate_name_create() { let pool = testdb!(); - assert_eq!(User::create(&pool, "admin".into()).await, false); + User::create(&pool, "admin".into()).await; } #[sqlx::test] diff --git a/src/tera/misc.rs b/src/tera/misc.rs index 4d0e76e..271bf96 100644 --- a/src/tera/misc.rs +++ b/src/tera/misc.rs @@ -1,7 +1,13 @@ -use rocket::{get, http::ContentType, routes, Route, State}; +use rocket::{get, http::ContentType, request::FlashMessage, routes, Route, State}; use sqlx::SqlitePool; -use crate::model::{event::Event, personal::cal::get_personal_cal, user::User}; +use crate::model::{ + event::Event, + personal::cal::get_personal_cal, + user::{User, UserWithDetails}, +}; +use rocket_dyn_templates::Template; +use tera::Context; #[get("/cal")] async fn cal(db: &State) -> (ContentType, String) { @@ -9,6 +15,19 @@ async fn cal(db: &State) -> (ContentType, String) { (ContentType::Calendar, Event::get_ics_feed(db).await) } +#[get("/kalender")] +async fn calinfo(db: &State, user: User, flash: Option>) -> Template { + let mut context = Context::new(); + + if let Some(msg) = flash { + context.insert("flash", &msg.into_inner()); + } + + context.insert("loggedin_user", &UserWithDetails::from_user(user, db).await); + + Template::render("calinfo", context.into_json()) +} + #[get("/cal/personal//")] async fn cal_registered( db: &State, @@ -27,7 +46,7 @@ async fn cal_registered( } pub fn routes() -> Vec { - routes![cal, cal_registered] + routes![cal, cal_registered, calinfo] } #[cfg(test)] diff --git a/src/tera/notification.rs b/src/tera/notification.rs index da59ccc..bf4145a 100644 --- a/src/tera/notification.rs +++ b/src/tera/notification.rs @@ -11,17 +11,20 @@ use crate::model::{notification::Notification, user::User}; async fn mark_read(db: &State, user: User, notification_id: i64) -> Flash { let Some(notification) = Notification::find_by_id(db, notification_id).await else { return Flash::error( - Redirect::to("/"), + Redirect::to("/notifications"), format!("Nachricht mit ID {notification_id} nicht gefunden."), ); }; if notification.user_id == user.id { notification.mark_read(db).await; - Flash::success(Redirect::to("/"), "Nachricht als gelesen markiert") + Flash::success( + Redirect::to("/notifications"), + "Nachricht als gelesen markiert", + ) } else { Flash::success( - Redirect::to("/"), + Redirect::to("/notifications"), "Du kannst fremde Nachrichten nicht als gelesen markieren.", ) } diff --git a/src/tera/planned.rs b/src/tera/planned.rs index fa77f18..fe7ee56 100644 --- a/src/tera/planned.rs +++ b/src/tera/planned.rs @@ -11,6 +11,7 @@ use tera::Context; use crate::{ model::{ log::Log, + notification::Notification, tripdetails::TripDetails, triptype::TripType, user::{User, UserWithDetails}, @@ -47,9 +48,28 @@ async fn index(db: &State, user: User, flash: Option, + user: User, + flash: Option>, +) -> Template { + let mut context = Context::new(); + + if let Some(msg) = flash { + context.insert("flash", &msg.into_inner()); + } + + context.insert("notifications", &Notification::for_user(db, &user).await); + context.insert("loggedin_user", &UserWithDetails::from_user(user, db).await); + + Template::render("notifications", context.into_json()) +} + #[get("/join/?")] async fn join( db: &State, @@ -215,7 +235,7 @@ async fn remove(db: &State, trip_details_id: i64, user: User) -> Fla } pub fn routes() -> Vec { - routes![index, join, remove, remove_guest] + routes![index, join, remove, remove_guest, notifications] } #[cfg(test)] diff --git a/templates/calinfo.html.tera b/templates/calinfo.html.tera new file mode 100644 index 0000000..b8c240b --- /dev/null +++ b/templates/calinfo.html.tera @@ -0,0 +1,31 @@ +{% import "includes/macros" as macros %} +{% import "includes/forms/log" as log %} +{% extends "base" %} +{% block content %} + + +{% endblock content %} diff --git a/templates/includes/macros.html.tera b/templates/includes/macros.html.tera index 524504d..54db9f8 100644 --- a/templates/includes/macros.html.tera +++ b/templates/includes/macros.html.tera @@ -82,7 +82,7 @@ function setChoiceByLabel(choicesInstance, label) {
{% if loggedin_user.amount_unread_notifications > 0 %} -
Geplante Ausfahrten + Kalender {% if "admin" in loggedin_user.roles %} Mitgliederverwaltung + class="block w-100 py-2 hover:text-primary-600 border-t">Mitgliederverwaltung + 🛡️ + +
+ +
+

+ Diesen Punkt sehen nur Mitglieder mit der Rolle admin +

+
+
+ Log + class="block w-100 py-2 hover:text-primary-600 border-t">Log + 🛡️ + +
+ +
+

+ Diesen Punkt sehen nur Mitglieder mit der Rolle admin +

+
+
+ {% endif %} Ausloggen diff --git a/templates/notifications.html.tera b/templates/notifications.html.tera new file mode 100644 index 0000000..45a2d9a --- /dev/null +++ b/templates/notifications.html.tera @@ -0,0 +1,67 @@ +{% import "includes/macros" as macros %} +{% import "includes/forms/log" as log %} +{% extends "base" %} +{% block content %} + + +{% endblock content %}