Bug 15494 - Block renewals by arbitrary item values
Summary: Block renewals by arbitrary item values
Status: Failed QA
Alias: None
Product: Koha
Classification: Unclassified
Component: Circulation (show other bugs)
Version: master
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Nick Clemens
QA Contact: Marcel de Rooy
URL: http://devs.bywatersolutions.com/proj...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-06 16:27 UTC by Nicole C. Engard
Modified: 2018-02-02 18:37 UTC (History)
7 users (show)

See Also:
Change sponsored?: Sponsored
Patch complexity: Small patch
Bot Control: ---
When did the bot last check this:
Who signed the patch off:
Text to go in the release notes:


Attachments
Bug 15494 - Unit tests (5.62 KB, patch)
2017-05-24 14:46 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 15494 - Add _items_denied_renewal sub to C4:Circulation::CanBookBeRenewed (2.20 KB, patch)
2017-05-24 14:46 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 15494 - Update display of renewal errors (7.03 KB, patch)
2017-05-24 14:46 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 15494 - Add syspref (3.60 KB, patch)
2017-05-24 14:46 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 15494 - Unit tests (5.66 KB, patch)
2017-10-10 16:35 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 15494 - Add _items_denied_renewal sub to C4:Circulation::CanBookBeRenewed (2.19 KB, patch)
2017-10-10 16:35 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 15494 - Update display of renewal errors (7.08 KB, patch)
2017-10-10 16:35 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 15494 - Add syspref (3.60 KB, patch)
2017-10-10 16:35 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 15494 - Unit tests (5.71 KB, patch)
2017-10-14 23:09 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 15494 - Add _items_denied_renewal sub to C4:Circulation::CanBookBeRenewed (2.24 KB, patch)
2017-10-14 23:09 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 15494 - Update display of renewal errors (7.14 KB, patch)
2017-10-14 23:10 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 15494 - Add syspref (3.66 KB, patch)
2017-10-14 23:10 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 15494 - Followup: Make sure items in tests are not overdue (1.47 KB, patch)
2018-01-05 15:41 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 15494 - Unit tests (6.44 KB, patch)
2018-01-17 17:57 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 15494 - Add _items_denied_renewal sub to C4:Circulation::CanBookBeRenewed (2.34 KB, patch)
2018-01-17 17:58 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 15494 - Update display of renewal errors (7.14 KB, patch)
2018-01-17 17:58 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 15494 - Add syspref (3.85 KB, patch)
2018-01-17 17:58 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 15494 - Unit tests (6.48 KB, patch)
2018-02-02 09:02 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 15494 - Add _items_denied_renewal sub to C4:Circulation::CanBookBeRenewed (2.38 KB, patch)
2018-02-02 09:03 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 15494 - Update display of renewal errors (7.17 KB, patch)
2018-02-02 09:03 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 15494 - Add syspref (3.89 KB, patch)
2018-02-02 09:03 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 15494: (QA follow-up) Additional polishing (4.45 KB, patch)
2018-02-02 09:03 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 15494 - Unit tests (6.53 KB, patch)
2018-02-02 09:05 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 15494 - Add _items_denied_renewal sub to C4:Circulation::CanBookBeRenewed (2.44 KB, patch)
2018-02-02 09:05 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 15494 - Update display of renewal errors (7.23 KB, patch)
2018-02-02 09:05 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 15494 - Add syspref (3.95 KB, patch)
2018-02-02 09:05 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 15494: (QA follow-up) Additional polishing (4.45 KB, patch)
2018-02-02 09:05 UTC, Marcel de Rooy
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Nicole C. Engard 2016-01-06 16:27:14 UTC
This development would allow a library to prevent the renewal of items based on the values of any field in the items table including but not limited to any itemlost value.

Work to be done:
1) Add new system preference ItemsDeniedRenewal patterned after OpacHiddenItems
2) Modify C4::Circulation::CanBookBeRenewed to check this system preference


Seeking Co-sponsors: http://devs.bywatersolutions.com/projects/make-longoverduelost-items-not-renewable/
Comment 1 Nick Clemens 2017-05-24 14:46:16 UTC Comment hidden (obsolete)
Comment 2 Nick Clemens 2017-05-24 14:46:19 UTC Comment hidden (obsolete)
Comment 3 Nick Clemens 2017-05-24 14:46:22 UTC Comment hidden (obsolete)
Comment 4 Nick Clemens 2017-05-24 14:46:25 UTC Comment hidden (obsolete)
Comment 5 Katrin Fischer 2017-10-08 09:51:08 UTC Comment hidden (obsolete)
Comment 6 Nick Clemens 2017-10-10 16:35:30 UTC Comment hidden (obsolete)
Comment 7 Nick Clemens 2017-10-10 16:35:33 UTC Comment hidden (obsolete)
Comment 8 Nick Clemens 2017-10-10 16:35:36 UTC Comment hidden (obsolete)
Comment 9 Nick Clemens 2017-10-10 16:35:39 UTC Comment hidden (obsolete)
Comment 10 Katrin Fischer 2017-10-14 23:09:20 UTC
This seems to work quite well! Also tested renew through checkout, renewal tab and OPAC.

When renewing the item from the list of checkouts and using the renewal limit override functionality, the message displayed is:

Renew failed: item_denied_renewal

This could be improved, maybe with a small follow-up?
Comment 11 Katrin Fischer 2017-10-14 23:09:52 UTC
Created attachment 68146 [details] [review]
Bug 15494 - Unit tests

prove t/db_dependent/Circulation.t

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 12 Katrin Fischer 2017-10-14 23:09:56 UTC
Created attachment 68147 [details] [review]
Bug 15494 - Add _items_denied_renewal sub to C4:Circulation::CanBookBeRenewed

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 13 Katrin Fischer 2017-10-14 23:10:00 UTC
Created attachment 68148 [details] [review]
Bug 15494 - Update display of renewal errors

To test:
1 - Define a rule to deny renewal
2 - Checkout an item meeting this rule
3 - Attempt renew an item via the OPAC
4 - Attempt renewal via SIP
5 - Attempt renewal via staff client
6 - Verify errors are reasonable

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 14 Katrin Fischer 2017-10-14 23:10:04 UTC
Created attachment 68149 [details] [review]
Bug 15494 - Add syspref

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 15 Marcel de Rooy 2018-01-05 07:12:25 UTC Comment hidden (obsolete)
Comment 16 Nick Clemens 2018-01-05 10:54:05 UTC Comment hidden (obsolete)
Comment 17 Marcel de Rooy 2018-01-05 15:14:09 UTC Comment hidden (obsolete)
Comment 18 Nick Clemens 2018-01-05 15:41:06 UTC
Created attachment 70295 [details] [review]
Bug 15494 - Followup: Make sure items in tests are not overdue

prove -v t/db_dependent/Circulation.t
Comment 19 Nick Clemens 2018-01-05 15:41:56 UTC Comment hidden (obsolete)
Comment 20 Marcel de Rooy 2018-01-05 16:07:03 UTC Comment hidden (obsolete)
Comment 21 Marcel de Rooy 2018-01-05 16:49:34 UTC
+ unless ($item)    { carp "No item passed in!" && return }
Not our preferred coding style

+ return () if (! $yaml =~ /\S/ );
Just return here. The only call is in scalar context. We do not need a list.
Shorter: return if $yaml !~ /\S/;

+    eval {
+        $denyingrules = YAML::Load($yaml);
+    };
How much time are we spending on doing this? What is the performance effect? If the pref always looks like field1: [val]\nfield2: [val2] we can just split on newline and split on ':', etc. Give me some convincing numbers please.

+        return ();
Same as above

+        my $val;
+        if (exists $item->{$field}) {
+            $val = $item->{$field};
+        }
+        $val = '' unless defined $val;
Why not in just one line: my $val = $item->{$field} // '';

+            - How to write these rules is documented on the <a href="http://wiki.koha-community.org/wiki/OpacHiddenItems" target="_blank">Koha wiki</a>.
This is from the preference file. Not sure if this is the preferred way. A wiki page could be gone just as easily. Why not just provide an example as close as possible to the pref itself. Just another 40 chars ?

Just curious too if this supports denying renewal on an empty string? If so, the conversion from undef to empty string might not be what we want. Can we signal empty string or undef to be a blocking value? [No blocker for me btw :)]

Changing status. Please make some adjustments.
Comment 22 Nick Clemens 2018-01-17 17:57:58 UTC
Created attachment 70629 [details] [review]
Bug 15494 - Unit tests

prove -v t/db_dependent/Circulation.t
Comment 23 Nick Clemens 2018-01-17 17:58:01 UTC
Created attachment 70630 [details] [review]
Bug 15494 - Add _items_denied_renewal sub to C4:Circulation::CanBookBeRenewed
Comment 24 Nick Clemens 2018-01-17 17:58:04 UTC
Created attachment 70631 [details] [review]
Bug 15494 - Update display of renewal errors

To test:
1 - Define a rule to deny renewal
2 - Checkout an item meeting this rule
3 - Attempt renew an item via the OPAC
4 - Attempt renewal via SIP
5 - Attempt renewal via staff client
6 - Verify errors are reasonable

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 25 Nick Clemens 2018-01-17 17:58:08 UTC
Created attachment 70632 [details] [review]
Bug 15494 - Add syspref
Comment 26 Nick Clemens 2018-01-17 18:02:35 UTC
(In reply to Marcel de Rooy from comment #21)
> + unless ($item)    { carp "No item passed in!" && return }
> Not our preferred coding style

This was just copying others in this file, changed to "return unless $item"

> + return () if (! $yaml =~ /\S/ );
> Just return here. 
Removed

> +    eval {
> +        $denyingrules = YAML::Load($yaml);
> +    };
> How much time are we spending on doing this? What is the performance effect?
Was about .037 seconds (with 2 fields and 1000 values)
Using split is about .014 seconds, okay, I switched

> +        return ();
Yup

> Why not in just one line: my $val = $item->{$field} // '';
Good point

>Why not just provide an example as close as possible to the pref itself?

Okay

> Just curious too if this supports denying renewal on an empty string? If so,
> the conversion from undef to empty string might not be what we want. 
Okay, can use "" or NULL for specific now (see the pref explanation)


> Changing status. Please make some adjustments.
Improved, squashed, sent back for SO
Comment 27 Marcel de Rooy 2018-02-02 07:08:05 UTC
Working on this one now
Comment 28 Marcel de Rooy 2018-02-02 09:02:57 UTC
Created attachment 71129 [details] [review]
Bug 15494 - Unit tests

prove -v t/db_dependent/Circulation.t
Comment 29 Marcel de Rooy 2018-02-02 09:03:01 UTC
Created attachment 71130 [details] [review]
Bug 15494 - Add _items_denied_renewal sub to C4:Circulation::CanBookBeRenewed
Comment 30 Marcel de Rooy 2018-02-02 09:03:06 UTC
Created attachment 71131 [details] [review]
Bug 15494 - Update display of renewal errors

To test:
1 - Define a rule to deny renewal
2 - Checkout an item meeting this rule
3 - Attempt renew an item via the OPAC
4 - Attempt renewal via SIP
5 - Attempt renewal via staff client
6 - Verify errors are reasonable

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 31 Marcel de Rooy 2018-02-02 09:03:10 UTC
Created attachment 71132 [details] [review]
Bug 15494 - Add syspref
Comment 32 Marcel de Rooy 2018-02-02 09:03:15 UTC
Created attachment 71133 [details] [review]
Bug 15494: (QA follow-up) Additional polishing

[1] Fix two typos in Circulation.t.
    Although the test does not fail, line 2127 contains two typos.
    Changing INVISILE to INVISIBLE :)
    And type should be itype.
[2] Remove $yaml as leftover from older code.
[3] Add a next when the split on /:/ does not give two results. This will
    prevent uninit warnings (although still disabled now in Circulation).
[4] For the same reason we should switch the lines for NULL and empty
    string. The undefs you insert should trigger a warn.
[5] The line for empty string should not insert undef, but empty string.
    For the same reason adding the condition defined($_) ...
    And proving it by adding two tests for the opposite values of
    callnumber and itemnotes.
[6] Adding a strip spaces around the fieldname. User friendly..

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 33 Marcel de Rooy 2018-02-02 09:05:25 UTC
Created attachment 71134 [details] [review]
Bug 15494 - Unit tests

prove -v t/db_dependent/Circulation.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 34 Marcel de Rooy 2018-02-02 09:05:30 UTC
Created attachment 71135 [details] [review]
Bug 15494 - Add _items_denied_renewal sub to C4:Circulation::CanBookBeRenewed

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 35 Marcel de Rooy 2018-02-02 09:05:35 UTC
Created attachment 71136 [details] [review]
Bug 15494 - Update display of renewal errors

To test:
1 - Define a rule to deny renewal
2 - Checkout an item meeting this rule
3 - Attempt renew an item via the OPAC
4 - Attempt renewal via SIP
5 - Attempt renewal via staff client
6 - Verify errors are reasonable

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 36 Marcel de Rooy 2018-02-02 09:05:39 UTC
Created attachment 71137 [details] [review]
Bug 15494 - Add syspref

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 37 Marcel de Rooy 2018-02-02 09:05:45 UTC
Created attachment 71138 [details] [review]
Bug 15494: (QA follow-up) Additional polishing

[1] Fix two typos in Circulation.t.
    Although the test does not fail, line 2127 contains two typos.
    Changing INVISILE to INVISIBLE :)
    And type should be itype.
[2] Remove $yaml as leftover from older code.
[3] Add a next when the split on /:/ does not give two results. This will
    prevent uninit warnings (although still disabled now in Circulation).
[4] For the same reason we should switch the lines for NULL and empty
    string. The undefs you insert should trigger a warn.
[5] The line for empty string should not insert undef, but empty string.
    For the same reason adding the condition defined($_) ...
    And proving it by adding two tests for the opposite values of
    callnumber and itemnotes.
[6] Adding a strip spaces around the fieldname. User friendly..

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 38 Marcel de Rooy 2018-02-02 09:09:04 UTC
Has been tested already before, spent sufficient time on changes now.
Looks good to me.
No blocker, but slightly confusing in staff checkouts table:

0 Renewal denied by syspref
(10 of 10 renewals remaining)

If I can't renew, what is the value of these 10? :)

Passed QA with follow-up for some minor issues.
Comment 39 Jonathan Druart 2018-02-02 14:55:06 UTC
1. In tests, prefer Koha::IssuingRules->search->update($what_you_need_to_be_set);
instead of the DELETE then INSERT. It makes the changes more readable in my opinion.

2. What about "NULL" string values? :)

3. Should not we have the same code for 
OpacHiddenItems and ItemsDeniedRenewal (and UpdateNotForLoanStatusOnCheckin?)
There is also UpdateItemLocationOnCheckin (bug 14576)

The minimum would be a new get_rules_from_prefs sub

Marking as FQA for discussion
Comment 40 Jonathan Druart 2018-02-02 14:56:39 UTC
We should also tell people that a new item_denied_renewal condition must be added to AUTO_RENEWALS
Comment 41 Katrin Fischer 2018-02-02 17:28:31 UTC
(In reply to Jonathan Druart from comment #40)
> We should also tell people that a new item_denied_renewal condition must be
> added to AUTO_RENEWALS

Can you explain that one? People?
Comment 42 Jonathan Druart 2018-02-02 17:41:49 UTC
s/people/Koha administrators

In the update DB process I guess, a warning to tell this new code is added and must be taken into account in the template of the notice.
Comment 43 Katrin Fischer 2018-02-02 18:37:03 UTC
Ah! Not sure the reason is available in the template tho.