https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 --- Comment #16 from Lisette Scheer <lisette@bywatersolutions.com> --- Created attachment 212716 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212716&action=edit Bug 41550: Add Koha::AccessControl::Role and patron role grants This adds roles, grants of roles and permissions to patrons, and the patron methods that read them. It also loads the default system roles. Roles: - Koha::AccessControl::Role(s): a named set of permissions that can inherit every permission of a parent role. permissions() includes inherited permissions unless { inherited => 0 } is passed. add_permission / remove_permission manage the role's own permissions. ancestor_ids reads the role tree in one query. store refuses a role that would inherit from itself, directly or indirectly. Grants: - Koha::AccessControl::UserRole(s) and UserPermission(s): a role or a single permission granted to a patron, either everywhere (library_id NULL) or at one library. store refuses duplicate grants itself, because the database's unique key treats NULL library_id values as distinct, and locks the patron's row while checking, so two saves at once can't both add the same grant. Koha::Patron: - access_control_roles, grant_access_control_role, revoke_access_control_role, access_control_user_roles, access_control_user_permissions and access_control_permissions (named so they don't read like ERM's user roles or the housebound role). Without a library_id only everywhere grants apply; with a library_id, that library's grants apply too. access_control_permissions is the union of the patron's role permissions (including inherited ones) and their direct grants. Default roles, all system roles: - superlibrarian, holding *:*:* - legacy_<flag> for every other flag, holding every permission mapped from that flag. Granting a whole flag in the legacy interface will become a grant of this role. legacy_editcatalogue and legacy_tools include the unrestricted item editing permissions (bug 41845). Protections: - Superlibrarian access only comes from the superlibrarian role: no role can inherit from it, no other role can hold *:*:*, and *:*:* can't be granted directly. Otherwise a custom role inheriting from superlibrarian would keep that access after the legacy flag is removed, and get round ProtectSuperlibrarianPrivileges. - System roles can't be created, changed (renamed, given a parent, made non-system, or given or stripped of permissions) or deleted. Giving legacy_catalogue the parent legacy_borrowers, for example, would hand the borrowers permissions to everyone with catalogue. - That includes the legacy_* roles when nobody holds them: giving a staff member a whole legacy permission module grants its legacy_* role, and their legacy permissions are worked out back from it (bug 44275), so a deleted role would break saving permissions. A module's legacy role goes with the database update that retires its legacy permission. The system roles follow the access control permissions at the end of userpermissions.sql. The database update adds the same rows. Nothing uses these for permission checks yet. Test plan: 1. Apply the patch 2. ktd --shell 3. updatedatabase 4. koha-mysql kohadev 5. SELECT COUNT(*) FROM access_control_roles; Result: 32 SELECT COUNT(*) FROM access_control_role_permissions; Result: 198 6. updatedatabase again, the counts don't change 7. Try to delete legacy_tools, a system role nobody holds: perl -e 'use Koha::AccessControl::Roles; Koha::AccessControl::Roles->find({ code => "legacy_tools" })->delete' Result: Exception 'Koha::Exceptions::AccessControl::SystemRole' thrown 'System roles cannot be created, changed or deleted' with code => legacy_tools 8. prove t/db_dependent/Koha/AccessControl/ 9. prove t/db_dependent/Koha/Patron.t t/db_dependent/TestBuilder.t 10. Do a fresh install (in KTD, reset_all does this), confirm the same counts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.