2023-09-29 21:17:31 +02:00
|
|
|
|
{# -*- mode: jinja-html -*- #}
|
|
|
|
|
{# -*- Edition des rôles/permissions -*- #}
|
|
|
|
|
{% extends "base.j2" %}
|
2023-11-15 20:38:51 +01:00
|
|
|
|
{% import 'wtf.j2' as wtf %}
|
2023-09-29 21:17:31 +02:00
|
|
|
|
|
|
|
|
|
{% block styles %}
|
|
|
|
|
{{super()}}
|
|
|
|
|
<link rel="stylesheet" href="{{ scu.STATIC_DIR }}/css/role_editor.css">
|
|
|
|
|
{% endblock %}
|
|
|
|
|
|
|
|
|
|
{% block app_content %}
|
|
|
|
|
|
|
|
|
|
<h1>Définition des rôles et leurs permissions</h1>
|
|
|
|
|
|
|
|
|
|
<div class="help">Les rôles sont associés à un ensemble de permissions. Chaque
|
|
|
|
|
utilisateur peut avoir un nombre quelconque de rôles <em>dans chaque
|
2023-11-15 20:38:51 +01:00
|
|
|
|
département</em>.
|
2023-09-29 21:17:31 +02:00
|
|
|
|
Sur cette page vous pouvez modifier les permissions associée à chaque rôle, ou créer de nouveaux rôles.
|
|
|
|
|
|
|
|
|
|
Les rôles <b>en gras</b> sont les rôles standards de ScoDoc.
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{# <div class="links">
|
|
|
|
|
<a class="stdlink" href="{{ url_for('scodoc.users') }}">liste des comptes utilisateurs</a>
|
|
|
|
|
</div> #}
|
|
|
|
|
|
|
|
|
|
<main class="roles-editor">
|
|
|
|
|
<div class="re-row re-row-titres">
|
|
|
|
|
<div class="re-cell role-titre permission-titre"></div>
|
|
|
|
|
{% for role in roles %}
|
|
|
|
|
<div class="re-cell role-titre {{'role-standard' if role.name in SCO_ROLES_DEFAULTS else ''}}">
|
|
|
|
|
<a class="discretelink" href="{{
|
|
|
|
|
url_for('scodoc.role_info', role_name=role.name)
|
|
|
|
|
}}">{{role.name}}</a>
|
|
|
|
|
</div>
|
|
|
|
|
{% endfor %}
|
|
|
|
|
</div>
|
|
|
|
|
{% for permission_name in permissions_names %}
|
|
|
|
|
<div class="re-row re-row-perm">
|
2023-11-15 20:38:51 +01:00
|
|
|
|
<div class="re-cell permission-titre" style="position: relative;">
|
2023-09-29 21:17:31 +02:00
|
|
|
|
<div class="with_scoplement">
|
|
|
|
|
<div><a class="discretelink" href="{{
|
|
|
|
|
url_for('scodoc.permission_info', perm_name=permission_name)
|
|
|
|
|
}}">{{permission_name}}</a></div>
|
|
|
|
|
<div class="scoplement">
|
|
|
|
|
{{ Permission.description.get(permission_name) }}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{% for role in roles %}
|
|
|
|
|
<div class="re-cell {{'role-standard' if role.name in SCO_ROLES_DEFAULTS else ''}}">
|
|
|
|
|
<label>
|
2023-11-15 20:38:51 +01:00
|
|
|
|
<input type="checkbox"
|
2023-09-29 21:17:31 +02:00
|
|
|
|
name="{{role.id}}-{{Permission.get_by_name(permission_name)}}"
|
|
|
|
|
data-role="{{role.name}}"
|
|
|
|
|
data-permission="{{permission_name}}"
|
|
|
|
|
{{'checked' if role.has_permission(Permission.get_by_name(permission_name)) else ''}}
|
|
|
|
|
>
|
|
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
{% endfor %}
|
|
|
|
|
</div>
|
|
|
|
|
{% endfor %}
|
|
|
|
|
</main>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
➕ <a class="stdlink" href="{{url_for('scodoc.role_create')}}">Créer un nouveau rôle</a>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div style="margin-top: 16px;">
|
|
|
|
|
🛟 <a class="stdlink" href="{{url_for('auth.reset_standard_roles_permissions')}}">Remettre
|
|
|
|
|
les permissions des rôles standards à leurs valeurs par défaut</a>
|
|
|
|
|
<em>(efface les modifications apportées aux rôles <tt>{{ ', '.join(SCO_ROLES_DEFAULTS.keys()) }}</tt>)</em>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
|
|
async function associe_role_permission(event) {
|
|
|
|
|
// /role/<string:role_name>/add_permission/<string:perm_name>"
|
|
|
|
|
const method = event.target.checked ? "/add_permission/" : "/remove_permission/";
|
2024-01-06 14:32:06 +01:00
|
|
|
|
const url = `/ScoDoc/api/role/${event.target.dataset.role}${method}${event.target.dataset.permission}`;
|
2023-09-29 21:17:31 +02:00
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(
|
|
|
|
|
url,
|
|
|
|
|
{
|
|
|
|
|
method: "POST",
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
if (data.role_name != event.target.dataset.role) {
|
|
|
|
|
console.error("Fetch error, received:", data);
|
|
|
|
|
alert("Une erreur est survenue");
|
|
|
|
|
location.reload();
|
|
|
|
|
}
|
|
|
|
|
sco_message(`rôle ${event.target.dataset.role} enregistré`);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Fetch error:", error);
|
|
|
|
|
sco_message("Erreur réseau: valeur non enregistrée");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-15 20:38:51 +01:00
|
|
|
|
document.querySelectorAll("label").forEach(btn => {
|
|
|
|
|
btn.addEventListener("mousedown", (event) => { event.preventDefault() })
|
2023-09-29 21:17:31 +02:00
|
|
|
|
});
|
|
|
|
|
document.querySelectorAll(".re-cell input").forEach(input => {
|
2023-11-15 20:38:51 +01:00
|
|
|
|
input.addEventListener("input", associe_role_permission)
|
2023-09-29 21:17:31 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
2023-11-15 20:38:51 +01:00
|
|
|
|
{% endblock %}
|