Skip to content

Commit eeca908

Browse files
committed
Limit photo album visibility
1 parent e280910 commit eeca908

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

app/models/photo_album.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ class PhotoAlbum < ApplicationRecord
99
validates :publicly_visible, inclusion: [true, false]
1010

1111
scope :publicly_visible, (-> { where(publicly_visible: true) })
12+
scope :posted_between_or_publicly_visible, (lambda { |start_date, end_date|
13+
where(publicly_visible: true)
14+
.or(where.not(date: nil).where(date: start_date..end_date))
15+
.or(where(date: nil).where(created_at: start_date..end_date))
16+
})
1217

1318
def owners
1419
if group.present?

app/policies/photo_album_policy.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
class PhotoAlbumPolicy < ApplicationPolicy
22
class Scope < ApplicationPolicy::Scope
3-
def resolve
3+
def resolve # rubocop:disable Metrics/AbcSize
44
if user_can_read?
5-
scope
5+
membership = user.memberships.joins(:group).where(groups: { name: 'Leden' }).first
6+
return scope.publicly_visible if membership.nil?
7+
8+
scope.posted_between_or_publicly_visible(
9+
membership.start_date&.advance(months: -18),
10+
membership.end_date&.advance(months: 6)
11+
)
612
else
713
scope.publicly_visible
814
end

0 commit comments

Comments
 (0)