Add access control for kit management in event administration. Introduce the function fxAdminCanEditEveAccesKits to validate user permissions based on email or login. Update event access page to restrict modification actions and enhance UI feedback for non-editable states, aligning with MSIN-4401 requirements for improved event management functionality.

This commit is contained in:
2026-07-13 12:31:22 -04:00
parent ccf895c8fb
commit 0fcb7dc9f8
3 changed files with 92 additions and 4 deletions

View File

@ -194,6 +194,44 @@ function fxAdminCanUsePermInspectTools() {
return !empty($_SESSION['usa_id']);
}
/**
* MSIN-4401 — Créer / modifier / supprimer les définitions de kits (pas l'assignation).
* Liste blanche courriel ou login (session usa_info = inscriptions_comptes).
*/
function fxAdminCanEditEveAccesKits() {
if (empty($_SESSION['usa_id']) || empty($_SESSION['usa_info']) || !is_array($_SESSION['usa_info'])) {
return false;
}
static $arrAllow = array(
'stephan@progiweb.ca',
);
$arrNorm = array();
foreach ($arrAllow as $strItem) {
$strItem = strtolower(trim((string)$strItem));
if ($strItem !== '') {
$arrNorm[$strItem] = true;
}
}
if (count($arrNorm) === 0) {
return false;
}
$arrCandidates = array(
strtolower(trim((string)($_SESSION['usa_info']['com_courriel'] ?? ''))),
strtolower(trim((string)($_SESSION['usa_info']['com_login'] ?? ''))),
);
foreach ($arrCandidates as $strCand) {
if ($strCand !== '' && isset($arrNorm[$strCand])) {
return true;
}
}
return false;
}
function fxAdminPermInspectModeActive() {
return fxAdminCanUsePermInspectTools() && !empty($_SESSION['ms1_perm_inspect_mode']);
}

View File

@ -20,6 +20,16 @@ $strError = '';
$intRoleId = isset($_GET['id']) ? intval($_GET['id']) : 0;
if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'duplicate':
case 'toggle':
case 'delete':
if (!fxAdminCanEditEveAccesKits()) {
header('Location: eve_acces.php?p=kits&err=' . urlencode('Modification des kits réservée.'));
exit;
}
break;
}
switch ($_GET['action']) {
case 'duplicate':
if ($intRoleId <= 0) {
@ -60,6 +70,10 @@ if (isset($_GET['action'])) {
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'save_kit') {
if (!fxAdminCanEditEveAccesKits()) {
header('Location: eve_acces.php?p=kits&err=' . urlencode('Modification des kits réservée.'));
exit;
}
$intRoleId = intval($_POST['role_id'] ?? 0);
$arrResult = fxEveAccesAdminSaveRole($_POST, $_POST['perm_keys'] ?? array());
if ($arrResult['state'] === 'ok') {
@ -119,6 +133,12 @@ include('inc_header.php');
if ($strFlash !== '' && $strError === '') {
echo '<div class="alert alert-success">' . htmlspecialchars($strFlash, ENT_QUOTES, 'UTF-8') . '</div>';
}
// MSIN-4401 — Nouveau kit réservé aux éditeurs ; lecture seule pour les autres.
if ($intRoleId <= 0 && !fxAdminCanEditEveAccesKits()) {
echo '<div class="alert alert-warning">Création de kit réservée. Vous pouvez consulter les kits existants.</div>';
fxEveAccesAdminRenderKitsList('');
break;
}
fxEveAccesAdminRenderKitForm($intRoleId, $strError);
break;
case 'assignations':

View File

@ -5,6 +5,9 @@
*/
require_once dirname(__DIR__, 2) . '/php/inc_fx_eve_acces.php';
if (!function_exists('fxAdminCanEditEveAccesKits')) {
require_once dirname(__DIR__, 2) . '/php/inc_fonctions_sl.php';
}
function fxEveAccesAdminHasDelegableColumn()
{
@ -677,16 +680,25 @@ function fxEveAccesAdminRenderKitsList($strFlash = '')
$blnActifOnly = isset($_GET['actif']) && $_GET['actif'] === '1';
$arrRoles = fxEveAccesAdminGetRolesForList($blnActifOnly);
$blnCanEditKits = fxAdminCanEditEveAccesKits();
if ($strFlash !== '') {
echo '<div class="alert alert-success">' . htmlspecialchars($strFlash, ENT_QUOTES, 'UTF-8') . '</div>';
}
?>
<div class="d-flex justify-content-between align-items-center mb-3">
<h1 class="mb-0">Kits d'accès</h1>
<?php if ($blnCanEditKits) { ?>
<a class="btn btn-success" href="eve_acces.php?p=kit">
<i class="fa fa-plus"></i> Nouveau kit
</a>
<?php } ?>
</div>
<?php if (!$blnCanEditKits) { ?>
<div class="alert alert-info py-2">
Lecture seule : vous pouvez consulter les kits. Création / modification réservées.
Lassignation aux comptes reste disponible sur la fiche compte.
</div>
<?php } ?>
<div class="card mb-3 border-info">
<div class="card-header py-2 bg-light">
@ -778,9 +790,11 @@ function fxEveAccesAdminRenderKitsList($strFlash = '')
<?php } ?>
</td>
<td class="text-right text-nowrap">
<a class="btn btn-sm btn-primary" href="eve_acces.php?p=kit&amp;id=<?= intval($row['role_id']) ?>" title="Modifier">
<i class="fa fa-pencil"></i>
<a class="btn btn-sm btn-primary" href="eve_acces.php?p=kit&amp;id=<?= intval($row['role_id']) ?>"
title="<?= $blnCanEditKits ? 'Modifier' : 'Voir' ?>">
<i class="fa <?= $blnCanEditKits ? 'fa-pencil' : 'fa-eye' ?>"></i>
</a>
<?php if ($blnCanEditKits) { ?>
<a class="btn btn-sm btn-secondary" href="eve_acces.php?action=duplicate&amp;id=<?= intval($row['role_id']) ?>"
title="Dupliquer">
<i class="fa fa-copy"></i>
@ -802,6 +816,7 @@ function fxEveAccesAdminRenderKitsList($strFlash = '')
<i class="fa fa-trash"></i>
</span>
<?php } ?>
<?php } ?>
</td>
</tr>
<?php
@ -835,6 +850,8 @@ function fxEveAccesAdminRenderKitForm($intRoleId, $strError = '')
}
$blnCodeLocked = ($row !== null && ($row['role_code'] ?? '') === 'migration_legacy');
$blnCanEditKits = fxAdminCanEditEveAccesKits();
$strDisabled = $blnCanEditKits ? '' : ' disabled';
$arrDelete = ($intRoleId > 0) ? fxEveAccesAdminCanDeleteRole($intRoleId) : array('can' => false, 'message' => '');
$arrCatalog = fxEveAccesGetCatalogPermissions(null, true);
$arrByGroup = array();
@ -870,11 +887,21 @@ function fxEveAccesAdminRenderKitForm($intRoleId, $strError = '')
<i class="fa fa-chevron-left"></i> Retour à la liste
</a>
</div>
<h1><?= $intRoleId > 0 ? 'Modifier le kit' : 'Nouveau kit' ?></h1>
<h1><?php
if (!$blnCanEditKits) {
echo 'Voir le kit';
} else {
echo $intRoleId > 0 ? 'Modifier le kit' : 'Nouveau kit';
}
?></h1>
<?php if (!$blnCanEditKits) { ?>
<div class="alert alert-info py-2">Lecture seule — vous ne pouvez pas modifier ce kit.</div>
<?php } ?>
<form method="post" action="eve_acces.php?p=kit<?= $intRoleId > 0 ? '&amp;id=' . intval($intRoleId) : '' ?>">
<form method="post" action="eve_acces.php?p=kit<?= $intRoleId > 0 ? '&amp;id=' . intval($intRoleId) : '' ?>"<?= $blnCanEditKits ? '' : ' onsubmit="return false;"' ?>>
<input type="hidden" name="action" value="save_kit">
<input type="hidden" name="role_id" value="<?= intval($intRoleId) ?>">
<fieldset<?= $strDisabled ?>>
<div class="card mb-3">
<div class="card-header">Identité</div>
@ -1039,6 +1066,7 @@ function fxEveAccesAdminRenderKitForm($intRoleId, $strError = '')
</div>
</div>
<?php if ($blnCanEditKits) { ?>
<button type="submit" class="btn btn-success">
<i class="fa fa-save"></i> Enregistrer
</button>
@ -1053,6 +1081,8 @@ function fxEveAccesAdminRenderKitForm($intRoleId, $strError = '')
<i class="fa fa-info-circle"></i> <?= htmlspecialchars($arrDelete['message'], ENT_QUOTES, 'UTF-8') ?>
</span>
<?php } ?>
<?php } ?>
</fieldset>
</form>
<?php if ($intRoleId > 0) {