diff --git a/uffd/role/templates/role.html b/uffd/role/templates/role.html index e7c494b74c4db76f74f402c13b7f58a9fdfc2088..6f8645c9f83bfba94fc097eb5934ee25290d4559 100644 --- a/uffd/role/templates/role.html +++ b/uffd/role/templates/role.html @@ -3,111 +3,125 @@ {% block body %} <form action="{{ url_for("role.update", roleid=role.id) }}" method="POST"> <div class="align-self-center"> - <div class="form-group col"> - <label for="role-name">Role Name</label> - <input type="text" class="form-control" id="role-name" name="name" value="{{ role.name }}"> - <small class="form-text text-muted"> - </small> - </div> - <div class="form-group col"> - <label for="role-description">Description</label> - <textarea class="form-control" id="role-description" name="description" rows="5">{{ role.description }}</textarea> - <small class="form-text text-muted"> - </small> - </div> - - <div class="form-group col"> - <span>Roles to include groups from recursively</span> - <table class="table table-striped table-sm"> - <thead> - <tr> - <th scope="col"></th> - <th scope="col">name</th> - <th scope="col">description</th> - <th scope="col">currently includes groups</th> - </tr> - </thead> - <tbody> - {% for r in roles|sort(attribute="name")|sort(attribute='name') %} - <tr id="include-role-{{ role.id }}"> - <td> - <div class="form-check"> - <input class="form-check-input" type="checkbox" id="include-role-{{ r.id }}-checkbox" name="include-role-{{ r.id }}" value="1" aria-label="enabled" - {% if r == role %}disabled{% endif %} - {% if r in role.included_roles %}checked{% endif %}> - </div> - </td> - <td> - <a href="{{ url_for("role.show", roleid=r.id) }}"> - {{ r.name }} - </a> - </td> - <td> - {{ r.description }} - </td> - <td> - {% for group in r.included_groups.union(r.groups)|sort(attribute='name') %} - <a href="{{ url_for("group.show", gid=group.gid) }}">{{ group.name }}</a>{{ ', ' if not loop.last }} - {% endfor %} - </td> - </tr> - {% endfor %} - </tbody> - </table> - </div> - - <div class="form-group col"> - <span>Included groups</span> - <table class="table table-striped table-sm"> - <thead> - <tr> - <th scope="col"></th> - <th scope="col">name</th> - <th scope="col">description</th> - </tr> - </thead> - <tbody> - {% for group in groups|sort(attribute="name") %} - <tr id="group-{{ group.gid }}"> - <td> - <div class="form-check"> - <input class="form-check-input" type="checkbox" id="group-{{ group.gid }}-checkbox" name="group-{{ group.gid }}" value="1" aria-label="enabled" {% if group in role.groups %}checked{% endif %}> - </div> - </td> - <td> - <a href="{{ url_for("group.show", gid=group.gid) }}"> - {{ group.name }} - </a> - </td> - <td> - {{ group.description }} - </td> - </tr> - {% endfor %} - </tbody> - </table> - </div> - - <div class="form-group col"> - <p> - Members - </p> - <ul> - {% for dbmember in role.db_members %} - <li>{{ dbmember.dn }}</li> - {% endfor %} - </ul> - </div> - - <div class="form-group col"> + <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) }}" class="btn btn-danger"><i class="fa fa-trash" aria-hidden="true"></i> Delete</a> + <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"> + <label for="role-name">Role Name</label> + <input type="text" class="form-control" id="role-name" name="name" value="{{ role.name }}"> + <small class="form-text text-muted"> + </small> + </div> + <div class="form-group col"> + <label for="role-description">Description</label> + <textarea class="form-control" id="role-description" name="description" rows="5">{{ role.description }}</textarea> + <small class="form-text text-muted"> + </small> + </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"> + <span>Roles to include groups from recursively</span> + <table class="table table-striped table-sm"> + <thead> + <tr> + <th scope="col"></th> + <th scope="col">name</th> + <th scope="col">description</th> + <th scope="col">currently includes groups</th> + </tr> + </thead> + <tbody> + {% for r in roles|sort(attribute="name")|sort(attribute='name') %} + <tr id="include-role-{{ role.id }}"> + <td> + <div class="form-check"> + <input class="form-check-input" type="checkbox" id="include-role-{{ r.id }}-checkbox" name="include-role-{{ r.id }}" value="1" aria-label="enabled" + {% if r == role %}disabled{% endif %} + {% if r in role.included_roles %}checked{% endif %}> + </div> + </td> + <td> + <a href="{{ url_for("role.show", roleid=r.id) }}"> + {{ r.name }} + </a> + </td> + <td> + {{ r.description }} + </td> + <td> + {% for group in r.included_groups.union(r.groups)|sort(attribute='name') %} + <a href="{{ url_for("group.show", gid=group.gid) }}">{{ group.name }}</a>{{ ', ' if not loop.last }} + {% endfor %} + </td> + </tr> + {% endfor %} + </tbody> + </table> + </div> + </div> + <div class="tab-pane fade" id="groups" role="tabpanel" aria-labelledby="groups-tab"> + <div class="form-group col"> + <span>Included groups</span> + <table class="table table-striped table-sm"> + <thead> + <tr> + <th scope="col"></th> + <th scope="col">name</th> + <th scope="col">description</th> + </tr> + </thead> + <tbody> + {% for group in groups|sort(attribute="name") %} + <tr id="group-{{ group.gid }}"> + <td> + <div class="form-check"> + <input class="form-check-input" type="checkbox" id="group-{{ group.gid }}-checkbox" name="group-{{ group.gid }}" value="1" aria-label="enabled" {% if group in role.groups %}checked{% endif %}> + </div> + </td> + <td> + <a href="{{ url_for("group.show", gid=group.gid) }}"> + {{ group.name }} + </a> + </td> + <td> + {{ group.description }} + </td> + </tr> + {% endfor %} + </tbody> + </table> + </div> + </div> + </div> </div> </form> {% endblock %} diff --git a/uffd/role/views.py b/uffd/role/views.py index a5e11be0242f260cfaf3f0e78f7fe813daf56924..eab345b59a8a77a63dcd1b92cd4c0dccbc370ff6 100644 --- a/uffd/role/views.py +++ b/uffd/role/views.py @@ -54,6 +54,8 @@ def index(): @bp.route("/<int:roleid>") @bp.route("/new") 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: role = Role() else: @@ -85,7 +87,7 @@ def update(roleid=False): role.update_member_groups() db.session.commit() ldap.session.commit() - return redirect(url_for('role.index')) + return redirect(url_for('role.show', roleid=roleid)) @bp.route("/<int:roleid>/del") @csrf_protect(blueprint=bp) diff --git a/uffd/user/templates/group.html b/uffd/user/templates/group.html index b56fbe914a3e73af8bdbe738c1c43725337316ed..e98726d817abbb505b21c43975d5b014edd87a5d 100644 --- a/uffd/user/templates/group.html +++ b/uffd/user/templates/group.html @@ -14,7 +14,7 @@ <div class="col"> <span>Members:</span> <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> {% endfor %} </ul>