Files
ms1inscription-v5/sql/MSIN-eve-acces-v2-phase2-multi-granular.sql
stephan 9310c12536 Add event access management functions and enhance mobile permissions
This commit introduces several new functions for managing event access, including `fxEveAccesComHasV2ForEvent`, `fxEveAccesGrantExtra`, and `fxEveAccesRevokeExtra`, which facilitate the granting and revocation of permissions for events. Additionally, the mobile registration logic is updated with the new `fxInscrMobileCanDo` function to streamline permission checks for various actions. These enhancements improve the overall access control and user experience across the application.
2026-06-19 13:20:52 -04:00

265 lines
9.4 KiB
SQL

/*
MSIN - Acces evenement v2 (phase 2)
Multi-kits par compte/evenement + permissions a l'unite + granularite mobile.
Executer APRES :
MSIN-eve-acces-v2-phase1-tables.sql
MSIN-eve-acces-v2-phase1-seed.sql
MSIN-eve-acces-v2-bib-qr-seed.sql (si deja applique)
Safe en prod pilote : n'enleve aucun acces existant.
*/
SET NAMES utf8mb4;
/* ------------------------------------------------------------------
1. Niveau permission : page | action | api | report
------------------------------------------------------------------ */
ALTER TABLE `inscriptions_eve_permissions`
ADD COLUMN `perm_scope` enum('page','action','api','report') NOT NULL DEFAULT 'api'
AFTER `perm_group`;
UPDATE `inscriptions_eve_permissions` SET `perm_scope` = 'api'
WHERE `perm_group` = 'api';
UPDATE `inscriptions_eve_permissions` SET `perm_scope` = 'report'
WHERE `perm_group` = 'reports';
UPDATE `inscriptions_eve_permissions` SET `perm_scope` = 'page'
WHERE `perm_key` IN (
'inscriptions.view', 'inscriptions_mobile.view',
'dossards.view', 'epreuves.view', 'rabais.view', 'team.view'
);
UPDATE `inscriptions_eve_permissions` SET `perm_scope` = 'action'
WHERE `perm_key` IN (
'inscriptions.edit', 'dossards.manage', 'epreuves.edit_qte',
'rabais.manage', 'emails.send', 'registrations.scan',
'team.invite', 'team.manage', 'tools.qr_test'
);
/* ------------------------------------------------------------------
2. Multi-kits : plusieurs roles par compte x evenement
------------------------------------------------------------------ */
ALTER TABLE `inscriptions_eve_acces`
DROP INDEX `uk_com_eve`;
ALTER TABLE `inscriptions_eve_acces`
ADD UNIQUE KEY `uk_com_eve_role` (`com_id`, `eve_id`, `role_id`);
/* ------------------------------------------------------------------
3. Permissions additionnelles a l'unite (hors kit)
------------------------------------------------------------------ */
CREATE TABLE IF NOT EXISTS `inscriptions_eve_acces_extra` (
`ae_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`com_id` int(10) unsigned NOT NULL,
`eve_id` int(10) unsigned NOT NULL,
`perm_key` varchar(64) NOT NULL,
`ae_statut` enum('actif','revoke') NOT NULL DEFAULT 'actif',
`ae_granted_by` int(10) unsigned DEFAULT NULL,
`ae_note` varchar(255) DEFAULT NULL,
`ae_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`ae_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
`ae_revoked_at` datetime DEFAULT NULL,
PRIMARY KEY (`ae_id`),
UNIQUE KEY `uk_com_eve_perm` (`com_id`, `eve_id`, `perm_key`),
KEY `idx_ae_eve_actif` (`eve_id`, `ae_statut`),
KEY `idx_ae_com_actif` (`com_id`, `ae_statut`),
CONSTRAINT `fk_ae_perm`
FOREIGN KEY (`perm_key`) REFERENCES `inscriptions_eve_permissions` (`perm_key`)
ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
COMMENT='Grants permission unitaire v2 (complement des kits)';
/* ------------------------------------------------------------------
4. Permissions actions mobile (niveau fonction dans la fiche)
------------------------------------------------------------------ */
INSERT INTO `inscriptions_eve_permissions`
(`perm_key`, `perm_group`, `perm_scope`, `perm_label_fr`, `perm_label_en`,
`perm_description_fr`, `perm_description_en`, `perm_phase`, `perm_actif`, `perm_tri`)
VALUES
('inscriptions_mobile.statut_edit', 'inscriptions', 'action',
'Mobile : statut course', 'Mobile: race status',
'Modifier le statut course sur la fiche mobile', NULL, 2, 1, 131),
('inscriptions_mobile.bib_edit', 'inscriptions', 'action',
'Mobile : no dossard', 'Mobile: bib number',
'Modifier le numero de dossard sur la fiche mobile', NULL, 2, 1, 132),
('inscriptions_mobile.bib_remis', 'inscriptions', 'action',
'Mobile : dossard remis', 'Mobile: bib handed out',
'Marquer dossard remis sur la fiche mobile', NULL, 2, 1, 133),
('inscriptions_mobile.edit', 'inscriptions', 'action',
'Mobile : modifier fiche', 'Mobile: edit registration',
'Bouton modifier inscription sur fiche mobile', NULL, 2, 1, 134),
('inscriptions_mobile.cancel', 'inscriptions', 'action',
'Mobile : annuler', 'Mobile: cancel',
'Annuler une inscription depuis la fiche mobile', NULL, 2, 1, 135),
('inscriptions_mobile.restore', 'inscriptions', 'action',
'Mobile : retablir', 'Mobile: restore',
'Retablir une inscription annulee depuis la fiche mobile', NULL, 2, 1, 136)
ON DUPLICATE KEY UPDATE
`perm_group` = VALUES(`perm_group`),
`perm_scope` = VALUES(`perm_scope`),
`perm_label_fr` = VALUES(`perm_label_fr`),
`perm_label_en` = VALUES(`perm_label_en`),
`perm_description_fr` = VALUES(`perm_description_fr`),
`perm_phase` = VALUES(`perm_phase`),
`perm_actif` = VALUES(`perm_actif`),
`perm_tri` = VALUES(`perm_tri`);
UPDATE `inscriptions_eve_permissions` SET `perm_scope` = 'page'
WHERE `perm_key` = 'inscriptions_mobile.view';
/* ------------------------------------------------------------------
5. Kits : mobile_ops complet, mobile_statut (exemple granulaire)
------------------------------------------------------------------ */
INSERT INTO `inscriptions_eve_roles`
(`role_code`, `role_label_fr`, `role_label_en`, `role_description_fr`, `role_description_en`, `role_icone`, `role_systeme`, `role_actif`, `role_tri`)
VALUES
('mobile_statut', 'Mobile statuts seulement', 'Mobile status only',
'Fiche mobile : consulter et modifier les statuts (pas le dossard)',
'Mobile sheet: view and edit status only (not bib number)',
'fa-flag-checkered', 1, 1, 25)
ON DUPLICATE KEY UPDATE
`role_label_fr` = VALUES(`role_label_fr`),
`role_label_en` = VALUES(`role_label_en`),
`role_description_fr` = VALUES(`role_description_fr`),
`role_description_en` = VALUES(`role_description_en`),
`role_icone` = VALUES(`role_icone`),
`role_actif` = VALUES(`role_actif`),
`role_tri` = VALUES(`role_tri`);
DELETE erp FROM inscriptions_eve_role_permissions erp
INNER JOIN inscriptions_eve_roles r ON r.role_id = erp.role_id
WHERE r.role_code = 'owner';
INSERT INTO inscriptions_eve_role_permissions (role_id, perm_key)
SELECT r.role_id, p.perm_key
FROM inscriptions_eve_roles r
CROSS JOIN inscriptions_eve_permissions p
WHERE r.role_code = 'owner'
AND p.perm_actif = 1;
DELETE erp FROM inscriptions_eve_role_permissions erp
INNER JOIN inscriptions_eve_roles r ON r.role_id = erp.role_id
WHERE r.role_code = 'mobile_ops';
INSERT INTO inscriptions_eve_role_permissions (role_id, perm_key)
SELECT r.role_id, p.perm_key
FROM inscriptions_eve_roles r
INNER JOIN inscriptions_eve_permissions p
ON p.perm_key IN (
'events.list', 'events.view', 'registrations.view', 'registrations.scan',
'inscriptions_mobile.view',
'inscriptions_mobile.statut_edit', 'inscriptions_mobile.bib_edit',
'inscriptions_mobile.bib_remis', 'inscriptions_mobile.edit',
'inscriptions_mobile.cancel', 'inscriptions_mobile.restore'
)
AND p.perm_actif = 1
WHERE r.role_code = 'mobile_ops';
DELETE erp FROM inscriptions_eve_role_permissions erp
INNER JOIN inscriptions_eve_roles r ON r.role_id = erp.role_id
WHERE r.role_code = 'mobile_readonly';
INSERT INTO inscriptions_eve_role_permissions (role_id, perm_key)
SELECT r.role_id, p.perm_key
FROM inscriptions_eve_roles r
INNER JOIN inscriptions_eve_permissions p
ON p.perm_key IN (
'events.list', 'events.view', 'registrations.view', 'inscriptions_mobile.view'
)
AND p.perm_actif = 1
WHERE r.role_code = 'mobile_readonly';
DELETE erp FROM inscriptions_eve_role_permissions erp
INNER JOIN inscriptions_eve_roles r ON r.role_id = erp.role_id
WHERE r.role_code = 'mobile_statut';
INSERT INTO inscriptions_eve_role_permissions (role_id, perm_key)
SELECT r.role_id, p.perm_key
FROM inscriptions_eve_roles r
INNER JOIN inscriptions_eve_permissions p
ON p.perm_key IN (
'events.list', 'events.view', 'registrations.view', 'inscriptions_mobile.view',
'inscriptions_mobile.statut_edit', 'inscriptions_mobile.bib_remis'
)
AND p.perm_actif = 1
WHERE r.role_code = 'mobile_statut';
/* ------------------------------------------------------------------
6. Vues : union kits multiples + extras
------------------------------------------------------------------ */
DROP VIEW IF EXISTS `v_eve_acces_permissions`;
DROP VIEW IF EXISTS `v_eve_acces_actif`;
CREATE VIEW `v_eve_acces_actif` AS
SELECT
ea.ea_id,
ea.com_id,
ea.eve_id,
ea.role_id,
r.role_code,
r.role_label_fr,
r.role_label_en,
ea.ea_statut,
ea.ea_expires_at,
ea.ea_expire_days,
ea.ea_granted_by,
ea.ea_created_at
FROM inscriptions_eve_acces ea
INNER JOIN inscriptions_eve_roles r
ON r.role_id = ea.role_id
AND r.role_actif = 1
WHERE ea.ea_statut = 'actif'
AND (ea.ea_expires_at IS NULL OR ea.ea_expires_at > NOW());
CREATE VIEW `v_eve_acces_permissions` AS
SELECT
v.ea_id,
v.com_id,
v.eve_id,
v.role_id,
v.role_code,
erp.perm_key,
p.perm_group,
p.perm_scope,
p.perm_label_fr,
p.perm_phase
FROM v_eve_acces_actif v
INNER JOIN inscriptions_eve_role_permissions erp
ON erp.role_id = v.role_id
INNER JOIN inscriptions_eve_permissions p
ON p.perm_key = erp.perm_key
AND p.perm_actif = 1
UNION
SELECT
NULL AS ea_id,
ae.com_id,
ae.eve_id,
NULL AS role_id,
'extra' AS role_code,
ae.perm_key,
p.perm_group,
p.perm_scope,
p.perm_label_fr,
p.perm_phase
FROM inscriptions_eve_acces_extra ae
INNER JOIN inscriptions_eve_permissions p
ON p.perm_key = ae.perm_key
AND p.perm_actif = 1
WHERE ae.ae_statut = 'actif';