#------------------------------------------------------------------------------
# written by:   DonatoBD
#               eduNEXT               
#
# date:         mar-2023
#
# usage:        eduNEXT's scorm proxy solution for resolving storage challenges
#               when running behind a proxy server
#------------------------------------------------------------------------------

# copied from: https://github.com/overhangio/tutor-mfe/blob/master/tutormfe/patches/openedx-common-settings
#
# MFE: enable API and set a low cache timeout for the settings. otherwise, weird
# configuration bugs occur. Also, the view is not costly at all, and it's also cached on
# the frontend. (5 minutes, hardcoded)
ENABLE_MFE_CONFIG_API = True
MFE_CONFIG_API_CACHE_TIMEOUT = 1

# MFE-specific settings
{% if get_mfe("authn") %}
FEATURES['ENABLE_AUTHN_MICROFRONTEND'] = True
{% endif %}
{% if get_mfe("communications") %}
FEATURES['ENABLE_NEW_BULK_EMAIL_EXPERIENCE'] = True
{% endif %}

# SCORM SETTINGS
def scorm_xblock_storage(xblock):
  from django.conf import settings
  from storages.backends.s3boto3 import S3Boto3Storage

  if SERVICE_VARIANT == "lms":
    domain = settings.LMS_BASE
  else:
    domain = settings.CMS_BASE

  return S3Boto3Storage(
    bucket=AWS_STORAGE_BUCKET_NAME,
    access_key=AWS_ACCESS_KEY_ID,
    secret_key=AWS_SECRET_ACCESS_KEY,
    querystring_expire=86400,
    custom_domain=f"{domain}/scorm-proxy"
  )

XBLOCK_SETTINGS["ScormXBlock"] = {
  "STORAGE_FUNC": scorm_xblock_storage,
}