Bugzilla – Attachment 63762 Details for
Bug 1985
Email notification of new OPAC comments
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 1985: Introduction of review alerts
Bug-1985-Introduction-of-review-alerts.patch (text/plain), 16.93 KB, created by
Marc Véron
on 2017-05-27 06:27:16 UTC
(
hide
)
Description:
Bug 1985: Introduction of review alerts
Filename:
MIME Type:
Creator:
Marc Véron
Created:
2017-05-27 06:27:16 UTC
Size:
16.93 KB
patch
obsolete
>From 9b43e9512963ac3440439b1a125c580cbc46938a Mon Sep 17 00:00:00 2001 >From: Mark Tompsett <mtompset@hotmail.com> >Date: Fri, 26 May 2017 10:02:46 -0400 >Subject: [PATCH] Bug 1985: Introduction of review alerts >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >In comment #11, it was mentioned that title and biblionumber from >the biblio table were not available as variables in the letter. > >This corrects this by converting the parameter list to a hashref, >and adding the missing biblio number. > >It also cleans up the license on C4/Review.pm to be in line with >the current coding guidelines license. Also strict and warning >have been changed to the 'Use Modern::Perl;' now. > >Additionally, <<reviews.reviewid>> is now usable in the letter, >as is <<staffClientBaseURL>>. These were required additions, >because comment #1 expressly says there should be a direct link >to approve or delete. I also included a review everything link, >since there could be multiple comments outstanding. > >The default letter was tweaked as well to reflect these changes. > >Fixed bad URLs as noted in comment #26. > >TEST PLAN >--------- >1) Create test branch and apply patch >2) run installer/data/mysql/updatedatabase.pl > -- this will add the required default letter. >3) In the staff client: > a) set the CommentModeratorsEmail system preference. > -- not setting it will mean you won't get any queued > letters. > a) set the staffClientBaseURL system preference. > -- not setting it will mean your email links won't be > valid (i.e http:///...). > b) modify the COMMENT_CREATED default letter as desired. > -- feel free to add other things. >4) In the OPAC: > a) Log in > b) Find something > c) Click on the 'Comments' tab > -- Holdings/Title notes/Comments (#) is at the bottom > d) Click 'Post or edit your comments on this item' > e) In the window that pops up, type your comment. > f) Click 'Submit and close this window'. > g) Click 'Edit' and repeat steps e and f again. >5) In a mysql client: > a) Open the koha database > b) SELECT * FROM message_queue WHERE letter_code='COMMENT_CREATED'; > -- There should be at least two. > -- They should be able to contain the borrower number, biblio > title, and other borrower and biblio related things. > -- Comments are at a biblio level, so items, and issues don't > make sense as variables for the letter. > -- Confirm the URLs are valid by pasting into a browser. >6) prove -v t/db_dependent/Koha/Reviews.t > -- six new tests should run. >7) Run the koha qa test tool. > >Signed-off-by: Marc Véron <veron@veron.ch> >--- > C4/Letters.pm | 6 ++- > Koha/Review.pm | 48 ++++++++++++++++++++++ > installer/data/mysql/atomicupdate/bug_1985.sql | 38 +++++++++++++++++ > .../data/mysql/en/mandatory/sample_notices.sql | 25 +++++++++++ > installer/data/mysql/sysprefs.sql | 1 + > .../prog/en/modules/admin/preferences/opac.pref | 4 ++ > opac/opac-review.pl | 31 ++++++++++---- > t/db_dependent/Koha/Reviews.t | 44 +++++++++++++++++++- > 8 files changed, 187 insertions(+), 10 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug_1985.sql > >diff --git a/C4/Letters.pm b/C4/Letters.pm >index 8df9df2..97e5efc 100644 >--- a/C4/Letters.pm >+++ b/C4/Letters.pm >@@ -719,9 +719,12 @@ sub GetPreparedLetter { > } > } > >- my $OPACBaseURL = C4::Context->preference('OPACBaseURL'); >+ my $OPACBaseURL = C4::Context->preference('OPACBaseURL') // ''; > $letter->{content} =~ s/<<OPACBaseURL>>/$OPACBaseURL/go; > >+ my $staffClientBaseURL = C4::Context->preference('staffClientBaseURL') // ''; >+ $letter->{content} =~ s/<<staffClientBaseURL>>/$staffClientBaseURL/go; >+ > if ($want_librarian) { > # parsing librarian name > my $userenv = C4::Context->userenv; >@@ -841,6 +844,7 @@ sub _parseletter_sth { > ($table eq 'aqbooksellers') ? "SELECT * FROM $table WHERE id = ?" : > ($table eq 'aqorders' ) ? "SELECT * FROM $table WHERE ordernumber = ?" : > ($table eq 'opac_news' ) ? "SELECT * FROM $table WHERE idnew = ?" : >+ ($table eq 'reviews' ) ? "SELECT * FROM $table WHERE reviewid = ?" : > ($table eq 'article_requests') ? "SELECT * FROM $table WHERE id = ?" : > ($table eq 'borrower_modifications') ? "SELECT * FROM $table WHERE verification_token = ?" : > ($table eq 'subscription') ? "SELECT * FROM $table WHERE subscriptionid = ?" : >diff --git a/Koha/Review.pm b/Koha/Review.pm >index 72e3e2f..75da3e3 100644 >--- a/Koha/Review.pm >+++ b/Koha/Review.pm >@@ -20,6 +20,7 @@ use Modern::Perl; > use Carp; > > use Koha::Database; >+use C4::Letters; > > use base qw(Koha::Object); > >@@ -67,4 +68,51 @@ sub _type { > return 'Review'; > } > >+=head3 SendReviewAlert >+ >+ $review->SendReviewAlert($parameters); >+ >+Queue an outgoing email alert when a borrower posts a review, >+using the passed parameters in a hash reference. >+ >+=cut >+ >+sub SendReviewAlert { >+ my ( $self, $params ) = @_; >+ >+ my $borrowernumber = $params->{borrowernumber}; >+ my $reviewid = $params->{reviewid}; >+ my $biblionumber = $params->{biblionumber}; >+ >+ my $moderatorEmail = C4::Context->preference('CommentModeratorsEmail'); >+ unless ($moderatorEmail) { >+ carp 'CommentModeratorsEmail is not set!'; >+ return; >+ } >+ >+ my $letter = C4::Letters::GetPreparedLetter ( >+ module => 'members', >+ letter_code => 'COMMENT_CREATED', >+ tables => { >+ 'reviews' => $reviewid, >+ 'borrowers' => $borrowernumber, >+ 'biblio' => $biblionumber, >+ 'biblioitems' => $biblionumber, >+ } >+ ); >+ unless ($letter) { >+ carp 'COMMENT_CREATED member letter not found!'; >+ return; >+ } >+ >+ C4::Letters::EnqueueLetter({ >+ letter => $letter, >+ borrowernumber => $borrowernumber, >+ message_transport_type => 'email', >+ to_address => $moderatorEmail, >+ }); >+ >+ return 1; >+} >+ > 1; >diff --git a/installer/data/mysql/atomicupdate/bug_1985.sql b/installer/data/mysql/atomicupdate/bug_1985.sql >new file mode 100644 >index 0000000..6c23ef1 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_1985.sql >@@ -0,0 +1,38 @@ >+INSERT IGNORE INTO letter >+ (module, code, branchcode, name, is_html, >+ title, >+ content, message_transport_type) >+VALUES >+ ('members', 'COMMENT_CREATED', '', 'Comment created notification', '0', >+ 'Comment from <<borrowers.cardnumber>> is waiting for moderation', >+'Dear moderator, >+ >+We want to inform you that borrower <<borrowers.cardnumber>> has just created a new comment on <<biblio.title>>, which is biblionumber <<biblio.biblionumber>>. >+ >+--- BEGIN COMMENT --- >+<<reviews.review>> >+--- END COMMENT --- >+ >+To approve: >+http://<<staffClientBaseURL>>/cgi-bin/koha/reviews/reviewswaiting.pl?op=approve&reviewid=<<reviews.reviewid>> >+ >+To delete: >+http://<<staffClientBaseURL>>/cgi-bin/koha/reviews/reviewswaiting.pl?op=delete&reviewid=<<reviews.reviewid>> >+ >+Or to review all comments: >+http://<<staffClientBaseURL>>/cgi-bin/koha/reviews/reviewswaiting.pl >+ >+Check it out! >+ >+Your library.', >+'email' >+ ); >+ >+INSERT IGNORE INTO systempreferences >+ (variable, value,options, >+ explanation, >+ type) >+VALUES >+ ('CommentModeratorsEmail','', '', >+ 'The email address where to send a notification (template code COMMENT_CREATED) when a Borrower adds/modifies a review/comment for a Biblio. Set to empty to disable sending email notifications.', >+ 'Textarea'); >diff --git a/installer/data/mysql/en/mandatory/sample_notices.sql b/installer/data/mysql/en/mandatory/sample_notices.sql >index 7a5c4da..b911abc 100644 >--- a/installer/data/mysql/en/mandatory/sample_notices.sql >+++ b/installer/data/mysql/en/mandatory/sample_notices.sql >@@ -129,6 +129,31 @@ Your library account has been created. Please verify your email address by click > If you did not initiate this request, you may safely ignore this one-time message. The request will expire shortly.' > ); > >+INSERT INTO letter (module, code, branchcode, name, is_html, title, content, message_transport_type) >+VALUES ( 'members', 'COMMENT_CREATED', '', 'Comment created notification', '0', 'Comment from <<borrowers.cardnumber>> is waiting for moderation', >+'Dear moderator, >+ >+We want to inform you that borrower <<borrowers.cardnumber>> has just created a new comment on <<biblio.title>>, which is biblionumber <<biblio.biblionumber>>. >+ >+--- BEGIN COMMENT --- >+<<reviews.review>> >+--- END COMMENT --- >+ >+To approve: >+http://<<staffClientBaseURL>>/cgi-bin/koha/reviews/reviewswaiting.pl?op=approve&reviewid=<<reviews.reviewid>> >+ >+To delete: >+http://<<staffClientBaseURL>>/cgi-bin/koha/reviews/reviewswaiting.pl?op=delete&reviewid=<<reviews.reviewid>> >+ >+Or to review all comments: >+http://<<staffClientBaseURL>>/cgi-bin/koha/reviews/reviewswaiting.pl >+ >+Check it out! >+ >+Your library.', >+'email' >+); >+ > INSERT INTO letter (module, code, branchcode, name, is_html, title, content) > VALUES ('members', 'SHARE_INVITE', '', 'Invitation for sharing a list', '0', 'Share list <<listname>>', 'Dear patron, > >diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql >index 0bd8cac..993b299 100644 >--- a/installer/data/mysql/sysprefs.sql >+++ b/installer/data/mysql/sysprefs.sql >@@ -110,6 +110,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` > ('CoceHost', '', NULL, 'Coce server URL', 'Free'), > ('CoceProviders', '', 'aws,gb,ol', 'Coce providers', 'multiple'), > ('COinSinOPACResults','1','','If ON, use COinS in OPAC search results page. NOTE: this can slow down search response time significantly','YesNo'), >+('CommentModeratorsEmail','','','The email address where to send a notification (template code COMMENT_CREATED) when a Borrower adds/modifies a review/comment for a Biblio. Set to empty to disable sending email notifications.','Textarea'), > ('ConfirmFutureHolds','0','','Number of days for confirming future holds','Integer'), > ('ConsiderOnSiteCheckoutsAsNormalCheckouts','1',NULL,'Consider on-site checkouts as normal checkouts','YesNo'), > ('CronjobLog','0',NULL,'If ON, log information from cron jobs.','YesNo'), >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref >index b6954ef..5ffd1a9 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref >@@ -450,6 +450,10 @@ OPAC: > no: Hide > - reviewer's avatar beside comments in OPAC. The avatar will be searched on www.libravatar.org using the patron's e-mail address. > - >+ - The email address where to send a notification (template code COMMENT_CREATED) when a Borrower adds/modifies a review/comment for a Biblio. Set to empty to disable sending email notifications. >+ - pref: CommentModeratorsEmail >+ class: textarea >+ - > - pref: RequestOnOpac > choices: > yes: Allow >diff --git a/opac/opac-review.pl b/opac/opac-review.pl >index 8fc50ec..24f9aef 100755 >--- a/opac/opac-review.pl >+++ b/opac/opac-review.pl >@@ -31,8 +31,8 @@ use Koha::Reviews; > > my $query = new CGI; > my $biblionumber = $query->param('biblionumber'); >-my $review = $query->param('review'); >-my $reviewid = $query->param('reviewid'); >+my $review = $query->param('review'); # if defined submit >+my $reviewid = $query->param('reviewid'); # if defined edit > my ( $template, $borrowernumber, $cookie ) = get_template_and_user( > { > template_name => "opac-review.tt", >@@ -44,7 +44,11 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( > > # FIXME: need to allow user to delete their own comment(s) > >-my ( $clean, @errors, $savedreview ); >+my ( $clean, @errors, $savedreview, $affectedreview ); >+ >+my $submitting = ( defined $review && $review ne q{} ) ? 1 : 0; >+my $editing = ( defined $reviewid ) ? 1: 0; >+ > my $biblio = GetBiblioData($biblionumber); > > if( !$biblio ) { >@@ -58,7 +62,7 @@ if( !$biblio ) { > $review = $savedreview? $savedreview->review: $review; > } > >-if( !@errors && defined $review ) { >+if( !@errors && $submitting ) { > if ($review !~ /\S/) { > push @errors, {empty=>1}; > } else { >@@ -72,22 +76,33 @@ if( !@errors && defined $review ) { > my $js_ok_review = $clean; > $js_ok_review =~ s/"/"/g; # probably redundant w/ TMPL ESCAPE=JS > $template->param(clean_review=>$js_ok_review); >- if ($savedreview) { >- $savedreview->set( >+ if ($editing) { >+ my $updatedreview = $savedreview->set( > { > review => $clean, > approved => 0, > datereviewed => dt_from_string > } > )->store; >+ $affectedreview = $updatedreview; > } else { >- $reviewid = Koha::Review->new( >+ my $newreview = Koha::Review->new( > { biblionumber => $biblionumber, > borrowernumber => $borrowernumber, > review => $clean, > } >- )->store->reviewid; >+ )->store; >+ $reviewid = $newreview ? $newreview->reviewid : 0; >+ $affectedreview = $newreview; > } >+ if ($reviewid) { >+ $affectedreview->SendReviewAlert({ >+ 'borrowernumber' => $borrowernumber, >+ 'reviewid' => $reviewid, >+ 'biblionumber' => $biblionumber >+ }); >+ } >+ > unless (@errors){ $template->param(WINDOW_CLOSE=>1); } > } > } >diff --git a/t/db_dependent/Koha/Reviews.t b/t/db_dependent/Koha/Reviews.t >index da164f7..e10da80 100644 >--- a/t/db_dependent/Koha/Reviews.t >+++ b/t/db_dependent/Koha/Reviews.t >@@ -19,10 +19,14 @@ > > use Modern::Perl; > >-use Test::More tests => 7; >+use Test::More tests => 13; >+use Test::Warn; > > use Koha::Review; > use Koha::Reviews; >+use Koha::Notice::Messages; >+use Koha::Notice::Templates; >+use t::lib::Mocks; > use Koha::Database; > > use t::lib::TestBuilder; >@@ -35,6 +39,7 @@ my $patron_1 = $builder->build({ source => 'Borrower' }); > my $patron_2 = $builder->build({ source => 'Borrower' }); > my $biblio_1 = $builder->build({ source => 'Biblio' }); > my $biblio_2 = $builder->build({ source => 'Biblio' }); >+my $nb_of_messages = Koha::Notice::Messages->search->count; > my $nb_of_reviews = Koha::Reviews->search->count; > my $nb_of_approved_reviews = Koha::Reviews->search({ approved => 1 })->count; > my $new_review_1_1 = Koha::Review->new({ >@@ -68,6 +73,43 @@ is( $retrieved_review_1_1->review, $new_review_1_1->review, 'Find a review by id > $retrieved_review_1_1->delete; > is( Koha::Reviews->search->count, $nb_of_reviews + 2, 'Delete should have deleted the review' ); > >+# Test SendReview Alert >+ >+# empty CommentModeratorsEmail >+t::lib::Mocks::mock_preference('CommentModeratorsEmail',undef); >+warning_like { >+$new_review_1_2->SendReviewAlert({ >+ borrowernumber => $patron_1->{borrowernumber}, >+ biblionumber => $biblio_2->{biblionumber}, >+ reviewid => $new_review_1_2->reviewid >+}) } qr/CommentModeratorsEmail is not set!/, 'SendReviewAlert triggered expected CommentModeratorsEmail warning.'; >+is( Koha::Notice::Messages->search->count, $nb_of_messages, 'SendReviewAlert lacking CommentModeratorsEmail triggered nothing.' ); >+ >+# set CommentModeratorsEmail >+t::lib::Mocks::mock_preference('CommentModeratorsEmail','test@test.test'); >+warning_is { >+$new_review_1_2->SendReviewAlert({ >+ borrowernumber => $patron_1->{borrowernumber}, >+ biblionumber => $biblio_2->{biblionumber}, >+ reviewid => $new_review_1_2->reviewid >+}) } '', 'SendReviewAlert triggered no warnings as expected.'; >+is( Koha::Notice::Messages->search->count, $nb_of_messages+1, 'SendReviewAlert triggered notice.' ); >+ >+# letter missing >+Koha::Notice::Templates->search({ >+ module => 'members', >+ code => 'COMMENT_CREATED' >+})->delete; >+warnings_like { >+$new_review_1_2->SendReviewAlert({ >+ borrowernumber => $patron_1->{borrowernumber}, >+ biblionumber => $biblio_2->{biblionumber}, >+ reviewid => $new_review_1_2->reviewid >+}) } >+[ qr/No members COMMENT_CREATED letter transported by email/, >+ qr/COMMENT_CREATED member letter not found!/ ] , 'SendReviewAlert triggered expected COMMENT_CREATED warnings.'; >+is( Koha::Notice::Messages->search->count, $nb_of_messages+1, 'SendReviewAlert lacking letter triggered nothing new.' ); >+ > $schema->storage->txn_rollback; > > 1; >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 1985
:
33916
|
33918
|
36065
|
36516
|
36517
|
36521
|
36522
|
36613
|
36614
|
36628
|
36629
|
36643
|
36644
|
36645
|
36677
|
36678
|
36720
|
38908
|
38909
|
38910
|
39062
|
63746
|
63747
|
63748
|
63749
|
63750
|
63751
|
63752
|
63761
|
63762
|
63763
|
74760
|
74761
|
74762
|
74763
|
74764
|
74769
|
74770
|
74771
|
91190
|
91191
|
91192
|
91193
|
91194
|
91195
|
91196
|
91197
|
91198
|
91818
|
91819
|
91820
|
91821
|
91822
|
91823