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
pull/174/head
Matt Baer 5 years ago
parent 5429ca4ab0
commit da7dcfee6a
  1. 5
      templates/user/admin/users.tmpl
  2. 11
      templates/user/admin/view-user.tmpl
  3. 4
      users.go

@ -19,9 +19,8 @@
<td>{{.CreatedFriendly}}</td>
<td style="text-align:center">{{if .IsAdmin}}Admin{{else}}User{{end}}</td>
<td style="text-align:center">
<a
href="/admin/user/{{.Username}}#status"
title="View or change account status">{{if eq .Status 1}}suspended{{else}}active{{end}}</a></td>
<a href="/admin/user/{{.Username}}#status" title="View or change account status">{{if .IsSuspended}}suspended{{else}}active{{end}}</a>
</td>
</tr>
{{end}}
</table>

@ -60,14 +60,15 @@ td.active-suspend > input[type="submit"] {
<form action="/admin/user/{{.User.Username}}/status" method="POST">
<a id="status"/>
<th>Status</th>
{{if eq .User.Status 1}}
<td class="active-suspend"><p>User is currently Suspended</p><input type="submit" value="Activate"/></td>
{{else}}
<td class="active-suspend">
<p>User is currently Active</p>
{{if .User.IsSuspended}}
<p>Suspended</p>
<input type="submit" value="Activate"/>
{{else}}
<p>Active</p>
<input class="danger" type="submit" value="Suspend" {{if .User.IsAdmin}}disabled{{end}}/>
</td>
{{end}}
</td>
</form>
</tr>
</table>

@ -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
}

Loading…
Cancel
Save