Пример #1
0
    def can_load():
        """
        NOTE: This does not check that the student is enrolled in the course
        that contains this module.  We may or may not want to allow non-enrolled
        students to see modules.  If not, views should check the course, so we
        don't have to hit the enrollments table on every module load.
        """
        # If the user (or the role the user is currently masquerading as) does not have
        # access to this content, then deny access. The problem with calling _has_staff_access_to_descriptor
        # before this method is that _has_staff_access_to_descriptor short-circuits and returns True
        # for staff users in preview mode.
        group_access_response = _has_group_access(descriptor, user, course_key)
        if not group_access_response:
            return group_access_response

        # If the user has staff access, they can load the module and checks below are not needed.
        staff_access_response = _has_staff_access_to_descriptor(user, descriptor, course_key)
        if staff_access_response:
            return staff_access_response

        return (
            _visible_to_nonstaff_users(descriptor, display_error_to_user=False) and
            (
                _has_detached_class_tag(descriptor) or
                check_start_date(
                    user,
                    descriptor.days_early_for_beta,
                    descriptor.start,
                    course_key,
                    display_error_to_user=False
                )
            )
        )
Пример #2
0
    def transform_block_filters(self, usage_info, block_structure):
        # Users with staff access bypass the Start Date check.
        if usage_info.has_staff_access:
            return [block_structure.create_universal_filter()]

        removal_condition = lambda block_key: not check_start_date(
            usage_info.user,
            block_structure.get_xblock_field(block_key, 'days_early_for_beta'),
            self._get_merged_start_date(block_structure, block_key),
            usage_info.course_key,
        )
        return [block_structure.create_removal_filter(removal_condition)]
Пример #3
0
    def transform_block_filters(self, usage_info, block_structure):
        # Users with staff access bypass the Start Date check.
        if usage_info.has_staff_access:
            return [block_structure.create_universal_filter()]

        removal_condition = lambda block_key: not check_start_date(
            usage_info.user,
            block_structure.get_xblock_field(block_key, 'days_early_for_beta'),
            self._get_merged_start_date(block_structure, block_key),
            usage_info.course_key,
        )
        return [block_structure.create_removal_filter(removal_condition)]
Пример #4
0
    def transform(self, usage_info, block_structure):
        """
        Mutates block_structure based on the given usage_info.
        """
        # Users with staff access bypass the Start Date check.
        if usage_info.has_staff_access:
            return

        block_structure.remove_block_if(lambda block_key: not check_start_date(
            usage_info.user,
            block_structure.get_xblock_field(block_key, 'days_early_for_beta'),
            self.get_merged_start_date(block_structure, block_key),
            usage_info.course_key,
        ))
Пример #5
0
    def transform(self, usage_info, block_structure):
        """
        Mutates block_structure based on the given usage_info.
        """
        # Users with staff access bypass the Start Date check.
        if usage_info.has_staff_access:
            return

        block_structure.remove_block_if(
            lambda block_key: not check_start_date(
                usage_info.user,
                block_structure.get_xblock_field(block_key, 'days_early_for_beta'),
                self.get_merged_start_date(block_structure, block_key),
                usage_info.course_key,
            )
        )
Пример #6
0
    def transform_block_filters(self, usage_info, block_structure):
        # Users with staff access bypass the Start Date check.
        if usage_info.has_staff_access or usage_info.allow_start_dates_in_future:
            return [block_structure.create_universal_filter()]

        now = datetime.now(UTC)

        removal_condition = lambda block_key: not check_start_date(
            usage_info.user,
            block_structure.get_xblock_field(block_key, 'days_early_for_beta'),
            self._get_merged_start_date(block_structure, block_key),
            usage_info.course_key,
            now=now,
        )

        if usage_info.include_has_scheduled_content:
            self._check_has_scheduled_content(block_structure, removal_condition)

        return [block_structure.create_removal_filter(removal_condition)]