Merge pull request #2539 from alphagov/optimise-orgs-services-for-user

Return all required information about a user’s organisations and services
This commit is contained in:
Chris Hill-Scott
2019-06-18 10:28:20 +01:00
committed by GitHub
4 changed files with 154 additions and 69 deletions

View File

@@ -367,6 +367,13 @@ class Organisation(db.Model):
nullable=True,
)
@property
def live_services(self):
return [
service for service in self.services
if service.active and not service.restricted
]
def serialize(self):
return {
"id": str(self.id),
@@ -384,6 +391,7 @@ class Organisation(db.Model):
domain.domain for domain in self.domains
],
"request_to_go_live_notes": self.request_to_go_live_notes,
"count_of_live_services": len(self.live_services),
}

View File

@@ -515,7 +515,8 @@ def get_orgs_and_services(user):
}
for service in org.services
if service.active and service in user.services
]
],
'count_of_live_services': len(org.live_services),
}
for org in user.organisations if org.active
],
@@ -534,5 +535,14 @@ def get_orgs_and_services(user):
service.organisation not in user.organisations
)
)
],
'services': [
{
'id': service.id,
'name': service.name,
'restricted': service.restricted,
'organisation': service.organisation.id if service.organisation else None,
}
for service in user.services if service.active
]
}