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'))