From bdb86fdc10685fb0a072b89b4db3130379a5b759 Mon Sep 17 00:00:00 2001 From: EvB Date: Thu, 5 Jan 2017 15:25:41 -0500 Subject: [PATCH 1/2] fix(js/set-repo-permissions): chk not null before iterating --- .../js/directives/ui/set-repo-permissions.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/static/js/directives/ui/set-repo-permissions.js b/static/js/directives/ui/set-repo-permissions.js index 5510503c6..5732b7649 100644 --- a/static/js/directives/ui/set-repo-permissions.js +++ b/static/js/directives/ui/set-repo-permissions.js @@ -39,6 +39,9 @@ angular.module('quay').directive('setRepoPermissions', function () { var checkForChanges = function() { var hasChanges = false; + if (!$scope.repositories) { + return; + } $scope.repositories.forEach(function(repo) { if (repo['permission'] != repo['original_permission']) { @@ -51,6 +54,9 @@ angular.module('quay').directive('setRepoPermissions', function () { }; var handleRepoCheckChange = function() { + if (!$scope.repositories) { + return; + } $scope.repositories.forEach(function(repo) { if ($scope.checkedRepos.isChecked(repo)) { if (repo['permission'] == 'none') { @@ -121,6 +127,11 @@ angular.module('quay').directive('setRepoPermissions', function () { $scope.currentNamespace = $scope.namespace; var repos = []; + if (!resp || !resp['repositories'] || resp['repositories'].length == 0) { + $scope.repositoriesLoaded({'repositories': []}); + return; + } + resp['repositories'].forEach(function(repo) { var existingPermission = existingPermissionsMap[repo.name] || 'none'; @@ -134,11 +145,6 @@ angular.module('quay').directive('setRepoPermissions', function () { }); }); - if (repos.length == 0) { - $scope.repositoriesLoaded({'repositories': repos}); - return; - } - $scope.repositories = repos; $scope.checkedRepos = UIService.createCheckStateController($scope.repositories, 'name'); @@ -232,4 +238,4 @@ angular.module('quay').directive('setRepoPermissions', function () { } }; return directiveDefinitionObject; -}); \ No newline at end of file +}); From bd027b9cbc1f72244c2bdf8103713efa4126caeb Mon Sep 17 00:00:00 2001 From: EvB Date: Thu, 5 Jan 2017 15:31:29 -0500 Subject: [PATCH 2/2] fix(js/signin-form): check for resp body first --- static/js/directives/ui/signin-form.js | 29 +++++++++++++++++--------- static/js/services/api-service.js | 2 +- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/static/js/directives/ui/signin-form.js b/static/js/directives/ui/signin-form.js index 1b1d78f90..e21a3ab96 100644 --- a/static/js/directives/ui/signin-form.js +++ b/static/js/directives/ui/signin-form.js @@ -23,10 +23,10 @@ angular.module('quay').directive('signinForm', function () { $scope.signInUser = {}; $scope.markStarted = function() { - $scope.signingIn = true; - if ($scope.signInStarted != null) { - $scope.signInStarted(); - } + $scope.signingIn = true; + if ($scope.signInStarted != null) { + $scope.signInStarted(); + } }; $scope.cancelInterval = function() { @@ -110,6 +110,10 @@ angular.module('quay').directive('signinForm', function () { }, function(result) { $scope.signingIn = false; + if (!result || !result.status /* malformed response */) { + return bootbox.alert(ApiService.getErrorMessage(result)); + } + if (result.status == 429 /* try again later */) { $scope.needsEmailVerification = false; $scope.invalidCredentials = false; @@ -124,13 +128,18 @@ angular.module('quay').directive('signinForm', function () { $scope.cancelInterval(); } }, 1000, $scope.tryAgainSoon); - } else if (result.status == 400) { - bootbox.alert(ApiService.getErrorMessage(result)); - } else { - $scope.needsEmailVerification = result.data.needsEmailVerification; - $scope.invalidCredentials = result.data.invalidCredentials; - $scope.invalidCredentialsMessage = result.data.message; + + return; } + + if (!result.data || result.status == 400 /* bad request */) { + return bootbox.alert(ApiService.getErrorMessage(result)); + } + + /* success - set scope values to response */ + $scope.needsEmailVerification = result.data.needsEmailVerification; + $scope.invalidCredentials = result.data.invalidCredentials; + $scope.invalidCredentialsMessage = result.data.message; }); }; } diff --git a/static/js/services/api-service.js b/static/js/services/api-service.js index 34e026c48..1b1bd275b 100644 --- a/static/js/services/api-service.js +++ b/static/js/services/api-service.js @@ -290,7 +290,7 @@ angular.module('quay').factory('ApiService', ['Restangular', '$q', 'UtilService' apiService.getErrorMessage = function(resp, defaultMessage) { var message = defaultMessage; - if (resp['data']) { + if (resp && resp['data']) { //TODO: remove error_message and error_description (old style error) message = resp['data']['detail'] || resp['data']['error_message'] || resp['data']['message'] || resp['data']['error_description'] || message; }