|
16 | 16 | from openedx_events.content_authoring.signals import XBLOCK_DUPLICATED |
17 | 17 | from openedx_events.tests.utils import OpenEdxEventsTestMixin |
18 | 18 | from edx_proctoring.exceptions import ProctoredExamNotFoundException |
| 19 | +from edx_toggles.toggles.testutils import override_waffle_flag |
19 | 20 | from opaque_keys import InvalidKeyError |
20 | 21 | from opaque_keys.edx.asides import AsideUsageKeyV2 |
21 | 22 | from opaque_keys.edx.keys import CourseKey, UsageKey |
|
49 | 50 | from cms.djangoapps.contentstore.tests.utils import CourseTestCase |
50 | 51 | from cms.djangoapps.contentstore.utils import reverse_course_url, reverse_usage_url |
51 | 52 | from cms.djangoapps.contentstore.views import block as item_module |
| 53 | +from cms.djangoapps.contentstore.config.waffle import PREVENT_STAFF_STRUCTURE_DELETION |
| 54 | +from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole, CourseCreatorRole |
52 | 55 | from common.djangoapps.student.tests.factories import StaffFactory, UserFactory |
53 | 56 | from common.djangoapps.xblock_django.models import ( |
54 | 57 | XBlockConfiguration, |
@@ -3473,3 +3476,147 @@ def test_self_paced_item_visibility_state(self, store_type): |
3473 | 3476 | # Check that in self paced course content has live state now |
3474 | 3477 | xblock_info = self._get_xblock_info(chapter.location) |
3475 | 3478 | self._verify_visibility_state(xblock_info, VisibilityState.live) |
| 3479 | + |
| 3480 | + def test_staff_show_delete_button(self): |
| 3481 | + """ |
| 3482 | + Test delete button is *not visible* to user with CourseStaffRole |
| 3483 | + """ |
| 3484 | + # Add user as course staff |
| 3485 | + CourseStaffRole(self.course_key).add_users(self.user) |
| 3486 | + |
| 3487 | + # Get xblock outline |
| 3488 | + xblock_info = create_xblock_info( |
| 3489 | + self.course, |
| 3490 | + include_child_info=True, |
| 3491 | + course_outline=True, |
| 3492 | + include_children_predicate=lambda xblock: not xblock.category == 'vertical', |
| 3493 | + user=self.user |
| 3494 | + ) |
| 3495 | + self.assertTrue(xblock_info['show_delete_button']) |
| 3496 | + |
| 3497 | + def test_staff_show_delete_button_with_waffle(self): |
| 3498 | + """ |
| 3499 | + Test delete button is *not visible* to user with CourseStaffRole and |
| 3500 | + PREVENT_STAFF_STRUCTURE_DELETION waffle set |
| 3501 | + """ |
| 3502 | + # Add user as course staff |
| 3503 | + CourseStaffRole(self.course_key).add_users(self.user) |
| 3504 | + |
| 3505 | + with override_waffle_flag(PREVENT_STAFF_STRUCTURE_DELETION, active=True): |
| 3506 | + # Get xblock outline |
| 3507 | + xblock_info = create_xblock_info( |
| 3508 | + self.course, |
| 3509 | + include_child_info=True, |
| 3510 | + course_outline=True, |
| 3511 | + include_children_predicate=lambda xblock: not xblock.category == 'vertical', |
| 3512 | + user=self.user |
| 3513 | + ) |
| 3514 | + |
| 3515 | + self.assertFalse(xblock_info['show_delete_button']) |
| 3516 | + |
| 3517 | + def test_no_user_show_delete_button(self): |
| 3518 | + """ |
| 3519 | + Test delete button is *visible* when user attribute is not set on |
| 3520 | + xblock. This happens with ajax requests. |
| 3521 | + """ |
| 3522 | + # Get xblock outline |
| 3523 | + xblock_info = create_xblock_info( |
| 3524 | + self.course, |
| 3525 | + include_child_info=True, |
| 3526 | + course_outline=True, |
| 3527 | + include_children_predicate=lambda xblock: not xblock.category == 'vertical', |
| 3528 | + user=None |
| 3529 | + ) |
| 3530 | + self.assertTrue(xblock_info['show_delete_button']) |
| 3531 | + |
| 3532 | + def test_no_user_show_delete_button_with_waffle(self): |
| 3533 | + """ |
| 3534 | + Test delete button is *visible* when user attribute is not set on |
| 3535 | + xblock (this happens with ajax requests) and PREVENT_STAFF_STRUCTURE_DELETION waffle set. |
| 3536 | + """ |
| 3537 | + |
| 3538 | + with override_waffle_flag(PREVENT_STAFF_STRUCTURE_DELETION, active=True): |
| 3539 | + # Get xblock outline |
| 3540 | + xblock_info = create_xblock_info( |
| 3541 | + self.course, |
| 3542 | + include_child_info=True, |
| 3543 | + course_outline=True, |
| 3544 | + include_children_predicate=lambda xblock: not xblock.category == 'vertical', |
| 3545 | + user=None |
| 3546 | + ) |
| 3547 | + |
| 3548 | + self.assertFalse(xblock_info['show_delete_button']) |
| 3549 | + |
| 3550 | + def test_instructor_show_delete_button(self): |
| 3551 | + """ |
| 3552 | + Test delete button is *visible* to user with CourseInstructorRole only |
| 3553 | + """ |
| 3554 | + # Add user as course instructor |
| 3555 | + CourseInstructorRole(self.course_key).add_users(self.user) |
| 3556 | + |
| 3557 | + # Get xblock outline |
| 3558 | + xblock_info = create_xblock_info( |
| 3559 | + self.course, |
| 3560 | + include_child_info=True, |
| 3561 | + course_outline=True, |
| 3562 | + include_children_predicate=lambda xblock: not xblock.category == 'vertical', |
| 3563 | + user=self.user |
| 3564 | + ) |
| 3565 | + self.assertTrue(xblock_info['show_delete_button']) |
| 3566 | + |
| 3567 | + def test_instructor_show_delete_button_with_waffle(self): |
| 3568 | + """ |
| 3569 | + Test delete button is *visible* to user with CourseInstructorRole only |
| 3570 | + and PREVENT_STAFF_STRUCTURE_DELETION waffle set |
| 3571 | + """ |
| 3572 | + # Add user as course instructor |
| 3573 | + CourseInstructorRole(self.course_key).add_users(self.user) |
| 3574 | + |
| 3575 | + with override_waffle_flag(PREVENT_STAFF_STRUCTURE_DELETION, active=True): |
| 3576 | + # Get xblock outline |
| 3577 | + xblock_info = create_xblock_info( |
| 3578 | + self.course, |
| 3579 | + include_child_info=True, |
| 3580 | + course_outline=True, |
| 3581 | + include_children_predicate=lambda xblock: not xblock.category == 'vertical', |
| 3582 | + user=self.user |
| 3583 | + ) |
| 3584 | + |
| 3585 | + self.assertTrue(xblock_info['show_delete_button']) |
| 3586 | + |
| 3587 | + def test_creator_show_delete_button(self): |
| 3588 | + """ |
| 3589 | + Test delete button is *visible* to user with CourseInstructorRole only |
| 3590 | + """ |
| 3591 | + # Add user as course creator |
| 3592 | + CourseCreatorRole(self.course_key).add_users(self.user) |
| 3593 | + |
| 3594 | + # Get xblock outline |
| 3595 | + xblock_info = create_xblock_info( |
| 3596 | + self.course, |
| 3597 | + include_child_info=True, |
| 3598 | + course_outline=True, |
| 3599 | + include_children_predicate=lambda xblock: not xblock.category == 'vertical', |
| 3600 | + user=self.user |
| 3601 | + ) |
| 3602 | + self.assertTrue(xblock_info['show_delete_button']) |
| 3603 | + |
| 3604 | + def test_creator_show_delete_button_with_waffle(self): |
| 3605 | + """ |
| 3606 | + Test delete button is *visible* to user with CourseInstructorRole only |
| 3607 | + and PREVENT_STAFF_STRUCTURE_DELETION waffle set |
| 3608 | + """ |
| 3609 | + # Add user as course creator |
| 3610 | + CourseCreatorRole(self.course_key).add_users(self.user) |
| 3611 | + |
| 3612 | + with override_waffle_flag(PREVENT_STAFF_STRUCTURE_DELETION, active=True): |
| 3613 | + # Get xblock outline |
| 3614 | + xblock_info = create_xblock_info( |
| 3615 | + self.course, |
| 3616 | + include_child_info=True, |
| 3617 | + course_outline=True, |
| 3618 | + include_children_predicate=lambda xblock: not xblock.category == 'vertical', |
| 3619 | + user=self.user |
| 3620 | + ) |
| 3621 | + |
| 3622 | + self.assertFalse(xblock_info['show_delete_button']) |
0 commit comments