Skip to content

Commit

Permalink
Fixes tl-its-umich-edu#1304 Ability to add/edit deployment ids though…
Browse files Browse the repository at this point in the history
… the django admin panel
  • Loading branch information
jonespm committed Sep 16, 2021
1 parent 11987be commit 23d19be
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 28 deletions.
2 changes: 2 additions & 0 deletions config/env_sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
60 changes: 32 additions & 28 deletions dashboard/lti_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions dashboard/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 23d19be

Please sign in to comment.