Bug 22774 - Add ability to limit the number of purchase suggestions a patron may submit in a specified time period
Summary: Add ability to limit the number of purchase suggestions a patron may submit i...
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Acquisitions (show other bugs)
Version: master
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Devinim
QA Contact: Katrin Fischer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-25 15:36 UTC by Joy Nelson
Modified: 2021-12-13 21:08 UTC (History)
9 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
This enhancement allows the library to limit the number of purchase suggestions a user may submit within a given time period. **New system preferences**: `MaxTotalSuggestions` defaults to empty (unrestricted) and `NumberOfSuggestionDays` defaults to empty (disabled).
Version(s) released in:
20.05.00


Attachments
Bug 22774: New systempreferences for suggestions (2.34 KB, patch)
2019-12-03 10:52 UTC, Devinim
Details | Diff | Splinter Review
Bug 22774: Limit Purchase Suggestion in a specified Time period (8.68 KB, patch)
2019-12-03 10:54 UTC, Devinim
Details | Diff | Splinter Review
Bug 22774: (follow-up) Limit Purchase Suggestion in a specified Time period (8.76 KB, patch)
2020-01-09 10:50 UTC, Devinim
Details | Diff | Splinter Review
Bug 22774: New systempreferences for suggestions (2.40 KB, patch)
2020-01-09 12:33 UTC, ByWater Sandboxes
Details | Diff | Splinter Review
Bug 22774: (follow-up) Limit Purchase Suggestion in a specified Time period (8.81 KB, patch)
2020-01-09 12:33 UTC, ByWater Sandboxes
Details | Diff | Splinter Review
Bug 22774: New systempreferences for suggestions (2.46 KB, patch)
2020-02-14 21:13 UTC, ByWater Sandboxes
Details | Diff | Splinter Review
Bug 22774: (follow-up) Limit Purchase Suggestion in a specified Time period (8.95 KB, patch)
2020-02-14 21:13 UTC, ByWater Sandboxes
Details | Diff | Splinter Review
New systempreferences for suggestions added to sysprefs.sql (1.39 KB, patch)
2020-02-21 13:56 UTC, Devinim
Details | Diff | Splinter Review
Bug 22774: New systempreferences for suggestions added to sysprefs.sql (1.35 KB, patch)
2020-02-21 14:09 UTC, Devinim
Details | Diff | Splinter Review
Bug 22774: (follow-up) New systempreferences for suggestions (2.46 KB, patch)
2020-02-21 14:14 UTC, Devinim
Details | Diff | Splinter Review
Bug 22774: New systempreferences for suggestions (2.28 KB, patch)
2020-03-05 13:25 UTC, Devinim
Details | Diff | Splinter Review
Bug 22774: New systempreferences for suggestions (2.37 KB, patch)
2020-03-05 13:36 UTC, Devinim
Details | Diff | Splinter Review
Bug 22774: New systempreferences for suggestions added to sysprefs.sql (3.51 KB, patch)
2020-03-17 15:57 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 22774: Limit Purchase Suggestion in a specified Time period (9.74 KB, patch)
2020-03-17 15:57 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 22774: (follow-up) Limit Purchase Suggestion in a specified Time period (1.86 KB, patch)
2020-03-23 13:32 UTC, Devinim
Details | Diff | Splinter Review
Bug 22774: New systempreferences for suggestions added to sysprefs.sql (3.54 KB, patch)
2020-04-13 18:32 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 22774: Limit Purchase Suggestion in a specified Time period (9.78 KB, patch)
2020-04-13 18:33 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 22774: (follow-up) Limit purchase suggestion in a specified time period (1.91 KB, patch)
2020-04-13 18:33 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 22774: (QA follow-up) Add syspref descriptions to database update and sysprefs.sql (5.02 KB, patch)
2020-04-13 18:33 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 22774: (QA follow-up) Rephrase OPAC notes (5.96 KB, patch)
2020-04-13 18:33 UTC, Katrin Fischer
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Joy Nelson 2019-04-25 15:36:07 UTC
Many libraries would like the ability to limit purchase suggestions made by a patron to a certain number over a specified period.  i.e. 3 suggestions every 30 days.  The MaxOpenSuggestions works to limit 'open' suggestions, but does not take into account the total suggestions made by patrons. We need the ability to limit the number of suggestions a patron can make in a "rolling number of weeks" (over last X weeks). 

The variables for this would be the number of suggestions and the number of rolling weeks.

Suggested system preference "MaxTotalSuggestions" with two variables.  First is the number of total suggestions and the second is the number of days.

e.g. MaxTotalSuggestion Allow 3 total suggestions over 30 days.  (user configures the numbers to suit their policy)

Result: Users are prevented from making any suggestions if the total suggestions (pending/checked/accepted/rejected) they've made over the last X days is equal to the max specified.
Comment 1 Lisette Scheer 2019-04-26 15:22:35 UTC
This would be very helpful for a number of libraries I've talked with about purchase suggestions. 
Lisette
Comment 2 Devinim 2019-12-03 10:52:53 UTC
Created attachment 95940 [details] [review]
Bug 22774: New systempreferences for suggestions
Comment 3 Devinim 2019-12-03 10:54:05 UTC
Created attachment 95941 [details] [review]
Bug 22774: Limit Purchase Suggestion in a specified Time period

Test plan:
1- Apply this patch
2- Run updatedatabase.pl
3- By default you may have max. 3 suggestions in last 30 days.
4- Go to purchase suggestion page from OPAC
5- If you exceed limits of suggestions in step 3 you will not able to add new suggestions.
6- If you want to change the limits go to systempreferences and change  MaxTotalSuggestions and NumberOfSuggestionDays parameters.
7- Test again from step 4.
Comment 4 Kelly McElligott 2020-01-07 13:49:53 UTC
Hi,
Upon testing this, I received this error when trying to place a hold on the OPAC side.

Could not compile /kohadevbox/koha/opac/opac-suggestions.pl: Global symbol "$suggestions_loop" requires explicit package name (did you forget to declare "my $suggestions_loop"?) at /kohadevbox/koha/opac/opac-suggestions.pl line 144
Comment 5 Devinim 2020-01-09 10:50:59 UTC
Created attachment 97061 [details] [review]
Bug 22774: (follow-up) Limit Purchase Suggestion in a specified Time period

This was resolved. Fail occured because of some changes after we commit the patch
Comment 6 ByWater Sandboxes 2020-01-09 12:33:33 UTC
Created attachment 97070 [details] [review]
Bug 22774: New systempreferences for suggestions

Signed-off-by: Kelly McElligott <kelly@bywatersolutions.com>
Comment 7 ByWater Sandboxes 2020-01-09 12:33:35 UTC
Created attachment 97071 [details] [review]
Bug 22774: (follow-up) Limit Purchase Suggestion in a specified Time period

Signed-off-by: Kelly McElligott <kelly@bywatersolutions.com>
Comment 8 Jonathan Druart 2020-02-05 10:45:30 UTC
I do not think it is correct to have the condition check in the controller. I am pretty sure Tomas will disagree with that as we will want the API taking into account those new sysprefs.

CCing Tomas to get his opinion on this.
Comment 9 ByWater Sandboxes 2020-02-14 21:13:50 UTC
Created attachment 99045 [details] [review]
Bug 22774: New systempreferences for suggestions

Signed-off-by: Kelly McElligott <kelly@bywatersolutions.com>

Signed-off-by: Rhonda Kuiper <rkuiper@roundrocktexas.gov>
Comment 10 ByWater Sandboxes 2020-02-14 21:13:53 UTC
Created attachment 99046 [details] [review]
Bug 22774: (follow-up) Limit Purchase Suggestion in a specified Time period

Signed-off-by: Kelly McElligott <kelly@bywatersolutions.com>

Signed-off-by: Rhonda Kuiper <rkuiper@roundrocktexas.gov>
Comment 11 Katrin Fischer 2020-02-15 08:48:34 UTC
1) The database update will limit the number of suggestions for existing installations:

+    $dbh->do( q{
+            INSERT IGNORE INTO systempreferences (variable,value,explanation,type) VALUES
+                ('MaxTotalSuggestions','3','Number of total suggestions','free'),
+                ('NumberOfSuggestionDays','30','days','free')
+            });

This is against the "rules" as we always aim for having no change of behaviour on update. We should set them to empty (unlimited)

2) For the same reason I am wondering about the default settings in the YAML file, I don't think they are needed.

3) This patch set misses the change to sysprefs.sql for setting up new installations. While we could do the 3 and 30 there, I wonder if we should be a little less restrictive there as well?

4) Please (re)add descriptions of the changes and test plans to the commit messages. I've seen quite a lot of them showing here but not being part of the attached files. Make sure you write them up in your git commit step, not when using git bz attach, as the latter won't change the files.
Comment 12 Devinim 2020-02-21 13:56:07 UTC Comment hidden (obsolete)
Comment 13 Devinim 2020-02-21 14:09:16 UTC
Created attachment 99381 [details] [review]
Bug 22774: New systempreferences for suggestions added to sysprefs.sql

New patch added for new installations
Comment 14 Devinim 2020-02-21 14:14:42 UTC Comment hidden (obsolete)
Comment 15 Devinim 2020-03-05 13:25:46 UTC Comment hidden (obsolete)
Comment 16 Devinim 2020-03-05 13:36:29 UTC
Created attachment 100193 [details] [review]
Bug 22774: New systempreferences for suggestions

Test plan:
1- Apply this patch
2- Run updatedatabase.pl
3- By default you may have max. 3 suggestions in last 30 days.
4- Go to purchase suggestion page from OPAC
5- If you exceed limits of suggestions in step 3 you will not able to add new suggestions.
6- If you want to change the limits go to systempreferences and change  MaxTotalSuggestions and NumberOfSuggestionDays parameters.
7- Test again from step 4.
Comment 17 Nick Clemens 2020-03-17 15:57:22 UTC
Created attachment 100912 [details] [review]
Bug 22774: New systempreferences for suggestions added to sysprefs.sql

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 18 Nick Clemens 2020-03-17 15:57:26 UTC
Created attachment 100913 [details] [review]
Bug 22774: Limit Purchase Suggestion in a specified Time period

Test plan:
 1 - Apply this patch
 2 - Run updatedatabase.pl
 3 - By default the preferences are blank and do not limit.
 4 - Set the limits to 3 in 30 days
 5 - Go to purchase suggestion page from OPAC as a logged in patron
 6 - Place 3 suggestions and confirm you cannot place any more
 7 - Alter one of the suggestions to have been made more than 30 days ago
    UPDATE suggestions SET suggesteddate = '2020-01-01' WHERE suggestionid=3;
 8 - Confirm you can place another suggestion
 9 - Log out of OPAC
10 - Make sure AnonSyggestions is set to 'Allow' and AnonymousPatron is set
11 - Confirm anonymous suggestions are not limited by the syspref
12 - Confirm that a blank value in either  MaxTotalSuggestions  or  NumberOfSuggestionDays  does not limit suggestions

Signed-off-by: Kelly McElligott <kelly@bywatersolutions.com>

Signed-off-by: Rhonda Kuiper <rkuiper@roundrocktexas.gov>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 19 Devinim 2020-03-23 13:32:46 UTC
Created attachment 101448 [details] [review]
Bug 22774: (follow-up) Limit Purchase Suggestion in a specified Time period

We changed the code to satisfy new methods:
we used Koha::Suggestions->search()->count instead of scalar search
Comment 20 Katrin Fischer 2020-03-26 22:52:00 UTC

1) QA test tools

Looks good, only got what looks like a false positive:

Processing additional checks
	* Email's author 'kohadevinim@devinim.com.tr' seems invalid

2) Capitalization

(Bug 22774 - Limit Purchase Suggestion in a specified Time period)

Please stick with our capitalization rules everywhere! :)

Still testing here, but won't finish tonight. Will fix 2) myself.
Comment 21 Devinim 2020-03-27 12:49:48 UTC
(In reply to Katrin Fischer from comment #20)
> 
> 1) QA test tools
> 
> Looks good, only got what looks like a false positive:
> 
> Processing additional checks
> 	* Email's author 'kohadevinim@devinim.com.tr' seems invalid

Hi Katrin,

I didn't understand that. It is one of our valid email address.
Comment 22 Katrin Fischer 2020-03-27 13:42:33 UTC
> 
> I didn't understand that. It is one of our valid email address.

Yep, was just noting it - we can safely ignore it in my opinion. Maybe it's not aware of com.tr?
Comment 23 Jonathan Druart 2020-03-27 15:56:23 UTC
You can ignore it, IIRC I added a check on "*koha*", to catch example developer emails (like the default from kohadevbox, etc.)
Comment 24 Katrin Fischer 2020-04-13 17:34:34 UTC
Oh, sorry, it looks like I forgot to continue here - will do it now.
Comment 25 Katrin Fischer 2020-04-13 18:32:21 UTC
Created attachment 102882 [details] [review]
Bug 22774: New systempreferences for suggestions added to sysprefs.sql

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 26 Katrin Fischer 2020-04-13 18:33:11 UTC
Created attachment 102883 [details] [review]
Bug 22774: Limit Purchase Suggestion in a specified Time period

Test plan:
 1 - Apply this patch
 2 - Run updatedatabase.pl
 3 - By default the preferences are blank and do not limit.
 4 - Set the limits to 3 in 30 days
 5 - Go to purchase suggestion page from OPAC as a logged in patron
 6 - Place 3 suggestions and confirm you cannot place any more
 7 - Alter one of the suggestions to have been made more than 30 days ago
    UPDATE suggestions SET suggesteddate = '2020-01-01' WHERE suggestionid=3;
 8 - Confirm you can place another suggestion
 9 - Log out of OPAC
10 - Make sure AnonSyggestions is set to 'Allow' and AnonymousPatron is set
11 - Confirm anonymous suggestions are not limited by the syspref
12 - Confirm that a blank value in either  MaxTotalSuggestions  or  NumberOfSuggestionDays  does not limit suggestions

Signed-off-by: Kelly McElligott <kelly@bywatersolutions.com>

Signed-off-by: Rhonda Kuiper <rkuiper@roundrocktexas.gov>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 27 Katrin Fischer 2020-04-13 18:33:19 UTC
Created attachment 102884 [details] [review]
Bug 22774: (follow-up) Limit purchase suggestion in a specified time period

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 28 Katrin Fischer 2020-04-13 18:33:27 UTC
Created attachment 102885 [details] [review]
Bug 22774: (QA follow-up) Add syspref descriptions to database update and sysprefs.sql

Moves the updatedatabase entry to the new format and
adds information for the explanation column of the
systempreferences table.

Also slightly rephrases the description in the system preference
editor.

To test:
- Verify database update still works the same with addition
  of explanations
- Verify the sys pref description makes sense
Comment 29 Katrin Fischer 2020-04-13 18:33:33 UTC
Created attachment 102886 [details] [review]
Bug 22774: (QA follow-up) Rephrase OPAC notes

I've changed the OPAC notes a little bit, main change is
the removal of the <b> tags used to highlight single words
in one sentence as they would result in splitting up the
sentence into multiple parts which makes proper translations really
hard.
Comment 30 Katrin Fischer 2020-04-13 18:34:14 UTC
RM, as a native speaker, please check the follow-ups make sense :)
Comment 31 Devinim 2020-04-13 19:08:18 UTC
Thanks Katrin
Comment 32 Martin Renvoize 2020-04-14 15:41:09 UTC
(In reply to Jonathan Druart from comment #8)
> I do not think it is correct to have the condition check in the controller.
> I am pretty sure Tomas will disagree with that as we will want the API
> taking into account those new sysprefs.
> 
> CCing Tomas to get his opinion on this.

Discussed with Tomas and we agreed to push this and followup with an API fix later.. a bigger discussion on how to handle things like needs to happen in a broader scope.
Comment 33 Martin Renvoize 2020-04-14 15:42:58 UTC
(In reply to Katrin Fischer from comment #30)
> RM, as a native speaker, please check the follow-ups make sense :)

Looks good to me :)
Comment 34 Martin Renvoize 2020-04-14 16:23:14 UTC
Nice work everyone!

Pushed to master for 20.05
Comment 35 Tomás Cohen Arazi 2020-04-14 20:09:24 UTC Comment hidden (obsolete)
Comment 36 Tomás Cohen Arazi 2020-04-14 20:11:31 UTC
Wrong bug, sorry
Comment 37 Joy Nelson 2020-05-05 21:23:08 UTC
enhancement not backported to 19.11.x
Comment 38 Daniel Gaghan 2020-09-08 17:06:23 UTC
Thanks folks for all your work, we just discovered this enhancement and our collection development librarians are looking forward to this feature.