From: erickson Date: Fri, 11 Dec 2009 17:20:56 +0000 (+0000) Subject: added support for alerting and optionally preventing users when they attempt to place... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=49c7ab515f6d27f6e20db57b1336b6e2f8f49bd7;p=evergreen%2Fmasslnc.git added support for alerting and optionally preventing users when they attempt to place a hold on an item that is already checked out to them. give the override perm to everyone by default for backwards compat git-svn-id: svn://svn.open-ils.org/ILS/trunk@15143 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm index 92ba6e5278..e60b024e66 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm @@ -111,6 +111,9 @@ sub create_hold { my $existing = $e->search_action_hold_request($sargs); push( @events, OpenILS::Event->new('HOLD_EXISTS')) if @$existing; + my $checked_out = hold_item_is_checked_out($e, $recipient->id, $hold->hold_type, $hold->target); + push( @events, OpenILS::Event->new('HOLD_ITEM_CHECKED_OUT')) if $checked_out; + if( $t eq OILS_HOLD_TYPE_METARECORD ) { $pevt = $e->event unless $e->allowed('MR_HOLDS', $porg); } @@ -2238,4 +2241,82 @@ sub hold_has_copy_at { } +# returns true if the user already has an item checked out +# that could be used to fulfill the requested hold. +sub hold_item_is_checked_out { + my($e, $user_id, $hold_type, $hold_target) = @_; + + my $query = { + select => {acp => ['id']}, + from => {acp => {}}, + where => { + '+acp' => { + id => { + in => { # copies for circs the user has checked out + select => {circ => ['target_copy']}, + from => 'circ', + where => { + usr => $user_id, + checkin_time => undef, + '-or' => [ + {stop_fines => ["MAXFINES","LONGOVERDUE"]}, + {stop_fines => undef} + ], + } + } + } + } + }, + limit => 1 + }; + + if($hold_type eq 'C') { + + $query->{where}->{'+acp'}->{id} = $hold_target; + + } elsif($hold_type eq 'V') { + + $query->{where}->{'+acp'}->{call_number} = $hold_target; + + } elsif($hold_type eq 'T') { + + $query->{from}->{acp}->{acn} = { + field => 'id', + fkey => 'call_number', + 'join' => { + bre => { + field => 'id', + filter => {id => $hold_target}, + fkey => 'record' + } + } + }; + + } else { + + $query->{from}->{acp}->{acn} = { + field => 'id', + fkey => 'call_number', + join => { + bre => { + field => 'id', + fkey => 'record', + join => { + mmrsm => { + field => 'source', + fkey => 'id', + filter => {metarecord => $hold_target}, + } + } + } + } + }; + } + + return $e->json_query($query)->[0]; +} + + + + 1; diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index ff444f33f6..58f0e08c36 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -51,7 +51,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0113'); -- berick +INSERT INTO config.upgrade_log (version) VALUES ('0114'); -- berick CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, 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 1de57c6593..64a2e25d43 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -1248,6 +1248,7 @@ INSERT INTO permission.perm_list VALUES (356, 'ADMIN_BOOKING_RESOURCE_ATTR_VALUE', oils_i18n_gettext(356, 'Enables the user to create/update/delete booking resource attribute values', 'ppl', 'description')), (357, 'ADMIN_BOOKING_RESERVATION', oils_i18n_gettext(357, 'Enables the user to create/update/delete booking reservations', 'ppl', 'description')), (358, 'ADMIN_BOOKING_RESERVATION_ATTR_VALUE_MAP', oils_i18n_gettext(358, 'Enables the user to create/update/delete booking reservation attribute value maps', 'ppl', 'description')) + (359, 'HOLD_ITEM_CHECKED_OUT.override', oils_i18n_gettext(359, 'Allows a user to place a hold on an item that they already have checked out', 'ppl', 'description')) ; ; @@ -1433,6 +1434,8 @@ INSERT INTO permission.grp_perm_map (grp, perm, depth, grantable) VALUES (7, (SE INSERT INTO permission.grp_perm_map (grp, perm, depth, grantable) VALUES (7, (SELECT id FROM permission.perm_list WHERE code = 'ADMIN_FUND'), 1, false); INSERT INTO permission.grp_perm_map (grp, perm, depth, grantable) VALUES (7, (SELECT id FROM permission.perm_list WHERE code = 'ADMIN_CURRENCY_TYPE'), 1, false); +INSERT INTO permission.grp_perm_map (grp, perm, depth, grantable) VALUES (1, (SELECT id FROM permission.perm_list WHERE code = 'HOLD_ITEM_CHECKED_OUT.override'), 0, false); + -- Admin user account INSERT INTO actor.usr ( profile, card, usrname, passwd, first_given_name, family_name, dob, master_account, super_user, ident_type, ident_value, home_ou ) VALUES ( 1, 1, 'admin', 'open-ils', 'Administrator', 'System Account', '1979-01-22', TRUE, TRUE, 1, 'identification', 1 ); diff --git a/Open-ILS/src/sql/Pg/upgrade/0114.data.hold_item_checked_out_perm.sql b/Open-ILS/src/sql/Pg/upgrade/0114.data.hold_item_checked_out_perm.sql new file mode 100644 index 0000000000..a97dff7cdb --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0114.data.hold_item_checked_out_perm.sql @@ -0,0 +1,11 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0114'); + +INSERT INTO permission.perm_list (id, code, description) VALUES + (359, 'HOLD_ITEM_CHECKED_OUT.override', oils_i18n_gettext(359, 'Allows a user to place a hold on an item that they already have checked out', 'ppl', 'description')); + +-- for backwards compat, give everyone the permission +INSERT INTO permission.grp_perm_map (grp, perm, depth, grantable) VALUES (1, (SELECT id FROM permission.perm_list WHERE code = 'HOLD_ITEM_CHECKED_OUT.override'), 0, false); + +COMMIT; diff --git a/Open-ILS/web/opac/locale/en-US/opac.dtd b/Open-ILS/web/opac/locale/en-US/opac.dtd index 0c17233e1a..97f5284e7b 100644 --- a/Open-ILS/web/opac/locale/en-US/opac.dtd +++ b/Open-ILS/web/opac/locale/en-US/opac.dtd @@ -590,9 +590,10 @@ We recommend that you remove this title from any bookbags it may have been added + + - + &common.hold.delivery; &common.hold.exists; + &common.hold.checked_out; &common.hold.exists.override; + &common.hold.checked_out.override; &common.hold.barred;