From 768c2d0d64f8349e800172330dcb2219264775e6 Mon Sep 17 00:00:00 2001 From: dbs Date: Tue, 29 Jan 2008 19:14:29 +0000 Subject: [PATCH] Return explicit nulls if no matching username / barcode is found (and modify tests accordingly). We suspect JSON::XS started returning '0' instead of 0, which threw off our logic. git-svn-id: svn://svn.open-ils.org/ILS/trunk@8528 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Evergreen/xul/staff_client/server/patron/ue_config.js | 6 +++--- Open-ILS/src/perlmods/OpenILS/Application/Actor.pm | 10 +++++----- Open-ILS/web/opac/skin/default/js/myopac.js | 9 ++++++++- Open-ILS/xul/staff_client/server/patron/ue_config.js | 6 +++--- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Evergreen/xul/staff_client/server/patron/ue_config.js b/Evergreen/xul/staff_client/server/patron/ue_config.js index e540314ac9..ab3ba468a7 100644 --- a/Evergreen/xul/staff_client/server/patron/ue_config.js +++ b/Evergreen/xul/staff_client/server/patron/ue_config.js @@ -37,12 +37,12 @@ var barredAlerted = false; function uEditUsrnameBlur(field) { var usrname = uEditNodeVal(field); - if(!usrname) return; + if (!usrname) { return; } var req = new Request(CHECK_USERNAME, SESSION, usrname); req.callback( function(r) { var res = r.getResultObject(); - if( res && res != patron.id() ) { + if( res !== null && res != patron.id() ) { field.widget.onblur = null; /* prevent alert storm */ alertId('ue_dup_username'); field.widget.onblur = uEditUsrnameBlur; @@ -67,7 +67,7 @@ function uEditBarcodeBlur(field) { req.callback( function(r) { var res = r.getResultObject(); - if( res && res != patron.id() ) { + if( res !== null && res != patron.id() ) { field.widget.onblur = null; /* prevent alert storm */ alertId('ue_dup_barcode'); field.widget.onblur = uEditBarcodeBlur; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm index 9330f96af7..3cbeaa1f8c 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm @@ -2704,7 +2704,7 @@ __PACKAGE__->register_method( method => 'usrname_exists', api_name => 'open-ils.actor.username.exists', signature => q/ - Returns 1 if the requested username exists, returns 0 otherwise + Returns the user ID of the requested username if that username exists, returns null otherwise / ); @@ -2714,14 +2714,14 @@ sub usrname_exists { return $e->event unless $e->checkauth; my $a = $e->search_actor_user({usrname => $usrname, deleted=>'f'}, {idlist=>1}); return $$a[0] if $a and @$a; - return 0; + return undef; } __PACKAGE__->register_method( method => 'barcode_exists', api_name => 'open-ils.actor.barcode.exists', signature => q/ - Returns 1 if the requested barcode exists, returns 0 otherwise + Returns the user ID for the requested barcode if that barcode exists, returns null otherwise / ); @@ -2730,8 +2730,8 @@ sub barcode_exists { my $e = new_editor(authtoken=>$auth); return $e->event unless $e->checkauth; my $card = $e->search_actor_card({barcode => $barcode}); - return 0 unless @$card; - return $card->[0]->usr; + return undef unless @$card; + return $card->[0]->usr; } diff --git a/Open-ILS/web/opac/skin/default/js/myopac.js b/Open-ILS/web/opac/skin/default/js/myopac.js index 0e5b49ff46..e2b6188684 100644 --- a/Open-ILS/web/opac/skin/default/js/myopac.js +++ b/Open-ILS/web/opac/skin/default/js/myopac.js @@ -859,7 +859,14 @@ function myOPACUpdateUsername() { var req = new Request(CHECK_USERNAME, G.user.session, username); req.send(true); var res = req.result(); - if( res && res == G.user.id() ) { + /* If the username does not already exist, res will be null; + * we can move on to updating the username. + * + * If the username does exist, then res will be the user ID. + * G.user.id() gives us the currently authenticated user ID. + * If res == G.user.id(), we try to update the username anyways. + */ + if( res !== null && res != G.user.id() ) { alertId('myopac_username_dup'); return; } diff --git a/Open-ILS/xul/staff_client/server/patron/ue_config.js b/Open-ILS/xul/staff_client/server/patron/ue_config.js index 172124a6ac..f5281b9884 100644 --- a/Open-ILS/xul/staff_client/server/patron/ue_config.js +++ b/Open-ILS/xul/staff_client/server/patron/ue_config.js @@ -52,12 +52,12 @@ var barredAlerted = false; function uEditUsrnameBlur(field) { var usrname = uEditNodeVal(field); - if(!usrname) return; + if (!usrname) { return; } var req = new Request(CHECK_USERNAME, SESSION, usrname); req.callback( function(r) { var res = r.getResultObject(); - if( res && res != patron.id() ) { + if( res !== null && res != patron.id() ) { field.widget.onblur = null; /* prevent alert storm */ alertId('ue_dup_username'); field.widget.onblur = uEditUsrnameBlur; @@ -81,7 +81,7 @@ function uEditBarcodeBlur(field) { req.callback( function(r) { var res = r.getResultObject(); - if( res && res != patron.id() ) { + if( res !== null && res != patron.id() ) { field.widget.onblur = null; /* prevent alert storm */ alertId('ue_dup_barcode'); field.widget.onblur = uEditBarcodeBlur; -- 2.43.2