From: Jason Etheridge Date: Wed, 8 Jan 2020 14:02:52 +0000 (-0500) Subject: lp1846354 toward consolidated patron notes X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=ac037f5143b33fdb03fbaa445b82a274f1b1efc1;p=evergreen%2Ftadl.git lp1846354 toward consolidated patron notes * changes to IDL, DB, and upgrade script A new view actor.usr_message_penalty and associated IDL entry will be created for use with populating the staff Messages interface. It will perform a full outer join between penalties and user messages. The default IDL permissions for user messages will remain VIEW_USER and UPDATE_USER. The view that populates the Message Center will be changed slightly to ensure that staff-only messages are never retrieved for patrons. The Date column in the grid/list view will show the edit_date value if populated in lieu of the create_date value. The message view will explicitly show an Edit Date label and value below the Date row if set. The actor.usr_message table will gain a new boolean column called pub, which will default to false. The actor.usr_message table will also gain a stop_date column for handling archival as with standing penalties. The actor.usr_message table will also gain editor and edit_date columns. The actor.usr_message_limited view will be changed to only include rows where pub is true. As part of the upgrade script, Patron alert messages will be migrated as ALERT_NOTE penalties and linked User Messages. A database assertion will ensure that this has happened prior to the removal of the alert_message field from the actor.usr table. The field will also be removed from the corresponding IDL entry. The sending_lib column for these user messages and the org unit field for these penalties will be set to the top org from the org hierarchy. Also, non-public entries in the actor.usr_note table will be migrated as non-public User Messages. Subject to a database assertion that this has happened, the table actor.usr_note and the actor.convert_usr_note_to_message trigger will be removed. The corresponding IDL entry will also be removed. The sending_lib column for these user messages will be set to the top org from the org hierarchy. Also, rows from actor.org_unit_setting for ui.staff.require_initials.patron_info_notes will be migrated to ui.staff.require_initials.patron_standing_penalty. Collisions will be recorded in a text file but otherwise dropped. The row in config.org_unit_setting_type for ui.staff.require_initials.patron_info_notes will then be removed. The label and description for ui.staff.require_initials.patron_standing_penalty in config.org_unit_setting_type will be edited to reflect the Notes/Penalties labeling from the UI. The actor.usr_standing_penalty table and associated IDL entry will gain a foreign key column linking to actor.usr_message called usr_message, and the note column itself will be migrated to User Messages. The usr_message field on the penalties will be updated accordingly. Subject to a database assertion that this has happened, the note field on the actor.usr_standing_penalty table will be removed. The corresponding IDL entry will also be removed. The sending_lib column for these user messages will be set to match the org_unit column from their associated penalties. * middle layer changes The ApplyPatronPenalty A/T Reactor will be modified to create a user message if needed instead of setting the note field on the created penalty, and will set the new usr_message field accordingly. The API method open-ils.actor.user.penalty.note.update will be similarly adjusted, though it may edit or create a user message as needed. The API method open-ils.actor.user.penalty.apply will also be modified to create user messages in lieu of setting a note field. The sending_lib field for such messages will be set to match the session's workstation library, regardless of the org unit that actually gets applied to the penalty's org_unit field. The org_unit field will use the value as passed by the caller, and no longer do the org_unit_ancestor_at_depth adjustment that happens today. Both penalty.note.update and penalty.apply will set the editor and edit date columns on any linked user messages to the current time and staff member for any already existing message that has its title or message value modified. The read_date column will also be NULL'ed in such circumstances so that the message will appear unread to the patron if public. The react sub in Event.pm will be tweaked to explicitly set the pub field on created user messages to true for Action/Trigger. * OPAC changes Surface the edit date for patron visible notes in the Message Center. * staff client changes References to Message or Messages in the UI, including the button bar that spawns the interface, will be changed to Note and Notes. The Alert Message field in the patron editor will be removed. The Notes interface under Other -> Notes will be removed. The Notes (and count) indicator in the patron summary sidebar will be removed. The note count will instead be presented as part of the Notes nav button. The patron summary sidebar and the "stop sign page" will be modified to retrieve and display user messages linked to standing penalties that are flagged as staff alerting. It will retain the same styling (i.e. red text) by default. The Messages interface, including the archived view, will be populated with a combination of user messages and user penalties, which may or may not be linked in pairs via a new foreign key on the penalties. For messages without associated standing penalties, the sending_lib column will be used for the implicit filtering on org units that standing penalties get now, based on the workstation library. This combined view will result in new columns for the interface. At minimum the following columns (subject to label changes) will be displayed by default: Title, Message, Create Date, Creator, Library, and Patron Visible. Columns such as Staff Alert, Org Depth, Block List, Ignore Proximity, and Penalty Label will still be available. The Apply Penalty / Message dialog will gain a new widget for toggling whether or not a message is intended to be visible to the patron. The Edit message version of the dialog will also show when/if a patron has read and/or deleted the message. An entry field for the message title will be added. The dialog will also gain an org selector to the right of the penalty type selector, which will default to the workstation library, and will change based on the org depth of any standing penalty type selected in the UI (either via the Note/Alert/Block buttons or the penalty menu). This will be passed as the org_unit field for a penalty instead of the workstation library and org depth that is implicitly used today The sending_lib field for the user message will always be set to the workstation library. The Archive Penalty / Message action will be modified to work with both penalties and user messages depending on what it is selected. If an archived penalty has a linked user message, then both will have their archive fields set. An archived user message may still be otherwise visible to the patron if it is not marked as deleted or staff only. The Remove Penalty / Message action will behave as normal for a selected penalty. For a user message, linked or unlinked, the message will be flagged as deleted and, even if public, will no longer show up in the patron's Message Center. * release notes Patron notes, messages, alert messages, and standing penalties have been folded into one Notes interface. Notes designated as public will show in the My Account -> Message Center in the OPAC for patrons. The underlying data structure has also changed with all notes living in the actor.usr_message table, so certain reports may need to be adjusted. * qa tests * alert message wording * set existing user messages to public before adding new ones; also, remove a lingering reference to alert_message in Storage/CDBI/actor.pm * upgrade script tweaks the main change is that we're creating SILENT_NOTE penalties for migrated actor.usr_note's in order to preserve the creator. I'm also removing explicit TEMP tables in case admins do want to preserve these staging tables (by commenting out the DROP's at the bottom of the script). * update auditors fixes updating patrons and allowing them to login one consequence of this is that old alert_messages in the auditor will be deleted * add a WARNING to the release notes about the auditor table Signed-off-by: Jason Etheridge Signed-off-by: Mike Rylander Signed-off-by: Ruth Frasur Signed-off-by: Dawn Dale Signed-off-by: Terran McCanna Signed-off-by: Galen Charlton Signed-off-by: Chris Sharp --- diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 03319baa48..dc8e55d1dc 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -2312,9 +2312,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + + + + @@ -2335,9 +2340,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + + + + @@ -2347,38 +2357,56 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - - + + + - - - - + + + + + + + + + + - + + + + + + + + + + + + + + - + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + @@ -3902,7 +3930,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - @@ -3988,7 +4015,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - + @@ -4604,7 +4631,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - + @@ -4662,13 +4689,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - + + diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm index 0faeea2c7a..8681e5d7cc 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm @@ -1508,6 +1508,20 @@ sub retrieve_coordinates { } __PACKAGE__->register_method( + method => "get_my_org_ancestor_at_depth", + api_name => "open-ils.actor.org_unit.ancestor_at_depth.retrieve" +); + +sub get_my_org_ancestor_at_depth { + my( $self, $client, $auth, $org_id, $depth ) = @_; + my $e = new_editor(authtoken=>$auth); + return $e->event unless $e->checkauth; + $org_id = $e->requestor->ws_ou unless defined $org_id; + + return $apputils->org_unit_ancestor_at_depth( $org_id, $depth ); +} + +__PACKAGE__->register_method( method => "patron_adv_search", api_name => "open-ils.actor.patron.search.advanced" ); @@ -1975,7 +1989,13 @@ sub user_opac_vitals { $out->{"total_out"} = reduce { $a + $out->{$b} } 0, qw/out overdue/; my $unread_msgs = $e->search_actor_usr_message([ - {usr => $user_id, read_date => undef, deleted => 'f'}, + {usr => $user_id, read_date => undef, deleted => 'f', + 'pub' => 't', # this is for the unread message count in the opac + '-or' => [ + {stop_date => undef}, + {stop_date => {'>' => 'now'}} + ], + }, {idlist => 1} ]); @@ -3097,7 +3117,9 @@ __PACKAGE__->register_method( ); sub apply_penalty { - my($self, $conn, $auth, $penalty) = @_; + my($self, $conn, $auth, $penalty, $msg) = @_; + + $msg ||= {}; my $e = new_editor(authtoken=>$auth, xact => 1); return $e->die_event unless $e->checkauth; @@ -3107,10 +3129,23 @@ sub apply_penalty { my $ptype = $e->retrieve_config_standing_penalty($penalty->standing_penalty) or return $e->die_event; - my $ctx_org = - (defined $ptype->org_depth) ? - $U->org_unit_ancestor_at_depth($penalty->org_unit, $ptype->org_depth) : - $penalty->org_unit; + my $ctx_org = $penalty->org_unit; # csp org_depth is now considered in the UI for the org drop-down menu + + if (($msg->{title} || $msg->{message}) && ($msg->{title} ne '' || $msg->{message} ne '')) { + my $aum = Fieldmapper::actor::usr_message->new; + + $aum->create_date('now'); + $aum->sending_lib($e->requestor->ws_ou); + $aum->title($msg->{title}); + $aum->usr($penalty->usr); + $aum->message($msg->{message}); + $aum->pub($msg->{pub}); + + $aum = $e->create_actor_usr_message($aum) + or return $e->die_event; + + $penalty->usr_message($aum->id); + } $penalty->org_unit($ctx_org); $penalty->staff($e->requestor->id); @@ -3121,6 +3156,44 @@ sub apply_penalty { } __PACKAGE__->register_method( + method => "modify_penalty", + api_name => "open-ils.actor.user.penalty.modify" +); + +sub modify_penalty { + my($self, $conn, $auth, $penalty, $usr_msg) = @_; + + my $e = new_editor(authtoken=>$auth, xact => 1); + return $e->die_event unless $e->checkauth; + + my $user = $e->retrieve_actor_user($penalty->usr) or return $e->die_event; + return $e->die_event unless $e->allowed('UPDATE_USER', $user->home_ou); + + $usr_msg->editor($e->requestor->id); + $usr_msg->edit_date('now'); + + if ($usr_msg->isnew) { + $usr_msg = $e->create_actor_usr_message($usr_msg) + or return $e->die_event; + $penalty->usr_message($usr_msg->id); + } else { + $usr_msg = $e->update_actor_usr_message($usr_msg) + or return $e->die_event; + } + + if ($penalty->isnew) { + $penalty = $e->create_actor_user_standing_penalty($penalty) + or return $e->die_event; + } else { + $penalty = $e->update_actor_user_standing_penalty($penalty) + or return $e->die_event; + } + + $e->commit; + return 1; +} + +__PACKAGE__->register_method( method => "remove_penalty", api_name => "open-ils.actor.user.penalty.remove" ); @@ -3147,14 +3220,39 @@ sub update_penalty_note { my $e = new_editor(authtoken=>$auth, xact => 1); return $e->die_event unless $e->checkauth; for my $penalty_id (@$penalty_ids) { - my $penalty = $e->search_actor_user_standing_penalty( { id => $penalty_id } )->[0]; + my $penalty = $e->search_actor_user_standing_penalty([ + { id => $penalty_id }, + { flesh => 1, + flesh_fields => {aum => ['usr_message']} + } + ])->[0]; if (! $penalty ) { return $e->die_event; } my $user = $e->retrieve_actor_user($penalty->usr) or return $e->die_event; return $e->die_event unless $e->allowed('UPDATE_USER', $user->home_ou); - $penalty->note( $note ); $penalty->ischanged( 1 ); + my $aum = $penalty->usr_message(); + if (!$aum) { + $aum = Fieldmapper::actor::usr_message->new; + + $aum->create_date('now'); + $aum->sending_lib($e->requestor->ws_ou); + $aum->title(''); + $aum->usr($penalty->usr); + $aum->message($note); + $aum->pub(0); + $aum->isnew(1); - $e->update_actor_user_standing_penalty($penalty) or return $e->die_event; + $aum = $e->create_actor_usr_message($aum) + or return $e->die_event; + + $penalty->usr_message($aum->id); + $penalty->ischanged(1); + $e->update_actor_user_standing_penalty($penalty) or return $e->die_event; + } else { + $aum = $e->retrieve_actor_usr_message($aum) or return $e->die_event; + $aum->message($note); $aum->ischanged(1); + $e->update_actor_usr_message($aum) or return $e->die_event; + } } $e->commit; return 1; @@ -3224,6 +3322,12 @@ sub new_flesh_user { $fetch_penalties = 1; } + my $fetch_notes = 0; + if(grep {$_ eq 'notes'} @$fields) { + $fields = [grep {$_ ne 'notes'} @$fields]; + $fetch_notes = 1; + } + my $fetch_usr_act = 0; if(grep {$_ eq 'usr_activity'} @$fields) { $fields = [grep {$_ ne 'usr_activity'} @$fields]; @@ -3272,12 +3376,27 @@ sub new_flesh_user { org_unit => $U->get_org_full_path($e->requestor->ws_ou) }, { flesh => 1, - flesh_fields => {ausp => ['standing_penalty']} + flesh_fields => {ausp => ['standing_penalty','usr_message']} } ]) ); } + if($fetch_notes) { + # grab undeleted notes (now actor.usr_message_penalty) that have not hit their stop_date + $user->notes( + $e->search_actor_usr_message_penalty([ + { usr => $id, + deleted => 'f', + '-or' => [ + {stop_date => undef}, + {stop_date => {'>' => 'now'}} + ], + }, {} + ]) + ); + } + # retrieve the most recent usr_activity entry if ($fetch_usr_act) { diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm index b451cbd8ee..5b9a3c71ea 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm @@ -487,8 +487,8 @@ sub put_into_collections { $pen->usr($user_id); $pen->standing_penalty(30); # PATRON_IN_COLLECTIONS $pen->staff($e->requestor->id); - $pen->note($fee_note) if $fee_note; - $U->simplereq('open-ils.actor', 'open-ils.actor.user.penalty.apply', $auth, $pen); + my $msg = { 'pub' => 0, 'title' => 'PATRON_IN_COLLECTIONS', 'message' => $fee_note }; + $U->simplereq('open-ils.actor', 'open-ils.actor.user.penalty.apply', $auth, $pen, $msg); return OpenILS::Event->new('SUCCESS'); } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/actor.pm index a4047f794e..4db37c2b0f 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/actor.pm @@ -17,7 +17,7 @@ __PACKAGE__->columns( Essential => qw/usrname email first_given_name ident_type2 ident_value2 net_access_level alias photo_url create_date expire_date credit_forward_balance super_user usrgroup passwd card last_xact_id - standing barred profile prefix suffix alert_message + standing barred profile prefix suffix day_phone evening_phone other_phone mailing_address claims_never_checked_out_count last_update_time/ ); diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Event.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Event.pm index 4291eeb407..1c0286bd82 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Event.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Event.pm @@ -209,6 +209,7 @@ sub react { $usr_message->message( $message_template_output ); $usr_message->usr( $env->{usr_message}{usr}->id ); $usr_message->sending_lib( $env->{usr_message}{sending_lib}->id ); + $usr_message->pub('t'); if ($self->editor->xact_begin) { if ($self->editor->create_actor_usr_message( $usr_message )) { diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/ApplyPatronPenalty.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/ApplyPatronPenalty.pm index cbe4a089cd..808d3f182c 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/ApplyPatronPenalty.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/ApplyPatronPenalty.pm @@ -60,7 +60,22 @@ sub handler { $penalty->usr($user->id); $penalty->org_unit($context_org); $penalty->standing_penalty($ptype->id); - $penalty->note($self->run_TT($env)); + + my $aum = Fieldmapper::actor::usr_message->new; + $aum->create_date('now'); + $aum->sending_lib($context_org); + $aum->title(''); + $aum->usr($penalty->usr); + $aum->message($self->run_TT($env)); + $aum->pub(0); + + $aum = $e->create_actor_usr_message($aum); + unless($aum) { + $e->rollback; + return 0; + } + + $penalty->usr_message($aum->id); unless($e->create_actor_user_standing_penalty($penalty)) { $e->rollback; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm index f50a9ceb68..3449a7cf46 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -584,6 +584,7 @@ sub load_myopac_messages { title => $aum->title, message => $aum->message, create_date => $aum->create_date, + edit_date => $aum->edit_date, is_read => defined($aum->read_date) ? 1 : 0, library => $aum->sending_lib->name, }; @@ -2637,7 +2638,7 @@ sub load_myopac_main { my $offset = $self->cgi->param('offset') || 0; $self->ctx->{search_ou} = $self->_get_search_lib(); $self->ctx->{user}->notes( - $self->editor->search_actor_usr_note({ + $self->editor->search_actor_usr_message({ usr => $self->ctx->{user}->id, pub => 't' }) diff --git a/Open-ILS/src/perlmods/live_t/14-lp1499123_csp_ignore_proximity.t b/Open-ILS/src/perlmods/live_t/14-lp1499123_csp_ignore_proximity.t index 709fcb02e0..6201c035e9 100644 --- a/Open-ILS/src/perlmods/live_t/14-lp1499123_csp_ignore_proximity.t +++ b/Open-ILS/src/perlmods/live_t/14-lp1499123_csp_ignore_proximity.t @@ -61,7 +61,7 @@ sub apply_staff_chr_to_patron { $penalty->set_date('now'); $penalty->staff($staff->id()); $penalty->org_unit(1); # Consortium-wide. - $penalty->note('LP 1499123 csp.ignore_proximity test'); + #$penalty->note('LP 1499123 csp.ignore_proximity test'); my $r = $apputils->simplereq( 'open-ils.actor', 'open-ils.actor.user.penalty.apply', diff --git a/Open-ILS/src/perlmods/live_t/18-lp1592891_sip_standing_penalties.t b/Open-ILS/src/perlmods/live_t/18-lp1592891_sip_standing_penalties.t index ca8754eb19..72e96cf1c1 100644 --- a/Open-ILS/src/perlmods/live_t/18-lp1592891_sip_standing_penalties.t +++ b/Open-ILS/src/perlmods/live_t/18-lp1592891_sip_standing_penalties.t @@ -43,7 +43,7 @@ sub apply_penalty_to_patron { $penalty->set_date('now'); $penalty->staff($staff->id()); $penalty->org_unit(1); # Consortium-wide. - $penalty->note('LP 1592891 SIP standing penalties test'); + #$penalty->note('LP 1592891 SIP standing penalties test'); my $r = $apputils->simplereq( 'open-ils.actor', 'open-ils.actor.user.penalty.apply', diff --git a/Open-ILS/src/perlmods/live_t/30-lp1846354_actor_usr_message_penalty.t b/Open-ILS/src/perlmods/live_t/30-lp1846354_actor_usr_message_penalty.t new file mode 100644 index 0000000000..68e23da7c2 --- /dev/null +++ b/Open-ILS/src/perlmods/live_t/30-lp1846354_actor_usr_message_penalty.t @@ -0,0 +1,133 @@ +#!perl +use strict; use warnings; + +use Test::More tests => 12; +use Data::Dumper; + +diag("Test actor.usr_message_penalty feature."); + +use OpenILS::Utils::TestUtils; +use OpenILS::SIP::Patron; +my $script = OpenILS::Utils::TestUtils->new(); +our $apputils = 'OpenILS::Application::AppUtils'; + +use constant WORKSTATION_NAME => 'BR1-test-30-lp1846354_actor_usr_message_penalty.t'; +use constant WORKSTATION_LIB => 4; + +sub retrieve_user_by_barcode { + my $barcode = shift; + return $apputils->simplereq( + 'open-ils.actor', + 'open-ils.actor.user.fleshed.retrieve_by_barcode', + $script->authtoken, + $barcode + ); +} + +sub retrieve_user_messages { + my $patron = shift; + return $apputils->simplereq( + 'open-ils.pcrud', + 'open-ils.pcrud.search.aum.atomic', + $script->authtoken, + { 'usr' => $patron->id() } + ); +} + +sub apply_staff_chr_to_patron_with_msg { + my $patron = shift; + my $penalty = Fieldmapper::actor::user_standing_penalty->new(); + $penalty->standing_penalty(25); + $penalty->usr($patron->id()); + $penalty->set_date('now'); + $penalty->staff(1); # admin + $penalty->org_unit(1); # Consortium-wide. + my $msg = { + pub => 't', + title => 'lp1846354 test title', + message => 'lp1846354 test message' + }; + my $r = $apputils->simplereq( + 'open-ils.actor', + 'open-ils.actor.user.penalty.apply', + $script->authtoken, + $penalty, + $msg + ); + if (ref($r)) { + undef($penalty); + } else { + $penalty->id($r); + } + return $penalty; +} + +sub remove_staff_chr_from_patron { + my $penalty = shift; + return $apputils->simplereq( + 'open-ils.actor', + 'open-ils.actor.user.penalty.remove', + $script->authtoken, + $penalty + ); +} + +# In concerto, we need to register a workstation. +$script->authenticate({ + username => 'admin', + password => 'demo123', + type => 'staff', +}); +ok($script->authtoken, 'Initial Login'); + +SKIP: { + my $ws = $script->find_workstation(WORKSTATION_NAME, WORKSTATION_LIB); + skip 'Workstation exists', 1 if ($ws); + $ws = $script->register_workstation(WORKSTATION_NAME, WORKSTATION_LIB) unless ($ws); + ok(! ref $ws, 'Registered a new workstation'); +} + +$script->logout(); +$script->authenticate({ + username => 'admin', + password => 'demo123', + type => 'staff', + workstation => WORKSTATION_NAME +}); +ok($script->authtoken, 'Login with workstaion'); + +my $patron = retrieve_user_by_barcode("99999350419"); +isa_ok($patron, 'Fieldmapper::actor::user', 'Patron'); + +# Patron should have no penalties. +ok(! scalar(@{$patron->standing_penalties()}), 'Patron has no penalties'); + +# Patron should have no user messages +my $user_messages = retrieve_user_messages($patron); +ok(! scalar(@{$user_messages}), 'Patron has no user messages'); + +# Add the STAFF_CHR to the patron +my $penalty = apply_staff_chr_to_patron_with_msg($patron); +ok(ref $penalty, 'Added STAFF_CHR to patron'); + +# Patron should have one user message +$user_messages = retrieve_user_messages($patron); +ok(scalar(@{$user_messages} == 1), 'Patron has a user message'); + +# It should be public/patron-visible +ok(@{$user_messages}[0]->pub() eq 't', 'User message pub flag is true'); + +# It should be flagged as not deleted +ok(@{$user_messages}[0]->deleted() eq 'f', 'User message is not flagged deleted'); + +# We remove the STAFF_CHR from our test patron. +my $r = remove_staff_chr_from_patron($penalty); +ok( ! ref $r, 'STAFF_CHR removed from patron'); + +# It should be flagged as not deleted +$user_messages = retrieve_user_messages($patron); +ok(@{$user_messages}[0]->deleted() eq 'f', 'User message is not flagged deleted'); +# worth noting that the Remove Note action in the staff client will delete both +# the penalty and its user message + +$script->logout(); diff --git a/Open-ILS/src/sql/Pg/005.schema.actors.sql b/Open-ILS/src/sql/Pg/005.schema.actors.sql index b3b2b7a013..9e39cccf46 100644 --- a/Open-ILS/src/sql/Pg/005.schema.actors.sql +++ b/Open-ILS/src/sql/Pg/005.schema.actors.sql @@ -68,7 +68,6 @@ CREATE TABLE actor.usr ( claims_returned_count INT NOT NULL DEFAULT 0, credit_forward_balance NUMERIC(6,2) NOT NULL DEFAULT 0.00, last_xact_id TEXT NOT NULL DEFAULT 'none', - alert_message TEXT, create_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), expire_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT (now() + '3 years'::INTERVAL), claims_never_checked_out_count INT NOT NULL DEFAULT 0, @@ -192,18 +191,6 @@ CREATE TRIGGER user_ingest_name_keywords_tgr BEFORE INSERT OR UPDATE ON actor.usr FOR EACH ROW EXECUTE PROCEDURE actor.user_ingest_name_keywords(); -CREATE TABLE actor.usr_note ( - id BIGSERIAL PRIMARY KEY, - usr BIGINT NOT NULL REFERENCES actor.usr ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - creator BIGINT NOT NULL REFERENCES actor.usr ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - create_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - pub BOOL NOT NULL DEFAULT FALSE, - title TEXT NOT NULL, - value TEXT NOT NULL -); -CREATE INDEX actor_usr_note_usr_idx ON actor.usr_note (usr); -CREATE INDEX actor_usr_note_creator_idx ON actor.usr_note ( creator ); - CREATE TABLE actor.usr_setting ( id BIGSERIAL PRIMARY KEY, usr INT NOT NULL REFERENCES actor.usr ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, @@ -681,8 +668,7 @@ CREATE TABLE actor.usr_standing_penalty ( standing_penalty INT NOT NULL REFERENCES config.standing_penalty (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, staff INT REFERENCES actor.usr (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED, set_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - stop_date TIMESTAMP WITH TIME ZONE, - note TEXT + stop_date TIMESTAMP WITH TIME ZONE ); COMMENT ON TABLE actor.usr_standing_penalty IS $$ User standing penalties @@ -804,9 +790,15 @@ CREATE TABLE actor.usr_message ( create_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), deleted BOOL NOT NULL DEFAULT FALSE, read_date TIMESTAMP WITH TIME ZONE, - sending_lib INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED + sending_lib INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED, + pub BOOL NOT NULL DEFAULT FALSE, + stop_date TIMESTAMP WITH TIME ZONE, + editor BIGINT REFERENCES actor.usr (id), + edit_date TIMESTAMP WITH TIME ZONE + ); CREATE INDEX aum_usr ON actor.usr_message (usr); +ALTER TABLE actor.usr_standing_penalty ADD COLUMN usr_message BIGINT REFERENCES actor.usr_message(id); CREATE RULE protect_usr_message_delete AS ON DELETE TO actor.usr_message DO INSTEAD ( @@ -815,42 +807,11 @@ CREATE RULE protect_usr_message_delete AS WHERE OLD.id = actor.usr_message.id ); -CREATE FUNCTION actor.convert_usr_note_to_message () RETURNS TRIGGER AS $$ -DECLARE - sending_ou INTEGER; -BEGIN - IF NEW.pub THEN - IF TG_OP = 'UPDATE' THEN - IF OLD.pub = TRUE THEN - RETURN NEW; - END IF; - END IF; - - SELECT INTO sending_ou aw.owning_lib - FROM auditor.get_audit_info() agai - JOIN actor.workstation aw ON (aw.id = agai.eg_ws); - IF sending_ou IS NULL THEN - SELECT INTO sending_ou home_ou - FROM actor.usr - WHERE id = NEW.creator; - END IF; - INSERT INTO actor.usr_message (usr, title, message, sending_lib) - VALUES (NEW.usr, NEW.title, NEW.value, sending_ou); - END IF; - - RETURN NEW; -END; -$$ LANGUAGE PLPGSQL; - -CREATE TRIGGER convert_usr_note_to_message_tgr - AFTER INSERT OR UPDATE ON actor.usr_note - FOR EACH ROW EXECUTE PROCEDURE actor.convert_usr_note_to_message(); - -- limited view to ensure that a library user who somehow -- manages to figure out how to access pcrud cannot change -- the text of messages sent them CREATE VIEW actor.usr_message_limited -AS SELECT * FROM actor.usr_message; +AS SELECT * FROM actor.usr_message WHERE pub AND NOT deleted; CREATE FUNCTION actor.restrict_usr_message_limited () RETURNS TRIGGER AS $$ BEGIN @@ -869,6 +830,47 @@ CREATE TRIGGER restrict_usr_message_limited_tgr INSTEAD OF UPDATE OR INSERT OR DELETE ON actor.usr_message_limited FOR EACH ROW EXECUTE PROCEDURE actor.restrict_usr_message_limited(); +-- combined view of actor.usr_standing_penalty and actor.usr_message for populating +-- staff Notes (formerly Messages) interface + +CREATE VIEW actor.usr_message_penalty +AS SELECT + COALESCE(ausp.id::TEXT,'') || ':' || COALESCE(aum.id::TEXT,'') AS "id", + ausp.id AS "ausp_id", + aum.id AS "aum_id", + COALESCE(ausp.org_unit,aum.sending_lib) AS "org_unit", + ausp.org_unit AS "ausp_org_unit", + aum.sending_lib AS "aum_sending_lib", + COALESCE(ausp.usr,aum.usr) AS "usr", + ausp.usr as "ausp_usr", + aum.usr as "aum_usr", + ausp.standing_penalty AS "standing_penalty", + ausp.staff AS "staff", + LEAST(ausp.set_date,aum.create_date) AS "create_date", + ausp.set_date AS "ausp_set_date", + aum.create_date AS "aum_create_date", + LEAST(ausp.stop_date,aum.stop_date) AS "stop_date", + ausp.stop_date AS "ausp_stop_date", + aum.stop_date AS "aum_stop_date", + ausp.usr_message AS "ausp_usr_message", + aum.title AS "title", + aum.message AS "message", + aum.deleted AS "deleted", + aum.read_date AS "read_date", + aum.pub AS "pub", + aum.editor AS "editor", + aum.edit_date AS "edit_date" +FROM + actor.usr_standing_penalty ausp +FULL OUTER JOIN + actor.usr_message aum +ON ( + ausp.usr_message = aum.id +) +WHERE + NOT (ausp.id IS NULL AND aum.deleted); +; + CREATE TABLE actor.passwd_type ( code TEXT PRIMARY KEY, name TEXT UNIQUE NOT NULL, diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index 3f5bf12c00..7f39bb3988 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -1656,8 +1656,6 @@ INSERT INTO permission.perm_list ( id, code, description ) VALUES 'VIEW_MERGE_PROFILE', 'ppl', 'description' )), ( 479, 'VIEW_SERIAL_SUBSCRIPTION', oils_i18n_gettext( 479, 'VIEW_SERIAL_SUBSCRIPTION', 'ppl', 'description' )), - ( 480, 'VIEW_STANDING_PENALTY', oils_i18n_gettext( 480, - 'VIEW_STANDING_PENALTY', 'ppl', 'description' )), ( 481, 'ADMIN_SERIAL_CAPTION_PATTERN', oils_i18n_gettext( 481, 'ADMIN_SERIAL_CAPTION_PATTERN', 'ppl', 'description' )), ( 482, 'ADMIN_SERIAL_DISTRIBUTION', oils_i18n_gettext( 482, @@ -2399,7 +2397,6 @@ INSERT INTO permission.grp_perm_map (grp, perm, depth, grantable) 'VIEW_BOOKING_RESERVATION', 'VIEW_BOOKING_RESERVATION_ATTR_MAP', 'VIEW_GROUP_PENALTY_THRESHOLD', - 'VIEW_STANDING_PENALTY', 'VOID_BILLING', 'VOLUME_HOLDS'); @@ -2565,7 +2562,6 @@ INSERT INTO permission.grp_perm_map (grp, perm, depth, grantable) 'VIEW_BOOKING_RESERVATION', 'VIEW_BOOKING_RESERVATION_ATTR_MAP', 'VIEW_REPORT_OUTPUT', - 'VIEW_STANDING_PENALTY', 'VOID_BILLING', 'TRANSIT_CHECKIN_INTERVAL_BLOCK.override', 'VOLUME_HOLDS', @@ -4848,24 +4844,6 @@ INSERT into config.org_unit_setting_type 'coust', 'description'), 'bool', null) -,( 'ui.patron.edit.au.alert_message.show', 'gui', - oils_i18n_gettext('ui.patron.edit.au.alert_message.show', - 'Show alert_message field on patron registration', - 'coust', 'label'), - oils_i18n_gettext('ui.patron.edit.au.alert_message.show', - 'The alert_message field will be shown on the patron registration screen. Showing a field makes it appear with required fields even when not required. If the field is required this setting is ignored.', - 'coust', 'description'), - 'bool', null) - -,( 'ui.patron.edit.au.alert_message.suggest', 'gui', - oils_i18n_gettext('ui.patron.edit.au.alert_message.suggest', - 'Suggest alert_message field on patron registration', - 'coust', 'label'), - oils_i18n_gettext('ui.patron.edit.au.alert_message.suggest', - 'The alert_message field will be suggested on the patron registration screen. Suggesting a field makes it appear when suggested fields are shown. If the field is shown or required this setting is ignored.', - 'coust', 'description'), - 'bool', null) - ,( 'ui.patron.edit.au.alias.show', 'gui', oils_i18n_gettext('ui.patron.edit.au.alias.show', 'Show alias field on patron registration', @@ -5417,22 +5395,12 @@ INSERT into config.org_unit_setting_type ,( 'ui.staff.require_initials.patron_standing_penalty', 'gui', oils_i18n_gettext('ui.staff.require_initials.patron_standing_penalty', - 'Require staff initials for entry/edit of patron standing penalties and messages.', + 'Require staff initials for entry/edit of patron standing penalties and notes.', 'coust', 'label'), oils_i18n_gettext('ui.staff.require_initials.patron_standing_penalty', - 'Appends staff initials and edit date into patron standing penalties and messages.', - 'coust', 'description'), - 'bool', null) - -,( 'ui.staff.require_initials.patron_info_notes', 'gui', - oils_i18n_gettext('ui.staff.require_initials.patron_info_notes', - 'Require staff initials for entry/edit of patron notes.', - 'coust', 'label'), - oils_i18n_gettext('ui.staff.require_initials.patron_info_notes', - 'Appends staff initials and edit date into patron note content.', + 'Require staff initials for entry/edit of patron standing penalties and notes.', 'coust', 'description'), 'bool', null) - ,( 'ui.staff.require_initials.copy_notes', 'gui', oils_i18n_gettext('ui.staff.require_initials.copy_notes', 'Require staff initials for entry/edit of copy notes.', diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.note_and_message_consolidation b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.note_and_message_consolidation new file mode 100644 index 0000000000..5da0cac0e5 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.note_and_message_consolidation @@ -0,0 +1,486 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + +ALTER TABLE actor.usr_message ADD COLUMN pub BOOL NOT NULL DEFAULT FALSE; +ALTER TABLE actor.usr_message ADD COLUMN stop_date TIMESTAMP WITH TIME ZONE; +ALTER TABLE actor.usr_message ADD COLUMN editor BIGINT REFERENCES actor.usr (id); +ALTER TABLE actor.usr_message ADD COLUMN edit_date TIMESTAMP WITH TIME ZONE; + +DROP VIEW actor.usr_message_limited; +CREATE VIEW actor.usr_message_limited +AS SELECT * FROM actor.usr_message WHERE pub AND NOT deleted; + +ALTER TABLE actor.usr_standing_penalty ADD COLUMN usr_message BIGINT REFERENCES actor.usr_message(id); + +-- alright, let's set all existing user messages to public + +UPDATE actor.usr_message SET pub = TRUE; + +-- alright, let's migrate penalty notes to usr_messages and link the messages back to the penalties: + +CREATE TABLE actor.XXXX_penalty_notes AS + SELECT id, usr, org_unit, set_date, note + FROM actor.usr_standing_penalty + WHERE NULLIF(BTRIM(note),'') IS NOT NULL; + +-- here is our staging table which will be shaped exactly like +-- actor.usr_message and use the same id sequence +CREATE TABLE actor.XXXX_usr_message_for_penalty_notes ( + LIKE actor.usr_message INCLUDING DEFAULTS EXCLUDING CONSTRAINTS +); + +INSERT INTO actor.XXXX_usr_message_for_penalty_notes ( + usr, + title, + message, + create_date, + sending_lib, + pub +) SELECT + usr, + 'Penalty Note ID ' || id, + note, + set_date, + org_unit, + FALSE +FROM + actor.XXXX_penalty_notes +; + +-- so far so good, let's push this into production + +INSERT INTO actor.usr_message + SELECT * FROM actor.XXXX_usr_message_for_penalty_notes; + +-- and link the production penalties to these new user messages + +UPDATE actor.usr_standing_penalty p SET usr_message = m.id + FROM actor.XXXX_usr_message_for_penalty_notes m + WHERE m.title = 'Penalty Note ID ' || p.id; + +-- and remove the temporary overloading of the message title we used for this: + +UPDATE + actor.usr_message +SET + title = 'Penalty Note' +WHERE + id IN (SELECT id FROM actor.XXXX_usr_message_for_penalty_notes) +; + +-- probably redundant here, but the spec calls for an assertion before removing +-- the note column from actor.usr_standing_penalty, so being extra cautious: + +do $$ begin + assert ( + select count(*) + from actor.XXXX_usr_message_for_penalty_notes + where id not in ( + select id from actor.usr_message + ) + ) = 0, 'failed migrating to actor.usr_message'; +end; $$; + +ALTER TABLE actor.usr_standing_penalty DROP COLUMN note; + +-- combined view of actor.usr_standing_penalty and actor.usr_message for populating +-- staff Notes (formerly Messages) interface + +CREATE VIEW actor.usr_message_penalty +AS SELECT + COALESCE(ausp.id::TEXT,'') || ':' || COALESCE(aum.id::TEXT,'') AS "id", + ausp.id AS "ausp_id", + aum.id AS "aum_id", + COALESCE(ausp.org_unit,aum.sending_lib) AS "org_unit", + ausp.org_unit AS "ausp_org_unit", + aum.sending_lib AS "aum_sending_lib", + COALESCE(ausp.usr,aum.usr) AS "usr", + ausp.usr as "ausp_usr", + aum.usr as "aum_usr", + ausp.standing_penalty AS "standing_penalty", + ausp.staff AS "staff", + LEAST(ausp.set_date,aum.create_date) AS "create_date", + ausp.set_date AS "ausp_set_date", + aum.create_date AS "aum_create_date", + LEAST(ausp.stop_date,aum.stop_date) AS "stop_date", + ausp.stop_date AS "ausp_stop_date", + aum.stop_date AS "aum_stop_date", + ausp.usr_message AS "ausp_usr_message", + aum.title AS "title", + aum.message AS "message", + aum.deleted AS "deleted", + aum.read_date AS "read_date", + aum.pub AS "pub", + aum.editor AS "editor", + aum.edit_date AS "edit_date" +FROM + actor.usr_standing_penalty ausp +FULL OUTER JOIN + actor.usr_message aum +ON ( + ausp.usr_message = aum.id +) +WHERE + NOT (ausp.id IS NULL AND aum.deleted); +; + +-- fun part where we migrate the following alert messages: + +CREATE TABLE actor.XXXX_note_and_message_consolidation AS + SELECT id, home_ou, alert_message + FROM actor.usr + WHERE NOT deleted AND NULLIF(BTRIM(alert_message),'') IS NOT NULL; + +-- here is our staging table which will be shaped exactly like +-- actor.usr_message and use the same id sequence +CREATE TABLE actor.XXXX_usr_message ( + LIKE actor.usr_message INCLUDING DEFAULTS EXCLUDING CONSTRAINTS +); + +INSERT INTO actor.XXXX_usr_message ( + usr, + title, + message, + create_date, + sending_lib, + pub +) SELECT + id, + 'converted Alert Message, real date unknown', + alert_message, + NOW(), -- best we can do + 1, -- it's this or home_ou + FALSE +FROM + actor.XXXX_note_and_message_consolidation +; + +-- another staging table, but for actor.usr_standing_penalty +CREATE TABLE actor.XXXX_usr_standing_penalty ( + LIKE actor.usr_standing_penalty INCLUDING DEFAULTS EXCLUDING CONSTRAINTS +); + +INSERT INTO actor.XXXX_usr_standing_penalty ( + org_unit, + usr, + standing_penalty, + staff, + set_date, + usr_message +) SELECT + sending_lib, + usr, + 20, -- ALERT_NOTE + 1, -- admin user, usually; best we can do + create_date, + id +FROM + actor.XXXX_usr_message +; + +-- so far so good, let's push these into production + +INSERT INTO actor.usr_message + SELECT * FROM actor.XXXX_usr_message; +INSERT INTO actor.usr_standing_penalty + SELECT * FROM actor.XXXX_usr_standing_penalty; + +-- probably redundant here, but the spec calls for an assertion before removing +-- the alert message column from actor.usr, so being extra cautious: + +do $$ begin + assert ( + select count(*) + from actor.XXXX_usr_message + where id not in ( + select id from actor.usr_message + ) + ) = 0, 'failed migrating to actor.usr_message'; +end; $$; + +do $$ begin + assert ( + select count(*) + from actor.XXXX_usr_standing_penalty + where id not in ( + select id from actor.usr_standing_penalty + ) + ) = 0, 'failed migrating to actor.usr_standing_penalty'; +end; $$; + +-- WARNING: we're going to lose the history of alert_message +ALTER TABLE actor.usr DROP COLUMN alert_message CASCADE; +SELECT auditor.update_auditors(); + +-- fun part where we migrate actor.usr_notes as penalties to preserve +-- their creator, and then the private ones to private user messages. +-- For public notes, we try to link to existing user messages if we +-- can, but if we can't, we'll create new, but archived, user messages +-- for the note contents. + +CREATE TABLE actor.XXXX_usr_message_for_private_notes ( + LIKE actor.usr_message INCLUDING DEFAULTS EXCLUDING CONSTRAINTS +); + +INSERT INTO actor.XXXX_usr_message_for_private_notes ( + usr, + title, + message, + create_date, + sending_lib, + pub +) SELECT + usr, + title, + value, + create_date, + (select home_ou from actor.usr where id = creator), -- best we can do + FALSE +FROM + actor.usr_note +WHERE + NOT pub +; + +CREATE TABLE actor.XXXX_usr_message_for_unmatched_public_notes ( + LIKE actor.usr_message INCLUDING DEFAULTS EXCLUDING CONSTRAINTS +); + +INSERT INTO actor.XXXX_usr_message_for_unmatched_public_notes ( + usr, + title, + message, + create_date, + stop_date, + sending_lib, + pub +) SELECT + usr, + title, + value, + create_date, + NOW(), -- we want these "archived" since the patron probably already saw a corresponding usr_message + (select home_ou from actor.usr where id = creator), -- best we can do + FALSE +FROM + actor.usr_note n +WHERE + pub AND NOT EXISTS (SELECT 1 FROM actor.usr_message m WHERE n.usr = m.usr AND n.create_date = m.create_date) +; + +-- now, in order to preserve the creator from usr_note, we want to create standing SILENT_NOTE penalties for +-- 1) actor.XXXX_usr_message_for_private_notes and associated usr_note entries +-- 2) actor.XXXX_usr_message_for_unmatched_public_notes and associated usr_note entries, but archive these +-- 3) usr_note and usr_message entries that can be matched + +CREATE TABLE actor.XXXX_usr_standing_penalties_for_notes ( + LIKE actor.usr_standing_penalty INCLUDING DEFAULTS EXCLUDING CONSTRAINTS +); + +-- 1) actor.XXXX_usr_message_for_private_notes and associated usr_note entries +INSERT INTO actor.XXXX_usr_standing_penalties_for_notes ( + org_unit, + usr, + standing_penalty, + staff, + set_date, + stop_date, + usr_message +) SELECT + m.sending_lib, + m.usr, + 21, -- SILENT_NOTE + n.creator, + m.create_date, + m.stop_date, + m.id +FROM + actor.usr_note n, + actor.XXXX_usr_message_for_private_notes m +WHERE + n.usr = m.usr AND n.create_date = m.create_date AND NOT n.pub AND NOT m.pub +; + +-- 2) actor.XXXX_usr_message_for_unmatched_public_notes and associated usr_note entries, but archive these +INSERT INTO actor.XXXX_usr_standing_penalties_for_notes ( + org_unit, + usr, + standing_penalty, + staff, + set_date, + stop_date, + usr_message +) SELECT + m.sending_lib, + m.usr, + 21, -- SILENT_NOTE + n.creator, + m.create_date, + m.stop_date, + m.id +FROM + actor.usr_note n, + actor.XXXX_usr_message_for_unmatched_public_notes m +WHERE + n.usr = m.usr AND n.create_date = m.create_date AND n.pub AND m.pub +; + +-- 3) usr_note and usr_message entries that can be matched +INSERT INTO actor.XXXX_usr_standing_penalties_for_notes ( + org_unit, + usr, + standing_penalty, + staff, + set_date, + stop_date, + usr_message +) SELECT + m.sending_lib, + m.usr, + 21, -- SILENT_NOTE + n.creator, + m.create_date, + m.stop_date, + m.id +FROM + actor.usr_note n, + actor.usr_message m +WHERE + n.usr = m.usr AND n.create_date = m.create_date AND m.id NOT IN ( + SELECT id FROM actor.XXXX_usr_message_for_private_notes + UNION + SELECT id FROM actor.XXXX_usr_message_for_unmatched_public_notes + ) +; + +-- so far so good, let's push these into production + +INSERT INTO actor.usr_message + SELECT * FROM actor.XXXX_usr_message_for_private_notes + UNION SELECT * FROM actor.XXXX_usr_message_for_unmatched_public_notes; +INSERT INTO actor.usr_standing_penalty + SELECT * FROM actor.XXXX_usr_standing_penalties_for_notes; + +-- probably redundant here, but the spec calls for an assertion before dropping +-- the actor.usr_note table, so being extra cautious: + +do $$ begin + assert ( + select count(*) + from actor.XXXX_usr_message_for_private_notes + where id not in ( + select id from actor.usr_message + ) + ) = 0, 'failed migrating to actor.usr_message'; +end; $$; + +DROP TABLE actor.usr_note; + +-- preserve would-be collisions for migrating +-- ui.staff.require_initials.patron_info_notes +-- to ui.staff.require_initials.patron_standing_penalty + +\o ui.staff.require_initials.patron_info_notes.collisions.txt +SELECT a.* +FROM actor.org_unit_setting a +WHERE + a.name = 'ui.staff.require_initials.patron_info_notes' + -- hits on org_unit + AND a.org_unit IN ( + SELECT b.org_unit + FROM actor.org_unit_setting b + WHERE b.name = 'ui.staff.require_initials.patron_standing_penalty' + ) + -- but doesn't hit on org_unit + value + AND CONCAT_WS('|',a.org_unit::TEXT,a.value::TEXT) NOT IN ( + SELECT CONCAT_WS('|',b.org_unit::TEXT,b.value::TEXT) + FROM actor.org_unit_setting b + WHERE b.name = 'ui.staff.require_initials.patron_standing_penalty' + ); +\o + +-- and preserve the _log data + +\o ui.staff.require_initials.patron_info_notes.log_data.txt +SELECT * +FROM config.org_unit_setting_type_log +WHERE field_name = 'ui.staff.require_initials.patron_info_notes'; +\o + +-- migrate the non-collisions + +INSERT INTO actor.org_unit_setting (org_unit, name, value) +SELECT a.org_unit, 'ui.staff.require_initials.patron_standing_penalty', a.value +FROM actor.org_unit_setting a +WHERE + a.name = 'ui.staff.require_initials.patron_info_notes' + AND a.org_unit NOT IN ( + SELECT b.org_unit + FROM actor.org_unit_setting b + WHERE b.name = 'ui.staff.require_initials.patron_standing_penalty' + ) +; + +-- and now delete the old patron_info_notes settings + +DELETE FROM actor.org_unit_setting + WHERE name = 'ui.staff.require_initials.patron_info_notes'; +DELETE FROM config.org_unit_setting_type_log + WHERE field_name = 'ui.staff.require_initials.patron_info_notes'; +DELETE FROM config.org_unit_setting_type + WHERE name = 'ui.staff.require_initials.patron_info_notes'; + +-- relabel the org unit setting type + +UPDATE config.org_unit_setting_type +SET + label = oils_i18n_gettext('ui.staff.require_initials.patron_standing_penalty', + 'Require staff initials for entry/edit of patron standing penalties and notes.', + 'coust', 'label'), + description = oils_i18n_gettext('ui.staff.require_initials.patron_standing_penalty', + 'Require staff initials for entry/edit of patron standing penalties and notes.', + 'coust', 'description') +WHERE + name = 'ui.staff.require_initials.patron_standing_penalty' +; + +-- preserve _log data for some different settings on their way out + +\o ui.patron.edit.au.alert_message.show_suggest.log_data.txt +SELECT * +FROM config.org_unit_setting_type_log +WHERE field_name IN ( + 'ui.patron.edit.au.alert_message.show', + 'ui.patron.edit.au.alert_message.suggest' +); +\o + +-- remove patron editor alert message settings + +DELETE FROM actor.org_unit_setting + WHERE name = 'ui.patron.edit.au.alert_message.show'; +DELETE FROM config.org_unit_setting_type_log + WHERE field_name = 'ui.patron.edit.au.alert_message.show'; +DELETE FROM config.org_unit_setting_type + WHERE name = 'ui.patron.edit.au.alert_message.show'; + +DELETE FROM actor.org_unit_setting + WHERE name = 'ui.patron.edit.au.alert_message.suggest'; +DELETE FROM config.org_unit_setting_type_log + WHERE field_name = 'ui.patron.edit.au.alert_message.suggest'; +DELETE FROM config.org_unit_setting_type + WHERE name = 'ui.patron.edit.au.alert_message.suggest'; + +-- comment these out if you want the staging tables to stick around +DROP TABLE actor.XXXX_note_and_message_consolidation; +DROP TABLE actor.XXXX_penalty_notes; +DROP TABLE actor.XXXX_usr_message_for_penalty_notes; +DROP TABLE actor.XXXX_usr_message; +DROP TABLE actor.XXXX_usr_standing_penalty; +DROP TABLE actor.XXXX_usr_message_for_private_notes; +DROP TABLE actor.XXXX_usr_message_for_unmatched_public_notes; +DROP TABLE actor.XXXX_usr_standing_penalties_for_notes; + +COMMIT; + diff --git a/Open-ILS/src/templates/actor/user/register_table.tt2 b/Open-ILS/src/templates/actor/user/register_table.tt2 index 5ad5dfd785..27c0c6539a 100644 --- a/Open-ILS/src/templates/actor/user/register_table.tt2 +++ b/Open-ILS/src/templates/actor/user/register_table.tt2 @@ -61,7 +61,6 @@ - diff --git a/Open-ILS/src/templates/opac/myopac/messages/list.tt2 b/Open-ILS/src/templates/opac/myopac/messages/list.tt2 index 7702c1e150..ed9d9d05a3 100644 --- a/Open-ILS/src/templates/opac/myopac/messages/list.tt2 +++ b/Open-ILS/src/templates/opac/myopac/messages/list.tt2 @@ -100,7 +100,11 @@ + [% IF message.edit_date %] + [% date.format(ctx.parse_datetime(message.edit_date), DATE_FORMAT); %] + [% ELSE %] [% date.format(ctx.parse_datetime(message.create_date), DATE_FORMAT); %] + [% END %] [% message.library | html %] [% message.title | html %] diff --git a/Open-ILS/src/templates/opac/myopac/messages/single_message.tt2 b/Open-ILS/src/templates/opac/myopac/messages/single_message.tt2 index 2e49ddb661..ff8303996a 100644 --- a/Open-ILS/src/templates/opac/myopac/messages/single_message.tt2 +++ b/Open-ILS/src/templates/opac/myopac/messages/single_message.tt2 @@ -30,6 +30,13 @@ class='color_4 light_border'>[% l("Date") %] [% date.format(ctx.parse_datetime(ctx.patron_messages.0.create_date), DATE_FORMAT); %] + [% IF ctx.patron_messages.0.edit_date %] + + [% l("Edit Date") %] + [% date.format(ctx.parse_datetime(ctx.patron_messages.0.edit_date), DATE_FORMAT); %] + + [% END %] [% l("Library") %] diff --git a/Open-ILS/src/templates/staff/circ/patron/index.tt2 b/Open-ILS/src/templates/staff/circ/patron/index.tt2 index b5b92f42ec..b6a72bd8d4 100644 --- a/Open-ILS/src/templates/staff/circ/patron/index.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/index.tt2 @@ -76,7 +76,7 @@ angular.module('egCoreMod').run(['egStrings', function(s) { s.PAGE_TITLE_PATRON_SEARCH = "[% l('Patron Search') %]"; s.PAGE_TITLE_PATRON_NAME = "[% l('[_1], [_2] [_3]', '{{lname}}','{{fname}}','{{mname}}') %]"; s.PAGE_TITLE_PATRON_CHECKOUT = "[% l('Checkout') %]"; - s.PAGE_TITLE_PATRON_MESSAGES = "[% l('Messages') %]"; + s.PAGE_TITLE_PATRON_MESSAGES = "[% l('Notes') %]"; /* TODO: The "Other" page title could be smarter.. */ s.PAGE_TITLE_PATRON_OTHER = "[% l('Other') %]"; s.PAGE_TITLE_PATRON_BILLS = "[% l('Bills') %]"; @@ -116,7 +116,6 @@ angular.module('egCoreMod').run(['egStrings', function(s) { -

Notes  {{patron().notes().length}}

  • - [% l('Messages') %] + [% l('Notes') %] + + ({{visible_notes().length}}) + +
  • [% l('Edit') %] @@ -177,12 +180,7 @@ angular.module('egCoreMod').run(['egStrings', function(s) {
  • - -
    -
    -
    -
    -
    [% l('Alert Message') %]
    -
    -
    - {{patron().alert_message()}} -
    -
    -
    -
    -
    -
    [% l('Penalties') %]
    +
    [% l('Alerts') %]
    - {{penalty.standing_penalty().label()}} -
    {{penalty.note()}}
    + title="{{penalty.standing_penalty().name()}} (id {{penalty.id()}})"> + {{penalty.usr_message().title() || penalty.standing_penalty().label()}} +
    {{penalty.usr_message().message()}}
    +
     
    {{penalty.set_date() | date:$root.egDateFormat}} diff --git a/Open-ILS/src/templates/staff/circ/patron/t_edit.tt2 b/Open-ILS/src/templates/staff/circ/patron/t_edit.tt2 index 4b4925d9ec..e9a166bb71 100644 --- a/Open-ILS/src/templates/staff/circ/patron/t_edit.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/t_edit.tt2 @@ -704,25 +704,6 @@ within the "form" by name for validation.
    - - -
    - [% draw_field_label('au', 'alert_message') %] -
    - -
    -
    - [% draw_example_text('au', 'alert_message') %] -
    -
    -
    -
    -
    - {{patron().alert_message()}} -
    -
    [% l('Patron account will expire soon. Please renew.') %]
    @@ -28,7 +20,7 @@
    + ng-class="{'patron-summary-divider' : alert_penalties().length}">
    [% l('Profile') %]
    {{patron().profile().name()}}
    diff --git a/Open-ILS/src/templates/staff/circ/share/t_new_message_dialog.tt2 b/Open-ILS/src/templates/staff/circ/share/t_new_message_dialog.tt2 index d588f8bf4c..0637a63c83 100644 --- a/Open-ILS/src/templates/staff/circ/share/t_new_message_dialog.tt2 +++ b/Open-ILS/src/templates/staff/circ/share/t_new_message_dialog.tt2 @@ -1,39 +1,93 @@ -
    +