From 5bb19cf062e68aae5288154f95ca7f0ea7cf5162 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 22 Dec 2025 17:06:31 +0000 Subject: [PATCH] Bug 20956: (QA follow-up) Match getuserflags() return structure This patch changes Koha::Patron->permissions() to return the same structure as C4::Auth::getuserflags() for architectural consistency. Previously, permissions() only returned granted permissions: { catalogue => 1, circulate => { override_renewals => 1 } } Now it returns ALL flags (matching getuserflags()): { superlibrarian => 0, catalogue => 1, circulate => { override_renewals => 1 }, borrowers => 0, ... } This provides several benefits: 1. Consistency - Matches established C4::Auth::getuserflags() pattern 2. Simpler checks - Can use "if ($flags->{module})" instead of "if (exists $flags->{module})" 3. Future compatibility - Enables eventual deprecation of getuserflags() in favor of the ORM-based $patron->permissions() 4. Helper compatibility - Works with existing _dispatch() logic The logging functionality still works correctly - the diff will now show explicit changes from 0 to 1 rather than absence to presence. Test plan: 1. prove t/db_dependent/Koha/Patron.t 2. prove t/db_dependent/Log.t 3. Verify all tests pass 4. Confirm permissions() now returns all flags with 0/1 values Signed-off-by: Martin Renvoize --- Koha/Patron.pm | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 95769e38ae..25853703aa 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -3596,9 +3596,13 @@ sub is_anonymous { my $flags = $patron->permissions -Returns a structure such as: +Returns a hashref of the patron's permissions. This method has the same +return structure as C4::Auth::getuserflags for consistency. + +Exemple return structure: { - "permissions": 1, + "superlibrarian": 0, + "permissions": 0, "borrowers": 1, "circulate": { "manage_curbside_pickups": 1, @@ -3609,13 +3613,17 @@ Returns a structure such as: "manage_bookings": 1 }, "catalogue": 1, - "reserveforothers": { - "place_holds": 1, - "modify_holds_priority": 1 - } + "reserveforothers": 0, + "tools": 0, + ... + } -where a 1 indicates full permissions and a hash indicates -partial permissions with the given permissions as hash keys + +All permission flags are included in the returned hashref: +- Flags set to 1 indicate the user has full permissions for that module +- Flags set to 0 indicate the user does not have that permission +- Flags set to a hashref indicate partial/granular permissions, where the + hash keys are the specific subpermissions granted =cut -- 2.52.0