From c381e3fc6588bf675b7506eec8ace8bf550fd684 Mon Sep 17 00:00:00 2001
From: nd <git@notandy.de>
Date: Sun, 19 Jul 2020 15:53:51 +0200
Subject: [PATCH] reworked user admin view

---
 uffd/role/__init__.py         |   1 +
 uffd/role/templates/role.html |   4 +-
 uffd/user/templates/user.html | 165 +++++++++++++++++-----------------
 3 files changed, 85 insertions(+), 85 deletions(-)

diff --git a/uffd/role/__init__.py b/uffd/role/__init__.py
index 67157866..cd6180ed 100644
--- a/uffd/role/__init__.py
+++ b/uffd/role/__init__.py
@@ -1,3 +1,4 @@
 from .views import bp as bp_ui
+from .models import Role, RoleGroup, RoleUser
 
 bp = [bp_ui]
diff --git a/uffd/role/templates/role.html b/uffd/role/templates/role.html
index cdddccee..a300953b 100644
--- a/uffd/role/templates/role.html
+++ b/uffd/role/templates/role.html
@@ -16,9 +16,7 @@
 		</small>
 	</div>
 	<div class="form-group col">
-		<p>
-			Included groups
-		</p>
+		<span>Included groups</span>
 		<table class="table table-striped table-sm">
 			<thead>
 				<tr>
diff --git a/uffd/user/templates/user.html b/uffd/user/templates/user.html
index a2084400..3ac0a02b 100644
--- a/uffd/user/templates/user.html
+++ b/uffd/user/templates/user.html
@@ -3,97 +3,98 @@
 {% block body %}
 <form action="{{ url_for("user.update", uid=user.uid) }}" method="POST">
 <div class="align-self-center">
-	<div class="form-group col">
-		<label for="user-uid">uid</label>
-		{% if user.uid %}
-		<input type="number" class="form-control" id="user-uid" name="uid" value="{{ user.uid }}" readonly>
-		{% else %}
-		<input type="string" class="form-control" id="user-uid" name="uid" placeholder="will be choosen" readonly>
-		{% endif %}
-	</div>
-	<div class="form-group col">
-		<label for="user-loginname">Login Name</label>
-		<input type="text" class="form-control" id="user-loginname" name="loginname" value="{{ user.loginname }}" {% if user.uid %}readonly{% endif %}>
-		<small class="form-text text-muted">
-			Only letters, numbers and underscore ("_") are allowed. At most 32, at least 2 characters. There is a word blacklist. Musst be unique.
-		</small>
-	</div>
-	<div class="form-group col">
-		<label for="user-loginname">Display Name</label>
-		<input type="text" class="form-control" id="user-displayname" name="displayname" value="{{ user.displayname }}">
-		<small class="form-text text-muted">
-			If you leave this empty it will be set to the login name. At most 128, at least 2 characters. No character restrictions.
-		</small>
-	</div>
-	<div class="form-group col">
-		<label for="user-mail">Mail</label>
-		<input type="email" class="form-control" id="user-mail" name="mail" value="{{ user.mail }}">
-		<small class="form-text text-muted">
-			Do a sanity check here. A user can take over another account if both have the same mail address set.
-		</small>
-	</div>
-	<div class="form-group col">
-		<label for="user-loginname">Password</label>
-		{% if user.uid %}
-		<input type="password" class="form-control" id="user-password" name="password" placeholder="●●●●●●●●">
-		{% else %}
-		<input type="password" class="form-control" id="user-password" name="password" placeholder="mail to set it will be sent" readonly>
-		{% endif %}
-		<small class="form-text text-muted">
-			At least 8 characters, no other special requirements. But please don't be stupid and use a password manager.
-		</small>
-	</div>
-	{% if user.uid %}
-	<div class="form-group col "id="accordion">
-		<div class="card">
-			<div class="card-header" id="user-ldif">
-				<h5 class="mb-0">
-					<a class="btn btn-link collapsed" data-toggle="collapse" data-target="#user-ldif-body" aria-expanded="false" aria-controls="user-ldif">
-						ldif
-					</a>
-				</h5>
+	<ul class="nav nav-tabs " id="tablist" role="tablist">
+		<li class="nav-item">
+			<a class="nav-link active" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="true">Profile</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">Roles</a>
+		</li>
+		<li class="nav-item">
+			<a class="nav-link" id="ldif-tab" data-toggle="tab" href="#ldif" role="tab" aria-controls="ldif" aria-selected="false">LDIF</a>
+		</li>
+	</ul>
+	<div class="tab-content border border-top-0 mb-2 pt-2" id="tabcontent">
+		<div class="tab-pane fade show active" id="profile" role="tabpanel" aria-labelledby="roles-tab">
+			<div class="form-group col">
+				<label for="user-uid">uid</label>
+				{% if user.uid %}
+				<input type="number" class="form-control" id="user-uid" name="uid" value="{{ user.uid }}" readonly>
+				{% else %}
+				<input type="string" class="form-control" id="user-uid" name="uid" placeholder="will be choosen" readonly>
+				{% endif %}
 			</div>
-			<div id="user-ldif-body" class="collapse" aria-labelledby="user-ldif" data-parent="#accordion">
-				<div class="card-body">
-					<pre>{{ user_ldif }}</pre>
-				</div>
+			<div class="form-group col">
+				<label for="user-loginname">Login Name</label>
+				<input type="text" class="form-control" id="user-loginname" name="loginname" value="{{ user.loginname }}" {% if user.uid %}readonly{% endif %}>
+				<small class="form-text text-muted">
+					Only letters, numbers and underscore ("_") are allowed. At most 32, at least 2 characters. There is a word blacklist. Musst be unique.
+				</small>
 			</div>
-		</div>
-		<div class="card">
-			<div class="card-header" id="user-group">
-				<h5 class="mb-0">
-					<a class="btn btn-link collapsed" data-toggle="collapse" data-target="#user-group-body" aria-expanded="false" aria-controls="user-group">
-						groups
-					</a>
-				</h5>
+			<div class="form-group col">
+				<label for="user-loginname">Display Name</label>
+				<input type="text" class="form-control" id="user-displayname" name="displayname" value="{{ user.displayname }}">
+				<small class="form-text text-muted">
+					If you leave this empty it will be set to the login name. At most 128, at least 2 characters. No character restrictions.
+				</small>
 			</div>
-			<div id="user-group-body" class="collapse" aria-labelledby="user-group" data-parent="#accordion">
-				<div class="card-body">
-					<ul class="list-group">
-					{% for group in user.get_groups() %}
-					<li class="list-group-item"><a href="{{ url_for("group.show", gid=group.gid) }}">{{ group.name }}</a></li>
-					{% endfor %}
-					</ul>
-				</div>
+			<div class="form-group col">
+				<label for="user-mail">Mail</label>
+				<input type="email" class="form-control" id="user-mail" name="mail" value="{{ user.mail }}">
+				<small class="form-text text-muted">
+					Do a sanity check here. A user can take over another account if both have the same mail address set.
+				</small>
+			</div>
+			<div class="form-group col">
+				<label for="user-loginname">Password</label>
+				{% if user.uid %}
+				<input type="password" class="form-control" id="user-password" name="password" placeholder="●●●●●●●●">
+				{% else %}
+				<input type="password" class="form-control" id="user-password" name="password" placeholder="mail to set it will be sent" readonly>
+				{% endif %}
+				<small class="form-text text-muted">
+					At least 8 characters, no other special requirements. But please don't be stupid and use a password manager.
+				</small>
 			</div>
 		</div>
-		<div class="card">
-			<div class="card-header" id="user-role">
-				<h5 class="mb-0">
-					<a class="btn btn-link" data-toggle="collapse" data-target="#user-role-body" aria-expanded="true" aria-controls="user-role">
-						roles
-					</a>
-				</h5>
+		<div class="tab-pane fade" id="roles" role="tabpanel" aria-labelledby="roles-tab">
+			<div class="form-group col">
+				<span>Roles:</span>
+			</div>
+			<div class="form-group col">
+				<span>Resulting groups (only updated after save):</span>
+				<table class="table table-striped table-sm">
+					<thead>
+						<tr>
+							<th scope="col">name</th>
+							<th scope="col">description</th>
+						</tr>
+					</thead>
+					<tbody>
+						{% for group in user.get_groups()|sort(attribute="name") %}
+						<tr id="group-{{ group.gid }}">
+							<td>
+								<a href="{{ url_for("group.show", gid=group.gid) }}">
+									{{ group.name }}
+								</a>
+							</td>
+							<td>
+								{{ group.description }}
+							</td>
+						</tr>
+						{% endfor %}
+					</tbody>
+				</table>
 			</div>
-			<div id="user-role-body" class="collapse show" aria-labelledby="user-role" data-parent="#accordion">
-				<div class="card-body">
-					roles.
-				</div>
+		</div>
+		<div class="tab-pane fade" id="ldif" role="tabpanel" aria-labelledby="ldif-tab">
+			<div class="form-group col">
+				<pre>{{ user_ldif }}</pre>
 			</div>
 		</div>
 	</div>
-	{% endif %}
-	<div class="form-group col">
+
+	<div class="form-group col pl-0">
 		<button type="submit" class="btn btn-primary"><i class="fa fa-save" aria-hidden="true"></i> Save</button>
 		<a href="{{ url_for("user.index") }}" class="btn btn-secondary">Cancel</a>
 		{% if user.uid %}
-- 
GitLab