Skip to content

Commit

Permalink
Merge pull request #2132 from GSA/2109-build-out-architecture-for-new…
Browse files Browse the repository at this point in the history
…-about-pages-behind-feature-flag

Added new header button that is displayed in header
  • Loading branch information
alexjanousekGSA authored Dec 2, 2024
2 parents 162d370 + 1931e43 commit 4170ca7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 41 deletions.
40 changes: 35 additions & 5 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
import pathlib
import secrets
from functools import partial
from time import monotonic
from urllib.parse import urlparse, urlunparse
from urllib.parse import unquote, urlparse, urlunparse

import jinja2
from flask import (
Expand Down Expand Up @@ -114,6 +115,7 @@
get_lines_with_normalised_whitespace,
)
from notifications_utils.recipients import format_phone_number_human_readable
from notifications_utils.url_safe_token import generate_token

login_manager = LoginManager()
csrf = CSRFProtect()
Expand Down Expand Up @@ -168,10 +170,38 @@ def create_app(application):

@application.context_processor
def inject_feature_flags():
feature_best_practices_enabled = application.config[
"FEATURE_BEST_PRACTICES_ENABLED"
]
return dict(FEATURE_BEST_PRACTICES_ENABLED=feature_best_practices_enabled)
feature_best_practices_enabled = application.config.get("FEATURE_BEST_PRACTICES_ENABLED", False)
feature_about_page_enabled = application.config.get("FEATURE_ABOUT_PAGE_ENABLED", False)
return dict(
FEATURE_BEST_PRACTICES_ENABLED=feature_best_practices_enabled,
FEATURE_ABOUT_PAGE_ENABLED=feature_about_page_enabled,
)

@application.context_processor
def inject_initial_signin_url():
ttl = 24 * 60 * 60

# make and store the state
state = generate_token(
str(request.remote_addr),
current_app.config["SECRET_KEY"],
current_app.config["DANGEROUS_SALT"],
)

state_key = f"login-state-{unquote(state)}"
redis_client.set(state_key, state, ex=ttl)

# make and store the nonce
nonce = secrets.token_urlsafe()
nonce_key = f"login-nonce-{unquote(nonce)}"
redis_client.set(nonce_key, nonce, ex=ttl)

url = os.getenv("LOGIN_DOT_GOV_INITIAL_SIGNIN_URL")
if url is not None:
url = url.replace("NONCE", nonce)
url = url.replace("STATE", state)

return {'initial_signin_url': url}

notify_environment = os.environ["NOTIFY_ENVIRONMENT"]

Expand Down
30 changes: 2 additions & 28 deletions app/main/views/index.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import os
import secrets
from urllib.parse import unquote

from flask import (
abort,
current_app,
Expand All @@ -13,7 +9,7 @@
)
from flask_login import current_user

from app import redis_client, status_api_client
from app import status_api_client
from app.formatters import apply_html_class, convert_markdown_template
from app.main import main
from app.main.views.pricing import CURRENT_SMS_RATE
Expand All @@ -24,7 +20,6 @@
using_notify_nav,
)
from app.utils.user import user_is_logged_in
from notifications_utils.url_safe_token import generate_token


# Hook to check for feature flags
Expand Down Expand Up @@ -57,31 +52,10 @@ def index():
if current_user and current_user.is_authenticated:
return redirect(url_for("main.choose_account"))

ttl = 24 * 60 * 60

# make and store the state
state = generate_token(
str(request.remote_addr),
current_app.config["SECRET_KEY"],
current_app.config["DANGEROUS_SALT"],
)
state_key = f"login-state-{unquote(state)}"
redis_client.set(state_key, state, ex=ttl)

# make and store the nonce
nonce = secrets.token_urlsafe()
nonce_key = f"login-nonce-{unquote(nonce)}"
redis_client.set(nonce_key, nonce, ex=ttl)

url = os.getenv("LOGIN_DOT_GOV_INITIAL_SIGNIN_URL")
if url is not None:
url = url.replace("NONCE", nonce)
url = url.replace("STATE", state)
return render_template(
"views/signedout.html",
sms_rate=CURRENT_SMS_RATE,
counts=status_api_client.get_count_of_live_services_and_organizations(),
initial_signin_url=url,
counts=status_api_client.get_count_of_live_services_and_organizations()
)


Expand Down
28 changes: 20 additions & 8 deletions app/templates/components/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,29 @@
<header class="usa-header usa-header--extended">
<div class="usa-nav-container">
<div class="usa-navbar">
<div class="usa-logo display-flex flex-align-center flex-justify" id="-logo">
<div class="logo-img display-flex">
<a href="/">
<span class="usa-sr-only">Notify.gov logo</span>
<img src="{{ (asset_path | default('/static')) + 'images/notify-logo.svg' }}" alt="Notify.gov logo"
class="usa-flag-logo margin-right-1">
<div class="display-flex flex-align-center flex-justify">
<div class="usa-logo display-flex flex-align-center flex-justify" id="-logo">
<div class="logo-img display-flex">
<a href="/">
<span class="usa-sr-only">Notify.gov logo</span>
<img src="{{ (asset_path | default('/static')) + 'images/notify-logo.svg' }}" alt="Notify.gov logo"
class="usa-flag-logo margin-right-1">
</a>
</div>
{% if navigation %}
<button type="button" class="usa-menu-btn">Menu</button>
{% endif %}
</div>
{% if not current_user.is_authenticated and FEATURE_ABOUT_PAGE_ENABLED and request.path == '/about'%}
<div class="usa-nav__login">
<a class="usa-button usa-button login-button login-button--primary margin-right-2"
href="{{ initial_signin_url }}">Sign
in with <img src="{{ asset_url('images/logo-login.svg') }}" alt="Login.gov logo">
</a>
</div>
{% if navigation %}
<button type="button" class="usa-menu-btn">Menu</button>
{% endif %}
</div>

</div>
<nav aria-label="Primary navigation" class="usa-nav">
<div class="usa-nav__inner">
Expand Down Expand Up @@ -89,6 +100,7 @@
{% endif %}
</ul>
</div>

</div>
</nav>
</div>
Expand Down

0 comments on commit 4170ca7

Please sign in to comment.