Allows authorities to have editable owners and descriptions

This commit is contained in:
kevgliss 2015-09-01 14:05:32 -07:00
parent 3fb226ec11
commit 46a5355377
6 changed files with 67 additions and 13 deletions

View File

@ -22,7 +22,7 @@ from lemur.certificates.models import Certificate
from lemur.plugins.base import plugins from lemur.plugins.base import plugins
def update(authority_id, active=None, roles=None): def update(authority_id, description=None, owner=None, active=None, roles=None):
""" """
Update a an authority with new values. Update a an authority with new values.
@ -37,6 +37,9 @@ def update(authority_id, active=None, roles=None):
if active: if active:
authority.active = active authority.active = active
authority.description = description
authority.owner = owner
return database.update(authority) return database.update(authority)

View File

@ -20,6 +20,7 @@ from lemur.common.utils import paginated_parser, marshal_items
FIELDS = { FIELDS = {
'name': fields.String, 'name': fields.String,
'owner': fields.String,
'description': fields.String, 'description': fields.String,
'options': fields.Raw, 'options': fields.Raw,
'pluginName': fields.String, 'pluginName': fields.String,
@ -264,7 +265,9 @@ class Authorities(AuthenticatedResource):
{ {
"roles": [], "roles": [],
"active": false "active": false,
"owner": "bob@example.com",
"description": "this is authority1"
} }
**Example response**: **Example response**:
@ -279,12 +282,12 @@ class Authorities(AuthenticatedResource):
"id": 1, "id": 1,
"name": "authority1", "name": "authority1",
"description": "this is authority1", "description": "this is authority1",
"pluginname": null, "pluginName": null,
"chain": "-----begin ...", "chain": "-----begin ...",
"body": "-----begin ...", "body": "-----begin ...",
"active": false, "active": false,
"notbefore": "2015-06-05t17:09:39", "notBefore": "2015-06-05t17:09:39",
"notafter": "2015-06-10t17:09:39" "notAfter": "2015-06-10t17:09:39"
"options": null "options": null
} }
@ -292,8 +295,10 @@ class Authorities(AuthenticatedResource):
:statuscode 200: no error :statuscode 200: no error
:statuscode 403: unauthenticated :statuscode 403: unauthenticated
""" """
self.reqparse.add_argument('roles', type=list, location='json') self.reqparse.add_argument('roles', type=list, default=[], location='json')
self.reqparse.add_argument('active', type=str, location='json') self.reqparse.add_argument('active', type=str, location='json', required=True)
self.reqparse.add_argument('owner', type=str, location='json', required=True)
self.reqparse.add_argument('description', type=str, location='json', required=True)
args = self.reqparse.parse_args() args = self.reqparse.parse_args()
authority = service.get(authority_id) authority = service.get(authority_id)
@ -315,7 +320,13 @@ class Authorities(AuthenticatedResource):
return dict(message="You are not allowed to associate a role which you are not a member of"), 400 return dict(message="You are not allowed to associate a role which you are not a member of"), 400
if permission.can(): if permission.can():
return service.update(authority_id, active=args['active'], roles=args['roles']) return service.update(
authority_id,
owner=args['owner'],
description=args['description'],
active=args['active'],
roles=args['roles']
)
return dict(message="You are not authorized to update this authority"), 403 return dict(message="You are not authorized to update this authority"), 403

View File

@ -1,9 +1,32 @@
<div class="modal-header"> <div class="modal-header">
<div class="modal-title"> <div class="modal-title">
<div class="modal-header">Edit Authority <span class="text-muted"><small>chain of command!</small></span></div> <h3 class="modal-header">Edit <span class="text-muted"><small>{{ authority.name }}</small></span></h3>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<form name="createForm" class="form-horizontal" role="form" novalidate> <form name="createForm" class="form-horizontal" role="form" novalidate>
<div class="form-group"
ng-class="{'has-error': editForm.owner.$invalid, 'has-success': !editForm.owner.$invalid&&editForm.owner.$dirty}">
<label class="control-label col-sm-2">
Owner
</label>
<div class="col-sm-10">
<input type="email" name="owner" ng-model="authority.owner" placeholder="owner@netflix.com"
class="form-control" required/>
<p ng-show="editForm.owner.$invalid && !editForm.owner.$pristine" class="help-block">Enter a valid
email.</p>
</div>
</div>
<div class="form-group"
ng-class="{'has-error': editForm.description.$invalid, 'has-success': !editForm.$invalid&&editForm.description.$dirty}">
<label class="control-label col-sm-2">
Description
</label>
<div class="col-sm-10">
<textarea name="description" ng-model="authority.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>
</div>
</div>
<div class="form-group"> <div class="form-group">
<label class="control-label col-sm-2"> <label class="control-label col-sm-2">
Roles Roles

View File

@ -46,7 +46,7 @@ angular.module('lemur')
$scope.edit = function (authorityId) { $scope.edit = function (authorityId) {
var modalInstance = $modal.open({ var modalInstance = $modal.open({
animation: true, animation: true,
templateUrl: '/angular/authorities/authority/authorityEdit.tpl.html', templateUrl: '/angular/authorities/authority/edit.tpl.html',
controller: 'AuthorityEditController', controller: 'AuthorityEditController',
size: 'lg', size: 'lg',
resolve: { resolve: {
@ -62,6 +62,25 @@ angular.module('lemur')
}; };
$scope.editRole = function (roleId) {
var modalInstance = $modal.open({
animation: true,
templateUrl: '/angular/roles/role/role.tpl.html',
controller: 'RolesEditController',
size: 'lg',
resolve: {
editId: function () {
return roleId;
}
}
});
modalInstance.result.then(function () {
$scope.authoritiesTable.reload();
});
};
$scope.create = function () { $scope.create = function () {
var modalInstance = $modal.open({ var modalInstance = $modal.open({
animation: true, animation: true,

View File

@ -29,7 +29,7 @@
</td> </td>
<td data-title="'Roles'"> <!--filter="{ 'select': 'role' }" filter-data="roleService.getRoleDropDown()">--> <td data-title="'Roles'"> <!--filter="{ 'select': 'role' }" filter-data="roleService.getRoleDropDown()">-->
<div class="btn-group"> <div class="btn-group">
<a href="#/roles/{{ role.id }}/edit" ng-repeat="role in authority.roles" class="btn btn-sm btn-danger"> <a ng-click="editRole(role.id)" ng-repeat="role in authority.roles" class="btn btn-sm btn-danger">
{{ role.name }} {{ role.name }}
</a> </a>
</div> </div>

View File

@ -55,7 +55,6 @@ angular.module('lemur')
title: role.name, title: role.name,
body: 'Has been successfully created!' body: 'Has been successfully created!'
}); });
$location.path('roles');
}, },
function (response) { function (response) {
toaster.pop({ toaster.pop({
@ -74,7 +73,6 @@ angular.module('lemur')
title: role.name, title: role.name,
body: 'Successfully updated!' body: 'Successfully updated!'
}); });
$location.path('roles');
}, },
function (response) { function (response) {
toaster.pop({ toaster.pop({