mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-16 20:48:37 -04:00
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:
@@ -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),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user