lp1517595 webstaff: purge patron account action
authorJason Etheridge <jason@equinoxinitiative.org>
Thu, 15 Jun 2017 16:58:19 +0000 (12:58 -0400)
committerMike Rylander <mrylander@gmail.com>
Fri, 30 Jun 2017 15:27:10 +0000 (11:27 -0400)
TODO: disable the menu entry based on permissions

Signed-off-by: Jason Etheridge <jason@equinoxinitiative.org>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/templates/staff/circ/patron/index.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/app.js

index 88c5dca..b9d19c8 100644 (file)
@@ -53,6 +53,12 @@ angular.module('egCoreMod').run(['egStrings', function(s) {
   s.PAYMENT_OVER_MAX = "[% l('Payments over $[_1] are denied by policy.', '{{max_amount}}') %]";
   s.PATRON_NOTE_DELETE_CONFIRM_TITLE = "[% l('Delete Note?') %]";
   s.PATRON_NOTE_DELETE_CONFIRM = "[% l('Delete the note titled \"[_1]\" created on [_2]?', '{{note_title}}', '{{create_date | date}}') %]";
+  s.PATRON_PURGE_CONFIRM_TITLE = "[% l('Completely Purge Patron Account?') %]";
+  s.PATRON_PURGE_CONFIRM = "[% l('Completely OBLITERATE this patron account, including bills, payments, bookbags, etc? This is IRREVERSIBLE.') %]";
+  s.PATRON_PURGE_LAST_CHANCE = "[% l('Last chance, are you sure you want to completely delete this account?') %]";
+  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}}') %]";
 }]);
@@ -198,6 +204,11 @@ angular.module('egCoreMod').run(['egStrings', function(s) {
               [% l('Booking: Return Reservations') %]
             </a>
           </li>
+          <li>
+            <a href ng-click="purge_account()" a-disabled="patron().super_user() == 't' || patron().id() == auth_user_id">
+              [% l('Completely Purge Account') %]
+            </a>
+          </li>
        </ul>
       </li>
       <li ng-class="{active : tab == 'search'}" class="pull-right">
index fe126d4..1452ce5 100644 (file)
@@ -589,8 +589,8 @@ function($q , $timeout , $location , egCore,  egUser , $locale) {
  *
  * */
 .controller('PatronCtrl',
-       ['$scope','$q','$location','$filter','egCore','egUser','patronSvc',
-function($scope,  $q,  $location , $filter,  egCore,  egUser,  patronSvc) {
+       ['$scope','$q','$location','$filter','egCore','egNet','egUser','egAlertDialog','egConfirmDialog','egPromptDialog','patronSvc',
+function($scope,  $q , $location , $filter , egCore , egNet , egUser , egAlertDialog , egConfirmDialog , egPromptDialog , patronSvc) {
 
     $scope.is_patron_edit = function() {
         return Boolean($location.path().match(/patron\/\d+\/edit$/));
@@ -645,6 +645,7 @@ function($scope,  $q,  $location , $filter,  egCore,  egUser,  patronSvc) {
         console.log('init tab ' + tab);
         $scope.tab = tab;
         $scope.aous = egCore.env.aous;
+        $scope.auth_user_id = egCore.auth.user().id();
 
         if (patron_id) {
             $scope.patron_id = patron_id;
@@ -705,6 +706,71 @@ function($scope,  $q,  $location , $filter,  egCore,  egUser,  patronSvc) {
         return $scope.tab != 'search' && $scope.collapsePatronSummary;
     }
 
+    function _purge_account(dest_usr,override) {
+        egNet.request(
+            'open-ils.actor',
+            'open-ils.actor.user.delete' + (override ? '.override' : ''),
+            egCore.auth.token(),
+            $scope.patron().id(),
+            dest_usr
+        ).then(function(resp){
+            if (evt = egCore.evt.parse(resp)) {
+                if (evt.code == '2004' /* ACTOR_USER_DELETE_OPEN_XACTS */) {
+                    egConfirmDialog.open(
+                        egCore.strings.PATRON_PURGE_CONFIRM_TITLE, egCore.strings.PATRON_PURGE_OVERRIDE_PROMPT,
+                        {ok : function() {
+                            _purge_account(dest_usr,true);
+                        }}
+                    );
+                } else {
+                    alert(js2JSON(evt));
+                }
+            } else {
+                location.href = egCore.env.basePath + '/circ/patron/search';
+            }
+        });
+    }
+
+    function _purge_account_with_destination(dest_barcode) {
+        egCore.pcrud.search('ac', {barcode : dest_barcode})
+        .then(function(card) {
+            if (!card) {
+                egAlertDialog.open(egCore.strings.PATRON_PURGE_STAFF_BAD_BARCODE);
+            } else {
+                _purge_account(card.usr());
+            }
+        });
+    }
+
+    $scope.purge_account = function() {
+        egConfirmDialog.open(
+            egCore.strings.PATRON_PURGE_CONFIRM_TITLE, egCore.strings.PATRON_PURGE_CONFIRM,
+            {ok : function() {
+                egConfirmDialog.open(
+                    egCore.strings.PATRON_PURGE_CONFIRM_TITLE, egCore.strings.PATRON_PURGE_LAST_CHANCE,
+                    {ok : function() {
+                        egNet.request(
+                            'open-ils.actor',
+                            'open-ils.actor.user.has_work_perm_at',
+                            egCore.auth.token(), 'STAFF_LOGIN', $scope.patron().id()
+                        ).then(function(resp) {
+                            var is_staff = resp.length > 0;
+                            if (is_staff) {
+                                egPromptDialog.open(
+                                    egCore.strings.PATRON_PURGE_STAFF_PROMPT,
+                                    null, // TODO: this would be cool if it worked: egCore.auth.user().card().barcode(),
+                                    {ok : function(barcode) {_purge_account_with_destination(barcode)}}
+                                );
+                            } else {
+                                _purge_account();
+                            }
+                        });
+                    }
+                });
+            }
+        });
+    }
+
     egCore.hatch.getItem('eg.circ.patron.summary.collapse')
     .then(function(val) {$scope.collapsePatronSummary = Boolean(val)});
 }])