Skip to content

Commit 23d19be

Browse files
committed
Fixes tl-its-umich-edu#1304 Ability to add/edit deployment ids though the django admin panel
1 parent 11987be commit 23d19be

File tree

3 files changed

+37
-28
lines changed

3 files changed

+37
-28
lines changed

config/env_sample.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@
9696
"STUDENT_DASHBOARD_LTI": false,
9797
"/* LTI 1.3 configuration":"*/",
9898
"/* The first key of LTI_CONFIG is the Canvas URL (production, beta, or test)":"*/",
99+
"/* Note: If you leave this undefined, it will be available for configuration in the admin interface":"*/",
100+
"/* If you define any settings here, these will take effect instead of the admin settings":"*/",
99101
"LTI_CONFIG": {
100102
"https://canvas.instructure.com": [
101103
{

dashboard/lti_new.py

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from django.views.decorators.csrf import csrf_exempt
2424
from django.views.decorators.http import require_POST
2525
from pylti1p3.contrib.django import DjangoOIDCLogin, DjangoMessageLaunch, \
26-
DjangoCacheDataStorage
26+
DjangoCacheDataStorage, DjangoDbToolConf
2727
from pylti1p3.tool_config import ToolConfDict
2828

2929
from dashboard.common.db_util import canvas_id_to_incremented_id
@@ -68,38 +68,42 @@ def __str__(self):
6868
def get_tool_conf():
6969
lti_config = settings.LTI_CONFIG
7070

71-
try:
72-
config = ToolConfDict(lti_config)
73-
except Exception as error:
74-
return error
75-
76-
# There should be one key per platform
77-
# and the name relay on platforms generic domain not institution specific
78-
platform_domain = list(lti_config.keys())[0]
79-
platform_config = lti_config[platform_domain][0]
80-
client_id = platform_config['client_id']
81-
82-
try:
83-
with open(platform_config.get(
84-
'private_key_file', '/secrets/private.key'),
85-
'r') as private_key_file:
86-
config.set_private_key(
87-
platform_domain, private_key_file.read(), client_id)
88-
89-
with open(platform_config.get(
90-
'public_key_file', '/secrets/public.key'),
91-
'r') as public_key_file:
92-
config.set_public_key(
93-
platform_domain, public_key_file.read(), client_id)
94-
95-
except OSError as error:
96-
return error
71+
# If there are configurations for lti_config, use that otherwise use the database config
72+
if lti_config:
73+
try:
74+
config = ToolConfDict(lti_config)
75+
except Exception as error:
76+
return error
77+
78+
# There should be one key per platform
79+
# and the name relay on platforms generic domain not institution specific
80+
platform_domain = list(lti_config.keys())[0]
81+
platform_config = lti_config[platform_domain][0]
82+
client_id = platform_config['client_id']
83+
84+
try:
85+
with open(platform_config.get(
86+
'private_key_file', '/secrets/private.key'),
87+
'r') as private_key_file:
88+
config.set_private_key(
89+
platform_domain, private_key_file.read(), client_id)
90+
91+
with open(platform_config.get(
92+
'public_key_file', '/secrets/public.key'),
93+
'r') as public_key_file:
94+
config.set_public_key(
95+
platform_domain, public_key_file.read(), client_id)
96+
97+
except OSError as error:
98+
return error
9799

100+
else:
101+
config = DjangoDbToolConf()
98102
return config
99103

100104

101105
def is_config_valid(config: ToolConfDict):
102-
if isinstance(config, ToolConfDict):
106+
if isinstance(config, (ToolConfDict, DjangoDbToolConf)):
103107
logger.info('LTI configuration valid.')
104108
return True
105109
else:

dashboard/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,9 @@
441441
LTI_CONFIG = ENV.get('LTI_CONFIG', {})
442442
LTI_CONFIG_TEMPLATE_PATH = ENV.get('LTI_CONFIG_TEMPLATE_PATH')
443443
LTI_CONFIG_DISABLE_DEPLOYMENT_ID_VALIDATION = ENV.get('LTI_CONFIG_DISABLE_DEPLOYMENT_ID_VALIDATION', False)
444+
# If LTI_CONFIG is not defined then add the admin interface config
445+
if not LTI_CONFIG:
446+
INSTALLED_APPS += ('pylti1p3.contrib.django.lti1p3_tool_config',)
444447

445448
# This is used to fix ids from Canvas Data which are incremented by some large number
446449
CANVAS_DATA_ID_INCREMENT = ENV.get("CANVAS_DATA_ID_INCREMENT", 17700000000000000)

0 commit comments

Comments
 (0)