From fa23d13eac79680d127eaa79880f19a07250c661 Mon Sep 17 00:00:00 2001 From: Jesus Federico Date: Thu, 20 Jun 2024 09:03:36 -0400 Subject: [PATCH] LTI-382: generalized code and fixed format for 1.1 launches (#255) * LTI-382: generalized code and fixed format for 1.1 launches * LTI-382: generalized code and fixed format for 1.1 launches --- lib/bbb_lti_broker/helpers.rb | 50 ++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/lib/bbb_lti_broker/helpers.rb b/lib/bbb_lti_broker/helpers.rb index e927773b..0ba1e105 100644 --- a/lib/bbb_lti_broker/helpers.rb +++ b/lib/bbb_lti_broker/helpers.rb @@ -60,8 +60,8 @@ def secure_url(url) # def standarized_message(message_json) message = JSON.parse(message_json) - - # Consider for conversion all 1.3 launches, which even though , b) launches that did not come in common format + custom_params = message['custom_params'] || {} + ext_params = message['ext_params'] || {} if message['user_id'].blank? migration_map.each do |param, claim| claims = claim.split('#') @@ -72,28 +72,23 @@ def standarized_message(message_json) end custom_params = message['unknown_params']['https://purl.imsglobal.org/spec/lti/claim/custom'] || {} - custom_params.each do |key, value| - # for following the format used by LTI 1.1 apps. - message["custom_#{key}"] = value - # for following a standard format used by our own apps. - prefixed_key = key.start_with?('custom_') ? key : "custom_#{key}" - message['custom_params'][prefixed_key] = value - end - # message['custom_params'] = keys_with_prefix(custom_params, 'custom_') - ext_params = message['unknown_params']['https://purl.imsglobal.org/spec/lti/claim/ext'] || {} - ext_params.each do |key, value| - # for following the format used by LTI 1.1 apps. - message["ext_#{key}"] = value - # for following a standard format used by our own apps. - prefixed_key = key.start_with?('ext_') ? key : "ext_#{key}" - message['ext_params'][prefixed_key] = value - end - # message['ext_params'] = keys_with_prefix(ext_params, 'ext_') + end - curated_message = custom_overrides(message) - curated_message.to_json + custom_params_prefixed = keys_with_prefix(custom_params, 'custom_') + ext_params_prefixed = keys_with_prefix(ext_params, 'ext_') + + # backward compatible with format used by LTI 1.1 apps. + message.merge!(custom_params_prefixed) + message.merge!(ext_params_prefixed) + + # for following a standard format used by our own apps. + message['custom_params'] = custom_params_prefixed + message['ext_params'] = ext_params_prefixed + + message_with_custom_overrides = custom_overrides(message) + message_with_custom_overrides.to_json end def user_params(tc_instance_guid, params) @@ -189,5 +184,18 @@ def safe_custom_override_params # 2) set the overriding rules through tenant settings (safest) ['user_image'] end + + def keys_with_prefix(keys, prefix) + logger.debug("Keys: #{keys}") + prefixed_keys = {} + + keys.each do |key, value| + prefixed_key = key.start_with?(prefix) ? key : "#{prefix}#{key}" + prefixed_keys[prefixed_key] = value + end + logger.debug("Prefixed keys: #{prefixed_keys}") + + prefixed_keys + end end end