Merge pull request #148 from kevgliss/120-error-length

Closes #120
This commit is contained in:
kevgliss 2015-11-23 15:25:30 -08:00
commit f0324e4755
12 changed files with 194 additions and 170 deletions

View File

@ -63,9 +63,9 @@ class marshal_items(object):
if hasattr(e, 'data'): if hasattr(e, 'data'):
return {'message': e.data['message']}, 400 return {'message': e.data['message']}, 400
else: else:
return {'message': 'unknown'}, 400 return {'message': {'exception': 'unknown'}}, 400
else: else:
return {'message': str(e)}, 400 return {'message': {'exception': str(e)}}, 400
return wrapper return wrapper

View File

@ -87,9 +87,22 @@ lemur.factory('LemurRestangular', function (Restangular, $location, $auth) {
} else { } else {
extractedData = data; extractedData = data;
} }
return extractedData; 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) { RestangularConfigurer.addFullRequestInterceptor(function (element, operation, route, url, headers, params) {
// We want to make sure the user is auth'd before any requests // We want to make sure the user is auth'd before any requests
if (!$auth.isAuthenticated()) { if (!$auth.isAuthenticated()) {

View File

@ -2,24 +2,32 @@
angular.module('lemur') 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) { AuthorityApi.get(editId).then(function (authority) {
AuthorityService.getRoles(authority); AuthorityService.getRoles(authority);
$scope.authority = authority; $scope.authority = authority;
}); });
$scope.authorityService = AuthorityService;
$scope.roleService = RoleService; $scope.roleService = RoleService;
$scope.save = function (authority) { $scope.save = function (authority) {
AuthorityService.update(authority).then( AuthorityService.update(authority).then(
function () { function () {
toaster.pop({
type: 'success',
title: authority.name,
body: 'Successfully updated!'
});
$modalInstance.close(); $modalInstance.close();
}, },
function () { function (response) {
toaster.pop({
} type: 'error',
); title: authority.name,
body: 'Update Failed! ' + response.data.message,
timeout: 100000
});
});
}; };
$scope.cancel = function () { $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'); $scope.authority = LemurRestangular.restangularizeElement(null, {}, 'authorities');
// set the defaults // set the defaults
AuthorityService.getDefaults($scope.authority); AuthorityService.getDefaults($scope.authority);
$scope.loading = false;
$scope.create = function (authority) { $scope.create = function (authority) {
WizardHandler.wizard().context.loading = true; WizardHandler.wizard().context.loading = true;
AuthorityService.create(authority).then(function () { AuthorityService.create(authority).then(
WizardHandler.wizard().context.loading = false; function () {
toaster.pop({
type: 'success',
title: authority.name,
body: 'Was created!'
});
$modalInstance.close(); $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;
}); });
}; };

View File

@ -56,7 +56,7 @@ angular.module('lemur')
}); });
return LemurRestangular.all('authorities'); return LemurRestangular.all('authorities');
}) })
.service('AuthorityService', function ($location, AuthorityApi, DefaultService, toaster) { .service('AuthorityService', function ($location, AuthorityApi, DefaultService) {
var AuthorityService = this; var AuthorityService = this;
AuthorityService.findAuthorityByName = function (filterValue) { AuthorityService.findAuthorityByName = function (filterValue) {
return AuthorityApi.getList({'filter[name]': filterValue}) return AuthorityApi.getList({'filter[name]': filterValue})
@ -80,41 +80,11 @@ angular.module('lemur')
AuthorityService.create = function (authority) { AuthorityService.create = function (authority) {
authority.attachSubAltName(); authority.attachSubAltName();
return AuthorityApi.post(authority).then( return AuthorityApi.post(authority);
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
});
});
}; };
AuthorityService.update = function (authority) { AuthorityService.update = function (authority) {
return authority.put().then( return authority.put();
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
});
});
}; };
AuthorityService.getDefaults = function (authority) { AuthorityService.getDefaults = function (authority) {
@ -134,20 +104,7 @@ angular.module('lemur')
}; };
AuthorityService.updateActive = function (authority) { AuthorityService.updateActive = function (authority) {
return authority.put().then( return authority.put();
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
});
});
}; };
}); });

View File

@ -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.filter = $stateParams;
$scope.authoritiesTable = new ngTableParams({ $scope.authoritiesTable = new ngTableParams({
page: 1, // show first page 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 () { $scope.getAuthorityStatus = function () {
var def = $q.defer(); var def = $q.defer();

View File

@ -24,7 +24,7 @@
</td> </td>
<td data-title="'Active'" filter="{ 'active': 'select' }" filter-data="getAuthorityStatus()"> <td data-title="'Active'" filter="{ 'active': 'select' }" filter-data="getAuthorityStatus()">
<form> <form>
<switch ng-change="authorityService.updateActive(authority)" id="status" name="status" ng-model="authority.active" class="green small"></switch> <switch ng-change="updateActive(authority)" id="status" name="status" ng-model="authority.active" class="green small"></switch>
</form> </form>
</td> </td>
<td data-title="'Roles'"> <!--filter="{ 'select': 'role' }" filter-data="roleService.getRoleDropDown()">--> <td data-title="'Roles'"> <!--filter="{ 'select': 'role' }" filter-data="roleService.getRoleDropDown()">-->
@ -35,7 +35,7 @@
</div> </div>
</td> </td>
<td data-title="''"> <td data-title="''">
<a ui-sref="authority({'name': '{{ authority.name }}'})">Permalink</a> <a ui-sref="authority({name: authority.name})">Permalink</a>
</td> </td>
<td data-title="''"> <td data-title="''">
<div class="btn-group-vertical pull-right"> <div class="btn-group-vertical pull-right">

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('lemur') 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) { CertificateApi.get(editId).then(function (certificate) {
CertificateService.getNotifications(certificate); CertificateService.getNotifications(certificate);
CertificateService.getDestinations(certificate); CertificateService.getDestinations(certificate);
@ -13,8 +13,22 @@ angular.module('lemur')
}; };
$scope.save = function (certificate) { $scope.save = function (certificate) {
CertificateService.update(certificate).then(function () { CertificateService.update(certificate).then(
function () {
toaster.pop({
type: 'success',
title: certificate.name,
body: 'Successfully updated!'
});
$modalInstance.close(); $modalInstance.close();
},
function (response) {
toaster.pop({
type: 'error',
title: certificate.name,
body: 'Failed to update ' + response.data.message,
timeout: 100000
});
}); });
}; };
@ -22,7 +36,7 @@ angular.module('lemur')
$scope.notificationService = NotificationService; $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'); $scope.certificate = LemurRestangular.restangularizeElement(null, {}, 'certificates');
// set the defaults // set the defaults
@ -30,9 +44,23 @@ angular.module('lemur')
$scope.create = function (certificate) { $scope.create = function (certificate) {
WizardHandler.wizard().context.loading = true; WizardHandler.wizard().context.loading = true;
CertificateService.create(certificate).then(function () { CertificateService.create(certificate).then(
WizardHandler.wizard().context.loading = false; function () {
toaster.pop({
type: 'success',
title: certificate.name,
body: 'Successfully created!'
});
$modalInstance.close(); $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;
}); });
}; };

View File

@ -23,7 +23,7 @@
Description Description
</label> </label>
<div class="col-sm-10"> <div class="col-sm-10">
<textarea name="description" ng-model="certificate.description" placeholder="Something elegant" class="form-control" ng-pattern="/^[\w\-\s]+$/" required></textarea> <textarea name="description" ng-model="certificate.description" placeholder="Something elegant" class="form-control" required></textarea>
<p ng-show="editForm.description.$invalid && !editForm.description.$pristine" class="help-block">You must give a short description about this authority will be used for, this description should only include alphanumeric characters</p> <p ng-show="editForm.description.$invalid && !editForm.description.$pristine" class="help-block">You must give a short description about this authority will be used for, this description should only include alphanumeric characters</p>
</div> </div>
</div> </div>

View File

@ -2,7 +2,7 @@
angular.module('lemur') 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.certificate = LemurRestangular.restangularizeElement(null, {}, 'certificates');
$scope.upload = CertificateService.upload; $scope.upload = CertificateService.upload;
@ -14,8 +14,22 @@ angular.module('lemur')
}); });
$scope.save = function (certificate) { $scope.save = function (certificate) {
CertificateService.upload(certificate).then(function () { CertificateService.upload(certificate).then(
function () {
toaster.pop({
type: 'success',
title: certificate.name,
body: 'Successfully uploaded!'
});
$modalInstance.close(); $modalInstance.close();
},
function (response) {
toaster.pop({
type: 'error',
title: certificate.name,
body: 'Failed to upload ' + response.data.message,
timeout: 100000
});
}); });
}; };

View File

@ -89,7 +89,7 @@ angular.module('lemur')
}); });
return LemurRestangular.all('certificates'); return LemurRestangular.all('certificates');
}) })
.service('CertificateService', function ($location, CertificateApi, LemurRestangular, DefaultService, toaster) { .service('CertificateService', function ($location, CertificateApi, LemurRestangular, DefaultService) {
var CertificateService = this; var CertificateService = this;
CertificateService.findCertificatesByName = function (filterValue) { CertificateService.findCertificatesByName = function (filterValue) {
return CertificateApi.getList({'filter[name]': filterValue}) return CertificateApi.getList({'filter[name]': filterValue})
@ -100,80 +100,15 @@ angular.module('lemur')
CertificateService.create = function (certificate) { CertificateService.create = function (certificate) {
certificate.attachSubAltName(); certificate.attachSubAltName();
return CertificateApi.post(certificate).then( return CertificateApi.post(certificate);
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
});
}
);
}; };
CertificateService.update = function (certificate) { CertificateService.update = function (certificate) {
return LemurRestangular.copy(certificate).put().then( return LemurRestangular.copy(certificate).put();
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
});
});
}; };
CertificateService.upload = function (certificate) { CertificateService.upload = function (certificate) {
return CertificateApi.customPOST(certificate, 'upload').then( return CertificateApi.customPOST(certificate, 'upload');
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!'
});
});
}; };
CertificateService.getAuthority = function (certificate) { CertificateService.getAuthority = function (certificate) {
@ -216,22 +151,12 @@ angular.module('lemur')
}); });
}; };
CertificateService.loadPrivateKey = function (certificate) {
return certificate.customGET('key');
};
CertificateService.updateActive = function (certificate) { CertificateService.updateActive = function (certificate) {
return certificate.put().then( return certificate.put();
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 CertificateService; return CertificateService;

View File

@ -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.filter = $stateParams;
$scope.certificateTable = new ngTableParams({ $scope.certificateTable = new ngTableParams({
page: 1, // show first page page: 1, // show first page
@ -45,15 +45,64 @@ angular.module('lemur')
} }
}); });
$scope.certificateService = CertificateService;
$scope.momentService = MomentService; $scope.momentService = MomentService;
$scope.remove = function (certificate) { $scope.remove = function (certificate) {
certificate.remove().then(function () { certificate.remove().then(
function () {
$scope.certificateTable.reload(); $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 () { $scope.getCertificateStatus = function () {
var def = $q.defer(); var def = $q.defer();
def.resolve([{'title': 'Active', 'id': true}, {'title': 'Inactive', 'id': false}]); def.resolve([{'title': 'Active', 'id': true}, {'title': 'Inactive', 'id': false}]);

View File

@ -32,7 +32,7 @@
</td> </td>
<td data-title="'Active'" filter="{ 'active': 'select' }" filter-data="getCertificateStatus()"> <td data-title="'Active'" filter="{ 'active': 'select' }" filter-data="getCertificateStatus()">
<form> <form>
<switch ng-change="certificateService.updateActive(certificate)" id="status" name="status" <switch ng-change="updateActive(certificate)" id="status" name="status"
ng-model="certificate.active" class="green small"></switch> ng-model="certificate.active" class="green small"></switch>
</form> </form>
</td> </td>
@ -156,7 +156,7 @@
</tab-heading> </tab-heading>
<pre style="width: 100%">{{ certificate.body }}</pre> <pre style="width: 100%">{{ certificate.body }}</pre>
</tab> </tab>
<tab ng-click="certificateService.loadPrivateKey(certificate)"> <tab ng-click="loadPrivateKey(certificate)">
<tab-heading> <tab-heading>
Private Key Private Key
<button class="btn btn-xs btn-default clipboard-btn glyphicon glyphicon-copy" <button class="btn btn-xs btn-default clipboard-btn glyphicon glyphicon-copy"