user-role-cluster #761
@ -1,9 +1,9 @@
|
|||||||
use std::ops::DerefMut;
|
use std::ops::DerefMut;
|
||||||
|
|
||||||
use serde::Serialize;
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
|
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
|
||||||
|
|
||||||
#[derive(FromRow, Serialize, Clone)]
|
#[derive(FromRow, Serialize, Clone, Deserialize, Debug)]
|
||||||
pub struct Role {
|
pub struct Role {
|
||||||
pub(crate) id: i64,
|
pub(crate) id: i64,
|
||||||
pub(crate) name: String,
|
pub(crate) name: String,
|
||||||
|
@ -513,6 +513,21 @@ ASKÖ Ruderverein Donau Linz", self.name),
|
|||||||
.into_iter().map(|r| r.name).collect()
|
.into_iter().map(|r| r.name).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn real_roles(&self, db: &SqlitePool) -> Vec<Role> {
|
||||||
|
sqlx::query_as!(
|
||||||
|
Role,
|
||||||
|
"SELECT r.id, r.name, r.cluster
|
||||||
|
FROM role r
|
||||||
|
JOIN user_role ur ON r.id = ur.role_id
|
||||||
|
JOIN user u ON u.id = ur.user_id
|
||||||
|
WHERE ur.user_id = ? AND u.deleted = 0;",
|
||||||
|
self.id
|
||||||
|
)
|
||||||
|
.fetch_all(db)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn has_role_tx(&self, db: &mut Transaction<'_, Sqlite>, role: &str) -> bool {
|
pub async fn has_role_tx(&self, db: &mut Transaction<'_, Sqlite>, role: &str) -> bool {
|
||||||
if sqlx::query!(
|
if sqlx::query!(
|
||||||
"SELECT * FROM user_role WHERE user_id=? AND role_id = (SELECT id FROM role WHERE name = ?)",
|
"SELECT * FROM user_role WHERE user_id=? AND role_id = (SELECT id FROM role WHERE name = ?)",
|
||||||
@ -1154,7 +1169,7 @@ pub struct UserWithRolesAndMembershipPdf {
|
|||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub user: User,
|
pub user: User,
|
||||||
pub membership_pdf: bool,
|
pub membership_pdf: bool,
|
||||||
pub roles: Vec<String>,
|
pub roles: Vec<String>, // TODO: get rid of this...
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UserWithRolesAndMembershipPdf {
|
impl UserWithRolesAndMembershipPdf {
|
||||||
|
@ -293,6 +293,8 @@ async fn update(
|
|||||||
data: Form<UserEditForm<'_>>,
|
data: Form<UserEditForm<'_>>,
|
||||||
admin: ManageUserUser,
|
admin: ManageUserUser,
|
||||||
) -> Flash<Redirect> {
|
) -> Flash<Redirect> {
|
||||||
|
println!("{data:#?}");
|
||||||
|
|
||||||
let user = User::find_by_id(db, data.id).await;
|
let user = User::find_by_id(db, data.id).await;
|
||||||
Log::create(
|
Log::create(
|
||||||
db,
|
db,
|
||||||
|
@ -79,8 +79,24 @@
|
|||||||
<div class="w-full grid gap-3 mt-3">
|
<div class="w-full grid gap-3 mt-3">
|
||||||
<input type="hidden" name="id" value="{{ user.id }}" />
|
<input type="hidden" name="id" value="{{ user.id }}" />
|
||||||
<div class="grid sm:grid-cols-2 lg:grid-cols-4 gap-3">
|
<div class="grid sm:grid-cols-2 lg:grid-cols-4 gap-3">
|
||||||
|
{% for cluster, r in roles | group_by(attribute="cluster") %}
|
||||||
|
{{ cluster }}
|
||||||
|
<label for="{{ cluster }}" class="flex items-center cursor-pointer text-black dark:text-white hover:text-gray-900 dark:hover:text-gray-100">
|
||||||
|
<select id="{{ cluster }}" name="{{ cluster }}" class="h-8 accent-primary-600 dark:accent-primary-200 mr-2">
|
||||||
|
<option value="">None</option>
|
||||||
|
{% for role in r %}
|
||||||
|
<option value="{{ role.id }}">{{ role.name }}</option>
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
|
||||||
{% for role in roles %}
|
{% for role in roles %}
|
||||||
|
{% if not role.cluster %}
|
||||||
{{ macros::checkbox(label=role.name, name="roles[" ~ role.id ~ "]", id=loop.index , checked=role.name in user.roles, disabled=allowed_to_edit == false) }}
|
{{ macros::checkbox(label=role.name, name="roles[" ~ role.id ~ "]", id=loop.index , checked=role.name in user.roles, disabled=allowed_to_edit == false) }}
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<hr class="sm:col-span-2 lg:col-span-4 my-3" />
|
<hr class="sm:col-span-2 lg:col-span-4 my-3" />
|
||||||
{% if user.membership_pdf %}
|
{% if user.membership_pdf %}
|
||||||
|
Loading…
Reference in New Issue
Block a user