Bug 15128

Summary: Add ability to limit the number of open purchase suggestions a patron can make
Product: Koha Reporter: Kyle M Hall <kyle>
Component: AcquisitionsAssignee: Nick Clemens <nick>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: amy, jonathan.druart, koha, kyle.m.hall, marjorie.barry-vila, nick, nicole, rkuiper, veron
Version: unspecified   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=16767
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=16920
Change sponsored?: Sponsored Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Attachments: Bug 15128 - Add ability to limit patrons open purchase suggestions
Bug 15128 - Add ability to limit patrons open purchase suggestions
Bug 15128 - Add ability to limit patrons open purchase suggestions
Bug 15128 - Add ability to limit patrons open purchase suggestions
Bug 15128 [QA Followup] - Make suggestion display after being added
Bug 15128 - Add ability to limit patrons open purchase suggestions
Bug 15128 [QA Followup] - Make suggestion display after being added
Bug 15128 [QA Followup 2] - Only count pending suggestions for the limit
Bug 15128 - Followup
Bug 15128 - Add ability to limit patrons open purchase suggestions
Bug 15128 [QA Followup] - Make suggestion display after being added
Bug 15128 [QA Followup 2] - Only count pending suggestions for the limit
Bug 15128 - Followup
Bug 15128 - Add ability to limit patrons open purchase suggestions
Bug 15128 [QA Followup] - Make suggestion display after being added
Bug 15128 [QA Followup 2] - Only count pending suggestions for the limit
Bug 15128 - Followup
Bug 15128 (QA Followup) Display all purchase suggestions whether or not suggestion was added Correct enforcement of 0 limit
Bug 15128 - (QA Followup) Fix use of 'my' variable causing loss of data
Bug 15128 - (QA Followup) Don't get patrons suggestions if limit not set
Bug 15128 - Add ability to limit patrons open purchase suggestions
Bug 15128 [QA Followup] - Make suggestion display after being added
Bug 15128 [QA Followup 2] - Only count pending suggestions for the limit
Bug 15128 - Followup
Bug 15128 (QA Followup) Display all purchase suggestions whether or not suggestion was added Correct enforcement of 0 limit
Bug 15128 - (QA Followup) Fix use of 'my' variable causing loss of data
Bug 15128 - (QA Followup) Don't get patrons suggestions if limit not set
Bug 15128: Revert Display all purchase suggestions whether or not suggestion was added
Bug 15128: Do not display "New suggestion" if limit has just been reached

Description Kyle M Hall 2015-11-04 14:24:53 UTC
Some libraries are finding that some patrons have a tendency to "spam" the purchase suggestions with dozens of requests at a time. It would be nice if we could limit the number of purchase suggestions a patron can place that are neither Accepted or Rejected.

Idea:
1) Add new system preference "MaxOpenSuggestions"
2) Modify opac-suggestions.pl to count the number of suggesions the patron has that are not Accepted or Rejected
3) If that count has reached the number specified in MaxOpenSuggestions, deny the ability to place another suggestion with the message:
"You have reached your limit of suggestions you can place at this time. Once the library has processed those suggestions you will be able to place more"
Comment 1 Nick Clemens 2016-06-15 20:11:13 UTC Comment hidden (obsolete)
Comment 2 Marc Véron 2016-06-16 13:40:08 UTC
Works fine, I like this feature.

Maybe the following could be improved:

Let's say MaxOpenSuggestions is set to 2.

From OPAC, I add a suggestion 'AAA'. I get the following:
----
Your suggestion has been submitted.
There are no pending purchase suggestions. (Hmm, should be one?)
New purchase suggestion (Link)
----

I add a 2nd suggestion 'BBB'
----
Your suggestion has been submitted.
There are no pending purchase suggestions. (Hmm, should be two?)
New purchase suggestion (Link)
----
Clicking the link results in a new screen with the message:
"You cannot place any more suggestions" etc.

Question: Couldn't the link be replaced by the message (like in the overview page)? That would be a nicer user experience.

Then a minor typo on the overview page: The second sentence has no ending punctuation:
----
You have reached your limit of suggestions you can place at this time.
Once the library has processed those suggestions you will be able to place more
---

Ah, and it would be nice to have the maximum number in the user message.
Comment 3 Nicole C. Engard 2016-06-16 17:27:39 UTC
*** Bug 14979 has been marked as a duplicate of this bug. ***
Comment 4 Nick Clemens 2016-06-18 01:22:51 UTC Comment hidden (obsolete)
Comment 5 Nick Clemens 2016-06-18 01:24:36 UTC
(In reply to Marc Véron from comment #2)
> From OPAC, I add a suggestion 'AAA'. I get the following:
> ----
> Your suggestion has been submitted.
> There are no pending purchase suggestions. (Hmm, should be one?)

> Clicking the link results in a new screen with the message:
> "You cannot place any more suggestions" etc.
> 
> Question: Couldn't the link be replaced by the message (like in the overview
> page)? That would be a nicer user experience.

The two above points are related and are related to existing functionality - I filed a new bug for those bug 16767 and will work on that there
 
> Then a minor typo on the overview page: The second sentence has no ending
> punctuation:

Fixed
> Ah, and it would be nice to have the maximum number in the user message.

Fixed
Comment 6 Marc Véron 2016-06-18 06:09:51 UTC
(In reply to Nick Clemens from comment #5)
> (In reply to Marc Véron from comment #2)
> > From OPAC, I add a suggestion 'AAA'. I get the following:
> > ----
> > Your suggestion has been submitted.
> > There are no pending purchase suggestions. (Hmm, should be one?)
> 
> > Clicking the link results in a new screen with the message:
> > "You cannot place any more suggestions" etc.
> > 
> > Question: Couldn't the link be replaced by the message (like in the overview
> > page)? That would be a nicer user experience.
> 
> The two above points are related and are related to existing functionality -
> I filed a new bug for those bug 16767 and will work on that there
I tested together with 16767, works OK

> > Then a minor typo on the overview page: The second sentence has no ending
> > punctuation:
OK

> Fixed
> > Ah, and it would be nice to have the maximum number in the user message.
> 
> Fixed
There seems to be one more needed, line 258. 

Sorry, while testing I found a way to circumvent the restriction:
- Add sussgestions until you reach the limit
- Hit the browser back button
- You are back on the entry form, fill it and submit
- Purchase suggestion is submitted
- Repeat as many times you want
Comment 7 Koha Team University Lyon 3 2016-06-20 13:19:06 UTC
I have tried to install it on a sandbox :
Some problems occurred applying patches from bug 14752:
<h1>Something went wrong !</h1>Applying: Bug 14752 - Add multiple copies to a basket at once
Applying: Bug 14752 - (QA followup) Remove annoying modal, use dialog box instead Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging C4/Barcodes/hbyymmincr.pm
CONFLICT (content): Merge conflict in C4/Barcodes/hbyymmincr.pm Failed to merge in the changes.
Patch failed at 0001 Bug 14752 - (QA followup) Remove annoying modal, use dialog box instead

When you have resolved this problem run git bz apply --continue.
If you would prefer to skip this patch, instead run git bz apply --skip.
To restore the original branch and stop patching run git bz apply --abort.
Bug 14752 - Add multiple copies to a basket at once

51481 - Bug 14752 - Add multiple copies to a basket at once
52083 - Bug 14752 - (QA followup) Remove annoying modal, use dialog box instead

Sonia
Comment 8 Koha Team University Lyon 3 2016-06-20 13:20:12 UTC
sorry wrong bug...
Comment 9 Owen Leonard 2016-06-20 13:35:50 UTC
If this requires a change to the database, shouldn't there be an atomicupdate file?

https://wiki.koha-community.org/wiki/Database_updates#New_workflow_since_bug_13068_has_been_pushed
Comment 10 Nick Clemens 2016-06-20 14:31:05 UTC Comment hidden (obsolete)
Comment 11 Nick Clemens 2016-06-20 14:33:16 UTC
(In reply to Marc Véron from comment #6)
> Sorry, while testing I found a way to circumvent the restriction

Limits now checked before adding

(In reply to Owen Leonard from comment #9)
> shouldn't there be an atomicupdate file?

Atomic update file included now
Comment 12 Kyle M Hall 2016-06-20 16:46:08 UTC Comment hidden (obsolete)
Comment 13 Kyle M Hall 2016-06-20 16:46:15 UTC Comment hidden (obsolete)
Comment 14 Kyle M Hall 2016-06-20 16:47:24 UTC
(In reply to Kyle M Hall from comment #13)
> Created attachment 52611 [details] [review] [review]
> Bug 15128 [QA Followup] - Make suggestion display after being added
> 
> Also fixes the issue that the add suggestion link would sometimes
> show even if the patron could not make an additional suggestion.

This followup also tidys a chunk of very poorly formatted code. No changes in that part were made aside for tidying.
Comment 15 Kyle M Hall 2016-06-20 19:26:07 UTC Comment hidden (obsolete)
Comment 16 Kyle M Hall 2016-06-20 19:26:20 UTC Comment hidden (obsolete)
Comment 17 Kyle M Hall 2016-06-20 19:26:23 UTC Comment hidden (obsolete)
Comment 18 Nick Clemens 2016-06-20 20:05:14 UTC Comment hidden (obsolete)
Comment 19 Marc Véron 2016-06-21 13:49:26 UTC
No i can add as many suggestions as I want.

It is related to:
opac/opac-suggestions.pl line 117

my $patrons_pending_suggestions_count = scalar @{ SearchSuggestion( { suggestedby => $borrowernumber, STATUS => 'ASKED' } ) } ;

'my' should be removed
Comment 20 Nicole C. Engard 2016-06-23 13:24:56 UTC Comment hidden (obsolete)
Comment 21 Nicole C. Engard 2016-06-23 13:25:01 UTC Comment hidden (obsolete)
Comment 22 Nicole C. Engard 2016-06-23 13:25:06 UTC Comment hidden (obsolete)
Comment 23 Nicole C. Engard 2016-06-23 13:25:11 UTC Comment hidden (obsolete)
Comment 24 Kyle M Hall 2016-06-23 13:27:11 UTC Comment hidden (obsolete)
Comment 25 Kyle M Hall 2016-06-23 13:27:18 UTC Comment hidden (obsolete)
Comment 26 Kyle M Hall 2016-06-23 13:27:21 UTC Comment hidden (obsolete)
Comment 27 Kyle M Hall 2016-06-23 13:27:24 UTC Comment hidden (obsolete)
Comment 28 Jonathan Druart 2016-06-25 13:49:40 UTC
This cannot be signed off, the patchset does not work at all, there is no limitation!
Comment 29 Jonathan Druart 2016-06-25 13:55:50 UTC
Code review:
1/ MaxOpenSuggestions = 0 will not work as expected
2/ If a patron tries to force the add, he will get "There are no pending purchase suggestions." even if there are.
Comment 30 Nick Clemens 2016-06-30 14:22:07 UTC Comment hidden (obsolete)
Comment 31 Jonathan Druart 2016-07-01 15:10:24 UTC
(In reply to Jonathan Druart from comment #28)
> This cannot be signed off, the patchset does not work at all, there is no
> limitation!

Still valid...
Nick, could you confirm that these patches have been tested correctly?
They do not work for me.
Comment 32 Nick Clemens 2016-07-01 15:41:13 UTC Comment hidden (obsolete)
Comment 33 Nick Clemens 2016-07-01 15:41:18 UTC Comment hidden (obsolete)
Comment 34 Jonathan Druart 2016-07-01 16:03:28 UTC
Created attachment 53037 [details] [review]
Bug 15128 - Add ability to limit patrons open purchase suggestions

To test:
1 - Define a number of MaxOpenSuggestions
2 - Add some suggestions for a patron
3 - Note they cannot add any more suggestions if limit is reached
4 - Delete a suggestion and note you can add another
5 - Add them to limit again
6 - Accept a suggestion in the staff client and note user can add more
7 - Repeat above with rejecting or deleting
8 - Sign off.

Sponsored by:
    North Central Regional Library (http://ncrl.org/)

Signed-off-by: Barbara Walters <bwalters@ncrl.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 35 Jonathan Druart 2016-07-01 16:03:33 UTC
Created attachment 53038 [details] [review]
Bug 15128 [QA Followup] - Make suggestion display after being added

Also fixes the issue that the add suggestion link would sometimes
show even if the patron could not make an additional suggestion.

Signed-off-by: Barbara Walters <bwalters@ncrl.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 36 Jonathan Druart 2016-07-01 16:03:48 UTC
Created attachment 53039 [details] [review]
Bug 15128 [QA Followup 2] - Only count pending suggestions for the limit

Signed-off-by: Barbara Walters <bwalters@ncrl.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 37 Jonathan Druart 2016-07-01 16:04:00 UTC
Created attachment 53040 [details] [review]
Bug 15128 - Followup

Only check limit for signed in borrower
Show all suggestions after a new one is added

Signed-off-by: Barbara Walters <bwalters@ncrl.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 38 Jonathan Druart 2016-07-01 16:04:04 UTC
Created attachment 53041 [details] [review]
Bug 15128 (QA Followup) Display all purchase suggestions whether or not suggestion was added Correct enforcement of 0 limit

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 39 Jonathan Druart 2016-07-01 16:04:10 UTC
Created attachment 53042 [details] [review]
Bug 15128 - (QA Followup) Fix use of 'my' variable causing loss of data

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 40 Jonathan Druart 2016-07-01 16:04:15 UTC
Created attachment 53043 [details] [review]
Bug 15128 - (QA Followup) Don't get patrons suggestions if limit not set

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 41 Jonathan Druart 2016-07-01 16:04:20 UTC
Created attachment 53044 [details] [review]
Bug 15128: Revert Display all purchase suggestions whether or not suggestion was added

This does not work correctly and should be handle on another bug report.
The behavior existed prior to this patchset.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 42 Jonathan Druart 2016-07-01 16:04:24 UTC
Created attachment 53045 [details] [review]
Bug 15128: Do not display "New suggestion" if limit has just been reached

If limit is X and patrons has X-1 pending suggestions, when a new one is
added, the "New suggestion" should not been added.
to avoid another call to SearchSuggestions, we assume than the
suggestion has been correctly added.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 43 Kyle M Hall 2016-07-08 14:13:22 UTC
Pushed to master for 16.11, thanks Nick, Jonathan!