Bug 10589

Summary: Override OpacHiddenItems based on Patron Branch
Product: Koha Reporter: Mark Tompsett <mtompset>
Component: OPACAssignee: Mark Tompsett <mtompset>
Status: ASSIGNED --- QA Contact: Marcel de Rooy <m.de.rooy>
Severity: enhancement    
Priority: P5 - low CC: chris, gitbot, gmcharlt, jkpattison, jonathan.druart, m.de.rooy, manueltamayao, nengard, rcoert, srdjan, tomascohen, veron
Version: Main   
Hardware: All   
OS: All   
See Also: http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=10895
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=2946
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14385
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on: 10900, 11592, 14385, 15777    
Bug Blocks:    
Attachments: Provide two system preferences to flexibly override OpacHiddenItems
Based on patron category unhide items hidden with OpacHiddenItems
Uses patron category to keep visible some things hidden by OPACHiddenItems
Using list of category codes OPACHiddenItems can be overridden
Using list of category codes OPACHiddenItems can be overridden
Provide two system preferences to flexibly override OpacHiddenItems
[SIGNED-OFF] Bug 10589 - Override OpacHiddenItems based on Patron Category
Bug 10589 - Override OpacHiddenItems based on Patron Category
Bug 10589 - Override OpacHiddenItems based on Patron Category
Bug 10589 - Override OpacHiddenItems based on Patron Category
Bug 10589 - Override OpacHiddenItems based on Patron Category
Bug 10589 - Override OpacHiddenItems based on Patron Category
Bug 10589 - Override OpacHiddenItems based on Patron Category
Bug 10589 - Override OpacHiddenItems based on Patron Category
[SIGNED-OFF] Bug 10589 - Override OpacHiddenItems based on Patron Category
Bug 10589: local exceptions overriding OpacHiddenItems
Bug 10589: Unit tests of changes

Description Mark Tompsett 2013-07-15 10:57:56 UTC
This patch will:
1) Add two system preferences: PatronSingleBranch and PatronEveryBranch.
2) Items which would normally be hidden by OpacHiddenItems will be visible if:
a) The patron's category code matches the PatronSingleBranch patron category code AND the home branch of the item is the same as the home branch of the patron.
OR
b) The patron's category code matches the PatronEveryBranch patron category code.

The two system preferences default to PTSB and PTEB which are not added to the list of possible patron categories. This means OpacHiddenItems will continue to function as is normally. Having them as system preferences means the patron category code is not hard coded and can be changed.
Comment 1 Mark Tompsett 2013-07-15 11:28:29 UTC Comment hidden (obsolete)
Comment 2 Mark Tompsett 2013-07-17 03:13:25 UTC Comment hidden (obsolete)
Comment 3 Mark Tompsett 2013-07-24 18:23:25 UTC Comment hidden (obsolete)
Comment 4 Srdjan Jankovic 2013-07-25 04:38:36 UTC Comment hidden (obsolete)
Comment 5 Mark Tompsett 2013-07-25 05:55:54 UTC Comment hidden (obsolete)
Comment 6 Mark Tompsett 2013-07-25 06:01:17 UTC Comment hidden (obsolete)
Comment 7 Mark Tompsett 2013-07-25 06:13:51 UTC Comment hidden (obsolete)
Comment 8 Srdjan Jankovic 2013-07-25 07:24:08 UTC Comment hidden (obsolete)
Comment 9 Mark Tompsett 2013-07-25 18:19:33 UTC Comment hidden (obsolete)
Comment 10 Srdjan Jankovic 2013-07-25 23:11:32 UTC Comment hidden (obsolete)
Comment 11 Srdjan Jankovic 2013-07-26 00:06:28 UTC Comment hidden (obsolete)
Comment 12 Mark Tompsett 2013-07-26 03:47:26 UTC Comment hidden (obsolete)
Comment 13 Mark Tompsett 2013-09-13 01:13:20 UTC Comment hidden (obsolete)
Comment 14 Mark Tompsett 2013-09-13 01:14:46 UTC Comment hidden (obsolete)
Comment 15 Srdjan Jankovic 2013-09-13 02:13:15 UTC Comment hidden (obsolete)
Comment 16 Mark Tompsett 2013-09-19 18:04:00 UTC Comment hidden (obsolete)
Comment 17 I'm just a bot 2013-09-24 05:44:50 UTC Comment hidden (obsolete)
Comment 18 Mark Tompsett 2013-09-24 06:17:55 UTC Comment hidden (obsolete)
Comment 19 Srdjan Jankovic 2013-09-30 02:38:32 UTC Comment hidden (obsolete)
Comment 20 Mark Tompsett 2013-10-30 12:53:10 UTC Comment hidden (obsolete)
Comment 21 Mark Tompsett 2013-10-30 12:53:57 UTC Comment hidden (obsolete)
Comment 22 Marcel de Rooy 2013-10-31 10:28:04 UTC Comment hidden (obsolete)
Comment 23 Marcel de Rooy 2013-10-31 10:38:56 UTC Comment hidden (obsolete)
Comment 24 Marcel de Rooy 2013-10-31 10:40:28 UTC Comment hidden (obsolete)
Comment 25 Chris Cormack 2013-12-27 00:55:30 UTC Comment hidden (obsolete)
Comment 26 Galen Charlton 2014-05-05 23:07:42 UTC Comment hidden (obsolete)
Comment 27 Manny Tamayao 2014-05-07 06:20:25 UTC
This patch will work perfectly with us in terms of managing our patrons that can view hidden materials.
We are a network of linguistic libraries located in different countries in South East Asia and we have materials that would need to be hidden from one library to another and we used OpacHiddenItems to manage this. It really works well with us in restricting general public and regular patrons in viewing hidden materials from the Opac. But since we have patrons who works in multiple countries that needs access to the hidden materials, once they logged in Opac they must have a privilege to view hidden materials.
Comment 28 Jane Pattison 2014-05-08 02:26:18 UTC
I second Manny's comments. Our situation with a variety of libraries spread throughout countries and yet connected in purpose is complicated. We have so appreciated Koha as a means to serve all these libraries. The upgrades and patches -- several headed up by Mark Tompsett (thanks Mark!) -- have been huge in our ability to serve our patrons. This particular patch would really help us in this unique situation in which we work.
Comment 29 Marc Véron 2014-08-14 17:45:35 UTC Comment hidden (obsolete)
Comment 30 Srdjan Jankovic 2014-08-15 01:18:37 UTC Comment hidden (obsolete)
Comment 31 Jonathan Druart 2014-09-05 14:58:17 UTC Comment hidden (obsolete)
Comment 32 Mark Tompsett 2014-09-05 15:22:22 UTC Comment hidden (obsolete)
Comment 33 Jonathan Druart 2014-09-10 15:25:17 UTC Comment hidden (obsolete)
Comment 34 Mark Tompsett 2014-09-10 22:12:02 UTC Comment hidden (obsolete)
Comment 35 Mark Tompsett 2014-09-17 03:22:13 UTC Comment hidden (obsolete)
Comment 36 Marc Véron 2015-12-24 14:04:53 UTC Comment hidden (obsolete)
Comment 37 Mark Tompsett 2016-02-12 15:16:36 UTC Comment hidden (obsolete)
Comment 38 Mark Tompsett 2016-04-22 17:05:07 UTC Comment hidden (obsolete)
Comment 39 Mark Tompsett 2016-04-22 18:04:25 UTC Comment hidden (obsolete)
Comment 40 Mark Tompsett 2016-08-01 11:43:51 UTC Comment hidden (obsolete)
Comment 41 Mark Tompsett 2017-06-28 02:55:34 UTC
The PatronEveryBranch is duplicate of bug 14385, but the PatronSingleBranch is a granularity which that bug lacks.
Comment 42 Mark Tompsett 2017-08-01 15:46:06 UTC Comment hidden (obsolete)
Comment 43 Mark Tompsett 2017-08-01 15:46:47 UTC Comment hidden (obsolete)
Comment 44 Mark Tompsett 2018-11-19 18:49:33 UTC
Created attachment 82521 [details] [review]
Bug 10589: local exceptions overriding OpacHiddenItems

This patch adds the functionality change to C4/Items.pm
which allows to cross check the patron branch with the
item branch in addition to the local exception patron
category list.

This patch is large because is also merely adds
patron_branch to a series of function calls which
OpacHiddenItems affects.
Comment 45 Mark Tompsett 2018-11-19 18:49:38 UTC
Created attachment 82522 [details] [review]
Bug 10589: Unit tests of changes

The core changes were in C4/Items.pm with
GetHiddenItemnumbers now processing logic against
a patron branch vs. an item's home branch and
does the patron have the local exception category.

This adds 4 tests to confirm those changes.

prove -v t/db_dependent/Items.t

If you apply just this, the tests should fail.
If you apply both patches, the tests should pass.
Comment 46 Mark Tompsett 2018-11-19 19:26:02 UTC
Now that bug 14385 has been pushed to master, this patch will merely need to add a patron branch code to the passed parameter hash, so that logic can be added. A fuller test plan will come shortly.
Comment 47 Tomás Cohen Arazi (tcohen) 2019-03-06 10:53:27 UTC
Please take a look at bug 22454 and bug 22455. The rationale is that if you have the biblio object, you can know all that is needed regarding hiding in OPAC without fetching MARC data or complex calculations. And if we were to add parameters like category and library, I would rather pass the Koha::Patron object altogether.
This check, with bug 22457 in mind could be written:

my $should_hide = ( $patron->category->overrides_opac_hidding_policy or
                    $patron->library->overrides_opac_hidding_policy )
                ? 0
                : 1;

while ( my $biblio = $biblios->next ) {
 next if $biblio->hidden_in_opac and $should_hide;
 do_your_things();
}

This check should be written on the controller script.
Comment 48 Mark Tompsett 2019-06-11 00:28:11 UTC
(In reply to Tomás Cohen Arazi from comment #47)
> Please take a look at bug 22454 and bug 22455. The rationale is that if you
> have the biblio object, you can know all that is needed regarding hiding in
> OPAC without fetching MARC data or complex calculations. And if we were to
> add parameters like category and library, I would rather pass the
> Koha::Patron object altogether.
> This check, with bug 22457 in mind could be written:
> 
> my $should_hide = ( $patron->category->overrides_opac_hidding_policy or
>                     $patron->library->overrides_opac_hidding_policy )
>                 ? 0
>                 : 1;
> 
> while ( my $biblio = $biblios->next ) {
>  next if $biblio->hidden_in_opac and $should_hide;
>  do_your_things();
> }
> 
> This check should be written on the controller script.

Doesn't quite work.

The idea is:
if (! defined $patron) {
    $globally_override = 0;
} elsif (! defined $patron->category) {
    $globally_override = 0;
} else {
    $globally_override = $patron->category->globally_overrides_opac_hiding;
}
while ( my $biblio = $bilbios->next ) {
    if (! defined $patron) {
        $locally_override = 0;
    } else {
        $locally_override = ($patron->branchcode ne $biblio->homebranch)
            ? 0
            : $patron->category->overrides_opac_hiding_policy_locally;
    }
    $should_show = $globally_override || $locally_override;
    $should_hide = ! $should_show;
    next if $biblio->hidden_in_opac && $should_hide;
    do_your_things();
}
Comment 49 Mark Tompsett 2019-06-11 00:39:07 UTC
Doh! That doesn't quite work, because homebranch is on item. So, you want to pass patron to hidden_in_opac on items... Okay... Hmm... thinking....