text attachments for cosora and shadow

reduce bytes and boilerplate
This commit is contained in:
Azareal 2020-06-08 21:31:45 +10:00
parent 8be3f79abb
commit 5073c78364
10 changed files with 63 additions and 50 deletions

View File

@ -8,8 +8,8 @@ import (
c "github.com/Azareal/Gosora/common" c "github.com/Azareal/Gosora/common"
) )
func Users(w http.ResponseWriter, r *http.Request, user *c.User) c.RouteError { func Users(w http.ResponseWriter, r *http.Request, u *c.User) c.RouteError {
basePage, ferr := buildBasePage(w, r, user, "users", "users") basePage, ferr := buildBasePage(w, r, u, "users", "users")
if ferr != nil { if ferr != nil {
return ferr return ferr
} }
@ -27,27 +27,27 @@ func Users(w http.ResponseWriter, r *http.Request, user *c.User) c.RouteError {
return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "", "", "panel_users", &pi}) return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "", "", "panel_users", &pi})
} }
func UsersEdit(w http.ResponseWriter, r *http.Request, user *c.User, suid string) c.RouteError { func UsersEdit(w http.ResponseWriter, r *http.Request, u *c.User, suid string) c.RouteError {
basePage, ferr := buildBasePage(w, r, user, "edit_user", "users") basePage, ferr := buildBasePage(w, r, u, "edit_user", "users")
if ferr != nil { if ferr != nil {
return ferr return ferr
} }
if !user.Perms.EditUser { if !u.Perms.EditUser {
return c.NoPermissions(w, r, user) return c.NoPermissions(w, r, u)
} }
uid, err := strconv.Atoi(suid) uid, err := strconv.Atoi(suid)
if err != nil { if err != nil {
return c.LocalError("The provided UserID is not a valid number.", w, r, user) return c.LocalError("The provided UserID is not a valid number.", w, r, u)
} }
targetUser, err := c.Users.Get(uid) targetUser, err := c.Users.Get(uid)
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
return c.LocalError("The user you're trying to edit doesn't exist.", w, r, user) return c.LocalError("The user you're trying to edit doesn't exist.", w, r, u)
} else if err != nil { } else if err != nil {
return c.InternalError(err, w, r) return c.InternalError(err, w, r)
} }
if targetUser.IsAdmin && !user.IsAdmin { if targetUser.IsAdmin && !u.IsAdmin {
return c.LocalError("Only administrators can edit the account of an administrator.", w, r, user) return c.LocalError("Only administrators can edit the account of an administrator.", w, r, u)
} }
// ? - Should we stop admins from deleting all the groups? Maybe, protect the group they're currently using? // ? - Should we stop admins from deleting all the groups? Maybe, protect the group they're currently using?
@ -58,10 +58,10 @@ func UsersEdit(w http.ResponseWriter, r *http.Request, user *c.User, suid string
var groupList []*c.Group var groupList []*c.Group
for _, group := range groups { for _, group := range groups {
if !user.Perms.EditUserGroupAdmin && group.IsAdmin { if !u.Perms.EditUserGroupAdmin && group.IsAdmin {
continue continue
} }
if !user.Perms.EditUserGroupSuperMod && group.IsMod { if !u.Perms.EditUserGroupSuperMod && group.IsMod {
continue continue
} }
groupList = append(groupList, group) groupList = append(groupList, group)
@ -183,31 +183,31 @@ func UsersEditSubmit(w http.ResponseWriter, r *http.Request, user *c.User, suid
return nil return nil
} }
func UsersAvatarSubmit(w http.ResponseWriter, r *http.Request, user *c.User, suid string) c.RouteError { func UsersAvatarSubmit(w http.ResponseWriter, r *http.Request, u *c.User, suid string) c.RouteError {
_, ferr := c.SimplePanelUserCheck(w, r, user) _, ferr := c.SimplePanelUserCheck(w, r, u)
if ferr != nil { if ferr != nil {
return ferr return ferr
} }
// TODO: Check the UploadAvatars permission too? // TODO: Check the UploadAvatars permission too?
if !user.Perms.EditUser { if !u.Perms.EditUser {
return c.NoPermissions(w, r, user) return c.NoPermissions(w, r, u)
} }
uid, err := strconv.Atoi(suid) uid, err := strconv.Atoi(suid)
if err != nil { if err != nil {
return c.LocalError("The provided UserID is not a valid number.", w, r, user) return c.LocalError("The provided UserID is not a valid number.", w, r, u)
} }
targetUser, err := c.Users.Get(uid) targetUser, err := c.Users.Get(uid)
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
return c.LocalError("The user you're trying to edit doesn't exist.", w, r, user) return c.LocalError("The user you're trying to edit doesn't exist.", w, r, u)
} else if err != nil { } else if err != nil {
return c.InternalError(err, w, r) return c.InternalError(err, w, r)
} }
if targetUser.IsAdmin && !user.IsAdmin { if targetUser.IsAdmin && !u.IsAdmin {
return c.LocalError("Only administrators can edit the account of other administrators.", w, r, user) return c.LocalError("Only administrators can edit the account of other administrators.", w, r, u)
} }
ext, ferr := c.UploadAvatar(w, r, user, targetUser.ID) ext, ferr := c.UploadAvatar(w, r, u, targetUser.ID)
if ferr != nil { if ferr != nil {
return ferr return ferr
} }
@ -221,7 +221,7 @@ func UsersAvatarSubmit(w http.ResponseWriter, r *http.Request, user *c.User, sui
return c.InternalError(err, w, r) return c.InternalError(err, w, r)
} }
err = c.AdminLogs.Create("edit", targetUser.ID, "user", user.GetIP(), user.ID) err = c.AdminLogs.Create("edit", targetUser.ID, "user", u.GetIP(), u.ID)
if err != nil { if err != nil {
return c.InternalError(err, w, r) return c.InternalError(err, w, r)
} }
@ -234,34 +234,34 @@ func UsersAvatarSubmit(w http.ResponseWriter, r *http.Request, user *c.User, sui
return nil return nil
} }
func UsersAvatarRemoveSubmit(w http.ResponseWriter, r *http.Request, user *c.User, suid string) c.RouteError { func UsersAvatarRemoveSubmit(w http.ResponseWriter, r *http.Request, u *c.User, suid string) c.RouteError {
_, ferr := c.SimplePanelUserCheck(w, r, user) _, ferr := c.SimplePanelUserCheck(w, r, u)
if ferr != nil { if ferr != nil {
return ferr return ferr
} }
if !user.Perms.EditUser { if !u.Perms.EditUser {
return c.NoPermissions(w, r, user) return c.NoPermissions(w, r, u)
} }
uid, err := strconv.Atoi(suid) uid, err := strconv.Atoi(suid)
if err != nil { if err != nil {
return c.LocalError("The provided UserID is not a valid number.", w, r, user) return c.LocalError("The provided UserID is not a valid number.", w, r, u)
} }
targetUser, err := c.Users.Get(uid) targetUser, err := c.Users.Get(uid)
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
return c.LocalError("The user you're trying to edit doesn't exist.", w, r, user) return c.LocalError("The user you're trying to edit doesn't exist.", w, r, u)
} else if err != nil { } else if err != nil {
return c.InternalError(err, w, r) return c.InternalError(err, w, r)
} }
if targetUser.IsAdmin && !user.IsAdmin { if targetUser.IsAdmin && !u.IsAdmin {
return c.LocalError("Only administrators can edit the account of other administrators.", w, r, user) return c.LocalError("Only administrators can edit the account of other administrators.", w, r, u)
} }
ferr = c.ChangeAvatar("", w, r, targetUser) ferr = c.ChangeAvatar("", w, r, targetUser)
if ferr != nil { if ferr != nil {
return ferr return ferr
} }
err = c.AdminLogs.Create("edit", targetUser.ID, "user", user.GetIP(), user.ID) err = c.AdminLogs.Create("edit", targetUser.ID, "user", u.GetIP(), u.ID)
if err != nil { if err != nil {
return c.InternalError(err, w, r) return c.InternalError(err, w, r)
} }

View File

@ -86,8 +86,8 @@ func PollResults(w http.ResponseWriter, r *http.Request, user *c.User, sPollID s
defer rows.Close() defer rows.Close()
optionList := "" optionList := ""
var votes int
for rows.Next() { for rows.Next() {
var votes int
err := rows.Scan(&votes) err := rows.Scan(&votes)
if err != nil { if err != nil {
return c.InternalError(err, w, r) return c.InternalError(err, w, r)

View File

@ -4,8 +4,8 @@
{{template "panel_analytics_time_range.html" . }} {{template "panel_analytics_time_range.html" . }}
</div> </div>
</div> </div>
<form id="timeRangeForm" name="timeRangeForm" action="/panel/analytics/agent/{{.Agent}}" method="get"></form> <form id="timeRangeForm"name="timeRangeForm"action="/panel/analytics/agent/{{.Agent}}"method="get"></form>
<div id="panel_analytics_views" class="colstack_graph_holder"> <div id="panel_analytics_views"class="colstack_graph_holder">
<div class="ct_chart"></div> <div class="ct_chart"></div>
</div> </div>
{{template "panel_analytics_script.html" . }} {{template "panel_analytics_script.html" . }}

View File

@ -4,14 +4,14 @@
{{template "panel_analytics_time_range.html" . }} {{template "panel_analytics_time_range.html" . }}
</div> </div>
</div> </div>
<form id="timeRangeForm" name="timeRangeForm" action="/panel/analytics/agents/" method="get"></form> <form id="timeRangeForm"name="timeRangeForm"action="/panel/analytics/agents/"method="get"></form>
<div id="panel_analytics_agents_chart" class="colstack_graph_holder"> <div id="panel_analytics_agents_chart"class="colstack_graph_holder">
<div class="ct_chart"></div> <div class="ct_chart"></div>
</div> </div>
<div id="panel_analytics_agents" class="colstack_item rowlist"> <div id="panel_analytics_agents"class="colstack_item rowlist">
{{range .ItemList}} {{range .ItemList}}
<div class="rowitem panel_compactrow editable_parent"> <div class="rowitem panel_compactrow editable_parent">
<a href="/panel/analytics/agent/{{.Agent}}" class="panel_upshift">{{.FriendlyAgent}}</a> <a href="/panel/analytics/agent/{{.Agent}}"class="panel_upshift">{{.FriendlyAgent}}</a>
<span class="panel_compacttext to_right">{{.Count}}{{lang "panel_stats_views_suffix"}}</span> <span class="panel_compacttext to_right">{{.Count}}{{lang "panel_stats_views_suffix"}}</span>
</div> </div>
{{else}}<div class="rowitem passive rowmsg">{{lang "panel_stats_user_agents_no_user_agents"}}</div>{{end}} {{else}}<div class="rowitem passive rowmsg">{{lang "panel_stats_user_agents_no_user_agents"}}</div>{{end}}

View File

@ -4,8 +4,8 @@
{{template "panel_analytics_time_range.html" . }} {{template "panel_analytics_time_range.html" . }}
</div> </div>
</div> </div>
<form id="timeRangeForm" name="timeRangeForm" action="/panel/analytics/forum/{{.Agent}}" method="get"></form> <form id="timeRangeForm"name="timeRangeForm"action="/panel/analytics/forum/{{.Agent}}"method="get"></form>
<div id="panel_analytics_views" class="colstack_graph_holder"> <div id="panel_analytics_views"class="colstack_graph_holder">
<div class="ct_chart"></div> <div class="ct_chart"></div>
</div> </div>
{{template "panel_analytics_script.html" . }} {{template "panel_analytics_script.html" . }}

View File

@ -4,14 +4,14 @@
{{template "panel_analytics_time_range.html" . }} {{template "panel_analytics_time_range.html" . }}
</div> </div>
</div> </div>
<form id="timeRangeForm" name="timeRangeForm" action="/panel/analytics/forums/" method="get"></form> <form id="timeRangeForm"name="timeRangeForm"action="/panel/analytics/forums/"method="get"></form>
<div id="panel_analytics_forums_chart" class="colstack_graph_holder"> <div id="panel_analytics_forums_chart"class="colstack_graph_holder">
<div class="ct_chart"></div> <div class="ct_chart"></div>
</div> </div>
<div id="panel_analytics_routes" class="colstack_item rowlist"> <div id="panel_analytics_routes"class="colstack_item rowlist">
{{range .ItemList}} {{range .ItemList}}
<div class="rowitem panel_compactrow editable_parent"> <div class="rowitem panel_compactrow editable_parent">
<a href="/panel/analytics/forum/{{.Agent}}" class="panel_upshift">{{.FriendlyAgent}}</a> <a href="/panel/analytics/forum/{{.Agent}}"class="panel_upshift">{{.FriendlyAgent}}</a>
<span class="panel_compacttext to_right">{{.Count}}{{lang "panel_stats_views_suffix"}}</span> <span class="panel_compacttext to_right">{{.Count}}{{lang "panel_stats_views_suffix"}}</span>
</div> </div>
{{else}}<div class="rowitem passive rowmsg">{{lang "panel_stats_forums_no_forums"}}</div>{{end}} {{else}}<div class="rowitem passive rowmsg">{{lang "panel_stats_forums_no_forums"}}</div>{{end}}

View File

@ -4,8 +4,8 @@
{{template "panel_analytics_time_range.html" . }} {{template "panel_analytics_time_range.html" . }}
</div> </div>
</div> </div>
<form id="timeRangeForm" name="timeRangeForm" action="/panel/analytics/lang/{{.Agent}}" method="get"></form> <form id="timeRangeForm"name="timeRangeForm"action="/panel/analytics/lang/{{.Agent}}"method="get"></form>
<div id="panel_analytics_langs" class="colstack_graph_holder"> <div id="panel_analytics_langs"class="colstack_graph_holder">
<div class="ct_chart"></div> <div class="ct_chart"></div>
</div> </div>
{{template "panel_analytics_script.html" . }} {{template "panel_analytics_script.html" . }}

View File

@ -4,14 +4,14 @@
{{template "panel_analytics_time_range.html" . }} {{template "panel_analytics_time_range.html" . }}
</div> </div>
</div> </div>
<form id="timeRangeForm" name="timeRangeForm" action="/panel/analytics/langs/" method="get"></form> <form id="timeRangeForm"name="timeRangeForm"action="/panel/analytics/langs/"method="get"></form>
<div id="panel_analytics_langs_chart" class="colstack_graph_holder"> <div id="panel_analytics_langs_chart"class="colstack_graph_holder">
<div class="ct_chart"></div> <div class="ct_chart"></div>
</div> </div>
<div id="panel_analytics_langs" class="colstack_item rowlist"> <div id="panel_analytics_langs"class="colstack_item rowlist">
{{range .ItemList}} {{range .ItemList}}
<div class="rowitem panel_compactrow editable_parent"> <div class="rowitem panel_compactrow editable_parent">
<a href="/panel/analytics/lang/{{.Agent}}" class="panel_upshift">{{.FriendlyAgent}}</a> <a href="/panel/analytics/lang/{{.Agent}}"class="panel_upshift">{{.FriendlyAgent}}</a>
<span class="panel_compacttext to_right">{{.Count}}{{lang "panel_stats_views_suffix"}}</span> <span class="panel_compacttext to_right">{{.Count}}{{lang "panel_stats_views_suffix"}}</span>
</div> </div>
{{else}}<div class="rowitem passive rowmsg">{{lang "panel_stats_languages_no_languages"}}</div>{{end}} {{else}}<div class="rowitem passive rowmsg">{{lang "panel_stats_languages_no_languages"}}</div>{{end}}

View File

@ -1266,6 +1266,13 @@ red {
.hide_spoil img { .hide_spoil img {
content: " "; content: " ";
} }
.attach_box {
background-color: #5a5555;
background-color: #EFEEEE;
border-radius: 3px;
padding: 16px;
white-space: nowrap;
}
#ip_search_container .rowlist:not(.has_items) { #ip_search_container .rowlist:not(.has_items) {
display: block; display: block;

View File

@ -377,6 +377,12 @@ red {
.hide_spoil img { .hide_spoil img {
content: " "; content: " ";
} }
.attach_box {
background-color: #5a5555;
background-color: rgb(71,71,76);
border-radius: 3px;
padding: 16px;
}
.formrow.real_first_child, .formrow:first-child { .formrow.real_first_child, .formrow:first-child {
margin-top: 8px; margin-top: 8px;