LP#1684988: add opt-in check to patron service
authorJeff Davis <jdavis@sitka.bclibraries.ca>
Mon, 21 Aug 2017 23:12:46 +0000 (16:12 -0700)
committerJason Etheridge <jason@EquinoxInitiative.org>
Fri, 25 Aug 2017 16:41:28 +0000 (12:41 -0400)
Signed-off-by: Jeff Davis <jdavis@sitka.bclibraries.ca>
Signed-off-by: Jason Etheridge <jason@EquinoxInitiative.org>
Open-ILS/src/templates/staff/base_js.tt2
Open-ILS/src/templates/staff/circ/patron/index.tt2
Open-ILS/web/js/ui/default/staff/services/patron_search.js

index 1880f66..211eace 100644 (file)
@@ -89,6 +89,9 @@
     s.OP_CHANGE_PERM_MESSAGE = "[% l('Another staff member with the above permission may authorize this specific action.  Please notify your library administrator if you need this permission.  If you feel you have received this exception in error, please inform your friendly Evergreen developers or helpdesk staff of the above permission.') %]";
     s.PERM_OP_CHANGE_SUCCESS = "[% l('Permission Override Login Succeeded') %]";
     s.PERM_OP_CHANGE_FAILURE = "[% l('Permission Override Login Failed') %]";
+    s.OPT_IN_DIALOG_TITLE = "[% l('Verify Permission to Share Personal Information') %]";
+    s.OPT_IN_DIALOG = "[% l('Does patron [_1], [_2] from [_3] ([_4]) consent to having their personal information shared with your library?', '{{family_name}}', '{{first_given_name}}', '{{org_name}}', '{{org_shortname}}') %]";
+    s.OPT_IN_RESTRICTED = "[% l("This patron's record is not viewable at your library.") %]";
   }]);
 </script>
 
index d2908d3..de70995 100644 (file)
@@ -60,8 +60,6 @@ angular.module('egCoreMod').run(['egStrings', function(s) {
   s.PATRON_PURGE_STAFF_PROMPT = "[% l('The account you are attempting to delete has STAFF_LOGIN privileges. Please enter the barcode for a destination account to receive miscellaneous staff artifacts (reports, etc.) from the account to be deleted.') %]";
   s.PATRON_PURGE_STAFF_BAD_BARCODE = "[% l('Could not retrieve a destination account with the barcode provided. Aborting the purge...') %]";
   s.PATRON_PURGE_OVERRIDE_PROMPT = "[% l('The account has open transactions (circulations and/or unpaid bills). Purge anyway?') %]";
-  s.OPT_IN_DIALOG_TITLE = "[% l('Verify Permission to Share Personal Information') %]";
-  s.OPT_IN_DIALOG = "[% l('Does patron [_1], [_2] from [_3] ([_4]) consent to having their personal information shared with your library?', '{{family_name}}', '{{first_given_name}}', '{{org_name}}', '{{org_shortname}}') %]";
   s.PATRON_EDIT_COLLISION = "[% l('Patron record was modified by another user while you were editing it. Your changes were not saved; please reapply them.') %]";
 }]);
 </script>
index 48859d8..ed5c86b 100644 (file)
@@ -9,8 +9,8 @@ angular.module('egPatronSearchMod', ['ngRoute', 'ui.bootstrap',
  * Patron service
  */
 .factory('patronSvc',
-       ['$q','$timeout','$location','egCore','egUser','$locale',
-function($q , $timeout , $location , egCore,  egUser , $locale) {
+       ['$q','$timeout','$location','egCore','egUser','egConfirmDialog','$locale',
+function($q , $timeout , $location , egCore,  egUser , egConfirmDialog , $locale) {
 
     var service = {
         // cached patron search results
@@ -126,9 +126,17 @@ function($q , $timeout , $location , egCore,  egUser , $locale) {
             }
 
             service.resetPatronLists();
-            service.current = user;
-            service.localFlesh(user);
-            return service.fetchUserStats();
+
+            return service.checkOptIn(user).then(
+                function() {
+                    service.current = user;
+                    service.localFlesh(user);
+                    return service.fetchUserStats();
+                },
+                function() {
+                    return $q.reject();
+                }
+            );
 
         } else if (id) {
             if (!force && service.current && service.current.id() == id) {
@@ -143,9 +151,16 @@ function($q , $timeout , $location , egCore,  egUser , $locale) {
 
             return egUser.get(id).then(
                 function(user) {
-                    service.current = user;
-                    service.localFlesh(user);
-                    return service.fetchUserStats();
+                    return service.checkOptIn(user).then(
+                        function() {
+                            service.current = user;
+                            service.localFlesh(user);
+                            return service.fetchUserStats();
+                        },
+                        function() {
+                            return $q.reject();
+                        }
+                    );
                 },
                 function(err) {
                     console.error(
@@ -354,6 +369,59 @@ function($q , $timeout , $location , egCore,  egUser , $locale) {
         });
     }
 
+    service.createOptIn = function(user_id) {
+        return egCore.net.request(
+            'open-ils.actor',
+            'open-ils.actor.user.org_unit_opt_in.create',
+            egCore.auth.token(), user_id);
+    }
+
+    service.checkOptIn = function(user) {
+        var deferred = $q.defer();
+        egCore.net.request(
+            'open-ils.actor',
+            'open-ils.actor.user.org_unit_opt_in.check',
+            egCore.auth.token(), user.id())
+        .then(function(optInResp) {
+            if (eg_evt = egCore.evt.parse(optInResp)) {
+                deferred.reject();
+                console.log('error on opt-in check: ' + eg_evt);
+            } else if (optInResp == 2) {
+                // opt-in disallowed at this location by patron's home library
+                deferred.reject();
+                alert(egCore.strings.OPT_IN_RESTRICTED);
+            } else if (optInResp == 1) {
+                // opt-in handled or not needed, do nothing
+                deferred.resolve();
+            } else {
+                // opt-in needed, show the opt-in dialog
+                var org = egCore.org.get(user.home_ou());
+                egConfirmDialog.open(
+                    egCore.strings.OPT_IN_DIALOG_TITLE,
+                    egCore.strings.OPT_IN_DIALOG,
+                    {   family_name : user.family_name(),
+                        first_given_name : user.first_given_name(),
+                        org_name : org.name(),
+                        org_shortname : org.shortname(),
+                        ok : function() {
+                            service.createOptIn(user.id())
+                            .then(function(resp) {
+                                if (evt = egCore.evt.parse(resp)) {
+                                    deferred.reject();
+                                    alert(evt);
+                                } else {
+                                    deferred.resolve();
+                                }
+                            });
+                        },
+                        cancel : function() { deferred.reject(); }
+                    }
+                );
+            }
+        });
+        return deferred.promise;
+    }
+
     // Avoid using parens [e.g. (1.23)] to indicate negative numbers, 
     // which is the Angular default.
     // http://stackoverflow.com/questions/17441254/why-angularjs-currency-filter-formats-negative-numbers-with-parenthesis