From a7ab1c5ace6e654fe684bf9b0f615e44e745f6be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Sat, 23 Mar 2019 16:07:50 -0700 Subject: [PATCH] Add missing CMS config (just in case) I don't think this affects the CMS behaviour, but SESSION_COOKIE_DOMAIN is used by the CMS, so rather be safe than sorry. --- CHANGELOG.md | 4 ++++ tutor/config.py | 3 +++ tutor/templates/apps/openedx/config/cms.env.json | 1 + tutor/templates/apps/openedx/config/lms.env.json | 2 +- tutor/utils.py | 16 ++++++++++++++++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7ba450..ee98719 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Latest + +- [Improvement] Support CMS login when the CMS is not a subdomain of the LMS + ## 3.3.0 (2019-03-22) - [Feature] Upgrade from Hawthorn to Ironwood diff --git a/tutor/config.py b/tutor/config.py index 0ac5f96..36a6b5d 100644 --- a/tutor/config.py +++ b/tutor/config.py @@ -164,6 +164,9 @@ def load_defaults(config): if k not in config: config[k] = v + # Add extra configuration parameters that need to be computed separately + config["lms_cms_common_domain"] = utils.common_domain(config["LMS_HOST"], config["CMS_HOST"]) + def ask(question, key, config): default = env.render_str(config, config[key]) config[key] = click.prompt( diff --git a/tutor/templates/apps/openedx/config/cms.env.json b/tutor/templates/apps/openedx/config/cms.env.json index 45a83d6..783f30b 100644 --- a/tutor/templates/apps/openedx/config/cms.env.json +++ b/tutor/templates/apps/openedx/config/cms.env.json @@ -33,6 +33,7 @@ "EMAIL_PORT": {{ SMTP_PORT }}, "HTTPS": "{{ "on" if ACTIVATE_HTTPS else "off" }}", "LANGUAGE_CODE": "{{ LANGUAGE_CODE }}", + "SESSION_COOKIE_DOMAIN": ".{{ lms_cms_common_domain }}", "CACHES": { "default": { "KEY_PREFIX": "default", diff --git a/tutor/templates/apps/openedx/config/lms.env.json b/tutor/templates/apps/openedx/config/lms.env.json index f983e51..ae99c0c 100644 --- a/tutor/templates/apps/openedx/config/lms.env.json +++ b/tutor/templates/apps/openedx/config/lms.env.json @@ -44,7 +44,7 @@ {% endif %} "LANGUAGE_CODE": "{{ LANGUAGE_CODE }}", "LOGIN_REDIRECT_WHITELIST": ["{{ CMS_HOST }}", "studio.localhost"], - "SESSION_COOKIE_DOMAIN": ".{{ LMS_HOST }}", + "SESSION_COOKIE_DOMAIN": ".{{ lms_cms_common_domain }}", "CACHES": { "default": { "KEY_PREFIX": "default", diff --git a/tutor/utils.py b/tutor/utils.py index d017d12..8d2de24 100644 --- a/tutor/utils.py +++ b/tutor/utils.py @@ -21,6 +21,22 @@ def parse_yaml_value(v): v = (v == "true") return v +def common_domain(d1, d2): + """ + Return the common domain between two domain names. + + Ex: "sub1.domain.com" and "sub2.domain.com" -> "domain.com" + """ + components1 = d1.split(".")[::-1] + components2 = d2.split(".")[::-1] + common = [] + for c in range(0, min(len(components1), len(components2))): + if components1[c] == components2[c]: + common.append(components1[c]) + else: + break + return ".".join(common[::-1]) + def docker_run(*command): return docker("run", "--rm", "-it", *command)