From 4e087166fc543c3f0f311f47d4d9bd825e2d2eea Mon Sep 17 00:00:00 2001 From: Simone Duca Date: Fri, 2 Feb 2018 17:19:58 +0000 Subject: [PATCH 01/15] Experiment in token refresh. Leave logs for testing on preview. --- app/modules/auth/auth.factory.js | 25 ++++++++++++++++++++----- gulp/tasks/browserify.js | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/app/modules/auth/auth.factory.js b/app/modules/auth/auth.factory.js index 7db4afc..7c716e5 100644 --- a/app/modules/auth/auth.factory.js +++ b/app/modules/auth/auth.factory.js @@ -4,6 +4,7 @@ require('./auth.module.js') .factory('authFactory', authFactory); var OAuth = require('panoptes-client/lib/oauth'); +var Auth = require('panoptes-client/lib/auth'); // @ngInject function authFactory($interval, $timeout, $location, $window, localStorageService, ModalsFactory, zooAPI, zooAPIConfig, CribsheetFactory, $rootScope) { @@ -11,13 +12,27 @@ function authFactory($interval, $timeout, $location, $window, localStorageServic var factory; var _user = {}; + // 2 hrs + var timeout = 120 * 60 * 1000; + + $timeout( function() { + Auth.checkBearerToken() + .then(function (token) { + console.log('Token refreshed: ', token); + }) + .catch(function (error) { + console.log('Failed to refresh token: ', error); + factory.signOut; + }) + }, 10000); // 20 sec, just for testing. Swap with timeout variable when I get this to work + OAuth.checkCurrent() - .then(function (user) { - if (user) { - _setUserData(); - } - }); + .then(function (user) { + if (user) { + _setUserData(); + } + }); factory = { signIn: signIn, diff --git a/gulp/tasks/browserify.js b/gulp/tasks/browserify.js index 1821b5d..7f6c5f5 100644 --- a/gulp/tasks/browserify.js +++ b/gulp/tasks/browserify.js @@ -66,7 +66,7 @@ function buildScript(file) { .pipe(gulpif(createSourcemap, sourcemaps.init())) .pipe(gulpif(global.isProd, streamify( uglify({ - compress: { drop_console: true } + compress: { } // leave console.log in prod, for testing }) .on('error', handleErrors) ))) From 0a603ee7bac02690a151feaf4d61dafc856f96dc Mon Sep 17 00:00:00 2001 From: Simone Duca Date: Mon, 12 Feb 2018 15:26:11 +0000 Subject: [PATCH 02/15] use new oauth.checkBearerToken --- app/modules/auth/auth.factory.js | 15 --------------- app/modules/zoo-api/zooapi.factory.js | 13 +++++++++++-- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/app/modules/auth/auth.factory.js b/app/modules/auth/auth.factory.js index 7c716e5..d518e66 100644 --- a/app/modules/auth/auth.factory.js +++ b/app/modules/auth/auth.factory.js @@ -4,7 +4,6 @@ require('./auth.module.js') .factory('authFactory', authFactory); var OAuth = require('panoptes-client/lib/oauth'); -var Auth = require('panoptes-client/lib/auth'); // @ngInject function authFactory($interval, $timeout, $location, $window, localStorageService, ModalsFactory, zooAPI, zooAPIConfig, CribsheetFactory, $rootScope) { @@ -12,20 +11,6 @@ function authFactory($interval, $timeout, $location, $window, localStorageServic var factory; var _user = {}; - // 2 hrs - var timeout = 120 * 60 * 1000; - - $timeout( function() { - Auth.checkBearerToken() - .then(function (token) { - console.log('Token refreshed: ', token); - }) - .catch(function (error) { - console.log('Failed to refresh token: ', error); - factory.signOut; - }) - }, 10000); // 20 sec, just for testing. Swap with timeout variable when I get this to work - OAuth.checkCurrent() .then(function (user) { diff --git a/app/modules/zoo-api/zooapi.factory.js b/app/modules/zoo-api/zooapi.factory.js index 7d872a9..d84592e 100644 --- a/app/modules/zoo-api/zooapi.factory.js +++ b/app/modules/zoo-api/zooapi.factory.js @@ -4,10 +4,19 @@ require('./zooapi.module.js') .factory('zooAPI', zooAPI); var ApiClient = require('panoptes-client/lib/api-client'); - +var OAuth = require('panoptes-client/lib/oauth') // @ngInject function zooAPI(zooAPIConfig) { - + ApiClient.beforeEveryRequest = function() { + return OAuth.checkBearerToken() + .then(function (token) { + console.log('Token refreshed: ', token); + }) + .catch(function (error) { + console.log('Failed to refresh token: ', error); + factory.signOut; + }) + } // There's only a version of this project on production, so rather than // defer to the client we manually override the API root. // Panoptes.apiClient.root = 'https://www.zooniverse.org/api'; From 03e6cecd2280d2aec63b7e7c94888a811db277b4 Mon Sep 17 00:00:00 2001 From: Simone Duca Date: Mon, 12 Feb 2018 16:07:34 +0000 Subject: [PATCH 03/15] Update logout view if token refresh fails. --- app/modules/zoo-api/zooapi.factory.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/modules/zoo-api/zooapi.factory.js b/app/modules/zoo-api/zooapi.factory.js index d84592e..40ce96d 100644 --- a/app/modules/zoo-api/zooapi.factory.js +++ b/app/modules/zoo-api/zooapi.factory.js @@ -6,7 +6,7 @@ require('./zooapi.module.js') var ApiClient = require('panoptes-client/lib/api-client'); var OAuth = require('panoptes-client/lib/oauth') // @ngInject -function zooAPI(zooAPIConfig) { +function zooAPI($rootScope, zooAPIConfig) { ApiClient.beforeEveryRequest = function() { return OAuth.checkBearerToken() .then(function (token) { @@ -14,7 +14,9 @@ function zooAPI(zooAPIConfig) { }) .catch(function (error) { console.log('Failed to refresh token: ', error); - factory.signOut; + alert('Your session has finished. Please save your work and login again.') + $rootScope.$broadcast('auth:loginChange'); + OAuth.signOut(); }) } // There's only a version of this project on production, so rather than From 42d06c9df59fd7433fc1b093320339eaa09e9312 Mon Sep 17 00:00:00 2001 From: Simone Duca Date: Tue, 13 Feb 2018 16:40:46 +0000 Subject: [PATCH 04/15] Warn of session expiration, save their work and refresh token for them --- app/modules/zoo-api/zooapi.factory.js | 7 ++++--- app/modules/zoo-api/zooapi.module.js | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/modules/zoo-api/zooapi.factory.js b/app/modules/zoo-api/zooapi.factory.js index 40ce96d..bf91845 100644 --- a/app/modules/zoo-api/zooapi.factory.js +++ b/app/modules/zoo-api/zooapi.factory.js @@ -6,7 +6,7 @@ require('./zooapi.module.js') var ApiClient = require('panoptes-client/lib/api-client'); var OAuth = require('panoptes-client/lib/oauth') // @ngInject -function zooAPI($rootScope, zooAPIConfig) { +function zooAPI(AnnotationsFactory, $location, $rootScope) { ApiClient.beforeEveryRequest = function() { return OAuth.checkBearerToken() .then(function (token) { @@ -14,9 +14,10 @@ function zooAPI($rootScope, zooAPIConfig) { }) .catch(function (error) { console.log('Failed to refresh token: ', error); - alert('Your session has finished. Please save your work and login again.') + alert('Your session is about to expire. Press "OK" to save your work and get a new session.'); + AnnotationsFactory.updateCache(); + OAuth.signIn($location.absUrl()); $rootScope.$broadcast('auth:loginChange'); - OAuth.signOut(); }) } // There's only a version of this project on production, so rather than diff --git a/app/modules/zoo-api/zooapi.module.js b/app/modules/zoo-api/zooapi.module.js index d21f7eb..b5589ac 100644 --- a/app/modules/zoo-api/zooapi.module.js +++ b/app/modules/zoo-api/zooapi.module.js @@ -1,4 +1,6 @@ 'use strict'; module.exports = require('angular') - .module('app.zooapi', []); + .module('app.zooapi', [ + 'app.transcribe.annotations' + ]); From 2caa3874c9c5785501790903165f30f3786b8602 Mon Sep 17 00:00:00 2001 From: Simone Duca Date: Tue, 27 Feb 2018 12:55:02 +0000 Subject: [PATCH 05/15] Improve UX for token refresh failure --- app/modules/zoo-api/zooapi.factory.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/modules/zoo-api/zooapi.factory.js b/app/modules/zoo-api/zooapi.factory.js index bf91845..686cf85 100644 --- a/app/modules/zoo-api/zooapi.factory.js +++ b/app/modules/zoo-api/zooapi.factory.js @@ -4,20 +4,18 @@ require('./zooapi.module.js') .factory('zooAPI', zooAPI); var ApiClient = require('panoptes-client/lib/api-client'); -var OAuth = require('panoptes-client/lib/oauth') +var oauth = require('panoptes-client/lib/oauth') // @ngInject -function zooAPI(AnnotationsFactory, $location, $rootScope) { +function zooAPI(AnnotationsFactory, $location) { ApiClient.beforeEveryRequest = function() { - return OAuth.checkBearerToken() + return oauth.checkBearerToken() .then(function (token) { console.log('Token refreshed: ', token); }) .catch(function (error) { console.log('Failed to refresh token: ', error); - alert('Your session is about to expire. Press "OK" to save your work and get a new session.'); AnnotationsFactory.updateCache(); - OAuth.signIn($location.absUrl()); - $rootScope.$broadcast('auth:loginChange'); + oauth.signIn($location.absUrl()); }) } // There's only a version of this project on production, so rather than From 29b0a2140e117140f80ba958e36d84f2e8010681 Mon Sep 17 00:00:00 2001 From: Simone Duca Date: Thu, 1 Mar 2018 15:15:20 +0000 Subject: [PATCH 06/15] Move check to auth factory --- app/modules/auth/auth.factory.js | 23 ++++++++++++++++++++++- app/modules/zoo-api/zooapi.factory.js | 16 +++------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/app/modules/auth/auth.factory.js b/app/modules/auth/auth.factory.js index d518e66..22d221e 100644 --- a/app/modules/auth/auth.factory.js +++ b/app/modules/auth/auth.factory.js @@ -6,7 +6,7 @@ require('./auth.module.js') var OAuth = require('panoptes-client/lib/oauth'); // @ngInject -function authFactory($interval, $timeout, $location, $window, localStorageService, ModalsFactory, zooAPI, zooAPIConfig, CribsheetFactory, $rootScope) { +function authFactory($location, $rootScope, AnnotationsFactory, zooAPI, CribsheetFactory) { var factory; @@ -17,6 +17,10 @@ function authFactory($interval, $timeout, $location, $window, localStorageServic if (user) { _setUserData(); } + return user; + }) + .then(function(user) { + return zooAPI.beforeEveryRequest = _checkUserAndToken(user); }); factory = { @@ -68,4 +72,21 @@ function authFactory($interval, $timeout, $location, $window, localStorageServic OAuth.signOut(); } + function _checkUserAndToken(user) { + return OAuth.checkBearerToken() + .then(function (token) { + console.log('>>>>>>> just for testing, user and token', user, token); + // The Panoptes client doesn't return an error but just null + // when it can't refresh the token. + if (user && token === null) { + // We are logged in but don't have a token any more. + // Need to save any unsaved work and redirect to Panoptes for a new token. + alert('Your session is expired. Press OK to save your work and start a new one.') + AnnotationsFactory.updateCache(); + OAuth.signIn($location.absUrl()); + } + console.log('Token refreshed: ', token); + }) + } + } diff --git a/app/modules/zoo-api/zooapi.factory.js b/app/modules/zoo-api/zooapi.factory.js index 686cf85..0029f70 100644 --- a/app/modules/zoo-api/zooapi.factory.js +++ b/app/modules/zoo-api/zooapi.factory.js @@ -4,20 +4,10 @@ require('./zooapi.module.js') .factory('zooAPI', zooAPI); var ApiClient = require('panoptes-client/lib/api-client'); -var oauth = require('panoptes-client/lib/oauth') + // @ngInject -function zooAPI(AnnotationsFactory, $location) { - ApiClient.beforeEveryRequest = function() { - return oauth.checkBearerToken() - .then(function (token) { - console.log('Token refreshed: ', token); - }) - .catch(function (error) { - console.log('Failed to refresh token: ', error); - AnnotationsFactory.updateCache(); - oauth.signIn($location.absUrl()); - }) - } +function zooAPI() { + // There's only a version of this project on production, so rather than // defer to the client we manually override the API root. // Panoptes.apiClient.root = 'https://www.zooniverse.org/api'; From d770466d17a903d313fa92fb638f49947326b555 Mon Sep 17 00:00:00 2001 From: Simone Duca Date: Thu, 1 Mar 2018 16:25:19 +0000 Subject: [PATCH 07/15] Fix silly error --- app/modules/auth/auth.factory.js | 33 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/app/modules/auth/auth.factory.js b/app/modules/auth/auth.factory.js index 22d221e..2660d2e 100644 --- a/app/modules/auth/auth.factory.js +++ b/app/modules/auth/auth.factory.js @@ -20,7 +20,21 @@ function authFactory($location, $rootScope, AnnotationsFactory, zooAPI, Cribshee return user; }) .then(function(user) { - return zooAPI.beforeEveryRequest = _checkUserAndToken(user); + zooAPI.beforeEveryRequest = function() { + return OAuth.checkBearerToken() + .then(function (token) { + // The Panoptes client doesn't return an error but just null + // when it can't refresh the token. + if (user && token === null) { + // We are logged in but don't have a token any more. + // Need to save any unsaved work and redirect to Panoptes for a new token. + alert('Your session is expired. Press OK to save your work and start a new one.') + AnnotationsFactory.updateCache(); + OAuth.signIn($location.absUrl()); + } + console.log('Token refreshed: ', token); + }) + } }); factory = { @@ -72,21 +86,4 @@ function authFactory($location, $rootScope, AnnotationsFactory, zooAPI, Cribshee OAuth.signOut(); } - function _checkUserAndToken(user) { - return OAuth.checkBearerToken() - .then(function (token) { - console.log('>>>>>>> just for testing, user and token', user, token); - // The Panoptes client doesn't return an error but just null - // when it can't refresh the token. - if (user && token === null) { - // We are logged in but don't have a token any more. - // Need to save any unsaved work and redirect to Panoptes for a new token. - alert('Your session is expired. Press OK to save your work and start a new one.') - AnnotationsFactory.updateCache(); - OAuth.signIn($location.absUrl()); - } - console.log('Token refreshed: ', token); - }) - } - } From 834a8dad068d5d73192525a1df16729423bab5f3 Mon Sep 17 00:00:00 2001 From: Simone Duca Date: Mon, 5 Mar 2018 20:39:00 +0000 Subject: [PATCH 08/15] Fixes user check loop. --- app/modules/auth/auth.factory.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/modules/auth/auth.factory.js b/app/modules/auth/auth.factory.js index 2660d2e..348e635 100644 --- a/app/modules/auth/auth.factory.js +++ b/app/modules/auth/auth.factory.js @@ -17,22 +17,20 @@ function authFactory($location, $rootScope, AnnotationsFactory, zooAPI, Cribshee if (user) { _setUserData(); } - return user; }) - .then(function(user) { + .then(function() { zooAPI.beforeEveryRequest = function() { return OAuth.checkBearerToken() .then(function (token) { // The Panoptes client doesn't return an error but just null // when it can't refresh the token. - if (user && token === null) { + if (_user.id && token === null) { // We are logged in but don't have a token any more. // Need to save any unsaved work and redirect to Panoptes for a new token. alert('Your session is expired. Press OK to save your work and start a new one.') AnnotationsFactory.updateCache(); OAuth.signIn($location.absUrl()); } - console.log('Token refreshed: ', token); }) } }); From f3c4e287dec0c603ec1fc4d560b6962ead267db9 Mon Sep 17 00:00:00 2001 From: Simone Duca Date: Wed, 7 Mar 2018 13:10:08 +0000 Subject: [PATCH 09/15] Update client --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 17a7e60..5afa64f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14837,9 +14837,9 @@ "dev": true }, "panoptes-client": { - "version": "2.9.4", - "resolved": "https://registry.npmjs.org/panoptes-client/-/panoptes-client-2.9.4.tgz", - "integrity": "sha1-J7TipkzdAH3qX9eJdbPOtzG3LJ0=", + "version": "2.9.6", + "resolved": "https://registry.npmjs.org/panoptes-client/-/panoptes-client-2.9.6.tgz", + "integrity": "sha1-abQQNSWXLGoaPac9B9ZqoXJF95I=", "dev": true, "requires": { "json-api-client": "3.3.0", diff --git a/package.json b/package.json index 05ff2fc..f8305be 100644 --- a/package.json +++ b/package.json @@ -90,7 +90,7 @@ "nib": "^1.1.0", "node-dir": "0.1.16", "npm": "^5.3.0", - "panoptes-client": "^2.9.4", + "panoptes-client": "^2.9.6", "pretty-hrtime": "^1.0.3", "q": "^1.2.0", "run-sequence": "^2.1.0", From 3ca3b8c9cef436795d1b599cb60ecde16436369a Mon Sep 17 00:00:00 2001 From: Simone Duca Date: Wed, 7 Mar 2018 14:54:51 +0000 Subject: [PATCH 10/15] Break promise chain, maybe --- app/modules/auth/auth.factory.js | 17 ++++++++++------- app/modules/transcribe/transcribe.controller.js | 8 ++++++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/modules/auth/auth.factory.js b/app/modules/auth/auth.factory.js index 348e635..43eb4fb 100644 --- a/app/modules/auth/auth.factory.js +++ b/app/modules/auth/auth.factory.js @@ -6,7 +6,7 @@ require('./auth.module.js') var OAuth = require('panoptes-client/lib/oauth'); // @ngInject -function authFactory($location, $rootScope, AnnotationsFactory, zooAPI, CribsheetFactory) { +function authFactory($location, $rootScope, $state, $transitions, AnnotationsFactory, zooAPI, CribsheetFactory) { var factory; @@ -22,14 +22,17 @@ function authFactory($location, $rootScope, AnnotationsFactory, zooAPI, Cribshee zooAPI.beforeEveryRequest = function() { return OAuth.checkBearerToken() .then(function (token) { - // The Panoptes client doesn't return an error but just null - // when it can't refresh the token. + // The Panoptes client doesn't return an error but just null when it can't refresh the token. + // So we check for null, instead of using a catch block. + if (_user.id && token === null) { // We are logged in but don't have a token any more. - // Need to save any unsaved work and redirect to Panoptes for a new token. - alert('Your session is expired. Press OK to save your work and start a new one.') - AnnotationsFactory.updateCache(); - OAuth.signIn($location.absUrl()); + // alert('Your session is expired. Press OK to save your work and start a new one.') + // Save any unsaved work and redirect to Panoptes for a new token. + // AnnotationsFactory.updateCache(); + // OAuth.signIn($location.absUrl()); + return Promise.reject(new Error('HELP!')); + } }) } diff --git a/app/modules/transcribe/transcribe.controller.js b/app/modules/transcribe/transcribe.controller.js index a5397f3..223fd5b 100644 --- a/app/modules/transcribe/transcribe.controller.js +++ b/app/modules/transcribe/transcribe.controller.js @@ -78,7 +78,8 @@ function TranscribeController($stateParams, $modal, $scope, $window, Annotations function loadSubject() { return SubjectsFactory.$getData($stateParams.subjectSet) .then(subjectLoaded, subjectLoadError) - .then(loadAggregations); + .then(loadAggregations) + .catch(handleErrors); } function openTutorial() { @@ -93,11 +94,14 @@ function TranscribeController($stateParams, $modal, $scope, $window, Annotations vm.subject = SubjectsFactory.current; } + function handleErrors(result) { + return Promise.reject(new Error('Error loading subject')); + } function subjectLoadError(result) { if (result === 'outOfData') { $scope.$broadcast('subject:outOfData'); } else { - console.error('Error loading subject', result); + return Promise.reject(new Error('Error loading subject')); } } From 090cb1727bbd4ef2dc637f95ac81ebdc9c2ea787 Mon Sep 17 00:00:00 2001 From: Simone Duca Date: Wed, 7 Mar 2018 16:12:55 +0000 Subject: [PATCH 11/15] Remove SubjectLoadError --- app/modules/transcribe/transcribe.controller.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/app/modules/transcribe/transcribe.controller.js b/app/modules/transcribe/transcribe.controller.js index 223fd5b..8aea2bc 100644 --- a/app/modules/transcribe/transcribe.controller.js +++ b/app/modules/transcribe/transcribe.controller.js @@ -77,7 +77,7 @@ function TranscribeController($stateParams, $modal, $scope, $window, Annotations function loadSubject() { return SubjectsFactory.$getData($stateParams.subjectSet) - .then(subjectLoaded, subjectLoadError) + .then(subjectLoaded) .then(loadAggregations) .catch(handleErrors); } @@ -97,12 +97,4 @@ function TranscribeController($stateParams, $modal, $scope, $window, Annotations function handleErrors(result) { return Promise.reject(new Error('Error loading subject')); } - function subjectLoadError(result) { - if (result === 'outOfData') { - $scope.$broadcast('subject:outOfData'); - } else { - return Promise.reject(new Error('Error loading subject')); - } - } - } From b156158c84fdd2863caa2fbc9106656a1105bbc0 Mon Sep 17 00:00:00 2001 From: Simone Duca Date: Thu, 8 Mar 2018 11:50:26 +0000 Subject: [PATCH 12/15] Don't catch errors mid-chain. --- app/modules/auth/auth.factory.js | 2 +- app/modules/transcribe/transcribe.controller.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/modules/auth/auth.factory.js b/app/modules/auth/auth.factory.js index 43eb4fb..6977acd 100644 --- a/app/modules/auth/auth.factory.js +++ b/app/modules/auth/auth.factory.js @@ -27,7 +27,7 @@ function authFactory($location, $rootScope, $state, $transitions, AnnotationsFac if (_user.id && token === null) { // We are logged in but don't have a token any more. - // alert('Your session is expired. Press OK to save your work and start a new one.') + alert('Your session is expired. Press OK to save your work and start a new one.') // Save any unsaved work and redirect to Panoptes for a new token. // AnnotationsFactory.updateCache(); // OAuth.signIn($location.absUrl()); diff --git a/app/modules/transcribe/transcribe.controller.js b/app/modules/transcribe/transcribe.controller.js index 8aea2bc..5eb989e 100644 --- a/app/modules/transcribe/transcribe.controller.js +++ b/app/modules/transcribe/transcribe.controller.js @@ -94,7 +94,10 @@ function TranscribeController($stateParams, $modal, $scope, $window, Annotations vm.subject = SubjectsFactory.current; } - function handleErrors(result) { - return Promise.reject(new Error('Error loading subject')); + function handleErrors(error) { + if (error === 'outOfData') { + $scope.$broadcast('subject:outOfData'); + } + console.log('Oh no: ', error) } } From 2a6d6b6de8f0afec6c20b78fbe48acd89b683b3c Mon Sep 17 00:00:00 2001 From: Simone Duca Date: Thu, 8 Mar 2018 12:11:19 +0000 Subject: [PATCH 13/15] Remove catch block to let error propagate to handler. --- app/modules/transcribe/subjects.factory.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/modules/transcribe/subjects.factory.js b/app/modules/transcribe/subjects.factory.js index e4cb9c9..49803ef 100644 --- a/app/modules/transcribe/subjects.factory.js +++ b/app/modules/transcribe/subjects.factory.js @@ -114,10 +114,7 @@ function SubjectsFactory($q, AnnotationsFactory, localStorageService, zooAPI, zo return zooAPI.type('workflows').get(zooAPIConfig.workflow_id) .then(function(wf) { var randomSet = _.sample(wf.links.subject_sets) - return randomSet - }) - .catch(function(error) { - console.log('Error fetching active subject sets', error) + return randomSet; }) } From 0f925ad5c02e7eebdb974dfe341479c89fc307ac Mon Sep 17 00:00:00 2001 From: Simone Duca Date: Thu, 8 Mar 2018 13:58:12 +0000 Subject: [PATCH 14/15] Prevent transcribe page from loading. --- app/modules/auth/auth.factory.js | 30 +++++++++++-------- .../transcribe/transcribe.controller.js | 2 +- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/modules/auth/auth.factory.js b/app/modules/auth/auth.factory.js index 6977acd..06386cb 100644 --- a/app/modules/auth/auth.factory.js +++ b/app/modules/auth/auth.factory.js @@ -6,7 +6,7 @@ require('./auth.module.js') var OAuth = require('panoptes-client/lib/oauth'); // @ngInject -function authFactory($location, $rootScope, $state, $transitions, AnnotationsFactory, zooAPI, CribsheetFactory) { +function authFactory($location, $rootScope, $state, $transitions, $window, AnnotationsFactory, zooAPI, CribsheetFactory) { var factory; @@ -22,18 +22,22 @@ function authFactory($location, $rootScope, $state, $transitions, AnnotationsFac zooAPI.beforeEveryRequest = function() { return OAuth.checkBearerToken() .then(function (token) { - // The Panoptes client doesn't return an error but just null when it can't refresh the token. - // So we check for null, instead of using a catch block. - - if (_user.id && token === null) { - // We are logged in but don't have a token any more. - alert('Your session is expired. Press OK to save your work and start a new one.') - // Save any unsaved work and redirect to Panoptes for a new token. - // AnnotationsFactory.updateCache(); - // OAuth.signIn($location.absUrl()); - return Promise.reject(new Error('HELP!')); - - } + // We catch any request to access the transcribe route. + $transitions.onStart({ to: 'Transcribe'}, function(transition) { + token = $window.sessionStorage.getItem('panoptesClientOAuth_tokenDetails'); + // The Panoptes client doesn't return an error but just null when it can't refresh the token. + // So we check for null, instead of using a catch block. + if (_user.id && token === null) { + // We're logged in but don't have a token any more. + alert('Your session is expired. Press OK to save your work and start a new one.') + // Save any unsaved work and redirect to Panoptes for a new token. + AnnotationsFactory.updateCache(); + OAuth.signIn($location.absUrl()); + // Abort ui-router state transition + return Promise.reject(new Error('ui-router transition aborted')); + } + } + ) }) } }); diff --git a/app/modules/transcribe/transcribe.controller.js b/app/modules/transcribe/transcribe.controller.js index 5eb989e..6e57965 100644 --- a/app/modules/transcribe/transcribe.controller.js +++ b/app/modules/transcribe/transcribe.controller.js @@ -98,6 +98,6 @@ function TranscribeController($stateParams, $modal, $scope, $window, Annotations if (error === 'outOfData') { $scope.$broadcast('subject:outOfData'); } - console.log('Oh no: ', error) + console.log(error); } } From 9469307d9b1e34006f8ae118f12e7a50c1755a15 Mon Sep 17 00:00:00 2001 From: Simone Duca Date: Thu, 8 Mar 2018 15:16:29 +0000 Subject: [PATCH 15/15] Remove route check. --- app/modules/auth/auth.factory.js | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/app/modules/auth/auth.factory.js b/app/modules/auth/auth.factory.js index 06386cb..e63f37a 100644 --- a/app/modules/auth/auth.factory.js +++ b/app/modules/auth/auth.factory.js @@ -22,22 +22,17 @@ function authFactory($location, $rootScope, $state, $transitions, $window, Annot zooAPI.beforeEveryRequest = function() { return OAuth.checkBearerToken() .then(function (token) { - // We catch any request to access the transcribe route. - $transitions.onStart({ to: 'Transcribe'}, function(transition) { - token = $window.sessionStorage.getItem('panoptesClientOAuth_tokenDetails'); - // The Panoptes client doesn't return an error but just null when it can't refresh the token. - // So we check for null, instead of using a catch block. - if (_user.id && token === null) { - // We're logged in but don't have a token any more. - alert('Your session is expired. Press OK to save your work and start a new one.') - // Save any unsaved work and redirect to Panoptes for a new token. - AnnotationsFactory.updateCache(); - OAuth.signIn($location.absUrl()); - // Abort ui-router state transition - return Promise.reject(new Error('ui-router transition aborted')); - } - } - ) + // The Panoptes client doesn't return an error but just null when it can't refresh the token. + // So we check for null, instead of using a catch block. + if (_user.id && token === null) { + // We're logged in but don't have a token any more. + alert('Your session is expired. Press OK to save your work and start a new one.') + // Save any unsaved work and redirect to Panoptes for a new token. + AnnotationsFactory.updateCache(); + OAuth.signIn($location.absUrl()); + // Abort ui-router state transition + return Promise.reject(new Error('ui-router transition aborted')); + } }) } });