Bugzilla – Attachment 42717 Details for
Bug 14855
Resend notices in Notices tab with AJAX + REST
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14855: Resend notices in Notices tab with AJAX + REST
Bug-14855-Resend-notices-in-Notices-tab-with-AJAX-.patch (text/plain), 11.43 KB, created by
Lari Taskula
on 2015-09-21 10:55:52 UTC
(
hide
)
Description:
Bug 14855: Resend notices in Notices tab with AJAX + REST
Filename:
MIME Type:
Creator:
Lari Taskula
Created:
2015-09-21 10:55:52 UTC
Size:
11.43 KB
patch
obsolete
>From a0f34df6ae07f3d4e825a7af6745102862d3e655 Mon Sep 17 00:00:00 2001 >From: Lari Taskula <larit@student.uef.fi> >Date: Mon, 21 Sep 2015 12:39:45 +0300 >Subject: [PATCH] Bug 14855: Resend notices in Notices tab with AJAX + REST > >Bug 12426 introduces a resend link to resend sent and failed messages. It uses >POST method. Since Bug 14843 gives us REST API for notifications, we should >enhance 12426 to use REST API via AJAX and only allow Staff members with >permission "resend_message" to be able to see the link and use it. > >This patch changes the request into AJAX POST via the REST API for notifications. > >To test: >-2. Make sure you have all the dependant patches >-1. Enable system preference EnhancedMessagingPreferences >-0. Make sure you do not have permission messages -> resend_message > >To test: >1. Have/create some pending sms messages into message_queue >2. Go to Patrons -> Notices >3. Resend one of the message and observe the page will reload >4. Apply patch >5. Reload Patrons -> Notices and observe there is no Resend link >6. Add yourself the permission messages -> resend_message >7. Reload Patrons -> Notices and observe there is Resend link >8. Resend a message and observe page will not reload >9. Observe that the message status has changed to pending >--- > .../prog/en/modules/members/notices.tt | 24 +++- > members/notices.pl | 29 ++-- > t/db_dependent/ResendMessage.t | 155 +++++++++++++++++++++ > 3 files changed, 190 insertions(+), 18 deletions(-) > create mode 100644 t/db_dependent/ResendMessage.t > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt >index 0208374..198f76d 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt >@@ -21,6 +21,21 @@ > }); > > }); >+ function resendMessage(id, status_element){ >+ var resend = $.ajax({ >+ type: "POST", >+ url: "/api/v1/messages/"+id+"/resend", >+ data: { }, >+ statusCode: { >+ 404: function(){ >+ alert("Message not found."); >+ }, >+ 204: function(){ >+ $(status_element).text("pending"); >+ } >+ } >+ }); >+ } > //]]> > </script> > <style type="text/css"> >@@ -74,14 +89,9 @@ > [% ELSIF ( QUEUED_MESSAGE.status == 'failed' ) %]failed > [% ELSIF ( QUEUED_MESSAGE.status == 'deleted' ) %]deleted > [% ELSE %][% QUEUED_MESSAGE.status %][% END %] >- [% IF ( QUEUED_MESSAGE.status != 'pending' ) %] >+ [% IF ( QUEUED_MESSAGE.status != 'pending' ) AND showResendLink == 1 %] > <div class="notice"> >- <form action="/cgi-bin/koha/members/notices.pl?borrowernumber=[% borrowernumber %]" method="POST"> >- <input type="hidden" name="op" value="resend_notice" /> >- <input type="hidden" name="borrowernumber" value="[% borrowernumber %]" /> >- <input type="hidden" name="message_id" value="[% QUEUED_MESSAGE.message_id %]" /> >- <a href="#" onclick="$(this).closest('form').submit();return false;" title="Attempt to resend the notice">Resend</a> >- </form> >+ <a href="#" onclick="resendMessage([% QUEUED_MESSAGE.message_id %], $(this).closest('td'));return false;" title="Attempt to resend the notice">Resend</a> > </div> > [% END %] > </td> >diff --git a/members/notices.pl b/members/notices.pl >index 95595ef..7800dec 100755 >--- a/members/notices.pl >+++ b/members/notices.pl >@@ -28,6 +28,8 @@ use C4::Members; > use C4::Branch; > use C4::Letters; > use C4::Members::Attributes qw(GetBorrowerAttributes); >+use Try::Tiny; >+use Scalar::Util qw ( blessed ); > > use C4::Dates qw/format_date/; > my $input=new CGI; >@@ -52,17 +54,6 @@ $template->param( $borrower ); > my ($picture, $dberror) = GetPatronImage($borrower->{'borrowernumber'}); > $template->param( picture => 1 ) if $picture; > >-# Allow resending of messages in Notices tab >-if ( $op eq 'resend_notice' ) { >- my $message_id = $input->param('message_id'); >- my $message = C4::Letters::GetMessage( $message_id ); >- if ( $message->{borrowernumber} = $borrowernumber ) { >- C4::Letters::ResendMessage( $message_id ); >- # redirect to self to avoid form submission on refresh >- print $input->redirect("/cgi-bin/koha/members/notices.pl?borrowernumber=$borrowernumber"); >- } >-} >- > # Getting the messages > my $queued_messages = C4::Letters::GetQueuedMessages({borrowernumber => $borrowernumber}); > >@@ -77,6 +68,21 @@ if (C4::Context->preference('ExtendedPatronAttributes')) { > my $roadtype = C4::Koha::GetAuthorisedValueByCode( 'ROADTYPE', $borrower->{'streettype'} ); > $template->param(%$borrower); > >+my $showResendLink = 0; >+ >+my $permissionManager = Koha::Auth::PermissionManager->new(); >+try { >+ $showResendLink = 1 if $permissionManager->hasPermission($loggedinuser,'messages','resend_message'); >+} catch { >+ if (blessed($_) && $_->isa('Koha::Exception::NoPermission')) { >+ # no permission >+ } >+ else { >+ die $_; >+ } >+}; >+ >+ > $template->param( > QUEUED_MESSAGES => $queued_messages, > borrowernumber => $borrowernumber, >@@ -86,6 +92,7 @@ $template->param( > roadtype => $roadtype, > activeBorrowerRelationship => (C4::Context->preference('borrowerRelationship') ne ''), > RoutingSerials => C4::Context->preference('RoutingSerials'), >+ showResendLink => $showResendLink, > ); > output_html_with_http_headers $input, $cookie, $template->output; > >diff --git a/t/db_dependent/ResendMessage.t b/t/db_dependent/ResendMessage.t >new file mode 100644 >index 0000000..f17f996 >--- /dev/null >+++ b/t/db_dependent/ResendMessage.t >@@ -0,0 +1,155 @@ >+#!/usr/bin/env perl >+ >+# Copyright 2015 Vaara-kirjastot >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+$ENV{KOHA_PAGEOBJECT_DEBUG} = 1; >+use Modern::Perl; >+ >+use Test::More; >+use Try::Tiny; #Even Selenium::Remote::Driver uses Try::Tiny :) >+ >+use Koha::Auth::PermissionManager; >+ >+use t::lib::Page::Mainpage; >+use t::lib::Page::Opac::OpacMain; >+use t::lib::Page::Opac::OpacMemberentry; >+use t::lib::Page::Members::Memberentry; >+use t::lib::Page::Members::Moremember; >+use t::lib::Page::Members::Notices; >+ >+use t::lib::TestObjects::BorrowerFactory; >+use t::lib::TestObjects::MessageQueueFactory; >+use t::lib::TestObjects::SystemPreferenceFactory; >+ >+use C4::Context; >+use C4::Members; >+ >+##Setting up the test context >+my $testContext = {}; >+ >+my $password = '1234'; >+my $invalidBorrowerNumber = '000'; >+my $borrowerFactory = t::lib::TestObjects::BorrowerFactory->new(); >+my $borrowers = $borrowerFactory->createTestGroup([ >+ {firstname => 'Testthree', >+ surname => 'Testfour', >+ cardnumber => 'superuberadmin', >+ branchcode => 'CPL', >+ userid => 'god', >+ address => 'testi', >+ city => 'joensuu', >+ smsalertnumber => '99999999999912007', >+ zipcode => '80100', >+ password => $password, >+ }, >+ ], undef, $testContext); >+my $messages = t::lib::TestObjects::MessageQueueFactory->createTestGroup([ >+ {subject => "Test pending", >+ content => "Tessst content", >+ cardnumber => $borrowers->{'superuberadmin'}->cardnumber, >+ message_transport_type => 'sms', >+ from_address => 'A001@example.com', >+ }, >+ {subject => "Test sent", >+ content => "Tessst content", >+ cardnumber => $borrowers->{'superuberadmin'}->cardnumber, >+ message_transport_type => 'sms', >+ from_address => 'A002@example.com', >+ }, >+ {subject => "Test failed", >+ content => "Tessst content", >+ cardnumber => $borrowers->{'superuberadmin'}->cardnumber, >+ message_transport_type => 'sms', >+ to_address => '', >+ from_address => 'A003@example.com', >+ }, >+ ], undef, $testContext); >+my $systempreferences = t::lib::TestObjects::SystemPreferenceFactory->createTestGroup([ >+ {preference => 'SMSSendDriver', >+ value => 'nonexistentdriver' >+ }, >+ { >+ preference => 'EnhancedMessagingPreferences', >+ value => '1' >+ } >+ ], undef, $testContext); >+ >+my $permissionManager = Koha::Auth::PermissionManager->new(); >+$permissionManager->grantPermissions($borrowers->{'superuberadmin'}, {catalogue => 'staff_login', borrowers => 'view_borrowers'}); >+ >+eval { >+ >+ # staff client >+ my $notices = t::lib::Page::Members::Notices->new({borrowernumber => $borrowers->{'superuberadmin'}->borrowernumber}); >+ >+ setMessageStatus($messages->{'A001@example.com'}->{message_id}, "pending"); >+ setMessageStatus($messages->{'A002@example.com'}->{message_id}, "sent"); >+ setMessageStatus($messages->{'A003@example.com'}->{message_id}, "failed"); >+ >+ # then, login to intranet >+ $notices->doPasswordLogin($borrowers->{'superuberadmin'}->userid(), $password) >+ ->openNotice("Test pending") >+ ->openNotice("Test sent") >+ ->openNotice("Test failed") >+ ->resendMessage("Test pending", 0) #pending cannot be resent >+ ->resendMessage("Test sent", 0) # --these two should fail because >+ ->resendMessage("Test failed", 0); # of missing permissions-- >+ >+ # add permission and refresh page >+ $permissionManager->grantPermissions($borrowers->{'superuberadmin'}, {messages => 'resend_message'}); >+ $notices >+ ->navigateToNotices() # refresh page and make sure everything is pending >+ ->openNotice("Test pending") >+ ->openNotice("Test sent") >+ ->openNotice("Test failed") >+ ->resendMessage("Test pending", 0) # pending cannot be resent >+ ->resendMessage("Test sent", 1) # --these two should now >+ ->resendMessage("Test failed", 1) # resend successfully-- >+ ->navigateToNotices() >+ ->getTextInColumnAtRow("pending", { row => 1, column => 3 }) >+ ->getTextInColumnAtRow("pending", { row => 2, column => 3 }) >+ ->getTextInColumnAtRow("pending", { row => 3, column => 3 }); >+}; >+if ($@) { #Catch all leaking errors and gracefully terminate. >+ warn $@; >+ tearDown(); >+ exit 1; >+} >+ >+##All tests done, tear down test context >+tearDown(); >+done_testing; >+ >+sub tearDown { >+ t::lib::TestObjects::ObjectFactory->tearDownTestContext($testContext); >+} >+ >+ >+ >+ >+ >+ >+ >+ >+###################################################### >+ ### STARTING TEST IMPLEMENTATIONS ### >+###################################################### >+ >+sub setMessageStatus { >+ my ($message_id, $status) = @_; >+ return C4::Letters::UpdateQueuedMessage({ message_id => $message_id, status => $status } ); >+} >\ No newline at end of file >-- >1.9.1
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 14855
: 42717