From 9c3ae7434e771bb6a02a9b730ba082e91bebdb6a Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 4 Mar 2024 09:19:04 +0100 Subject: [PATCH] allow vorstand to see member details, Fixes #199 --- src/tera/admin/user.rs | 11 ++++++----- templates/admin/user/index.html.tera | 28 +++++++++++++++++----------- templates/includes/macros.html.tera | 4 ++-- templates/index.html.tera | 1 + 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/tera/admin/user.rs b/src/tera/admin/user.rs index 91e8ee8..be3f7a8 100644 --- a/src/tera/admin/user.rs +++ b/src/tera/admin/user.rs @@ -19,7 +19,7 @@ use sqlx::SqlitePool; #[get("/user")] async fn index( db: &State, - admin: AdminUser, + user: VorstandUser, flash: Option>, ) -> Template { let user_futures: Vec<_> = User::all(db) @@ -28,6 +28,9 @@ async fn index( .map(|u| async move { UserWithRoles::from_user(u, db).await }) .collect(); + let user: User = user.into(); + let allowed_to_edit = user.has_role(db, "admin").await; + let users: Vec = join_all(user_futures).await; let roles = Role::all(db).await; @@ -37,13 +40,11 @@ async fn index( if let Some(msg) = flash { context.insert("flash", &msg.into_inner()); } + context.insert("allowed_to_edit", &allowed_to_edit); context.insert("users", &users); context.insert("roles", &roles); context.insert("families", &families); - context.insert( - "loggedin_user", - &UserWithRoles::from_user(admin.user, db).await, - ); + context.insert("loggedin_user", &UserWithRoles::from_user(user, db).await); Template::render("admin/user/index", context.into_json()) } diff --git a/templates/admin/user/index.html.tera b/templates/admin/user/index.html.tera index 496e5c9..619f838 100644 --- a/templates/admin/user/index.html.tera +++ b/templates/admin/user/index.html.tera @@ -10,6 +10,7 @@

Users

+ {% if allowed_to_edit %}

Neuen User hinzufügen

@@ -24,6 +25,7 @@
+ {% endif %}
@@ -60,21 +62,24 @@
{% for role in roles %} - {{ macros::checkbox(label=role.name, name="roles[" ~ role.id ~ "]", id=loop.index , checked=role.name in user.roles) }} + {{ macros::checkbox(label=role.name, name="roles[" ~ role.id ~ "]", id=loop.index , checked=role.name in user.roles, disabled=allowed_to_edit == false) }} {% endfor%} - {{ macros::input(label='DOB', name='dob', id=loop.index, type="text", value=user.dob) }} - {{ macros::input(label='Weight (kg)', name='weight', id=loop.index, type="text", value=user.weight) }} - {{ macros::input(label='Sex', name='sex', id=loop.index, type="text", value=user.sex) }} - {{ macros::input(label='Mitglied seit', name='member_since_date', id=loop.index, type="text", value=user.member_since_date) }} - {{ macros::input(label='Geburtsdatum', name='birthdate', id=loop.index, type="text", value=user.birthdate) }} - {{ macros::input(label='Mail', name='mail', id=loop.index, type="text", value=user.mail) }} - {{ macros::input(label='Nickname', name='nickname', id=loop.index, type="text", value=user.nickname) }} - {{ macros::input(label='Notizen', name='notes', id=loop.index, type="text", value=user.notes) }} - {{ macros::input(label='Telefon', name='phone', id=loop.index, type="text", value=user.phone) }} - {{ macros::input(label='Adresse', name='address', id=loop.index, type="text", value=user.address) }} + {{ macros::input(label='DOB', name='dob', id=loop.index, type="text", value=user.dob, readonly=allowed_to_edit == false) }} + {{ macros::input(label='Weight (kg)', name='weight', id=loop.index, type="text", value=user.weight, readonly=allowed_to_edit == false) }} + {{ macros::input(label='Sex', name='sex', id=loop.index, type="text", value=user.sex, readonly=allowed_to_edit == false) }} + {{ macros::input(label='Mitglied seit', name='member_since_date', id=loop.index, type="text", value=user.member_since_date, readonly=allowed_to_edit == false) }} + {{ macros::input(label='Geburtsdatum', name='birthdate', id=loop.index, type="text", value=user.birthdate, readonly=allowed_to_edit == false) }} + {{ macros::input(label='Mail', name='mail', id=loop.index, type="text", value=user.mail, readonly=allowed_to_edit == false) }} + {{ macros::input(label='Nickname', name='nickname', id=loop.index, type="text", value=user.nickname, readonly=allowed_to_edit == false) }} + {{ macros::input(label='Notizen', name='notes', id=loop.index, type="text", value=user.notes, readonly=allowed_to_edit == false) }} + {{ macros::input(label='Telefon', name='phone', id=loop.index, type="text", value=user.phone, readonly=allowed_to_edit == false) }} + {{ macros::input(label='Adresse', name='address', id=loop.index, type="text", value=user.address, readonly=allowed_to_edit == false) }} + {% if allowed_to_edit %} {{ macros::select(label="Familie", data=families, name='family_id', selected_id=user.family_id, display=['names'], default="Keine Familie", new_last_entry='Neue Familie anlegen') }} + {% endif %}
+ {% if allowed_to_edit %} + {% endif %} {% endfor %} diff --git a/templates/includes/macros.html.tera b/templates/includes/macros.html.tera index a534578..fefc2e7 100644 --- a/templates/includes/macros.html.tera +++ b/templates/includes/macros.html.tera @@ -154,10 +154,10 @@
{% endmacro header %} -{% macro input(label, name, type, required=false, class='rounded-md', value='', min='', hide_label=false, id='', autofocus=false, wrapper_class='', pattern='') %} +{% macro input(label, name, type, required=false, class='rounded-md', value='', min='', hide_label=false, id='', autofocus=false, wrapper_class='', pattern='', readonly=false) %}
- +
{% endmacro input %} diff --git a/templates/index.html.tera b/templates/index.html.tera index 6304144..eb40ead 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -73,6 +73,7 @@