mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-04 05:31:44 -04:00
Merge branch 'master' of https://github.com/alphagov/notifications-admin into vb-platform-admin-admin
This commit is contained in:
@@ -87,6 +87,7 @@ class Config(object):
|
||||
r"bl\.uk",
|
||||
r"stfc\.ac\.uk",
|
||||
r"wmfs\.net",
|
||||
r"bbsrc\.ac\.uk",
|
||||
]
|
||||
|
||||
LOGO_UPLOAD_BUCKET_NAME = 'public-logos-local'
|
||||
|
||||
@@ -511,7 +511,8 @@ class ServiceBrandingOrg(Form):
|
||||
choices=[
|
||||
('govuk', 'GOV.UK only'),
|
||||
('both', 'GOV.UK and organisation'),
|
||||
('org', 'Organisation only')
|
||||
('org', 'Organisation only'),
|
||||
('org_banner', 'Organisation banner')
|
||||
],
|
||||
validators=[
|
||||
DataRequired()
|
||||
|
||||
@@ -13,11 +13,7 @@ from app.notify_client.api_key_api_client import KEY_TYPE_NORMAL, KEY_TYPE_TEST,
|
||||
def api_integration(service_id):
|
||||
return render_template(
|
||||
'views/api/index.html',
|
||||
api_notifications=notification_api_client.get_notifications_for_service(
|
||||
service_id=service_id,
|
||||
include_jobs=False,
|
||||
include_from_test_key=True
|
||||
)
|
||||
api_notifications=notification_api_client.get_api_notifications_for_service(service_id)
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -71,7 +71,9 @@ def manage_org(logo=None):
|
||||
return redirect(
|
||||
url_for('.manage_org', logo=upload_filename))
|
||||
|
||||
logo = persist_logo(logo, session["user_id"])
|
||||
if logo:
|
||||
logo = persist_logo(logo, session["user_id"])
|
||||
|
||||
delete_temp_files_created_by(session["user_id"])
|
||||
|
||||
if org:
|
||||
|
||||
@@ -66,3 +66,14 @@ class NotificationApiClient(NotifyAdminAPIClient):
|
||||
|
||||
def get_notification(self, service_id, notification_id):
|
||||
return self.get(url='/service/{}/notifications/{}'.format(service_id, notification_id))
|
||||
|
||||
def get_api_notifications_for_service(self, service_id):
|
||||
ret = self.get_notifications_for_service(service_id, include_jobs=False, include_from_test_key=True)
|
||||
return self.map_letters_to_accepted(ret)
|
||||
|
||||
@staticmethod
|
||||
def map_letters_to_accepted(notifications):
|
||||
for notification in notifications['notifications']:
|
||||
if notification['notification_type'] == 'letter' and notification['status'] in ('created', 'sending'):
|
||||
notification['status'] = 'accepted'
|
||||
return notifications
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
secondary_link=False,
|
||||
secondary_link_text=None,
|
||||
delete_link=False,
|
||||
delete_link_text="delete",
|
||||
button_disabled=False
|
||||
delete_link_text="delete"
|
||||
) %}
|
||||
<div class="page-footer">
|
||||
{% if button_text %}
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
|
||||
<input type="submit" class="button{% if destructive %}-destructive{% endif %}" value="{{ button_text }}"{% if button_disabled %} disabled{% endif %}/>
|
||||
<input type="submit" class="button{% if destructive %}-destructive{% endif %}" value="{{ button_text }}" />
|
||||
{% endif %}
|
||||
{% if back_link %}
|
||||
<a class="page-footer-back-link" href="{{ back_link }}">{{ back_link_text }}</a>
|
||||
|
||||
@@ -26,14 +26,13 @@
|
||||
<form method="post">
|
||||
<div class="form-group">
|
||||
<div style='margin-top:15px;'>{{textbox(form.name)}}</div>
|
||||
<div>{{textbox(form.colour, width='1-4')}}
|
||||
<div>{{textbox(form.colour, width='1-4')}}
|
||||
<span id='colour_span' style="background: {{ organisation.colour }}; {% if not organisation.colour %}visibility:hidden; {% endif %}border:1px black solid; width: 3px; height: 25px;position:absolute;margin-top:138px;margin-left:135px;display:block;"></span>
|
||||
</div>
|
||||
{{ page_footer(
|
||||
'Save',
|
||||
back_link=url_for('.organisations', organisation_id=organisation.id if organisation else 'None'),
|
||||
back_link_text='Back to organisation selection',
|
||||
button_disabled=True if not logo else False
|
||||
) }}
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -187,6 +187,8 @@
|
||||
GOV.UK and {{ organisation.name if organisation else None }}
|
||||
{% elif current_service.branding == 'org' %}
|
||||
Only {{ organisation.name if organisation else None }}
|
||||
{% elif current_service.branding == 'org_banner' %}
|
||||
Only {{ organisation.name if organisation else None }} banner
|
||||
{% endif %}
|
||||
{% endcall %}
|
||||
{{ edit_field('Change', url_for('.service_set_branding_and_org', service_id=current_service.id)) }}
|
||||
|
||||
@@ -117,12 +117,12 @@
|
||||
<div class="grid-row bottom-gutter">
|
||||
<div class="column-half">
|
||||
<h3 class="visually-hidden">Services</h3>
|
||||
<div class="product-page-big-number">77</div>
|
||||
<div class="product-page-big-number">79</div>
|
||||
services
|
||||
</div>
|
||||
<div class="column-half">
|
||||
<h3 class="visually-hidden">Departments</h3>
|
||||
<div class="product-page-big-number">37</div>
|
||||
<div class="product-page-big-number">38</div>
|
||||
departments
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -23,4 +23,4 @@ notifications-python-client==4.4.0
|
||||
awscli>=1.11,<1.12
|
||||
awscli-cwlogs>=1.4,<1.5
|
||||
|
||||
git+https://github.com/alphagov/notifications-utils.git@21.0.0#egg=notifications-utils==21.0.0
|
||||
git+https://github.com/alphagov/notifications-utils.git@21.2.0#egg=notifications-utils==21.2.0
|
||||
|
||||
@@ -266,6 +266,7 @@ def notification_json(
|
||||
'service': service_id,
|
||||
'template_version': template['version'],
|
||||
'personalisation': personalisation or {},
|
||||
'notification_type': 'sms',
|
||||
} for i in range(rows)],
|
||||
'total': rows,
|
||||
'page_size': 50,
|
||||
@@ -281,7 +282,8 @@ def single_notification_json(
|
||||
status=None,
|
||||
sent_at=None,
|
||||
created_at=None,
|
||||
updated_at=None
|
||||
updated_at=None,
|
||||
notification_type='sms'
|
||||
):
|
||||
if template is None:
|
||||
template = template_json(service_id, str(generate_uuid()))
|
||||
@@ -310,7 +312,7 @@ def single_notification_json(
|
||||
'id': '29441662-17ce-4ffe-9502-fcaed73b2826',
|
||||
'template': template,
|
||||
'job_row_number': 0,
|
||||
'notification_type': 'sms',
|
||||
'notification_type': notification_type,
|
||||
'api_key': None,
|
||||
'job': job_payload,
|
||||
'sent_by': 'mmg'
|
||||
|
||||
@@ -96,6 +96,7 @@ def _gen_mock_field(x):
|
||||
'test@bl.uk',
|
||||
'test@stfc.ac.uk',
|
||||
'test@wmfs.net',
|
||||
'test@bbsrc.ac.uk',
|
||||
])
|
||||
def test_valid_list_of_white_list_email_domains(
|
||||
client,
|
||||
|
||||
@@ -113,20 +113,11 @@ def test_manage_orgs_shows_correct_org_info(request_get_manage_org_with_org):
|
||||
|
||||
|
||||
def test_manage_orgs_does_not_show_data_for_new_org(request_get_manage_org_without_org):
|
||||
assert request_get_manage_org_without_org.select_one('div.page-footer input.button').has_attr('disabled')
|
||||
assert request_get_manage_org_without_org.select_one('#logo-img > img') is None
|
||||
assert request_get_manage_org_without_org.select_one('#name').attrs.get('value') == ''
|
||||
assert request_get_manage_org_without_org.select_one('#colour').attrs.get('value') == ''
|
||||
|
||||
|
||||
def test_save_is_enabled_when_logo_is_set(request_get_manage_org_with_org):
|
||||
assert request_get_manage_org_with_org.select_one('div.page-footer input.button').has_attr('disabled') is False
|
||||
|
||||
|
||||
def test_save_is_disabled_when_logo_is_not_set(request_get_manage_org_without_org):
|
||||
assert request_get_manage_org_without_org.select_one('div.page-footer input.button').has_attr('disabled')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def request_post_manage_org_redirect(logged_in_platform_admin_client, mocker, fake_uuid):
|
||||
with logged_in_platform_admin_client.session_transaction() as session:
|
||||
@@ -262,3 +253,29 @@ def test_create_new_organisation_when_organisation_saved(logged_in_platform_admi
|
||||
name=new_org['name'],
|
||||
colour=new_org['colour']
|
||||
)
|
||||
|
||||
|
||||
def test_create_new_organisation_without_logo(logged_in_platform_admin_client, mocker, fake_uuid):
|
||||
|
||||
new_org = {'logo': None, 'colour': 'red', 'name': 'new name'}
|
||||
|
||||
mocked_new_org = mocker.patch('app.organisations_client.create_organisation')
|
||||
mock_persist = mocker.patch('app.main.views.organisations.persist_logo')
|
||||
mocker.patch('app.main.views.organisations.delete_temp_files_created_by')
|
||||
|
||||
logged_in_platform_admin_client.post(
|
||||
url_for('.manage_org'),
|
||||
content_type='multipart/form-data',
|
||||
data={
|
||||
'colour': new_org['colour'],
|
||||
'name': new_org['name'],
|
||||
}
|
||||
)
|
||||
|
||||
assert mocked_new_org.called
|
||||
assert mocked_new_org.call_args == call(
|
||||
logo=new_org['logo'],
|
||||
name=new_org['name'],
|
||||
colour=new_org['colour']
|
||||
)
|
||||
assert mock_persist.call_args_list == []
|
||||
|
||||
@@ -922,10 +922,12 @@ def test_should_show_branding(
|
||||
assert page.find('input', attrs={"id": "branding_type-0"})['value'] == 'govuk'
|
||||
assert page.find('input', attrs={"id": "branding_type-1"})['value'] == 'both'
|
||||
assert page.find('input', attrs={"id": "branding_type-2"})['value'] == 'org'
|
||||
assert page.find('input', attrs={"id": "branding_type-3"})['value'] == 'org_banner'
|
||||
|
||||
assert 'checked' in page.find('input', attrs={"id": "branding_type-0"}).attrs
|
||||
assert 'checked' not in page.find('input', attrs={"id": "branding_type-1"}).attrs
|
||||
assert 'checked' not in page.find('input', attrs={"id": "branding_type-2"}).attrs
|
||||
assert 'checked' not in page.find('input', attrs={"id": "branding_type-3"}).attrs
|
||||
|
||||
app.organisations_client.get_organisations.assert_called_once_with()
|
||||
app.service_api_client.get_service.assert_called_once_with(service_one['id'])
|
||||
@@ -945,10 +947,12 @@ def test_should_show_organisations(
|
||||
assert page.find('input', attrs={"id": "branding_type-0"})['value'] == 'govuk'
|
||||
assert page.find('input', attrs={"id": "branding_type-1"})['value'] == 'both'
|
||||
assert page.find('input', attrs={"id": "branding_type-2"})['value'] == 'org'
|
||||
assert page.find('input', attrs={"id": "branding_type-3"})['value'] == 'org_banner'
|
||||
|
||||
assert 'checked' in page.find('input', attrs={"id": "branding_type-0"}).attrs
|
||||
assert 'checked' not in page.find('input', attrs={"id": "branding_type-1"}).attrs
|
||||
assert 'checked' not in page.find('input', attrs={"id": "branding_type-2"}).attrs
|
||||
assert 'checked' not in page.find('input', attrs={"id": "branding_type-3"}).attrs
|
||||
|
||||
app.organisations_client.get_organisations.assert_called_once_with()
|
||||
app.service_api_client.get_service.assert_called_once_with(service_one['id'])
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
|
||||
from app.notify_client.notification_api_client import NotificationApiClient
|
||||
|
||||
from tests import single_notification_json, notification_json
|
||||
|
||||
|
||||
@pytest.mark.parametrize("arguments,expected_call", [
|
||||
(
|
||||
@@ -55,3 +60,23 @@ def test_get_notification(mocker):
|
||||
mock_get.assert_called_once_with(
|
||||
url='/service/foo/notifications/bar'
|
||||
)
|
||||
|
||||
|
||||
def test_get_api_notifications_changes_letter_statuses(mocker):
|
||||
service_id = str(uuid.uuid4())
|
||||
sms_notification = single_notification_json(service_id, notification_type='sms', status='created')
|
||||
email_notification = single_notification_json(service_id, notification_type='email', status='created')
|
||||
letter_notification = single_notification_json(service_id, notification_type='letter', status='created')
|
||||
notis = notification_json(service_id=service_id, rows=0)
|
||||
notis['notifications'] = [sms_notification, email_notification, letter_notification]
|
||||
|
||||
mock_post = mocker.patch('app.notify_client.notification_api_client.NotificationApiClient.get', return_value=notis)
|
||||
|
||||
ret = NotificationApiClient().get_api_notifications_for_service(service_id)
|
||||
|
||||
assert ret['notifications'][0]['notification_type'] == 'sms'
|
||||
assert ret['notifications'][1]['notification_type'] == 'email'
|
||||
assert ret['notifications'][2]['notification_type'] == 'letter'
|
||||
assert ret['notifications'][0]['status'] == 'created'
|
||||
assert ret['notifications'][1]['status'] == 'created'
|
||||
assert ret['notifications'][2]['status'] == 'accepted'
|
||||
|
||||
Reference in New Issue
Block a user