Skip to content
This repository was archived by the owner on Jul 12, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/server/assets/admin/users/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
{{end}}
</td>
<td class="text-truncate">
{{.Name}}
<a href="/admin/users/{{.ID}}">{{.Name}}</a>
{{if .IsRealmAdmin}}
<span class="oi oi-badge ml-2" aria-hidden="true"
data-toggle="tooltip" title="Realm admin"></span>
Expand Down
73 changes: 73 additions & 0 deletions cmd/server/assets/admin/users/show.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{{define "admin/users/show"}}
{{$user := .user}}
{{$stats := .stats}}

<!doctype html>
<html lang="en">
<head>
{{template "head" .}}
</head>

<body id="users-show" class="tab-content">
{{template "admin/navbar" .}}

<main role="main" class="container">
{{template "flash" .}}

<h1>{{$user.Name}}</h1>
<p>
Here is information about the user.
</p>

<div class="card mb-3 shadow-sm">
<div class="card-header">Details</div>
<div class="card-body">
<h6 class="mb-2">Name</h6>
<div class="form-group">
{{$user.Name}}
</div>

<hr>
<h6 class="mb-2">Email</h6>
<div class="form-group">
{{$user.Email}}
</div>

<hr>
<h6 class="mb-2">Password</h6>
<div class="form-group">
Password was last changed <span class="text-info">{{$user.PasswordAgeString}}</span> ago.
</div>

{{if $user.SystemAdmin}}
<hr>
<h6 class="mb-2">System admin</h6>
<div class="form-group text-success">Enabled</div>
{{end}}
</div>
</div>

<div class="card mb-3 shadow-sm">
<div class="card">
<div class="card-header">Member of realms</div>
<ul class="list-group list-group-flush">
{{range $realm := $user.Realms}}
<li class="list-group-item">
{{$realm.Name}}

{{range $admin := $user.AdminRealms}}
{{if eq $admin.ID $realm.ID}}
<span class="badge badge-primary">Admin</span>
{{end}}
{{end}}
</li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you'll end up doing this, but do you want to link to things like disabling the user? Adding them additional realms, etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is all coming soon, but I want to start a new PR for it. The trouble is that the regular link assumes currentUser and passes a realm - we need to pass both a user and a realm for the system-admin case

{{end}}
</ul>
</div>
</div>

<a class="card-link" href="/admin/users">&larr; All users</a>
</main>
</body>
</html>
{{end}}
10 changes: 5 additions & 5 deletions cmd/server/assets/login/account.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@
{{template "flash" .}}

<h1>My Account</h1>
<p>Information and settings for your account</p>
<p>Information and settings for your account.</p>

<div class="card mb-3 shadow-sm">
<div class="card-header">Details</div>
<div class="card-body">
<h6 class="card-title">Name</h6>
<div class="card-text mb-3">
<div class="card-text mb-3 mt-n2">
{{$user.Name}}
</div>

<h6 class="card-title">Email</h6>
<div class="card-text">
<div class="card-text mt-n2">
{{$user.Email}}
</div>

{{if $user.SystemAdmin}}
<h6 class="card-title mt-3">System admin</h6>
<div class="card-text text-success">Enabled</div>
<div class="card-text text-success mt-n2">Enabled</div>
{{end}}
</div>
</div>
Expand All @@ -51,7 +51,7 @@ <h6 class="card-title mt-3">System admin</h6>
</li>
<li class="list-group-item">
<div class="card-text">Password was last changed <span class="text-info">{{$user.PasswordAgeString}}</span>
ago</div>
ago.</div>
<a href="/login/change-password" class="card-link">Change password</a>
</li>
</ul>
Expand Down
18 changes: 11 additions & 7 deletions cmd/server/assets/users/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,23 @@ <h1>{{$user.Name}}</h1>
<div class="card mb-3 shadow-sm">
<div class="card-header">Details</div>
<div class="card-body">
<strong>Name</strong>
<div class="mb-3">
<h6 class="card-title">Name</h6>
<div class="mb-3 mt-n2">
{{$user.Name}}
</div>

<strong>Email</strong>
<div class="mb-3">
<h6 class="card-title">Email</h6>
<div class="mb-3 mt-n2">
{{$user.Email}}
</div>

<strong>Admin</strong>
<div class="mb-3">
{{$user.CanAdminRealm $currentRealm.ID}}
<h6 class="card-title">Realm admin</h6>
<div class="mb-3 mt-n2">
{{if $user.CanAdminRealm $currentRealm.ID}}
<div class="card-text text-success mb-3 mt-n2">Enabled</div>
{{else}}
<div class="card-text mb-3 mt-n2">Disabled</div>
{{end}}
</div>

<a href="/users/{{$user.ID}}/reset-password" data-method="POST" class="btn btn-primary btn-block">Send password reset</a>
Expand Down
1 change: 1 addition & 0 deletions internal/routes/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ func Server(
adminSub.Handle("/realms/{id:[0-9]+}", adminController.HandleRealmsUpdate()).Methods("PATCH")

adminSub.Handle("/users", adminController.HandleUsersIndex()).Methods("GET")
adminSub.Handle("/users/{id:[0-9]+}", adminController.HandleUserShow()).Methods("GET")
adminSub.Handle("/users/{id:[0-9]+}", adminController.HandleUserDelete()).Methods("DELETE")
adminSub.Handle("/users", adminController.HandleSystemAdminCreate()).Methods("POST")
adminSub.Handle("/users/new", adminController.HandleSystemAdminCreate()).Methods("GET")
Expand Down
24 changes: 24 additions & 0 deletions pkg/controller/admin/users_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@ func (c *Controller) HandleUsersIndex() http.Handler {
})
}

// HandleUserShow renders details about a user.
func (c *Controller) HandleUserShow() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)

// Pull the user from the id.
user, err := c.db.FindUser(vars["id"])
if err != nil {
if database.IsNotFound(err) {
controller.NotFound(w, r, c.h)
return
}

controller.InternalError(w, r, c.h, err)
return
}

m := controller.TemplateMapFromContext(ctx)
m["user"] = user
c.h.RenderHTML(w, "admin/users/show", m)
})
}

// HandleUserDelete deletes a user from the system.
func (c *Controller) HandleUserDelete() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down