Skip to content

Commit cf91cd6

Browse files
committed
Added a check to see the RfC is visible to the user.
1 parent f86349e commit cf91cd6

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

app/policies/comment_policy.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ class CommentPolicy < ApplicationPolicy
44
REPORT_RECEIVER_CONFIGURED = CodeOcean::Config.new(:code_ocean).read.dig(:content_moderation, :report_emails).present?
55

66
def create?
7-
everyone
7+
show?
88
end
99

1010
def show?
11-
everyone
11+
Pundit.policy(@user, @record.request_for_comment).show? && everyone
1212
end
1313

1414
%i[destroy? update? edit?].each do |action|
1515
define_method(action) { admin? || author? || teacher_in_study_group? }
1616
end
1717

1818
def index?
19-
everyone
19+
show?
2020
end
2121

2222
def report?
23-
REPORT_RECEIVER_CONFIGURED && everyone && !author?
23+
REPORT_RECEIVER_CONFIGURED && show? && !author?
2424
end
2525
end

spec/policies/comment_policy_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
expect(described_class).to permit(build_stubbed(user_type), comment)
1414
end
1515
end
16+
17+
it 'does not grant access to users who have no access to the RfC' do
18+
learner = build_stubbed(:learner)
19+
rfc_policy = instance_double(RequestForCommentPolicy, show?: false)
20+
allow(RequestForCommentPolicy).to receive(:new).with(learner, comment.request_for_comment)
21+
.and_return(rfc_policy)
22+
23+
expect(described_class).not_to permit(learner, comment)
24+
end
1625
end
1726

1827
permissions :destroy?, :update?, :edit? do
@@ -61,6 +70,15 @@
6170
it 'does not grants access to the author' do
6271
expect(described_class).not_to permit(comment.user, comment)
6372
end
73+
74+
it 'does not grant access to users who have no access to the RfC' do
75+
learner = build_stubbed(:learner)
76+
rfc_policy = instance_double(RequestForCommentPolicy, show?: false)
77+
allow(RequestForCommentPolicy).to receive(:new).with(learner, comment.request_for_comment)
78+
.and_return(rfc_policy)
79+
80+
expect(described_class).not_to permit(learner, comment)
81+
end
6482
end
6583

6684
context 'when content moderation is disabled' do

0 commit comments

Comments
 (0)