Implement small improvements

- fix golangci-lint warnings
- start setup for user management
- nicer formatting of user login information
main
Jan Dittberner 2 years ago
parent 47092bfa9b
commit 1695ce0168

@ -105,9 +105,10 @@ const (
type templateData struct {
PrevPage string
NextPage string
User *models.User
Motion *models.MotionForDisplay
Motions []*models.MotionForDisplay
User *models.User
Users []*models.User
Request *http.Request
Flash string
Form any
@ -272,7 +273,7 @@ func (app *application) calculateMotionListOptions(r *http.Request) (*models.Mot
}
if voter != nil {
listOptions.VoterId = voter.ID
listOptions.VoterID = voter.ID
}
}
@ -472,8 +473,10 @@ func (app *application) proxyVoteSubmit(_ http.ResponseWriter, _ *http.Request)
panic("not implemented")
}
func (app *application) userList(_ http.ResponseWriter, _ *http.Request) {
panic("not implemented")
func (app *application) userList(w http.ResponseWriter, r *http.Request) {
data := app.newTemplateData(r, topLevelNavUsers, subLevelNavUsers)
app.render(w, http.StatusOK, "users.html", data)
}
func (app *application) submitUserRoles(_ http.ResponseWriter, _ *http.Request) {
@ -499,6 +502,6 @@ func (app *application) deleteUserForm(_ http.ResponseWriter, _ *http.Request) {
panic("not implemented")
}
func (app *application) deletetUserSubmit(_ http.ResponseWriter, _ *http.Request) {
func (app *application) deleteUserSubmit(_ http.ResponseWriter, _ *http.Request) {
panic("not implemented")
}

@ -190,7 +190,7 @@ func setupHTTPRedirect(config *Config, errChan chan error) {
redirect := &http.Server{
Addr: config.HTTPAddress,
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
redirectUrl := url.URL{
redirectURL := url.URL{
Scheme: "https://",
Host: strings.Join(
[]string{
@ -202,7 +202,7 @@ func setupHTTPRedirect(config *Config, errChan chan error) {
Path: r.URL.Path,
}
http.Redirect(w, r, redirectUrl.String(), http.StatusMovedPermanently)
http.Redirect(w, r, redirectURL.String(), http.StatusMovedPermanently)
}),
IdleTimeout: config.Timeouts.Idle,
ReadHeaderTimeout: config.Timeouts.ReadHeader,

@ -64,9 +64,10 @@ func (app *application) authenticateRequest(r *http.Request) (*models.User, erro
}
emails := r.TLS.PeerCertificates[0].EmailAddresses
user, err := app.users.GetUser(r.Context(), emails)
if err != nil {
return nil, err
return nil, fmt.Errorf("could not get user information from database: %w", err)
}
return user, nil

@ -92,7 +92,7 @@ func (app *application) routes() http.Handler {
router.Handler(http.MethodGet, "/users/:id/add-mail", canManageUsers.ThenFunc(app.userAddEmailForm))
router.Handler(http.MethodPost, "/users/:id/add-mail", canManageUsers.ThenFunc(app.userAddEmailSubmit))
router.Handler(http.MethodGet, "/users/:id/delete", canManageUsers.ThenFunc(app.deleteUserForm))
router.Handler(http.MethodPost, "/users/:id/delete", canManageUsers.ThenFunc(app.deletetUserSubmit))
router.Handler(http.MethodPost, "/users/:id/delete", canManageUsers.ThenFunc(app.deleteUserSubmit))
standard := alice.New(app.logRequest, secureHeaders)

@ -441,7 +441,7 @@ type MotionListOptions struct {
Limit int
UnvotedOnly bool
Before, After *time.Time
VoterId int64
VoterID int64
}
func (m *MotionModel) TimestampRange(ctx context.Context, options *MotionListOptions) (*time.Time, *time.Time, error) {
@ -455,7 +455,7 @@ FROM decisions
WHERE due >= ?
AND NOT EXISTS(SELECT * FROM votes WHERE decision = decisions.id AND voter = ?)`,
time.Now().UTC(),
options.VoterId,
options.VoterID,
)
} else {
row = m.DB.QueryRowxContext(
@ -684,7 +684,7 @@ WHERE NOT EXISTS(SELECT * FROM votes WHERE decision = decisions.id AND voter = ?
AND due >= ?
ORDER BY decisions.proposed DESC
LIMIT ?`,
options.VoterId,
options.VoterID,
time.Now().UTC(),
options.Limit,
)
@ -709,6 +709,7 @@ LIMIT ?`,
options.Limit,
)
}
if err != nil {
return nil, fmt.Errorf("could not query motions: %w", err)
}
@ -809,5 +810,4 @@ func (m *MotionModel) GetByID(ctx context.Context, id int64) (*Motion, error) {
}
return &motion, nil
}

@ -17,11 +17,13 @@
<div class="ui text container">
<h1 class="ui header">
{{ template "title" . }}
{{ if .User }}
<span class="ui left pointing label">Authenticated as {{ .User.Name }} &lt;{{ .User.Reminder }}&gt;
</span>
{{ end }}
</h1>
{{ with .User }}
<div class="ui label">
<i class="user icon"></i>
Authenticated as {{ .Name }} &lt;{{ .Reminder }}&gt;
</div>
{{ end }}
</div>
</div>
</header>

@ -1,4 +1,4 @@
{{ define "title" }}CAcert Board Decisions: New motion{{ end }}
{{ define "title" }}New motion{{ end }}
{{ define "main" }}
<div class="ui raised segment">

@ -1,4 +1,4 @@
{{ define "title" }}CAcert Board Decisions: {{ .Motion.Tag }}{{ end }}
{{ define "title" }}Motion {{ .Motion.Tag }}{{ end }}
{{ define "main" }}
{{ $voter := .User }}

@ -1,4 +1,4 @@
{{ define "title" }}CAcert Board Decisions{{ end }}
{{ define "title" }}Board Decisions{{ end }}
{{ define "main" }}
{{ $page := . }}

@ -0,0 +1,15 @@
{{ define "title"}}User Management{{ end }}
{{ define "main"}}
{{ if .Users }}
{{ else }}
<div class="ui basic segment">
<div class="ui icon message">
<i class="users icon"></i>
<div class="content">
<div class="header">No users found.</div>
</div>
</div>
</div>
{{ end }}
{{ end }}
Loading…
Cancel
Save