mirror of
https://github.com/writefreely/writefreely
synced 2024-11-10 11:24:13 +00:00
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:
parent
5429ca4ab0
commit
da7dcfee6a
3 changed files with 12 additions and 8 deletions
|
@ -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>
|
||||
|
|
4
users.go
4
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue