services-or-dashboard (name TBD) now redirects to orgs too

if there's a service in the session, go there.
if there's an org in the session, go there.
if the user has one service and no orgs, go there.
if the user has one org and no services, go there.
else go to choose service page
This commit is contained in:
Leo Hemsted
2018-03-07 18:24:35 +00:00
parent b37613cbc6
commit dc5c3ba2b8

View File

@@ -13,7 +13,6 @@ from app.utils import is_gov_user
def choose_service():
orgs_and_services = user_api_client.get_organisations_and_services_for_user(current_user)
from pprint import pprint
pprint(orgs_and_services)
orgs_and_services['organisations'] = [
OrganisationBrowsableItem(org) for org in orgs_and_services['organisations']
]
@@ -35,12 +34,18 @@ def show_all_services_or_dashboard():
if not current_user.is_authenticated:
return redirect(url_for('.index'))
services = service_api_client.get_active_services({'user_id': current_user.id})['data']
service_id = session.get('service_id')
if any(service_id == x for x in current_user.services):
return redirect(url_for('.service_dashboard', service_id=service_id))
if 1 == len(services):
return redirect(url_for('.service_dashboard', service_id=services[0]['id']))
else:
service_id = session.get('service_id', None)
if any([service_id == x['id'] for x in services]):
return redirect(url_for('.service_dashboard', service_id=service_id))
return redirect(url_for('.choose_service'))
organisation_id = session.get('organisation_id')
if any(organisation_id == x for x in current_user.organisations):
return redirect(url_for('.organisation_dashboard', org_id=organisation_id))
if len(current_user.services) == 1 and not current_user.organisations:
return redirect(url_for('.service_dashboard', service_id=current_user.services[0]))
if len(current_user.organisations) == 1 and not current_user.services:
return redirect(url_for('.organisation_dashboard', org_id=current_user.organisations[0]))
return redirect(url_for('.choose_service'))