From 44dca4a9bfbf039e18628d923d7973366733b13c Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Fri, 8 Jul 2022 18:37:55 +0000 Subject: [PATCH] Bug 12029: Patrons should be able to delete their patron messages This patch adds an option for patrons to dismiss OPAC messages sent to them by the staff. The messages remain visible in the staff interface with an indication that the message has been read. To test, apply the patch and run the database update. - View a patron record in the staff interface. - Click "Add message" and select "OPAC" from the "Add a message for..." dropdown. - Add a message. - Log in to the OPAC as that patron. - On the "Your summary" page you should see the message along with a "Dismiss" link." - Clicking the "Dismiss" link should make the message disappear. - Go to the OPAC home page. The "User summary" box in the right sidebar should have the correct count of messages. - View the patron record in the staff interface again. - The list of patron messages should still include the message which was dismissed via the OPAC, but there should be indication that the message was read, e.g. "read 11-2-2022" --- Koha/Patron/Messages.pm | 33 ++++++++ .../data/mysql/atomicupdate/bug_12029.pl | 28 +++++++ installer/data/mysql/kohastructure.sql | 1 + .../prog/en/includes/patron_messages.inc | 3 + .../bootstrap/en/includes/opac-note.inc | 5 +- .../bootstrap/en/modules/opac-main.tt | 6 +- opac/dismiss_message.pl | 82 +++++++++++++++++++ t/db_dependent/Koha/Patron/Messages.t | 41 +++++++++- 8 files changed, 193 insertions(+), 6 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_12029.pl create mode 100755 opac/dismiss_message.pl diff --git a/Koha/Patron/Messages.pm b/Koha/Patron/Messages.pm index 7cc729ac86..33eb7d6901 100644 --- a/Koha/Patron/Messages.pm +++ b/Koha/Patron/Messages.pm @@ -42,8 +42,41 @@ sub _type { return 'Message'; } +=head3 object_class + +=cut + sub object_class { return 'Koha::Patron::Message'; } +=head3 unread + + Returns a result set of messages that haven't been marked read by the patron + +=cut + +sub unread { + # return resultset of messages with an undefined patron_read_date + my ($self, $params) = @_; + $params ||= {}; + return $self->search({ + patron_read_date => {IS => undef}, + %$params, + }); +} + +=head3 unread_count + + Returns a count of messages that haven't been marked read by the patron + +=cut + + +sub unread_count { + # return count of unread + my ($self, $params) = @_; + $params ||= {}; + return $self->unread(%$params)->count(); +} 1; diff --git a/installer/data/mysql/atomicupdate/bug_12029.pl b/installer/data/mysql/atomicupdate/bug_12029.pl new file mode 100755 index 0000000000..f352a66edf --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_12029.pl @@ -0,0 +1,28 @@ +use Modern::Perl; + +return { + bug_number => "12029", + description => "Enable patrons to delete messages", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + + # Do you stuffs here + my $alteration = qq{ + ALTER TABLE messages + ADD COLUMN `patron_read_date` timestamp NULL DEFAULT NULL + COMMENT 'date and time patron dismissed message' + AFTER `manager_id` + }; + if( column_exists('messages', 'patron_read_date') ) { + say $out "NOTICE: Column 'messages.patron_read_date' already exists"; + } + else { + say $out "ALTERATION: $alteration"; + $dbh->do($alteration); + } + + # Print useful stuff here + say $out "INFO: Bug 12029 migration applied"; + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index f797810c80..4f9b2eae16 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -3782,6 +3782,7 @@ CREATE TABLE `messages` ( `message` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'the text of the message', `message_date` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'the date and time the message was written', `manager_id` int(11) DEFAULT NULL COMMENT 'creator of message', + `patron_read_date` timestamp NULL DEFAULT NULL COMMENT 'date and time the patron dismissed the message', PRIMARY KEY (`message_id`), KEY `messages_ibfk_1` (`manager_id`), KEY `messages_borrowernumber` (`borrowernumber`), diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron_messages.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron_messages.inc index 97219917e7..4214a8caaa 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron_messages.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron_messages.inc @@ -218,6 +218,9 @@ ( [% patron_message.get_column('manager_firstname') | html %] [% patron_message.get_column('manager_surname') | html %] ) [% END %] "[% patron_message.message | html %]" + [% IF patron_message.patron_read_date %] + read [% patron_message.patron_read_date | $KohaDates %] + [% END %] [% IF patron_message.branchcode == Branches.GetLoggedInBranchcode OR Koha.Preference('AllowAllMessageDeletion') %] Delete diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-note.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-note.inc index 22e6a068ce..8b2c39f861 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-note.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-note.inc @@ -1,12 +1,13 @@ -[% IF patron_messages.count OR opacnote %] +[% IF patron_messages.unread_count OR opacnote %]

Messages for you