mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 13:39:41 -04:00
Merge branch 'main' of https://github.com/GSA/notifications-admin into 1269-content-update-for-login-gov-settings
This commit is contained in:
@@ -134,11 +134,17 @@ def template_usage(service_id):
|
||||
months=months,
|
||||
stats=stats,
|
||||
most_used_template_count=max(
|
||||
max(
|
||||
(template["requested_count"] for template in month["templates_used"]),
|
||||
default=0,
|
||||
)
|
||||
for month in months
|
||||
(
|
||||
max(
|
||||
(
|
||||
template["requested_count"]
|
||||
for template in month["templates_used"]
|
||||
),
|
||||
default=0,
|
||||
)
|
||||
for month in months
|
||||
),
|
||||
default=0,
|
||||
),
|
||||
years=get_tuples_of_financial_years(
|
||||
partial(url_for, ".template_usage", service_id=service_id),
|
||||
@@ -155,31 +161,16 @@ def usage(service_id):
|
||||
year, current_financial_year = requested_and_current_financial_year(request)
|
||||
|
||||
free_sms_allowance = billing_api_client.get_free_sms_fragment_limit_for_year(
|
||||
service_id, year
|
||||
service_id
|
||||
)
|
||||
|
||||
units = billing_api_client.get_monthly_usage_for_service(service_id, year)
|
||||
|
||||
yearly_usage = billing_api_client.get_annual_usage_for_service(service_id, year)
|
||||
|
||||
more_stats = format_monthly_stats_to_list(
|
||||
service_api_client.get_monthly_notification_stats(service_id, year)["data"]
|
||||
)
|
||||
if year == current_financial_year:
|
||||
# This includes Oct, Nov, Dec
|
||||
# but we don't need next year's data yet
|
||||
more_stats = [
|
||||
month
|
||||
for month in more_stats
|
||||
if month["name"] in ["October", "November", "December"]
|
||||
]
|
||||
elif year == (current_financial_year + 1):
|
||||
# This is all the other months
|
||||
# and we need last year's data
|
||||
more_stats = [
|
||||
month
|
||||
for month in more_stats
|
||||
if month["name"] not in ["October", "November", "December"]
|
||||
]
|
||||
|
||||
return render_template(
|
||||
"views/usage.html",
|
||||
months=list(get_monthly_usage_breakdown(year, units, more_stats)),
|
||||
@@ -341,8 +332,15 @@ def get_dashboard_partials(service_id):
|
||||
dashboard_totals = (get_dashboard_totals(stats),)
|
||||
free_sms_allowance = billing_api_client.get_free_sms_fragment_limit_for_year(
|
||||
current_service.id,
|
||||
get_current_financial_year(),
|
||||
)
|
||||
# These 2 calls will update the dashboard sms allowance count while in trial mode.
|
||||
billing_api_client.get_monthly_usage_for_service(
|
||||
service_id, get_current_financial_year()
|
||||
)
|
||||
billing_api_client.create_or_update_free_sms_fragment_limit(
|
||||
service_id, free_sms_fragment_limit=free_sms_allowance
|
||||
)
|
||||
|
||||
yearly_usage = billing_api_client.get_annual_usage_for_service(
|
||||
service_id,
|
||||
get_current_financial_year(),
|
||||
@@ -433,13 +431,7 @@ def aggregate_status_types(counts_dict):
|
||||
|
||||
|
||||
def get_months_for_financial_year(year, time_format="%B"):
|
||||
return [
|
||||
month.strftime(time_format)
|
||||
for month in (
|
||||
get_months_for_year(10, 13, year) + get_months_for_year(1, 10, year + 1)
|
||||
)
|
||||
if month < datetime.now()
|
||||
]
|
||||
return [month.strftime(time_format) for month in (get_months_for_year(1, 13, year))]
|
||||
|
||||
|
||||
def get_months_for_year(start, end, year):
|
||||
|
||||
@@ -6,6 +6,7 @@ import jwt
|
||||
import requests
|
||||
from flask import (
|
||||
Markup,
|
||||
Response,
|
||||
abort,
|
||||
current_app,
|
||||
flash,
|
||||
@@ -26,6 +27,7 @@ from app.main.views.verify import activate_user
|
||||
from app.models.user import InvitedUser, User
|
||||
from app.utils import hide_from_search_engines
|
||||
from app.utils.login import is_safe_redirect_url
|
||||
from app.utils.time import is_less_than_days_ago
|
||||
|
||||
|
||||
def _reformat_keystring(orig):
|
||||
@@ -63,6 +65,10 @@ def _get_access_token(code, state):
|
||||
url = f"{base_url}{cli_assert}&{cli_assert_type}&{code_param}&grant_type=authorization_code"
|
||||
headers = {"Authorization": "Bearer %s" % token}
|
||||
response = requests.post(url, headers=headers)
|
||||
if response.json().get("access_token") is None:
|
||||
# Capture the response json here so it hopefully shows up in error reports
|
||||
current_app.logger.error(f"Error when getting access token {response.json()}")
|
||||
raise KeyError(f"'access_token' {response.json()}")
|
||||
access_token = response.json()["access_token"]
|
||||
return access_token
|
||||
|
||||
@@ -84,31 +90,59 @@ def _do_login_dot_gov():
|
||||
code = request.args.get("code")
|
||||
state = request.args.get("state")
|
||||
login_gov_error = request.args.get("error")
|
||||
if code and state:
|
||||
access_token = _get_access_token(code, state)
|
||||
user_email, user_uuid = _get_user_email_and_uuid(access_token)
|
||||
redirect_url = request.args.get("next")
|
||||
|
||||
if login_gov_error:
|
||||
current_app.logger.error(f"login.gov error: {login_gov_error}")
|
||||
raise Exception(f"Could not login with login.gov {login_gov_error}")
|
||||
elif code and state:
|
||||
|
||||
# activate the user
|
||||
try:
|
||||
access_token = _get_access_token(code, state)
|
||||
user_email, user_uuid = _get_user_email_and_uuid(access_token)
|
||||
redirect_url = request.args.get("next")
|
||||
user = user_api_client.get_user_by_uuid_or_email(user_uuid, user_email)
|
||||
activate_user(user["id"])
|
||||
|
||||
# Check if the email needs to be revalidated
|
||||
is_fresh_email = is_less_than_days_ago(
|
||||
user["email_access_validated_at"], 90
|
||||
)
|
||||
if not is_fresh_email:
|
||||
return verify_email(user, redirect_url)
|
||||
|
||||
usr = User.from_email_address(user["email_address"])
|
||||
activate_user(usr.id)
|
||||
except BaseException as be: # noqa B036
|
||||
current_app.logger.error(be)
|
||||
error(401)
|
||||
|
||||
return redirect(url_for("main.show_accounts_or_dashboard", next=redirect_url))
|
||||
|
||||
elif login_gov_error:
|
||||
current_app.logger.error(f"login.gov error: {login_gov_error}")
|
||||
raise Exception(f"Could not login with login.gov {login_gov_error}")
|
||||
# end login.gov
|
||||
|
||||
|
||||
def verify_email(user, redirect_url):
|
||||
user_api_client.send_verify_code(user["id"], "email", None, redirect_url)
|
||||
title = "Email resent" if request.args.get("email_resent") else "Check your email"
|
||||
redirect_url = request.args.get("next")
|
||||
return render_template(
|
||||
"views/re-validate-email-sent.html", title=title, redirect_url=redirect_url
|
||||
)
|
||||
|
||||
|
||||
@main.route("/sign-in", methods=(["GET", "POST"]))
|
||||
@hide_from_search_engines
|
||||
def sign_in():
|
||||
_do_login_dot_gov()
|
||||
# If we have to revalidated the email, send the message
|
||||
# via email and redirect to the "verify your email page"
|
||||
# and don't proceed further with login
|
||||
email_verify_template = _do_login_dot_gov()
|
||||
if (
|
||||
email_verify_template
|
||||
and not isinstance(email_verify_template, Response)
|
||||
and "Check your email" in email_verify_template
|
||||
):
|
||||
return email_verify_template
|
||||
|
||||
redirect_url = request.args.get("next")
|
||||
|
||||
if os.getenv("NOTIFY_E2E_TEST_EMAIL"):
|
||||
@@ -192,7 +226,6 @@ def sign_in():
|
||||
form=form,
|
||||
again=bool(redirect_url),
|
||||
other_device=other_device,
|
||||
login_gov_enabled=True,
|
||||
password_reset_url=password_reset_url,
|
||||
initial_signin_url=url,
|
||||
)
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
Sorry, we can't deliver what you asked for right now.
|
||||
</h1>
|
||||
<p class="usa-body">
|
||||
Please try again later or <a class="usa-link" href="mailto:notify-support@gsa.gov"></a>email us</a> for more information.</p>
|
||||
Please try again later or <a class="usa-link" href="mailto:notify-support@gsa.gov">email us</a> for more information.</p>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
30
app/templates/new/components/main_nav.html
Normal file
30
app/templates/new/components/main_nav.html
Normal file
@@ -0,0 +1,30 @@
|
||||
{% if help %}
|
||||
{% include 'partials/tour.html' %}
|
||||
{% else %}
|
||||
<nav class="nav margin-bottom-4">
|
||||
<a class="usa-button margin-top-1 margin-bottom-5 width-full"
|
||||
href="{{ url_for('.choose_template', service_id=current_service.id) }}">Send messages</a>
|
||||
<ul class="usa-sidenav">
|
||||
{% if current_user.has_permissions() %}
|
||||
{% if current_user.has_permissions('view_activity') %}
|
||||
<li class="usa-sidenav__item"><a class="{{ main_navigation.is_selected('dashboard') }}" href="{{ url_for('.service_dashboard', service_id=current_service.id) }}">Dashboard</a></li>
|
||||
{% endif %}
|
||||
{% if not current_user.has_permissions('view_activity') %}
|
||||
<li class="usa-sidenav__item"><a class="{{ casework_navigation.is_selected('sent-messages') }}" href="{{ url_for('.view_notifications', service_id=current_service.id, status='sending,delivered,failed') }}">Sent messages</a></li>
|
||||
{% endif %}
|
||||
{% if current_user.has_permissions('manage_service', allow_org_user=True) %}
|
||||
{# <li class="usa-sidenav__item"><a class="{{ main_navigation.is_selected('usage') }}" href="{{ url_for('.usage', service_id=current_service.id) }}">Usage</a></li> #}
|
||||
{% endif %}
|
||||
<!-- {% if current_user.has_permissions('manage_api_keys', 'manage_service') %}
|
||||
<li class="usa-sidenav__item"><a class="{{ main_navigation.is_selected('settings') }}" href="{{ url_for('.service_settings', service_id=current_service.id) }}">Settings</a></li>
|
||||
{% endif %} -->
|
||||
{% if current_user.has_permissions('manage_api_keys') %}
|
||||
<!-- <li><a class="usa-link{{ main_navigation.is_selected('api-integration') }}" href="{{ url_for('.api_integration', service_id=current_service.id) }}">API integration</a></li> -->
|
||||
{% endif %}
|
||||
{% elif current_user.has_permissions(allow_org_user=True) %}
|
||||
<li class="usa-sidenav__item"><a class="usa-link{{ main_navigation.is_selected('usage') }}" href="{{ url_for('.usage', service_id=current_service.id) }}">Usage</a></li>
|
||||
<li class="usa-sidenav__item"><a class="usa-link{{ main_navigation.is_selected('team-members') }}" href="{{ url_for('.manage_users', service_id=current_service.id) }}">Team members</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</nav>
|
||||
{% endif %}
|
||||
11
app/templates/new/components/org_nav.html
Normal file
11
app/templates/new/components/org_nav.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<nav class="navigation">
|
||||
<ul>
|
||||
<li><a class="usa-link{{ org_navigation.is_selected('dashboard') }}" href="{{ url_for('.organization_dashboard', org_id=current_org.id) }}">Usage</a></li>
|
||||
<li><a class="usa-link{{ org_navigation.is_selected('team-members') }}" href="{{ url_for('.manage_org_users', org_id=current_org.id) }}">Team members</a></li>
|
||||
{% if current_user.platform_admin %}
|
||||
<li><a class="usa-link{{ org_navigation.is_selected('settings') }}" href="{{ url_for('.organization_settings', org_id=current_org.id) }}">Settings</a></li>
|
||||
<li><a class="usa-link{{ org_navigation.is_selected('trial-services') }}" href="{{ url_for('.organization_trial_mode_services', org_id=current_org.id) }}">Trial mode services</a></li>
|
||||
<li><a class="usa-link{{ org_navigation.is_selected('billing') }}" href="{{ url_for('.organization_billing', org_id=current_org.id) }}">Billing</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</nav>
|
||||
15
app/templates/new/components/service_navigation.html
Normal file
15
app/templates/new/components/service_navigation.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<div class="navigation-service margin-top-5 display-flex flex-align-end flex-justify border-bottom padding-bottom-1">
|
||||
{% if current_service.organization_id %}
|
||||
{% if current_user.platform_admin or
|
||||
(current_user.belongs_to_organization(current_service.organization_id) and current_service.live) %}
|
||||
<a href="{{ url_for('.organization_dashboard', org_id=current_service.organization_id) }}" class="usa-link navigation-organization-link">{{ current_service.organization_name }}</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<div class="font-body-2xl text-bold">
|
||||
{{ current_service.name }}
|
||||
{% if not current_service.active %}
|
||||
<span class="navigation-service-name navigation-service-type--suspended">Suspended</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<a href="{{ url_for('main.choose_account') }}" class="usa-link">Switch service</a>
|
||||
</div>
|
||||
16
app/templates/new/components/settings_navigation.html
Normal file
16
app/templates/new/components/settings_navigation.html
Normal file
@@ -0,0 +1,16 @@
|
||||
{% if help %}
|
||||
{% include 'partials/tour.html' %}
|
||||
{% else %}
|
||||
<nav class="nav">
|
||||
<ul class="usa-sidenav">
|
||||
{# {% if current_user.has_permissions() %} #}
|
||||
<li class="usa-sidenav__item"><a class="{{ main_navigation.is_selected('settings') }}"
|
||||
href="{{ url_for('main.service_settings', service_id=current_service.id) }}">General</a></li>
|
||||
<li class="usa-sidenav__item"><a class="{{ main_navigation.is_selected('user-profile') }}"
|
||||
href="{{ url_for('main.user_profile', service_id=current_service.id) }}">User profile</a></li>
|
||||
<li class="usa-sidenav__item"><a class="{{ main_navigation.is_selected('team-members') }}"
|
||||
href="{{ url_for('main.manage_users', service_id=current_service.id) }}">Team members</a></li>
|
||||
{# {% endif %} #}
|
||||
</ul>
|
||||
</nav>
|
||||
{% endif %}
|
||||
@@ -1,4 +1,4 @@
|
||||
{% extends "base.html" %}
|
||||
{% extends "/new/base.html" %}
|
||||
|
||||
{% block per_page_title %}
|
||||
{% block org_page_title %}{% endblock %} – {{ current_org.name }}
|
||||
@@ -17,7 +17,7 @@
|
||||
</div>
|
||||
<div class="grid-row">
|
||||
<div class="grid-col-3">
|
||||
{% include "org_nav.html" %}
|
||||
{% include "/new/components/org_nav.html" %}
|
||||
</div>
|
||||
<div class="grid-col-9">
|
||||
{% block beforeContent %}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{% extends "base.html" %}
|
||||
{% extends "/new/base.html" %}
|
||||
|
||||
{% block per_page_title %}
|
||||
{% block service_page_title %}{% endblock %} – {{ current_service.name }}
|
||||
@@ -7,9 +7,9 @@
|
||||
{% block main %}
|
||||
<div class="grid-container">
|
||||
{% block serviceNavigation %}
|
||||
{% include "service_navigation.html" %}
|
||||
{% include "new/components/service_navigation.html" %}
|
||||
{% endblock %}
|
||||
<!-- The withnav_template can be used to replace the settings_template. when it comes to setting_template and withnav_template, this service_navigation.html is only used in withnav_template and in settings_template, it was not used. That is one out of the two differences between settings template and withnav template. Child templates that extends settings_template, include the block serviceNavigation but leave it empty. Within the app, the only pages settings_template.html is used: manage-users.html, service-settings.html, and user-profile.html -->
|
||||
<!-- The withnav_template can be used to replace the settings_template. When it comes to setting_template and withnav_template, this service_navigation.html on line 10 is only used in withnav_template. In settings_template, it was not used. That is one out of the two differences between settings template and withnav template. Child templates that extends settings_template, include the block serviceNavigation but leave it empty because we don't need to call in service_navigation. Within the app, the only pages settings_template.html is used: manage-users.html, service-settings.html, and user-profile.html -->
|
||||
<div class="grid-row margin-top-5">
|
||||
{% if help %}
|
||||
<div class="grid-col-3">
|
||||
@@ -17,8 +17,8 @@
|
||||
<div class="grid-col-3">
|
||||
{% endif %}
|
||||
{% block sideNavigation %}
|
||||
{% include "main_nav.html" %}
|
||||
<!-- include settings_nav.html for child templates that used settings_template -->
|
||||
{% include "/new/components/main_nav.html" %}
|
||||
<!-- instead of "main_nav.html" include "settings_nav.html" for child templates that extends settings_template -->
|
||||
{% endblock %}
|
||||
</div>
|
||||
{% if help %}
|
||||
|
||||
@@ -14,6 +14,10 @@ This document serves as a glossary for the templates directory structure of the
|
||||
- `head.html`: Template for the site's <head>, included in `base.html`.
|
||||
- `header.html`: Template for the site's header, included in `base.html`.
|
||||
- `footer.html`: Template for the site's footer, included in `base.html`.
|
||||
- `settings_navigation.html`: The settings navigation used in `withnav_template.html` that previously extended `settings_template.html`.
|
||||
- `org_nav.html`: The organization's navigation used solely in `org_template.html`.
|
||||
- `main_nav.html`: The main navigation used in `withnav_template.html`
|
||||
- `service_navigation.html`: The service navigation used in `withnav_template.html`. In withnav_template.html, the `serviceNavigation` block will be left empty in any child templates that previously extended `settings_template.html`.
|
||||
- **/views** (or **/pages**): Individual page templates that use the base layouts, components, and partials to present content.
|
||||
|
||||
### Best Practices
|
||||
@@ -30,9 +34,9 @@ This document serves as a glossary for the templates directory structure of the
|
||||
- withoutnav_template.html Delete
|
||||
- main_template.html Delete
|
||||
- settings_templates.html `withnav_template` can be used to replace `settings_template`.
|
||||
- settings_nav.html (move to /new/navigation directory)
|
||||
- main_nav.html (move to /new/navigation directory)
|
||||
- service_navigation.html (move to /new/navigation directory)
|
||||
- settings_nav.html (move to /components/ directory)
|
||||
- main_nav.html (move to /components/ directory)
|
||||
- service_navigation.html (move to /components/ directory)
|
||||
- org_template, could be under it's own directory called /layout/organization
|
||||
- org_nav.html (move to /new/navigation directory)
|
||||
- org_nav.html (move to /components/ directory)
|
||||
- content_template.html Delete
|
||||
|
||||
@@ -12,18 +12,6 @@
|
||||
|
||||
{% block maincolumn_content %}
|
||||
|
||||
{% if login_gov_enabled %}
|
||||
<div class="grid-row">
|
||||
<div id="countdown-container" class="usa-alert usa-alert--warning width-full margin-bottom-4">
|
||||
<div class="usa-alert__body">
|
||||
<h4 class="usa-alert__heading">Login.gov is required by April 16, 2024</h4>
|
||||
<p class="usa-alert__text">
|
||||
You have <span id="countdown"></span> left to use Login.gov to sign in
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="grid-row margin-bottom-4">
|
||||
<div class="tablet:grid-col-5">
|
||||
{% if again %}
|
||||
@@ -39,22 +27,12 @@
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<h1 class="font-body-2xl margin-bottom-3">Sign in</h1>
|
||||
{% if login_gov_enabled %}
|
||||
<p>You can access your account by signing in with one of the options below:</p>
|
||||
<a class="usa-link usa-button usa-button--outline" href="{{ initial_signin_url }}">Sign in with Login.gov</a>
|
||||
<p class="margin-y-3"><strong>Or:</strong></p>
|
||||
{% endif %}
|
||||
<p>Access your Notify.gov account by signing in with Login.gov:</p>
|
||||
<a class="usa-link usa-button" href="{{ initial_signin_url }}">Sign in with Login.gov</a>
|
||||
{% endif %}
|
||||
|
||||
{% call form_wrapper(autocomplete=True) %}
|
||||
{{ form.email_address(param_extensions={"autocomplete": "email"}) }}
|
||||
{{ form.password(param_extensions={"autocomplete": "current-password"}) }}
|
||||
{{ page_footer("Continue", secondary_link=password_reset_url, secondary_link_text="Forgot your password?") }}
|
||||
{% endcall %}
|
||||
</div>
|
||||
{% if login_gov_enabled %}
|
||||
<div class="tablet:grid-col-6 tablet:grid-offset-1 margin-top-2 padding-y-2 padding-x-4 bg-base-lightest">
|
||||
<h2 class="font-body-lg">Notify.gov is changing the sign-in experience to Login.gov effective<br>April 16, 2024</h2>
|
||||
<h2 class="font-body-lg">Effective April 16, 2024 Notify.gov requires you sign-in through Login.gov</h2>
|
||||
<p>Why are we doing this?</p>
|
||||
<ul class="usa-list">
|
||||
<li><strong>Enhanced security:</strong> Login.gov is really secure and trustworthy</li>
|
||||
@@ -64,12 +42,11 @@
|
||||
<p>What do I need to do?</p>
|
||||
<ul class="usa-list">
|
||||
<li>If you have a Login.gov account, start using it to sign in to Notify today.</li>
|
||||
<li>If you don’t have a Login.gov account, you must create one by April 16, 2024 to continue to access Notify.</li>
|
||||
<li>If you don’t have a Login.gov account, you must create one to continue to access Notify.</li>
|
||||
</ul>
|
||||
<div class="border-bottom border-base-lighter margin-y-4"></div>
|
||||
<a class="usa-link usa-button margin-bottom-3" href="{{ initial_signin_url }}">Create Login.gov account</a>
|
||||
<a class="usa-link usa-button usa-button--outline margin-bottom-3" href="{{ initial_signin_url }}">Create Login.gov account</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -11,7 +11,7 @@ def get_current_financial_year():
|
||||
now = datetime.now(preferred_tz)
|
||||
current_month = int(now.strftime("%-m"))
|
||||
current_year = int(now.strftime("%Y"))
|
||||
return current_year if current_month > 9 else current_year - 1
|
||||
return current_year if current_month < 10 else current_year + 1
|
||||
|
||||
|
||||
def is_less_than_days_ago(date_from_db, number_of_days):
|
||||
|
||||
Reference in New Issue
Block a user