Skip to content

Commit 8ddbe00

Browse files
committed
update all policies
1 parent 19eef1f commit 8ddbe00

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

app/models/photo.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ class Photo < ApplicationRecord
2525
joins(:photo_album).where(photo_albums: { visibility: 'everybody' })
2626
}
2727

28-
scope :alumni_visible, lambda {
29-
joins(:photo_album).where(photo_albums: { visibility: 'alumni' })
28+
scope :alumni_visible, lambda { |start_date, end_date|
29+
joins(:photo_album)
30+
.where(photo_albums: { visibility: 'alumni' })
31+
.or(photo_albums: { visibility: 'everybody' })
32+
.or(where.not(photo_albums: { date: nil}).where(photo_albums: { date: start_date..end_date}))
33+
.or(where(photo_albums: { date: nil }).where(photo_albums: { created_at: start_date..end_date}))
3034
}
3135

3236
scope :with_tags, lambda {

app/models/photo_album.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ class PhotoAlbum < ApplicationRecord
99
validates :title, presence: true
1010
validates :visibility, inclusion: { in: %w[everybody alumni members] }
1111

12-
scope :alumni_visible, -> { where(visibility: 'alumni') }
13-
scope :publicly_visible, -> { where(visibility: 'everybody') }
14-
scope :posted_between_or_publicly_visible, lambda { |start_date, end_date|
15-
where(publicly_visible: true)
16-
.or(where.not(date: nil).where(date: start_date..end_date))
17-
.or(where(date: nil).where(created_at: start_date..end_date))
12+
scope :publicly_visible, lambda {
13+
joins(:photo_album).where(photo_albums: { visibility: 'everybody' })
14+
}
15+
scope :alumni_visible, lambda { |start_date, end_date|
16+
joins(:photo_album)
17+
.where(photo_albums: { visibility: 'alumni' })
18+
.or(photo_albums: { visibility: 'everybody' })
19+
.or(where.not(date: nil).where(date: start_date..end_date))
20+
.or(where(date: nil).where(created_at: start_date..end_date))
1821
}
1922
scope :without_photo_tags, lambda {
2023
where.not(id: Photo.joins(:tags).select(:photo_album_id).distinct)

app/models/photo_comment.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ class PhotoComment < ApplicationRecord
1010
joins(:photo_album).where(photo_albums: { visibility: 'everybody' })
1111
}
1212

13-
scope :alumni_visible, lambda {
14-
joins(:photo_album).where(photo_albums: { visibility: 'alumni' })
13+
scope :alumni_visible, lambda { |start_date, end_date|
14+
joins(:photo_album)
15+
.where(photo_albums: { visibility: 'alumni' })
16+
.or(photo_albums: { visibility: 'everybody' })
17+
.or(where.not(photo_albums: { date: nil}).where(photo_albums: { date: start_date..end_date}))
18+
.or(where(photo_albums: { date: nil }).where(photo_albums: { created_at: start_date..end_date}))
1519
}
1620
end

0 commit comments

Comments
 (0)