more self-explanatory roles + formatted_names for roles
This commit is contained in:
parent
b2e07653e6
commit
68cf563964
@ -28,7 +28,10 @@ CREATE TABLE IF NOT EXISTS "family" (
|
||||
CREATE TABLE IF NOT EXISTS "role" (
|
||||
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"name" text NOT NULL UNIQUE,
|
||||
"cluster" text
|
||||
"formatted_name" text,
|
||||
"desc" text,
|
||||
"cluster" text,
|
||||
"hide_in_lists" BOOLEAN NOT NULL DEFAULT false
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "user_role" (
|
||||
|
@ -7,6 +7,9 @@ use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
|
||||
pub struct Role {
|
||||
pub(crate) id: i64,
|
||||
pub(crate) name: String,
|
||||
pub(crate) formatted_name: Option<String>,
|
||||
pub(crate) desc: Option<String>,
|
||||
pub(crate) hide_in_lists: bool,
|
||||
pub(crate) cluster: Option<String>,
|
||||
}
|
||||
|
||||
@ -18,17 +21,20 @@ impl Display for Role {
|
||||
|
||||
impl Role {
|
||||
pub async fn all(db: &SqlitePool) -> Vec<Role> {
|
||||
sqlx::query_as!(Role, "SELECT id, name, cluster FROM role")
|
||||
.fetch_all(db)
|
||||
.await
|
||||
.unwrap()
|
||||
sqlx::query_as!(
|
||||
Role,
|
||||
"SELECT id, name, formatted_name, desc, hide_in_lists, cluster FROM role"
|
||||
)
|
||||
.fetch_all(db)
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub async fn find_by_id(db: &SqlitePool, name: i32) -> Option<Self> {
|
||||
sqlx::query_as!(
|
||||
Self,
|
||||
"
|
||||
SELECT id, name, cluster
|
||||
SELECT id, name, formatted_name, desc, hide_in_lists, cluster
|
||||
FROM role
|
||||
WHERE id like ?
|
||||
",
|
||||
@ -42,7 +48,7 @@ WHERE id like ?
|
||||
sqlx::query_as!(
|
||||
Self,
|
||||
"
|
||||
SELECT id, name, cluster
|
||||
SELECT id, name, formatted_name, desc, hide_in_lists, cluster
|
||||
FROM role
|
||||
WHERE id like ?
|
||||
",
|
||||
@ -57,7 +63,7 @@ WHERE id like ?
|
||||
sqlx::query_as!(
|
||||
Self,
|
||||
"
|
||||
SELECT id, name, cluster
|
||||
SELECT id, name, formatted_name, desc, hide_in_lists, cluster
|
||||
FROM role
|
||||
WHERE cluster = ?
|
||||
",
|
||||
@ -72,7 +78,7 @@ WHERE cluster = ?
|
||||
sqlx::query_as!(
|
||||
Self,
|
||||
"
|
||||
SELECT id, name, cluster
|
||||
SELECT id, name, formatted_name, desc, hide_in_lists, cluster
|
||||
FROM role
|
||||
WHERE name like ?
|
||||
",
|
||||
@ -87,7 +93,7 @@ WHERE name like ?
|
||||
sqlx::query_as!(
|
||||
Self,
|
||||
"
|
||||
SELECT id, name, cluster
|
||||
SELECT id, name, formatted_name, desc, hide_in_lists, cluster
|
||||
FROM role
|
||||
WHERE name like ?
|
||||
",
|
||||
|
@ -315,7 +315,7 @@ ASKÖ Ruderverein Donau Linz", self.name),
|
||||
pub async fn real_roles(&self, db: &SqlitePool) -> Vec<Role> {
|
||||
sqlx::query_as!(
|
||||
Role,
|
||||
"SELECT r.id, r.name, r.cluster
|
||||
"SELECT r.id, r.name, r.cluster, r.formatted_name, r.desc, r.hide_in_lists
|
||||
FROM role r
|
||||
JOIN user_role ur ON r.id = ur.role_id
|
||||
JOIN user u ON u.id = ur.user_id
|
||||
|
@ -3,3 +3,25 @@ INSERT INTO user(name) VALUES('Marie');
|
||||
INSERT INTO "user_role" (user_id, role_id) VALUES((SELECT id from user where name = 'Marie'),(SELECT id FROM role where name = 'Donau Linz'));
|
||||
INSERT INTO user(name) VALUES('Philipp');
|
||||
INSERT INTO "user_role" (user_id, role_id) VALUES((SELECT id from user where name = 'Philipp'),(SELECT id FROM role where name = 'Donau Linz'));
|
||||
|
||||
|
||||
ALTER TABLE role ADD COLUMN formatted_name text;
|
||||
ALTER TABLE role ADD COLUMN desc text;
|
||||
ALTER TABLE role ADD COLUMN hide_in_lists BOOLEAN NOT NULL DEFAULT false;
|
||||
UPDATE role SET hide_in_lists=true WHERE name='paid';
|
||||
UPDATE role SET hide_in_lists=true WHERE name='ergo';
|
||||
UPDATE role SET desc='Can do ANYTHING.' WHERE name='admin';
|
||||
UPDATE role SET desc='Kann Ausfahrten ausschreiben und kann alle Boote die in Linz lagern verwenden.', formatted_name='Steuerperson' WHERE name='cox';
|
||||
UPDATE role SET desc='Darf reparierte Bootschäden verifizieren und wird über Bootsschäden informiert.', formatted_name='Bootsreparateur' WHERE name='tech';
|
||||
UPDATE role SET desc='' WHERE name='Rechnungsprüfer';
|
||||
UPDATE role SET desc='Darf Boote die in Ottensheim lagern verwenden.' WHERE name='Rennrudern';
|
||||
UPDATE role SET desc='Haben zahlreiche Berechtigungen, siehe den Vorstand-Block im Menü.' WHERE name='Vorstand';
|
||||
UPDATE role SET desc='Können Events ausschreiben und bearbeiten.' WHERE name='manage_events';
|
||||
UPDATE role SET desc='Sieht Details zum Schnupperkurs (Teilnehmer, Bezahlstatus, ...)' WHERE name='schnupper-betreuer';
|
||||
UPDATE role SET desc='' WHERE name='kassier';
|
||||
UPDATE role SET desc='' WHERE name='schriftfuehrer';
|
||||
UPDATE role SET desc='Entfernt bei der Gebührenberechnung die Einschreibgebühr.' WHERE name='no-einschreibgebuehr';
|
||||
UPDATE role SET desc='Es können Logbucheinträge im Nachhinein hinzugefügt werden. Idealerweise diese Rolle nur kurzfristig vergeben.' WHERE name='allow-retroactive-logbookentries';
|
||||
UPDATE role SET desc='Erlaubt den Login auf der Wordpress-Website um zB Artikel zu schreiben.' WHERE name='allow_website_login';
|
||||
UPDATE role SET desc='Muss nur den halben Rennruderbeitrag bezahlen (da zB erst in der 2. Jahreshälfte dazugestoßen wurde)' WHERE name='half-rennrudern';
|
||||
UPDATE role SET desc='Muss keinen Rennruderbeitrag bezahlen, obwohl man in Rennruder-Gruppe ist.' WHERE name='renntrainer';
|
||||
|
@ -60,9 +60,15 @@
|
||||
Rollen:
|
||||
<ul class="list-disc ms-4">
|
||||
{% for role in user.proper_roles -%}
|
||||
{% if not role.cluster %}
|
||||
{% if not role.cluster and not role.hide_in_lists %}
|
||||
<li>
|
||||
<strong>{{ role.name }}:</strong> Hier folgt eine Beschreibung der Rolle
|
||||
<strong>
|
||||
{% if role.formatted_name %}
|
||||
{{ role.formatted_name }}
|
||||
{% else %}
|
||||
{{ role.name }}
|
||||
{% endif %}
|
||||
</strong> {{ role.desc }}
|
||||
{% if allowed_to_edit %}
|
||||
<a href="/admin/user/{{ user.id }}/remove-role/{{ role.id }}"
|
||||
onclick="return confirm('Willst du die Rolle \'{{ role.name }}\' von {{ user.name }} wirklich entfernen?');">🗑️</a>
|
||||
@ -78,8 +84,12 @@
|
||||
<fieldset>
|
||||
<select name="role_id">
|
||||
{% for role in roles %}
|
||||
{% if not role.cluster and role not in user.proper_roles %}
|
||||
<option value="{{ role.id }}">{{ role.name }}</option>
|
||||
{% if not role.cluster and role not in user.proper_roles and not role.hide_in_lists %}
|
||||
<option value="{{ role.id }}">{% if role.formatted_name %}
|
||||
{{ role.formatted_name }}
|
||||
{% else %}
|
||||
{{ role.name }}
|
||||
{% endif %} {% if role.desc %} ({{ role.desc }}) {% endif %}</option>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
Loading…
x
Reference in New Issue
Block a user