mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-11 09:28:27 -04:00
Merge pull request #2906 from alphagov/auto-service-counts
Automate counting of live services and orgs
This commit is contained in:
@@ -12,7 +12,7 @@ from notifications_utils.international_billing_rates import (
|
||||
)
|
||||
from notifications_utils.template import HTMLEmailTemplate, LetterImageTemplate
|
||||
|
||||
from app import email_branding_client, letter_branding_client
|
||||
from app import email_branding_client, letter_branding_client, status_api_client
|
||||
from app.main import main
|
||||
from app.main.forms import FieldWithNoneOption, SearchByNameForm
|
||||
from app.main.views.sub_navigation_dictionaries import features_nav
|
||||
@@ -21,9 +21,14 @@ from app.utils import AgreementInfo, get_logo_cdn_domain
|
||||
|
||||
@main.route('/')
|
||||
def index():
|
||||
|
||||
if current_user and current_user.is_authenticated:
|
||||
return redirect(url_for('main.choose_account'))
|
||||
return render_template('views/signedout.html')
|
||||
|
||||
return render_template(
|
||||
'views/signedout.html',
|
||||
counts=status_api_client.get_count_of_live_services_and_organisations(),
|
||||
)
|
||||
|
||||
|
||||
@main.route('/robots.txt')
|
||||
|
||||
@@ -262,12 +262,7 @@ def service_switch_live(service_id):
|
||||
)
|
||||
|
||||
if form.validate_on_submit():
|
||||
current_service.update(
|
||||
# TODO This limit should be set depending on the agreement signed by
|
||||
# with Notify.
|
||||
message_limit=250000 if form.enabled.data else 50,
|
||||
restricted=(not form.enabled.data)
|
||||
)
|
||||
current_service.update_status(live=form.enabled.data)
|
||||
return redirect(url_for('.service_settings', service_id=service_id))
|
||||
|
||||
return render_template(
|
||||
|
||||
@@ -72,6 +72,9 @@ class Service():
|
||||
def update(self, **kwargs):
|
||||
return service_api_client.update_service(self.id, **kwargs)
|
||||
|
||||
def update_status(self, live):
|
||||
return service_api_client.update_status(self.id, live=live)
|
||||
|
||||
def switch_permission(self, permission):
|
||||
return self.force_permission(
|
||||
permission,
|
||||
|
||||
@@ -25,6 +25,7 @@ class OrganisationsClient(NotifyAdminAPIClient):
|
||||
return self.get(url="/service/{}/organisation".format(service_id))
|
||||
|
||||
@cache.delete('service-{service_id}')
|
||||
@cache.delete('live-service-and-organisation-counts')
|
||||
def update_service_organisation(self, service_id, org_id):
|
||||
data = {
|
||||
'service_id': service_id
|
||||
|
||||
@@ -98,6 +98,14 @@ class ServiceAPIClient(NotifyAdminAPIClient):
|
||||
endpoint = "/service/{0}".format(service_id)
|
||||
return self.post(endpoint, data)
|
||||
|
||||
@cache.delete('live-service-and-organisation-counts')
|
||||
def update_status(self, service_id, live):
|
||||
return self.update_service(
|
||||
service_id,
|
||||
message_limit=250000 if live else 50,
|
||||
restricted=(not live),
|
||||
)
|
||||
|
||||
# This method is not cached because it calls through to one which is
|
||||
def update_service_with_properties(self, service_id, properties):
|
||||
return self.update_service(service_id, **properties)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
from app.notify_client import NotifyAdminAPIClient
|
||||
from app.notify_client import NotifyAdminAPIClient, cache
|
||||
|
||||
|
||||
class StatusApiClient(NotifyAdminAPIClient):
|
||||
@@ -7,5 +6,9 @@ class StatusApiClient(NotifyAdminAPIClient):
|
||||
def get_status(self, *params):
|
||||
return self.get(url='/_status', *params)
|
||||
|
||||
@cache.set('live-service-and-organisation-counts')
|
||||
def get_count_of_live_services_and_organisations(self):
|
||||
return self.get(url='/_status/live-service-and-organisation-counts')
|
||||
|
||||
|
||||
status_api_client = StatusApiClient()
|
||||
|
||||
@@ -115,17 +115,17 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="product-page-section">
|
||||
<div class="with-keyline bottom-gutter-2">
|
||||
<div class="with-keyline bottom-gutter-2" id="whos-using-notify">
|
||||
<h2>Who’s using GOV.UK Notify</h2>
|
||||
<div class="grid-row bottom-gutter">
|
||||
<div class="column-half">
|
||||
<h3 class="visually-hidden">Services</h3>
|
||||
<div class="product-page-big-number">745</div>
|
||||
<div class="product-page-big-number">{{ counts.services }}</div>
|
||||
services
|
||||
</div>
|
||||
<div class="column-half">
|
||||
<h3 class="visually-hidden">Organisations</h3>
|
||||
<div class="product-page-big-number">233</div>
|
||||
<div class="product-page-big-number">{{ counts.organisations }}</div>
|
||||
organisations
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user