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 @@