Roles stage 1: Admin > Roles rebuilt showing each role's access per module as level-colored pills or Admin - everything, its agents with a link to Users filtered by role, search, Current and Archived tabs, and Edit, Copy, Archive, Restore and Delete greyed out with the reason when blocked; one role window for New, Edit and Copy with an Admin switch and a None, Read, Modify or Full level per module, each level listing what it allows, Reports limited to None and Read, and a copy dropping the Built-in description prefix; hardcoded role 3 checks replaced by guards so admin can't be taken off your own role or the only admins' role, archive needs no active agents, delete needs no agents at all, and names are unique in any case with the description optional; Administrator role can now be opened and renamed; role names escaped in flash messages, fixing an XSS; audit log records what changed on a role; lookupUserPermission reads the role's levels once per request instead of one query per check; new functions/roles.php, shared role_form.php and js/role_form.js; database 3.1.6 removes orphaned and duplicate user_role_permissions rows, clamps levels to 3 and adds a primary key on role and module; changelog updated

This commit is contained in:
johnnyq
2026-10-17 20:43:45 -04:00
parent bf89a86ab1
commit 5e87f6fa25
13 changed files with 798 additions and 571 deletions

View File

@@ -0,0 +1,25 @@
<?php
/*
* ITFlow - Database update to version 3.1.6 (from 3.1.5)
* Included by admin/database_updates.php - do not access directly
*/
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
// A role's level for each module - one row each. Rows left behind by a
// role or module that is gone, or of no access, are dropped; a module a
// role has twice keeps its highest level, held to 1 to 3. Then a primary
// key, so it can only have one.
mysqli_query($mysqli, "DELETE FROM user_role_permissions
WHERE user_role_permission_level <= 0
OR user_role_id NOT IN (SELECT role_id FROM user_roles)
OR module_id NOT IN (SELECT module_id FROM modules)");
mysqli_query($mysqli, "CREATE TEMPORARY TABLE role_permissions_kept AS
SELECT user_role_id, module_id, LEAST(MAX(user_role_permission_level), 3) AS kept_level
FROM user_role_permissions GROUP BY user_role_id, module_id");
mysqli_query($mysqli, "DELETE FROM user_role_permissions");
mysqli_query($mysqli, "INSERT INTO user_role_permissions (user_role_id, module_id, user_role_permission_level)
SELECT user_role_id, module_id, kept_level FROM role_permissions_kept");
mysqli_query($mysqli, "DROP TEMPORARY TABLE role_permissions_kept");
mysqli_query($mysqli, "ALTER TABLE `user_role_permissions` ADD PRIMARY KEY (`user_role_id`, `module_id`)");