|
15 | 15 | from hypha.apply.users.tests.factories import ( |
16 | 16 | AdminFactory, |
17 | 17 | ApplicantFactory, |
| 18 | + ContractingFactory, |
| 19 | + FinanceFactory, |
18 | 20 | ReviewerFactory, |
19 | 21 | StaffFactory, |
20 | 22 | UserFactory, |
@@ -310,6 +312,23 @@ def test_limit_reached_blocks_invite(self): |
310 | 312 | result, _ = can_invite_co_applicants(applicant, submission) |
311 | 313 | self.assertFalse(result) |
312 | 314 |
|
| 315 | + def test_complete_project_blocks_invite(self): |
| 316 | + """The submission owner could otherwise invite, so this isolates status""" |
| 317 | + from hypha.apply.projects.models.project import COMPLETE |
| 318 | + from hypha.apply.projects.tests.factories import ProjectFactory |
| 319 | + |
| 320 | + submission = ProjectFactory(status=COMPLETE).submission |
| 321 | + result, _ = can_invite_co_applicants(submission.user, submission) |
| 322 | + self.assertFalse(result) |
| 323 | + |
| 324 | + def test_incomplete_project_does_not_block_invite(self): |
| 325 | + from hypha.apply.projects.models.project import INVOICING_AND_REPORTING |
| 326 | + from hypha.apply.projects.tests.factories import ProjectFactory |
| 327 | + |
| 328 | + submission = ProjectFactory(status=INVOICING_AND_REPORTING).submission |
| 329 | + result, _ = can_invite_co_applicants(submission.user, submission) |
| 330 | + self.assertTrue(result) |
| 331 | + |
313 | 332 |
|
314 | 333 | class TestGetArchiveGroups(TestCase): |
315 | 334 | @override_settings( |
@@ -457,6 +476,15 @@ def test_archived_submission_blocks_update(self): |
457 | 476 | result, _ = can_update_co_applicant(self.inviter, invite) |
458 | 477 | self.assertFalse(result) |
459 | 478 |
|
| 479 | + def test_complete_project_blocks_update(self): |
| 480 | + from hypha.apply.projects.models.project import COMPLETE |
| 481 | + from hypha.apply.projects.tests.factories import ProjectFactory |
| 482 | + |
| 483 | + project = ProjectFactory(status=COMPLETE, user=self.inviter) |
| 484 | + invite = self._make_invite(project.submission, invited_by=self.inviter) |
| 485 | + result, _ = can_update_co_applicant(self.inviter, invite) |
| 486 | + self.assertFalse(result) |
| 487 | + |
460 | 488 |
|
461 | 489 | # --------------------------------------------------------------------------- |
462 | 490 | # user_can_view_post_comment_form — co-applicant VIEW vs EDIT/COMMENT role |
@@ -504,3 +532,47 @@ def test_staff_can_post_comment(self): |
504 | 532 | self.assertTrue( |
505 | 533 | user_can_view_post_comment_form(StaffFactory(), self.submission) |
506 | 534 | ) |
| 535 | + |
| 536 | + |
| 537 | +class TestViewComments(TestCase): |
| 538 | + """`view_comments` reaches a submission's project via `submission.projects`""" |
| 539 | + |
| 540 | + def setUp(self): |
| 541 | + from hypha.apply.projects.models.project import INVOICING_AND_REPORTING |
| 542 | + from hypha.apply.projects.tests.factories import ProjectFactory |
| 543 | + |
| 544 | + self.vendor = ApplicantFactory() |
| 545 | + self.project = ProjectFactory(status=INVOICING_AND_REPORTING, user=self.vendor) |
| 546 | + self.submission = self.project.submission |
| 547 | + |
| 548 | + def check(self, user): |
| 549 | + return has_object_permission("view_comments", user, self.submission) |
| 550 | + |
| 551 | + def test_staff_can(self): |
| 552 | + self.assertTrue(self.check(StaffFactory())) |
| 553 | + |
| 554 | + def test_admin_can(self): |
| 555 | + self.assertTrue(self.check(AdminFactory())) |
| 556 | + |
| 557 | + def test_project_vendor_can(self): |
| 558 | + self.assertTrue(self.check(self.vendor)) |
| 559 | + |
| 560 | + def test_finance_and_contracting_can_via_the_project(self): |
| 561 | + """These roles have no submission access, only project access""" |
| 562 | + for user in [FinanceFactory(), ContractingFactory()]: |
| 563 | + with self.subTest(user.roles): |
| 564 | + self.assertFalse(can_view_submission(user, self.submission)[0]) |
| 565 | + self.assertTrue(self.check(user)) |
| 566 | + |
| 567 | + def test_unrelated_applicant_cannot(self): |
| 568 | + self.assertFalse(self.check(ApplicantFactory())) |
| 569 | + |
| 570 | + def test_submission_without_a_project_falls_back_to_submission_access(self): |
| 571 | + submission = ApplicationSubmissionFactory() |
| 572 | + self.assertFalse(submission.projects.exists()) |
| 573 | + self.assertTrue( |
| 574 | + has_object_permission("view_comments", StaffFactory(), submission) |
| 575 | + ) |
| 576 | + self.assertFalse( |
| 577 | + has_object_permission("view_comments", ContractingFactory(), submission) |
| 578 | + ) |
0 commit comments