Skip to content

Commit

Permalink
Allow the 'My account' and 'Register' urls to be modified at the envi…
Browse files Browse the repository at this point in the history
…ronment level, and do not show the link when the value is not set
  • Loading branch information
ababic committed Jul 1, 2022
1 parent 0f4d11b commit dbcfe2c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"wagtail.contrib.settings.context_processors.settings",
"etna.core.context_processors.globals",
"etna.core.context_processors.feature_flags",
],
},
Expand All @@ -134,6 +135,8 @@
LOGIN_REDIRECT_URL = "/"
LOGOUT_URL = "/accounts/logout"
LOGOUT_REDIRECT_URL = "/"
MY_ACCOUNT_URL = os.getenv("MY_ACCOUNT_URL")
REGISTER_URL = os.getenv("REGISTER_URL")
WAGTAIL_FRONTEND_LOGIN_URL = LOGIN_URL
# View access control
IMAGE_VIEWER_REQUIRE_LOGIN = strtobool(os.getenv("IMAGE_VIEWER_REQUIRE_LOGIN", "True"))
Expand Down
10 changes: 10 additions & 0 deletions etna/core/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
from django.conf import settings


def globals(request):
"""
Adds common setting (and potentially other values) to the context.
"""
return {
"MY_ACCOUNT_URL": settings.MY_ACCOUNT_URL,
"REGISTER_URL": settings.REGISTER_URL,
}


def feature_flags(request):
"""
Makes any settings with the "FEATURE_" prefix available template contexts,
Expand Down
8 changes: 6 additions & 2 deletions templates/includes/login-status.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<div class="login-status" role="region" aria-labelledby="authentication_link">
{% if request.user.is_authenticated %}
<a href="https://tna-account-management-poc.torchbox.dev/" class="login-status__link">My account</a>
{% if MY_ACCOUNT_URL %}
<a href="{{ MY_ACCOUNT_URL }}" class="login-status__link">My account</a>
{% endif %}
<a href="{% url 'account_logout' %}" class="login-status__link" id="authentication_link">Logout</a>
{% else %}
<a href="{% url 'account_login' %}" class="login-status__link" id="authentication_link">Login</a>
<a href="{% url 'account_signup' %}" class="login-status__link">Register</a>
{% if REGISTER_URL %}
<a href="{{ REGISTER_URL }}" class="login-status__link">Register</a>
{% endif %}
{% endif %}
</div>

0 comments on commit dbcfe2c

Please sign in to comment.