Easy Mark Explicit button for admin users

This commit is contained in:
Noah Petherbridge 2023-12-26 16:26:23 -08:00
parent 2d8cdad601
commit be835ca8f9
3 changed files with 64 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package admin
import (
"net/http"
"strconv"
"strings"
"code.nonshy.com/nonshy/website/pkg/config"
"code.nonshy.com/nonshy/website/pkg/models"
@ -11,6 +12,44 @@ import (
"code.nonshy.com/nonshy/website/pkg/templates"
)
// Mark a user photo as Explicit for them.
func MarkPhotoExplicit() http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var (
photoID uint64
next = r.FormValue("next")
)
if !strings.HasPrefix(next, "/") {
next = "/"
}
if idInt, err := strconv.Atoi(r.FormValue("photo_id")); err == nil {
photoID = uint64(idInt)
} else {
session.FlashError(w, r, "Invalid or missing photo_id parameter: %s", err)
templates.Redirect(w, next)
return
}
// Get this photo.
photo, err := models.GetPhoto(photoID)
if err != nil {
session.FlashError(w, r, "Didn't find photo ID in database: %s", err)
templates.Redirect(w, next)
return
}
photo.Explicit = true
if err := photo.Save(); err != nil {
session.FlashError(w, r, "Couldn't save photo: %s", err)
} else {
session.Flash(w, r, "Marked photo as Explicit!")
}
templates.Redirect(w, next)
})
}
// Admin actions against a user account.
func UserActions() http.HandlerFunc {
tmpl := templates.Must("admin/user_actions.html")

View File

@ -98,6 +98,7 @@ func New() http.Handler {
mux.Handle("/forum/admin", middleware.AdminRequired(config.ScopeForumAdmin, forum.Manage()))
mux.Handle("/forum/admin/edit", middleware.AdminRequired(config.ScopeForumAdmin, forum.AddEdit()))
mux.Handle("/inner-circle/remove", middleware.LoginRequired(account.RemoveCircle()))
mux.Handle("/admin/photo/mark-explicit", middleware.AdminRequired(config.ScopePhotoModerator, admin.MarkPhotoExplicit()))
// JSON API endpoints.
mux.HandleFunc("/v1/version", api.Version())

View File

@ -479,6 +479,18 @@
{{template "card-body" .}}
<!-- Admin actions: quick mark photo as explicit -->
{{if and ($Root.CurrentUser.IsAdmin) (not .Explicit)}}
<div class="mt-2">
<a href="/admin/photo/mark-explicit?photo_id={{.ID}}&next={{$Root.Request.URL.Path}}"
class="has-text-danger is-size-7"
onclick="return confirm('Do you want to mark this photo as Explicit?')">
<i class="fa fa-peace mr-1"></i>
Mark photo as Explicit
</a>
</div>
{{end}}
<!-- Like & Comments buttons -->
{{if not $Root.AdminView}}
<div class="mt-4 columns is-centered is-mobile is-gapless">
@ -591,6 +603,18 @@
{{template "card-body" .}}
<!-- Admin actions: quick mark photo as explicit -->
{{if and ($Root.CurrentUser.IsAdmin) (not .Explicit)}}
<div class="mt-2">
<a href="/admin/photo/mark-explicit?photo_id={{.ID}}&next={{$Root.Request.URL}}"
class="has-text-danger is-size-7"
onclick="return confirm('Do you want to mark this photo as Explicit?')">
<i class="fa fa-peace mr-1"></i>
Mark photo as Explicit
</a>
</div>
{{end}}
<!-- Like & Comments buttons -->
{{if not $Root.AdminView}}
<div class="mt-4 columns is-centered is-mobile is-gapless">