2018-02-20 11:22:17 +00:00
|
|
|
from flask import redirect, render_template, session, url_for
|
2019-07-01 15:22:08 +01:00
|
|
|
from flask_login import current_user
|
2018-02-20 11:22:17 +00:00
|
|
|
|
2019-07-08 12:00:40 +01:00
|
|
|
from app import status_api_client
|
2018-02-20 11:22:17 +00:00
|
|
|
from app.main import main
|
2019-07-08 12:00:40 +01:00
|
|
|
from app.models.organisation import Organisations
|
2019-07-01 15:22:08 +01:00
|
|
|
from app.utils import PermanentRedirect, user_is_logged_in
|
2016-01-13 14:43:21 +00:00
|
|
|
|
|
|
|
|
|
2018-03-15 11:02:05 +00:00
|
|
|
@main.route("/services")
|
|
|
|
|
def choose_service():
|
2019-03-21 16:41:22 +00:00
|
|
|
raise PermanentRedirect(url_for('.choose_account'))
|
2018-03-15 11:02:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@main.route("/services-or-dashboard")
|
|
|
|
|
def services_or_dashboard():
|
2019-03-21 16:41:22 +00:00
|
|
|
raise PermanentRedirect(url_for('.show_accounts_or_dashboard'))
|
2018-03-15 11:02:05 +00:00
|
|
|
|
|
|
|
|
|
2018-03-08 16:51:53 +00:00
|
|
|
@main.route("/accounts")
|
2019-07-01 15:22:08 +01:00
|
|
|
@user_is_logged_in
|
2018-03-08 16:51:53 +00:00
|
|
|
def choose_account():
|
2019-07-08 12:00:40 +01:00
|
|
|
org_count, live_service_count = None, None
|
|
|
|
|
if current_user.platform_admin:
|
|
|
|
|
org_count, live_service_count = (
|
|
|
|
|
len(Organisations()),
|
|
|
|
|
status_api_client.get_count_of_live_services_and_organisations()['services'],
|
|
|
|
|
)
|
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,
|
2019-07-08 12:00:40 +01:00
|
|
|
org_count=org_count,
|
|
|
|
|
live_service_count=live_service_count,
|
2016-03-29 10:39:01 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2018-03-08 16:51:53 +00:00
|
|
|
@main.route("/accounts-or-dashboard")
|
|
|
|
|
def show_accounts_or_dashboard():
|
2016-04-24 09:46:44 +01:00
|
|
|
|
2016-05-04 13:01:55 +01:00
|
|
|
if not current_user.is_authenticated:
|
2016-04-24 09:46:44 +01:00
|
|
|
return redirect(url_for('.index'))
|
|
|
|
|
|
2018-03-07 18:24:35 +00:00
|
|
|
service_id = session.get('service_id')
|
2019-06-07 13:13:06 +01:00
|
|
|
if service_id and (current_user.belongs_to_service(service_id) or current_user.platform_admin):
|
2018-03-07 18:24:35 +00:00
|
|
|
return redirect(url_for('.service_dashboard', service_id=service_id))
|
2016-03-29 10:39:01 +01:00
|
|
|
|
2018-03-07 18:24:35 +00:00
|
|
|
organisation_id = session.get('organisation_id')
|
2019-06-07 13:13:06 +01:00
|
|
|
if organisation_id and (current_user.belongs_to_organisation(organisation_id) or current_user.platform_admin):
|
2018-03-07 18:24:35 +00:00
|
|
|
return redirect(url_for('.organisation_dashboard', org_id=organisation_id))
|
|
|
|
|
|
2019-06-07 12:22:15 +01:00
|
|
|
if len(current_user.service_ids) == 1 and not current_user.organisation_ids:
|
|
|
|
|
return redirect(url_for('.service_dashboard', service_id=current_user.service_ids[0]))
|
2018-03-07 18:24:35 +00:00
|
|
|
|
2019-06-07 13:06:53 +01:00
|
|
|
if len(current_user.organisation_ids) == 1 and not current_user.trial_mode_services:
|
2019-06-07 09:26:11 +01:00
|
|
|
return redirect(url_for('.organisation_dashboard', org_id=current_user.organisation_ids[0]))
|
2018-03-07 18:24:35 +00:00
|
|
|
|
2018-03-08 16:51:53 +00:00
|
|
|
return redirect(url_for('.choose_account'))
|