From 58e8fe0bd04e921afebb1f680db0f369edbc7ae5 Mon Sep 17 00:00:00 2001 From: kevgliss Date: Fri, 13 May 2016 14:35:38 -0700 Subject: [PATCH] Fixes various issues. (#316) --- lemur/authorities/schemas.py | 4 ++-- lemur/authorities/service.py | 6 +++--- lemur/database.py | 3 --- lemur/notifications/service.py | 2 +- lemur/notifications/views.py | 7 +++---- lemur/plugins/views.py | 21 +++++-------------- lemur/roles/schemas.py | 9 ++++---- lemur/roles/views.py | 2 +- lemur/schemas.py | 4 ++++ .../authorities/authority/edit.tpl.html | 6 +++--- .../authorities/authority/extensions.tpl.html | 16 +++++++------- .../authority/permissions.tpl.html | 6 +++--- .../angular/authorities/view/view.tpl.html | 2 +- .../certificates/certificate/options.tpl.html | 16 +++++++------- .../angular/certificates/view/view.tpl.html | 12 +++++------ .../angular/destinations/view/view.tpl.html | 4 ++-- .../notification/notification.js | 2 +- .../notification/notification.tpl.html | 4 ++-- .../angular/notifications/view/view.tpl.html | 4 ++-- .../app/angular/roles/role/role.tpl.html | 6 +++--- .../app/angular/sources/view/view.tpl.html | 4 ++-- lemur/static/app/angular/users/user/user.js | 1 - .../app/angular/users/user/user.tpl.html | 6 +++--- .../app/angular/users/view/view.tpl.html | 2 +- lemur/users/schemas.py | 7 +++---- lemur/users/views.py | 2 +- 26 files changed, 72 insertions(+), 86 deletions(-) diff --git a/lemur/authorities/schemas.py b/lemur/authorities/schemas.py index 773778fb..f1213a68 100644 --- a/lemur/authorities/schemas.py +++ b/lemur/authorities/schemas.py @@ -11,7 +11,7 @@ from marshmallow import fields, validates_schema from marshmallow import validate from marshmallow.exceptions import ValidationError -from lemur.schemas import PluginInputSchema, ExtensionSchema, AssociatedAuthoritySchema, AssociatedRoleSchema +from lemur.schemas import PluginInputSchema, PluginOutputSchema, ExtensionSchema, AssociatedAuthoritySchema, AssociatedRoleSchema from lemur.common.schema import LemurInputSchema, LemurOutputSchema from lemur.common import validators @@ -66,7 +66,7 @@ class AuthorityOutputSchema(LemurOutputSchema): owner = fields.Email() not_before = fields.DateTime() not_after = fields.DateTime() - plugin_name = fields.String() + plugin = fields.Nested(PluginOutputSchema) body = fields.String() chain = fields.String() active = fields.Boolean() diff --git a/lemur/authorities/service.py b/lemur/authorities/service.py index 3bd0dbf0..8c6a7bec 100644 --- a/lemur/authorities/service.py +++ b/lemur/authorities/service.py @@ -47,7 +47,7 @@ def create(kwargs): :return: """ - issuer = kwargs['plugin'] + issuer = kwargs['plugin']['plugin_object'] kwargs['creator'] = g.current_user.email cert_body, intermediate, issuer_roles = issuer.create_authority(kwargs) @@ -77,7 +77,7 @@ def create(kwargs): role = role_service.create( r['name'], password=r['password'], - description="{0} auto generated role".format(kwargs['plugin'].title), + description="{0} auto generated role".format(issuer.title), username=r['username']) # the user creating the authority should be able to administer it @@ -89,7 +89,7 @@ def create(kwargs): authority = Authority( kwargs.get('name'), kwargs['owner'], - kwargs['plugin'].slug, + issuer.slug, cert_body, description=kwargs['description'], chain=intermediate, diff --git a/lemur/database.py b/lemur/database.py index 5caa8160..28c667fd 100644 --- a/lemur/database.py +++ b/lemur/database.py @@ -239,9 +239,6 @@ def update_list(model, model_attr, item_model, items): """ ids = [] - for i in items: - ids.append(i['id']) - for i in getattr(model, model_attr): if i.id not in ids: getattr(model, model_attr).remove(i) diff --git a/lemur/notifications/service.py b/lemur/notifications/service.py index 0c59f965..12fe0162 100644 --- a/lemur/notifications/service.py +++ b/lemur/notifications/service.py @@ -273,7 +273,7 @@ def update(notification_id, label, options, description, active, certificates): notification.options = options notification.description = description notification.active = active - notification = database.update_list(notification, 'certificates', Certificate, certificates) + notification.certificates = certificates return database.update(notification) diff --git a/lemur/notifications/views.py b/lemur/notifications/views.py index 9d7d411d..da665221 100644 --- a/lemur/notifications/views.py +++ b/lemur/notifications/views.py @@ -335,7 +335,7 @@ class Notifications(AuthenticatedResource): return service.update( notification_id, data['label'], - data['notificationOptions'], + data['plugin']['plugin_options'], data['description'], data['active'], data['certificates'] @@ -352,7 +352,7 @@ class CertificateNotifications(AuthenticatedResource): super(CertificateNotifications, self).__init__() @validate_schema(None, notifications_output_schema) - def get(self, certificate_id, data=None): + def get(self, certificate_id): """ .. http:get:: /certificates/1/notifications @@ -426,8 +426,7 @@ class CertificateNotifications(AuthenticatedResource): :reqheader Authorization: OAuth token to authenticate :statuscode 200: no error """ - data['certificate_id'] = certificate_id - return service.render(data) + return service.render({'certificate_id': certificate_id}) api.add_resource(NotificationsList, '/notifications', endpoint='notifications') diff --git a/lemur/plugins/views.py b/lemur/plugins/views.py index d2dd606a..d92d5dc2 100644 --- a/lemur/plugins/views.py +++ b/lemur/plugins/views.py @@ -7,36 +7,25 @@ .. moduleauthor:: Kevin Glisson """ from flask import Blueprint -from flask.ext.restful import Api, reqparse, fields +from flask.ext.restful import Api, reqparse from lemur.auth.service import AuthenticatedResource -from lemur.common.utils import marshal_items +from lemur.schemas import plugins_output_schema, plugin_output_schema +from lemur.common.schema import validate_schema from lemur.plugins.base import plugins mod = Blueprint('plugins', __name__) api = Api(mod) -FIELDS = { - 'title': fields.String, - 'pluginOptions': fields.Raw(attribute='options'), - 'description': fields.String, - 'version': fields.String, - 'author': fields.String, - 'authorUrl': fields.String, - 'type': fields.String, - 'slug': fields.String, -} - - class PluginsList(AuthenticatedResource): """ Defines the 'plugins' endpoint """ def __init__(self): self.reqparse = reqparse.RequestParser() super(PluginsList, self).__init__() - @marshal_items(FIELDS) + @validate_schema(None, plugins_output_schema) def get(self): """ .. http:get:: /plugins @@ -94,7 +83,7 @@ class Plugins(AuthenticatedResource): def __init__(self): super(Plugins, self).__init__() - @marshal_items(FIELDS) + @validate_schema(None, plugin_output_schema) def get(self, name): """ .. http:get:: /plugins/ diff --git a/lemur/roles/schemas.py b/lemur/roles/schemas.py index eb204f38..b2ee3e26 100644 --- a/lemur/roles/schemas.py +++ b/lemur/roles/schemas.py @@ -6,6 +6,8 @@ .. moduleauthor:: Kevin Glisson """ from marshmallow import fields +from lemur.users.schemas import UserOutputSchema +from lemur.authorities.schemas import AuthorityOutputSchema from lemur.common.schema import LemurInputSchema, LemurOutputSchema from lemur.schemas import AssociatedUserSchema, AssociatedAuthoritySchema @@ -23,12 +25,9 @@ class RoleInputSchema(LemurInputSchema): class RoleOutputSchema(LemurOutputSchema): id = fields.Integer() name = fields.String() - username = fields.String() - password = fields.String() description = fields.String() - authorities = fields.Nested(AssociatedAuthoritySchema, many=True) - users = fields.Nested(AssociatedUserSchema, many=True) - users = fields.Nested(AssociatedUserSchema, many=True) + authorities = fields.Nested(AuthorityOutputSchema, many=True) + users = fields.Nested(UserOutputSchema, many=True) role_input_schema = RoleInputSchema() diff --git a/lemur/roles/views.py b/lemur/roles/views.py index d9c4f89f..a2b6ac44 100644 --- a/lemur/roles/views.py +++ b/lemur/roles/views.py @@ -30,7 +30,7 @@ class RolesList(AuthenticatedResource): self.reqparse = reqparse.RequestParser() super(RolesList, self).__init__() - @validate_schema(None, role_output_schema) + @validate_schema(None, roles_output_schema) def get(self): """ .. http:get:: /roles diff --git a/lemur/schemas.py b/lemur/schemas.py index d7dba5b4..3569e242 100644 --- a/lemur/schemas.py +++ b/lemur/schemas.py @@ -118,6 +118,10 @@ class PluginOutputSchema(LemurOutputSchema): title = fields.String() +plugins_output_schema = PluginOutputSchema(many=True) +plugin_output_schema = PluginOutputSchema + + class BaseExtensionSchema(LemurSchema): @pre_load(pass_many=True) def preprocess(self, data, many): diff --git a/lemur/static/app/angular/authorities/authority/edit.tpl.html b/lemur/static/app/angular/authorities/authority/edit.tpl.html index 2d6bfbf9..796b4b63 100644 --- a/lemur/static/app/angular/authorities/authority/edit.tpl.html +++ b/lemur/static/app/angular/authorities/authority/edit.tpl.html @@ -35,9 +35,9 @@
- + @@ -132,12 +132,12 @@
-
-
@@ -149,7 +149,7 @@
-
@@ -161,7 +161,7 @@
-
@@ -180,14 +180,14 @@ Custom
- +
- +
- + diff --git a/lemur/static/app/angular/authorities/authority/permissions.tpl.html b/lemur/static/app/angular/authorities/authority/permissions.tpl.html index 160b8326..8cccbc2f 100644 --- a/lemur/static/app/angular/authorities/authority/permissions.tpl.html +++ b/lemur/static/app/angular/authorities/authority/permissions.tpl.html @@ -5,9 +5,9 @@
diff --git a/lemur/static/app/angular/certificates/certificate/options.tpl.html b/lemur/static/app/angular/certificates/certificate/options.tpl.html index cef3904a..b517ebde 100644 --- a/lemur/static/app/angular/certificates/certificate/options.tpl.html +++ b/lemur/static/app/angular/certificates/certificate/options.tpl.html @@ -10,7 +10,7 @@
- + @@ -139,12 +139,12 @@
-
-
@@ -156,7 +156,7 @@
-
@@ -168,7 +168,7 @@
-
@@ -187,14 +187,14 @@ Custom
- +
- +
- + diff --git a/lemur/static/app/angular/certificates/view/view.tpl.html b/lemur/static/app/angular/certificates/view/view.tpl.html index d2989388..f51d4022 100644 --- a/lemur/static/app/angular/certificates/view/view.tpl.html +++ b/lemur/static/app/angular/certificates/view/view.tpl.html @@ -67,13 +67,13 @@
  • Not Before - + {{ momentService.createMoment(certificate.notBefore) }}
  • Not After - + {{ momentService.createMoment(certificate.notAfter) }}
  • @@ -97,7 +97,7 @@ {{ certificate.serial }}
  • Validity @@ -152,7 +152,7 @@ Chain
    {{ certificate.chain }}
    @@ -161,7 +161,7 @@ Public Certificate
    {{ certificate.body }}
    @@ -170,7 +170,7 @@ Private Key
    {{ certificate.privateKey }}
    diff --git a/lemur/static/app/angular/destinations/view/view.tpl.html b/lemur/static/app/angular/destinations/view/view.tpl.html index 83e9205a..b3615b3c 100644 --- a/lemur/static/app/angular/destinations/view/view.tpl.html +++ b/lemur/static/app/angular/destinations/view/view.tpl.html @@ -30,10 +30,10 @@
    - -
    diff --git a/lemur/static/app/angular/notifications/notification/notification.js b/lemur/static/app/angular/notifications/notification/notification.js index 5eb673e2..d3cfac9b 100644 --- a/lemur/static/app/angular/notifications/notification/notification.js +++ b/lemur/static/app/angular/notifications/notification/notification.js @@ -67,7 +67,7 @@ angular.module('lemur') toaster.pop({ type: 'success', title: notification.label, - body: 'Successfully Created!' + body: 'Successfully Updated!' }); $uibModalInstance.close(); }, function (response) { diff --git a/lemur/static/app/angular/notifications/notification/notification.tpl.html b/lemur/static/app/angular/notifications/notification/notification.tpl.html index 99428cfb..c8e9da70 100644 --- a/lemur/static/app/angular/notifications/notification/notification.tpl.html +++ b/lemur/static/app/angular/notifications/notification/notification.tpl.html @@ -53,8 +53,8 @@
    + uib-typeahead="certificate.name for certificate in certificateService.findCertificatesByName($viewValue)" typeahead-loading="loadingCertificates" + class="form-control input-md" typeahead-on-select="notification.attachCertificate($item)" typeahead-wait-ms="500"> -
    diff --git a/lemur/static/app/angular/roles/role/role.tpl.html b/lemur/static/app/angular/roles/role/role.tpl.html index b4b3b5ce..2aedef57 100644 --- a/lemur/static/app/angular/roles/role/role.tpl.html +++ b/lemur/static/app/angular/roles/role/role.tpl.html @@ -58,9 +58,9 @@
    - diff --git a/lemur/static/app/angular/sources/view/view.tpl.html b/lemur/static/app/angular/sources/view/view.tpl.html index 9655a7e2..6cfc2c34 100644 --- a/lemur/static/app/angular/sources/view/view.tpl.html +++ b/lemur/static/app/angular/sources/view/view.tpl.html @@ -30,10 +30,10 @@
    - -
    diff --git a/lemur/static/app/angular/users/user/user.js b/lemur/static/app/angular/users/user/user.js index c403dd9a..9a95a9f2 100644 --- a/lemur/static/app/angular/users/user/user.js +++ b/lemur/static/app/angular/users/user/user.js @@ -4,7 +4,6 @@ angular.module('lemur') .controller('UsersEditController', function ($scope, $uibModalInstance, UserApi, UserService, RoleService, toaster, editId) { UserApi.get(editId).then(function (user) { - UserService.getRoles(user); $scope.user = user; }); diff --git a/lemur/static/app/angular/users/user/user.tpl.html b/lemur/static/app/angular/users/user/user.tpl.html index 0b867673..9875b57b 100644 --- a/lemur/static/app/angular/users/user/user.tpl.html +++ b/lemur/static/app/angular/users/user/user.tpl.html @@ -56,10 +56,10 @@
    -
    diff --git a/lemur/users/schemas.py b/lemur/users/schemas.py index dd213f04..9960a339 100644 --- a/lemur/users/schemas.py +++ b/lemur/users/schemas.py @@ -15,16 +15,15 @@ class UserInputSchema(LemurInputSchema): email = fields.Email(required=True) password = fields.String(required=True) # TODO add complexity requirements active = fields.Boolean() - roles = fields.Nested(AssociatedRoleSchema, many=True) - certificates = fields.Nested(AssociatedCertificateSchema, many=True) - authorities = fields.Nested(AssociatedAuthoritySchema, many=True) + roles = fields.Nested(AssociatedRoleSchema, many=True, missing=[]) + certificates = fields.Nested(AssociatedCertificateSchema, many=True, missing=[]) + authorities = fields.Nested(AssociatedAuthoritySchema, many=True, missing=[]) class UserOutputSchema(LemurOutputSchema): id = fields.Integer() username = fields.String() email = fields.Email() - password = fields.String() active = fields.Boolean() roles = fields.Nested(AssociatedRoleSchema, many=True) certificates = fields.Nested(AssociatedCertificateSchema, many=True) diff --git a/lemur/users/views.py b/lemur/users/views.py index 2f7f43bc..fe01cad0 100644 --- a/lemur/users/views.py +++ b/lemur/users/views.py @@ -229,7 +229,7 @@ class CertificateUsers(AuthenticatedResource): self.reqparse = reqparse.RequestParser() super(CertificateUsers, self).__init__() - @validate_schema(None, users_output_schema) + @validate_schema(None, user_output_schema) def get(self, certificate_id): """ .. http:get:: /certificates/1/creator