Implement new realm overview design, Close #42
This commit is contained in:
parent
7519e69a2c
commit
e74878c0c4
@ -34,9 +34,12 @@ def is_realm_admin(view_func):
|
|||||||
@login_required
|
@login_required
|
||||||
def realm_list(request):
|
def realm_list(request):
|
||||||
user = request.user
|
user = request.user
|
||||||
if not user.is_superuser:
|
if user.is_superuser:
|
||||||
|
realms = Realm.objects.all()
|
||||||
|
else:
|
||||||
realms = Realm.objects.filter(admin_group__user__username__contains=user.username).order_by('name')
|
realms = Realm.objects.filter(admin_group__user__username__contains=user.username).order_by('name')
|
||||||
if len(realms) == 0:
|
|
||||||
|
if len(realms) == 0 and not user.is_superuser:
|
||||||
try:
|
try:
|
||||||
user = LdapUser.objects.get(username=user.username)
|
user = LdapUser.objects.get(username=user.username)
|
||||||
realm_base_dn = re.compile('(uid=[a-zA-Z0-9_]*),(ou=[a-zA-Z_]*),(.*)').match(user.dn).group(3)
|
realm_base_dn = re.compile('(uid=[a-zA-Z0-9_]*),(ou=[a-zA-Z_]*),(.*)').match(user.dn).group(3)
|
||||||
@ -48,8 +51,21 @@ def realm_list(request):
|
|||||||
elif len(realms) == 1:
|
elif len(realms) == 1:
|
||||||
return redirect('realm-detail', realms[0].id)
|
return redirect('realm-detail', realms[0].id)
|
||||||
else:
|
else:
|
||||||
return render(request, 'realm/realm_home.jinja2', {'realms': realms})
|
realm_wrappers = []
|
||||||
else:
|
for realm in realms:
|
||||||
|
realm_wrappers.append(_get_group_user_count_wrapper(realm))
|
||||||
|
return render(request, 'realm/realm_home.jinja2', {'realms': realms, 'realm_wrappers': realm_wrappers})
|
||||||
|
|
||||||
|
|
||||||
|
def _get_group_user_count_wrapper(realm):
|
||||||
|
LdapUser.base_dn = f'ou=people,{realm.ldap_base_dn}'
|
||||||
|
LdapGroup.base_dn = f'ou=groups,{realm.ldap_base_dn}'
|
||||||
|
return {'realm': realm, 'group_count': LdapGroup.objects.count(), 'user_count': LdapUser.objects.count()}
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def realm_add(request):
|
||||||
|
if request.user.is_superuser:
|
||||||
realms = Realm.objects.all().order_by('name')
|
realms = Realm.objects.all().order_by('name')
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = RealmAddForm(request.POST)
|
form = RealmAddForm(request.POST)
|
||||||
@ -70,7 +86,9 @@ def realm_list(request):
|
|||||||
{'realm_name': name})
|
{'realm_name': name})
|
||||||
else:
|
else:
|
||||||
form = RealmAddForm()
|
form = RealmAddForm()
|
||||||
return render(request, 'realm/realm_home.jinja2', {'realms': realms, 'form': form})
|
return render(request, 'realm/realm_add.jinja2', {'realms': realms, 'form': form})
|
||||||
|
else:
|
||||||
|
redirect('permission-denied')
|
||||||
|
|
||||||
|
|
||||||
def base_dn_available(base_dn):
|
def base_dn_available(base_dn):
|
||||||
|
|||||||
@ -7,6 +7,7 @@ from . import main_views
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# Realm
|
# Realm
|
||||||
path('', main_views.realm_list, name='realm-home'),
|
path('', main_views.realm_list, name='realm-home'),
|
||||||
|
path('realm/add/', main_views.realm_add, name='realm-add'),
|
||||||
path('realm/<int:realm_id>/', main_views.realm_detail, name='realm-detail'),
|
path('realm/<int:realm_id>/', main_views.realm_detail, name='realm-detail'),
|
||||||
path('realm/<int:realm_id>/update/', main_views.realm_update, name='realm-update'),
|
path('realm/<int:realm_id>/update/', main_views.realm_update, name='realm-update'),
|
||||||
path('realm/<int:realm_id>/delete/confirm/', main_views.realm_delete_confirm, name='realm-delete-confirm'),
|
path('realm/<int:realm_id>/delete/confirm/', main_views.realm_delete_confirm, name='realm-delete-confirm'),
|
||||||
|
|||||||
@ -29,6 +29,12 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if request.user.is_superuser %}
|
||||||
|
<div class="list-group-item bg-light"></div>
|
||||||
|
<a href="{{ url('realm-add') }}"
|
||||||
|
class="list-group-item list-group-item-action bg-light"><i class="fas fa-plus-square"></i>
|
||||||
|
Bereich hinufügen</a>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="page-content-wrapper">
|
<div class="page-content-wrapper">
|
||||||
|
|||||||
@ -55,3 +55,55 @@
|
|||||||
</table>
|
</table>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
|
{% macro get_realm_table(realms) -%}
|
||||||
|
<div class="form-group w-25 float-right">
|
||||||
|
<input type="text"
|
||||||
|
class="form-control"
|
||||||
|
id="data-table-search-input">
|
||||||
|
<label for="data-table-search-input">Suche</label>
|
||||||
|
</div>
|
||||||
|
<table class="table table-hover table-striped table-inverse table-bordered data-table text-center">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">Bereichsname</th>
|
||||||
|
<th scope="col">Ldap Basis DN</th>
|
||||||
|
<th scope="col">Mailadresse</th>
|
||||||
|
<th scope="col">Admingruppe</th>
|
||||||
|
<th scope="col">Defaultgruppe</th>
|
||||||
|
<th scope="col">Nutzer anzahl</th>
|
||||||
|
<th scope="col">Gruppen anzahl</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for realm_wrapper in realms %}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<a href="{{ url('realm-detail', args=[realm_wrapper.realm.id]) }}">{{ realm_wrapper.realm.name }}</a>
|
||||||
|
</td>
|
||||||
|
<td>{{ realm_wrapper.realm.ldap_base_dn }}</td>
|
||||||
|
<td>{{ realm_wrapper.realm.email }}</td>
|
||||||
|
<td>
|
||||||
|
{% if realm_wrapper.realm.admin_group %}
|
||||||
|
{{ realm_wrapper.realm.admin_group }}
|
||||||
|
{% else %}
|
||||||
|
<span class="text-warning"><i class="fas fa-exclamation-circle"></i></span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{% if realm_wrapper.realm.default_group %}
|
||||||
|
{{ realm_wrapper.realm.default_group }}
|
||||||
|
{% else %}
|
||||||
|
<span class="text-warning"><i class="fas fa-exclamation-circle align-middle"></i></span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>{{ realm_wrapper.user_count }}</td>
|
||||||
|
<td>{{ realm_wrapper.group_count }}</td>
|
||||||
|
{# <td class="text-center">{% if user.active %}#}
|
||||||
|
{# <i class="fas fa-check-circle text-success"></i>{% else %}#}
|
||||||
|
{# <i class="far fa-times-circle text-warning"></i>{% endif %}</td>#}
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
|||||||
19
templates/realm/realm_add.jinja2
Normal file
19
templates/realm/realm_add.jinja2
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{% extends 'base_admin.jinja2' %}
|
||||||
|
{% import 'macros/form_macros.jinja2' as mform %}
|
||||||
|
{% import 'macros/utils_macros.jinja2' as mutils %}
|
||||||
|
|
||||||
|
{% block admin_content %}
|
||||||
|
<div class="row justify-content-center justify-content-sm-center">
|
||||||
|
<div class="col-12 col-sm-8 col-md-8 col-lg-6 col-xl-5 bg-white text-dark p-3 mt-5">
|
||||||
|
{% if request.user.is_superuser %}
|
||||||
|
<h2>Neuen Bereich anlegen</h2>
|
||||||
|
<form method="post">
|
||||||
|
<input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
|
||||||
|
{{ mform.text_input(form.name) }}
|
||||||
|
{{ mform.text_input(form.ldap_base_dn) }}
|
||||||
|
<button type="submit" class="btn btn-primary btn-block">Anlegen</button>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@ -3,17 +3,14 @@
|
|||||||
{% import 'macros/utils_macros.jinja2' as mutils %}
|
{% import 'macros/utils_macros.jinja2' as mutils %}
|
||||||
|
|
||||||
{% block admin_content %}
|
{% block admin_content %}
|
||||||
|
<h2>Bereiche</h2>
|
||||||
|
{{ mutils.get_realm_table(realm_wrappers) }}
|
||||||
|
{% if request.user.is_superuser %}
|
||||||
<div class="row justify-content-center justify-content-sm-center">
|
<div class="row justify-content-center justify-content-sm-center">
|
||||||
<div class="col-12 col-sm-8 col-md-8 col-lg-6 col-xl-5 bg-white text-dark p-3 mt-5">
|
<div class="col-12 col-sm-8 col-md-8 col-lg-6 col-xl-5 bg-white text-dark p-3 mt-5">
|
||||||
{% if request.user.is_superuser %}
|
<a href="{{ url('realm-add') }}" class="btn btn-primary w-100">Bereich hinzufügen</a>
|
||||||
<h2>Neuen Bereich anlegen</h2>
|
</div>
|
||||||
<form method="post">
|
</div>
|
||||||
<input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
|
|
||||||
{{ mform.text_input(form.name) }}
|
|
||||||
{{ mform.text_input(form.ldap_base_dn) }}
|
|
||||||
<button type="submit" class="btn btn-primary btn-block">Anlegen</button>
|
|
||||||
</form>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user