Skip to content
This repository was archived by the owner on Jul 12, 2023. It is now read-only.

Commit 4a89294

Browse files
committed
Allow managing system admins via the UI
1 parent f5b9e9b commit 4a89294

File tree

17 files changed

+505
-245
lines changed

17 files changed

+505
-245
lines changed

cmd/add-users/main.go

-119
This file was deleted.

cmd/server/assets/admin/_nav.html

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{define "admin/navbar"}}
2+
<ul class="nav nav-pills justify-content-center mb-3">
3+
<li class="nav-item">
4+
<a class="nav-link{{if stringContains .currentPath "/admin/realms"}} active{{end}}" href="/admin/realms">Realms</a>
5+
</li>
6+
7+
<li class="nav-item">
8+
<a class="nav-link{{if stringContains .currentPath "/admin/users"}} active{{end}}" href="/admin/users">System admins</a>
9+
</li>
10+
11+
<li class="nav-item">
12+
<a class="nav-link{{if stringContains .currentPath "/admin/info"}} active{{end}}" href="/admin/info">Info</a>
13+
</li>
14+
</ul>
15+
{{end}}

cmd/server/assets/admin/realms.html

-53
This file was deleted.
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{{define "admin/realms/index"}}
2+
3+
{{$realms := .realms}}
4+
5+
<!doctype html>
6+
<html lang="en">
7+
<head>
8+
{{template "head" .}}
9+
</head>
10+
11+
<body class="bg-light">
12+
{{template "navbar" .}}
13+
{{template "admin/navbar" .}}
14+
15+
<main role="main" class="container">
16+
{{template "flash" .}}
17+
18+
<div class="card mb-3 shadow-sm">
19+
<div class="card-header">Realms</div>
20+
<div class="card-body">
21+
<div class="clearfix mb-3">
22+
<a class="btn btn-outline-secondary btn-sm float-right" href="/admin/realms/new">
23+
<span class="oi oi-plus" aria-hidden="true"></span>
24+
New realm
25+
</a>
26+
</div>
27+
28+
{{if $realms}}
29+
<div class="table-responsive">
30+
<table class="table table-bordered table-striped bg-white">
31+
<thead>
32+
<tr>
33+
<th scope="col">Name</th>
34+
<th scope="col" width="125">Region code</th>
35+
<th scope="col" width="125">Signing key</th>
36+
</tr>
37+
</thead>
38+
<tbody>
39+
{{range $realms}}
40+
<tr>
41+
<td>{{.Name}}</td>
42+
<td>{{.RegionCode}}</td>
43+
<td>
44+
{{if .UseRealmCertificateKey}}Realm{{else}}System{{end}}
45+
</td>
46+
</tr>
47+
{{end}}
48+
</tbody>
49+
</table>
50+
</div>
51+
{{else}}
52+
<p class="text-center">
53+
<em>There are no realms.</em>
54+
</p>
55+
{{end}}
56+
</div>
57+
</div>
58+
</main>
59+
60+
{{template "scripts" .}}
61+
</body>
62+
</html>
63+
{{end}}

cmd/server/assets/admin/new.html renamed to cmd/server/assets/admin/realms/new.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{define "admin/newrealm"}}
1+
{{define "admin/realms/new"}}
22

33
{{$realm := .realm}}
44

@@ -11,6 +11,7 @@
1111

1212
<body class="bg-light">
1313
{{template "navbar" .}}
14+
{{template "admin/navbar" .}}
1415

1516
<main role="main" class="container">
1617
{{template "flash" .}}
@@ -23,7 +24,7 @@ <h1>New realm</h1>
2324
<div class="card mb-3 shadow-sm">
2425
<div class="card-header">Details</div>
2526
<div class="card-body">
26-
<form method="POST" action="/admin/realms/create">
27+
<form method="POST" action="/admin/realms">
2728
{{ .csrfField }}
2829

2930
<div class="form-label-group">
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{{define "admin/users/index"}}
2+
3+
{{$currentUser := .currentUser}}
4+
{{$admins := .admins}}
5+
6+
<!doctype html>
7+
<html lang="en">
8+
<head>
9+
{{template "head" .}}
10+
</head>
11+
12+
<body class="bg-light">
13+
{{template "navbar" .}}
14+
{{template "admin/navbar" .}}
15+
16+
<main role="main" class="container">
17+
{{template "flash" .}}
18+
19+
<div class="card mb-3 shadow-sm">
20+
<div class="card-header">System admins</div>
21+
<div class="card-body">
22+
<div class="clearfix mb-3">
23+
<a class="btn btn-outline-secondary btn-sm float-right" href="/admin/users/new">
24+
<span class="oi oi-plus" aria-hidden="true"></span>
25+
New system admin
26+
</a>
27+
</div>
28+
29+
<div class="table-responsive">
30+
<table class="table table-bordered table-striped mb-0">
31+
<thead>
32+
<tr>
33+
<th scope="col">Name</th>
34+
<th scope="col" width="300">Email</th>
35+
<th scope="col" width="40"></th>
36+
</tr>
37+
</thead>
38+
<tbody>
39+
{{range $admins}}
40+
<tr>
41+
<td>{{.Name}}</td>
42+
<td>{{.Email}}</td>
43+
<td class="text-center">
44+
{{- /* cannot delete yourself */ -}}
45+
{{if not (eq .ID $currentUser.ID)}}
46+
<a href="/admin/users/{{.ID}}"
47+
class="d-block text-danger"
48+
data-method="DELETE"
49+
data-confirm="Are you sure you want to remove this system admin?"
50+
data-toggle="tooltip"
51+
title="Remove this system admin">
52+
<span class="oi oi-trash" aria-hidden="true"></span>
53+
</a>
54+
{{end}}
55+
</td>
56+
</tr>
57+
{{end}}
58+
</tbody>
59+
</table>
60+
</div>
61+
</div>
62+
</div>
63+
</main>
64+
65+
{{template "scripts" .}}
66+
</body>
67+
</html>
68+
{{end}}

0 commit comments

Comments
 (0)