From da7dcfee6affa0dc02255bcbd6669dce606dbd26 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Thu, 7 Nov 2019 14:07:00 +0900 Subject: [PATCH] Move admin template IsSuspended logic into method This adds a User.IsSuspended() method and uses it when displaying the user's status on admin pages, instead of doing a magic number check. This should also help in the future, in case this logic ever changes. Ref T661 --- templates/user/admin/users.tmpl | 5 ++--- templates/user/admin/view-user.tmpl | 11 ++++++----- users.go | 4 ++++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/templates/user/admin/users.tmpl b/templates/user/admin/users.tmpl index 6d5d6f7..03a3f6c 100644 --- a/templates/user/admin/users.tmpl +++ b/templates/user/admin/users.tmpl @@ -19,9 +19,8 @@ {{.CreatedFriendly}} {{if .IsAdmin}}Admin{{else}}User{{end}} - {{if eq .Status 1}}suspended{{else}}active{{end}} + {{if .IsSuspended}}suspended{{else}}active{{end}} + {{end}} diff --git a/templates/user/admin/view-user.tmpl b/templates/user/admin/view-user.tmpl index 01eb1f0..9226c39 100644 --- a/templates/user/admin/view-user.tmpl +++ b/templates/user/admin/view-user.tmpl @@ -60,14 +60,15 @@ td.active-suspend > input[type="submit"] {
Status - {{if eq .User.Status 1}} -

User is currently Suspended

- {{else}} -

User is currently Active

+ {{if .User.IsSuspended}} +

Suspended

+ + {{else}} +

Active

- {{end}} + diff --git a/users.go b/users.go index 05b5bb4..5eb2e61 100644 --- a/users.go +++ b/users.go @@ -126,3 +126,7 @@ func (u *User) IsAdmin() bool { // TODO: get this from database return u.ID == 1 } + +func (u *User) IsSuspended() bool { + return u.Status&UserSuspended != 0 +}