https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 --- Comment #17 from Lisette Scheer <lisette@bywatersolutions.com> --- Created attachment 212717 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212717&action=edit Bug 41550: (follow-up) Log changes to roles and to patrons' grants Changing which roles exist, what they hold, or who holds them changes what staff may do, so it is written to the action logs. Roles (module ACCESS_CONTROL, object the role id), always logged, with no system preference to turn it off, since a change reaches everyone holding the role: - CREATE, MODIFY (with the changed values in the diff) and DELETE - ADD_PERMISSION and REMOVE_PERMISSION, with the role code and the permission (resource:action:scope) Grants to a patron (module MEMBERS, object the borrowernumber), when BorrowersLog is on, like other changes to a patron's permissions: - GRANT_ROLE and REVOKE_ROLE, with the role and the library the grant is limited to - GRANT_PERMISSION and REVOKE_PERMISSION, with the permission and library Every entry has a diff: CREATE and grants or added permissions show the values as added, DELETE and revokes or removed permissions show them as removed, and MODIFY shows the old and new values. The logging is in the classes, so the staff interface, the REST API and scripts all log the same way, including deleting a set of grants. Deleting a role revokes it from its holders first, so each revoke is logged instead of disappearing with the role. Test plan: 1. ktd --shell 2. prove t/db_dependent/Koha/AccessControl/Roles.t t/db_dependent/Koha/AccessControl/Grants.t 3. Create a role, rename it, add and remove a permission, then delete it: perl -e 'use Koha::AccessControl::Role; use Koha::AccessControl::Permissions; my $r = Koha::AccessControl::Role->new({ code => "log_test", name => "Log test" })->store; $r->name("Log test renamed")->store; my $p = Koha::AccessControl::Permissions->find_by_string("patrons:list:own_library"); $r->add_permission($p); $r->remove_permission($p); $r->delete' 4. koha-mysql kohadev 5. SELECT action, diff FROM action_logs WHERE module = 'ACCESS_CONTROL' ORDER BY action_id; Result: CREATE, MODIFY, ADD_PERMISSION, REMOVE_PERMISSION and DELETE; the diffs show the role as added, the name changed, the permission added ({"A":"patrons:list:own_library"}) and removed ({"R":"patrons:list:own_library"}), and the role removed 6. Turn on BorrowersLog: UPDATE systempreferences SET value = 1 WHERE variable = 'BorrowersLog'; 7. Exit koha-mysql, then grant a role to the staff member with cardnumber 42 and revoke it: perl -e 'use Koha::Patrons; use Koha::AccessControl::Role; my $patron = Koha::Patrons->find({ cardnumber => "42" }); my $role = Koha::AccessControl::Role->new({ code => "log_test", name => "Log test" })->store; $patron->grant_access_control_role($role); $patron->revoke_access_control_role($role); $role->delete' 8. koha-mysql kohadev 9. SELECT action, diff FROM action_logs WHERE module = 'MEMBERS' AND action LIKE '%_ROLE' ORDER BY action_id; Result: GRANT_ROLE with the role as added ({"A":"log_test"}) and REVOKE_ROLE with it as removed ({"R":"log_test"}) 10. With BorrowersLog off, repeat 7: nothing new is logged under MEMBERS Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.