Bug 40841

Summary: Limit z39.50 targets to specific branches
Product: Koha Reporter: Andrew Fuerste-Henry <andrew>
Component: CatalogingAssignee: Tomás Cohen Arazi (tcohen) <tomascohen>
Status: Signed Off --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: david, esther.melander, hebah, m.de.rooy, mnero, tomascohen
Version: Main   
Hardware: All   
OS: All   
GIT URL: Initiative type: ---
Sponsorship status: --- Comma delimited list of Sponsors:
Crowdfunding goal: 0 Patch complexity: Medium patch
Documentation contact: Documentation submission:
Text to go in the release notes:
This enhancement adds the option to limit the Z3950/SRU targets to specific libraries. Within larger systems, catalogers at individual library may have different z39.50 targets that they prefer to use or are allowed access to.
Version(s) released in:
Circulation function:
Bug Depends on:    
Bug Blocks: 41136    
Attachments: Bug 40841: DB changes
Bug 40841: Add Z39.50 library limits
Bug 40841: DBIC schema [DO NOT PUSH]
Bug 40841: Add limits configuration UI
Bug 40841: Implement library limits on Z39.50 searches
Obsoletes: 188587 - Bug 40841: DB changes
Bug 40841: Add Z39.50 library limits
Bug 40841: DBIC schema [DO NOT PUSH]
Bug 40841: Add limits configuration UI
Bug 40841: Implement library limits on Z39.50 searches
Bug 40841: DB changes
Bug 40841: Add Z39.50 library limits
Bug 40841: DBIC schema [DO NOT PUSH]
Bug 40841: Add limits configuration UI
Bug 40841: Implement library limits on Z39.50 searches
Bug 40841: DB changes
Bug 40841: Add Z39.50 library limits
Bug 40841: DBIC schema [DO NOT PUSH]
Bug 40841: Add limits configuration UI
Bug 40841: Implement library limits on Z39.50 searches
Bug 40841: DB changes
Bug 40841: Add Z39.50 library limits
Bug 40841: DBIC schema [DO NOT PUSH]
Bug 40841: Add limits configuration UI
Bug 40841: Implement library limits on Z39.50 searches

Description Andrew Fuerste-Henry 2025-09-18 19:47:10 UTC
Within larger systems, catalogers at each individual library have different z39.50 targets that they prefer to use or are allowed access to. It would be good to limit z39.50 targets based on the user's logged-in branch.

Bug 5316 proposes limiting access per user. While that could also be helpful, limiting by branch offers a more lightweight and flexible option.
Comment 1 Tomás Cohen Arazi (tcohen) 2025-10-29 18:09:22 UTC
Created attachment 188587 [details] [review]
Bug 40841: DB changes
Comment 2 Tomás Cohen Arazi (tcohen) 2025-10-29 18:09:24 UTC
Created attachment 188588 [details] [review]
Bug 40841: Add Z39.50 library limits

This patch adds the library limits mixin to the Z39.50 classes following
a well established pattern in Koha.
Comment 3 Tomás Cohen Arazi (tcohen) 2025-10-29 18:09:26 UTC
Created attachment 188589 [details] [review]
Bug 40841: DBIC schema [DO NOT PUSH]

Patch from commit 56ac99b
Comment 4 Tomás Cohen Arazi (tcohen) 2025-10-29 18:09:28 UTC
Created attachment 188590 [details] [review]
Bug 40841: Add limits configuration UI

This patch adds branch limits selection to the Z30.50/SRU configuration
page.
Comment 5 Tomás Cohen Arazi (tcohen) 2025-10-29 18:09:30 UTC
Created attachment 188591 [details] [review]
Bug 40841: Implement library limits on Z39.50 searches

This patchset implements Z39.50/SRU limits by branch in Koha.

Key implementation notes:
- Follows Koha's established pattern for library limits
- A new table linking to library limits is added
- The admin UI is adjusted so the form includes library limit selection
- Z39.50/SRU search controllers use the `search_with_library_limits`
  methods to correctly constraint the offered servers.

To test:
1. Apply this patches
2. Run:
   $ ktd --shell
  k$ updatedatabase
=> SUCCESS: Database upgrade goes well
3. Re-run:
  k$ updatedatabase
=> SUCCESS: No explosions, DB update idempotent
4. Restart everything:
  k$ restart_all
5. POint your browser to the admin page:
   http://kohadev-intra.localhost/cgi-bin/koha/admin/z3950servers.pl
=> SUCCESS: A new column is displayed for library limits brief
6. Edit `LIBRARY OF CONGRESS`
=> SUCCESS: The form includes the usual library limit selection UI
7. Choose some branches, excluding your current one (KTD's default is
   'Centerville').
8. Save
=> SUCCESS: It is saved correctly
=> SUCCESS: The table shows the edited library has the library limits
set
9. Edit again
=> SUCCESS: The selected limits are preserved when editing
10. Pick some authorities Z39.50 target, and exclude your current branch
    for testing purposes.
11. Go to Cataloguing, and choose 'New from Z39.50/SRU'
=> SUCCESS: Limits are respected!
12. Go to Authorities, and choose 'New from Z39.50/SRU'
=> SUCCESS: Limits are respected!
13. Sign off :-D
Comment 6 Andrew Fuerste-Henry 2025-10-29 19:20:16 UTC
This explodes when attempting to add a new z30.50 or SRU server.
Also, these limits should apply in the advanced editor.
Comment 7 Tomás Cohen Arazi (tcohen) 2025-10-29 20:20:06 UTC Comment hidden (obsolete)
Comment 8 Tomás Cohen Arazi (tcohen) 2025-10-29 20:20:08 UTC
Created attachment 188598 [details] [review]
Bug 40841: Add Z39.50 library limits

This patch adds the library limits mixin to the Z39.50 classes following
a well established pattern in Koha.
Comment 9 Tomás Cohen Arazi (tcohen) 2025-10-29 20:20:10 UTC
Created attachment 188599 [details] [review]
Bug 40841: DBIC schema [DO NOT PUSH]

Patch from commit c86690d
Comment 10 Tomás Cohen Arazi (tcohen) 2025-10-29 20:20:12 UTC
Created attachment 188600 [details] [review]
Bug 40841: Add limits configuration UI

This patch adds branch limits selection to the Z30.50/SRU configuration
page.
Comment 11 Tomás Cohen Arazi (tcohen) 2025-10-29 20:20:14 UTC
Created attachment 188601 [details] [review]
Bug 40841: Implement library limits on Z39.50 searches

This patchset implements Z39.50/SRU limits by branch in Koha.

Key implementation notes:
- Follows Koha's established pattern for library limits
- A new table linking to library limits is added
- The admin UI is adjusted so the form includes library limit selection
- Z39.50/SRU search controllers use the `search_with_library_limits`
  methods to correctly constraint the offered servers.

To test:
1. Apply this patches
2. Run:
   $ ktd --shell
  k$ updatedatabase
=> SUCCESS: Database upgrade goes well
3. Re-run:
  k$ updatedatabase
=> SUCCESS: No explosions, DB update idempotent
4. Restart everything:
  k$ restart_all
5. POint your browser to the admin page:
   http://kohadev-intra.localhost/cgi-bin/koha/admin/z3950servers.pl
=> SUCCESS: A new column is displayed for library limits brief
6. Edit `LIBRARY OF CONGRESS`
=> SUCCESS: The form includes the usual library limit selection UI
7. Choose some branches, excluding your current one (KTD's default is
   'Centerville').
8. Save
=> SUCCESS: It is saved correctly
=> SUCCESS: The table shows the edited library has the library limits
set
9. Edit again
=> SUCCESS: The selected limits are preserved when editing
10. Pick some authorities Z39.50 target, and exclude your current branch
    for testing purposes.
11. Go to Cataloguing, and choose 'New from Z39.50/SRU'
=> SUCCESS: Limits are respected!
12. Go to Authorities, and choose 'New from Z39.50/SRU'
=> SUCCESS: Limits are respected!
13. Sign off :-D
Comment 12 Tomás Cohen Arazi (tcohen) 2025-10-29 20:24:56 UTC
Andrew,

(In reply to Andrew Fuerste-Henry from comment #6)
> This explodes when attempting to add a new z30.50 or SRU server.

=> solved!

> Also, these limits should apply in the advanced editor.

=> solved!

Also noticed the advanced editor didn't allow using SRU servers! Fixed on a separate bug so it can be backported and made this dependent on it!
Comment 13 Tomás Cohen Arazi (tcohen) 2025-10-29 20:28:41 UTC
Created attachment 188602 [details] [review]
Bug 40841: DB changes
Comment 14 Tomás Cohen Arazi (tcohen) 2025-10-29 20:28:44 UTC
Created attachment 188603 [details] [review]
Bug 40841: Add Z39.50 library limits

This patch adds the library limits mixin to the Z39.50 classes following
a well established pattern in Koha.
Comment 15 Tomás Cohen Arazi (tcohen) 2025-10-29 20:28:46 UTC
Created attachment 188604 [details] [review]
Bug 40841: DBIC schema [DO NOT PUSH]

Patch from commit c86690d
Comment 16 Tomás Cohen Arazi (tcohen) 2025-10-29 20:28:48 UTC
Created attachment 188605 [details] [review]
Bug 40841: Add limits configuration UI

This patch adds branch limits selection to the Z30.50/SRU configuration
page.
Comment 17 Tomás Cohen Arazi (tcohen) 2025-10-29 20:28:50 UTC
Created attachment 188606 [details] [review]
Bug 40841: Implement library limits on Z39.50 searches

This patchset implements Z39.50/SRU limits by branch in Koha.

Key implementation notes:
- Follows Koha's established pattern for library limits
- A new table linking to library limits is added
- The admin UI is adjusted so the form includes library limit selection
- Z39.50/SRU search controllers use the `search_with_library_limits`
  methods to correctly constraint the offered servers.

To test:
1. Apply this patches
2. Run:
   $ ktd --shell
  k$ updatedatabase
=> SUCCESS: Database upgrade goes well
3. Re-run:
  k$ updatedatabase
=> SUCCESS: No explosions, DB update idempotent
4. Restart everything:
  k$ restart_all
5. POint your browser to the admin page:
   http://kohadev-intra.localhost/cgi-bin/koha/admin/z3950servers.pl
=> SUCCESS: A new column is displayed for library limits brief
6. Edit `LIBRARY OF CONGRESS`
=> SUCCESS: The form includes the usual library limit selection UI
7. Choose some branches, excluding your current one (KTD's default is
   'Centerville').
8. Save
=> SUCCESS: It is saved correctly
=> SUCCESS: The table shows the edited library has the library limits
set
9. Edit again
=> SUCCESS: The selected limits are preserved when editing
10. Pick some authorities Z39.50 target, and exclude your current branch
    for testing purposes.
11. Go to Cataloguing, and choose 'New from Z39.50/SRU'
=> SUCCESS: Limits are respected!
12. Go to Authorities, and choose 'New from Z39.50/SRU'
=> SUCCESS: Limits are respected!
13. Sign off :-D
Comment 18 David Nind 2025-11-11 18:00:01 UTC
The patches no longer apply 8-(...

git bz apply 40841

Bug 40841 - Limit z39.50 targets to specific branches

188602 - Bug 40841: DB changes
188603 - Bug 40841: Add Z39.50 library limits
188604 - Bug 40841: DBIC schema [DO NOT PUSH]
188605 - Bug 40841: Add limits configuration UI
188606 - Bug 40841: Implement library limits on Z39.50 searches

Apply? [(y)es, (n)o, (i)nteractive] y
Applying: Bug 40841: DB changes
Applying: Bug 40841: Add Z39.50 library limits
Applying: Bug 40841: DBIC schema [DO NOT PUSH]
Applying: Bug 40841: Add limits configuration UI
Applying: Bug 40841: Implement library limits on Z39.50 searches
Using index info to reconstruct a base tree...
M	cataloguing/editor.pl
Falling back to patching base and 3-way merge...
Auto-merging cataloguing/editor.pl
CONFLICT (content): Merge conflict in cataloguing/editor.pl
error: Failed to merge in the changes.
Patch failed at 0001 Bug 40841: Implement library limits on Z39.50 searches
Comment 19 Tomás Cohen Arazi (tcohen) 2025-11-11 23:06:28 UTC
Created attachment 189497 [details] [review]
Bug 40841: DB changes

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Comment 20 Tomás Cohen Arazi (tcohen) 2025-11-11 23:06:30 UTC
Created attachment 189498 [details] [review]
Bug 40841: Add Z39.50 library limits

This patch adds the library limits mixin to the Z39.50 classes following
a well established pattern in Koha.

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Comment 21 Tomás Cohen Arazi (tcohen) 2025-11-11 23:06:32 UTC
Created attachment 189499 [details] [review]
Bug 40841: DBIC schema [DO NOT PUSH]

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Comment 22 Tomás Cohen Arazi (tcohen) 2025-11-11 23:06:34 UTC
Created attachment 189500 [details] [review]
Bug 40841: Add limits configuration UI

This patch adds branch limits selection to the Z30.50/SRU configuration
page.

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Comment 23 Tomás Cohen Arazi (tcohen) 2025-11-11 23:06:36 UTC
Created attachment 189501 [details] [review]
Bug 40841: Implement library limits on Z39.50 searches

This patchset implements Z39.50/SRU limits by branch in Koha.

Key implementation notes:
- Follows Koha's established pattern for library limits
- A new table linking to library limits is added
- The admin UI is adjusted so the form includes library limit selection
- Z39.50/SRU search controllers use the `search_with_library_limits`
  methods to correctly constraint the offered servers.

To test:
1. Apply this patches
2. Run:
   $ ktd --shell
  k$ updatedatabase
=> SUCCESS: Database upgrade goes well
3. Re-run:
  k$ updatedatabase
=> SUCCESS: No explosions, DB update idempotent
4. Restart everything:
  k$ restart_all
5. POint your browser to the admin page:
   http://kohadev-intra.localhost/cgi-bin/koha/admin/z3950servers.pl
=> SUCCESS: A new column is displayed for library limits brief
6. Edit `LIBRARY OF CONGRESS`
=> SUCCESS: The form includes the usual library limit selection UI
7. Choose some branches, excluding your current one (KTD's default is
   'Centerville').
8. Save
=> SUCCESS: It is saved correctly
=> SUCCESS: The table shows the edited library has the library limits
set
9. Edit again
=> SUCCESS: The selected limits are preserved when editing
10. Pick some authorities Z39.50 target, and exclude your current branch
    for testing purposes.
11. Go to Cataloguing, and choose 'New from Z39.50/SRU'
=> SUCCESS: Limits are respected!
12. Go to Authorities, and choose 'New from Z39.50/SRU'
=> SUCCESS: Limits are respected!
13. Same as 11 but with the advanced editor
=> SUCCESS: Limits are respected!
14. Sign off :-D

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Comment 24 David Nind 2025-11-12 19:27:58 UTC
Created attachment 189521 [details] [review]
Bug 40841: DB changes

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>
Comment 25 David Nind 2025-11-12 19:28:02 UTC
Created attachment 189522 [details] [review]
Bug 40841: Add Z39.50 library limits

This patch adds the library limits mixin to the Z39.50 classes following
a well established pattern in Koha.

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>
Comment 26 David Nind 2025-11-12 19:28:06 UTC
Created attachment 189523 [details] [review]
Bug 40841: DBIC schema [DO NOT PUSH]

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>
Comment 27 David Nind 2025-11-12 19:28:09 UTC
Created attachment 189524 [details] [review]
Bug 40841: Add limits configuration UI

This patch adds branch limits selection to the Z30.50/SRU configuration
page.

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>
Comment 28 David Nind 2025-11-12 19:28:13 UTC
Created attachment 189525 [details] [review]
Bug 40841: Implement library limits on Z39.50 searches

This patchset implements Z39.50/SRU limits by branch in Koha.

Key implementation notes:
- Follows Koha's established pattern for library limits
- A new table linking to library limits is added
- The admin UI is adjusted so the form includes library limit selection
- Z39.50/SRU search controllers use the `search_with_library_limits`
  methods to correctly constraint the offered servers.

To test:
1. Apply this patches
2. Run:
   $ ktd --shell
  k$ updatedatabase
=> SUCCESS: Database upgrade goes well
3. Re-run:
  k$ updatedatabase
=> SUCCESS: No explosions, DB update idempotent
4. Restart everything:
  k$ restart_all
5. POint your browser to the admin page:
   http://kohadev-intra.localhost/cgi-bin/koha/admin/z3950servers.pl
=> SUCCESS: A new column is displayed for library limits brief
6. Edit `LIBRARY OF CONGRESS`
=> SUCCESS: The form includes the usual library limit selection UI
7. Choose some branches, excluding your current one (KTD's default is
   'Centerville').
8. Save
=> SUCCESS: It is saved correctly
=> SUCCESS: The table shows the edited library has the library limits
set
9. Edit again
=> SUCCESS: The selected limits are preserved when editing
10. Pick some authorities Z39.50 target, and exclude your current branch
    for testing purposes.
11. Go to Cataloguing, and choose 'New from Z39.50/SRU'
=> SUCCESS: Limits are respected!
12. Go to Authorities, and choose 'New from Z39.50/SRU'
=> SUCCESS: Limits are respected!
13. Same as 11 but with the advanced editor
=> SUCCESS: Limits are respected!
14. Sign off :-D

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>
Comment 29 David Nind 2025-11-12 19:35:09 UTC
The only thing I noted was that some areas where the libraries limitation is set, the Select2 dropdown list is used. For example, patron categories.