diff --git a/hiboo/application/base.py b/hiboo/application/base.py index fa6a1b46f751ad308f24521e7b3f45d204256669..c20ae1b6f6237e418624106b6d53dadf18623b41 100644 --- a/hiboo/application/base.py +++ b/hiboo/application/base.py @@ -9,6 +9,7 @@ class BaseApplication(object): """ registry = dict() + actions = dict() sso_protocol = None name = None @@ -66,7 +67,20 @@ class BaseApplication(object): class OIDCApplication(BaseApplication): sso_protocol = sso.oidc + class SAMLApplication(BaseApplication): sso_protocol = sso.saml +def action(label, profile=False, quick=False): + """ Registers a profile or application action + """ + class Register(): + def __init__(self, function): + self.function = function + def __set_name__(self, owner, name): + if not owner.actions: + owner.actions = dict() + owner.actions[name] = (label, profile, quick) + setattr(owner, name, self.function) + return Register \ No newline at end of file diff --git a/hiboo/service/admin.py b/hiboo/service/admin.py index bd41a146c48ced2b6ba22129c9ee219a80a4d948..780e59834ae740ac2d63f331f73e91869516bdd4 100644 --- a/hiboo/service/admin.py +++ b/hiboo/service/admin.py @@ -10,7 +10,8 @@ import uuid @security.admin_required() def list(): services = models.Service.query.all() - return flask.render_template("service_list.html", services=services) + return flask.render_template("service_list.html", + services=services, application=application) @blueprint.route("/create") @@ -78,6 +79,19 @@ def delete(service_uuid): return flask.redirect(flask.url_for(".list")) +@blueprint.route("/action/<service_uuid>/<action>", methods=["GET", "POST"]) +@security.admin_required() +def action(service_uuid, action): + service = models.Service.query.get(service_uuid) or flask.abort(404) + app = application.registry.get(service.application_id) or flask.abort(404) + label, profile, quick = app.actions.get(action) or flask.abort(404) + if profile: + flask.abort(404) + result = getattr(app, action)(service) + return flask.render_template("service_action.html", + label=label, service=service, result=result) + + @blueprint.route("/setapp/<service_uuid>") @security.admin_required() def setapp_select(service_uuid): diff --git a/hiboo/service/templates/service_action.html b/hiboo/service/templates/service_action.html new file mode 100644 index 0000000000000000000000000000000000000000..5453afa8e80d5e1a3b26d90a53a965e9d0b2d65e --- /dev/null +++ b/hiboo/service/templates/service_action.html @@ -0,0 +1,15 @@ +{% extends "base.html" %} + +{% block title %}{{ service.name }}{% endblock %} +{% block subtitle %}{{ label }}{% endblock %} + +{% block content %} +<div class="row"> + <div class="col-xs-12"> + <div class="box"> + <div class="box-body"> + {{ result | safe }} + </div> + </div> +</div> +{% endblock %} diff --git a/hiboo/service/templates/service_details.html b/hiboo/service/templates/service_details.html index f54b44af988452b5a52a7ee116321f3d8a6c4b1b..19ca15c2e6c171c401a97912124f9ef43673f5ed 100644 --- a/hiboo/service/templates/service_details.html +++ b/hiboo/service/templates/service_details.html @@ -5,8 +5,11 @@ {% block content %} <div class="row"> - <div class="col-xs-12"> + <div class="col-md-6 col-xs-12"> <div class="box"> + <div class="box-header"> + <h4>{% trans %}Attributes{% endtrans %}</h4> + </div> <div class="box-body"> <dl class="dl-horizontal"> <dt>{% trans %}Service name{% endtrans %}</dt> @@ -30,6 +33,23 @@ </div> </div> </div> + <div class="col-md-6 col-xs-12"> + <div class="box"> + <div class="box-header"> + <h4>{% trans %}Advanced actions{% endtrans %}</h4> + </div> + <div class="box-body"> + <dl class="dl-horizontal"> + {% for action, (label, profile, _) in application.actions.items() %} + {% if not profile %} + <dt><a href="{{ url_for(".action", service_uuid=service.uuid, action=action) }}">{{ label }}</a></dt> + <dd>{{ function.__doc__ }}</dd> + {% endif %} + {% endfor %} + </dl> + </div> + </div> + </div> </div> <div class="row"> <div class="col-xs-12"> @@ -42,6 +62,11 @@ {% endblock %} {% block actions %} +{% for action, (label, profile, quick) in application.actions.items() %} +{% if quick and not profile %} +<a href="{{ url_for(".action", service_uuid=service.uuid, action=action) }}" class="btn btn-info">{{ label }}</a> +{% endif %} +{% endfor %} <a href="{{ url_for("profile.list_for_service", service_uuid=service.uuid) }}" class="btn btn-primary">{% trans %}View profiles{% endtrans %}</a> <a href="{{ url_for(".setapp_select", service_uuid=service.uuid) }}" class="btn btn-primary">{% trans %}Change application{% endtrans %}</a> <a href="{{ url_for(".edit", service_uuid=service.uuid) }}" class="btn btn-primary">{% trans %}Edit this service{% endtrans %}</a> diff --git a/hiboo/service/templates/service_list.html b/hiboo/service/templates/service_list.html index 615ada8f85ad68c64e6abf25be14b4291ddd09e6..fbf82e7a3fbe46e6924d45981b40c24342f8a910 100644 --- a/hiboo/service/templates/service_list.html +++ b/hiboo/service/templates/service_list.html @@ -18,15 +18,21 @@ <th>{% trans %}Actions{% endtrans %}</th> </tr> {% for service in services %} + {% set app = application.registry.get(service.application_id) %} <tr> <td><a href="{{ url_for(".details", service_uuid=service.uuid) }}">{{ service.name }}</a></td> <td>{{ service.provider }}</td> - <td>{{ service.application_id }}</td> + <td>{{ app.name }}</td> <td>{{ service.POLICIES[service.policy] }}</td> <td>{{ service.max_profiles }}</td> <td> - <a href="{{ url_for("profile.list_for_service", service_uuid=service.uuid)}}">Profiles</a> - <a href="{{ url_for(".edit", service_uuid=service.uuid)}}">Edit</a> + <a href="{{ url_for("profile.list_for_service", service_uuid=service.uuid)}}">Profiles</a> + <a href="{{ url_for(".edit", service_uuid=service.uuid)}}">Edit</a> + {% for action, (label, profile, quick) in app.actions.items() %} + {% if quick and not profile %} + <a href="{{ url_for(".action", service_uuid=service.uuid, action=action) }}">{{ label }}</a> + {% endif %} + {% endfor %} </td> </tr> {% endfor %}