From a2006a565ec4dea62a46a8abe90fd9e17382cae8 Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 9 Apr 2007 19:41:45 +0000 Subject: [PATCH] added collision detection to the user editor code to prevent overwiting changes git-svn-id: svn://svn.open-ils.org/ILS/trunk@7133 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../xul/staff_client/server/patron/ue.js | 8 ++++- .../xul/staff_client/server/patron/ue.xhtml | 9 +++++ Open-ILS/src/extras/ils_events.xml | 4 +++ .../src/perlmods/OpenILS/Application/Actor.pm | 35 ++++++++++--------- 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/Evergreen/xul/staff_client/server/patron/ue.js b/Evergreen/xul/staff_client/server/patron/ue.js index fc95175185..ddc7f6a1f2 100644 --- a/Evergreen/xul/staff_client/server/patron/ue.js +++ b/Evergreen/xul/staff_client/server/patron/ue.js @@ -524,7 +524,13 @@ function uEditSaveUser(cloneme) { var evt; if( (evt = checkILSEvent(newuser)) || ! newuser ) { if(evt) { - var j = js2JSON(newuser); + evt = newuser; + if( evt.textcode == 'XACT_COLLISION' ) { + if( confirmId('ue_xact_collision') ) + location.href = location.href; + return; + } + var j = js2JSON(evt); alert(j); _debug("USER UPDATE FAILED:\n" + j); } diff --git a/Evergreen/xul/staff_client/server/patron/ue.xhtml b/Evergreen/xul/staff_client/server/patron/ue.xhtml index a0ead4cd3b..bdbefc0d60 100644 --- a/Evergreen/xul/staff_client/server/patron/ue.xhtml +++ b/Evergreen/xul/staff_client/server/patron/ue.xhtml @@ -1007,6 +1007,15 @@ You have unsaved changes. + + It appears that someone else was also editing this user. Saving the user + now will destroy their changes. Click "OK" to refresh the user and continue + editing. Click "Cancel" to do nothing. + + Note that you will not be able to save the user until this page has been refreshed. + + + diff --git a/Open-ILS/src/extras/ils_events.xml b/Open-ILS/src/extras/ils_events.xml index 46fc303bd7..a19fa223b2 100644 --- a/Open-ILS/src/extras/ils_events.xml +++ b/Open-ILS/src/extras/ils_events.xml @@ -146,6 +146,10 @@ The requested volume is marked as deleted + + The saved item has been edited by another user + + diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm index 3339695449..baf6fd1c80 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm @@ -168,22 +168,7 @@ __PACKAGE__->register_method( # ------------------------------------------------------------------ sub ou_ancestor_setting { my( $self, $client, $orgid, $name ) = @_; - my $e = new_editor(); - - do { - my $setting = $e->search_actor_org_unit_setting({org_unit=>$orgid, name=>$name})->[0]; - - if( $setting ) { - $logger->info("found org_setting $name at org $orgid : " . $setting->value); - return { org => $orgid, value => JSON->JSON2perl($setting->value) }; - } - - my $org = $e->retrieve_actor_org_unit($orgid) or return $e->event; - $orgid = $org->parent_ou or return undef; - - } while(1); - - return undef; + return $U->ou_ancestor_setting($orgid, $name); } @@ -244,7 +229,6 @@ sub update_patron { return $evt if $evt; - # XXX does this user have permission to add/create users. Granularity? # $new_patron is the patron in progress. $patron is the original patron # passed in with the method. new_patron will change as the components # of patron are added/updated. @@ -459,6 +443,9 @@ sub _update_patron { $patron->clear_ident_value; } + $evt = verify_last_xact($session, $patron); + return (undef, $evt) if $evt; + my $stat = $session->request( "open-ils.storage.direct.actor.user.update",$patron )->gather(1); return (undef, $U->DB_UPDATE_FAILED($patron)) unless defined($stat); @@ -466,6 +453,20 @@ sub _update_patron { return ($patron); } +sub verify_last_xact { + my( $session, $patron ) = @_; + return undef unless $patron->id and $patron->id > 0; + my $p = $session->request( + 'open-ils.storage.direct.actor.user.retrieve', $patron->id)->gather(1); + my $xact = $p->last_xact_id; + return undef unless $xact; + $logger->info("user xact = $xact, saving with xact " . $patron->last_xact_id); + return OpenILS::Event->new('XACT_COLLISION') + if $xact != $patron->last_xact_id; + return undef; +} + + sub _check_dup_ident { my( $session, $patron ) = @_; -- 2.43.2