LP#1467663 Browser client overcome missing workstation user/berick/lp1467663-webstaff-workstation-kludge
authorBill Erickson <berickxx@gmail.com>
Fri, 16 Sep 2016 20:02:44 +0000 (16:02 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 16 Sep 2016 20:04:33 +0000 (16:04 -0400)
When a user logs in with a workstation that is not registered with the
server, remove the workstation from local settings, warn the user that
no workstation will be used, then continue the login process.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/web/js/ui/default/staff/services/auth.js

index a677ff4..2d37622 100644 (file)
@@ -85,8 +85,8 @@ function($q , $timeout , $rootScope , egNet , egHatch) {
      * Returns a promise, which is resolved on successful 
      * login and rejected on failed login.
      */
-    service.login = function(args) {
-        var deferred = $q.defer();
+    service.login = function(args, promise_wip) {
+        var deferred = promise_wip || $q.defer();
 
         // Clear old LoginSession keys that were left in localStorage
         // when the previous user closed the browser without logging
@@ -102,6 +102,7 @@ function($q , $timeout , $rootScope , egNet , egHatch) {
             'open-ils.auth',
             'open-ils.auth.authenticate.init', args.username).then(
             function(seed) {
+                var bare_password = args.password;
                 args.password = hex_md5(seed + hex_md5(args.password))
                 egNet.request(
                     'open-ils.auth',
@@ -115,6 +116,19 @@ function($q , $timeout , $rootScope , egNet , egHatch) {
                             egHatch.setLoginSessionItem(
                                 'eg.auth.time', evt.payload.authtime);
                             deferred.resolve();
+                        } else if (evt.textcode == 'WORKSTATION_NOT_FOUND') {
+
+                            // LP#1467663 stop-gap
+                            alert('Workstation "' + args.workstation + '"' +
+                                ' not found. Removing and logging in with no workstation.');
+
+                            return service.remove_unknown_workstation(args.workstation)
+                            .then(function() {
+                                delete args.workstation;
+                                args.password = bare_password;
+                                return service.login(args, deferred);
+                            });
+
                         } else {
                             // note: the likely outcome here is a NO_SESION
                             // server event, which results in broadcasting an 
@@ -130,6 +144,29 @@ function($q , $timeout , $rootScope , egNet , egHatch) {
         return deferred.promise;
     };
 
+    // remove offending workstation from list of locally stored 
+    // workstations and remove the default workstation if it matches 
+    // the invalid workstation.
+    service.remove_unknown_workstation = function(name) {
+        console.debug('Removing unknown workstation: ' + name);
+
+        return egHatch.getItem('eg.workstation.all')
+        .then(function(all) {
+            if (!all) all = [];
+            var keep = all.filter(function(ws) {return ws.name != name});
+            return egHatch.setItem('eg.workstation.all', keep)
+
+        }).then(function() { 
+            return egHatch.getItem('eg.workstation.default')
+
+        }).then(function(def) {
+            if (def == name) {
+                console.debug('Removing default workstation: ' + name);
+                return egHatch.setItem('eg.workstation.default');
+            }
+        });
+    }
+
     /**
      * Force-check the validity of the authtoken on occasion. 
      * This allows us to redirect an idle staff client back to the login