mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-06 17:28:24 -04:00
add front end for download all users
This commit is contained in:
@@ -3,7 +3,7 @@ import json
|
|||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from flask import abort, flash, render_template, request, url_for
|
from flask import Response, abort, flash, render_template, request, send_file, url_for
|
||||||
from notifications_python_client.errors import HTTPError
|
from notifications_python_client.errors import HTTPError
|
||||||
|
|
||||||
from app import (
|
from app import (
|
||||||
@@ -70,6 +70,29 @@ def platform_admin():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@main.route("/platform-admin/download-all-users")
|
||||||
|
@user_is_platform_admin
|
||||||
|
def download_all_users():
|
||||||
|
|
||||||
|
# Create a CSV string from the user data
|
||||||
|
csv_data = "Name,Email Address,Mobile Number,Service\n"
|
||||||
|
users = user_api_client.get_all_users_detailed()
|
||||||
|
|
||||||
|
if len(users) == 0:
|
||||||
|
return "No data to download."
|
||||||
|
users = json.loads(users)
|
||||||
|
for user in users:
|
||||||
|
if user["name"].startswith("e2e"):
|
||||||
|
continue
|
||||||
|
csv_data += f"{user['name']},{user['email_address']},{user['mobile_number']},{user['service']}\n"
|
||||||
|
|
||||||
|
# Create a direct download response with the CSV data and appropriate headers
|
||||||
|
response = Response(csv_data, content_type="text/csv")
|
||||||
|
response.headers["Content-Disposition"] = "attachment; filename=users.csv"
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
def is_over_threshold(number, total, threshold):
|
def is_over_threshold(number, total, threshold):
|
||||||
percentage = number / total * 100 if total else 0
|
percentage = number / total * 100 if total else 0
|
||||||
return percentage > threshold
|
return percentage > threshold
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ class HeaderNavigation(Navigation):
|
|||||||
"get_billing_report",
|
"get_billing_report",
|
||||||
"get_users_report",
|
"get_users_report",
|
||||||
"get_daily_volumes",
|
"get_daily_volumes",
|
||||||
|
"download_all_users",
|
||||||
"get_daily_sms_provider_volumes",
|
"get_daily_sms_provider_volumes",
|
||||||
"get_volumes_by_service",
|
"get_volumes_by_service",
|
||||||
"organizations",
|
"organizations",
|
||||||
|
|||||||
@@ -157,6 +157,10 @@ class UserApiClient(NotifyAdminAPIClient):
|
|||||||
endpoint = "/user"
|
endpoint = "/user"
|
||||||
return self.get(endpoint)["data"]
|
return self.get(endpoint)["data"]
|
||||||
|
|
||||||
|
def get_all_users_detailed(self):
|
||||||
|
endpoint = "/user/report-all-users"
|
||||||
|
return self.get(endpoint)["data"]
|
||||||
|
|
||||||
@cache.delete("service-{service_id}")
|
@cache.delete("service-{service_id}")
|
||||||
@cache.delete("service-{service_id}-template-folders")
|
@cache.delete("service-{service_id}-template-folders")
|
||||||
@cache.delete("user-{user_id}")
|
@cache.delete("user-{user_id}")
|
||||||
|
|||||||
@@ -31,4 +31,8 @@
|
|||||||
<p>
|
<p>
|
||||||
<a class="usa-link" href="{{ url_for('main.get_users_report') }}">Users Report</a>
|
<a class="usa-link" href="{{ url_for('main.get_users_report') }}">Users Report</a>
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
<a class="usa-link" href="{{ url_for('main.download_all_users') }}">Download All Users</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user