Ejemplo n.º 1
0
def config(request):
    launch_url = request.build_absolute_uri(reverse('lti'))

    lti_tool_config = ToolConfig(
        title='OpenSubmit',
        description='Assignment Management and Submission System',
        launch_url=launch_url,
        secure_launch_url=launch_url)

    return HttpResponse(lti_tool_config.to_xml(), content_type='text/xml')
def tool_config(request):
    url = "https://{}{}".format(request.get_host(), reverse('lti_launch'))
    url = _url(url)

    title = 'LTI Emailer'
    lti_tool_config = ToolConfig(
        title=title,
        launch_url=url,
        secure_launch_url=url,
        description=
        "This LTI tool allows email functionality for this course site.")

    # this is how to tell Canvas that this tool provides a course navigation link:
    course_nav_params = {
        'enabled': 'true',
        'text': title,
        'default': 'disabled',
        'visibility': 'admins',
    }
    custom_fields = {'canvas_membership_roles': '$Canvas.membership.roles'}
    lti_tool_config.set_ext_param('canvas.instructure.com', 'custom_fields',
                                  custom_fields)
    lti_tool_config.set_ext_param('canvas.instructure.com',
                                  'course_navigation', course_nav_params)
    lti_tool_config.set_ext_param('canvas.instructure.com', 'privacy_level',
                                  'public')

    return HttpResponse(lti_tool_config.to_xml(), content_type='text/xml')
Ejemplo n.º 3
0
    def test_optional_config_parameters(self):
        '''
        Should contain cartridge_icon, and blti:icon.
        '''
        config = ToolConfig(title="Test config",
                            launch_url="http://www.example.com",
                            secure_launch_url="http://www.example.com")
        config.icon = 'http://wil.to/_/beardslap.gif'
        config.cartridge_icon = 'BLTI001_Icon'

        correct = normalize_xml(CC_LTI_OPTIONAL_PARAMS_XML)
        got = normalize_xml(config.to_xml())
        self.assertEqual(got, correct)
Ejemplo n.º 4
0
def tool_config(request):
    url = request.build_absolute_uri("/")[:-1] + reverse(
        settings.LTI_SETUP["LAUNCH_URL"])
    lti_tool_config = ToolConfig(
        title=settings.LTI_SETUP["TOOL_TITLE"],
        launch_url=url,
        secure_launch_url=url,
        extensions=settings.LTI_SETUP.get("EXTENSION_PARAMETERS", ""),
        description=settings.LTI_SETUP["TOOL_DESCRIPTION"],
    )
    lti_tool_config.initialize_models = settings.LTI_SETUP["INITIALIZE_MODELS"]

    return HttpResponse(lti_tool_config.to_xml(), content_type="text/xml")
Ejemplo n.º 5
0
    def test_optional_config_parameters(self):
        '''
        Should contain cartridge_icon, and blti:icon.
        '''
        config = ToolConfig(title = "Test config",
                launch_url = "http://www.example.com",
                secure_launch_url = "http://www.example.com")
        config.icon = 'http://wil.to/_/beardslap.gif'
        config.secure_icon = 'https://www.example.com/secure_icon.png'
        config.cartridge_icon = 'BLTI001_Icon'

        correct = normalize_xml(CC_LTI_OPTIONAL_PARAMS_XML)
        got = normalize_xml(config.to_xml())
        self.assertEqual(got, correct)
Ejemplo n.º 6
0
def tool_config(request):
    app_title = 'Bridge'
    app_description = 'Bridge for Adaptivity'
    launch_view_name = 'lti_launch'
    launch_url = request.build_absolute_uri(reverse(launch_view_name))

    extensions = {}

    lti_tool_config = ToolConfig(title=app_title,
                                 launch_url=launch_url,
                                 secure_launch_url=launch_url,
                                 extensions=extensions,
                                 description=app_description)

    return HttpResponse(lti_tool_config.to_xml(), content_type='text/xml')
Ejemplo n.º 7
0
    def get(self, request, pk):
        '''
        The LTI tool consumer performs a GET request when it wants to fetch the tool configuration.
        We create one LTI tool per assignment, which may sound strange. The reason is that the
        natural method of treating OpenSubmit as LTI tool, and giving a choice of assignments to the
        LTI tool consumer Moodle, works in theory form the protocol viewpoint, but not in Moodle
        correctly (TODO: Reference to according Moodle issue).
        '''
        launch_url = request.build_absolute_uri(reverse('lti', args=[pk]))
        assignment = get_object_or_404(Assignment, pk=pk)

        lti_tool_config = ToolConfig(title=assignment.title,
                                     launch_url=launch_url,
                                     secure_launch_url=launch_url)

        return HttpResponse(lti_tool_config.to_xml(), content_type='text/xml')
Ejemplo n.º 8
0
 def test_read_xml_config(self):
     '''
     Should read an XML config.
     '''
     config = ToolConfig.create_from_xml(CC_LTI_XML)
     self.assertEqual(normalize_xml(config.to_xml()),
                      normalize_xml(CC_LTI_XML))
Ejemplo n.º 9
0
 def get_tool_config(self):
     '''Returns an instance of ToolConfig()'''
     return ToolConfig(
         title=self.TOOL_TITLE,
         description=self.TOOL_DESCRIPTION,
         launch_url=self.get_launch_url(),
         secure_launch_url=self.get_launch_url(force_secure=True),
     )
Ejemplo n.º 10
0
 def test_can_parse_optional_config_parameters(self):
     '''
     Config should have cartridge_icon and blti:icon set
     '''
     config = ToolConfig.create_from_xml(CC_LTI_OPTIONAL_PARAMS_XML)
     self.assertEqual(config.cartridge_icon, 'BLTI001_Icon')
     self.assertEqual(config.icon, 'http://wil.to/_/beardslap.gif')
     self.assertEqual(config.secure_icon, 'https://www.example.com/secure_icon.png')
Ejemplo n.º 11
0
    def get(self, request, *args, **kwargs):
        app_title = "My App"
        app_description = "An example LTI App"
        launch_url = request.build_absolute_uri(reverse("lti:index"))

        extensions = {}

        lti_tool_config = ToolConfig(
            title=app_title,
            launch_url=launch_url,
            secure_launch_url=launch_url,
            extensions=extensions,
            description=app_description,
        )

        lti_tool_config.icon = "http://www.example.com/icon.png"

        return HttpResponse(lti_tool_config.to_xml(), content_type="text/xml")
Ejemplo n.º 12
0
 def get_tool_config(self, request):
     '''
     Returns an instance of ToolConfig().
     '''
     launch_url = self.get_launch_url(request)
     return ToolConfig(
         title=LTI_SETUP['TOOL_TITLE'],
         description=LTI_SETUP['TOOL_DESCRIPTION'],
         launch_url=launch_url,
         secure_launch_url=launch_url,
     )
    def test_tool_config(self):
        launch_url = "http://foo.bar/"
        self.view.get_launch_url = Mock(return_value=launch_url)

        expected = ToolConfig(title=settings.LTI_SETUP.get('TOOL_TITLE'),
                              launch_url=launch_url,
                              secure_launch_url=launch_url)
        actual = self.view.get_tool_config(self.view.request)

        self.assertEqual(actual.title, expected.title)
        self.assertEqual(actual.launch_url, expected.launch_url)
        self.assertEqual(actual.secure_launch_url, expected.secure_launch_url)
Ejemplo n.º 14
0
    def get(self, request):
        app_title = 'My App'
        app_description = 'An example LTI app'
        launch_view_name = 'lti_launch'
        launch_url = request.build_absolute_uri(reverse('lti_launch'))

        # maybe you've got some extensions
        extensions = {
            'my_extensions_provider': {
                # extension settings...
            }
        }

        lti_tool_config = ToolConfig(
            title=app_title,
            launch_url=launch_url,
            secure_launch_url=launch_url,
            extensions=extensions,
            description = app_description
        )

        return HttpResponse(lti_tool_config.to_xml(), content_type='text/xml')
Ejemplo n.º 15
0
 def get_tool_config(self, request):
     '''
     Returns an instance of ToolConfig().
     '''
     launch_url = self.get_launch_url(request)
     extensions = {
         'canvas.instructure.com': {
             'privacy_level': 'public',
             'course_navigation': {
                 'enabled': 'true',
                 'default': 'disabled',
                 'text': self.TOOL_TITLE,
             }
         }
     }
     return ToolConfig(
         title=self.TOOL_TITLE,
         description=self.TOOL_DESCRIPTION,
         launch_url=launch_url,
         secure_launch_url=launch_url,
         extensions=extensions,
     )
Ejemplo n.º 16
0
 def test_read_xml_config(self):
     '''
     Should read an XML config.
     '''
     config = ToolConfig.create_from_xml(CC_LTI_XML)
     self.assertEqual(normalize_xml(config.to_xml()), normalize_xml(CC_LTI_XML))
Ejemplo n.º 17
0
 def test_can_parse_optional_config_parameters(self):
     '''
     Config should have cartridge_icon and blti:icon set
     '''
     config = ToolConfig.create_from_xml(CC_LTI_OPTIONAL_PARAMS_XML)
     self.assertEqual(config.cartridge_icon, 'BLTI001_Icon')
Ejemplo n.º 18
0
def tool_config(request):

    # basic stuff
    app_title = 'LTI Inspector'
    app_description = 'A simple LTI App that echoes the launch parameters'
    launch_view_name = 'lti_launch'
    launch_url = request.build_absolute_uri(
        reverse(launch_view_name, args=('', )))

    icon_url = request.build_absolute_uri(static('harvard-shield-30-2x.png'))

    # maybe you've got some extensions
    extensions = {
        'canvas.instructure.com': {
            # extension settings...
            'privacy_level': 'public',
            'custom_fields': {},
            'course_navigation': {
                'url': '{}/course_navigation'.format(launch_url),
                'text': '{} - course_navigation'.format(app_title),
                'icon_url': icon_url,
                'visibility': 'public',
                'default': 'enabled',
                'enabled': 'true',
            },
            'account_navigation': {
                'url': '{}/account_navigation'.format(launch_url),
                'text': '{} - account_navigation'.format(app_title),
                'visibility': 'public',
                'default': 'enabled',
                'enabled': 'true',
            },
            'user_navigation': {
                'url': '{}/user_navigation'.format(launch_url),
                'text': '{} - user_navigation'.format(app_title),
                'visibility': 'public',
                'default': 'enabled',
                'enabled': 'true',
            },
            'global_navigation': {
                'url': '{}/global_navigation'.format(launch_url),
                'text': '{} - global_navigation'.format(app_title),
                'visibility': 'public',
                'default': 'enabled',
                'enabled': 'true',
            },
            'course_home_sub_navigation': {
                'url': '{}/course_home_sub_navigation'.format(launch_url),
                'text': '{} - course_home_sub_navigation'.format(app_title),
                'icon_url': icon_url,
                'canvas_icon_class': 'icon-lti',
            },
            'course_settings_sub_navigation': {
                'url': '{}/course_settings_sub_navigation'.format(launch_url),
                'text':
                '{} - course_settings_sub_navigation'.format(app_title),
                'canvas_icon_class': 'icon-standards',
            },
            'homework_submission': {
                'url': '{}/homework_submission'.format(launch_url),
                'text': '{} - homework_submission'.format(app_title),
                'icon_url': icon_url,
                'message_type': 'ContentItemSelectionRequest',
                'selection_width': '800',
                'selection_height': '600',
                'enabled': 'true',
            },
            'assignment_selection': {
                'url': '{}/assignment_selection'.format(launch_url),
                'text': '{} - assignment_selection'.format(app_title),
                'message_type': 'ContentItemSelectionRequest',
                'icon_url': icon_url,
                'selection_width': '800',
                'selection_height': '600',
                'enabled': 'true',
            },
            'editor_button': {
                'url': '{}/editor_button'.format(launch_url),
                'text': '{} - editor_button'.format(app_title),
                'message_type': 'ContentItemSelectionRequest',
                'icon_url': icon_url,
                'selection_width': '800',
                'selection_height': '600',
                'enabled': 'true',
            },
            'link_selection': {
                'url': '{}/link_selection'.format(launch_url),
                'text': '{} - link_selection'.format(app_title),
                'icon_url': icon_url,
                'message_type': 'ContentItemSelectionRequest',
                'selection_width': '800',
                'selection_height': '600',
                'enabled': 'true',
            },
            'resource_selection': {
                'url': '{}/resource_selection'.format(launch_url),
                'text': '{} - resource_selection'.format(app_title),
                'icon_url': icon_url,
                'selection_width': '800',
                'selection_height': '600',
                'enabled': 'true',
            },
            'tool_configuration': {
                'url': '{}/tool_configuration'.format(launch_url),
                'text': '{} - tool_configuration'.format(app_title),
                'selection_width': '800',
                'selection_height': '600',
                'enabled': 'true',
            },
            'file_menu': {
                'url': '{}/file_menu'.format(launch_url),
                'text': '{} - file_menu'.format(app_title),
            },
        }
    }

    for varname in VARIABLE_EXPANSIONS:
        extensions['canvas.instructure.com']['custom_fields'][
            varname] = '${}'.format(varname)

    lti_tool_config = ToolConfig(title=app_title,
                                 launch_url=launch_url,
                                 secure_launch_url=launch_url,
                                 extensions=extensions,
                                 description=app_description)

    return HttpResponse(lti_tool_config.to_xml(), content_type='text/xml')
Ejemplo n.º 19
0
    def test_allow_suboptions(self):

        config = ToolConfig(title="Test Config",
                            secure_launch_url="https://www.example.com/lti",
                            custom_params={"custom1": "customval1"})
        config.description = 'Description of boringness'
        config.launch_url = 'http://www.example.com/lti'
        config.vendor_code = 'test'
        config.vendor_name = 'test.tool'
        config.vendor_description = 'We test things'
        config.vendor_url = 'http://www.example.com/about'
        config.vendor_contact_email = '*****@*****.**'
        config.vendor_contact_name = 'Joe Support'

        config.set_custom_param('custom2', 'customval2')

        config.set_ext_params('example.com', {'extkey1': 'extval1'})
        config.set_ext_param('example.com', 'extkey2', 'extval2')
        config.set_ext_param('example.com', 'extopt1', {
            'optkey1': 'optval1',
            'optkey2': 'optval2'
        })
        config.set_ext_param('example.com', 'extopt1', {
            'labels': {
                'en': 'Image Library',
                'es': 'Biblioteca de Imagenes'
            }
        })
        config.set_ext_param('two.example.com', 'ext1key', 'ext1val')

        config.cartridge_bundle = 'BLTI001_Bundle'

        correct = normalize_xml(CC_LTI_WITH_SUBOPTIONS_XML)
        got = normalize_xml(config.to_xml())
        self.assertEqual(got, correct)
Ejemplo n.º 20
0
 def test_invalid_config_xml(self):
     '''
     Should not allow creating invalid config xml.
     '''
     config = ToolConfig(title='Test Config')
     self.assertRaises(InvalidLTIConfigError, config.to_xml)
Ejemplo n.º 21
0
    def test_allow_suboptions(self):

        config = ToolConfig(title = "Test Config",
                secure_launch_url = "https://www.example.com/lti",
                custom_params = {"custom1": "customval1"})
        config.description ='Description of boringness'
        config.launch_url = 'http://www.example.com/lti'
        config.icon = 'http://wil.to/_/beardslap.gif'
        config.vendor_code = 'test'
        config.vendor_name = 'test.tool'
        config.vendor_description = 'We test things'
        config.vendor_url = 'http://www.example.com/about'
        config.vendor_contact_email = '*****@*****.**'
        config.vendor_contact_name = 'Joe Support'

        config.set_custom_param('custom2', 'customval2')

        config.set_ext_params('example.com', { 'extkey1': 'extval1' })
        config.set_ext_param('example.com', 'extkey2', 'extval2')
        config.set_ext_param('example.com', 'extopt1',
                { 'optkey1': 'optval1', 'optkey2': 'optval2' })
        config.set_ext_param('example.com', 'extopt1',
                { 'labels':{
                    'en':'Image Library',
                    'es':'Biblioteca de Imagenes'
                    }
                })
        config.set_ext_param('two.example.com', 'ext1key', 'ext1val')

        config.cartridge_bundle = 'BLTI001_Bundle'

        correct = normalize_xml(CC_LTI_WITH_SUBOPTIONS_XML)
        got = normalize_xml(config.to_xml())
        self.assertEqual(got, correct)
Ejemplo n.º 22
0
    def test_generate_xml(self):
        '''
        Should generate the expected config xml.
        '''
        config = ToolConfig(title="Test Config",
                            secure_launch_url="https://www.example.com/lti",
                            custom_params={"custom1": "customval1"})
        config.description = 'Description of boringness'
        config.launch_url = 'http://www.example.com/lti'
        config.vendor_code = 'test'
        config.vendor_name = 'test.tool'
        config.vendor_description = 'We test things'
        config.vendor_url = 'http://www.example.com/about'
        config.vendor_contact_email = '*****@*****.**'
        config.vendor_contact_name = 'Joe Support'

        config.set_custom_param('custom2', 'customval2')

        config.set_ext_params('example.com', {'extkey1': 'extval1'})
        config.set_ext_param('example.com', 'extkey2', 'extval2')
        config.set_ext_param('example.com', 'extopt1', {
            'optkey1': 'optval1',
            'optkey2': 'optval2'
        })
        config.set_ext_param('two.example.com', 'ext1key', 'ext1val')

        config.cartridge_bundle = 'BLTI001_Bundle'

        correct = normalize_xml(CC_LTI_XML)
        got = normalize_xml(config.to_xml())
        self.assertEqual(got, correct)
Ejemplo n.º 23
0
    def test_generate_xml(self):
        '''
        Should generate the expected config xml.
        '''
        config = ToolConfig(title = "Test Config",
                secure_launch_url = "https://www.example.com/lti",
                custom_params = {"custom1": "customval1"})
        config.description ='Description of boringness'
        config.launch_url = 'http://www.example.com/lti'
        config.icon = 'http://wil.to/_/beardslap.gif'
        config.vendor_code = 'test'
        config.vendor_name = 'test.tool'
        config.vendor_description = 'We test things'
        config.vendor_url = 'http://www.example.com/about'
        config.vendor_contact_email = '*****@*****.**'
        config.vendor_contact_name = 'Joe Support'

        config.set_custom_param('custom2', 'customval2')

        config.set_ext_params('example.com', { 'extkey1': 'extval1' })
        config.set_ext_param('example.com', 'extkey2', 'extval2')
        config.set_ext_param('example.com', 'extopt1',
                { 'optkey1': 'optval1', 'optkey2': 'optval2' })
        config.set_ext_param('two.example.com', 'ext1key', 'ext1val')

        config.cartridge_bundle = 'BLTI001_Bundle'

        correct = normalize_xml(CC_LTI_XML)
        got = normalize_xml(config.to_xml())
        self.assertEqual(got, correct)