Bug 16631 - Limit listing of reports using patron library
Summary: Limit listing of reports using patron library
Status: Needs Signoff
Alias: None
Product: Koha
Classification: Unclassified
Component: Reports (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Casey Conlin
QA Contact: Testopia
URL:
Keywords:
: 10903 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-06-01 15:16 UTC by Christopher Brannon
Modified: 2025-12-31 19:18 UTC (History)
23 users (show)

See Also:
GIT URL:
Initiative type: ---
Sponsorship status: Sponsored
Comma delimited list of Sponsors:
Crowdfunding goal: 0
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
koha patch file (336.71 KB, text/plain)
2025-07-21 02:06 UTC, Casey Conlin
Details
Bug 16631: 0001-reports_branches-table-SQL-established (2.76 KB, text/plain)
2025-07-22 21:57 UTC, Casey Conlin
Details
Bug 16631: 0002-Make-DBversion-in-sync-with-the-Koha-module (1.39 KB, text/plain)
2025-07-22 21:58 UTC, Casey Conlin
Details
Bug 16631: 0003-Add-Filter-Reports-system-preference.-Add-UI-for-man (4.66 KB, text/plain)
2025-07-22 22:00 UTC, Casey Conlin
Details
Bug 16631: 0004-Add-ReportsBranch.pm (2.25 KB, text/plain)
2025-07-22 22:00 UTC, Casey Conlin
Details
Bug 16631: 0005-Not-working.-Trying-to-get-branches-to-show-up-in-gu (4.68 KB, application/mbox)
2025-07-22 22:01 UTC, Casey Conlin
Details
Bug 16631: 0006-The-reports-list-can-be-limited-by-library-via-the-q (3.21 KB, text/plain)
2025-07-22 22:01 UTC, Casey Conlin
Details
Bug 16631: 0007-Add-branch-libraries-to-reports-edit-view (3.79 KB, text/plain)
2025-07-22 22:02 UTC, Casey Conlin
Details
Bug 16631: 0008-Populate-Library-limitations-selection-with-librarie (3.61 KB, text/plain)
2025-07-22 22:02 UTC, Casey Conlin
Details
Bug 16631: 0009-Get-selected-reports-and-save-selected-reports-from- (9.15 KB, text/plain)
2025-07-22 22:03 UTC, Casey Conlin
Details
Bug 16631: 0010-Refactor-getting-selected-lirbaries (5.68 KB, text/plain)
2025-07-22 22:03 UTC, Casey Conlin
Details
Bug 16631: 0011-Add-library-limits-info-to-duplicate-section-and-fix (6.83 KB, text/plain)
2025-07-22 22:04 UTC, Casey Conlin
Details
Bug 16631: 0012-Add-unit-tests-for-reports_branches-updates (2.31 KB, text/plain)
2025-07-22 22:04 UTC, Casey Conlin
Details
Bug 16631: 0013-Pass-the-current-branch-as-the-filter-branchcode (850 bytes, text/plain)
2025-07-22 22:05 UTC, Casey Conlin
Details
Bug 16631: 0014-Fix-library-limit-method-issue-by-defining-use-state (1.26 KB, text/plain)
2025-07-22 22:05 UTC, Casey Conlin
Details
Bug 16631: 0015-Filtering-the-list-based-on-the-library-limits-works (13.02 KB, text/plain)
2025-07-22 22:06 UTC, Casey Conlin
Details
Bug 16631: Update Report Listing (835.74 KB, text/plain)
2025-07-23 00:56 UTC, Casey Conlin
Details
Bug 16631: Patch (835.72 KB, patch)
2025-07-23 01:12 UTC, Casey Conlin
Details | Diff | Splinter Review
Bug-16631 (30.08 KB, patch)
2025-07-25 17:19 UTC, Casey Conlin
Details | Diff | Splinter Review
Patch file for reports enhancement. (26.16 KB, patch)
2025-07-25 20:59 UTC, Casey Conlin
Details | Diff | Splinter Review
This patch adds the reports_branches table to enforce library limits for reports, and adjusts the saved_sql table to point to reports_branches. (7.26 KB, text/plain)
2025-07-26 19:28 UTC, Casey Conlin
Details
This patch implements the library_limit concept for Report/Reports. Staff can set libaries to which the report should be visible, if the system preference is enabled. (24.09 KB, text/plain)
2025-07-26 19:29 UTC, Casey Conlin
Details
Add library limits to reports. (31.73 KB, patch)
2025-07-27 13:33 UTC, Casey Conlin
Details | Diff | Splinter Review
Add-library-limits-to-Reports (31.71 KB, patch)
2025-07-27 19:50 UTC, Casey Conlin
Details | Diff | Splinter Review
Add library limits to Reports (31.71 KB, patch)
2025-07-27 20:28 UTC, Casey Conlin
Details | Diff | Splinter Review
0001-Bug-16631-Institute-library-limits (24.15 KB, patch)
2025-07-27 21:31 UTC, Casey Conlin
Details | Diff | Splinter Review
0002-Bug-16631-Fix-bug_16631 (1.69 KB, patch)
2025-07-27 21:32 UTC, Casey Conlin
Details | Diff | Splinter Review
0003-Bug-16631-Fix-missing-double-quote-in-guided_reports (1.56 KB, patch)
2025-07-27 21:32 UTC, Casey Conlin
Details | Diff | Splinter Review
0001-Bug-16631-DO-NOT-PUSH-Add-schema-files-for-reports_b (1) (7.26 KB, patch)
2025-07-27 22:31 UTC, Casey Conlin
Details | Diff | Splinter Review
0002-Bug-16631-Institute-library-limits (1) (24.10 KB, patch)
2025-07-27 22:32 UTC, Casey Conlin
Details | Diff | Splinter Review
Bug 16631: Add schema files for reports_branches and adjust saved_sql table (10.39 KB, patch)
2025-07-30 00:06 UTC, Casey Conlin
Details | Diff | Splinter Review
Bug 16631: Institute library limits (24.08 KB, patch)
2025-07-30 00:06 UTC, Casey Conlin
Details | Diff | Splinter Review
Bug 16631: [DO NOT PUSH] Add schema files for reports_branches and adjust saved_sql table (10.44 KB, patch)
2025-07-30 00:14 UTC, Casey Conlin
Details | Diff | Splinter Review
Bug 16631: Institute library limits (24.08 KB, patch)
2025-07-30 00:14 UTC, Casey Conlin
Details | Diff | Splinter Review
Bug 16631: [DO NOT PUSH] Add schema files for reports_branches and adjust saved_sql table (10.48 KB, patch)
2025-07-30 08:56 UTC, Casey Conlin
Details | Diff | Splinter Review
Bug 16631: Institute library limits (24.08 KB, patch)
2025-07-30 08:57 UTC, Casey Conlin
Details | Diff | Splinter Review
Bug 16631: [DO NOT PUSH] Add schema files for reports_branches and adjust saved_sql table (12.77 KB, patch)
2025-08-21 13:49 UTC, Casey Conlin
Details | Diff | Splinter Review
Bug 16631: Institute library limits (28.38 KB, patch)
2025-08-21 13:50 UTC, Casey Conlin
Details | Diff | Splinter Review
0001-Bug-16631-DO-NOT-PUSH-Add-schema-files-for-reports_b-1 (12.77 KB, patch)
2025-08-25 23:06 UTC, Casey Conlin
Details | Diff | Splinter Review
0002-Bug-16631-Institute-library-limits-1 (30.55 KB, patch)
2025-08-25 23:07 UTC, Casey Conlin
Details | Diff | Splinter Review
185780: 0002-Bug-16631-Institute-library-limits-1 (30.98 KB, patch)
2025-08-26 00:11 UTC, Casey Conlin
Details | Diff | Splinter Review
0002-Bug-16631-Institute-library-limits (30.80 KB, patch)
2025-08-26 00:23 UTC, Casey Conlin
Details | Diff | Splinter Review
0001-Bug-16631-DO-NOT-PUSH-Add-schema-files-for-reports_b-1 (14.95 KB, patch)
2025-08-26 11:58 UTC, Casey Conlin
Details | Diff | Splinter Review
0002-Bug-16631-Institute-library-limits (30.81 KB, patch)
2025-08-26 11:59 UTC, Casey Conlin
Details | Diff | Splinter Review
0001-Bug-16631-DO-NOT-PUSH-Add-schema-files-for-reports_b-1 (15.05 KB, patch)
2025-08-26 12:19 UTC, Casey Conlin
Details | Diff | Splinter Review
0001-Bug-16631-DO-NOT-PUSH-Add-schema-files-for-reports_b-2.patch (15.05 KB, patch)
2025-09-09 13:59 UTC, Casey Conlin
Details | Diff | Splinter Review
0002-Bug-16631-Institute-library-limits-1.patch (30.81 KB, patch)
2025-09-09 13:59 UTC, Casey Conlin
Details | Diff | Splinter Review
0002-Bug-16631-Institute-library-limits-2.patch (30.82 KB, patch)
2025-09-10 20:08 UTC, Casey Conlin
Details | Diff | Splinter Review
0001-Bug-16631-DO-NOT-PUSH-Add-schema-files-for-reports_b.patch (15.67 KB, patch)
2025-09-14 20:14 UTC, Casey Conlin
Details | Diff | Splinter Review
0001-Bug-16631-DO-NOT-PUSH-Add-schema-files-for-reports_b (15.68 KB, patch)
2025-09-20 20:36 UTC, Casey Conlin
Details | Diff | Splinter Review
0002-Bug-16631-Institute-library-limits-1 (30.82 KB, patch)
2025-09-20 20:37 UTC, Casey Conlin
Details | Diff | Splinter Review
0001-Bug-16631-DO-NOT-PUSH-Add-schema-files-for-reports_b.patch (16.96 KB, patch)
2025-10-25 19:36 UTC, Casey Conlin
Details | Diff | Splinter Review
0002-Bug-16631-Institute-library-limits.patch (69.36 KB, patch)
2025-10-25 19:37 UTC, Casey Conlin
Details | Diff | Splinter Review
Bug 16631: [DO NOT PUSH] Add schema files for reports_branches and adjust saved_sql table (8.30 KB, patch)
2025-11-21 00:50 UTC, Casey Conlin
Details | Diff | Splinter Review
Bug 16631: Institute library limits This patch implements the library_limit concept for Report/Reports. Staff with the correct permission and superlibrarians can set libaries to which the report should be visible, if the system preference is enabled. (78.32 KB, patch)
2025-11-21 00:50 UTC, Casey Conlin
Details | Diff | Splinter Review
Bug 16631: [DO NOT PUSH] Add schema files for reports_branches and adjust saved_sql table (8.40 KB, patch)
2025-12-07 14:23 UTC, Casey Conlin
Details | Diff | Splinter Review
Bug 16631: Institute library limits (78.37 KB, patch)
2025-12-07 14:23 UTC, Casey Conlin
Details | Diff | Splinter Review
Bug 16631: [DO NOT PUSH] Add schema files for reports_branches and adjust saved_sql table (8.40 KB, patch)
2025-12-17 13:25 UTC, Casey Conlin
Details | Diff | Splinter Review
Bug 16631: Institute library limits (82.45 KB, patch)
2025-12-17 13:25 UTC, Casey Conlin
Details | Diff | Splinter Review
Bug 16631: [DO NOT PUSH] Add schema files for reports_branches and adjust saved_sql table (8.40 KB, patch)
2025-12-28 18:04 UTC, Casey Conlin
Details | Diff | Splinter Review
Bug 16631: Institute library limits (82.31 KB, patch)
2025-12-28 18:04 UTC, Casey Conlin
Details | Diff | Splinter Review
Bug 16631: [DO NOT PUSH] Add schema files for reports_branches and adjust saved_sql table (8.40 KB, patch)
2025-12-28 18:08 UTC, Casey Conlin
Details | Diff | Splinter Review
Bug 16631: Institute library limits (82.31 KB, patch)
2025-12-28 18:08 UTC, Casey Conlin
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Brannon 2016-06-01 15:16:44 UTC
It would be helpful to have reports that are specific groups/categories to be authorized under the reports permissions in a patron account.  Not everyone wants to see everyone else's reports, some are similar but are not.  Some are for superlibrarians to test, and are not ready for use.  It would be great if we could specify groups and even subgroups in the permissions that the staff could access, or specify all groups.  All groups should be the norm for a superlibrarian.

Christopher
Comment 1 Brenda Turnbull 2017-02-28 12:34:12 UTC
This is something we would be interested in to as there are some reports we would like to give to the Stock Librarians only and so restrictions can be places on when they are run too.
Comment 2 Cab Vinton 2018-10-20 21:12:04 UTC
*** Bug 10903 has been marked as a duplicate of this bug. ***
Comment 3 Cab Vinton 2018-10-20 21:18:08 UTC
Would also be nice to limit access to reports by the home library of the staff.

Some reports are specific to the needs of just one library. Some reports are in development for a while. And so on.

As reports proliferate over time, libraries would welcome any option that reduces the number of reports visible to them.
Comment 4 Daniel Gaghan 2019-10-02 21:38:32 UTC
Having the ability to limit who can see which reports would help a lot at PCCLD. It would certainly clean up the report module and make relevant reports easier for staff to find.
Comment 5 Christopher Brannon 2019-10-02 22:45:15 UTC
(In reply to Cab Vinton from comment #3)
> Would also be nice to limit access to reports by the home library of the
> staff.
> 
> Some reports are specific to the needs of just one library. Some reports are
> in development for a while. And so on.
> 
> As reports proliferate over time, libraries would welcome any option that
> reduces the number of reports visible to them.

+1
Comment 6 Christopher Brannon 2019-10-02 22:45:38 UTC
(In reply to Daniel Gaghan from comment #4)
> Having the ability to limit who can see which reports would help a lot at
> PCCLD. It would certainly clean up the report module and make relevant
> reports easier for staff to find.

+1
Comment 7 Christopher Brannon 2019-10-02 22:48:47 UTC
Perhaps a branch field and a borrower field could be added.  If the field is empty, it applies to everyone.  Otherwise, it would be limited to matching borrower IDs or branches.
Comment 8 Cab Vinton 2023-03-25 21:44:24 UTC
Shame this enhancement hasn't got any traction, but I thought of a kludge that would work in a pinch --

Add a comment with a unique string to all reports in a particular grouping (e.g., for circ staff, a particular branch, etc.), then use the string in the keyword filter on the left. Only reports with that particular string will then be shown in the Reports module. 

In theory, multiple strings could be used to cover reports in more than one group. I believe the keyword filter is actually doing a phrase search, though, so some careful planning would be required.

As I said, a kludge ...
Comment 9 Christine Lee 2023-09-26 15:58:14 UTC
We're also interested in this enhancement for reports. We've accumulated a large amount of reports since joining in 2014. Many of these are kept for reference and as a record.
Since these are not useful for the majority of our staff, we'd like these to be hidden in a restricted Report Group. It would make it a clutter-free experience for staff to search reports while allowing access to those that may need it.
Comment 10 Alex Carver [Acerock7] 2025-02-18 19:53:40 UTC
+1 There are many reports that libraries would like that only apply to their own daily operations. It would be helpful to be able to hide these from most users. In addition, something like this would allow pre-baked reports for cron emailing to be hidden from those libraries not specified in the report parameters.
Comment 11 Angela Berrett 2025-02-25 16:45:00 UTC
+1 The ability to have smaller lists for each staff to browse through to find the report they want would be very helpful.  Some staff only use a handful of reports but they have to memorize the title/number for the reports to find them again.  Would love to see this feature.
Comment 12 Casey Conlin 2025-07-21 02:06:01 UTC Comment hidden (obsolete)
Comment 13 Casey Conlin 2025-07-22 21:57:58 UTC Comment hidden (obsolete)
Comment 14 Casey Conlin 2025-07-22 21:58:33 UTC Comment hidden (obsolete)
Comment 15 Casey Conlin 2025-07-22 22:00:27 UTC Comment hidden (obsolete)
Comment 16 Casey Conlin 2025-07-22 22:00:58 UTC Comment hidden (obsolete)
Comment 17 Casey Conlin 2025-07-22 22:01:30 UTC Comment hidden (obsolete)
Comment 18 Casey Conlin 2025-07-22 22:01:59 UTC Comment hidden (obsolete)
Comment 19 Casey Conlin 2025-07-22 22:02:24 UTC Comment hidden (obsolete)
Comment 20 Casey Conlin 2025-07-22 22:02:48 UTC Comment hidden (obsolete)
Comment 21 Casey Conlin 2025-07-22 22:03:09 UTC Comment hidden (obsolete)
Comment 22 Casey Conlin 2025-07-22 22:03:34 UTC Comment hidden (obsolete)
Comment 23 Casey Conlin 2025-07-22 22:04:02 UTC Comment hidden (obsolete)
Comment 24 Casey Conlin 2025-07-22 22:04:28 UTC
Created attachment 184519 [details]
Bug 16631: 0012-Add-unit-tests-for-reports_branches-updates
Comment 25 Casey Conlin 2025-07-22 22:05:04 UTC
Created attachment 184520 [details]
Bug 16631: 0013-Pass-the-current-branch-as-the-filter-branchcode
Comment 26 Casey Conlin 2025-07-22 22:05:29 UTC
Created attachment 184521 [details]
Bug 16631: 0014-Fix-library-limit-method-issue-by-defining-use-state
Comment 27 Casey Conlin 2025-07-22 22:06:00 UTC
Created attachment 184522 [details]
Bug 16631: 0015-Filtering-the-list-based-on-the-library-limits-works
Comment 28 David Cook 2025-07-22 23:43:23 UTC
A few obvious standout problems here:

1. Not sure what your 0005 file is there but it looks like it's not a patch
2. Database updates aren't done via updatedatabase.pl anymore. You'll want to read through https://wiki.koha-community.org/wiki/Database_updates
3. Commit author sometimes seems to be different to the person uploading. Also, sometimes commit author the default one from KTD. Would be good to fix/clarify these.
4. There are no commit messages and no test plan. Take a look at https://wiki.koha-community.org/wiki/Commit_messages
5. Looks like some patches would fail QA based on whitespace and formatting alone. Would be good for the author to use koha-testing-docker from development to avoid those kinds of errors

Probably worth squashing a lot of these overall.

I'm not sure about this design, but I haven't exhaustively reviewed the code. 

In any case, great to see some code trying to better organise the reports!
Comment 29 Casey Conlin 2025-07-23 00:56:44 UTC
Created attachment 184525 [details]
Bug 16631: Update Report Listing
Comment 30 Casey Conlin 2025-07-23 01:12:00 UTC
Created attachment 184526 [details] [review]
Bug 16631: Patch
Comment 31 David Cook 2025-07-23 04:23:51 UTC
(In reply to David Cook from comment #28)
> Probably worth squashing a lot of these overall.

Apologies. I meant squashing ones that changed the same files. Just trying to keep things a bit more cohesive and coherent. 

(In reply to Casey Conlin from comment #30)
> Created attachment 184526 [details] [review] [review]
> Bug 16631: Patch

This looks very weird. Looks like you've got a rebase problem there.
Comment 32 Casey Conlin 2025-07-25 17:19:35 UTC
Created attachment 184657 [details] [review]
Bug-16631
Comment 33 Casey Conlin 2025-07-25 20:59:43 UTC
Created attachment 184674 [details] [review]
Patch file for reports enhancement.
Comment 34 Casey Conlin 2025-07-26 19:28:30 UTC
Created attachment 184686 [details]
This patch adds the reports_branches table to enforce library limits for reports, and adjusts the saved_sql table to point to reports_branches.
Comment 35 Casey Conlin 2025-07-26 19:29:04 UTC
Created attachment 184687 [details]
This patch implements the library_limit concept for Report/Reports. Staff can set libaries to which the report should be visible, if the system preference is enabled.
Comment 36 Casey Conlin 2025-07-27 13:33:21 UTC
Created attachment 184688 [details] [review]
Add library limits to reports.
Comment 37 Casey Conlin 2025-07-27 19:50:18 UTC
Created attachment 184689 [details] [review]
Add-library-limits-to-Reports
Comment 38 Casey Conlin 2025-07-27 20:28:56 UTC
Created attachment 184690 [details] [review]
Add library limits to Reports
Comment 39 Casey Conlin 2025-07-27 21:31:54 UTC
Created attachment 184691 [details] [review]
0001-Bug-16631-Institute-library-limits
Comment 40 Casey Conlin 2025-07-27 21:32:17 UTC
Created attachment 184692 [details] [review]
0002-Bug-16631-Fix-bug_16631
Comment 41 Casey Conlin 2025-07-27 21:32:51 UTC
Created attachment 184693 [details] [review]
0003-Bug-16631-Fix-missing-double-quote-in-guided_reports
Comment 42 Casey Conlin 2025-07-27 22:31:40 UTC
Created attachment 184694 [details] [review]
0001-Bug-16631-DO-NOT-PUSH-Add-schema-files-for-reports_b (1)
Comment 43 Casey Conlin 2025-07-27 22:32:05 UTC
Created attachment 184695 [details] [review]
0002-Bug-16631-Institute-library-limits (1)
Comment 44 Casey Conlin 2025-07-30 00:06:22 UTC
Created attachment 184845 [details] [review]
Bug 16631: Add schema files for reports_branches and adjust saved_sql table
Comment 45 Casey Conlin 2025-07-30 00:06:54 UTC
Created attachment 184846 [details] [review]
Bug 16631: Institute library limits
Comment 46 Casey Conlin 2025-07-30 00:14:18 UTC
Created attachment 184847 [details] [review]
Bug 16631: [DO NOT PUSH] Add schema files for reports_branches and adjust saved_sql table
Comment 47 Casey Conlin 2025-07-30 00:14:42 UTC
Created attachment 184848 [details] [review]
Bug 16631: Institute library limits
Comment 48 Casey Conlin 2025-07-30 00:27:45 UTC
(In reply to David Cook from comment #31)
> (In reply to David Cook from comment #28)
> > Probably worth squashing a lot of these overall.
> 
> Apologies. I meant squashing ones that changed the same files. Just trying
> to keep things a bit more cohesive and coherent. 
> 
> (In reply to Casey Conlin from comment #30)
> > Created attachment 184526 [details] [review] [review] [review]
> > Bug 16631: Patch
> 
> This looks very weird. Looks like you've got a rebase problem there.

Thank you for the notes, David! 
This should be ready for review now.
Any questions or comments are welcome.
Comment 49 Casey Conlin 2025-07-30 08:51:57 UTC
Comment on attachment 184847 [details] [review]
Bug 16631: [DO NOT PUSH] Add schema files for reports_branches and adjust saved_sql table

>From 04bb1e1220d059f1d28b48de8a5d095912311ef6 Mon Sep 17 00:00:00 2001
>From: "Cameron E. Tidd" <ctidd@citlink.net>
>Date: Sat, 26 Jul 2025 02:02:50 +0000
>Subject: [PATCH 1/2] Bug 16631: [DO NOT PUSH] Add schema files for
> reports_branches and adjust saved_sql table
>MIME-Version: 1.0
>Content-Type: text/plain; charset=UTF-8
>Content-Transfer-Encoding: 8bit
>
>This patch adds the reports_branches table to enforce library limits for reports, and adjusts the saved_sql table to point to reports_branches.
>
> Sponsored-by: The Ramapo Catskill Library System
>Test plan:
>Confirm Initial Settings
>1. Log in to Koha staff and set your library as Centerville if itâs not already.
>2. Visit the Saved reports.
>3. Three (3) previously created reports should be visible.
>
>Verify Patch Settings
>4. From the Koha Sandbox, Apply the patch, then Restart services.
>5. Go to the System Preferences page (Click the More dropdown from the top nav bar, click Administration, click System Preferences).
>6. Verify Reports is an option in the left side navigation bar, and that when clicked, you see the EnableFilteringReports option.
>7. Enable EnableFilteringReports as described in step 6.
>8. Go back to Saved reports as in Step 2.
>9. Click Edit in the row menu for Report 1.
>10. At the bottom of the Report 1 edit page, you should see a Library limitation select box.
>
>Verify the Library Limitation Settings are Persisted
>11. Choose Centerville from the select box and click Update SQL.
>12. Reload the page, or navigate away from the page and go back to the edit screen for Report 1.
>13. Verify that Centerville is still in the Library limitation select box.
>14. Add Fairfield in the Library limitation select box and click Update and run SQL.
>15. Go back to editing Report 1.
>16. Confirm the Library limitation select box has both Centerville and Fairfield selected.
>17. Duplicate Report 1.
>18. Confirm the Library limitation select box has both Centerville and Fairfield selected.
>19. Click Save Report.
>20. Confirm the Library limitation select box has both Centerville and Fairfield selected.
>
>Verify Reports are Filtered Based on Library Limitations
>21. Go to Saved reports as in Step 2.
>22. Click Edit for Report 2.
>23. Add Fairfield in the Library limitation select box as the only choice and click Update and run SQL.
>24. Go to Saved reports as in Step 2.
>25. Confirm you do not see Report 2, and only Report 1 and Report 3.
>26. In the upper right corner, click the drop down that says koha Centerville and click Set library to change your library.
>27. Set your library to Fairfield.
>28. Go to Saved reports as in Step 2.
>29. Confirm you do not see Report 1, and only Report 2 and Report 3.
>
>Verify Disabling EnableFilteringReports Preference Shows All Reports
>30. Disable EnableFilteringReports preference as in steps 5 to 7.
>31. Go to Saved reports as in Step 2.
>32. Confirm Report 1, Report 2, Report 3 are visible.
>33. Click to edit Report 1 and verify there is no Library limitation select box.
>
>Verify Library limitations are Persisted When EnableFilteringReports is Toggled On or Off
>34. Enable EnableFilteringReports preference as in steps 5 to 7.
>35. Ensure youâre library is set to Fairfield as in step 26.
>36. Go to Saved reports as in Step 2.
>37. Confirm Report 1 is not visible, and Report 2 and Report 3 are visible.
>38. Click to edit Report 2 and verify the Library limitation select box is at the bottom of the page and that it has Fairfield selected.
>
>Run Unit Tests
>39. In the Koha home directory run the command: prove t/db_dependent/Koha/Reports.t
>40. The new unit tests for the reprots_branches tables are in this file
>41. All tests should pass.
>
>Signoff
>42. Sign off if the steps above checkout.
>---
> Koha/Schema/Result/ReportsBranch.pm |  86 ++++++++++++++
> Koha/Schema/Result/SavedSql.pm      | 220 ++++++++++++++++++++++++++++++++++++
> 2 files changed, 306 insertions(+)
> create mode 100644 Koha/Schema/Result/ReportsBranch.pm
>
>diff --git a/Koha/Schema/Result/ReportsBranch.pm b/Koha/Schema/Result/ReportsBranch.pm
>new file mode 100644
>index 0000000000..80472a5ff1
>--- /dev/null
>+++ b/Koha/Schema/Result/ReportsBranch.pm
>@@ -0,0 +1,86 @@
>+use utf8;
>+
>+package Koha::Schema::Result::ReportsBranch;
>+
>+# Created by DBIx::Class::Schema::Loader
>+# DO NOT MODIFY THE FIRST PART OF THIS FILE
>+
>+=head1 NAME
>+
>+Koha::Schema::Result::ItemtypesBranch
>+
>+=cut
>+
>+use strict;
>+use warnings;
>+
>+use base 'DBIx::Class::Core';
>+
>+=head1 TABLE: C<itemtypes_branches>
>+
>+=cut
>+
>+__PACKAGE__->table("reports_branches");
>+
>+=head1 ACCESSORS
>+
>+=head2 report_id
>+
>+  data_type: 'varchar'
>+  is_foreign_key: 1
>+  is_nullable: 1
>+  size: 80
>+
>+=head2 branchcode
>+
>+  data_type: 'varchar'
>+  is_foreign_key: 1
>+  is_nullable: 0
>+  size: 10
>+
>+=cut
>+
>+__PACKAGE__->add_columns(
>+    "report_id",
>+    { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 80 },
>+    "branchcode",
>+    { data_type => "varchar", is_foreign_key => 1, is_nullable => 0, size => 10 },
>+);
>+
>+=head1 RELATIONS
>+
>+=head2 branchcode
>+
>+Type: belongs_to
>+
>+Related object: L<Koha::Schema::Result::Branch>
>+
>+=cut
>+
>+__PACKAGE__->belongs_to(
>+    "branchcode",
>+    "Koha::Schema::Result::Branch",
>+    { branchcode    => "branchcode" },
>+    { is_deferrable => 1, on_delete => "CASCADE", on_update => "RESTRICT" },
>+);
>+
>+=head2 itemtype
>+
>+Type: belongs_to
>+
>+Related object: L<Koha::Schema::Result::Itemtype>
>+
>+=cut
>+
>+__PACKAGE__->belongs_to(
>+    "report_id",
>+    "Koha::Schema::Result::Report",
>+    { report_id     => "report_id" },
>+    { is_deferrable => 1, on_delete => "CASCADE", on_update => "RESTRICT" },
>+);
>+
>+# Created by DBIx::Class::Schema::Loader v0.07048 @ 2019-07-04 04:56:48
>+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:cBTswjKV8VWN1iueB+PygQ
>+
>+# You can replace this text with custom code or comments, and it will be preserved on regeneration
>+1;
>diff --git a/Koha/Schema/Result/SavedSql.pm b/Koha/Schema/Result/SavedSql.pm
>index 6f75ae3b31..88d54b52ef 100644
>--- a/Koha/Schema/Result/SavedSql.pm
>+++ b/Koha/Schema/Result/SavedSql.pm
>@@ -185,6 +185,221 @@ __PACKAGE__->add_columns(
> 
> __PACKAGE__->set_primary_key("id");
> 
>+=head1 RELATIONS
>+
>+=head2 reports_branches
>+
>+Type: has_many
>+
>+Related object: L<Koha::Schema::Result::ReportsBranch>
>+
>+=cut
>+
>+__PACKAGE__->has_many(
>+  "reports_branches",
>+  "Koha::Schema::Result::ReportsBranch",
>+  { "foreign.report_id" => "self.id" },
>+  { cascade_copy => 0, cascade_delete => 0 },
>+);
>+
>+
>+# Created by DBIx::Class::Schema::Loader v0.07051 @ 2025-07-26 01:58:59
>+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:w7XKvOV/ylS6Dq8tsUNmSg
>+# These lines were loaded from '/kohadevbox/koha/Koha/Schema/Result/SavedSql.pm' found in @INC.
>+# They are now part of the custom portion of this file
>+# for you to hand-edit.  If you do not either delete
>+# this section or remove that file from @INC, this section
>+# will be repeated redundantly when you re-create this
>+# file again via Loader!  See skip_load_external to disable
>+# this feature.
>+
>+use utf8;
>+package Koha::Schema::Result::SavedSql;
>+
>+# Created by DBIx::Class::Schema::Loader
>+# DO NOT MODIFY THE FIRST PART OF THIS FILE
>+
>+=head1 NAME
>+
>+Koha::Schema::Result::SavedSql
>+
>+=cut
>+
>+use strict;
>+use warnings;
>+
>+use base 'DBIx::Class::Core';
>+
>+=head1 TABLE: C<saved_sql>
>+
>+=cut
>+
>+__PACKAGE__->table("saved_sql");
>+
>+=head1 ACCESSORS
>+
>+=head2 id
>+
>+  data_type: 'integer'
>+  is_auto_increment: 1
>+  is_nullable: 0
>+
>+unique id and primary key assigned by Koha
>+
>+=head2 borrowernumber
>+
>+  data_type: 'integer'
>+  is_nullable: 1
>+
>+the staff member who created this report (borrowers.borrowernumber)
>+
>+=head2 date_created
>+
>+  data_type: 'datetime'
>+  datetime_undef_if_invalid: 1
>+  is_nullable: 1
>+
>+the date this report was created
>+
>+=head2 last_modified
>+
>+  data_type: 'datetime'
>+  datetime_undef_if_invalid: 1
>+  is_nullable: 1
>+
>+the date this report was last edited
>+
>+=head2 savedsql
>+
>+  data_type: 'mediumtext'
>+  is_nullable: 1
>+
>+the SQL for this report
>+
>+=head2 last_run
>+
>+  data_type: 'datetime'
>+  datetime_undef_if_invalid: 1
>+  is_nullable: 1
>+
>+=head2 report_name
>+
>+  data_type: 'varchar'
>+  default_value: (empty string)
>+  is_nullable: 0
>+  size: 255
>+
>+the name of this report
>+
>+=head2 type
>+
>+  data_type: 'varchar'
>+  is_nullable: 1
>+  size: 255
>+
>+always 1 for tabular
>+
>+=head2 notes
>+
>+  data_type: 'mediumtext'
>+  is_nullable: 1
>+
>+the notes or description given to this report
>+
>+=head2 cache_expiry
>+
>+  data_type: 'integer'
>+  default_value: 300
>+  is_nullable: 0
>+
>+=head2 public
>+
>+  data_type: 'tinyint'
>+  default_value: 0
>+  is_nullable: 0
>+
>+=head2 report_area
>+
>+  data_type: 'varchar'
>+  is_nullable: 1
>+  size: 6
>+
>+=head2 report_group
>+
>+  data_type: 'varchar'
>+  is_nullable: 1
>+  size: 80
>+
>+=head2 report_subgroup
>+
>+  data_type: 'varchar'
>+  is_nullable: 1
>+  size: 80
>+
>+=head2 mana_id
>+
>+  data_type: 'integer'
>+  is_nullable: 1
>+
>+=cut
>+
>+__PACKAGE__->add_columns(
>+  "id",
>+  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
>+  "borrowernumber",
>+  { data_type => "integer", is_nullable => 1 },
>+  "date_created",
>+  {
>+    data_type => "datetime",
>+    datetime_undef_if_invalid => 1,
>+    is_nullable => 1,
>+  },
>+  "last_modified",
>+  {
>+    data_type => "datetime",
>+    datetime_undef_if_invalid => 1,
>+    is_nullable => 1,
>+  },
>+  "savedsql",
>+  { data_type => "mediumtext", is_nullable => 1 },
>+  "last_run",
>+  {
>+    data_type => "datetime",
>+    datetime_undef_if_invalid => 1,
>+    is_nullable => 1,
>+  },
>+  "report_name",
>+  { data_type => "varchar", default_value => "", is_nullable => 0, size => 255 },
>+  "type",
>+  { data_type => "varchar", is_nullable => 1, size => 255 },
>+  "notes",
>+  { data_type => "mediumtext", is_nullable => 1 },
>+  "cache_expiry",
>+  { data_type => "integer", default_value => 300, is_nullable => 0 },
>+  "public",
>+  { data_type => "tinyint", default_value => 0, is_nullable => 0 },
>+  "report_area",
>+  { data_type => "varchar", is_nullable => 1, size => 6 },
>+  "report_group",
>+  { data_type => "varchar", is_nullable => 1, size => 80 },
>+  "report_subgroup",
>+  { data_type => "varchar", is_nullable => 1, size => 80 },
>+  "mana_id",
>+  { data_type => "integer", is_nullable => 1 },
>+);
>+
>+=head1 PRIMARY KEY
>+
>+=over 4
>+
>+=item * L</id>
>+
>+=back
>+
>+=cut
>+
>+__PACKAGE__->set_primary_key("id");
>+
> 
> # Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29
> # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:198dNG9DGQzop+s5IHy7sw
>@@ -214,3 +429,8 @@ sub koha_objects_class {
> }
> 
> 1;
>+# End of lines loaded from '/kohadevbox/koha/Koha/Schema/Result/SavedSql.pm'
>+
>+
>+# You can replace this text with custom code or comments, and it will be preserved on regeneration
>+1;
>-- 
>2.15.0
>
Comment 50 Casey Conlin 2025-07-30 08:56:47 UTC
Created attachment 184859 [details] [review]
Bug 16631: [DO NOT PUSH] Add schema files for reports_branches and adjust saved_sql table
Comment 51 Casey Conlin 2025-07-30 08:57:15 UTC
Created attachment 184861 [details] [review]
Bug 16631: Institute library limits
Comment 52 Casey Conlin 2025-08-06 12:25:38 UTC
This patch is ready for review at https://sandboxes.biblibre.eu/
Comment 53 Anneli Österman 2025-08-11 05:54:19 UTC
I tested this in Casey's sandbox and it worked as in the test plan.

I can not run the unit test, so maybe someone else could do that part?
Comment 54 Lucas Gass (lukeg) 2025-08-13 15:55:22 UTC
Hi Casey,

Tests are failing here, can you have a look? 

t/db_dependent/Koha/Reports.t
Comment 55 Casey Conlin 2025-08-13 18:41:42 UTC
(In reply to Lucas Gass (lukeg) from comment #54)
> Hi Casey,
> 
> Tests are failing here, can you have a look? 
> 
> t/db_dependent/Koha/Reports.t

Hi, Lucas, thanks for taking a look here!
When you ran the test command, were you in ktd shell? 

I omitted that step from my the test plan.

run: ktd --shell

kohadev-koha@kohadevbox:koha(16631-reports-libraries-filter-patch)$ t/db_dependent/Koha/Reports.t
1..10
ok 1 - Adding a new report should have set the id
ok 2 - The 2 reports should have been added
ok 3 - Find a report by id should return the correct report
ok 4 - Delete should have deleted the report
# Subtest: prep_report
    1..4
    ok 1 - Expected sql generated correctly with single param and name
    ok 2 - Expected sql generated correctly with multiple params and names
    ok 3 - Expected sql generated correctly with multiple params and no names
    ok 4
ok 5 - prep_report
# Subtest: is_sql_valid
    1..15
    ok 1 - Empty sql is missing SELECT
    ok 2 - Nonsense sql is missing SELECT
    ok 3 - select FOO is good
    ok 4 - select FOO with UPDATE BAR
    ok 5 - UPDATE qux
    ok 6 - select FOO with DELETE BAR
    ok 7 - DELETE qux
    ok 8 - select FOO with DROP BAR
    ok 9 - DROP qux
    ok 10 - select FOO with INSERT BAR
    ok 11 - INSERT qux
    ok 12 - select FOO with SHOW BAR
    ok 13 - SHOW qux
    ok 14 - select FOO with CREATE BAR
    ok 15 - CREATE qux
ok 6 - is_sql_valid
# Subtest: check_columns
    1..3
    ok 1 - Bad column found in SQL
    ok 2 - No bad column found in SQL
    ok 3 - Check column_names parameter
ok 7 - check_columns
# Subtest: _might_add_limit
    1..10
    ok 1 - Pref is undefined, no changes
    ok 2 - Pref is zero, no changes
    ok 3 - Pref is empty, no changes
    ok 4 - Limit 10 found at the end
    ok 5 - Already contains a limit
    ok 6 - Variation, also contains a limit
    ok 7 - Subquery, limit 10 found at the end
    ok 8 - Subquery variation, limit 10 found at the end
    ok 9 - Subquery lc variation, limit 10 found at the end
    ok 10 - Query refers to limit field, limit 10 found at the end
ok 8 - _might_add_limit
# Subtest: reports_branches are added and removed from report_branches table
    1..4
    ok 1 - 3 branches added to report_branches table
    ok 2 - 1 branch removed from report_branches table
    ok 3 - Report deleted, count is back to original
    ok 4 - No branches left in reports_branches table after report deletion
ok 9 - reports_branches are added and removed from report_branches table
ok 10 - no warnings
Comment 56 Casey Conlin 2025-08-13 19:02:29 UTC
(In reply to Lucas Gass (lukeg) from comment #54)
> Hi Casey,
> 
> Tests are failing here, can you have a look? 
> 
> t/db_dependent/Koha/Reports.t

It might be necessary to run reset_all to update the db with the new tables before running the test command. 

I can add this to the test plan in the commit if necessary.
Comment 57 Casey Conlin 2025-08-15 12:02:29 UTC
(In reply to Lucas Gass (lukeg) from comment #54)
> Hi Casey,
> 
> Tests are failing here, can you have a look? 
> 
> t/db_dependent/Koha/Reports.t

Hi Lucas. I see a couple changes to the status here and it's back at Needs Signoff now. Were you able to run the tests? Are we still at Needs Signoff?
Comment 58 Michael Grgurev 2025-08-18 22:32:52 UTC
Main Library Alliance would like to make a comment regarding consortium use, partially relating back to the original submission by Christopher Brannon.

While this feature may definitely prove useful to us, particularly for test reports, it didn't seem like there was a way for a superlibrarian to "view all" when demoing on the sandbox, unless I missed an option somewhere. In smaller systems this may not be as much of an issue, but in larger systems (56 and counting here, not counting lockers & bookmobiles) an admin having to manually check each branch could be a nuisance.

Some pathway for at least superlibrarians to "view all" would be preferable.
Comment 59 Casey Conlin 2025-08-21 13:49:48 UTC
Created attachment 185627 [details] [review]
Bug 16631: [DO NOT PUSH] Add schema files for reports_branches and adjust saved_sql table
Comment 60 Casey Conlin 2025-08-21 13:50:27 UTC
Created attachment 185628 [details] [review]
Bug 16631: Institute library limits
Comment 61 Casey Conlin 2025-08-25 23:06:41 UTC
Created attachment 185779 [details] [review]
0001-Bug-16631-DO-NOT-PUSH-Add-schema-files-for-reports_b-1
Comment 62 Casey Conlin 2025-08-25 23:07:05 UTC
Created attachment 185780 [details] [review]
0002-Bug-16631-Institute-library-limits-1
Comment 63 Casey Conlin 2025-08-26 00:11:53 UTC
Created attachment 185781 [details] [review]
185780: 0002-Bug-16631-Institute-library-limits-1
Comment 64 Casey Conlin 2025-08-26 00:23:03 UTC
Created attachment 185782 [details] [review]
0002-Bug-16631-Institute-library-limits
Comment 65 Casey Conlin 2025-08-26 11:58:46 UTC
Created attachment 185788 [details] [review]
0001-Bug-16631-DO-NOT-PUSH-Add-schema-files-for-reports_b-1
Comment 66 Casey Conlin 2025-08-26 11:59:09 UTC
Created attachment 185789 [details] [review]
0002-Bug-16631-Institute-library-limits
Comment 67 Casey Conlin 2025-08-26 12:19:34 UTC
Created attachment 185790 [details] [review]
0001-Bug-16631-DO-NOT-PUSH-Add-schema-files-for-reports_b-1
Comment 68 Casey Conlin 2025-08-26 12:30:08 UTC
(In reply to Michael Grgurev from comment #58)
> Main Library Alliance would like to make a comment regarding consortium use,
> partially relating back to the original submission by Christopher Brannon.
> 
> While this feature may definitely prove useful to us, particularly for test
> reports, it didn't seem like there was a way for a superlibrarian to "view
> all" when demoing on the sandbox, unless I missed an option somewhere. In
> smaller systems this may not be as much of an issue, but in larger systems
> (56 and counting here, not counting lockers & bookmobiles) an admin having
> to manually check each branch could be a nuisance.
> 
> Some pathway for at least superlibrarians to "view all" would be preferable.

Thanks for this note Michael! This is a great point, and the suggestion for a view all button is very helpful.

Taking your feedback here into consideration, we've added a new permission that would give a user access to managing limits on reports, and a button that will enable superlibrarians and users with this permission to toggle between viewing all reports and viewing only reports that match the user's current branch.

Please let me know if you have any other questions or comments.
Comment 69 Casey Conlin 2025-09-08 11:06:41 UTC
We have a sandbox set up named b16631 at https://sandboxes.biblibre.eu/ that has some users and reports set up to align with the test plan.
Comment 70 Ludovic 2025-09-09 13:47:03 UTC
Hello,

Thank you for your work on the patch!
I tried to apply it to my local Koha instance in order to run some tests, but unfortunately there's a merge conflict preventing me from proceeding.

Thanks again and looking forward to your update!
Comment 71 Ludovic 2025-09-09 13:58:36 UTC
I just realized I forgot to update my previous message — sorry about that.

I was able to apply the patch, but when I set EnableFilteringReports to "Enable" in system preferences, I get a 500 error when accessing the "Reports" page.

Let me know if there's anything I can provide to help debug this (logs, environment info, etc.).
Comment 72 Casey Conlin 2025-09-09 13:59:00 UTC
Created attachment 186299 [details] [review]
0001-Bug-16631-DO-NOT-PUSH-Add-schema-files-for-reports_b-2.patch
Comment 73 Casey Conlin 2025-09-09 13:59:33 UTC
Created attachment 186300 [details] [review]
0002-Bug-16631-Institute-library-limits-1.patch
Comment 74 Casey Conlin 2025-09-09 14:01:37 UTC
(In reply to Ludovic from comment #70)
> Hello,
> 
> Thank you for your work on the patch!
> I tried to apply it to my local Koha instance in order to run some tests,
> but unfortunately there's a merge conflict preventing me from proceeding.
> 
> Thanks again and looking forward to your update!

I see your additional comment; just commenting for clarity. I made up new patch files based on a new pull from main and attached them here.
Comment 75 Casey Conlin 2025-09-09 14:05:29 UTC
(In reply to Ludovic from comment #71)
> I just realized I forgot to update my previous message — sorry about that.
> 
> I was able to apply the patch, but when I set EnableFilteringReports to
> "Enable" in system preferences, I get a 500 error when accessing the
> "Reports" page.
> 
> Let me know if there's anything I can provide to help debug this (logs,
> environment info, etc.).

If you're running locally, did you apply the db changes?

The test plan is written for testing on the Koha sandbox until the end when unit tests are required. 

If you can update the db after applying the patch, that issue might go away. The steps related to that are below.

73. Using Koha Testing Docker, in the Koha home directory run the command: ktd --shell to start the ktd shell.
74. Run command: reset_all to drop and recreate the koha database.

Thank you for checking this out and for your feedback!
Comment 76 Lucas Gass (lukeg) 2025-09-10 19:23:34 UTC
Casey,

Thanks for your work here, it's looking good. I did notice that if I run updatedatabase twice I get an error. I think you need to wrapped that creation of the table SQL with something like:

unless ( TableExists('reports_branches') ) {

}
Comment 77 Casey Conlin 2025-09-10 20:08:26 UTC
Created attachment 186335 [details] [review]
0002-Bug-16631-Institute-library-limits-2.patch
Comment 78 Casey Conlin 2025-09-10 20:10:51 UTC
(In reply to Lucas Gass (lukeg) from comment #76)
> Casey,
> 
> Thanks for your work here, it's looking good. I did notice that if I run
> updatedatabase twice I get an error. I think you need to wrapped that
> creation of the table SQL with something like:
> 
> unless ( TableExists('reports_branches') ) {
> 
> }

Great feedback!

I got the same error you described when running the update command. 

I updated the bug.pl file to account for an existing table, and I was able to run the update command successfully. 

Let me know if you have any other questions or feedback. 

Thanks, Lucas!
Comment 79 Casey Conlin 2025-09-14 20:14:23 UTC
Created attachment 186393 [details] [review]
0001-Bug-16631-DO-NOT-PUSH-Add-schema-files-for-reports_b.patch
Comment 80 Casey Conlin 2025-09-20 20:36:50 UTC
Created attachment 186632 [details] [review]
0001-Bug-16631-DO-NOT-PUSH-Add-schema-files-for-reports_b
Comment 81 Casey Conlin 2025-09-20 20:37:27 UTC
Created attachment 186633 [details] [review]
0002-Bug-16631-Institute-library-limits-1
Comment 82 David Cook 2025-09-25 23:30:20 UTC
It would be good to clarify the intention of this change.

On one hand, the title is "Show groups/categories of reports to authorized staff", which implies that the change is just a visual/organisational one.

On the other hand, on the /cgi-bin/koha/reports/guided_reports.pl page, the hint for "Library limitation" says "Limits the use of this report to the selected libraries.", which implies that the change is restricting usage of reports based on some kind of library setting. 

In practice, the change appears to only be visual/organisational, since you can bypass "Library limitation" by changing the "id" URL parameter. 

In my test, I can only see report #2, so I run report #2, but then I am curious about report #1, so I change the URL and now I'm running a report that I'm not supposed to be able to see.

It's not 100% clear to me at this stage if that's a bug or a feature. I'm guessing bug, but I figure it's worth asking the question here.
Comment 83 David Cook 2025-09-25 23:41:47 UTC
Comment on attachment 186633 [details] [review]
0002-Bug-16631-Institute-library-limits-1

Review of attachment 186633 [details] [review]:
-----------------------------------------------------------------

::: Koha/Reports.pm
@@ +33,4 @@
>  
>  =cut
>  
> +=head3 search_with_localization

This function doesn't appear to be used in Koha? Could you clarify its purpose?

::: reports/guided_reports.pl
@@ +87,5 @@
> +if ( defined $input->param('show_all') ) {
> +    my $param = $input->param('show_all');
> +    if ( defined $param && $param eq '1' ) {
> +        $show_all = 1;
> +        $session->param( 'show_all', 1 ) if $session;

Since the session is for the whole of Koha, it would be wise to prefix this session parameter key with something like "reports_". 

That being said, generally speaking we don't use the Koha database session for sticky view settings. This would probably be done better using localStorage or a cookie I would think.

Alternatively, I'm not sure it's really necessary for this to be sticky either?

@@ +1115,5 @@
>      my $subgroup = $input->param('subgroup');
>      $filter->{group}    = $group;
>      $filter->{subgroup} = $subgroup;
> +
> +    my $pref_limit_reports_by_branch = C4::Context->preference("LimitReportsByBranch");

This block seems like it has quite a bit of copy/paste. Ideally we shouldn't be repeating code unnecessarily. The unique conditional code could be done above the repeated part, or you could move the repeated part into a function and call it twice.
Comment 84 David Cook 2025-09-25 23:43:40 UTC
I think it would be useful to optionally show the library limitation in the table on /cgi-bin/koha/reports/guided_reports.pl?op=list

Like... have it default to not shown, but then use the "Columns" button on the table to show it. 

Otherwise, I need to check each report one by one to try to figure out which library limitations it has.
Comment 85 David Cook 2025-09-25 23:54:21 UTC
(In reply to David Cook from comment #83)
> Comment on attachment 186633 [details] [review] [review]
> 0002-Bug-16631-Institute-library-limits-1
> 
> Review of attachment 186633 [details] [review] [review]:
> -----------------------------------------------------------------
> 
> ::: Koha/Reports.pm
> @@ +33,4 @@
> >  
> >  =cut
> >  
> > +=head3 search_with_localization
> 
> This function doesn't appear to be used in Koha? Could you clarify its
> purpose?

I think that this is probably a copy/paste error where Koha/Reports.pm was created from Koha/ItemTypes.pm?
Comment 86 David Cook 2025-09-26 00:00:25 UTC
Overall, I'm a bit curious about the workflow. Is the idea that there are cross-branch librarians who prepare the reports and assign them to the libraries?

If you have create_reports and execute_reports but not manage_report_limits, then your reports are by default open to all libraries. Does this make sense? When "LimitReportsByBranch" is enabled, should reports for non-privileged report creators default to their home library?

Should it then be necessary for a privileged user to share that report with other libraries?
Comment 87 Alex Carver [Acerock7] 2025-09-26 11:56:32 UTC
Hi David-- Yes, this is the workflow that we're looking for at RCLS. We have a library headquarters location defined (with a small circulating professional collection) and reports are written by RCLSHQ staff only. We're nearing on 300+ reports in our prod server, and many of them are Admin or Annual State reports that don't concern our member libraries. This bug will keep the reports module clean and useful for library staff while still keeping admin reports available to admins.

We're also looking forward to creating pre-baked parameter reports that can be emailed via cron. With 46 member libraries, offering these will exponentially balloon our reports library. The ability to hide them for libraries they don't apply to will keep the interface usable.
Comment 88 David Cook 2025-09-28 23:39:54 UTC
(In reply to Alex Carver from comment #87)
> Hi David-- Yes, this is the workflow that we're looking for at RCLS. We have
> a library headquarters location defined (with a small circulating
> professional collection) and reports are written by RCLSHQ staff only. We're
> nearing on 300+ reports in our prod server, and many of them are Admin or
> Annual State reports that don't concern our member libraries. This bug will
> keep the reports module clean and useful for library staff while still
> keeping admin reports available to admins.

Thanks for sharing that, Alex. That's good to know.

What do you think about my comment about how the reports created by your member libraries will be available to all member libraries. Is that something you'd still want? Or should they be limited so that member libraries only see reports created by their own librarians?
Comment 89 Alex Carver [Acerock7] 2025-09-29 11:58:30 UTC
Hi David. In my system--no one can create reports except for me. Thinking through how it would work for other setups, though, it seems to me like anyone who can create a report should be able to assign the reports to libraries as well.
Comment 90 David Cook 2025-09-30 00:06:09 UTC
(In reply to Alex Carver from comment #89)
> Hi David. In my system--no one can create reports except for me. Thinking
> through how it would work for other setups, though, it seems to me like
> anyone who can create a report should be able to assign the reports to
> libraries as well.

I think that could make sense, especially in the context of Library Groups, although that's not how the patched code works. 

Actually, now that I'm thinking about Library Groups, limiting by library groups could be interesting as well...
Comment 91 Casey Conlin 2025-09-30 15:28:41 UTC
(In reply to David Cook from comment #90)
> (In reply to Alex Carver from comment #89)
> > Hi David. In my system--no one can create reports except for me. Thinking
> > through how it would work for other setups, though, it seems to me like
> > anyone who can create a report should be able to assign the reports to
> > libraries as well.
> 
> I think that could make sense, especially in the context of Library Groups,
> although that's not how the patched code works. 
> 

(In reply to David Cook from comment #90)
> (In reply to Alex Carver from comment #89)
> > Hi David. In my system--no one can create reports except for me. Thinking
> > through how it would work for other setups, though, it seems to me like
> > anyone who can create a report should be able to assign the reports to
> > libraries as well.
> 
> I think that could make sense, especially in the context of Library Groups,
> although that's not how the patched code works. 


In the current patch, the ability to limit which libraries can access a report is separated from the ability to create reports. The permission 'Manage Report Limits' was added to allow users besides Superlibrarians to manage who can see reports. This decouples the report access management from report creation, which should be a less-disruptive way to add this enhancement and have admins utilize it; users with the 'Create SQL reports permission' permission will not automatically be able to limit report access, which would be the case if the ability to manage filters were tied directly to this permission. 


Regarding which users can see reports outlined in comment 82 (snippet below), the intention at this point is to limit what's shown in the reports list, but not limit access to limited reports. The language clarifying the preference in System preferences, "limiting report access based on staff home library," needs to be amended to reflect this more clearly. 

From comment 82:
In my test, I can only see report #2, so I run report #2, but then I am curious about report #1, so I change the URL and now I'm running a report that I'm not supposed to be able to see.

It's not 100% clear to me at this stage if that's a bug or a feature. I'm guessing bug, but I figure it's worth asking the question here.
Comment 92 Casey Conlin 2025-10-25 19:36:43 UTC
Created attachment 188444 [details] [review]
0001-Bug-16631-DO-NOT-PUSH-Add-schema-files-for-reports_b.patch
Comment 93 Casey Conlin 2025-10-25 19:37:12 UTC
Created attachment 188445 [details] [review]
0002-Bug-16631-Institute-library-limits.patch
Comment 94 Casey Conlin 2025-10-25 19:39:00 UTC
After some discussion, we've implemented restrictions on reports users aren't permitted to access. Please let us know if you have any questions.
Comment 95 Chris Cormack 2025-11-20 23:22:06 UTC
Automatic patch test results:

â ï¸ The patch applies with fuzzy option (ignoring whitespace).
This may indicate minor conflicts that need to be resolved.

Details: Patch applies with fuzzy option (ignoring whitespace)

This is an automated message from the patch testing system.
Comment 96 Casey Conlin 2025-11-21 00:50:46 UTC
Created attachment 189818 [details] [review]
Bug 16631: [DO NOT PUSH] Add schema files for reports_branches and adjust saved_sql table

This patch adds the reports_branches table to enforce library limits for reports, and adjusts the saved_sql table to point to reports_branches.
Comment 97 Casey Conlin 2025-11-21 00:50:50 UTC
Created attachment 189819 [details] [review]
Bug 16631: Institute library limits This patch implements the library_limit concept for Report/Reports. Staff with the correct permission and superlibrarians can set libaries to which the report should be visible, if the system preference is enabled.

    Test plan:

    Confirm Initial Settings
    1. Log in to Koha staff with username: koha and password: koha and set your library as Centerville if it’s not already.
    2. Visit the Saved reports page, and create and save three reports: Report 1, Report 2, and Report 3. The SQL query for each report doesn't matter, it should just be something valid.
    3. Visit the Patrons page and create two staff users: StaffReportLimitUser and StaffNoLimitPermission. Set their home libraries to Centerville and Fairfield, respectively.
    4. Under Allow access to the reports module, ensure both users have report management permissions for Create, Delete, Execute.

    Verify Patch Settings
    5. Apply the patch, then Restart services.
    6. Click Patrons in the top navbar to go to the Patrons page.
    7. Search for “StaffReportLimitUser” in the patron search field.
    8. Click StaffReportLimitUser to edit the patron record for this user.
    9. Click More -> Set permissions to access the permissions screens for the StaffReportLimitUser.
    10. In the row for Allow access to the reports module (reports), click Show details to view relevant permissions.
    11. Confirm Manage Report Limits (manage_report_limits) is an option under Allow access to the reports module (reports).
    12. Click the checkbox for Manage Report Limits to give this user this permission, and click Save.
    13. Go to the System Preferences page (Click the More dropdown from the top nav bar, click Administration, click System Preferences).
    14. Verify Reports is an option in the left side navigation bar, and that when clicked, you see the LimitReportsByBranch option.
    15. Enable LimitReportsByBranch as described in step 14.
    16. Go back to Saved reports as in Step 2.
    17. Click Edit in the row menu for Report 1.
    18. At the bottom of the Report 1 edit page, you should see a Library limitation select box.

    Verify the Library Limitation Settings are Persisted
    19. Choose Centerville from the select box and click Update SQL.
    20. Reload the page, or navigate away from the page and go back to the edit screen for Report 1.
    21. Verify that Centerville is still in the Library limitation select box.
    22. Add Fairfield in the Library limitation select box and click Update and run SQL.
    23. Go back to editing Report 1.
    24. Confirm the Library limitation select box has both Centerville and Fairfield selected.
    25. Duplicate Report 1.
    26. Confirm the Library limitation select box has both Centerville and Fairfield selected.
    27. Click Save Report.
    28. Confirm the Library limitation select box has both Centerville and Fairfield selected.

    Verify Reports are Limited Based on Library Limitations
    29. Edit Report 1 to add Centerville in the Library limitation select box as the only choice and click Update SQL.
    30. Edit Report 2 to add Fairfield in the Library limitation select box as the only choice and click Update SQL.
    31. Report 3 should have no library limitations, so it should be visible to all libraries.
    32. Go to Saved reports as in Step 2.
    33. Confirm you do not see Report 2, and only Report 1 and Report 3.
    34. In the upper right corner, click the drop down that says koha Centerville and click Set library to change your library.
    35. Set your library to Fairfield.
    36. Go to Saved reports as in Step 2.
    37. Confirm you do not see Report 1, and only Report 2 and Report 3.

    Verify Disabling LimitReportsByBranch Preference Shows All Reports
    38. Disable LimitReportsByBranch preference as in steps 13 to 15.
    39. Go to Saved reports as in Step 2.
    40. Confirm Report 1, Report 2, Report 3 are visible.
    41. Click to edit Report 1 and verify there is no Library limitation select box.

    Verify Library limitations are Persisted When EnableFilteringReports is Toggled On or Off
    42. Enable EnableFilteringReports preference as in steps 13 to 15.
    43. Ensure your library is set to Fairfield as in step 35.
    44. Go to Saved reports as in Step 2.
    45. Confirm Report 1 is not visible, and Report 2 and Report 3 are visible.
    46. Click to edit Report 2 and verify the Library limitation select box is at the bottom of the page and that it has Fairfield selected.

    Verify the Show all reports option shows all reports for users with the Manage Report Limits permission and superlibrarians
    47. Go to Saved reports as in Step 2 and in the Show reports dropdown, select Show all reports, and click Apply filter.
    48. Confirm the page reloads with all reports visible:  Report 1, Report 2, and Report 3 should be visible.
    49. Select Show my branch reports from the dropdown and click Apply filter.
    50. Confirm Report 1 is not visible, and Report 2 and Report 3 are visible (you should only see reports for your branch, Fairfield).

    Verify Report filters return the correct results
    51. Go to Saved reports as in Step 2.
    52. Verify you’re viewing only your branch’s reports in the filter.
    53. Under Filter in the left sidebar, type “2” in the Keyword field and click Apply filter.
    54. Confirm only Report 2 is visible.
    55. Under Filter in the left sidebar, type “1” in the Keyword field and click Apply filter.
    56. Confirm there are no reports visible, and the message "No saved reports match your criteria" is displayed.

    Verify Library Limits column is available to superlibrarians and users with the Manage Report Limits permission
    57. Go to Saved reports as in Step 2.
    58. Click the Columns dropdown and ensure that the Library limits column is available to select for display. Select it.
    59. Confirm that the Library limits column is now visible in the list of reports and that it shows the correct library limitations for each report (e.g., Report 1 should show CPL (Centerville), Re
port 2 should show FFL (Fairfield), and Report 3 should show no limitations).

    Verify the Show all reports and Limit reports options are available to users that are not superlibrarian but have the Manage Report Limits permission
    60. For the StaffReportLimitUser, add the permission for Manage Report Limits as described in steps 9 to 12. This will allow this user to see the Show all reports and Limit reports options.
    61. Log out of the koha admin account. In the upper right corner, click the drop down that says koha Fairfield and click Log out.
    62. Log in as StaffReportLimitUser, the previously created staff user with report permissions.
    63. Confirm the staff user’s library is Centerville in the upper right corner of the screen.
    64. Go to Saved reports as in Step 2.
    65. Confirm the filter option for Show reports is visible.
    66. Click to edit Report 1.
    67. Verify there is a Library limitation select box and that it can be interacted with.

    Verify the Show all reports and Limit reports options are not available to users that are not superlibrarian and do not have the Manage Report Limits permission
    68. Log out of the StaffReportLimitUser account.
    69. Log in as a previously created staff user without report permissions.
    70. Confirm the staff user’s library is Fairfield in the upper right corner of the screen.
    71. Go to Saved reports as in Step 2.
    72. Click the Columns dropdown and ensure that the Library limits column is not in the list of available columns to select for display.
    73. Confirm the filter option for Show reports is not available.
    74. Click to edit Report 2.
    75. Verify there is no Library limitation select box at the bottom of the page.

    Verify limited reports are not visible to users without permissions
    76. Log out of the staff user account without permissions.
    77. Log in as a superlibrarian or a user with the Manage Report Limits permission.
    78. Copy the URL for the edit page of Report 1, and log out of the superlibrarian or user with permissions account.
    79. Log in as, StaffNoLimitPermission, the user without the Manage Report Limits permission.
    80. Paste the copied URL for the edit page of Report 1 into the browser and navigate to it.
    81. Confirm that you see an error message that says "This report is restricted and cannot be accessed by the current user." and that the page does not load the report details.

    Run Unit Tests
    82. Using Koha Testing Docker, in the Koha home directory run the command: ktd --shell to start the ktd shell.
    83. Run command: reset_all to drop and recreate the koha database.
    84. Run command prove t/db_dependent/Koha/Reports.t to run the test.
    85. The new unit tests for the reports_branches tables are in this file.
    86. All tests should pass.
    87. Run command prove t/Koha/Auth/Permissions.t
    88. Permissions unit tests in this file were updated.
    89. All tests should pass
    90. Run command prove t/db_dependent/Reports/Guided.t
    91. The Guided report tests were updated to account for the new library limitations and permissions.
    92. All tests should pass.

    Signoff
    93. Sign off if the steps above check out.

    Sponsored by: Ramapo Catskill Library System
Comment 98 Casey Conlin 2025-12-07 14:23:19 UTC
Created attachment 190276 [details] [review]
Bug 16631: [DO NOT PUSH] Add schema files for reports_branches and adjust saved_sql table

This patch adds the reports_branches table to enforce library limits for reports, and adjusts the saved_sql table to point to reports_branches.

Co-authored-by: Casey Conlin <casey.conlin@gmail.com>
Sponsored-by: Ramapo Catskill Library System
Comment 99 Casey Conlin 2025-12-07 14:23:24 UTC
Created attachment 190277 [details] [review]
Bug 16631: Institute library limits

This patch implements the library_limit concept for Report/Reports. Staff with the correct permission and superlibrarians can set libaries to which the report should be visible, if the system preference is enabled.

    Test plan:

    Confirm Initial Settings
    1. Log in to Koha staff with username: koha and password: koha and set your library as Centerville if it’s not already.
    2. Visit the Saved reports page, and create and save three reports: Report 1, Report 2, and Report 3. The SQL query for each report doesn't matter, it should just be something valid.
    3. Visit the Patrons page and create two staff users: StaffReportLimitUser and StaffNoLimitPermission. Set their home libraries to Centerville and Fairfield, respectively.
    4. Under Allow access to the reports module, ensure both users have report management permissions for Create, Delete, Execute.

    Verify Patch Settings
    5. Apply the patch, then Restart services.
    6. Click Patrons in the top navbar to go to the Patrons page.
    7. Search for “StaffReportLimitUser” in the patron search field.
    8. Click StaffReportLimitUser to edit the patron record for this user.
    9. Click More -> Set permissions to access the permissions screens for the StaffReportLimitUser.
    10. In the row for Allow access to the reports module (reports), click Show details to view relevant permissions.
    11. Confirm Manage Report Limits (manage_report_limits) is an option under Allow access to the reports module (reports).
    12. Click the checkbox for Manage Report Limits to give this user this permission, and click Save.
    13. Go to the System Preferences page (Click the More dropdown from the top nav bar, click Administration, click System Preferences).
    14. Verify Reports is an option in the left side navigation bar, and that when clicked, you see the LimitReportsByBranch option.
    15. Enable LimitReportsByBranch as described in step 14.
    16. Go back to Saved reports as in Step 2.
    17. Click Edit in the row menu for Report 1.
    18. At the bottom of the Report 1 edit page, you should see a Library limitation select box.

    Verify the Library Limitation Settings are Persisted
    19. Choose Centerville from the select box and click Update SQL.
    20. Reload the page, or navigate away from the page and go back to the edit screen for Report 1.
    21. Verify that Centerville is still in the Library limitation select box.
    22. Add Fairfield in the Library limitation select box and click Update and run SQL.
    23. Go back to editing Report 1.
    24. Confirm the Library limitation select box has both Centerville and Fairfield selected.
    25. Duplicate Report 1.
    26. Confirm the Library limitation select box has both Centerville and Fairfield selected.
    27. Click Save Report.
    28. Confirm the Library limitation select box has both Centerville and Fairfield selected.

    Verify Reports are Limited Based on Library Limitations
    29. Edit Report 1 to add Centerville in the Library limitation select box as the only choice and click Update SQL.
    30. Edit Report 2 to add Fairfield in the Library limitation select box as the only choice and click Update SQL.
    31. Report 3 should have no library limitations, so it should be visible to all libraries.
    32. Go to Saved reports as in Step 2.
    33. Confirm you do not see Report 2, and only Report 1 and Report 3.
    34. In the upper right corner, click the drop down that says koha Centerville and click Set library to change your library.
    35. Set your library to Fairfield.
    36. Go to Saved reports as in Step 2.
    37. Confirm you do not see Report 1, and only Report 2 and Report 3.

    Verify Disabling LimitReportsByBranch Preference Shows All Reports
    38. Disable LimitReportsByBranch preference as in steps 13 to 15.
    39. Go to Saved reports as in Step 2.
    40. Confirm Report 1, Report 2, Report 3 are visible.
    41. Click to edit Report 1 and verify there is no Library limitation select box.

    Verify Library limitations are Persisted When EnableFilteringReports is Toggled On or Off
    42. Enable EnableFilteringReports preference as in steps 13 to 15.
    43. Ensure your library is set to Fairfield as in step 35.
    44. Go to Saved reports as in Step 2.
    45. Confirm Report 1 is not visible, and Report 2 and Report 3 are visible.
    46. Click to edit Report 2 and verify the Library limitation select box is at the bottom of the page and that it has Fairfield selected.

    Verify the Show all reports option shows all reports for users with the Manage Report Limits permission and superlibrarians
    47. Go to Saved reports as in Step 2 and in the Show reports dropdown, select Show all reports, and click Apply filter.
    48. Confirm the page reloads with all reports visible:  Report 1, Report 2, and Report 3 should be visible.
    49. Select Show my branch reports from the dropdown and click Apply filter.
    50. Confirm Report 1 is not visible, and Report 2 and Report 3 are visible (you should only see reports for your branch, Fairfield).

    Verify Report filters return the correct results
    51. Go to Saved reports as in Step 2.
    52. Verify you’re viewing only your branch’s reports in the filter.
    53. Under Filter in the left sidebar, type “2” in the Keyword field and click Apply filter.
    54. Confirm only Report 2 is visible.
    55. Under Filter in the left sidebar, type “1” in the Keyword field and click Apply filter.
    56. Confirm there are no reports visible, and the message "No saved reports match your criteria" is displayed.

    Verify Library Limits column is available to superlibrarians and users with the Manage Report Limits permission
    57. Go to Saved reports as in Step 2.
    58. Click the Columns dropdown and ensure that the Library limits column is available to select for display. Select it.
    59. Confirm that the Library limits column is now visible in the list of reports and that it shows the correct library limitations for each report (e.g., Report 1 should show CPL (Centerville), Re
port 2 should show FFL (Fairfield), and Report 3 should show no limitations).

    Verify the Show all reports and Limit reports options are available to users that are not superlibrarian but have the Manage Report Limits permission
    60. For the StaffReportLimitUser, add the permission for Manage Report Limits as described in steps 9 to 12. This will allow this user to see the Show all reports and Limit reports options.
    61. Log out of the koha admin account. In the upper right corner, click the drop down that says koha Fairfield and click Log out.
    62. Log in as StaffReportLimitUser, the previously created staff user with report permissions.
    63. Confirm the staff user’s library is Centerville in the upper right corner of the screen.
    64. Go to Saved reports as in Step 2.
    65. Confirm the filter option for Show reports is visible.
    66. Click to edit Report 1.
    67. Verify there is a Library limitation select box and that it can be interacted with.

    Verify the Show all reports and Limit reports options are not available to users that are not superlibrarian and do not have the Manage Report Limits permission
    68. Log out of the StaffReportLimitUser account.
    69. Log in as a previously created staff user without report permissions.
    70. Confirm the staff user’s library is Fairfield in the upper right corner of the screen.
    71. Go to Saved reports as in Step 2.
    72. Click the Columns dropdown and ensure that the Library limits column is not in the list of available columns to select for display.
    73. Confirm the filter option for Show reports is not available.
    74. Click to edit Report 2.
    75. Verify there is no Library limitation select box at the bottom of the page.

    Verify limited reports are not visible to users without permissions
    76. Log out of the staff user account without permissions.
    77. Log in as a superlibrarian or a user with the Manage Report Limits permission.
    78. Copy the URL for the edit page of Report 1, and log out of the superlibrarian or user with permissions account.
    79. Log in as, StaffNoLimitPermission, the user without the Manage Report Limits permission.
    80. Paste the copied URL for the edit page of Report 1 into the browser and navigate to it.
    81. Confirm that you see an error message that says "This report is restricted and cannot be accessed by the current user." and that the page does not load the report details.

    Run Unit Tests
    82. Using Koha Testing Docker, in the Koha home directory run the command: ktd --shell to start the ktd shell.
    83. Run command: reset_all to drop and recreate the koha database.
    84. Run command prove t/db_dependent/Koha/Reports.t to run the test.
    85. The new unit tests for the reports_branches tables are in this file.
    86. All tests should pass.
    87. Run command prove t/Koha/Auth/Permissions.t
    88. Permissions unit tests in this file were updated.
    89. All tests should pass
    90. Run command prove t/db_dependent/Reports/Guided.t
    91. The Guided report tests were updated to account for the new library limitations and permissions.
    92. All tests should pass.

    Signoff
    93. Sign off if the steps above check out.

Sponsored-by: Ramapo Catskill Library System
Co-authored-by: Casey Conlin <casey.conlin@gmail.com>
Comment 100 carthur@slolibrary.org 2025-12-09 16:15:40 UTC
+1
Comment 101 Jason Robb 2025-12-09 17:27:22 UTC
In the section starting with step 68, logging in with a patron that does *not* have the permission, the "Actions" column in the "Saved reports" table is consistently hidden by default.

Otherwise, up to that point everything seems to be working well as described!

Some other considerations:

It would be nice if the "Library limitation" multi-select used a select2 element like Koha uses elsewhere. That would also allow that input to fit nicely in the area above the SQL block since it takes up less space.

You can see an example at Administration > Item Types > Edit (/cgi-bin/koha/admin/itemtypes.pl?op=add_form&itemtype=BK)

Likewise, it would be nice if the "Library limits" column were consistent with the style that the Item types table uses, where it says the number of limitations and hovering that gives the library names and codes.

That's visible under Administration > Item types after you've set some limitations on an item type (/cgi-bin/koha/admin/itemtypes.pl)
Comment 102 Casey Conlin 2025-12-17 13:25:03 UTC
Created attachment 190573 [details] [review]
Bug 16631: [DO NOT PUSH] Add schema files for reports_branches and adjust saved_sql table

This patch adds the reports_branches table to enforce library limits for reports, and adjusts the saved_sql table to point to reports_branches.

Co-authored-by: Casey Conlin <casey.conlin@gmail.com>
Sponsored-by: Ramapo Catskill Library System
Comment 103 Casey Conlin 2025-12-17 13:25:08 UTC
Created attachment 190574 [details] [review]
Bug 16631: Institute library limits

This patch implements the library_limit concept for Report/Reports. Staff with the correct permission and superlibrarians can set libaries to which the report should be visible, if the system preference is enabled.

    Test plan:

    Confirm Initial Settings
    1. Log in to Koha staff with username: koha and password: koha and set your library as Centerville if it’s not already.
    2. Visit the Saved reports page, and create and save three reports: Report 1, Report 2, and Report 3. The SQL query for each report doesn't matter, it should just be something valid.
    3. Visit the Patrons page and create two staff users: StaffReportLimitUser and StaffNoLimitPermission. Set their home libraries to Centerville and Fairfield, respectively.
    4. Under Allow access to the reports module, ensure both users have report management permissions for Create, Delete, Execute.

    Verify Patch Settings
    5. Apply the patch, then Restart services.
    6. Click Patrons in the top navbar to go to the Patrons page.
    7. Search for “StaffReportLimitUser” in the patron search field.
    8. Click StaffReportLimitUser to edit the patron record for this user.
    9. Click More -> Set permissions to access the permissions screens for the StaffReportLimitUser.
    10. In the row for Allow access to the reports module (reports), click Show details to view relevant permissions.
    11. Confirm Manage Report Limits (manage_report_limits) is an option under Allow access to the reports module (reports).
    12. Click the checkbox for Manage Report Limits to give this user this permission, and click Save.
    13. Go to the System Preferences page (Click the More dropdown from the top nav bar, click Administration, click System Preferences).
    14. Verify Reports is an option in the left side navigation bar, and that when clicked, you see the LimitReportsByBranch option.
    15. Enable LimitReportsByBranch as described in step 14.
    16. Go back to Saved reports as in Step 2.
    17. Click Edit in the row menu for Report 1.
    18. At the bottom of the Report 1 edit page, you should see a Library limitation select box.

    Verify the Library Limitation Settings are Persisted
    19. Choose Centerville from the select box and click Update SQL.
    20. Reload the page, or navigate away from the page and go back to the edit screen for Report 1.
    21. Verify that Centerville is still in the Library limitation select box.
    22. Add Fairfield in the Library limitation select box and click Update and run SQL.
    23. Go back to editing Report 1.
    24. Confirm the Library limitation select box has both Centerville and Fairfield selected.
    25. Duplicate Report 1.
    26. Confirm the Library limitation select box has both Centerville and Fairfield selected.
    27. Click Save Report.
    28. Confirm the Library limitation select box has both Centerville and Fairfield selected.

    Verify Reports are Limited Based on Library Limitations
    29. Edit Report 1 to add Centerville in the Library limitation select box as the only choice and click Update SQL.
    30. Edit Report 2 to add Fairfield in the Library limitation select box as the only choice and click Update SQL.
    31. Report 3 should have no library limitations, so it should be visible to all libraries.
    32. Go to Saved reports as in Step 2.
    33. Confirm you do not see Report 2, and only Report 1 and Report 3.
    34. In the upper right corner, click the drop down that says koha Centerville and click Set library to change your library.
    35. Set your library to Fairfield.
    36. Go to Saved reports as in Step 2.
    37. Confirm you do not see Report 1, and only Report 2 and Report 3.

    Verify Disabling LimitReportsByBranch Preference Shows All Reports
    38. Disable LimitReportsByBranch preference as in steps 13 to 15.
    39. Go to Saved reports as in Step 2.
    40. Confirm Report 1, Report 2, Report 3 are visible.
    41. Click to edit Report 1 and verify there is no Library limitation select box.

    Verify Library limitations are Persisted When EnableFilteringReports is Toggled On or Off
    42. Enable EnableFilteringReports preference as in steps 13 to 15.
    43. Ensure your library is set to Fairfield as in step 35.
    44. Go to Saved reports as in Step 2.
    45. Confirm Report 1 is not visible, and Report 2 and Report 3 are visible.
    46. Click to edit Report 2 and verify the Library limitation select box is at the bottom of the page and that it has Fairfield selected.

    Verify the Show all reports option shows all reports for users with the Manage Report Limits permission and superlibrarians
    47. Go to Saved reports as in Step 2 and in the Show reports dropdown, select Show all reports, and click Apply filter.
    48. Confirm the page reloads with all reports visible:  Report 1, Report 2, and Report 3 should be visible.
    49. Select Show my branch reports from the dropdown and click Apply filter.
    50. Confirm Report 1 is not visible, and Report 2 and Report 3 are visible (you should only see reports for your branch, Fairfield).

    Verify Report filters return the correct results
    51. Go to Saved reports as in Step 2.
    52. Verify you’re viewing only your branch’s reports in the filter.
    53. Under Filter in the left sidebar, type “2” in the Keyword field and click Apply filter.
    54. Confirm only Report 2 is visible.
    55. Under Filter in the left sidebar, type “1” in the Keyword field and click Apply filter.
    56. Confirm there are no reports visible, and the message "No saved reports match your criteria" is displayed.

    Verify Library Limits column is available to superlibrarians and users with the Manage Report Limits permission
    57. Go to Saved reports as in Step 2.
    58. Click the Columns dropdown and ensure that the Library limits column is available to select for display. Select it.
    59. Confirm that the Library limits column is now visible in the list of reports and that it shows the correct library limitations for each report (e.g., Report 1 should show CPL (Centerville), Re
port 2 should show FFL (Fairfield), and Report 3 should show no limitations).

    Verify the Show all reports and Limit reports options are available to users that are not superlibrarian but have the Manage Report Limits permission
    60. For the StaffReportLimitUser, add the permission for Manage Report Limits as described in steps 9 to 12. This will allow this user to see the Show all reports and Limit reports options.
    61. Log out of the koha admin account. In the upper right corner, click the drop down that says koha Fairfield and click Log out.
    62. Log in as StaffReportLimitUser, the previously created staff user with report permissions.
    63. Confirm the staff user’s library is Centerville in the upper right corner of the screen.
    64. Go to Saved reports as in Step 2.
    65. Confirm the filter option for Show reports is visible.
    66. Click to edit Report 1.
    67. Verify there is a Library limitation select box and that it can be interacted with.

    Verify the Show all reports and Limit reports options are not available to users that are not superlibrarian and do not have the Manage Report Limits permission
    68. Log out of the StaffReportLimitUser account.
    69. Log in as a previously created staff user without report permissions.
    70. Confirm the staff user’s library is Fairfield in the upper right corner of the screen.
    71. Go to Saved reports as in Step 2.
    72. Click the Columns dropdown and ensure that the Library limits column is not in the list of available columns to select for display.
    73. Confirm the filter option for Show reports is not available.
    74. Click to edit Report 2.
    75. Verify there is no Library limitation select box at the bottom of the page.

    Verify limited reports are not visible to users without permissions
    76. Log out of the staff user account without permissions.
    77. Log in as a superlibrarian or a user with the Manage Report Limits permission.
    78. Copy the URL for the edit page of Report 1, and log out of the superlibrarian or user with permissions account.
    79. Log in as, StaffNoLimitPermission, the user without the Manage Report Limits permission.
    80. Paste the copied URL for the edit page of Report 1 into the browser and navigate to it.
    81. Confirm that you see an error message that says "This report is restricted and cannot be accessed by the current user." and that the page does not load the report details.

    Run Unit Tests
    82. Using Koha Testing Docker, in the Koha home directory run the command: ktd --shell to start the ktd shell.
    83. Run command: reset_all to drop and recreate the koha database.
    84. Run command prove t/db_dependent/Koha/Reports.t to run the test.
    85. The new unit tests for the reports_branches tables are in this file.
    86. All tests should pass.
    87. Run command prove t/Koha/Auth/Permissions.t
    88. Permissions unit tests in this file were updated.
    89. All tests should pass
    90. Run command prove t/db_dependent/Reports/Guided.t
    91. The Guided report tests were updated to account for the new library limitations and permissions.
    92. All tests should pass.

    Signoff
    93. Sign off if the steps above check out.

Sponsored-by: Ramapo Catskill Library System
Co-authored-by: Casey Conlin <casey.conlin@gmail.com>

Fix actions column, add select2 to limits, move limits, update limits column.

Fix actions column, add select2 to limits, move limits, update limits column.

Update column visibility handling.

Remove note.
Comment 104 Casey Conlin 2025-12-17 13:30:38 UTC
(In reply to Jason Robb from comment #101)
> In the section starting with step 68, logging in with a patron that does
> *not* have the permission, the "Actions" column in the "Saved reports" table
> is consistently hidden by default.
> 
> Otherwise, up to that point everything seems to be working well as described!
> 
> Some other considerations:
> 
> It would be nice if the "Library limitation" multi-select used a select2
> element like Koha uses elsewhere. That would also allow that input to fit
> nicely in the area above the SQL block since it takes up less space.
> 
> You can see an example at Administration > Item Types > Edit
> (/cgi-bin/koha/admin/itemtypes.pl?op=add_form&itemtype=BK)
> 
> Likewise, it would be nice if the "Library limits" column were consistent
> with the style that the Item types table uses, where it says the number of
> limitations and hovering that gives the library names and codes.
> 
> That's visible under Administration > Item types after you've set some
> limitations on an item type (/cgi-bin/koha/admin/itemtypes.pl)

Thank you for this feedback Jason! We were able to address each of the items you mentioned.

> In the section starting with step 68, logging in with a patron that does
> *not* have the permission, the "Actions" column in the "Saved reports" table
> is consistently hidden by default.

Great catch here! This has been fixed. 

> It would be nice if the "Library limitation" multi-select used a select2
> element like Koha uses elsewhere. That would also allow that input to fit
> nicely in the area above the SQL block since it takes up less space.

Thank you for this suggestion (and for the lead on where to find a similar implementation). This has been implemented in the new patch files, and it looks and functions better.

> Likewise, it would be nice if the "Library limits" column were consistent
> with the style that the Item types table uses, where it says the number of
> limitations and hovering that gives the library names and codes.

This is also a great suggestion. We've implemented this, and the result is a much cleaner-looking table. 

Thank you again for this feedback. Please let me know if you find anything else we can improve here.
Comment 105 Casey Conlin 2025-12-28 18:04:51 UTC
Created attachment 190749 [details] [review]
Bug 16631: [DO NOT PUSH] Add schema files for reports_branches and adjust saved_sql table

This patch adds the reports_branches table to enforce library limits for reports, and adjusts the saved_sql table to point to reports_branches.

Co-authored-by: Casey Conlin <casey.conlin@gmail.com>
Sponsored-by: Ramapo Catskill Library System
Comment 106 Casey Conlin 2025-12-28 18:04:56 UTC
Created attachment 190750 [details] [review]
Bug 16631: Institute library limits

This patch implements the library_limit concept for Report/Reports. Staff with the correct permission and superlibrarians can set libaries to which the report should be visible, if the system preference is enabled.

    Test plan:

    Confirm Initial Settings
    1. Log in to Koha staff with username: koha and password: koha and set your library as Centerville if it’s not already.
    2. Visit the Saved reports page, and create and save three reports: Report 1, Report 2, and Report 3. The SQL query for each report doesn't matter, it should just be something valid.
    3. Visit the Patrons page and create two staff users: StaffReportLimitUser and StaffNoLimitPermission. Set their home libraries to Centerville and Fairfield, respectively.
    4. Under Allow access to the reports module, ensure both users have report management permissions for Create, Delete, Execute.

    Verify Patch Settings
    5. Apply the patch, then Restart services.
    6. Click Patrons in the top navbar to go to the Patrons page.
    7. Search for “StaffReportLimitUser” in the patron search field.
    8. Click StaffReportLimitUser to edit the patron record for this user.
    9. Click More -> Set permissions to access the permissions screens for the StaffReportLimitUser.
    10. In the row for Allow access to the reports module (reports), click Show details to view relevant permissions.
    11. Confirm Manage Report Limits (manage_report_limits) is an option under Allow access to the reports module (reports).
    12. Click the checkbox for Manage Report Limits to give this user this permission, and click Save.
    13. Go to the System Preferences page (Click the More dropdown from the top nav bar, click Administration, click System Preferences).
    14. Verify Reports is an option in the left side navigation bar, and that when clicked, you see the LimitReportsByBranch option.
    15. Enable LimitReportsByBranch as described in step 14.
    16. Go back to Saved reports as in Step 2.
    17. Click Edit in the row menu for Report 1.
    18. At the bottom of the Report 1 edit page, you should see a Library limitation select box.

    Verify the Library Limitation Settings are Persisted
    19. Choose Centerville from the select box and click Update SQL.
    20. Reload the page, or navigate away from the page and go back to the edit screen for Report 1.
    21. Verify that Centerville is still in the Library limitation select box.
    22. Add Fairfield in the Library limitation select box and click Update and run SQL.
    23. Go back to editing Report 1.
    24. Confirm the Library limitation select box has both Centerville and Fairfield selected.
    25. Duplicate Report 1.
    26. Confirm the Library limitation select box has both Centerville and Fairfield selected.
    27. Click Save Report.
    28. Confirm the Library limitation select box has both Centerville and Fairfield selected.

    Verify Reports are Limited Based on Library Limitations
    29. Edit Report 1 to add Centerville in the Library limitation select box as the only choice and click Update SQL.
    30. Edit Report 2 to add Fairfield in the Library limitation select box as the only choice and click Update SQL.
    31. Report 3 should have no library limitations, so it should be visible to all libraries.
    32. Go to Saved reports as in Step 2.
    33. Confirm you do not see Report 2, and only Report 1 and Report 3.
    34. In the upper right corner, click the drop down that says koha Centerville and click Set library to change your library.
    35. Set your library to Fairfield.
    36. Go to Saved reports as in Step 2.
    37. Confirm you do not see Report 1, and only Report 2 and Report 3.

    Verify Disabling LimitReportsByBranch Preference Shows All Reports
    38. Disable LimitReportsByBranch preference as in steps 13 to 15.
    39. Go to Saved reports as in Step 2.
    40. Confirm Report 1, Report 2, Report 3 are visible.
    41. Click to edit Report 1 and verify there is no Library limitation select box.

    Verify Library limitations are Persisted When EnableFilteringReports is Toggled On or Off
    42. Enable EnableFilteringReports preference as in steps 13 to 15.
    43. Ensure your library is set to Fairfield as in step 35.
    44. Go to Saved reports as in Step 2.
    45. Confirm Report 1 is not visible, and Report 2 and Report 3 are visible.
    46. Click to edit Report 2 and verify the Library limitation select box is at the bottom of the page and that it has Fairfield selected.

    Verify the Show all reports option shows all reports for users with the Manage Report Limits permission and superlibrarians
    47. Go to Saved reports as in Step 2 and in the Show reports dropdown, select Show all reports, and click Apply filter.
    48. Confirm the page reloads with all reports visible:  Report 1, Report 2, and Report 3 should be visible.
    49. Select Show my branch reports from the dropdown and click Apply filter.
    50. Confirm Report 1 is not visible, and Report 2 and Report 3 are visible (you should only see reports for your branch, Fairfield).

    Verify Report filters return the correct results
    51. Go to Saved reports as in Step 2.
    52. Verify you’re viewing only your branch’s reports in the filter.
    53. Under Filter in the left sidebar, type “2” in the Keyword field and click Apply filter.
    54. Confirm only Report 2 is visible.
    55. Under Filter in the left sidebar, type “1” in the Keyword field and click Apply filter.
    56. Confirm there are no reports visible, and the message "No saved reports match your criteria" is displayed.

    Verify Library Limits column is available to superlibrarians and users with the Manage Report Limits permission
    57. Go to Saved reports as in Step 2.
    58. Click the Columns dropdown and ensure that the Library limits column is available to select for display. Select it.
    59. Confirm that the Library limits column is now visible in the list of reports and that it shows the correct library limitations for each report (e.g., Report 1 should show 1 library limitation and Centerville (CPL) on hover, Report 2 should show 1 library limitation and FFL (Fairfield) on hover, and Report 3 should show no limitation).

    Verify the Show all reports and Limit reports options are available to users that are not superlibrarian but have the Manage Report Limits permission
    60. For the StaffReportLimitUser, add the permission for Manage Report Limits as described in steps 9 to 12. This will allow this user to see the Show all reports and Limit reports options.
    61. Log out of the koha admin account. In the upper right corner, click the drop down that says koha Fairfield and click Log out.
    62. Log in as StaffReportLimitUser, the previously created staff user with report permissions.
    63. Confirm the staff user’s library is Centerville in the upper right corner of the screen.
    64. Go to Saved reports as in Step 2.
    65. Confirm the filter option for Show reports is visible.
    66. Click to edit Report 1.
    67. Verify there is a Library limitation select box and that it can be interacted with.

    Verify the Show all reports and Limit reports options are not available to users that are not superlibrarian and do not have the Manage Report Limits permission
    68. Log out of the StaffReportLimitUser account.
    69. Log in as a previously created staff user without report permissions.
    70. Confirm the staff user’s library is Fairfield in the upper right corner of the screen.
    71. Go to Saved reports as in Step 2.
    72. Click the Columns dropdown and ensure that the Library limits column is not in the list of available columns to select for display.
    73. Confirm the filter option for Show reports is not available.
    74. Click to edit Report 2.
    75. Verify there is no Library limitation select box at the bottom of the page.

    Verify limited reports are not visible to users without permissions
    76. Log out of the staff user account without permissions.
    77. Log in as a superlibrarian or a user with the Manage Report Limits permission.
    78. Copy the URL for the edit page of Report 1, and log out of the superlibrarian or user with permissions account.
    79. Log in as, StaffNoLimitPermission, the user without the Manage Report Limits permission.
    80. Paste the copied URL for the edit page of Report 1 into the browser and navigate to it.
    81. Confirm that you see an error message that says "This report is restricted and cannot be accessed by the current user." and that the page does not load the report details.

    Run Unit Tests
    82. Using Koha Testing Docker, in the Koha home directory run the command: ktd --shell to start the ktd shell.
    83. Run command: reset_all to drop and recreate the koha database.
    84. Run command prove t/db_dependent/Koha/Reports.t to run the test.
    85. The new unit tests for the reports_branches tables are in this file.
    86. All tests should pass.
    87. Run command prove t/Koha/Auth/Permissions.t
    88. Permissions unit tests in this file were updated.
    89. All tests should pass
    90. Run command prove t/db_dependent/Reports/Guided.t
    91. The Guided report tests were updated to account for the new library limitations and permissions.
    92. All tests should pass.

    Signoff
    93. Sign off if the steps above check out.

Sponsored-by: Ramapo Catskill Library System
Co-authored-by: Casey Conlin <casey.conlin@gmail.com>
Comment 107 Casey Conlin 2025-12-28 18:08:32 UTC
Created attachment 190751 [details] [review]
Bug 16631: [DO NOT PUSH] Add schema files for reports_branches and adjust saved_sql table

This patch adds the reports_branches table to enforce library limits for reports, and adjusts the saved_sql table to point to reports_branches.

Co-authored-by: Casey Conlin <casey.conlin@gmail.com>
Sponsored-by: Ramapo Catskill Library System
Comment 108 Casey Conlin 2025-12-28 18:08:37 UTC
Created attachment 190752 [details] [review]
Bug 16631: Institute library limits

This patch implements the library_limit concept for Report/Reports. Staff with the correct permission and superlibrarians can set libaries to which the report should be visible, if the system preference is enabled.

    Test plan:

    Confirm Initial Settings
    1. Log in to Koha staff with username: koha and password: koha and set your library as Centerville if it’s not already.
    2. Visit the Saved reports page, and create and save three reports: Report 1, Report 2, and Report 3. The SQL query for each report doesn't matter, it should just be something valid.
    3. Visit the Patrons page and create two staff users: StaffReportLimitUser and StaffNoLimitPermission. Set their home libraries to Centerville and Fairfield, respectively.
    4. Under Allow access to the reports module, ensure both users have report management permissions for Create, Delete, Execute.

    Verify Patch Settings
    5. Apply the patch, then Restart services.
    6. Click Patrons in the top navbar to go to the Patrons page.
    7. Search for “StaffReportLimitUser” in the patron search field.
    8. Click StaffReportLimitUser to edit the patron record for this user.
    9. Click More -> Set permissions to access the permissions screens for the StaffReportLimitUser.
    10. In the row for Allow access to the reports module (reports), click Show details to view relevant permissions.
    11. Confirm Manage Report Limits (manage_report_limits) is an option under Allow access to the reports module (reports).
    12. Click the checkbox for Manage Report Limits to give this user this permission, and click Save.
    13. Go to the System Preferences page (Click the More dropdown from the top nav bar, click Administration, click System Preferences).
    14. Verify Reports is an option in the left side navigation bar, and that when clicked, you see the LimitReportsByBranch option.
    15. Enable LimitReportsByBranch as described in step 14.
    16. Go back to Saved reports as in Step 2.
    17. Click Edit in the row menu for Report 1.
    18. At the bottom of the Report 1 edit page, you should see a Library limitation select box.

    Verify the Library Limitation Settings are Persisted
    19. Choose Centerville from the select box and click Update SQL.
    20. Reload the page, or navigate away from the page and go back to the edit screen for Report 1.
    21. Verify that Centerville is still in the Library limitation select box.
    22. Add Fairfield in the Library limitation select box and click Update and run SQL.
    23. Go back to editing Report 1.
    24. Confirm the Library limitation select box has both Centerville and Fairfield selected.
    25. Duplicate Report 1.
    26. Confirm the Library limitation select box has both Centerville and Fairfield selected.
    27. Click Save Report.
    28. Confirm the Library limitation select box has both Centerville and Fairfield selected.

    Verify Reports are Limited Based on Library Limitations
    29. Edit Report 1 to add Centerville in the Library limitation select box as the only choice and click Update SQL.
    30. Edit Report 2 to add Fairfield in the Library limitation select box as the only choice and click Update SQL.
    31. Report 3 should have no library limitations, so it should be visible to all libraries.
    32. Go to Saved reports as in Step 2.
    33. Confirm you do not see Report 2, and only Report 1 and Report 3.
    34. In the upper right corner, click the drop down that says koha Centerville and click Set library to change your library.
    35. Set your library to Fairfield.
    36. Go to Saved reports as in Step 2.
    37. Confirm you do not see Report 1, and only Report 2 and Report 3.

    Verify Disabling LimitReportsByBranch Preference Shows All Reports
    38. Disable LimitReportsByBranch preference as in steps 13 to 15.
    39. Go to Saved reports as in Step 2.
    40. Confirm Report 1, Report 2, Report 3 are visible.
    41. Click to edit Report 1 and verify there is no Library limitation select box.

    Verify Library limitations are Persisted When EnableFilteringReports is Toggled On or Off
    42. Enable EnableFilteringReports preference as in steps 13 to 15.
    43. Ensure your library is set to Fairfield as in step 35.
    44. Go to Saved reports as in Step 2.
    45. Confirm Report 1 is not visible, and Report 2 and Report 3 are visible.
    46. Click to edit Report 2 and verify the Library limitation select box is at the bottom of the page and that it has Fairfield selected.

    Verify the Show all reports option shows all reports for users with the Manage Report Limits permission and superlibrarians
    47. Go to Saved reports as in Step 2 and in the Show reports dropdown, select Show all reports, and click Apply filter.
    48. Confirm the page reloads with all reports visible:  Report 1, Report 2, and Report 3 should be visible.
    49. Select Show my branch reports from the dropdown and click Apply filter.
    50. Confirm Report 1 is not visible, and Report 2 and Report 3 are visible (you should only see reports for your branch, Fairfield).

    Verify Report filters return the correct results
    51. Go to Saved reports as in Step 2.
    52. Verify you’re viewing only your branch’s reports in the filter.
    53. Under Filter in the left sidebar, type “2” in the Keyword field and click Apply filter.
    54. Confirm only Report 2 is visible.
    55. Under Filter in the left sidebar, type “1” in the Keyword field and click Apply filter.
    56. Confirm there are no reports visible, and the message "No saved reports match your criteria" is displayed.

    Verify Library Limits column is available to superlibrarians and users with the Manage Report Limits permission
    57. Go to Saved reports as in Step 2.
    58. Click the Columns dropdown and ensure that the Library limits column is available to select for display. Select it.
    59. Confirm that the Library limits column is now visible in the list of reports and that it shows the correct library limitations for each report (e.g., Report 1 should show 1 library limitation and Centerville (CPL) on hover, Report 2 should show 1 library limitation and Fairfield (FFL) on hover, and Report 3 should show no limitation).

    Verify the Show all reports and Limit reports options are available to users that are not superlibrarian but have the Manage Report Limits permission
    60. For the StaffReportLimitUser, add the permission for Manage Report Limits as described in steps 9 to 12. This will allow this user to see the Show all reports and Limit reports options.
    61. Log out of the koha admin account. In the upper right corner, click the drop down that says koha Fairfield and click Log out.
    62. Log in as StaffReportLimitUser, the previously created staff user with report permissions.
    63. Confirm the staff user’s library is Centerville in the upper right corner of the screen.
    64. Go to Saved reports as in Step 2.
    65. Confirm the filter option for Show reports is visible.
    66. Click to edit Report 1.
    67. Verify there is a Library limitation select box and that it can be interacted with.

    Verify the Show all reports and Limit reports options are not available to users that are not superlibrarian and do not have the Manage Report Limits permission
    68. Log out of the StaffReportLimitUser account.
    69. Log in as a previously created staff user without report permissions.
    70. Confirm the staff user’s library is Fairfield in the upper right corner of the screen.
    71. Go to Saved reports as in Step 2.
    72. Click the Columns dropdown and ensure that the Library limits column is not in the list of available columns to select for display.
    73. Confirm the filter option for Show reports is not available.
    74. Click to edit Report 2.
    75. Verify there is no Library limitation select box at the bottom of the page.

    Verify limited reports are not visible to users without permissions
    76. Log out of the staff user account without permissions.
    77. Log in as a superlibrarian or a user with the Manage Report Limits permission.
    78. Copy the URL for the edit page of Report 1, and log out of the superlibrarian or user with permissions account.
    79. Log in as, StaffNoLimitPermission, the user without the Manage Report Limits permission.
    80. Paste the copied URL for the edit page of Report 1 into the browser and navigate to it.
    81. Confirm that you see an error message that says "This report is restricted and cannot be accessed by the current user." and that the page does not load the report details.

    Run Unit Tests
    82. Using Koha Testing Docker, in the Koha home directory run the command: ktd --shell to start the ktd shell.
    83. Run command: reset_all to drop and recreate the koha database.
    84. Run command prove t/db_dependent/Koha/Reports.t to run the test.
    85. The new unit tests for the reports_branches tables are in this file.
    86. All tests should pass.
    87. Run command prove t/Koha/Auth/Permissions.t
    88. Permissions unit tests in this file were updated.
    89. All tests should pass
    90. Run command prove t/db_dependent/Reports/Guided.t
    91. The Guided report tests were updated to account for the new library limitations and permissions.
    92. All tests should pass.

    Signoff
    93. Sign off if the steps above check out.

Sponsored-by: Ramapo Catskill Library System
Co-authored-by: Casey Conlin <casey.conlin@gmail.com>