From 34850321b736c10352c974d9051eb12c4cec466f Mon Sep 17 00:00:00 2001 From: Philipp Hofer Date: Tue, 29 Apr 2025 22:37:04 +0200 Subject: [PATCH 1/8] first draft of single user-edit page --- src/model/user/mod.rs | 4 +- src/tera/admin/user.rs | 38 +++++ templates/admin/mail.html.tera | 26 ++-- templates/admin/user/index.html.tera | 82 ++++++----- templates/admin/user/view.html.tera | 191 +++++++++++++++++++++++++ templates/ergo/final.html.tera | 4 +- templates/ergo/index.html.tera | 8 +- templates/forms/trip.html.tera | 10 +- templates/includes/forms/log.html.tera | 8 +- templates/includes/macros.html.tera | 9 +- templates/index.html.tera | 158 ++++++++++---------- templates/planned.html.tera | 42 +++--- 12 files changed, 414 insertions(+), 166 deletions(-) create mode 100644 templates/admin/user/view.html.tera diff --git a/src/model/user/mod.rs b/src/model/user/mod.rs index 707143f..7da7493 100644 --- a/src/model/user/mod.rs +++ b/src/model/user/mod.rs @@ -1036,7 +1036,8 @@ pub struct UserWithRolesAndMembershipPdf { #[serde(flatten)] pub user: User, pub membership_pdf: bool, - pub roles: Vec, + pub roles: Vec, // TODO: remove + pub proper_roles: Vec, } impl UserWithRolesAndMembershipPdf { @@ -1045,6 +1046,7 @@ impl UserWithRolesAndMembershipPdf { Self { roles: user.roles(db).await, + proper_roles: user.real_roles(db).await, user, membership_pdf, } diff --git a/src/tera/admin/user.rs b/src/tera/admin/user.rs index fe4e607..aa49ab7 100644 --- a/src/tera/admin/user.rs +++ b/src/tera/admin/user.rs @@ -112,6 +112,43 @@ async fn index_admin( Template::render("admin/user/index", context.into_json()) } +#[get("/user/")] +async fn view( + db: &State, + admin: VorstandUser, + flash: Option>, + user: i32, +) -> Result> { + let Some(user) = User::find_by_id(db, user).await else { + return Err(Flash::error( + Redirect::to("/admin/usert"), + format!("User mit ID {} gibts ned", user), + )); + }; + let user = UserWithRolesAndMembershipPdf::from_user(db, user).await; + + let admin: User = admin.into_inner(); + let allowed_to_edit = ManageUserUser::new(db, &admin).await.is_some(); + + let roles = Role::all(db).await; + let families = Family::all_with_members(db).await; + + let mut context = Context::new(); + if let Some(msg) = flash { + context.insert("flash", &msg.into_inner()); + } + context.insert("allowed_to_edit", &allowed_to_edit); + context.insert("user", &user); + context.insert("roles", &roles); + context.insert("families", &families); + context.insert( + "loggedin_user", + &UserWithDetails::from_user(admin, db).await, + ); + + Ok(Template::render("admin/user/view", context.into_json())) +} + #[get("/user/fees")] async fn fees( db: &State, @@ -469,6 +506,7 @@ pub fn routes() -> Vec { routes![ index, index_admin, + view, resetpw, update, create, diff --git a/templates/admin/mail.html.tera b/templates/admin/mail.html.tera index c80db2e..1e2ed46 100644 --- a/templates/admin/mail.html.tera +++ b/templates/admin/mail.html.tera @@ -26,26 +26,24 @@ role="alert">

Mitglieds-Beitrags-Info

diff --git a/templates/admin/user/index.html.tera b/templates/admin/user/index.html.tera index 69e0121..3cf66aa 100644 --- a/templates/admin/user/index.html.tera +++ b/templates/admin/user/index.html.tera @@ -5,28 +5,29 @@

Users

{% if allowed_to_edit %}
- Neue Person hinzufügen + + Neue Person hinzufügen +
-
-
- - + onsubmit="return confirm('Willst du wirklich einen neuen Benutzer anlegen?');" + method="post" + class="flex mt-4 rounded-md sm:flex items-end justify-between"> +
+
+ + +
-
-
- -
- +
+ +
+
- {% endif %}
@@ -36,26 +37,29 @@ id="filter-js" class="search-bar" placeholder="Suchen nach (Name, [yes|no]-role:, has-[no-]membership-pdf)" /> -
- - - - + + +
@@ -90,6 +94,8 @@ + ✏️
+

{{ user.name }}

+
+ + + + + +{% endblock content %} diff --git a/templates/ergo/final.html.tera b/templates/ergo/final.html.tera index 8dc4731..c530904 100644 --- a/templates/ergo/final.html.tera +++ b/templates/ergo/final.html.tera @@ -7,7 +7,7 @@ Dirty Thirty

-