lp#1016102: Solve the Problem of the UI allowing unreasonable dates from the user
authorZavier Banks <zbanks@catalyte.io>
Thu, 19 Sep 2019 16:27:08 +0000 (16:27 +0000)
committerZavier Banks <zbanks@catalyte.io>
Fri, 20 Sep 2019 19:23:02 +0000 (19:23 +0000)
I added a date limiter in the checkout.js file, that prevents the user from making unreasonable dates.

Signed-off-by: Zavier Banks <zbanks@catalyte.io>
lp#1016102: due date fields allow non-sane due dates

I added in a conditional that checks if the date is valid, and not unreasonable. Additionally,
I added a YAOUS that gives the amount of years maximum, you can check out a book. The code can be changed to
be more specific, if necessary.

Signed-off-by: Zavier Banks <zbanks@catalyte.io>
lp#1016102 due date fields allow non-sane due dates

I reconfigured the way I found and implemented the maximum due date. In the initialization of the
checkout.js document, I added a way to get the maximum date from the database, and add it to the current date.
In the t_checkout.tt2 file, I added a max_date to the date input as well.

Signed-off-by: Zavier Banks <zbanks@catalyte.io>
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.data.lp1016102-due-date-max-checkout-interval.sql [new file with mode: 0644]
Open-ILS/src/templates/staff/circ/patron/t_checkout.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/checkout.js

index daf37c3..716c501 100644 (file)
@@ -3002,8 +3002,17 @@ SELECT SETVAL('acq.user_request_type_id_seq'::TEXT, 7);
 -- org_unit setting types
 INSERT into config.org_unit_setting_type
 ( name, grp, label, description, datatype, fm_class ) VALUES
-
-( 'acq.copy_creator_uses_receiver', 'acq',
+( 'circ.maximum_due_date','gui',
+    oils_i18n_gettext(
+        'circ.maximum_due_date_length',
+        'Maximum Future Due Date Interval.',
+        'coust', 'label'),
+    oils_i18n_gettext(
+        'circ.maximum_due_date_length',
+        'How far in the future you can set a due date',
+        'coust', 'label'),
+    'interval', null )
+,( 'acq.copy_creator_uses_receiver', 'acq',
     oils_i18n_gettext('acq.copy_creator_uses_receiver',
         'Set copy creator as receiver',
         'coust', 'label'),
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.lp1016102-due-date-max-checkout-interval.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.lp1016102-due-date-max-checkout-interval.sql
new file mode 100644 (file)
index 0000000..423237b
--- /dev/null
@@ -0,0 +1,15 @@
+INSERT into config.org_unit_setting_type\r
+    (name, datatype, grp, label, description)\r
+VALUES (\r
+    'circ.maximum_due_date', 'interval', 'gui'\r
+    oils_i18n_gettext(\r
+        'circ.maximum_due_date_length',\r
+        'Maximum Future Due Date Interval.',\r
+        'coust', 'label'\r
+    ),\r
+    oils_i18n_gettext(\r
+        'circ.maximum_due_date_length',\r
+        'How far in the future you can set a due date'\r
+        'coust', 'label'\r
+    )\r
+);
\ No newline at end of file
index c7c6fc5..08ba06c 100644 (file)
@@ -75,8 +75,8 @@
           [% l('Specific Due Date') %]
         </label>
       </div> -->
-      <div class="col-md-4">
-        <eg-date-input ng-model="checkoutArgs.due_date" ng-disabled="!date_options.has_sticky_date" show-time-picker></eg-date-input>
+      <div class="col-md-4" ng-if="maxDate">
+        <eg-date-input ng-model="checkoutArgs.due_date" ng-disabled="!date_options.has_sticky_date" show-time-picker max-date="maxDate"></eg-date-input>
       </div>
 </div>
     </div>
index d79811c..1d71ed3 100644 (file)
@@ -10,7 +10,20 @@ angular.module('egPatronApp').controller('PatronCheckoutCtrl',
 function($scope , $q , $routeParams , egCore , egUser , patronSvc , 
          egGridDataProvider , $location , $timeout , egCirc , ngToast) {
 
-    $scope.initTab('checkout', $routeParams.id).finally(function(){
+    $scope.initTab('checkout', $routeParams.id).then(function(){
+        var dateLimit;
+        var limitedDate;
+        egCore.org.settings([
+            'circ.maximum_due_date'
+        ]).then(function(settings) { //Then log the maximum date set by the user.
+            dateLimit= settings['circ.maximum_due_date'];
+            if(dateLimit!=null){
+                limitedDate = new Date();
+                limitedDate.setSeconds(limitedDate.getSeconds()+egCore.date.intervalToSeconds(dateLimit))
+            }
+            $scope.maxDate=limitedDate;
+        })
+    }).finally(function(){
         $scope.focusMe = true;
     });
     $scope.checkouts = patronSvc.checkouts;
@@ -140,15 +153,14 @@ function($scope , $q , $routeParams , egCore , egUser , patronSvc ,
 
     $scope.checkout = function(args) {
         var params = angular.copy(args);
-        params.patron_id = patronSvc.current.id();
-
-        if (args.sticky_date) {
-            params.due_date = args.due_date.toISOString();
+        params.patron_id = patronSvc.current.id();       
+            
+        if (args.sticky_date) {//If the date, given by the user, is less that the date limit set by the admin
+            params.due_date = args.due_date.toISOString();//Add the due date to the parameters.
         } else {
             delete params.due_date;
         }
-        delete params.sticky_date;
-
+        delete params.sticky_date; 
         if (params.noncat_type == 'barcode') {
             if (!args.copy_barcode) return;