Files
notifications-admin/app/main/views/choose_service.py
Chris Hill-Scott ba7d9cd486 If not logged in, go home when clicking GOV.UK
It’s a bit of a weird experience to be taken to the sign in screen when
you click GOV.UK in the header. It’s doubly weird if you take the tour
before creating an account, and at the end of the tour you get prompted
to sign in.

This commit adds some extra logic to take you to the homepage instead,
which I think is more what you’d expect.
2016-04-24 09:48:13 +01:00

33 lines
1.1 KiB
Python

from flask import (render_template, redirect, url_for, session)
from flask_login import login_required, current_user
from app.main import main
from app import service_api_client
from app.notify_client.api_client import ServicesBrowsableItem
@main.route("/services")
@login_required
def choose_service():
return render_template(
'views/choose-service.html',
services=[ServicesBrowsableItem(x) for x in
service_api_client.get_services({'user_id': current_user.id})['data']]
)
@main.route("/services-or-dashboard")
def show_all_services_or_dashboard():
if not current_user.is_authenticated():
return redirect(url_for('.index'))
services = service_api_client.get_services({'user_id': current_user.id})['data']
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'))