From 5c574e3837b924c73c5b3d2f50b55538c5021d86 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Fri, 5 Jun 2020 10:59:59 +0200 Subject: [PATCH] Backend: Hide private photos in moments Signed-off-by: Michael Mayer --- internal/entity/album.go | 5 +++-- internal/photoprism/moments.go | 8 ++++++-- internal/query/moments.go | 8 ++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/internal/entity/album.go b/internal/entity/album.go index 89f98c463..bddf9c472 100644 --- a/internal/entity/album.go +++ b/internal/entity/album.go @@ -157,8 +157,9 @@ func NewMonthAlbum(albumTitle, albumSlug string, year, month int) *Album { } f := form.PhotoSearch{ - Year: year, - Month: month, + Year: year, + Month: month, + Public: true, } now := time.Now().UTC() diff --git a/internal/photoprism/moments.go b/internal/photoprism/moments.go index 440a5c574..93be72220 100644 --- a/internal/photoprism/moments.go +++ b/internal/photoprism/moments.go @@ -72,7 +72,8 @@ func (m *Moments) Start() (err error) { } else { for _, mom := range results { f := form.PhotoSearch{ - Path: mom.Path, + Path: mom.Path, + Public: true, } if a := entity.FindAlbumBySlug(mom.Slug(), entity.TypeFolder); a != nil { @@ -126,6 +127,7 @@ func (m *Moments) Start() (err error) { f := form.PhotoSearch{ Country: mom.Country, Year: mom.Year, + Public: true, } if a := entity.FindAlbumBySlug(mom.Slug(), entity.TypeMoment); a != nil { @@ -156,6 +158,7 @@ func (m *Moments) Start() (err error) { f := form.PhotoSearch{ Country: mom.Country, State: mom.State, + Public: true, } if a := entity.FindAlbumBySlug(mom.Slug(), entity.TypeMoment); a != nil { @@ -183,7 +186,8 @@ func (m *Moments) Start() (err error) { } else { for _, mom := range results { f := form.PhotoSearch{ - Label: mom.Label, + Label: mom.Label, + Public: true, } if a := entity.FindAlbumBySlug(mom.Slug(), entity.TypeMoment); a != nil { diff --git a/internal/query/moments.go b/internal/query/moments.go index bc3adcf9c..2fdc30fe1 100644 --- a/internal/query/moments.go +++ b/internal/query/moments.go @@ -89,7 +89,7 @@ type Moments []Moment func MomentsTime(threshold int) (results Moments, err error) { db := UnscopedDb().Table("photos"). Select("photos.photo_year AS year, photos.photo_month AS month, COUNT(*) AS photo_count"). - Where("photos.photo_quality >= 3 AND deleted_at IS NULL AND photos.photo_year > 0 AND photos.photo_month > 0"). + Where("photos.photo_quality >= 3 AND deleted_at IS NULL AND photo_private = 0 AND photos.photo_year > 0 AND photos.photo_month > 0"). Group("photos.photo_year, photos.photo_month"). Order("photos.photo_year DESC, photos.photo_month DESC"). Having("photo_count >= ?", threshold) @@ -105,7 +105,7 @@ func MomentsTime(threshold int) (results Moments, err error) { func MomentsCountries(threshold int) (results Moments, err error) { db := UnscopedDb().Table("photos"). Select("photo_country AS country, photo_year AS year, COUNT(*) AS photo_count "). - Where("photos.photo_quality >= 3 AND deleted_at IS NULL AND photo_country <> 'zz' AND photo_year > 0"). + Where("photos.photo_quality >= 3 AND deleted_at IS NULL AND photo_private = 0 AND photo_country <> 'zz' AND photo_year > 0"). Group("photo_country, photo_year"). Having("photo_count >= ?", threshold) @@ -121,7 +121,7 @@ func MomentsStates(threshold int) (results Moments, err error) { db := UnscopedDb().Table("photos"). Select("p.loc_country AS country, p.loc_state AS state, COUNT(*) AS photo_count"). Joins("JOIN places p ON p.id = photos.place_id"). - Where("photos.photo_quality >= 3 AND photos.deleted_at IS NULL AND p.loc_state <> '' AND p.loc_country <> 'zz'"). + Where("photos.photo_quality >= 3 AND photos.deleted_at IS NULL AND photo_private = 0 AND p.loc_state <> '' AND p.loc_country <> 'zz'"). Group("p.loc_country, p.loc_state"). Having("photo_count >= ?", threshold) @@ -144,7 +144,7 @@ func MomentsLabels(threshold int) (results Moments, err error) { Select("l.label_slug AS label, COUNT(*) AS photo_count"). Joins("JOIN photos_labels pl ON pl.photo_id = photos.id AND pl.uncertainty < 100"). Joins("JOIN labels l ON l.id = pl.label_id"). - Where("photos.photo_quality >= 3 AND photos.deleted_at IS NULL AND l.label_slug IN (?)", cats). + Where("photos.photo_quality >= 3 AND photos.deleted_at IS NULL AND photo_private = 0 AND l.label_slug IN (?)", cats). Group("l.label_slug"). Having("photo_count >= ?", threshold)