diff --git a/lemur/common/utils.py b/lemur/common/utils.py index 4b2d0a00..283b9ef9 100644 --- a/lemur/common/utils.py +++ b/lemur/common/utils.py @@ -63,9 +63,9 @@ class marshal_items(object): if hasattr(e, 'data'): return {'message': e.data['message']}, 400 else: - return {'message': 'unknown'}, 400 + return {'message': {'exception': 'unknown'}}, 400 else: - return {'message': str(e)}, 400 + return {'message': {'exception': str(e)}}, 400 return wrapper diff --git a/lemur/static/app/angular/app.js b/lemur/static/app/angular/app.js index a3e259d7..a4102dac 100644 --- a/lemur/static/app/angular/app.js +++ b/lemur/static/app/angular/app.js @@ -87,9 +87,22 @@ lemur.factory('LemurRestangular', function (Restangular, $location, $auth) { } else { extractedData = data; } + return extractedData; }); + RestangularConfigurer.setErrorInterceptor(function(response) { + if (response.status == 400) { + if (response.data.message) { + var data = ""; + _.each(response.data.message, function (value, key) { + data = data + " " + key + " " + value; + }); + response.data.message = data; + } + } + }); + RestangularConfigurer.addFullRequestInterceptor(function (element, operation, route, url, headers, params) { // We want to make sure the user is auth'd before any requests if (!$auth.isAuthenticated()) { diff --git a/lemur/static/app/angular/authorities/authority/authority.js b/lemur/static/app/angular/authorities/authority/authority.js index be8c4066..1e6ff95d 100644 --- a/lemur/static/app/angular/authorities/authority/authority.js +++ b/lemur/static/app/angular/authorities/authority/authority.js @@ -2,24 +2,32 @@ angular.module('lemur') - .controller('AuthorityEditController', function ($scope, $modalInstance, AuthorityApi, AuthorityService, RoleService, editId){ + .controller('AuthorityEditController', function ($scope, $modalInstance, AuthorityApi, AuthorityService, RoleService, toaster, editId){ AuthorityApi.get(editId).then(function (authority) { AuthorityService.getRoles(authority); $scope.authority = authority; }); - $scope.authorityService = AuthorityService; $scope.roleService = RoleService; $scope.save = function (authority) { AuthorityService.update(authority).then( function () { + toaster.pop({ + type: 'success', + title: authority.name, + body: 'Successfully updated!' + }); $modalInstance.close(); }, - function () { - - } - ); + function (response) { + toaster.pop({ + type: 'error', + title: authority.name, + body: 'Update Failed! ' + response.data.message, + timeout: 100000 + }); + }); }; $scope.cancel = function () { @@ -27,18 +35,31 @@ angular.module('lemur') }; }) - .controller('AuthorityCreateController', function ($scope, $modalInstance, AuthorityService, LemurRestangular, RoleService, PluginService, WizardHandler) { + .controller('AuthorityCreateController', function ($scope, $modalInstance, AuthorityService, LemurRestangular, RoleService, PluginService, WizardHandler, toaster) { $scope.authority = LemurRestangular.restangularizeElement(null, {}, 'authorities'); // set the defaults AuthorityService.getDefaults($scope.authority); - $scope.loading = false; $scope.create = function (authority) { WizardHandler.wizard().context.loading = true; - AuthorityService.create(authority).then(function () { - WizardHandler.wizard().context.loading = false; - $modalInstance.close(); + AuthorityService.create(authority).then( + function () { + toaster.pop({ + type: 'success', + title: authority.name, + body: 'Was created!' + }); + $modalInstance.close(); + }, + function (response) { + toaster.pop({ + type: 'error', + title: authority.name, + body: 'Was not created! ' + response.data.message, + timeout: 100000 + }); + WizardHandler.wizard().context.loading = false; }); }; diff --git a/lemur/static/app/angular/authorities/services.js b/lemur/static/app/angular/authorities/services.js index 235b7ee7..65cdfba3 100644 --- a/lemur/static/app/angular/authorities/services.js +++ b/lemur/static/app/angular/authorities/services.js @@ -80,41 +80,11 @@ angular.module('lemur') AuthorityService.create = function (authority) { authority.attachSubAltName(); - return AuthorityApi.post(authority).then( - function () { - toaster.pop({ - type: 'success', - title: authority.name, - body: 'Successfully created!' - }); - $location.path('/authorities'); - }, - function (response) { - toaster.pop({ - type: 'error', - title: authority.name, - body: 'Was not created! ' + response.data.message - }); - }); + return AuthorityApi.post(authority); }; AuthorityService.update = function (authority) { - return authority.put().then( - function () { - toaster.pop({ - type: 'success', - title: authority.name, - body: 'Successfully updated!' - }); - $location.path('/authorities'); - }, - function (response) { - toaster.pop({ - type: 'error', - title: authority.name, - body: 'Update Failed! ' + response.data.message - }); - }); + return authority.put(); }; AuthorityService.getDefaults = function (authority) { @@ -134,20 +104,7 @@ angular.module('lemur') }; AuthorityService.updateActive = function (authority) { - return authority.put().then( - function () { - toaster.pop({ - type: 'success', - title: authority.name, - body: 'Successfully updated!' - }); - }, - function (response) { - toaster.pop({ - type: 'error', - title: authority.name, - body: 'Update Failed! ' + response.data.message - }); - }); + return authority.put(); }; + }); diff --git a/lemur/static/app/angular/authorities/view/view.js b/lemur/static/app/angular/authorities/view/view.js index 8ae7343b..f7f68f31 100644 --- a/lemur/static/app/angular/authorities/view/view.js +++ b/lemur/static/app/angular/authorities/view/view.js @@ -16,7 +16,7 @@ angular.module('lemur') }); }) - .controller('AuthoritiesViewController', function ($scope, $q, $modal, $stateParams, AuthorityApi, AuthorityService, ngTableParams) { + .controller('AuthoritiesViewController', function ($scope, $q, $modal, $stateParams, AuthorityApi, AuthorityService, ngTableParams, toaster) { $scope.filter = $stateParams; $scope.authoritiesTable = new ngTableParams({ page: 1, // show first page @@ -38,7 +38,24 @@ angular.module('lemur') } }); - $scope.authorityService = AuthorityService; + $scope.updateActive = function (authority) { + AuthorityService.updateActive(authority).then( + function () { + toaster.pop({ + type: 'success', + title: authority.name, + body: 'Successfully updated!' + }); + }, + function (response) { + toaster.pop({ + type: 'error', + title: authority.name, + body: 'Update Failed! ' + response.data.message, + timeout: 100000 + }); + }); + }; $scope.getAuthorityStatus = function () { var def = $q.defer(); diff --git a/lemur/static/app/angular/authorities/view/view.tpl.html b/lemur/static/app/angular/authorities/view/view.tpl.html index 5bbc2e30..65a4c524 100644 --- a/lemur/static/app/angular/authorities/view/view.tpl.html +++ b/lemur/static/app/angular/authorities/view/view.tpl.html @@ -24,7 +24,7 @@
- +
@@ -35,7 +35,7 @@ - Permalink + Permalink
diff --git a/lemur/static/app/angular/certificates/certificate/certificate.js b/lemur/static/app/angular/certificates/certificate/certificate.js index a7a1c374..4fd1d67f 100644 --- a/lemur/static/app/angular/certificates/certificate/certificate.js +++ b/lemur/static/app/angular/certificates/certificate/certificate.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('lemur') - .controller('CertificateEditController', function ($scope, $modalInstance, CertificateApi, CertificateService, DestinationService, NotificationService, editId) { + .controller('CertificateEditController', function ($scope, $modalInstance, CertificateApi, CertificateService, DestinationService, NotificationService, toaster, editId) { CertificateApi.get(editId).then(function (certificate) { CertificateService.getNotifications(certificate); CertificateService.getDestinations(certificate); @@ -13,16 +13,30 @@ angular.module('lemur') }; $scope.save = function (certificate) { - CertificateService.update(certificate).then(function () { - $modalInstance.close(); - }); + CertificateService.update(certificate).then( + function () { + toaster.pop({ + type: 'success', + title: certificate.name, + body: 'Successfully updated!' + }); + $modalInstance.close(); + }, + function (response) { + toaster.pop({ + type: 'error', + title: certificate.name, + body: 'Failed to update ' + response.data.message, + timeout: 100000 + }); + }); }; $scope.destinationService = DestinationService; $scope.notificationService = NotificationService; }) - .controller('CertificateCreateController', function ($scope, $modalInstance, CertificateApi, CertificateService, DestinationService, AuthorityService, PluginService, MomentService, WizardHandler, LemurRestangular, NotificationService) { + .controller('CertificateCreateController', function ($scope, $modalInstance, CertificateApi, CertificateService, DestinationService, AuthorityService, PluginService, MomentService, WizardHandler, LemurRestangular, NotificationService, toaster) { $scope.certificate = LemurRestangular.restangularizeElement(null, {}, 'certificates'); // set the defaults @@ -30,10 +44,24 @@ angular.module('lemur') $scope.create = function (certificate) { WizardHandler.wizard().context.loading = true; - CertificateService.create(certificate).then(function () { - WizardHandler.wizard().context.loading = false; - $modalInstance.close(); - }); + CertificateService.create(certificate).then( + function () { + toaster.pop({ + type: 'success', + title: certificate.name, + body: 'Successfully created!' + }); + $modalInstance.close(); + }, + function (response) { + toaster.pop({ + type: 'error', + title: certificate.name, + body: 'Was not created! ' + response.data.message, + timeout: 100000 + }); + WizardHandler.wizard().context.loading = false; + }); }; $scope.templates = [ diff --git a/lemur/static/app/angular/certificates/certificate/edit.tpl.html b/lemur/static/app/angular/certificates/certificate/edit.tpl.html index aff493e3..8d9ad38a 100644 --- a/lemur/static/app/angular/certificates/certificate/edit.tpl.html +++ b/lemur/static/app/angular/certificates/certificate/edit.tpl.html @@ -23,7 +23,7 @@ Description
- +

You must give a short description about this authority will be used for, this description should only include alphanumeric characters

diff --git a/lemur/static/app/angular/certificates/certificate/upload.js b/lemur/static/app/angular/certificates/certificate/upload.js index 6d51a1b4..cf8bd11b 100644 --- a/lemur/static/app/angular/certificates/certificate/upload.js +++ b/lemur/static/app/angular/certificates/certificate/upload.js @@ -2,7 +2,7 @@ angular.module('lemur') - .controller('CertificateUploadController', function ($scope, $modalInstance, CertificateService, LemurRestangular, DestinationService, NotificationService, PluginService) { + .controller('CertificateUploadController', function ($scope, $modalInstance, CertificateService, LemurRestangular, DestinationService, NotificationService, PluginService, toaster) { $scope.certificate = LemurRestangular.restangularizeElement(null, {}, 'certificates'); $scope.upload = CertificateService.upload; @@ -14,9 +14,23 @@ angular.module('lemur') }); $scope.save = function (certificate) { - CertificateService.upload(certificate).then(function () { - $modalInstance.close(); - }); + CertificateService.upload(certificate).then( + function () { + toaster.pop({ + type: 'success', + title: certificate.name, + body: 'Successfully uploaded!' + }); + $modalInstance.close(); + }, + function (response) { + toaster.pop({ + type: 'error', + title: certificate.name, + body: 'Failed to upload ' + response.data.message, + timeout: 100000 + }); + }); }; $scope.cancel = function () { diff --git a/lemur/static/app/angular/certificates/services.js b/lemur/static/app/angular/certificates/services.js index fff61221..a9bf03f8 100644 --- a/lemur/static/app/angular/certificates/services.js +++ b/lemur/static/app/angular/certificates/services.js @@ -100,80 +100,15 @@ angular.module('lemur') CertificateService.create = function (certificate) { certificate.attachSubAltName(); - return CertificateApi.post(certificate).then( - function () { - toaster.pop({ - type: 'success', - title: certificate.name, - body: 'Successfully created!' - }); - }, - function (response) { - toaster.pop({ - type: 'error', - title: certificate.name, - body: 'Was not created! ' + response.data.message - }); - } - ); + return CertificateApi.post(certificate); }; CertificateService.update = function (certificate) { - return LemurRestangular.copy(certificate).put().then( - function () { - toaster.pop({ - type: 'success', - title: certificate.name, - body: 'Successfully updated!' - }); - }, - function (response) { - toaster.pop({ - type: 'error', - title: certificate.name, - body: 'Failed to update ' + response.data.message - }); - }); + return LemurRestangular.copy(certificate).put(); }; CertificateService.upload = function (certificate) { - return CertificateApi.customPOST(certificate, 'upload').then( - function () { - toaster.pop({ - type: 'success', - title: certificate.name, - body: 'Successfully uploaded!' - }); - }, - function (response) { - toaster.pop({ - type: 'error', - title: certificate.name, - body: 'Failed to upload ' + response.data.message - }); - }); - }; - - CertificateService.loadPrivateKey = function (certificate) { - return certificate.customGET('key').then( - function (response) { - if (response.key === null) { - toaster.pop({ - type: 'warning', - title: certificate.name, - body: 'No private key found!' - }); - } else { - certificate.privateKey = response.key; - } - }, - function () { - toaster.pop({ - type: 'error', - title: certificate.name, - body: 'You do not have permission to view this key!' - }); - }); + return CertificateApi.customPOST(certificate, 'upload'); }; CertificateService.getAuthority = function (certificate) { @@ -216,22 +151,12 @@ angular.module('lemur') }); }; + CertificateService.loadPrivateKey = function (certificate) { + return certificate.customGET('key'); + }; + CertificateService.updateActive = function (certificate) { - return certificate.put().then( - function () { - toaster.pop({ - type: 'success', - title: certificate.name, - body: 'Successfully updated!' - }); - }, - function (response) { - toaster.pop({ - type: 'error', - title: certificate.name, - body: 'Was not updated! ' + response.data.message - }); - }); + return certificate.put(); }; return CertificateService; diff --git a/lemur/static/app/angular/certificates/view/view.js b/lemur/static/app/angular/certificates/view/view.js index beedb618..c987a901 100644 --- a/lemur/static/app/angular/certificates/view/view.js +++ b/lemur/static/app/angular/certificates/view/view.js @@ -17,7 +17,7 @@ angular.module('lemur') }); }) - .controller('CertificatesViewController', function ($q, $scope, $modal, $stateParams, CertificateApi, CertificateService, MomentService, ngTableParams) { + .controller('CertificatesViewController', function ($q, $scope, $modal, $stateParams, CertificateApi, CertificateService, MomentService, ngTableParams, toaster) { $scope.filter = $stateParams; $scope.certificateTable = new ngTableParams({ page: 1, // show first page @@ -45,15 +45,64 @@ angular.module('lemur') } }); - $scope.certificateService = CertificateService; $scope.momentService = MomentService; $scope.remove = function (certificate) { - certificate.remove().then(function () { - $scope.certificateTable.reload(); - }); + certificate.remove().then( + function () { + $scope.certificateTable.reload(); + }, + function (response) { + toaster.pop({ + type: 'error', + title: certificate.name, + body: 'Unable to remove certificate! ' + response.data.message, + timeout: 100000 + }); + }); }; + $scope.loadPrivateKey = function (certificate) { + CertificateService.loadPrivateKey(certificate).then( + function (response) { + if (response.key === null) { + toaster.pop({ + type: 'warning', + title: certificate.name, + body: 'No private key found!' + }); + } else { + certificate.privateKey = response.key; + } + }, + function () { + toaster.pop({ + type: 'error', + title: certificate.name, + body: 'You do not have permission to view this key!', + timeout: 100000 + }); + }); + }; + + $scope.updateActive = function (certificate) { + CertificateService.updateActive(certificate).then( + function () { + toaster.pop({ + type: 'success', + title: certificate.name, + body: 'Updated!' + }); + }, + function (response) { + toaster.pop({ + type: 'error', + title: certificate.name, + body: 'Unable to update! ' + response.data.message, + timeout: 100000 + }); + }); + }; $scope.getCertificateStatus = function () { var def = $q.defer(); def.resolve([{'title': 'Active', 'id': true}, {'title': 'Inactive', 'id': false}]); diff --git a/lemur/static/app/angular/certificates/view/view.tpl.html b/lemur/static/app/angular/certificates/view/view.tpl.html index dc5ea575..4eb384dd 100644 --- a/lemur/static/app/angular/certificates/view/view.tpl.html +++ b/lemur/static/app/angular/certificates/view/view.tpl.html @@ -32,7 +32,7 @@
-
@@ -158,7 +158,7 @@
{{ certificate.body }}
- + Private Key