From dc5c3ba2b89aa3dab5d8769bf889ee5eb1a57786 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Wed, 7 Mar 2018 18:24:35 +0000 Subject: [PATCH] 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 --- app/main/views/choose_service.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/app/main/views/choose_service.py b/app/main/views/choose_service.py index cb5ab563b..e253c822e 100644 --- a/app/main/views/choose_service.py +++ b/app/main/views/choose_service.py @@ -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'))