Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2024-11-23 | MAIN --> PROD | DEV (84cb81e) --> STAGING #4477

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions backend/audit/views/home.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime, timezone
from django.conf import settings
from django.shortcuts import render, redirect
from django.urls import reverse
Expand Down Expand Up @@ -32,4 +33,12 @@ class Maintenance(generic.View):

def get(self, request, *args, **kwargs):
template_name = "503.html"

current_time = datetime.now(timezone.utc)
for date_range in settings.MAINTENANCE_BANNER_DATES:
if current_time > date_range.get("start") and current_time < date_range.get(
"end"
):
template_name = date_range.get("template_name", "503.html")

return render(request, template_name)
36 changes: 36 additions & 0 deletions backend/config/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from config import settings
from datetime import datetime, timezone


def static_site_url(request):
Expand All @@ -23,3 +24,38 @@ def current_environment(request):
Used in determining the display of the TEST SITE Banner.
"""
return {"ENVIRONMENT": settings.ENVIRONMENT}


def maintenance_banner(request):
"""
Returns maintenance banner template context.
MAINTENANCE_BANNER is True if the banner should be displaying and False if not, based on settings.MAINTENANCE_BANNER_DATES.
MAINTENANCE_BANNER_START_TIME and MAINTENANCE_BANNER_END_TIME are None if the banner does not display.
MAINTENANCE_BANNER_MESSAGE is included if it exists alongside the banner dates.
"""
current_time = datetime.now(timezone.utc)
context = {
"MAINTENANCE_BANNER": False,
}

# For every designated date range:
# If any start or end time is unavailable, something is misconfigured. So, disable the banner.
# If we are within the specified timeframes, enable the banner.
for date_range in settings.MAINTENANCE_BANNER_DATES:
start_time = date_range.get("start")
end_time = date_range.get("end")

if not start_time or not end_time:
return context

if current_time > start_time and current_time < end_time:
context["MAINTENANCE_BANNER"] = True
context = context | {
"MAINTENANCE_BANNER_START_TIME": start_time,
"MAINTENANCE_BANNER_END_TIME": end_time,
"MAINTENANCE_BANNER_MESSAGE": date_range.get("message", ""),
}
return context

# Base case - we are not within any of the given timeframes. Disable the banner.
return context
5 changes: 5 additions & 0 deletions backend/config/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ def __call__(self, request):
Check that maintenance mode is disabled before running request.
"""

# Let icons through
if request.path == "/icons/sprite.svg":
response = self.get_response(request)
return response

# redirect to maintenance page.
if is_maintenance_on():
if request.path != "/maintenance":
Expand Down
17 changes: 17 additions & 0 deletions backend/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

from base64 import b64decode
from datetime import datetime, timezone
import os
import sys
import logging
Expand Down Expand Up @@ -161,6 +162,7 @@
"config.context_processors.static_site_url",
"config.context_processors.omb_num_exp_date",
"config.context_processors.current_environment",
"config.context_processors.maintenance_banner",
"report_submission.context_processors.certifiers_emails_must_not_match",
],
"builtins": [
Expand Down Expand Up @@ -580,3 +582,18 @@
# Keep sessions alive if the user is active
# https://docs.djangoproject.com/en/dev/ref/settings/#session-save-every-request
SESSION_SAVE_EVERY_REQUEST = True

# Times for the maintenance banner to display.
# Requires a 'start' and an 'end'.
# 'template_name' is optional, and defines what will display if maintenance mode is enabled during this timeframe. If no name is given, the 503 error page is used.
# 'message' is optional, and overrides the default banner message.
# The default message states that maintenance will be ongoing for the duration of the banners uptime. This may be true in an emergency. Otherwise, be sure to set a custom message.
MAINTENANCE_BANNER_DATES = [
{
# December 5th to 10th, noon EST, uploading historical audits
"start": datetime(2024, 12, 5, 17, tzinfo=timezone.utc),
"end": datetime(2024, 12, 10, 17, tzinfo=timezone.utc),
"template_name": "maintenance_20241210.html",
"message": "FAC.gov will be doing a site upgrade on Tuesday, December 10, 2024 between 12:00 p.m. and 6:00 p.m ET. During this period, the entire website will be unavailable.",
},
]
5 changes: 5 additions & 0 deletions backend/templates/includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
</div>
</section>
{% endif %}

{% if MAINTENANCE_BANNER %}
{% include "includes/maintenance_banner.html" %}
{% endif %}

<section class="usa-banner" aria-label="Official government website">
<div class="usa-accordion">
<header class="usa-banner__header">
Expand Down
15 changes: 15 additions & 0 deletions backend/templates/includes/maintenance_banner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<section class="usa-alert usa-alert--warning margin-top-0" aria-label="Site alert">
<div class="usa-alert__body">
<h4 class="usa-alert__heading">Scheduled system upgrade</h4>

{% comment %} If a message is given, use it. If not, display a generic message with the timeframe. {% endcomment %}
<p class="usa-alert__text">
{% if MAINTENANCE_BANNER_MESSAGE %}
{{ MAINTENANCE_BANNER_MESSAGE }}
{% else %}
FAC.gov will be doing a site upgrade from {{ MAINTENANCE_BANNER_START_TIME|date:"N j, Y, f A" }} to {{ MAINTENANCE_BANNER_END_TIME|date:"N j, Y, f A" }}.
During this period, the entire website will be unavailable.
{% endif %}
</p>
</div>
</section>
13 changes: 13 additions & 0 deletions backend/templates/maintenance_20241210.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "base.html" %}
{% load sprite_helper %}
{% block content %}
<div class="display-flex flex-column flex-align-center margin-y-15">
<svg class="usa-icon usa-icon--size-7 text-error" focusable="false" role="img">
{% uswds_sprite "error" %}
</svg>
<h1 class="font-sans-2xl">Temporarily Down for System Maintenance</h1>
<p class="font-sans-lg margin-y-0">We are in the process of uploading historical audits to fac.gov.</p>
<p class="font-sans-lg margin-y-0">We should be back after December 10, 2024 at 6:00 p.m. ET.</p>
<p class="margin-top-10">Thank you for your patience. If you have any questions, please contact us via email at <a class="usa-link" href="mailto:[email protected]">[email protected]</a>.</p>
</div>
{% endblock content %}
Loading