Backend: Hide private photos in moments

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-06-05 10:59:59 +02:00
parent 43ec7e14e3
commit 5c574e3837
3 changed files with 13 additions and 8 deletions

View file

@ -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()

View file

@ -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 {

View file

@ -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)