|
46 | 46 | end |
47 | 47 | end |
48 | 48 | end |
| 49 | + |
| 50 | + permissions(:report?) do |
| 51 | + before do |
| 52 | + codeocean_config = instance_double(CodeOcean::Config) |
| 53 | + allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config) |
| 54 | + allow(codeocean_config).to receive(:read).and_return({ |
| 55 | + content_moderation: {report_emails: ['[email protected]']}, |
| 56 | + }) |
| 57 | + end |
| 58 | + |
| 59 | + it 'allows anyone to report RfCs' do |
| 60 | + %i[admin external_user teacher].each do |factory_name| |
| 61 | + expect(policy).to permit(create(factory_name), create(:rfc)) |
| 62 | + end |
| 63 | + end |
| 64 | + end |
49 | 65 | end |
50 | 66 |
|
51 | 67 | context 'when the RfC visibility is considered' do |
52 | | - shared_examples 'grants access to everyone' do |
| 68 | + shared_examples 'grants access to everyone' do |params| |
53 | 69 | it 'grants access to everyone' do |
54 | 70 | %i[external_user teacher admin].each do |factory_name| |
55 | 71 | expect(policy).to permit(create(factory_name, consumer: viewer_consumer, study_groups: viewer_study_groups), rfc) |
56 | 72 | end |
57 | 73 | end |
58 | 74 |
|
59 | | - it 'grants access to authors' do |
60 | | - expect(policy).to permit(rfc.author, rfc) |
| 75 | + if params && params[:block_author] |
| 76 | + it 'dose not grant access to authors' do |
| 77 | + expect(policy).not_to permit(rfc.author, rfc) |
| 78 | + end |
| 79 | + else |
| 80 | + it 'grants access to authors' do |
| 81 | + expect(policy).to permit(rfc.author, rfc) |
| 82 | + end |
61 | 83 | end |
62 | 84 |
|
63 | 85 | it 'grant access to other authors of the programming group' do |
|
87 | 109 | end |
88 | 110 | end |
89 | 111 |
|
| 112 | + shared_examples 'grants access to admins only' do |
| 113 | + it 'grants access to admins' do |
| 114 | + expect(policy).to permit(create(:admin, consumer: viewer_consumer, study_groups: viewer_study_groups), rfc) |
| 115 | + end |
| 116 | + |
| 117 | + it 'dose not grant access to authors' do |
| 118 | + expect(policy).not_to permit(rfc.author, rfc) |
| 119 | + end |
| 120 | + |
| 121 | + it 'grant access to other authors of the programming group' do |
| 122 | + rfc.submission.update(contributor: programming_group) |
| 123 | + expect(policy).to permit(viewer_other_group_member, rfc) |
| 124 | + end |
| 125 | + |
| 126 | + it 'does not grant access to all other users' do |
| 127 | + %i[external_user teacher].each do |factory_name| |
| 128 | + expect(policy).not_to permit(create(factory_name, consumer: viewer_consumer, study_groups: viewer_study_groups), rfc) |
| 129 | + end |
| 130 | + end |
| 131 | + end |
| 132 | + |
90 | 133 | let(:rfc_author) { create(:learner, consumer: author_consumer, study_groups: author_study_groups) } |
91 | 134 | let(:author_study_groups) { create_list(:study_group, 1, consumer: author_consumer) } |
92 | 135 | let(:rfc) { create(:rfc, user: rfc_author) } |
|
111 | 154 | it_behaves_like 'grants access to admins and authors only' |
112 | 155 | end |
113 | 156 | end |
| 157 | + |
| 158 | + permissions(:report?) do |
| 159 | + before do |
| 160 | + codeocean_config = instance_double(CodeOcean::Config) |
| 161 | + allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config) |
| 162 | + allow(codeocean_config).to receive(:read).and_return({ |
| 163 | + content_moderation: {report_emails: ['[email protected]']}, |
| 164 | + }) |
| 165 | + end |
| 166 | + |
| 167 | + it_behaves_like 'grants access to everyone', {block_author: true} |
| 168 | + end |
114 | 169 | end |
115 | 170 |
|
116 | 171 | context "when the viewer's rfc_visibility is set to consumer" do |
|
122 | 177 | it_behaves_like 'grants access to admins and authors only' |
123 | 178 | end |
124 | 179 | end |
| 180 | + |
| 181 | + permissions(:report?) do |
| 182 | + before do |
| 183 | + codeocean_config = instance_double(CodeOcean::Config) |
| 184 | + allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config) |
| 185 | + allow(codeocean_config).to receive(:read).and_return({ |
| 186 | + content_moderation: {report_emails: ['[email protected]']}, |
| 187 | + }) |
| 188 | + end |
| 189 | + |
| 190 | + it_behaves_like 'grants access to admins only' |
| 191 | + end |
125 | 192 | end |
126 | 193 |
|
127 | 194 | context "when the viewer's rfc_visibility is set to study_group" do |
|
133 | 200 | it_behaves_like 'grants access to admins and authors only' |
134 | 201 | end |
135 | 202 | end |
| 203 | + |
| 204 | + permissions(:report?) do |
| 205 | + before do |
| 206 | + codeocean_config = instance_double(CodeOcean::Config) |
| 207 | + allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config) |
| 208 | + allow(codeocean_config).to receive(:read).and_return({ |
| 209 | + content_moderation: {report_emails: ['[email protected]']}, |
| 210 | + }) |
| 211 | + end |
| 212 | + |
| 213 | + it_behaves_like 'grants access to admins only' |
| 214 | + end |
136 | 215 | end |
137 | 216 | end |
138 | 217 |
|
|
151 | 230 | it_behaves_like 'grants access to admins and authors only' |
152 | 231 | end |
153 | 232 | end |
| 233 | + |
| 234 | + permissions(:report?) do |
| 235 | + before do |
| 236 | + codeocean_config = instance_double(CodeOcean::Config) |
| 237 | + allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config) |
| 238 | + allow(codeocean_config).to receive(:read).and_return({ |
| 239 | + content_moderation: {report_emails: ['[email protected]']}, |
| 240 | + }) |
| 241 | + end |
| 242 | + |
| 243 | + it_behaves_like 'grants access to everyone', {block_author: true} |
| 244 | + end |
154 | 245 | end |
155 | 246 |
|
156 | 247 | context 'when the viewer is from the same study group' do |
|
165 | 256 | it_behaves_like 'grants access to admins and authors only' |
166 | 257 | end |
167 | 258 | end |
| 259 | + |
| 260 | + permissions(:report?) do |
| 261 | + before do |
| 262 | + codeocean_config = instance_double(CodeOcean::Config) |
| 263 | + allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config) |
| 264 | + allow(codeocean_config).to receive(:read).and_return({ |
| 265 | + content_moderation: {report_emails: ['[email protected]']}, |
| 266 | + }) |
| 267 | + end |
| 268 | + |
| 269 | + it_behaves_like 'grants access to everyone', {block_author: true} |
| 270 | + end |
168 | 271 | end |
169 | 272 | end |
170 | 273 | end |
|
182 | 285 | it_behaves_like 'grants access to admins and authors only' |
183 | 286 | end |
184 | 287 | end |
| 288 | + |
| 289 | + permissions(:report?) do |
| 290 | + before do |
| 291 | + codeocean_config = instance_double(CodeOcean::Config) |
| 292 | + allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config) |
| 293 | + allow(codeocean_config).to receive(:read).and_return({ |
| 294 | + content_moderation: {report_emails: ['[email protected]']}, |
| 295 | + }) |
| 296 | + end |
| 297 | + |
| 298 | + it_behaves_like 'grants access to admins only' |
| 299 | + end |
185 | 300 | end |
186 | 301 |
|
187 | 302 | context "when the viewer's rfc_visibility is set to consumer" do |
|
193 | 308 | it_behaves_like 'grants access to admins and authors only' |
194 | 309 | end |
195 | 310 | end |
| 311 | + |
| 312 | + permissions(:report?) do |
| 313 | + before do |
| 314 | + codeocean_config = instance_double(CodeOcean::Config) |
| 315 | + allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config) |
| 316 | + allow(codeocean_config).to receive(:read).and_return({ |
| 317 | + content_moderation: {report_emails: ['[email protected]']}, |
| 318 | + }) |
| 319 | + end |
| 320 | + |
| 321 | + it_behaves_like 'grants access to admins only' |
| 322 | + end |
196 | 323 | end |
197 | 324 |
|
198 | 325 | context "when the viewer's rfc_visibility is set to study_group" do |
|
204 | 331 | it_behaves_like 'grants access to admins and authors only' |
205 | 332 | end |
206 | 333 | end |
| 334 | + |
| 335 | + permissions(:report?) do |
| 336 | + before do |
| 337 | + codeocean_config = instance_double(CodeOcean::Config) |
| 338 | + allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config) |
| 339 | + allow(codeocean_config).to receive(:read).and_return({ |
| 340 | + content_moderation: {report_emails: ['[email protected]']}, |
| 341 | + }) |
| 342 | + end |
| 343 | + |
| 344 | + it_behaves_like 'grants access to admins only' |
| 345 | + end |
207 | 346 | end |
208 | 347 | end |
209 | 348 |
|
|
222 | 361 | it_behaves_like 'grants access to admins and authors only' |
223 | 362 | end |
224 | 363 | end |
| 364 | + |
| 365 | + permissions(:report?) do |
| 366 | + before do |
| 367 | + codeocean_config = instance_double(CodeOcean::Config) |
| 368 | + allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config) |
| 369 | + allow(codeocean_config).to receive(:read).and_return({ |
| 370 | + content_moderation: {report_emails: ['[email protected]']}, |
| 371 | + }) |
| 372 | + end |
| 373 | + |
| 374 | + it_behaves_like 'grants access to everyone', {block_author: true} |
| 375 | + end |
225 | 376 | end |
226 | 377 |
|
227 | 378 | context 'when the viewer is from the same study group' do |
|
236 | 387 | it_behaves_like 'grants access to admins and authors only' |
237 | 388 | end |
238 | 389 | end |
| 390 | + |
| 391 | + permissions(:report?) do |
| 392 | + before do |
| 393 | + codeocean_config = instance_double(CodeOcean::Config) |
| 394 | + allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config) |
| 395 | + allow(codeocean_config).to receive(:read).and_return({ |
| 396 | + content_moderation: {report_emails: ['[email protected]']}, |
| 397 | + }) |
| 398 | + end |
| 399 | + |
| 400 | + it_behaves_like 'grants access to everyone', {block_author: true} |
| 401 | + end |
239 | 402 | end |
240 | 403 | end |
241 | 404 | end |
|
253 | 416 | it_behaves_like 'grants access to admins and authors only' |
254 | 417 | end |
255 | 418 | end |
| 419 | + |
| 420 | + permissions(:report?) do |
| 421 | + before do |
| 422 | + codeocean_config = instance_double(CodeOcean::Config) |
| 423 | + allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config) |
| 424 | + allow(codeocean_config).to receive(:read).and_return({ |
| 425 | + content_moderation: {report_emails: ['[email protected]']}, |
| 426 | + }) |
| 427 | + end |
| 428 | + |
| 429 | + it_behaves_like 'grants access to admins only' |
| 430 | + end |
256 | 431 | end |
257 | 432 |
|
258 | 433 | context "when the viewer's rfc_visibility is set to consumer" do |
|
264 | 439 | it_behaves_like 'grants access to admins and authors only' |
265 | 440 | end |
266 | 441 | end |
| 442 | + |
| 443 | + permissions(:report?) do |
| 444 | + before do |
| 445 | + codeocean_config = instance_double(CodeOcean::Config) |
| 446 | + allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config) |
| 447 | + allow(codeocean_config).to receive(:read).and_return({ |
| 448 | + content_moderation: {report_emails: ['[email protected]']}, |
| 449 | + }) |
| 450 | + end |
| 451 | + |
| 452 | + it_behaves_like 'grants access to admins only' |
| 453 | + end |
267 | 454 | end |
268 | 455 |
|
269 | 456 | context "when the viewer's rfc_visibility is set to study_group" do |
|
275 | 462 | it_behaves_like 'grants access to admins and authors only' |
276 | 463 | end |
277 | 464 | end |
| 465 | + |
| 466 | + permissions(:report?) do |
| 467 | + before do |
| 468 | + codeocean_config = instance_double(CodeOcean::Config) |
| 469 | + allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config) |
| 470 | + allow(codeocean_config).to receive(:read).and_return({ |
| 471 | + content_moderation: {report_emails: ['[email protected]']}, |
| 472 | + }) |
| 473 | + end |
| 474 | + |
| 475 | + it_behaves_like 'grants access to admins only' |
| 476 | + end |
278 | 477 | end |
279 | 478 | end |
280 | 479 |
|
|
289 | 488 | it_behaves_like 'grants access to admins and authors only' |
290 | 489 | end |
291 | 490 | end |
| 491 | + |
| 492 | + permissions(:report?) do |
| 493 | + before do |
| 494 | + codeocean_config = instance_double(CodeOcean::Config) |
| 495 | + allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config) |
| 496 | + allow(codeocean_config).to receive(:read).and_return({ |
| 497 | + content_moderation: {report_emails: ['[email protected]']}, |
| 498 | + }) |
| 499 | + end |
| 500 | + |
| 501 | + it_behaves_like 'grants access to admins only' |
| 502 | + end |
292 | 503 | end |
293 | 504 |
|
294 | 505 | context 'when the viewer is from the same study group' do |
|
303 | 514 | it_behaves_like 'grants access to admins and authors only' |
304 | 515 | end |
305 | 516 | end |
306 | | - end |
307 | | - end |
308 | | - end |
309 | | - end |
310 | 517 |
|
311 | | - permissions(:report?) do |
312 | | - let(:user) { build_stubbed(:external_user) } |
| 518 | + permissions(:report?) do |
| 519 | + before do |
| 520 | + codeocean_config = instance_double(CodeOcean::Config) |
| 521 | + allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config) |
| 522 | + allow(codeocean_config).to receive(:read).and_return({ |
| 523 | + content_moderation: {report_emails: ['[email protected]']}, |
| 524 | + }) |
| 525 | + end |
313 | 526 |
|
314 | | - it 'allows anyone to report RfCs' do |
315 | | - %i[admin external_user teacher].each do |factory_name| |
316 | | - expect(policy).to permit(create(factory_name), create(:rfc)) |
| 527 | + it_behaves_like 'grants access to everyone', {block_author: true} |
| 528 | + end |
| 529 | + end |
317 | 530 | end |
318 | 531 | end |
319 | 532 |
|
320 | | - it 'dose not allow reports when the RfC is not accessable' do |
321 | | - allow_any_instance_of(policy).to receive(:show?).and_return(false) |
322 | | - |
323 | | - %i[admin external_user teacher].each do |factory_name| |
324 | | - expect(policy).not_to permit(create(factory_name), RequestForComment.new) |
| 533 | + context 'when no report email is configured' do |
| 534 | + permissions(:report?) do |
| 535 | + it 'dose not allow reports from anyone' do |
| 536 | + %i[admin external_user teacher].each do |factory_name| |
| 537 | + expect(policy).not_to permit(create(factory_name), RequestForComment.new) |
| 538 | + end |
| 539 | + end |
325 | 540 | end |
326 | 541 | end |
327 | | - |
328 | | - it 'dose not allow reports when no report email is configured' do |
329 | | - codeocean_config = instance_double(CodeOcean::Config) |
330 | | - allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config) |
331 | | - allow(codeocean_config).to receive(:read).and_return({}) |
332 | | - |
333 | | - expect(policy).not_to permit(user, RequestForComment.new) |
334 | | - end |
335 | | - |
336 | | - it 'dose not allow reports of your own content' do |
337 | | - expect(policy).not_to permit(user, RequestForComment.new(user: user)) |
338 | | - end |
339 | 542 | end |
340 | 543 | end |
0 commit comments