Skip to content

Commit

Permalink
Merge pull request #309 from zooniverse/posting-age-requirement
Browse files Browse the repository at this point in the history
Include discussion in posting age requirement
  • Loading branch information
zwolf authored Sep 28, 2023
2 parents c1886b0 + 498fbb5 commit 840a9c4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/policies/comment_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def show?
end

def create?
if Array.wrap(record).compact.any? { |a| a.section == 'zooniverse' }
if Array.wrap(record).compact.any? { |c| c.discussion.board.section == 'zooniverse' }
logged_in? && !locked? && writable? && of_posting_age?
else
logged_in? && !locked? && writable?
Expand Down
6 changes: 5 additions & 1 deletion app/policies/discussion_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ def show?
end

def create?
writable?
if Array.wrap(record).compact.any? { |d| d.board.section == 'zooniverse' }
writable? && of_posting_age?
else
writable?
end
end

def update?
Expand Down
8 changes: 8 additions & 0 deletions spec/policies/discussion_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
it_behaves_like 'a policy forbidding', :update, :destroy
end

context 'with a brand new user' do
ENV['POSTING_AGE_REQUIREMENT'] = '24'
let(:user){ create :user, created_at: Time.now }
let(:board){ create :board, section: 'zooniverse', permissions: { read: 'all', write: 'all' } }
it_behaves_like 'a policy permitting', :index, :show
it_behaves_like 'a policy forbidding', :create, :update, :destroy
end

context 'with the owner' do
let(:user){ record.user }
it_behaves_like 'a policy permitting', :index, :show, :create, :update
Expand Down

0 comments on commit 840a9c4

Please sign in to comment.