diff --git a/app/policies/comment_policy.rb b/app/policies/comment_policy.rb index d9219624..acd9ff2d 100644 --- a/app/policies/comment_policy.rb +++ b/app/policies/comment_policy.rb @@ -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? diff --git a/app/policies/discussion_policy.rb b/app/policies/discussion_policy.rb index 91f16424..47d1c1c5 100644 --- a/app/policies/discussion_policy.rb +++ b/app/policies/discussion_policy.rb @@ -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? diff --git a/spec/policies/discussion_policy_spec.rb b/spec/policies/discussion_policy_spec.rb index c64532c6..9c200d4e 100644 --- a/spec/policies/discussion_policy_spec.rb +++ b/spec/policies/discussion_policy_spec.rb @@ -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