Skip to content
Snippets Groups Projects
Commit 5884d867 authored by kaiyou's avatar kaiyou
Browse files

Support per service actions

parent a6381135
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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):
......
{% 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 %}
......@@ -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>
......
......@@ -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>&nbsp;
<a href="{{ url_for(".edit", service_uuid=service.uuid)}}">Edit</a>&nbsp;
{% 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>&nbsp;
{% endif %}
{% endfor %}
</td>
</tr>
{% endfor %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment