Files
notifications-admin/app/main/views/choose_account.py
T

48 lines
1.6 KiB
Python
Raw Normal View History

2018-02-20 11:22:17 +00:00
from flask import redirect, render_template, session, url_for
from flask_login import current_user, login_required
from app.main import main
from app.utils import PermanentRedirect
2016-01-13 14:43:21 +00:00
@main.route("/services")
def choose_service():
raise PermanentRedirect(url_for('.choose_account'))
@main.route("/services-or-dashboard")
def services_or_dashboard():
raise PermanentRedirect(url_for('.show_accounts_or_dashboard'))
2018-03-08 16:51:53 +00:00
@main.route("/accounts")
2016-01-13 14:43:21 +00:00
@login_required
2018-03-08 16:51:53 +00:00
def choose_account():
2016-01-18 11:15:14 +00:00
return render_template(
2018-03-08 16:51:53 +00:00
'views/choose-account.html',
2018-12-12 12:29:08 +00:00
can_add_service=current_user.is_gov_user,
)
2018-03-08 16:51:53 +00:00
@main.route("/accounts-or-dashboard")
def show_accounts_or_dashboard():
2016-05-04 13:01:55 +01:00
if not current_user.is_authenticated:
return redirect(url_for('.index'))
service_id = session.get('service_id')
2018-03-13 09:02:09 +00:00
if service_id and (service_id in current_user.services or current_user.platform_admin):
return redirect(url_for('.service_dashboard', service_id=service_id))
organisation_id = session.get('organisation_id')
2019-06-07 09:26:11 +01:00
if organisation_id and (organisation_id in current_user.organisation_ids or current_user.platform_admin):
return redirect(url_for('.organisation_dashboard', org_id=organisation_id))
2019-06-07 09:26:11 +01:00
if len(current_user.services) == 1 and not current_user.organisation_ids:
return redirect(url_for('.service_dashboard', service_id=current_user.services[0]))
2019-06-07 09:26:11 +01:00
if len(current_user.organisation_ids) == 1 and not current_user.services:
return redirect(url_for('.organisation_dashboard', org_id=current_user.organisation_ids[0]))
2018-03-08 16:51:53 +00:00
return redirect(url_for('.choose_account'))