'Modify block structure according to the behavior of milestones and special exams.'

def transform(self, usage_info, block_structure):

    required_content = self.get_required_content(usage_info, block_structure)
    def user_gated_from_block(block_key):
        '\n                                                Checks    whether    the    user    is    gated    from    accessing    this    block,    first    via    special    exams,\n                                                then    via    a    general    milestones    check.\n                                                '
        if usage_info.has_staff_access:
            return False
        elif self.has_pending_milestones_for_user(block_key, usage_info):
            return True
        elif self.gated_by_required_content(block_key, block_structure, required_content):
            return True
        elif (settings.FEATURES.get('ENABLE_SPECIAL_EXAMS', False) and (self.is_special_exam(block_key, block_structure) and (not self.include_special_exams))):
            return True
        return False
    for block_key in block_structure.topological_traversal():
        if user_gated_from_block(block_key):
            block_structure.remove_block(block_key, False)
        elif self.is_special_exam(block_key, block_structure):
            self.add_special_exam_info(block_key, block_structure, usage_info)
