[Bug 41550] New: Add Koha::Role object
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 Bug ID: 41550 Summary: Add Koha::Role object Initiative type: --- Sponsorship --- status: Product: Koha Version: unspecified Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: Architecture, internals, and plumbing Assignee: koha-bugs@lists.koha-community.org Reporter: lisette@bywatersolutions.com QA Contact: testopia@bugs.koha-community.org For RBAC -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=41549 CC| |martin.renvoize@openfifth.c | |o.uk Blocks| |20813 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20813 [Bug 20813] Revamp user permissions system -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 --- Comment #1 from Lisette Scheer <lisette@bywatersolutions.com> --- Make the object, create deafult system roles, add admin ui for role management -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |41551 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41551 [Bug 41551] Build migration tool for new permissions -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |38137 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38137 [Bug 38137] Refactor Auth to check the new Koha::Permissions and Koha::Roles objects -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dcook@prosentient.com.au -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 Jonathan Druart <jonathan.druart@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jonathan.druart@gmail.com --- Comment #2 from Jonathan Druart <jonathan.druart@gmail.com> --- I would suggest to group the different new modules under the same namespace. Koha::Role is too generic. Examples: Koha::Auth::Permissions Koha::Auth::Roles or Koha::AccessControl::Permissions Koha::AccessControl::Roles -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|Add Koha::Role object |Add | |Koha::AccessControl::Role | |object -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 --- Comment #3 from Lisette Scheer <lisette@bywatersolutions.com> --- *** Bug 38063 has been marked as a duplicate of this bug. *** -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks|20813, 41551 | Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20813 [Bug 20813] Revamp user permissions system https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41551 [Bug 41551] Build migration tool for new permissions -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 --- Comment #4 from Lisette Scheer <lisette@bywatersolutions.com> --- Add the objects, api, update the patron object to check for roles, permissions using this new model The spec for the work we're planning is linked on 20813 now, I'm trying to put relevant information from it on each bug. -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 --- Comment #5 from Lisette Scheer <lisette@bywatersolutions.com> --- Roles would stack, so the most permissive role would override less permissive roles beneath and you can set a role to inherit permissions from another role, rather than recreating all the permissions for role A if role B is all of role A+extra permissions Predefined System Roles (just a starting point, though might be good to do one/full checkbox with subpermissions that currently exists so we could port to those?) These would be imported but only assigned if the existing permissions are a full match (if possible, since not everything has scopes right now) 1. Superlibrarian Description: Full system access Permissions: *:*:* (all permissions) 2. Circulation Staff Description: Front desk circulation operations Permissions: patrons:read:own_library patrons:update:own_library (limited fields) checkouts:create:own_library checkouts:delete:own_library (checkin) holds:create:own_library holds:read:own_library holds:update:own_library fines:read:own_library fines:create:own_library restrictions:read:own_library 3. Circulation Manager Description: Circulation management + overrides Inherits: Circulation Staff Additional Permissions: patrons:create:own_library patrons:delete:own_library checkouts:force:own_library checkouts:override:own_library fines:writeoff:own_library fines:refund:own_library restrictions:create:own_library restrictions:delete:own_library 4. Cataloger Description: Cataloging and item management Permissions: biblios:create:any biblios:read:any biblios:update:any items:create:own_library items:read:any items:update:own_library items:delete:own_library authorities:read:any authorities:update:any 5. Cataloging Manager Description: Full cataloging control Inherits: Cataloger Additional Permissions: biblios:delete:any items:batch_modify:any items:batch_delete:any authorities:create:any authorities:delete:any frameworks:update:none 6. Acquisitions Staff Description: Order and receive materials Permissions: vendors:read:none budgets:read:own baskets:create:own baskets:read:own_library baskets:update:own orders:create:own orders:read:own_library orders:receive:own_library invoices:read:own_library 7. Acquisitions Manager Description: Budget and vendor management Inherits: Acquisitions Staff Additional Permissions: vendors:create:none vendors:update:none budgets:manage:library_group baskets:delete:own_library orders:delete:own_library invoices:create:own_library invoices:update:own_library 8. Reports User Description: Run existing reports Permissions: reports:read:any reports:execute:own (only own reports) 9. Reports Manager Description: Create and manage all reports Permissions: reports:create:own reports:read:any reports:update:own reports:delete:own reports:execute:any 10. System Administrator Description: System configuration (not all-powerful) Permissions: system_preferences:read:none system_preferences:update:none libraries:manage:any circ_rules:manage:any marc_frameworks:manage:none patron_categories:manage:none staff_users:manage:any roles:manage:system 11. Branch Manager Description: Full control of own library Permissions: patrons:manage:own_library checkouts:manage:own_library holds:manage:own_library items:manage:own_library fines:manage:own_library staff_users:create:own_library staff_users:update:own_library reports:execute:any 12. Self-Check User (Special) Description: Kiosk/automated patron Permissions: checkouts:create:own_library checkouts:read:own (only own checkouts) holds:read:own -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 --- Comment #6 from Katrin Fischer <katrin.fischer@bsz-bw.de> --- Will it be possible to create your own roles? And see what permissions a role includes? -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 --- Comment #7 from David Cook <dcook@prosentient.com.au> --- I wonder if we want to steer clear of the words "System Administrator", because to me "System Administrator" should be all powerful. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 --- Comment #8 from Lisette Scheer <lisette@bywatersolutions.com> --- Katrin, yes, the plan is to be able to make your own roles, these would be the prebuilt ones and the UI should show the permissions (plus reporting should be much easier to see what permissions folks have with the new/updates to tables) for each role. David, I can definitely see that. Maybe just "Administrator" or something? -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 --- Comment #9 from Katrin Fischer <katrin.fischer@bsz-bw.de> --- Thanks for the quick reply, Lisette! -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on| |38141 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38141 [Bug 38141] Add access_control_* tables for role-based access control -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on| |41549 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41549 [Bug 41549] Add Koha::AccessControl::Permission objects and the legacy permission mapping -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|Add |Add |Koha::AccessControl::Role |Koha::AccessControl::Role |object |objects and patron role | |grants Depends on|38141 | Blocks|38137 | Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38137 [Bug 38137] Refactor Auth to check the new Koha::AccessControl::Permissions and Koha::AccessControl::Roles objects https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38141 [Bug 38141] Add access_control_* tables for role-based access control -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |44275 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44275 [Bug 44275] Keep access control grants in step with legacy permissions -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 --- Comment #10 from Lisette Scheer <lisette@bywatersolutions.com> --- Created attachment 212699 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212699&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. Run updatedatabase.pl 3. SELECT COUNT(*) FROM access_control_roles; => 32 SELECT COUNT(*) FROM access_control_role_permissions; => 198 4. Run updatedatabase.pl again, the counts don't change 5. In a perl shell, try to delete a legacy role nobody holds: Koha::AccessControl::Roles->find({ code => 'legacy_tools' })->delete => it throws Koha::Exceptions::AccessControl::SystemRole 6. prove t/db_dependent/Koha/AccessControl/ 7. prove t/db_dependent/Koha/Patron.t t/db_dependent/TestBuilder.t 8. Do a fresh install, 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.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 --- Comment #11 from Lisette Scheer <lisette@bywatersolutions.com> --- Created attachment 212700 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212700&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 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. prove t/db_dependent/Koha/AccessControl/Roles.t t/db_dependent/Koha/AccessControl/Grants.t 2. In a perl shell (or with bug 44277's staff pages), create a role, rename it, add and remove a permission, then delete it 3. Tools > Log viewer, module ACCESS_CONTROL: one entry for each change 4. Turn on BorrowersLog, grant the role to a staff member and revoke it: the Log viewer shows GRANT_ROLE and REVOKE_ROLE under Patrons for that staff member. With BorrowersLog off, nothing is logged for them 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.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #212699|0 |1 is obsolete| | Attachment #212700|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 --- Comment #12 from Lisette Scheer <lisette@bywatersolutions.com> --- Created attachment 212701 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212701&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, 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.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 --- Comment #13 from Lisette Scheer <lisette@bywatersolutions.com> --- Created attachment 212702 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212702&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 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. prove t/db_dependent/Koha/AccessControl/Roles.t t/db_dependent/Koha/AccessControl/Grants.t 2. In a perl shell (or with bug 44277's staff pages), create a role, rename it, add and remove a permission, then delete it 3. Tools > Log viewer, module ACCESS_CONTROL: one entry for each change 4. Turn on BorrowersLog, grant the role to a staff member and revoke it: the Log viewer shows GRANT_ROLE and REVOKE_ROLE under Patrons for that staff member. With BorrowersLog off, nothing is logged for them 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.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #212701|0 |1 is obsolete| | Attachment #212702|0 |1 is obsolete| | -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 --- Comment #14 from Lisette Scheer <lisette@bywatersolutions.com> --- Created attachment 212706 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212706&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 watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 --- Comment #15 from Lisette Scheer <lisette@bywatersolutions.com> --- Created attachment 212707 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212707&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 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. prove t/db_dependent/Koha/AccessControl/Roles.t t/db_dependent/Koha/AccessControl/Grants.t 2. In a perl shell (or with bug 44277's staff pages), create a role, rename it, add and remove a permission, then delete it 3. Tools > Log viewer, module ACCESS_CONTROL: one entry for each change 4. Turn on BorrowersLog, grant the role to a staff member and revoke it: the Log viewer shows GRANT_ROLE and REVOKE_ROLE under Patrons for that staff member. With BorrowersLog off, nothing is logged for them 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.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #212706|0 |1 is obsolete| | Attachment #212707|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
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.
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.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #212716|0 |1 is obsolete| | Attachment #212717|0 |1 is obsolete| | -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 --- Comment #18 from Lisette Scheer <lisette@bywatersolutions.com> --- Created attachment 212719 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212719&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.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 --- Comment #19 from Lisette Scheer <lisette@bywatersolutions.com> --- Created attachment 212720 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212720&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 Result: all tests pass. They check every log entry above, its diff, and that nothing is logged for patrons with BorrowersLog off 3. To check the logs in the staff interface, also apply bug 44277: it adds the pages to manage roles and grant them, and shows these entries in the Log viewer. Its patch "Show role changes and grants in the log viewer" has the steps. 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.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41550 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Text to go in the| |Adds roles: named sets of release notes| |permissions that can | |inherit every permission of | |another role, granted to | |staff at every library or | |at one library. | |Koha installs the system | |roles: superlibrarian, and | |one role per top-level | |permission, holding all of | |that permission's | |subpermissions. | |System roles can't be | |changed or deleted, and | |superlibrarian access can | |only come from the | |superlibrarian role. | |Nothing changes for staff | |yet. | |Changes to roles are always | |written to the action logs, | |and roles and permissions | |granted to or revoked from | |staff members are logged | |when `BorrowersLog` is on. Status|NEW |Needs Signoff Assignee|koha-bugs@lists.koha-commun |lisette@bywatersolutions.co |ity.org |m -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org