Skip to content
Snippets Groups Projects
Verified Commit f47756f4 authored by nd's avatar nd
Browse files

enhance role view: use tabs, move buttons, stay on page after save

parent 165c4e98
Branches
No related tags found
No related merge requests found
...@@ -3,6 +3,29 @@ ...@@ -3,6 +3,29 @@
{% block body %} {% block body %}
<form action="{{ url_for("role.update", roleid=role.id) }}" method="POST"> <form action="{{ url_for("role.update", roleid=role.id) }}" method="POST">
<div class="align-self-center"> <div class="align-self-center">
<div class="float-sm-right pb-2">
<button type="submit" class="btn btn-primary"><i class="fa fa-save" aria-hidden="true"></i> Save</button>
<a href="{{ url_for("role.index") }}" class="btn btn-secondary">Cancel</a>
{% if role.id %}
<a href="{{ url_for("role.delete", roleid=role.id) }}" onClick="return confirm('Are you sure?');" class="btn btn-danger"><i class="fa fa-trash" aria-hidden="true"></i> Delete</a>
{% else %}
<a href="#" class="btn btn-danger disabled"><i class="fa fa-trash" aria-hidden="true"></i> Delete</a>
{% endif %}
</div>
<ul class="nav nav-tabs pt-2 border-0" id="tablist" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="settings-tab" data-toggle="tab" href="#settings" role="tab" aria-controls="settings" aria-selected="true">Settings</a>
</li>
<li class="nav-item">
<a class="nav-link" id="roles-tab" data-toggle="tab" href="#roles" role="tab" aria-controls="roles" aria-selected="false">Included roles <span class="badge badge-pill badge-secondary">{{ role.included_roles|length }}</span></a>
</li>
<li class="nav-item">
<a class="nav-link" id="groups-tab" data-toggle="tab" href="#groups" role="tab" aria-controls="groups" aria-selected="false">Included groups <span class="badge badge-pill badge-secondary">{{ role.groups|length }}</span></a>
</li>
</ul>
<div class="tab-content border mb-2 pt-2" id="tabcontent">
<div class="tab-pane fade show active" id="settings" role="tabpanel" aria-labelledby="settings-tab">
<div class="form-group col"> <div class="form-group col">
<label for="role-name">Role Name</label> <label for="role-name">Role Name</label>
<input type="text" class="form-control" id="role-name" name="name" value="{{ role.name }}"> <input type="text" class="form-control" id="role-name" name="name" value="{{ role.name }}">
...@@ -15,7 +38,16 @@ ...@@ -15,7 +38,16 @@
<small class="form-text text-muted"> <small class="form-text text-muted">
</small> </small>
</div> </div>
<div class="form-group col">
<span>Members:</span>
<ul class="row">
{% for member in role.members|sort(attribute='loginname') %}
<li class="col-12 col-xs-6 col-sm-4 col-md-3 col-lg-2"><a href="{{ url_for("user.show", uid=member.uid) }}">{{ member.loginname }}</a></li>
{% endfor %}
</ul>
</div>
</div>
<div class="tab-pane fade" id="roles" role="tabpanel" aria-labelledby="roles-tab">
<div class="form-group col"> <div class="form-group col">
<span>Roles to include groups from recursively</span> <span>Roles to include groups from recursively</span>
<table class="table table-striped table-sm"> <table class="table table-striped table-sm">
...@@ -55,7 +87,8 @@ ...@@ -55,7 +87,8 @@
</tbody> </tbody>
</table> </table>
</div> </div>
</div>
<div class="tab-pane fade" id="groups" role="tabpanel" aria-labelledby="groups-tab">
<div class="form-group col"> <div class="form-group col">
<span>Included groups</span> <span>Included groups</span>
<table class="table table-striped table-sm"> <table class="table table-striped table-sm">
...@@ -87,26 +120,7 @@ ...@@ -87,26 +120,7 @@
</tbody> </tbody>
</table> </table>
</div> </div>
<div class="form-group col">
<p>
Members
</p>
<ul>
{% for dbmember in role.db_members %}
<li>{{ dbmember.dn }}</li>
{% endfor %}
</ul>
</div> </div>
<div class="form-group col">
<button type="submit" class="btn btn-primary"><i class="fa fa-save" aria-hidden="true"></i> Save</button>
<a href="{{ url_for("role.index") }}" class="btn btn-secondary">Cancel</a>
{% if role.id %}
<a href="{{ url_for("role.delete", roleid=role.id) }}" class="btn btn-danger"><i class="fa fa-trash" aria-hidden="true"></i> Delete</a>
{% else %}
<a href="#" class="btn btn-danger disabled"><i class="fa fa-trash" aria-hidden="true"></i> Delete</a>
{% endif %}
</div> </div>
</div> </div>
</form> </form>
......
...@@ -54,6 +54,8 @@ def index(): ...@@ -54,6 +54,8 @@ def index():
@bp.route("/<int:roleid>") @bp.route("/<int:roleid>")
@bp.route("/new") @bp.route("/new")
def show(roleid=False): def show(roleid=False):
# prefetch all users so the ldap orm can cache them and doesn't run one ldap query per user
User.query.all()
if not roleid: if not roleid:
role = Role() role = Role()
else: else:
...@@ -85,7 +87,7 @@ def update(roleid=False): ...@@ -85,7 +87,7 @@ def update(roleid=False):
role.update_member_groups() role.update_member_groups()
db.session.commit() db.session.commit()
ldap.session.commit() ldap.session.commit()
return redirect(url_for('role.index')) return redirect(url_for('role.show', roleid=roleid))
@bp.route("/<int:roleid>/del") @bp.route("/<int:roleid>/del")
@csrf_protect(blueprint=bp) @csrf_protect(blueprint=bp)
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<div class="col"> <div class="col">
<span>Members:</span> <span>Members:</span>
<ul class="row"> <ul class="row">
{% for member in group.members %} {% for member in group.members|sort(attribute='loginname') %}
<li class="col-12 col-xs-6 col-sm-4 col-md-3 col-lg-2"><a href="{{ url_for("user.show", uid=member.uid) }}">{{ member.loginname }}</a></li> <li class="col-12 col-xs-6 col-sm-4 col-md-3 col-lg-2"><a href="{{ url_for("user.show", uid=member.uid) }}">{{ member.loginname }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment