Bug 12029: Ability for patrons to dismiss OPAC messages

This enhancement adds the ability for patrons to dismiss an OPAC
message, marking it as read to remove it from their summary page.

To test:
1) Update database and restart services
2) Log into the staff interface and go to your patron account
3) Click the Add message button
4) Add a message for the OPAC and Save
5) Log into the OPAC. Note there is a message on the homepage saying you
have a message. Go to your user summary and confirm the message
displays.
6) Click the button to dismiss the message. A confirmation box should
pop up - hitting Cancel should stop the action.
7) Dismiss the message again and this time Confirm. Make sure the
message is gone from the OPAC user summary and from the homepage.
8) Confirm tests pass t/db_dependent/Koha/Patron/Messages.t
9) Create a few more messages for the OPAC
10) Log into the OPAC and dismiss one of the messages
11) Confirm the count of unread messages on the OPAC home page is
correct

Sponsored-by: Koha-US
Signed-off-by: Christopher Brannon <cbrannon@cdalibrary.org>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Aleisha Amohia 2023-02-15 21:57:08 +13:00 committed by Tomas Cohen Arazi
parent 52f228c02a
commit 368dfdc7d0
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
6 changed files with 96 additions and 7 deletions

View File

@ -34,6 +34,25 @@ Koha::Patron::Messages - Koha Message Object set class
=cut
=head3 filter_by_unread
Returns a resultset of messages that have not been marked read by the patron
=cut
sub filter_by_unread {
my ( $self, $params ) = @_;
$params ||= {};
return $self->search(
{
patron_read_date => { is => undef },
%$params,
}
);
}
=head3 _type
=cut
@ -42,6 +61,10 @@ sub _type {
return 'Message';
}
=head3 object_class
=cut
sub object_class {
return 'Koha::Patron::Message';
}

View File

@ -308,6 +308,9 @@
( <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% patron_message.manager_id | uri %]">[% patron_message.get_column('manager_firstname') | html %] [% patron_message.get_column('manager_surname') | html %]</a> )
[% END %]
<em>"[% patron_message.message | html %]"</em>
[% IF patron_message.patron_read_date %]
Read: <em>[% patron_message.patron_read_date | $KohaDates %]</em>
[% END %]
</span>
[% IF patron_message.branchcode == Branches.GetLoggedInBranchcode OR Koha.Preference('AllowAllMessageDeletion') %]
[% IF moremember %]

View File

@ -1,12 +1,17 @@
[% IF patron_messages.count OR opacnote %]
[% IF patron_messages.filter_by_unread.count OR opacnote %]
<div class="alert alert-info">
<h3>Messages for you</h3>
<ul>
[% FOREACH message IN patron_messages %]
[% FOREACH message IN patron_messages.filter_by_unread %]
<li>
<strong>[% message.message | html | html_line_break %]</strong><br>
&nbsp;&nbsp;&nbsp;<em>Written on [% message.message_date | $KohaDates %] by [% Branches.GetName(message.branchcode) | html %]</em>
</li>
<form id="dismiss-message-form" action="/cgi-bin/koha/opac-dismiss-message.pl" method="post">
<input type="hidden" name="message_id" value="[% message.message_id | html %]">
<input type="hidden" name="patron_id" value="[% message.borrowernumber | html %]">
<button type="submit" class="dismiss-message-button btn btn-primary"><i class="fa fa-trash" aria-hidden="true"></i> Dismiss</button>
</form>
[% END %]
[% IF ( opacnote ) %]<li>[% opacnote | html | html_line_break %]</li>[% END %]

View File

@ -283,19 +283,19 @@
</a>
</li>
[% END %]
[% IF patron_messages && patron_messages.count > 0 || opacnote %]
[% IF patron_messages && patron_messages.filter_by_unread.count > 0 || opacnote %]
[% IF opacnote %]
<li>
<a href="/cgi-bin/koha/opac-user.pl">
<span class="count_label">[% patron_messages.count + 1 | html %]</span>
[% tn('message', 'messages', patron_messages.count + 1 ) | html %]
<span class="count_label">[% patron_messages.filter_by_unread.count + 1 | html %]</span>
[% tn('message', 'messages', patron_messages.filter_by_unread.count + 1 ) | html %]
</a>
</li>
[% ELSE %]
<li>
<a href="/cgi-bin/koha/opac-user.pl">
<span class="count_label">[% patron_messages.count | html %]</span>
[% tn('message', 'messages', patron_messages.count ) | html %]
<span class="count_label">[% patron_messages.filter_by_unread.count | html %]</span>
[% tn('message', 'messages', patron_messages.filter_by_unread.count ) | html %]
</a>
</li>
[% END %]

View File

@ -1292,6 +1292,10 @@
$("#addNoteTitle").text("");
$("#addNote").val("");
});
$(".dismiss-message-button").click(function(e){
return confirmDelete(_("Are you sure you want to dismiss this message?"));
});
});
function submitNote( title, issue_id, note ){

54
opac/opac-dismiss-message.pl Executable file
View File

@ -0,0 +1,54 @@
#!/usr/bin/perl
# Copyright 2023 Aleisha Amohia <aleisha@catalyst.net.nz>
#
# 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>.
use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Koha;
use C4::Context;
use C4::Output qw( output_html_with_http_headers );
use C4::Auth qw( get_template_and_user );
use Koha::DateUtils qw( dt_from_string );
use Koha::Patrons;
my $query = CGI->new;
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
{
template_name => "opac-user.tt",
query => $query,
type => "opac",
}
);
my $patron_id = $query->param('patron_id');
my $patron = Koha::Patrons->find( $patron_id );
my $message_id = $query->param('message_id');
my $message = $patron->messages->find( $message_id );
unless ( $message ) {
# exit early
print $query->redirect("/cgi-bin/koha/opac-user.pl");
exit;
}
$message->update({ patron_read_date => dt_from_string });
print $query->redirect("/cgi-bin/koha/opac-user.pl");
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };