From ea1c4aab18ac721121fca16684e3f12d17687cef Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Tue, 31 Dec 2024 15:56:08 -0800 Subject: [PATCH] Warning before user deletes their entire gallery * If a user is about to delete all remaining gallery photos, and their account is certified, show a warning banner and extra confirmation modal before they continue with the deletion, that their account will lose its certified status. * Minor improvements to change logs around cert photos. --- pkg/controller/photo/batch_edit.go | 19 ++++++++++++++++++- pkg/controller/photo/certification.go | 11 +++++++++-- pkg/models/certification.go | 3 +++ web/templates/photo/batch_edit.html | 26 +++++++++++++++++++++++++- 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/pkg/controller/photo/batch_edit.go b/pkg/controller/photo/batch_edit.go index 061b215..e80ad47 100644 --- a/pkg/controller/photo/batch_edit.go +++ b/pkg/controller/photo/batch_edit.go @@ -58,7 +58,8 @@ func BatchEdit() http.HandlerFunc { // Validate permission to edit all of these photos. var ( - ownerIDs []uint64 + ownerIDs []uint64 + allMyPhotos = true // all photos belong to the current user ) for _, photo := range photos { @@ -68,6 +69,10 @@ func BatchEdit() http.HandlerFunc { } ownerIDs = append(ownerIDs, photo.UserID) + + if photo.UserID != currentUser.ID { + allMyPhotos = false + } } // Load the photo owners. @@ -92,6 +97,15 @@ func BatchEdit() http.HandlerFunc { } } + // Warning in case the user will delete ALL of their photos and lose their certified status. + var warningDeletingAllPhotos bool + if intent == "delete" && allMyPhotos && currentUser.Certified { + photoCount := models.CountPhotos(currentUser.ID) + if int64(len(photos)) >= photoCount { + warningDeletingAllPhotos = true + } + } + // Confirm batch deletion or edit. if r.Method == http.MethodPost { @@ -130,6 +144,9 @@ func BatchEdit() http.HandlerFunc { var vars = map[string]interface{}{ "Intent": intent, "Photos": photos, + + // Warn if the current user will delete all their photos. + "WarningDeletingAllPhotos": warningDeletingAllPhotos, } if err := tmpl.Execute(w, r, vars); err != nil { diff --git a/pkg/controller/photo/certification.go b/pkg/controller/photo/certification.go index cae76fc..0e4bf7f 100644 --- a/pkg/controller/photo/certification.go +++ b/pkg/controller/photo/certification.go @@ -193,7 +193,13 @@ func Certification() http.HandlerFunc { // Log the change. Note the original IP and GeoIP insights - we once saw a spammer upload // their cert photo from Nigeria, and before we could reject it, they removed and reuploaded // it from New York using a VPN. If it wasn't seen in real time, this might have slipped by. - var insights string + var ( + logMessage = "Uploaded a new certification photo." + insights string + ) + if isSecondary { + logMessage = "Uploaded a secondary photo ID for certification." + } if i, err := geoip.GetRequestInsights(r); err == nil { insights = i.String() } else { @@ -204,7 +210,8 @@ func Certification() http.HandlerFunc { "certification_photos", currentUser.ID, fmt.Sprintf( - "Uploaded a new certification photo.\n\n* From IP address: %s\n* GeoIP insight: %s", + "%s\n\n* From IP address: %s\n* GeoIP insight: %s", + logMessage, cert.IPAddress, insights, ), diff --git a/pkg/models/certification.go b/pkg/models/certification.go index 278ebd3..85f245c 100644 --- a/pkg/models/certification.go +++ b/pkg/models/certification.go @@ -155,6 +155,9 @@ func MaybeRevokeCertificationForEmptyGallery(user *User) bool { log.Error("Couldn't save feedback from user auto-revoking their cert photo: %s", err) } + // Update the cert photo's change log. + LogEvent(user, nil, ChangeLogRejected, "certification_photos", user.ID, "Their cert photo was automatically rejected because they deleted their entire photo gallery.") + return true } diff --git a/web/templates/photo/batch_edit.html b/web/templates/photo/batch_edit.html index cb7bab2..ff26f34 100644 --- a/web/templates/photo/batch_edit.html +++ b/web/templates/photo/batch_edit.html @@ -150,9 +150,33 @@ this photo? {{- end}} + + + {{if .WarningDeletingAllPhotos}} +
+
+

+ + Certification Photo Warning +

+

+ You are about to delete ALL remaining photos on your gallery. If you continue with + this action, your Certification Photo will be automatically revoked + and your account will lose its Certified status. You would then need to submit a new + Certification Photo for approval (after uploading pictures back onto your gallery) to + continue using {{PrettyTitle}}. +

+
+
+ {{end}} +
{{if eq .Intent "delete"}} - + {{else}} {{end}}