Code cleanup

This commit is contained in:
Noah Petherbridge 2024-10-04 21:22:52 -07:00
parent 8078ff8755
commit 77a9d9a7fd

View File

@ -15,7 +15,6 @@ import (
// BatchEdit controller (/photo/batch-edit?id=N) to change properties about your picture.
func BatchEdit() http.HandlerFunc {
// Reuse the upload page but with an EditPhoto variable.
tmpl := templates.Must("photo/batch_edit.html")
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var (
@ -35,8 +34,6 @@ func BatchEdit() http.HandlerFunc {
}
}
log.Error("photoIDs: %+v", photoIDs)
// Validation.
if len(photoIDs) == 0 || len(photoIDs) > 100 {
session.FlashError(w, r, "Invalid number of photo IDs.")
@ -59,17 +56,11 @@ func BatchEdit() http.HandlerFunc {
return
}
// In case an admin is editing this photo: remember the HTTP request current user,
// before the currentUser may be set to the photo's owner below.
// var requestUser = currentUser
// Validate permission to edit all of these photos.
var (
ownerIDs []uint64
mapPhotos = map[uint64]*models.Photo{}
)
for _, photo := range photos {
mapPhotos[photo.ID] = photo
if !photo.CanBeEditedBy(currentUser) {
templates.ForbiddenPage(w, r)
@ -95,7 +86,7 @@ func BatchEdit() http.HandlerFunc {
// Check if this user's profile ID is being deleted.
if user.ProfilePhotoID != nil {
if _, ok := mapPhotos[*user.ProfilePhotoID]; ok {
if _, ok := photos[*user.ProfilePhotoID]; ok {
wasUserProfilePicture[user.ID] = true
}
}
@ -106,7 +97,7 @@ func BatchEdit() http.HandlerFunc {
confirm := r.PostFormValue("confirm") == "true"
if !confirm {
session.FlashError(w, r, "Confirm you want to delete this photo.")
session.FlashError(w, r, "Confirm you want to modify this photo.")
templates.Redirect(w, redirectURI)
return
}