mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 21:49:37 -04:00
notify-admin-529 remove provider view
This commit is contained in:
@@ -105,7 +105,6 @@ from app.notify_client.performance_dashboard_api_client import (
|
||||
performance_dashboard_api_client,
|
||||
)
|
||||
from app.notify_client.platform_stats_api_client import platform_stats_api_client
|
||||
from app.notify_client.provider_client import provider_client
|
||||
from app.notify_client.service_api_client import service_api_client
|
||||
from app.notify_client.status_api_client import status_api_client
|
||||
from app.notify_client.template_folder_api_client import template_folder_api_client
|
||||
@@ -191,7 +190,6 @@ def create_app(application):
|
||||
organizations_client,
|
||||
performance_dashboard_api_client,
|
||||
platform_stats_api_client,
|
||||
provider_client,
|
||||
service_api_client,
|
||||
status_api_client,
|
||||
template_folder_api_client,
|
||||
|
||||
@@ -26,7 +26,6 @@ from app.main.views import ( # noqa isort:skip
|
||||
performance,
|
||||
platform_admin,
|
||||
pricing,
|
||||
providers,
|
||||
register,
|
||||
security_policy,
|
||||
send,
|
||||
|
||||
@@ -1440,52 +1440,6 @@ class EstimateUsageForm(StripWhitespaceForm):
|
||||
return super().validate(*args, **kwargs)
|
||||
|
||||
|
||||
class AdminProviderRatioForm(Form):
|
||||
def __init__(self, providers):
|
||||
self._providers = providers
|
||||
|
||||
# hack: https://github.com/wtforms/wtforms/issues/736
|
||||
self._unbound_fields = [
|
||||
(
|
||||
provider["identifier"],
|
||||
GovukIntegerField(
|
||||
f"{provider['display_name']} (%)",
|
||||
validators=[
|
||||
validators.NumberRange(
|
||||
min=0, max=100, message="Must be between 0 and 100"
|
||||
)
|
||||
],
|
||||
param_extensions={
|
||||
"classes": "width-8",
|
||||
},
|
||||
),
|
||||
)
|
||||
for provider in providers
|
||||
]
|
||||
|
||||
super().__init__(
|
||||
data={
|
||||
provider["identifier"]: provider["priority"] for provider in providers
|
||||
}
|
||||
)
|
||||
|
||||
def validate(self, extra_validators=None):
|
||||
if not super().validate(extra_validators):
|
||||
return False
|
||||
|
||||
total = sum(
|
||||
getattr(self, provider["identifier"]).data for provider in self._providers
|
||||
)
|
||||
|
||||
if total == 100:
|
||||
return True
|
||||
|
||||
for provider in self._providers:
|
||||
getattr(self, provider["identifier"]).errors += ["Must add up to 100%"]
|
||||
|
||||
return False
|
||||
|
||||
|
||||
class ServiceContactDetailsForm(StripWhitespaceForm):
|
||||
contact_details_type = RadioField(
|
||||
"Type of contact details",
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
from datetime import datetime
|
||||
|
||||
from flask import render_template, url_for
|
||||
from werkzeug.utils import redirect
|
||||
|
||||
from app import provider_client
|
||||
from app.main import main
|
||||
from app.main.forms import AdminProviderRatioForm
|
||||
from app.utils.user import user_is_platform_admin
|
||||
|
||||
PROVIDER_PRIORITY_MEANING_SWITCHOVER = datetime(2019, 11, 29, 11, 0).isoformat()
|
||||
|
||||
|
||||
@main.route("/providers")
|
||||
@user_is_platform_admin
|
||||
def view_providers():
|
||||
providers = provider_client.get_all_providers()["provider_details"]
|
||||
domestic_email_providers, domestic_sms_providers, intl_sms_providers = [], [], []
|
||||
for provider in providers:
|
||||
if provider["notification_type"] == "sms":
|
||||
domestic_sms_providers.append(provider)
|
||||
if provider.get("supports_international", None):
|
||||
intl_sms_providers.append(provider)
|
||||
elif provider["notification_type"] == "email":
|
||||
domestic_email_providers.append(provider)
|
||||
|
||||
add_monthly_traffic(domestic_sms_providers)
|
||||
|
||||
return render_template(
|
||||
"views/providers/providers.html",
|
||||
email_providers=domestic_email_providers,
|
||||
domestic_sms_providers=domestic_sms_providers,
|
||||
intl_sms_providers=intl_sms_providers,
|
||||
)
|
||||
|
||||
|
||||
def add_monthly_traffic(domestic_sms_providers):
|
||||
total_sms_sent = sum(
|
||||
provider["current_month_billable_sms"] for provider in domestic_sms_providers
|
||||
)
|
||||
|
||||
for provider in domestic_sms_providers:
|
||||
percentage = (
|
||||
(provider["current_month_billable_sms"] / total_sms_sent * 100)
|
||||
if total_sms_sent
|
||||
else 0
|
||||
)
|
||||
provider["monthly_traffic"] = round(percentage)
|
||||
|
||||
|
||||
@main.route("/provider/edit-sms-provider-ratio", methods=["GET", "POST"])
|
||||
@user_is_platform_admin
|
||||
def edit_sms_provider_ratio():
|
||||
providers = [
|
||||
provider
|
||||
for provider in provider_client.get_all_providers()["provider_details"]
|
||||
if provider["notification_type"] == "sms" and provider["active"]
|
||||
]
|
||||
|
||||
form = AdminProviderRatioForm(providers)
|
||||
|
||||
if form.validate_on_submit():
|
||||
for provider in providers:
|
||||
field = getattr(form, provider["identifier"])
|
||||
provider_client.update_provider(provider["id"], field.data)
|
||||
return redirect(url_for(".view_providers"))
|
||||
|
||||
return render_template(
|
||||
"views/providers/edit-sms-provider-ratio.html", form=form, providers=providers
|
||||
)
|
||||
|
||||
|
||||
@main.route("/provider/<uuid:provider_id>")
|
||||
@user_is_platform_admin
|
||||
def view_provider(provider_id):
|
||||
versions = provider_client.get_provider_versions(provider_id)
|
||||
return render_template(
|
||||
"views/providers/provider.html", provider_versions=versions["data"]
|
||||
)
|
||||
@@ -165,7 +165,6 @@ class HeaderNavigation(Navigation):
|
||||
"change_user_auth",
|
||||
"clear_cache",
|
||||
"create_email_branding",
|
||||
"edit_sms_provider_ratio",
|
||||
"email_branding",
|
||||
"find_services_by_name",
|
||||
"find_users_by_email",
|
||||
@@ -186,8 +185,6 @@ class HeaderNavigation(Navigation):
|
||||
"trial_services",
|
||||
"update_email_branding",
|
||||
"user_information",
|
||||
"view_provider",
|
||||
"view_providers",
|
||||
},
|
||||
"sign-in": {
|
||||
"revalidate_email_sent",
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
from app.notify_client import NotifyAdminAPIClient, _attach_current_user
|
||||
|
||||
|
||||
class ProviderClient(NotifyAdminAPIClient):
|
||||
def get_all_providers(self):
|
||||
return self.get(url="/provider-details")
|
||||
|
||||
def get_provider_by_id(self, provider_id):
|
||||
return self.get(url="/provider-details/{}".format(provider_id))
|
||||
|
||||
def get_provider_versions(self, provider_id):
|
||||
return self.get(url="/provider-details/{}/versions".format(provider_id))
|
||||
|
||||
def update_provider(self, provider_id, priority):
|
||||
data = {"priority": priority}
|
||||
data = _attach_current_user(data)
|
||||
return self.post(url="/provider-details/{}".format(provider_id), data=data)
|
||||
|
||||
|
||||
provider_client = ProviderClient()
|
||||
@@ -19,12 +19,12 @@
|
||||
<div class="tablet:grid-col-3 margin-top-4">
|
||||
<nav class="navigation">
|
||||
<ul class="usa-sidenav">
|
||||
|
||||
{% for link_text, url in [
|
||||
('Summary', ('main.platform_admin')),
|
||||
('Live services', ('main.live_services')),
|
||||
('Trial mode services', ('main.trial_services')),
|
||||
('Organizations', ('main.organizations')),
|
||||
('Providers', ('main.view_providers')),
|
||||
('Reports', ('main.platform_admin_reports')),
|
||||
('Email branding', ('main.email_branding')),
|
||||
('Inbound SMS numbers', ('main.inbound_sms_admin')),
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
{% extends "views/platform-admin/_base_template.html" %}
|
||||
{% from "components/page-header.html" import page_header %}
|
||||
{% from "components/page-footer.html" import page_footer %}
|
||||
{% from "components/form.html" import form_wrapper %}
|
||||
|
||||
{% block per_page_title %}
|
||||
Edit SMS provider priorities
|
||||
{% endblock %}
|
||||
|
||||
{% block platform_admin_content %}
|
||||
|
||||
{{ page_header('Edit SMS provider priorities') }}
|
||||
|
||||
<p>
|
||||
If you change one priority you will need to change the others so they add up to 100%.
|
||||
</p>
|
||||
|
||||
{% call form_wrapper() %}
|
||||
{% for field in form %}
|
||||
{{ field }}
|
||||
{% endfor %}
|
||||
|
||||
{{ page_footer('Save') }}
|
||||
{% endcall %}
|
||||
{% endblock %}
|
||||
@@ -1,58 +0,0 @@
|
||||
{% extends "withoutnav_template.html" %}
|
||||
{% from "components/table.html" import list_table, field, text_field, link_field, right_aligned_field_heading, hidden_field_heading %}
|
||||
{% from "components/page-header.html" import page_header %}
|
||||
{% from "components/page-footer.html" import page_footer %}
|
||||
{% from "components/components/back-link/macro.njk" import usaBackLink %}
|
||||
|
||||
{% block per_page_title %}
|
||||
{{ provider_versions[0].display_name }}
|
||||
{% endblock %}
|
||||
|
||||
{% block backLink %}
|
||||
{{ usaBackLink({ "href": url_for('main.view_providers') }) }}
|
||||
{% endblock %}
|
||||
|
||||
{% block maincolumn_content %}
|
||||
|
||||
<div class="grid-row">
|
||||
<div class="grid-col-8">
|
||||
|
||||
{{ page_header(provider_versions[0].display_name) }}
|
||||
|
||||
<p>
|
||||
Only showing the latest 100 versions.
|
||||
</p>
|
||||
|
||||
{% call(item, row_number) list_table(
|
||||
provider_versions,
|
||||
caption='',
|
||||
caption_visible=False,
|
||||
empty_message='No history for this provider',
|
||||
field_headings=['Version', 'Last Updated', 'Updated By', 'Priority', 'Active'],
|
||||
field_headings_visible=True
|
||||
) %}
|
||||
|
||||
{{ text_field(item.version) }}
|
||||
|
||||
{% if item.updated_at %}
|
||||
{{ text_field(item.updated_at|format_datetime_short) }}
|
||||
{% else %}
|
||||
{{ text_field('None') }}
|
||||
{% endif %}
|
||||
|
||||
{% if item.created_by %}
|
||||
{{ text_field(item.created_by.name) }}
|
||||
{% else %}
|
||||
{{ text_field('None') }}
|
||||
{% endif %}
|
||||
|
||||
{{ text_field(item.priority) }}
|
||||
|
||||
{{ text_field(item.active) }}
|
||||
|
||||
{% endcall %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
@@ -1,90 +0,0 @@
|
||||
{% extends "views/platform-admin/_base_template.html" %}
|
||||
{% from "components/table.html" import list_table, field, text_field, link_field, right_aligned_field_heading, hidden_field_heading, optional_text_field %}
|
||||
{% from "components/show-more.html" import show_more %}
|
||||
|
||||
{% block per_page_title %}
|
||||
Providers
|
||||
{% endblock %}
|
||||
|
||||
{% block platform_admin_content %}
|
||||
|
||||
<h1 class="font-body-2xl">Providers</h1>
|
||||
|
||||
<h2 class="font-body-lg">SMS</h2>
|
||||
|
||||
<a class="usa-link" href="{{ url_for('main.edit_sms_provider_ratio') }}">Change priority</a>
|
||||
|
||||
{% call(item, row_number) list_table(
|
||||
domestic_sms_providers,
|
||||
caption="Domestic SMS providers",
|
||||
caption_visible=False,
|
||||
empty_message='No domestic sms providers',
|
||||
field_headings=['Provider', 'Priority', '% monthly traffic', 'Active', 'Last Updated', 'Updated By'],
|
||||
field_headings_visible=True
|
||||
) %}
|
||||
|
||||
{{ link_field(item.display_name, url_for('main.view_provider', provider_id=item.id)) }}
|
||||
|
||||
{{ optional_text_field(item.priority if item.active, default='None') }}
|
||||
|
||||
{{ text_field(item.monthly_traffic) }}
|
||||
|
||||
{{ text_field(item.active) }}
|
||||
|
||||
{{ optional_text_field(
|
||||
item.updated_at|format_datetime_short if item.updated_at,
|
||||
default='None'
|
||||
) }}
|
||||
|
||||
{{ optional_text_field(item.created_by_name, default='None') }}
|
||||
|
||||
{% endcall %}
|
||||
|
||||
<h2 class="font-body-lg">Email</h2>
|
||||
|
||||
{% call(item, row_number) list_table(
|
||||
email_providers,
|
||||
caption="Email providers",
|
||||
caption_visible=False,
|
||||
empty_message='No email providers',
|
||||
field_headings=['Provider', 'Active', 'Last Updated', 'Updated By'],
|
||||
field_headings_visible=True
|
||||
) %}
|
||||
|
||||
{{ link_field(item.display_name, url_for('main.view_provider', provider_id=item.id)) }}
|
||||
|
||||
{{ text_field(item.active) }}
|
||||
|
||||
{{ optional_text_field(
|
||||
item.updated_at|format_datetime_short if item.updated_at,
|
||||
default='None'
|
||||
) }}
|
||||
|
||||
{{ optional_text_field(item.created_by_name, default='None') }}
|
||||
{% endcall %}
|
||||
|
||||
<h2 class="font-body-lg">International SMS Providers</h2>
|
||||
|
||||
{% call(item, row_number) list_table(
|
||||
intl_sms_providers,
|
||||
caption="International SMS providers",
|
||||
caption_visible=False,
|
||||
empty_message='No international sms providers',
|
||||
field_headings=['Provider', 'Active', 'Last Updated', 'Updated By'],
|
||||
field_headings_visible=True
|
||||
) %}
|
||||
|
||||
{{ link_field(item.display_name, url_for('main.view_provider', provider_id=item.id)) }}
|
||||
|
||||
{{ text_field(item.active) }}
|
||||
|
||||
{{ optional_text_field(
|
||||
item.updated_at|format_datetime_short if item.updated_at,
|
||||
default='None'
|
||||
) }}
|
||||
|
||||
{{ optional_text_field(item.created_by_name, default='None') }}
|
||||
|
||||
{% endcall %}
|
||||
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user