diff --git a/ops/manifests/manifest-ab.yaml b/ops/manifests/manifest-ab.yaml index 062ad335c..463563a15 100644 --- a/ops/manifests/manifest-ab.yaml +++ b/ops/manifests/manifest-ab.yaml @@ -20,6 +20,8 @@ applications: DJANGO_BASE_URL: https://getgov-ab.app.cloud.gov # Tell Django how much stuff to log DJANGO_LOG_LEVEL: INFO + # Public site base URL + GETGOV_PUBLIC_SITE_URL: https://federalist-877ab29f-16f6-4f12-961c-96cf064cf070.sites.pages.cloud.gov/site/cisagov/getgov-home/ routes: - route: getgov-ab.app.cloud.gov services: diff --git a/ops/manifests/manifest-bl.yaml b/ops/manifests/manifest-bl.yaml index bb8723f2d..ec6d627ce 100644 --- a/ops/manifests/manifest-bl.yaml +++ b/ops/manifests/manifest-bl.yaml @@ -20,6 +20,8 @@ applications: DJANGO_BASE_URL: https://getgov-bl.app.cloud.gov # Tell Django how much stuff to log DJANGO_LOG_LEVEL: INFO + # Public site base URL + GETGOV_PUBLIC_SITE_URL: https://federalist-877ab29f-16f6-4f12-961c-96cf064cf070.sites.pages.cloud.gov/site/cisagov/getgov-home/ routes: - route: getgov-bl.app.cloud.gov services: diff --git a/ops/manifests/manifest-ik.yaml b/ops/manifests/manifest-ik.yaml index 2652b709a..60571e9ba 100644 --- a/ops/manifests/manifest-ik.yaml +++ b/ops/manifests/manifest-ik.yaml @@ -20,6 +20,8 @@ applications: DJANGO_BASE_URL: https://getgov-ik.app.cloud.gov # Tell Django how much stuff to log DJANGO_LOG_LEVEL: INFO + # Public site base URL + GETGOV_PUBLIC_SITE_URL: https://federalist-877ab29f-16f6-4f12-961c-96cf064cf070.sites.pages.cloud.gov/site/cisagov/getgov-home/ routes: - route: getgov-ik.app.cloud.gov services: diff --git a/ops/manifests/manifest-jon.yaml b/ops/manifests/manifest-jon.yaml index 4b32235fa..acc226ce3 100644 --- a/ops/manifests/manifest-jon.yaml +++ b/ops/manifests/manifest-jon.yaml @@ -20,6 +20,8 @@ applications: DJANGO_BASE_URL: https://getgov-jon.app.cloud.gov # Tell Django how much stuff to log DJANGO_LOG_LEVEL: INFO + # Public site base URL + GETGOV_PUBLIC_SITE_URL: https://federalist-877ab29f-16f6-4f12-961c-96cf064cf070.sites.pages.cloud.gov/site/cisagov/getgov-home/ routes: - route: getgov-jon.app.cloud.gov services: diff --git a/ops/manifests/manifest-mr.yaml b/ops/manifests/manifest-mr.yaml index 4280f0558..2ad39b9ff 100644 --- a/ops/manifests/manifest-mr.yaml +++ b/ops/manifests/manifest-mr.yaml @@ -20,6 +20,8 @@ applications: DJANGO_BASE_URL: https://getgov-mr.app.cloud.gov # Tell Django how much stuff to log DJANGO_LOG_LEVEL: INFO + # Public site base URL + GETGOV_PUBLIC_SITE_URL: https://federalist-877ab29f-16f6-4f12-961c-96cf064cf070.sites.pages.cloud.gov/site/cisagov/getgov-home/ routes: - route: getgov-mr.app.cloud.gov services: diff --git a/ops/manifests/manifest-nmb.yaml b/ops/manifests/manifest-nmb.yaml index 8352d8ed1..adea312d5 100644 --- a/ops/manifests/manifest-nmb.yaml +++ b/ops/manifests/manifest-nmb.yaml @@ -20,6 +20,8 @@ applications: DJANGO_BASE_URL: https://getgov-nmb.app.cloud.gov # Tell Django how much stuff to log DJANGO_LOG_LEVEL: INFO + # Public site base URL + GETGOV_PUBLIC_SITE_URL: https://federalist-877ab29f-16f6-4f12-961c-96cf064cf070.sites.pages.cloud.gov/site/cisagov/getgov-home/ routes: - route: getgov-nmb.app.cloud.gov services: diff --git a/ops/manifests/manifest-rjm.yaml b/ops/manifests/manifest-rjm.yaml index c5b51c3b5..9622f09bc 100644 --- a/ops/manifests/manifest-rjm.yaml +++ b/ops/manifests/manifest-rjm.yaml @@ -20,6 +20,8 @@ applications: DJANGO_BASE_URL: https://getgov-rjm.app.cloud.gov # Tell Django how much stuff to log DJANGO_LOG_LEVEL: INFO + # Public site base URL + GETGOV_PUBLIC_SITE_URL: https://federalist-877ab29f-16f6-4f12-961c-96cf064cf070.sites.pages.cloud.gov/site/cisagov/getgov-home/ routes: - route: getgov-rjm.app.cloud.gov services: diff --git a/ops/manifests/manifest-sspj.yaml b/ops/manifests/manifest-sspj.yaml index db1c29a1b..cec82c8a1 100644 --- a/ops/manifests/manifest-sspj.yaml +++ b/ops/manifests/manifest-sspj.yaml @@ -20,6 +20,8 @@ applications: DJANGO_BASE_URL: https://getgov-sspj.app.cloud.gov # Tell Django how much stuff to log DJANGO_LOG_LEVEL: INFO + # Public site base URL + GETGOV_PUBLIC_SITE_URL: https://federalist-877ab29f-16f6-4f12-961c-96cf064cf070.sites.pages.cloud.gov/site/cisagov/getgov-home/ routes: - route: getgov-sspj.app.cloud.gov services: diff --git a/ops/manifests/manifest-stable.yaml b/ops/manifests/manifest-stable.yaml index 619e5fc7a..72726cd08 100644 --- a/ops/manifests/manifest-stable.yaml +++ b/ops/manifests/manifest-stable.yaml @@ -20,6 +20,8 @@ applications: DJANGO_BASE_URL: https://getgov-stable.app.cloud.gov # Tell Django how much stuff to log DJANGO_LOG_LEVEL: INFO + # Public site base URL + GETGOV_PUBLIC_SITE_URL: https://federalist-877ab29f-16f6-4f12-961c-96cf064cf070.sites.pages.cloud.gov/site/cisagov/getgov-home/ routes: - route: getgov-stable.app.cloud.gov services: diff --git a/ops/scripts/manifest-sandbox-template.yaml b/ops/scripts/manifest-sandbox-template.yaml index ba814b3d5..1bf979c9f 100644 --- a/ops/scripts/manifest-sandbox-template.yaml +++ b/ops/scripts/manifest-sandbox-template.yaml @@ -20,6 +20,8 @@ applications: DJANGO_BASE_URL: https://getgov-ENVIRONMENT.app.cloud.gov # Tell Django how much stuff to log DJANGO_LOG_LEVEL: INFO + # default public site location + GETGOV_PUBLIC_SITE_URL: https://beta.get.gov routes: - route: getgov-ENVIRONMENT.app.cloud.gov services: diff --git a/src/docker-compose.yml b/src/docker-compose.yml index 4399c5b70..82642bc93 100644 --- a/src/docker-compose.yml +++ b/src/docker-compose.yml @@ -27,6 +27,8 @@ services: - DJANGO_DEBUG=True # Tell Django where it is being hosted - DJANGO_BASE_URL=http://localhost:8080 + # Public site URL link + - GETGOV_PUBLIC_SITE_URL=https://beta.get.gov # Set a username for accessing the registry - REGISTRY_CL_ID=nothing # Set a password for accessing the registry diff --git a/src/registrar/config/settings.py b/src/registrar/config/settings.py index ce6307e3d..54eb35d9f 100644 --- a/src/registrar/config/settings.py +++ b/src/registrar/config/settings.py @@ -62,6 +62,8 @@ secret_registry_key = b64decode(secret("REGISTRY_KEY", "")) secret_registry_key_passphrase = secret("REGISTRY_KEY_PASSPHRASE", "") secret_registry_hostname = secret("REGISTRY_HOSTNAME") +secret_getgov_public_site_url = secret("GETGOV_PUBLIC_SITE_URL", "") + # region: Basic Django Config-----------------------------------------------### # Build paths inside the project like this: BASE_DIR / "subdir". @@ -505,6 +507,10 @@ ROOT_URLCONF = "registrar.config.urls" # Must be relative and end with "/" STATIC_URL = "public/" +# Base URL of our separate static public website. Used by the +# {% public_site_url subdir/path %} template tag +GETGOV_PUBLIC_SITE_URL = secret_getgov_public_site_url + # endregion # region: Registry----------------------------------------------------------### diff --git a/src/registrar/templates/application_purpose.html b/src/registrar/templates/application_purpose.html index a28dc27b3..ca2ff7287 100644 --- a/src/registrar/templates/application_purpose.html +++ b/src/registrar/templates/application_purpose.html @@ -1,5 +1,5 @@ {% extends 'application_form.html' %} -{% load field_helpers %} +{% load field_helpers url_helpers %} {% block form_instructions %}

.Gov domain names are for use on the internet. Don’t register a .gov to simply reserve a @@ -8,7 +8,7 @@ domain name or for mainly internal use.

Describe the reason for your domain request. Explain how you plan to use this domain. Who is your intended audience? Will you use it for a website and/or email? Are you moving your website from another top-level domain (like .com or .org)? -Read about activities that are prohibited on .gov domains.

+Read about activities that are prohibited on .gov domains.

{% endblock %} diff --git a/src/registrar/templatetags/url_helpers.py b/src/registrar/templatetags/url_helpers.py index 6201e61eb..5b76c116f 100644 --- a/src/registrar/templatetags/url_helpers.py +++ b/src/registrar/templatetags/url_helpers.py @@ -1,6 +1,8 @@ from django import template from django.urls import reverse +from django.conf import settings + register = template.Library() @@ -15,3 +17,16 @@ def startswith(text, starts): if isinstance(text, str): return text.startswith(starts) return False + + +@register.simple_tag +def public_site_url(url_path): + """Make a full URL for this path at our public site. + + The public site base url is set by a GETGOV_PUBLIC_SITE_URL environment + variable. + """ + base_url = settings.GETGOV_PUBLIC_SITE_URL + # join the two halves with a single slash + public_url = "/".join([base_url.rstrip("/"), url_path.lstrip("/")]) + return public_url diff --git a/src/registrar/tests/test_templatetags.py b/src/registrar/tests/test_templatetags.py new file mode 100644 index 000000000..681d823b7 --- /dev/null +++ b/src/registrar/tests/test_templatetags.py @@ -0,0 +1,31 @@ +"""Test template tags.""" + +from django.conf import settings +from django.test import TestCase +from django.template import Context, Template + + +class TestTemplateTags(TestCase): + def _render_template(self, string, context=None): + """Helper method to render a template given as a string. + + Originally from https://stackoverflow.com/a/1690879 + """ + context = context or {} + context = Context(context) + return Template(string).render(context) + + def test_public_site_url(self): + result = self._render_template( + "{% load url_helpers %}{% public_site_url 'directory/page' %}" + ) + self.assertTrue(result.startswith(settings.GETGOV_PUBLIC_SITE_URL)) + self.assertTrue(result.endswith("/directory/page")) + + def test_public_site_url_leading_slash(self): + result = self._render_template( + "{% load url_helpers %}{% public_site_url '/directory/page' %}" + ) + self.assertTrue(result.startswith(settings.GETGOV_PUBLIC_SITE_URL)) + # slash-slash host slash directory slash page + self.assertEqual(result.count("/"), 4)