File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed
Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff 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
2525end
Original file line number Diff line number Diff line change 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
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
You can’t perform that action at this time.
0 commit comments