mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-09 12:29:51 -04:00
Merge branch 'master' of https://github.com/alphagov/notifications-api into vb-callback-receipt-1
This commit is contained in:
@@ -172,6 +172,7 @@ def dao_create_service(service, user, service_id=None, service_permissions=None)
|
|||||||
service.id = service_id or uuid.uuid4() # must be set now so version history model can use same id
|
service.id = service_id or uuid.uuid4() # must be set now so version history model can use same id
|
||||||
service.active = True
|
service.active = True
|
||||||
service.research_mode = False
|
service.research_mode = False
|
||||||
|
service.crown = service.organisation_type == 'central'
|
||||||
|
|
||||||
for permission in service_permissions:
|
for permission in service_permissions:
|
||||||
service_permission = ServicePermission(service_id=service.id, permission=permission)
|
service_permission = ServicePermission(service_id=service.id, permission=permission)
|
||||||
|
|||||||
@@ -249,6 +249,7 @@ class Service(db.Model, Versioned):
|
|||||||
db.String(255),
|
db.String(255),
|
||||||
nullable=True,
|
nullable=True,
|
||||||
)
|
)
|
||||||
|
crown = db.Column(db.Boolean, index=False, nullable=False, default=True)
|
||||||
|
|
||||||
association_proxy('permissions', 'service_permission_types')
|
association_proxy('permissions', 'service_permission_types')
|
||||||
|
|
||||||
|
|||||||
@@ -178,7 +178,11 @@ def update_service(service_id):
|
|||||||
service_going_live = fetched_service.restricted and not req_json.get('restricted', True)
|
service_going_live = fetched_service.restricted and not req_json.get('restricted', True)
|
||||||
current_data = dict(service_schema.dump(fetched_service).data.items())
|
current_data = dict(service_schema.dump(fetched_service).data.items())
|
||||||
current_data.update(request.get_json())
|
current_data.update(request.get_json())
|
||||||
|
|
||||||
update_dict = service_schema.load(current_data).data
|
update_dict = service_schema.load(current_data).data
|
||||||
|
org_type = req_json.get('organisation_type', None)
|
||||||
|
if org_type:
|
||||||
|
update_dict.crown = org_type == 'central'
|
||||||
dao_update_service(update_dict)
|
dao_update_service(update_dict)
|
||||||
|
|
||||||
# bridging code between frontend is deployed and data has not been migrated yet. Can only update current year
|
# bridging code between frontend is deployed and data has not been migrated yet. Can only update current year
|
||||||
|
|||||||
50
migrations/versions/0149_add_crown_to_services.py
Normal file
50
migrations/versions/0149_add_crown_to_services.py
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
"""
|
||||||
|
|
||||||
|
Revision ID: 0149_add_crown_column_to_services
|
||||||
|
Revises: 0148_add_letters_as_pdf_svc_perm
|
||||||
|
Create Date: 2017-12-04 12:13:35.268712
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
revision = '0149_add_crown_to_services'
|
||||||
|
down_revision = '0148_add_letters_as_pdf_svc_perm'
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.add_column('services', sa.Column('crown', sa.Boolean(), nullable=True))
|
||||||
|
op.execute("""
|
||||||
|
update services set crown = True
|
||||||
|
where organisation_type = 'central'
|
||||||
|
""")
|
||||||
|
op.execute("""
|
||||||
|
update services set crown = True
|
||||||
|
where organisation_type is null
|
||||||
|
""")
|
||||||
|
op.execute("""
|
||||||
|
update services set crown = False
|
||||||
|
where crown is null
|
||||||
|
""")
|
||||||
|
op.alter_column('services', 'crown', nullable=False)
|
||||||
|
|
||||||
|
op.add_column('services_history', sa.Column('crown', sa.Boolean(), nullable=True))
|
||||||
|
op.execute("""
|
||||||
|
update services_history set crown = True
|
||||||
|
where organisation_type = 'central'
|
||||||
|
""")
|
||||||
|
op.execute("""
|
||||||
|
update services_history set crown = True
|
||||||
|
where organisation_type is null
|
||||||
|
""")
|
||||||
|
op.execute("""
|
||||||
|
update services_history set crown = False
|
||||||
|
where crown is null
|
||||||
|
""")
|
||||||
|
op.alter_column('services_history', 'crown', nullable=False)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.drop_column('services', 'crown')
|
||||||
|
op.drop_column('services_history', 'crown')
|
||||||
@@ -87,6 +87,7 @@ def test_create_service(sample_user):
|
|||||||
email_from="email_from",
|
email_from="email_from",
|
||||||
message_limit=1000,
|
message_limit=1000,
|
||||||
restricted=False,
|
restricted=False,
|
||||||
|
organisation_type='central',
|
||||||
created_by=sample_user)
|
created_by=sample_user)
|
||||||
dao_create_service(service, sample_user)
|
dao_create_service(service, sample_user)
|
||||||
assert Service.query.count() == 1
|
assert Service.query.count() == 1
|
||||||
@@ -96,10 +97,14 @@ def test_create_service(sample_user):
|
|||||||
assert service_db.id == service.id
|
assert service_db.id == service.id
|
||||||
assert service_db.branding == BRANDING_GOVUK
|
assert service_db.branding == BRANDING_GOVUK
|
||||||
assert service_db.dvla_organisation_id == DVLA_ORG_HM_GOVERNMENT
|
assert service_db.dvla_organisation_id == DVLA_ORG_HM_GOVERNMENT
|
||||||
|
assert service_db.email_from == 'email_from'
|
||||||
assert service_db.research_mode is False
|
assert service_db.research_mode is False
|
||||||
assert service_db.prefix_sms is True
|
assert service_db.prefix_sms is True
|
||||||
assert service.active is True
|
assert service.active is True
|
||||||
assert sample_user in service_db.users
|
assert sample_user in service_db.users
|
||||||
|
assert service_db.free_sms_fragment_limit == 250000
|
||||||
|
assert service_db.organisation_type == 'central'
|
||||||
|
assert service_db.crown is True
|
||||||
|
|
||||||
|
|
||||||
def test_cannot_create_two_services_with_same_name(sample_user):
|
def test_cannot_create_two_services_with_same_name(sample_user):
|
||||||
|
|||||||
@@ -536,6 +536,26 @@ def test_update_service_flags(client, sample_service):
|
|||||||
assert set(result['data']['permissions']) == set([LETTER_TYPE, INTERNATIONAL_SMS_TYPE])
|
assert set(result['data']['permissions']) == set([LETTER_TYPE, INTERNATIONAL_SMS_TYPE])
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("org_type, expected",
|
||||||
|
[("central", True),
|
||||||
|
('local', False),
|
||||||
|
("nhs", False)])
|
||||||
|
def test_update_service_sets_crown(client, sample_service, org_type, expected):
|
||||||
|
data = {
|
||||||
|
'organisation_type': org_type,
|
||||||
|
}
|
||||||
|
auth_header = create_authorization_header()
|
||||||
|
|
||||||
|
resp = client.post(
|
||||||
|
'/service/{}'.format(sample_service.id),
|
||||||
|
data=json.dumps(data),
|
||||||
|
headers=[('Content-Type', 'application/json'), auth_header]
|
||||||
|
)
|
||||||
|
result = json.loads(resp.get_data(as_text=True))
|
||||||
|
assert resp.status_code == 200
|
||||||
|
assert result['data']['crown'] is expected
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def service_with_no_permissions(notify_db, notify_db_session):
|
def service_with_no_permissions(notify_db, notify_db_session):
|
||||||
return create_service(service_permissions=[])
|
return create_service(service_permissions=[])
|
||||||
|
|||||||
Reference in New Issue
Block a user