LP1864056: Don't compare multiple new Date()s
authorJason Boyer <JBoyer@eoli.info>
Fri, 21 Feb 2020 21:08:36 +0000 (16:08 -0500)
committerJane Sandberg <sandbej@linnbenton.edu>
Sun, 12 Jul 2020 15:31:17 +0000 (08:31 -0700)
This branch addresses a race condition when
checking out or renewing items.
(The use of minDate in items_out was implicitly
immune to this issue, but that is made explicit
with this patch.)

To test
-------
[1] The race condition would be difficult to reliably
    reproduce directly, although a tool like
    https://github.com/mattzeunert/javascript-clock-speedup
    might help simulate the problem, so to test, verify
    that the following actions do not break:

    * checking out a loan, both with and without
      setting a specific due date
    * renewing a loan with a specific due date
      from the patron items out tab
    * renewing a loan from Circulation -> Renew Items,
      both with and without setting a specific due date.

Signed-off-by: Jason Boyer <JBoyer@eoli.info>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>

Open-ILS/web/js/ui/default/staff/circ/patron/checkout.js
Open-ILS/web/js/ui/default/staff/circ/patron/items_out.js
Open-ILS/web/js/ui/default/staff/circ/renew/app.js

index 9510546..df4945b 100644 (file)
@@ -9,6 +9,7 @@ angular.module('egPatronApp').controller('PatronCheckoutCtrl',
 
 function($scope , $q , $routeParams , egCore , egUser , patronSvc , 
          egGridDataProvider , $location , $timeout , egCirc , ngToast) {
+    var now = new Date();
 
     $scope.initTab('checkout', $routeParams.id).finally(function(){
         $scope.focusMe = true;
@@ -16,10 +17,10 @@ function($scope , $q , $routeParams , egCore , egUser , patronSvc ,
     $scope.checkouts = patronSvc.checkouts;
     $scope.checkoutArgs = {
         noncat_type : 'barcode',
-        due_date : new Date()
+        due_date : new Date(now)
     };
 
-    $scope.minDate = new Date();
+    $scope.minDate = new Date(now);
     $scope.outOfRange = false;
     $scope.gridDataProvider = egGridDataProvider.instance({
         get : function(offset, count) {
index 26341c1..b17702f 100644 (file)
@@ -503,11 +503,12 @@ function($scope , $q , $routeParams , $timeout , egCore , egUser , patronSvc ,
             controller : [
                         '$scope','$uibModalInstance',
                 function($scope , $uibModalInstance) {
+                    var now = new Date();
                     $scope.outOfRange = false;
-                    $scope.minDate = new Date();
+                    $scope.minDate = new Date(now);
                     $scope.args = {
                         barcodes : barcodes,
-                        date : new Date()
+                        date : new Date(now)
                     }
                     $scope.cancel = function() {$uibModalInstance.dismiss()}
 
index b5cdfd1..95f59eb 100644 (file)
@@ -32,16 +32,16 @@ angular.module('egRenewApp',
 .controller('RenewCtrl',
        ['$scope','$window','$location','egCore','egGridDataProvider','egCirc',
 function($scope , $window , $location , egCore , egGridDataProvider , egCirc) {
+    var now = new Date();
 
     egCore.hatch.getItem('circ.renew.strict_barcode')
         .then(function(sb){ $scope.strict_barcode = sb });
     $scope.focusBarcode = true;
     $scope.outOfRange = false;
-    $scope.minDate = new Date();
+    $scope.minDate = new Date(now);
     $scope.renewals = [];
 
-    var today = new Date();
-    $scope.renewalArgs = {due_date : today};
+    $scope.renewalArgs = {due_date : new Date(now)};
 
     $scope.sort_money = function (a,b) {
         var ma = parseFloat(a);