admin: add source admin

This commit is contained in:
Jens Langhammer 2018-11-26 22:09:04 +01:00
parent caf6580ccb
commit b656cd1139
10 changed files with 126 additions and 60 deletions

View File

@ -8,14 +8,14 @@
<li class="{% is_active 'passbook_admin:overview' %}"> <li class="{% is_active 'passbook_admin:overview' %}">
<a href="{% url 'passbook_admin:overview' %}">{% trans 'Overview' %}</a> <a href="{% url 'passbook_admin:overview' %}">{% trans 'Overview' %}</a>
</li> </li>
<li class="{% is_active 'passbook_admin:applications' %}"> <li class="{% is_active 'passbook_admin:applications' 'passbook_admin:application-create' 'passbook_admin:application-update' 'passbook_admin:application-delete' %}">
<a href="{% url 'passbook_admin:applications' %}">{% trans 'Applications' %}</a> <a href="{% url 'passbook_admin:applications' %}">{% trans 'Applications' %}</a>
</li> </li>
<li class="{% is_active 'passbook_admin:sources' %}"> <li class="{% is_active 'passbook_admin:sources' 'passbook_admin:source-create' 'passbook_admin:source-update' 'passbook_admin:source-delete' %}">
<a href="{% url 'passbook_admin:sources' %}">{% trans 'Sources' %}</a> <a href="{% url 'passbook_admin:sources' %}">{% trans 'Sources' %}</a>
</li> </li>
<li> <li class="{% is_active 'passbook_admin:rules' 'passbook_admin:rule-create' 'passbook_admin:rule-update' 'passbook_admin:rule-delete' %}">
<a href="#">{% trans 'Rules' %}</a> <a href="{% url 'passbook_admin:rules' %}">{% trans 'Rules' %}</a>
</li> </li>
<li> <li>
<a href="#">{% trans 'Users' %}</a> <a href="#">{% trans 'Users' %}</a>

View File

@ -3,51 +3,53 @@
{% load i18n %} {% load i18n %}
{% block content %} {% block content %}
<div class="col-xs-6 col-sm-2 col-md-2"> <div class="container">
<div class="card-pf card-pf-accented card-pf-aggregate-status"> <div class="col-xs-6 col-sm-2 col-md-2">
<h2 class="card-pf-title"> <div class="card-pf card-pf-accented card-pf-aggregate-status">
<a href="#"><span class="fa fa-shield"></span><span class="card-pf-aggregate-status-count"></span> {% trans 'Applications' %}</a> <h2 class="card-pf-title">
</h2> <a href="#"><span class="fa fa-shield"></span><span class="card-pf-aggregate-status-count"></span> {% trans 'Applications' %}</a>
<div class="card-pf-body"> </h2>
<p class="card-pf-aggregate-status-notifications"> <div class="card-pf-body">
<span class="card-pf-aggregate-status-notification"><a href="#"><span class="pficon pficon-ok"></span>{{ application_count }}</a></span> <p class="card-pf-aggregate-status-notifications">
</p> <span class="card-pf-aggregate-status-notification"><a href="#"><span class="pficon pficon-ok"></span>{{ application_count }}</a></span>
</p>
</div>
</div> </div>
</div> </div>
</div> <div class="col-xs-6 col-sm-2 col-md-2">
<div class="col-xs-6 col-sm-2 col-md-2"> <div class="card-pf card-pf-accented card-pf-aggregate-status">
<div class="card-pf card-pf-accented card-pf-aggregate-status"> <h2 class="card-pf-title">
<h2 class="card-pf-title"> <a href="#"><span class="fa fa-shield"></span><span class="card-pf-aggregate-status-count"></span> {% trans 'Providers' %}</a>
<a href="#"><span class="fa fa-shield"></span><span class="card-pf-aggregate-status-count"></span> {% trans 'Providers' %}</a> </h2>
</h2> <div class="card-pf-body">
<div class="card-pf-body"> <p class="card-pf-aggregate-status-notifications">
<p class="card-pf-aggregate-status-notifications"> <span class="card-pf-aggregate-status-notification"><a href="#"><span class="pficon pficon-ok"></span>{{ provider_count }}</a></span>
<span class="card-pf-aggregate-status-notification"><a href="#"><span class="pficon pficon-ok"></span>{{ provider_count }}</a></span> </p>
</p> </div>
</div> </div>
</div> </div>
</div> <div class="col-xs-6 col-sm-2 col-md-2">
<div class="col-xs-6 col-sm-2 col-md-2"> <div class="card-pf card-pf-accented card-pf-aggregate-status">
<div class="card-pf card-pf-accented card-pf-aggregate-status"> <h2 class="card-pf-title">
<h2 class="card-pf-title"> <a href="#"><span class="fa fa-shield"></span><span class="card-pf-aggregate-status-count"></span> {% trans 'Rules' %}</a>
<a href="#"><span class="fa fa-shield"></span><span class="card-pf-aggregate-status-count"></span> {% trans 'Rules' %}</a> </h2>
</h2> <div class="card-pf-body">
<div class="card-pf-body"> <p class="card-pf-aggregate-status-notifications">
<p class="card-pf-aggregate-status-notifications"> <span class="card-pf-aggregate-status-notification"><a href="#"><span class="pficon pficon-ok"></span>{{ rule_count }}</a></span>
<span class="card-pf-aggregate-status-notification"><a href="#"><span class="pficon pficon-ok"></span>{{ rule_count }}</a></span> </p>
</p> </div>
</div> </div>
</div> </div>
</div> <div class="col-xs-6 col-sm-2 col-md-2">
<div class="col-xs-6 col-sm-2 col-md-2"> <div class="card-pf card-pf-accented card-pf-aggregate-status">
<div class="card-pf card-pf-accented card-pf-aggregate-status"> <h2 class="card-pf-title">
<h2 class="card-pf-title"> <a href="#"><span class="fa fa-shield"></span><span class="card-pf-aggregate-status-count"></span> {% trans 'Users' %}</a>
<a href="#"><span class="fa fa-shield"></span><span class="card-pf-aggregate-status-count"></span> {% trans 'Users' %}</a> </h2>
</h2> <div class="card-pf-body">
<div class="card-pf-body"> <p class="card-pf-aggregate-status-notifications">
<p class="card-pf-aggregate-status-notifications"> <span class="card-pf-aggregate-status-notification"><a href="#"><span class="pficon pficon-ok"></span>{{ user_count }}</a></span>
<span class="card-pf-aggregate-status-notification"><a href="#"><span class="pficon pficon-ok"></span>{{ user_count }}</a></span> </p>
</p> </div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -0,0 +1,11 @@
{% extends "generic/create.html" %}
{% load i18n %}
{% block title %}
{% blocktrans with type=request.GET.type %}Create {{ type }}{% endblocktrans %}
{% endblock %}
{% block above_form %}
<h1>{% blocktrans with type=request.GET.type %}Create {{ type }}{% endblocktrans %}</h1>
{% endblock %}

View File

@ -1,18 +1,41 @@
{% extends "generic/list.html" %} {% extends "administration/base.html" %}
{% load i18n %} {% load i18n %}
{% load utils %}
{% block above_table %} {% block content %}
<div class="dropdown"> <div class="container">
<button class="btn btn-primary dropdown-toggle" type="button" id="createDropdown" data-toggle="dropdown"> <div class="dropdown">
{% trans 'Create...' %} <button class="btn btn-primary dropdown-toggle" type="button" id="createDropdown" data-toggle="dropdown">
<span class="caret"></span> {% trans 'Create...' %}
</button> <span class="caret"></span>
<ul class="dropdown-menu" role="menu" aria-labelledby="createDropdown"> </button>
{% for type, name in types.items %} <ul class="dropdown-menu" role="menu" aria-labelledby="createDropdown">
<li role="presentation"><a role="menuitem" tabindex="-1" href="{% url 'passbook_admin:source-create' %}?type={{ type }}">{{ name }}</a></li> {% for type, name in types.items %}
{% endfor %} <li role="presentation"><a role="menuitem" tabindex="-1" href="{% url 'passbook_admin:source-create' %}?type={{ type }}">{{ name }}</a></li>
</ul> {% endfor %}
</ul>
</div>
<hr>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>{% trans 'Name' %}</th>
<th>{% trans 'Class' %}</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
{% for source in object_list %}
<tr>
<td>{{ source.name }}</td>
<td>{{ source.cast|fieldtype }}</td>
<td><a href="{% url 'passbook_admin:source-update' pk=source.uuid %}">{% trans 'Edit' %}</a></td>
<td><a href="{% url 'passbook_admin:source-delete' pk=source.uuid %}">{% trans 'Delete' %}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div> </div>
<hr>
{% endblock %} {% endblock %}

View File

@ -1,7 +1,7 @@
"""passbook URL Configuration""" """passbook URL Configuration"""
from django.urls import path from django.urls import path
from passbook.admin.views import applications, overview, sources from passbook.admin.views import applications, overview, rules, sources
urlpatterns = [ urlpatterns = [
path('', overview.AdministrationOverviewView.as_view(), name='overview'), path('', overview.AdministrationOverviewView.as_view(), name='overview'),
@ -14,6 +14,7 @@ urlpatterns = [
applications.ApplicationUpdateView.as_view(), name='application-update'), applications.ApplicationUpdateView.as_view(), name='application-update'),
path('applications/<uuid:pk>/delete/', path('applications/<uuid:pk>/delete/',
applications.ApplicationDeleteView.as_view(), name='application-delete'), applications.ApplicationDeleteView.as_view(), name='application-delete'),
# Sources
path('sources/', sources.SourceListView.as_view(), name='sources'), path('sources/', sources.SourceListView.as_view(), name='sources'),
path('sources/create/', sources.SourceCreateView.as_view(), name='source-create'), path('sources/create/', sources.SourceCreateView.as_view(), name='source-create'),
path('sources/<uuid:pk>/update/', sources.SourceUpdateView.as_view(), name='source-update'), path('sources/<uuid:pk>/update/', sources.SourceUpdateView.as_view(), name='source-update'),

View File

@ -21,11 +21,14 @@ class SourceListView(AdminRequiredMixin, ListView):
x.__name__: x._meta.verbose_name for x in Source.__subclasses__()} x.__name__: x._meta.verbose_name for x in Source.__subclasses__()}
return super().get_context_data(**kwargs) return super().get_context_data(**kwargs)
def get_queryset(self):
return super().get_queryset().select_subclasses()
class SourceCreateView(SuccessMessageMixin, AdminRequiredMixin, CreateView): class SourceCreateView(SuccessMessageMixin, AdminRequiredMixin, CreateView):
"""Create new Source""" """Create new Source"""
template_name = 'generic/create.html' template_name = 'administration/source/create.html'
success_url = reverse_lazy('passbook_admin:sources') success_url = reverse_lazy('passbook_admin:sources')
success_message = _('Successfully created Source') success_message = _('Successfully created Source')

View File

@ -0,0 +1,18 @@
"""passbook Core Application forms"""
from django import forms
from passbook.core.models import Application
class ApplicationForm(forms.ModelForm):
"""Application Form"""
class Meta:
model = Application
fields = ['name', 'launch_url', 'icon_url', 'rules', 'provider', 'skip_authorization']
widgets = {
'name': forms.TextInput(),
'launch_url': forms.TextInput(),
'icon_url': forms.TextInput(),
}

View File

@ -14,6 +14,14 @@ class LDAPSourceForm(forms.ModelForm):
model = LDAPSource model = LDAPSource
fields = SOURCE_FORM_FIELDS + ['server_uri', 'bind_cn', 'bind_password', fields = SOURCE_FORM_FIELDS + ['server_uri', 'bind_cn', 'bind_password',
'type', 'domain', 'base_dn', 'create_user', 'reset_password'] 'type', 'domain', 'base_dn', 'create_user', 'reset_password']
widgets = {
'name': forms.TextInput(),
'server_uri': forms.TextInput(),
'bind_cn': forms.TextInput(),
'bind_password': forms.TextInput(),
'domain': forms.TextInput(),
'base_dn': forms.TextInput(),
}
# class GeneralSettingsForm(SettingsForm): # class GeneralSettingsForm(SettingsForm):
# """general settings form""" # """general settings form"""

View File

@ -12,8 +12,8 @@ class LDAPSource(Source):
TYPE_ACTIVE_DIRECTORY = 'ad' TYPE_ACTIVE_DIRECTORY = 'ad'
TYPE_GENERIC = 'generic' TYPE_GENERIC = 'generic'
TYPES = ( TYPES = (
(TYPE_ACTIVE_DIRECTORY, TYPE_ACTIVE_DIRECTORY), (TYPE_ACTIVE_DIRECTORY, _('Active Directory')),
(TYPE_GENERIC, TYPE_GENERIC), (TYPE_GENERIC, _('Generic')),
) )
server_uri = models.TextField() server_uri = models.TextField()