mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-18 16:12:32 -05:00
Return services serialized for dashboard for orgs
- rather than returning the entire service, return only whats needed when listing the service on the org dashboard
This commit is contained in:
@@ -344,6 +344,15 @@ class Service(db.Model, Versioned):
|
||||
def has_permission(self, permission):
|
||||
return permission in [p.permission for p in self.permissions]
|
||||
|
||||
def serialize_for_org_dashboard(self):
|
||||
return {
|
||||
'id': str(self.id),
|
||||
'name': self.name,
|
||||
'active': self.active,
|
||||
'restricted': self.restricted,
|
||||
'research_mode': self.research_mode
|
||||
}
|
||||
|
||||
|
||||
class AnnualBilling(db.Model):
|
||||
__tablename__ = "annual_billing"
|
||||
|
||||
@@ -17,7 +17,6 @@ from app.organisation.organisation_schema import (
|
||||
post_link_service_to_organisation_schema,
|
||||
)
|
||||
from app.schema_validation import validate
|
||||
from app.schemas import service_schema
|
||||
|
||||
organisation_blueprint = Blueprint('organisation', __name__)
|
||||
register_errors(organisation_blueprint)
|
||||
@@ -77,4 +76,5 @@ def link_service_to_organisation(organisation_id):
|
||||
@organisation_blueprint.route('/<uuid:organisation_id>/services', methods=['GET'])
|
||||
def get_organisation_services(organisation_id):
|
||||
services = dao_get_organisation_services(organisation_id)
|
||||
return jsonify([service_schema.dump(s).data for s in services])
|
||||
sorted_services = sorted(services, key=lambda s: (-s.active, s.name))
|
||||
return jsonify([s.serialize_for_org_dashboard() for s in sorted_services])
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from app.models import Organisation
|
||||
from app.dao.organisation_dao import dao_add_service_to_organisation
|
||||
from tests.app.db import create_organisation
|
||||
from tests.app.db import create_organisation, create_service
|
||||
|
||||
|
||||
def test_get_all_organisations(admin_request, notify_db_session):
|
||||
@@ -193,6 +193,44 @@ def test_rest_get_organisation_services(
|
||||
_expected_status=200
|
||||
)
|
||||
|
||||
assert len(response) == 1
|
||||
assert response[0]['id'] == str(sample_service.id)
|
||||
assert response == [sample_service.serialize_for_org_dashboard()]
|
||||
|
||||
|
||||
def test_rest_get_organisation_services_is_ordered_by_name(
|
||||
admin_request, sample_organisation, sample_service):
|
||||
service_2 = create_service(service_name='service 2')
|
||||
service_1 = create_service(service_name='service 1')
|
||||
dao_add_service_to_organisation(service_1, sample_organisation.id)
|
||||
dao_add_service_to_organisation(service_2, sample_organisation.id)
|
||||
dao_add_service_to_organisation(sample_service, sample_organisation.id)
|
||||
|
||||
response = admin_request.get(
|
||||
'organisation.get_organisation_services',
|
||||
organisation_id=str(sample_organisation.id),
|
||||
_expected_status=200
|
||||
)
|
||||
|
||||
assert response[0]['name'] == sample_service.name
|
||||
assert response[1]['name'] == service_1.name
|
||||
assert response[2]['name'] == service_2.name
|
||||
|
||||
|
||||
def test_rest_get_organisation_services_inactive_services_at_end(
|
||||
admin_request, sample_organisation):
|
||||
inactive_service = create_service(service_name='inactive service', active=False)
|
||||
service = create_service()
|
||||
inactive_service_1 = create_service(service_name='inactive service 1', active=False)
|
||||
|
||||
dao_add_service_to_organisation(inactive_service, sample_organisation.id)
|
||||
dao_add_service_to_organisation(service, sample_organisation.id)
|
||||
dao_add_service_to_organisation(inactive_service_1, sample_organisation.id)
|
||||
|
||||
response = admin_request.get(
|
||||
'organisation.get_organisation_services',
|
||||
organisation_id=str(sample_organisation.id),
|
||||
_expected_status=200
|
||||
)
|
||||
|
||||
assert response[0]['name'] == service.name
|
||||
assert response[1]['name'] == inactive_service.name
|
||||
assert response[2]['name'] == inactive_service_1.name
|
||||
|
||||
Reference in New Issue
Block a user