예제 #1
0
def _render_course_outline_to_html(handler, course):
    """Renders course outline to HTML."""

    units = []
    for unit in course.get_units():
        if course.get_parent_unit(unit.unit_id):
            continue  # Will be rendered as part of containing element.
        if unit.type == verify.UNIT_TYPE_ASSESSMENT:
            units.append(_render_assessment_outline(handler, unit))
        elif unit.type == verify.UNIT_TYPE_LINK:
            units.append(_render_link_outline(handler, unit))
        elif unit.type == verify.UNIT_TYPE_UNIT:
            units.append(_render_unit_outline(handler, course, unit))
        elif unit.type == verify.UNIT_TYPE_CUSTOM:
            units.append(_render_custom_unit_outline(handler, course, unit))
        else:
            raise Exception('Unknown unit type: %s.' % unit.type)

    is_course_availability_editable = permissions.can_edit_property(
        handler.app_context, constants.SCOPE_COURSE_SETTINGS,
        'course/course:now_available')
    any_course_setting_viewable = permissions.can_view(
        handler.app_context, constants.SCOPE_COURSE_SETTINGS)
    template_values = {
        'course': {
            'title': course.title,
            'can_add_or_remove': roles.Roles.is_course_admin(
                handler.app_context),
            'can_reorder': roles.Roles.is_user_allowed(
                handler.app_context, custom_module,
                constants.COURSE_OUTLINE_REORDER_PERMISSION),
            'settings_viewable': any_course_setting_viewable,
            'availability': {
                'url': handler.get_action_url('course_availability'),
                'xsrf_token': handler.create_xsrf_token('course_availability'),
                'param': not handler.app_context.now_available,
                'now_available': handler.app_context.now_available,
                'is_editable': is_course_availability_editable,
            }
        },
        'units': units,
        'add_lesson_xsrf_token': handler.create_xsrf_token('add_lesson'),
        'unit_lesson_title_xsrf_token': handler.create_xsrf_token(
            unit_lesson_editor.UnitLessonTitleRESTHandler.XSRF_TOKEN),
        'unit_title_template': resources_display.get_unit_title_template(
            course.app_context),
        'extra_info_title': ', '.join(COURSE_OUTLINE_EXTRA_INFO_TITLES)
    }
    for item_type in unit_lesson_editor.UnitLessonEditor.CAN_EDIT_DRAFT:
        action_name = '%s_%s' % (
            unit_lesson_editor.UnitLessonEditor.ACTION_POST_SET_DRAFT_STATUS,
            item_type)
        token_name = 'status_xsrf_token_%s' % item_type
        template_values[token_name] = handler.create_xsrf_token(action_name)

    return jinja2.Markup(
        handler.get_template(
            'course_outline.html', [os.path.dirname(__file__)]
            ).render(template_values))
예제 #2
0
def _render_course_outline_to_html(handler, course):
    """Renders course outline to HTML."""

    units = []
    for unit in course.get_units():
        if course.get_parent_unit(unit.unit_id):
            continue  # Will be rendered as part of containing element.
        if unit.type == verify.UNIT_TYPE_ASSESSMENT:
            units.append(_render_assessment_outline(handler, unit))
        elif unit.type == verify.UNIT_TYPE_LINK:
            units.append(_render_link_outline(handler, unit))
        elif unit.type == verify.UNIT_TYPE_UNIT:
            units.append(_render_unit_outline(handler, course, unit))
        elif unit.type == verify.UNIT_TYPE_CUSTOM:
            units.append(_render_custom_unit_outline(handler, course, unit))
        else:
            raise Exception('Unknown unit type: %s.' % unit.type)

    is_course_availability_editable = permissions.can_edit_property(
        handler.app_context, constants.SCOPE_COURSE_SETTINGS,
        'course/course:now_available')
    any_course_setting_viewable = permissions.can_view(
        handler.app_context, constants.SCOPE_COURSE_SETTINGS)
    template_values = {
        'course': {
            'title':
            course.title,
            'can_add_or_remove':
            roles.Roles.is_course_admin(handler.app_context),
            'can_reorder':
            roles.Roles.is_user_allowed(
                handler.app_context, custom_module,
                constants.COURSE_OUTLINE_REORDER_PERMISSION),
            'settings_viewable':
            any_course_setting_viewable,
        },
        'units':
        units,
        'add_lesson_xsrf_token':
        handler.create_xsrf_token('add_lesson'),
        'unit_lesson_title_xsrf_token':
        handler.create_xsrf_token(
            unit_lesson_editor.UnitLessonTitleRESTHandler.XSRF_TOKEN),
        'unit_title_template':
        resources_display.get_unit_title_template(course.app_context),
        'extra_info_title':
        ', '.join(COURSE_OUTLINE_EXTRA_INFO_TITLES)
    }

    return jinja2.Markup(
        handler.get_template(
            'course_outline.html',
            [os.path.dirname(__file__)]).render(template_values))
 def test_admin_has_permissions_with_no_configuration_needed(self):
     actions.login(self.ADMIN_EMAIL, is_admin=True)
     self.assertTrue(permissions.can_view(
         self.app_context, constants.SCOPE_COURSE_SETTINGS))
     self.assertTrue(permissions.can_edit(
         self.app_context, constants.SCOPE_COURSE_SETTINGS))
     self.assertTrue(permissions.can_view_property(
         self.app_context, constants.SCOPE_COURSE_SETTINGS,
         'absolutely/anything'))
     self.assertTrue(permissions.can_edit_property(
         self.app_context, constants.SCOPE_COURSE_SETTINGS,
         'absolutely/anything'))
 def test_non_admin_has_no_permissions_with_no_configuration_needed(self):
     actions.login(self.IN_ROLE_EMAIL)
     self.assertFalse(
         permissions.can_view(self.app_context,
                              constants.SCOPE_COURSE_SETTINGS))
     self.assertFalse(
         permissions.can_edit(self.app_context,
                              constants.SCOPE_COURSE_SETTINGS))
     self.assertFalse(
         permissions.can_view_property(self.app_context,
                                       constants.SCOPE_COURSE_SETTINGS,
                                       'absolutely/anything'))
     self.assertFalse(
         permissions.can_edit_property(self.app_context,
                                       constants.SCOPE_COURSE_SETTINGS,
                                       'absolutely/anything'))
예제 #5
0
def _render_link_outline(handler, unit):
    course_writable = handler.app_context.is_editable_fs()
    can_edit_status = course_writable and permissions.can_edit_property(
        handler.app_context, constants.SCOPE_LINK, 'is_draft')
    can_view_props = course_writable and permissions.can_edit(
        handler.app_context, constants.SCOPE_LINK)

    return {
        'title': unit.title,
        'view_url': unit.href or '',
        'id': unit.unit_id,
        'component_type': 'link',
        'can_edit_status': can_edit_status,
        'can_view_props': can_view_props,
        'now_available': unit.now_available,
        'href': handler.canonicalize_url(
            '/dashboard?%s') % urllib.urlencode({
                'action': 'edit_link',
                'key': unit.unit_id}),
    }
예제 #6
0
def _render_unit_outline(handler, course, unit):
    course_writable = handler.app_context.is_editable_fs()
    can_edit_status = course_writable and permissions.can_edit_property(
        handler.app_context, constants.SCOPE_UNIT, 'is_draft')
    can_view_props = course_writable and permissions.can_edit(
        handler.app_context, constants.SCOPE_UNIT)

    unit_data = {
        'title': unit.title,
        'component_type': 'unit',
        'view_url': 'unit?unit=%s' % unit.unit_id,
        'id': unit.unit_id,
        'can_edit_status': can_edit_status,
        'can_view_props': can_view_props,
        'now_available': unit.now_available,
        'href': handler.canonicalize_url(
            '/dashboard?%s') % urllib.urlencode({
                'action': 'edit_unit',
                'key': unit.unit_id}),
    }

    if unit.pre_assessment:
        assessment = course.find_unit_by_id(unit.pre_assessment)
        if assessment:
            assessment_outline = _render_assessment_outline(handler, assessment)
            assessment_outline['component_type'] = 'pre-assessment'
            assessment_outline['not_reorderable'] = True
            unit_data['pre_assessment'] = assessment_outline

    # Here, just check whether user is course admin to see if lesson contents
    # are editable.  Eventually, can add specific sub-permissions to lessons,
    # if we like.
    lessons_editable = (handler.app_context.is_editable_fs() and
                        roles.Roles.is_course_admin(handler.app_context))
    lessons = []
    for lesson in course.get_lessons(unit.unit_id):
        extras = []
        for annotator in COURSE_OUTLINE_EXTRA_INFO_ANNOTATORS:
            extra_info = annotator(course, lesson)
            if extra_info:
                extras.append(extra_info)

        lessons.append({
            'title': lesson.title,
            'component_type': 'lesson',
            'view_url': 'unit?unit=%s&lesson=%s' % (
                unit.unit_id, lesson.lesson_id),
            'id': lesson.lesson_id,
            'href': handler.get_action_url('edit_lesson', key=lesson.lesson_id),
            'can_edit_status': lessons_editable,
            'can_view_props': lessons_editable,
            'auto_index': lesson.auto_index,
            'now_available': lesson.now_available,
            'extras': extras})

    unit_data['lessons'] = lessons

    if unit.post_assessment:
        assessment = course.find_unit_by_id(unit.post_assessment)
        if assessment:
            assessment_outline = _render_assessment_outline(handler, assessment)
            assessment_outline['component_type'] = 'post-assessment'
            assessment_outline['not_reorderable'] = True
            unit_data['post_assessment'] = assessment_outline

    return unit_data