diff --git a/config/env_sample.json b/config/env_sample.json index 315efb3db..22a8f79e7 100644 --- a/config/env_sample.json +++ b/config/env_sample.json @@ -96,6 +96,8 @@ "STUDENT_DASHBOARD_LTI": false, "/* LTI 1.3 configuration":"*/", "/* The first key of LTI_CONFIG is the Canvas URL (production, beta, or test)":"*/", + "/* Note: If you leave this undefined, it will be available for configuration in the admin interface":"*/", + "/* If you define any settings here, these will take effect instead of the admin settings":"*/", "LTI_CONFIG": { "https://canvas.instructure.com": [ { diff --git a/dashboard/lti_new.py b/dashboard/lti_new.py index c18244e88..6f1d00689 100644 --- a/dashboard/lti_new.py +++ b/dashboard/lti_new.py @@ -23,7 +23,7 @@ from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST from pylti1p3.contrib.django import DjangoOIDCLogin, DjangoMessageLaunch, \ - DjangoCacheDataStorage + DjangoCacheDataStorage, DjangoDbToolConf from pylti1p3.tool_config import ToolConfDict from dashboard.common.db_util import canvas_id_to_incremented_id @@ -68,38 +68,42 @@ def __str__(self): def get_tool_conf(): lti_config = settings.LTI_CONFIG - try: - config = ToolConfDict(lti_config) - except Exception as error: - return error - - # There should be one key per platform - # and the name relay on platforms generic domain not institution specific - platform_domain = list(lti_config.keys())[0] - platform_config = lti_config[platform_domain][0] - client_id = platform_config['client_id'] - - try: - with open(platform_config.get( - 'private_key_file', '/secrets/private.key'), - 'r') as private_key_file: - config.set_private_key( - platform_domain, private_key_file.read(), client_id) - - with open(platform_config.get( - 'public_key_file', '/secrets/public.key'), - 'r') as public_key_file: - config.set_public_key( - platform_domain, public_key_file.read(), client_id) - - except OSError as error: - return error + # If there are configurations for lti_config, use that otherwise use the database config + if lti_config: + try: + config = ToolConfDict(lti_config) + except Exception as error: + return error + + # There should be one key per platform + # and the name relay on platforms generic domain not institution specific + platform_domain = list(lti_config.keys())[0] + platform_config = lti_config[platform_domain][0] + client_id = platform_config['client_id'] + + try: + with open(platform_config.get( + 'private_key_file', '/secrets/private.key'), + 'r') as private_key_file: + config.set_private_key( + platform_domain, private_key_file.read(), client_id) + + with open(platform_config.get( + 'public_key_file', '/secrets/public.key'), + 'r') as public_key_file: + config.set_public_key( + platform_domain, public_key_file.read(), client_id) + + except OSError as error: + return error + else: + config = DjangoDbToolConf() return config def is_config_valid(config: ToolConfDict): - if isinstance(config, ToolConfDict): + if isinstance(config, (ToolConfDict, DjangoDbToolConf)): logger.info('LTI configuration valid.') return True else: diff --git a/dashboard/settings.py b/dashboard/settings.py index 77dfbccee..e47845643 100644 --- a/dashboard/settings.py +++ b/dashboard/settings.py @@ -441,6 +441,9 @@ LTI_CONFIG = ENV.get('LTI_CONFIG', {}) LTI_CONFIG_TEMPLATE_PATH = ENV.get('LTI_CONFIG_TEMPLATE_PATH') LTI_CONFIG_DISABLE_DEPLOYMENT_ID_VALIDATION = ENV.get('LTI_CONFIG_DISABLE_DEPLOYMENT_ID_VALIDATION', False) + # If LTI_CONFIG is not defined then add the admin interface config + if not LTI_CONFIG: + INSTALLED_APPS += ('pylti1p3.contrib.django.lti1p3_tool_config',) # This is used to fix ids from Canvas Data which are incremented by some large number CANVAS_DATA_ID_INCREMENT = ENV.get("CANVAS_DATA_ID_INCREMENT", 17700000000000000)