mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-06-19 04:36:32 -04:00
Merge pull request #3643 from alphagov/broadcast-org
move service to broadcast org when broadcasting is enabled
This commit is contained in:
@@ -84,6 +84,8 @@ class Config(object):
|
||||
ASSET_DOMAIN = ''
|
||||
ASSET_PATH = '/static/'
|
||||
|
||||
BROADCAST_ORGANISATION_ID = os.environ.get('BROADCAST_ORGANISATION_ID')
|
||||
|
||||
NOTIFY_SERVICE_ID = 'd6aa2c68-a2d9-4437-ab19-3ae8eb202553'
|
||||
|
||||
|
||||
@@ -177,6 +179,8 @@ class Live(Config):
|
||||
ASSET_DOMAIN = 'static.notifications.service.gov.uk'
|
||||
ASSET_PATH = 'https://static.notifications.service.gov.uk/'
|
||||
|
||||
BROADCAST_ORGANISATION_ID = '38e4bf69-93b0-445d-acee-53ea53fe02df'
|
||||
|
||||
|
||||
class CloudFoundryConfig(Config):
|
||||
pass
|
||||
|
||||
@@ -100,9 +100,16 @@ class Service(JSONModel):
|
||||
)
|
||||
|
||||
def force_broadcast_permission_on(self):
|
||||
return self.update_permissions(
|
||||
ret = self.update_permissions(
|
||||
set(self.permissions) - {'email', 'sms', 'letter'} | {'broadcast'}
|
||||
)
|
||||
broadcast_org_id = current_app.config['BROADCAST_ORGANISATION_ID']
|
||||
if broadcast_org_id:
|
||||
organisations_client.update_service_organisation(
|
||||
service_id=self.id,
|
||||
org_id=broadcast_org_id
|
||||
)
|
||||
return ret
|
||||
|
||||
def update_permissions(self, permissions):
|
||||
return self.update(permissions=list(permissions))
|
||||
|
||||
@@ -4,7 +4,7 @@ import pytest
|
||||
from flask import url_for
|
||||
|
||||
from app.main.views.service_settings import PLATFORM_ADMIN_SERVICE_PERMISSIONS
|
||||
from tests.conftest import normalize_spaces
|
||||
from tests.conftest import SERVICE_ONE_ID, normalize_spaces, set_config
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -215,3 +215,38 @@ def test_normal_user_doesnt_see_any_platform_admin_settings(
|
||||
|
||||
for permission in platform_admin_settings:
|
||||
assert permission not in page
|
||||
|
||||
|
||||
def test_setting_broadcast_sets_organisation_if_config_value_set(
|
||||
mock_update_service_organisation,
|
||||
mock_update_service,
|
||||
platform_admin_client,
|
||||
fake_uuid,
|
||||
):
|
||||
with set_config(platform_admin_client.application, 'BROADCAST_ORGANISATION_ID', fake_uuid):
|
||||
response = platform_admin_client.post(
|
||||
url_for('main.service_set_permission', service_id=SERVICE_ONE_ID, permission='broadcast'),
|
||||
data={'enabled': True}
|
||||
)
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for('main.service_settings', service_id=SERVICE_ONE_ID, _external=True)
|
||||
|
||||
mock_update_service_organisation.assert_called_once_with(
|
||||
service_id=SERVICE_ONE_ID,
|
||||
org_id=fake_uuid
|
||||
)
|
||||
|
||||
|
||||
def test_setting_broadcast_doesnt_set_organisation_if_config_value_not_set(
|
||||
mock_update_service_organisation,
|
||||
mock_update_service,
|
||||
platform_admin_client,
|
||||
):
|
||||
with set_config(platform_admin_client.application, 'BROADCAST_ORGANISATION_ID', None):
|
||||
response = platform_admin_client.post(
|
||||
url_for('main.service_set_permission', service_id=SERVICE_ONE_ID, permission='broadcast'),
|
||||
data={'enabled': True}
|
||||
)
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for('main.service_settings', service_id=SERVICE_ONE_ID, _external=True)
|
||||
assert not mock_update_service_organisation.called
|
||||
|
||||
@@ -3360,7 +3360,7 @@ def mock_get_service_organisation(
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_update_service_organisation(mocker):
|
||||
def _update_service_organisation(service_id, organisation_id):
|
||||
def _update_service_organisation(service_id, org_id):
|
||||
return
|
||||
|
||||
return mocker.patch(
|
||||
@@ -3504,7 +3504,7 @@ def mock_organisation_name_is_unique(mocker):
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_update_organisation(mocker):
|
||||
def _update_org(organisation_id, **kwargs):
|
||||
def _update_org(org, **kwargs):
|
||||
return
|
||||
|
||||
return mocker.patch('app.organisations_client.update_organisation', side_effect=_update_org)
|
||||
|
||||
Reference in New Issue
Block a user