From 648b4569dbed95fa55a8b81c9c82b7048a03734d Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 8 Nov 2018 17:28:37 -0500 Subject: [PATCH] JBAS-2118 Lost payments auth for webstaff WIP Signed-off-by: Bill Erickson --- .../web/js/ui/default/staff/circ/patron/bills.js | 95 +++++++++++++++++++--- 1 file changed, 83 insertions(+), 12 deletions(-) diff --git a/Open-ILS/web/js/ui/default/staff/circ/patron/bills.js b/Open-ILS/web/js/ui/default/staff/circ/patron/bills.js index e62cd3e60f..e3d1e1d708 100644 --- a/Open-ILS/web/js/ui/default/staff/circ/patron/bills.js +++ b/Open-ILS/web/js/ui/default/staff/circ/patron/bills.js @@ -28,7 +28,7 @@ function($q , egCore , egWorkLog , patronSvc) { } service.applyPayment = function( - type, payments, note, check, cc_args, patron_credit) { + type, payments, note, check, cc_args, patron_credit, refundable_args) { return egCore.net.request( 'open-ils.circ', @@ -40,6 +40,7 @@ function($q , egCore , egWorkLog , patronSvc) { check_number : check, payments : payments, patron_credit : patron_credit, + refundable_args: refundable_args, cc_args : cc_args }, patronSvc.current.last_xact_id() @@ -384,7 +385,8 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location, function(item) {return item.id == xactId})[0]; var stopFines = gridItem['circulation.stop_fines']; - if (stopFines === 'LOST') { + var ciTime = gridItem['circulation.checkin_time']; + if (stopFines === 'LOST' && !ciTime) { console.debug("Processing lost payment transaction ", xactId); lostXacts.push(xactId); } @@ -394,21 +396,62 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location, return $q.when(payments); } + return checkSecondaryAuth().then( + function(authKey) { + return { + secondary_auth_key: authKey, + transactions: lostXacts.map( + function(id) {return {xact: id}}) + }; + }, + function() { return $q.reject(); } + ); + } + + function checkSecondaryAuth(deferred) { + + if (!deferred) { + // Create the deferred object on the first run of this function. + deferred = $q.defer(); + } + + showSecondaryAuthDialog().then( + function(authKey) { + if (authKey) { + deferred.resolve(authKey); + } else { + return checkSecondaryAuth(deferred); + } + }, + function() { + deferred.reject(); + } + ); + + return deferred.promise; + } + + // Returns promise. + // Resolves to true on auth success, false on auth failure, and + // rejects on Cancel. + function showSecondaryAuthDialog() { + return $uibModal.open({ templateUrl : './circ/patron/t_lost_payment_auth', backdrop: 'static', controller : [ '$scope','$uibModalInstance', function($scope , $uibModalInstance) { - $scope.context = { - username: '', - password: '' - }; + $scope.context = {username: '',password: ''}; $scope.ok = function() { - console.log($scope.context.username); - console.log($scope.context.password); - $uibModalInstance.close(payments); + getSecondaryAuthKey( + $scope.context.username, $scope.context.password + ).then( + function(res) { + $uibModalInstance.close(res); + } + ); } $scope.cancel = function() { @@ -419,6 +462,34 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location, }).result; } + function getSecondaryAuthKey(username, password) { + + console.log('Checking secondary auth for ' + username); + + return egCore.net.request( + 'open-ils.circ', + 'open-ils.circ.staff.secondary_auth.ldap', + egCore.auth.token(), username, password + ).then(function(result) { + var evt = egCore.evt.parse(result); + console.log('2nd auth returned', result); + + if (evt) { + if (evt.textcode === 'LDAP_AUTH_FAILED') { + console.log("Secondary auth failed for " + username); + } else { + alert(evt); + } + } else if (typeof result === 'string') { + console.debug('Secondary auth succeeded with ' + result); + return result; + } + + return null; + }); + } + + // generates payments, collects user note if needed, and sends payment // to server. function sendPayment(note, cc_args) { @@ -429,11 +500,11 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location, // KCLS prompt for lost payment authorization. handleLostPayAuth(make_payments) - .then(function(make_payments) { + .then(function(refundable_args) { // NOTE: avoiding indentation to reduce variation with stock. - billSvc.applyPayment($scope.payment_type, - make_payments, note, $scope.check_number, cc_args, patron_credit) + billSvc.applyPayment($scope.payment_type, make_payments, note, + $scope.check_number, cc_args, patron_credit, refundable_args) .then( function(payment_ids) { -- 2.11.0