diff --git a/pkg/controller/admin/user_actions.go b/pkg/controller/admin/user_actions.go index 1046601..c0738de 100644 --- a/pkg/controller/admin/user_actions.go +++ b/pkg/controller/admin/user_actions.go @@ -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") diff --git a/pkg/router/router.go b/pkg/router/router.go index 7772260..9ae9618 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -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()) diff --git a/web/templates/photo/gallery.html b/web/templates/photo/gallery.html index be15b1d..37cb219 100644 --- a/web/templates/photo/gallery.html +++ b/web/templates/photo/gallery.html @@ -479,6 +479,18 @@ {{template "card-body" .}} + + {{if and ($Root.CurrentUser.IsAdmin) (not .Explicit)}} +
+ + + Mark photo as Explicit + +
+ {{end}} + {{if not $Root.AdminView}}
@@ -591,6 +603,18 @@ {{template "card-body" .}} + + {{if and ($Root.CurrentUser.IsAdmin) (not .Explicit)}} +
+ + + Mark photo as Explicit + +
+ {{end}} + {{if not $Root.AdminView}}