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
This commit is contained in:
Matt Baer 2019-11-07 14:07:00 +09:00
parent 5429ca4ab0
commit da7dcfee6a
3 changed files with 12 additions and 8 deletions

View file

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

View file

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

View file

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