From 90b97708f708c3c8f27b56b0413a3e21e983a851 Mon Sep 17 00:00:00 2001 From: Noah Date: Fri, 9 Sep 2022 20:11:50 -0700 Subject: [PATCH] Explicit admin filter for the site gallery * For admins, make it a specific opt-in filter for the Site Gallery to show all pictures regardless of friendship or grant (for moderation purposes). On this view, Like and Comment buttons are taken away. Non-admins are not shown the option and the back-end ignores the parameter for them. * Fix user avatars on compose and admin actions page. --- pkg/controller/photo/site_gallery.go | 4 +++- pkg/models/photo.go | 6 ++++-- web/templates/admin/user_actions.html | 4 ++-- web/templates/inbox/compose.html | 4 ++-- web/templates/photo/gallery.html | 18 ++++++++++++++++++ 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/pkg/controller/photo/site_gallery.go b/pkg/controller/photo/site_gallery.go index 681c8df..45dd8a2 100644 --- a/pkg/controller/photo/site_gallery.go +++ b/pkg/controller/photo/site_gallery.go @@ -27,6 +27,7 @@ func SiteGallery() http.HandlerFunc { // Search filters. filterExplicit = r.FormValue("explicit") filterVisibility = r.FormValue("visibility") + adminView = r.FormValue("admin_view") == "true" sort = r.FormValue("sort") sortOK bool ) @@ -60,7 +61,7 @@ func SiteGallery() http.HandlerFunc { Sort: sort, } pager.ParsePage(r) - photos, err := models.PaginateGalleryPhotos(currentUser, filterExplicit, filterVisibility, pager) + photos, err := models.PaginateGalleryPhotos(currentUser, filterExplicit, filterVisibility, adminView, pager) // Bulk load the users associated with these photos. var userIDs = []uint64{} @@ -93,6 +94,7 @@ func SiteGallery() http.HandlerFunc { "Sort": sort, "FilterExplicit": filterExplicit, "FilterVisibility": filterVisibility, + "AdminView": adminView, } if err := tmpl.Execute(w, r, vars); err != nil { diff --git a/pkg/models/photo.go b/pkg/models/photo.go index cfbd33b..a46200b 100644 --- a/pkg/models/photo.go +++ b/pkg/models/photo.go @@ -154,14 +154,13 @@ PaginateGalleryPhotos gets a page of all public user photos for the site gallery Admin view returns ALL photos regardless of Gallery status. */ -func PaginateGalleryPhotos(user *User, filterExplicit, filterVisibility string, pager *Pagination) ([]*Photo, error) { +func PaginateGalleryPhotos(user *User, filterExplicit, filterVisibility string, adminView bool, pager *Pagination) ([]*Photo, error) { var ( p = []*Photo{} query *gorm.DB // Get the user ID and their preferences. userID = user.ID - adminView = user.IsAdmin // Admins see everything on the site. explicitOK = user.Explicit // User opted-in for explicit content blocklist = BlockedUserIDs(userID) @@ -171,6 +170,9 @@ func PaginateGalleryPhotos(user *User, filterExplicit, filterVisibility string, placeholders = []interface{}{} ) + // Admins see everything on the site (only an admin user can get an admin view). + adminView = user.IsAdmin && adminView + // Include ourself in our friend IDs. friendIDs = append(friendIDs, userID) diff --git a/web/templates/admin/user_actions.html b/web/templates/admin/user_actions.html index 8ed64bb..dbcdb5b 100644 --- a/web/templates/admin/user_actions.html +++ b/web/templates/admin/user_actions.html @@ -38,10 +38,10 @@
- {{template "avatar-64x64" .}} + {{template "avatar-64x64" .User}}
-

{{.NameOrUsername}}

+

{{.User.NameOrUsername}}

{{.User.Username}} diff --git a/web/templates/inbox/compose.html b/web/templates/inbox/compose.html index c684bfe..cdf07a0 100644 --- a/web/templates/inbox/compose.html +++ b/web/templates/inbox/compose.html @@ -26,10 +26,10 @@

- {{template "avatar-64x64" .}} + {{template "avatar-64x64" .User}}
-

{{.NameOrUsername}}

+

{{.User.NameOrUsername}}

{{.User.Username}} diff --git a/web/templates/photo/gallery.html b/web/templates/photo/gallery.html index 27d7447..93cc07e 100644 --- a/web/templates/photo/gallery.html +++ b/web/templates/photo/gallery.html @@ -253,6 +253,20 @@

+ {{if .CurrentUser.IsAdmin}} +
+
+ +
+ +
+
+
+ {{end}} +
Reset @@ -356,6 +370,7 @@ {{template "card-body" .}} + {{if not $Root.AdminView}}
{{$Like := $Root.LikeMap.Get .ID}} @@ -379,6 +394,7 @@
+ {{end}}
@@ -456,6 +472,7 @@ {{template "card-body" .}} + {{if not $Root.AdminView}}
{{$Like := $Root.LikeMap.Get .ID}} @@ -479,6 +496,7 @@
+ {{end}}