mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-06 10:48:25 -04:00
@@ -20,7 +20,7 @@ from app.main.views import ( # noqa
|
||||
new_password,
|
||||
styleguide,
|
||||
user_profile,
|
||||
choose_service,
|
||||
choose_account,
|
||||
api_keys,
|
||||
manage_users,
|
||||
invites,
|
||||
|
||||
53
app/main/views/choose_account.py
Normal file
53
app/main/views/choose_account.py
Normal file
@@ -0,0 +1,53 @@
|
||||
from flask import redirect, render_template, session, url_for
|
||||
from flask_login import current_user, login_required
|
||||
from werkzeug.routing import RequestRedirect
|
||||
|
||||
from app import user_api_client
|
||||
from app.main import main
|
||||
from app.utils import is_gov_user
|
||||
|
||||
|
||||
@main.route("/services")
|
||||
def choose_service():
|
||||
raise RequestRedirect(url_for('.choose_account'))
|
||||
|
||||
|
||||
@main.route("/services-or-dashboard")
|
||||
def services_or_dashboard():
|
||||
raise RequestRedirect(url_for('.show_accounts_or_dashboard'))
|
||||
|
||||
|
||||
@main.route("/accounts")
|
||||
@login_required
|
||||
def choose_account():
|
||||
orgs_and_services = user_api_client.get_organisations_and_services_for_user(current_user)
|
||||
|
||||
return render_template(
|
||||
'views/choose-account.html',
|
||||
organisations=orgs_and_services['organisations'],
|
||||
services_without_organisations=orgs_and_services['services_without_organisations'],
|
||||
can_add_service=is_gov_user(current_user.email_address)
|
||||
)
|
||||
|
||||
|
||||
@main.route("/accounts-or-dashboard")
|
||||
def show_accounts_or_dashboard():
|
||||
|
||||
if not current_user.is_authenticated:
|
||||
return redirect(url_for('.index'))
|
||||
|
||||
service_id = session.get('service_id')
|
||||
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')
|
||||
if organisation_id and (organisation_id in current_user.organisations or current_user.platform_admin):
|
||||
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_account'))
|
||||
@@ -1,35 +0,0 @@
|
||||
from flask import redirect, render_template, session, url_for
|
||||
from flask_login import current_user, login_required
|
||||
|
||||
from app import service_api_client
|
||||
from app.main import main
|
||||
from app.notify_client.service_api_client import ServicesBrowsableItem
|
||||
from app.utils import is_gov_user
|
||||
|
||||
|
||||
@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_active_services({'user_id': current_user.id})['data']],
|
||||
can_add_service=is_gov_user(current_user.email_address)
|
||||
)
|
||||
|
||||
|
||||
@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_active_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'))
|
||||
@@ -15,7 +15,7 @@ from app.utils import AgreementInfo
|
||||
@main.route('/')
|
||||
def index():
|
||||
if current_user and current_user.is_authenticated:
|
||||
return redirect(url_for('main.choose_service'))
|
||||
return redirect(url_for('main.choose_account'))
|
||||
return render_template('views/signedout.html')
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ from app.main.forms import (
|
||||
RenameOrganisationForm,
|
||||
SearchUsersForm,
|
||||
)
|
||||
from app.utils import user_is_platform_admin
|
||||
from app.utils import user_has_permissions, user_is_platform_admin
|
||||
|
||||
|
||||
@main.route("/organisations", methods=['GET'])
|
||||
@@ -53,7 +53,7 @@ def add_organisation():
|
||||
|
||||
@main.route("/organisations/<org_id>", methods=['GET'])
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
@user_has_permissions()
|
||||
def organisation_dashboard(org_id):
|
||||
organisation_services = organisations_client.get_organisation_services(org_id)
|
||||
|
||||
@@ -65,7 +65,7 @@ def organisation_dashboard(org_id):
|
||||
|
||||
@main.route("/organisations/<org_id>/users", methods=['GET'])
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
@user_has_permissions()
|
||||
def manage_org_users(org_id):
|
||||
users = sorted(
|
||||
user_api_client.get_users_for_organisation(org_id=org_id) + [
|
||||
@@ -85,7 +85,7 @@ def manage_org_users(org_id):
|
||||
|
||||
@main.route("/organisations/<org_id>/users/invite", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
@user_has_permissions()
|
||||
def invite_org_user(org_id):
|
||||
form = InviteOrgUserForm(
|
||||
invalid_email_address=current_user.email_address
|
||||
@@ -109,7 +109,7 @@ def invite_org_user(org_id):
|
||||
|
||||
@main.route("/organisations/<org_id>/users/<user_id>", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
@user_has_permissions()
|
||||
def edit_user_org_permissions(org_id, user_id):
|
||||
user = user_api_client.get_user(user_id)
|
||||
|
||||
@@ -121,7 +121,7 @@ def edit_user_org_permissions(org_id, user_id):
|
||||
|
||||
@main.route("/organisations/<org_id>/users/<user_id>/delete", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
@user_has_permissions()
|
||||
def remove_user_from_organisation(org_id, user_id):
|
||||
user = user_api_client.get_user(user_id)
|
||||
if request.method == 'POST':
|
||||
@@ -151,7 +151,7 @@ def remove_user_from_organisation(org_id, user_id):
|
||||
|
||||
@main.route("/organisations/<org_id>/cancel-invited-user/<invited_user_id>", methods=['GET'])
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
@user_has_permissions()
|
||||
def cancel_invited_org_user(org_id, invited_user_id):
|
||||
org_invite_api_client.cancel_invited_user(org_id=org_id, invited_user_id=invited_user_id)
|
||||
|
||||
@@ -160,7 +160,7 @@ def cancel_invited_org_user(org_id, invited_user_id):
|
||||
|
||||
@main.route("/organisations/<org_id>/settings/", methods=['GET'])
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
@user_has_permissions()
|
||||
def organisation_settings(org_id):
|
||||
return render_template(
|
||||
'views/organisations/organisation/settings/index.html',
|
||||
@@ -169,7 +169,7 @@ def organisation_settings(org_id):
|
||||
|
||||
@main.route("/organisations/<org_id>/settings/edit-name", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
@user_has_permissions()
|
||||
def edit_organisation_name(org_id):
|
||||
form = RenameOrganisationForm()
|
||||
|
||||
@@ -192,7 +192,7 @@ def edit_organisation_name(org_id):
|
||||
|
||||
@main.route("/organisations/<org_id>/settings/edit-name/confirm", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
@user_has_permissions()
|
||||
def confirm_edit_organisation_name(org_id):
|
||||
# Validate password for form
|
||||
def _check_password(pwd):
|
||||
|
||||
@@ -16,7 +16,7 @@ from app.main.views.verify import activate_user
|
||||
@main.route('/register', methods=['GET', 'POST'])
|
||||
def register():
|
||||
if current_user and current_user.is_authenticated:
|
||||
return redirect(url_for('main.choose_service'))
|
||||
return redirect(url_for('main.choose_account'))
|
||||
|
||||
form = RegisterUserForm()
|
||||
if form.validate_on_submit():
|
||||
@@ -101,5 +101,5 @@ def _do_registration(form, send_sms=True, send_email=True, organisation_id=None)
|
||||
@main.route('/registration-continue')
|
||||
def registration_continue():
|
||||
if not session.get('user_details'):
|
||||
return redirect(url_for('.show_all_services_or_dashboard'))
|
||||
return redirect(url_for('.show_accounts_or_dashboard'))
|
||||
return render_template('views/registration-continue.html')
|
||||
|
||||
@@ -18,7 +18,7 @@ from app.main.forms import LoginForm
|
||||
@main.route('/sign-in', methods=(['GET', 'POST']))
|
||||
def sign_in():
|
||||
if current_user and current_user.is_authenticated:
|
||||
return redirect(url_for('main.choose_service'))
|
||||
return redirect(url_for('main.choose_account'))
|
||||
|
||||
form = LoginForm()
|
||||
|
||||
|
||||
@@ -117,4 +117,4 @@ def redirect_when_logged_in(user_id):
|
||||
if len(services) == 1:
|
||||
return redirect(url_for('main.service_dashboard', service_id=services[0]['id']))
|
||||
else:
|
||||
return redirect(url_for('main.choose_service'))
|
||||
return redirect(url_for('main.choose_account'))
|
||||
|
||||
Reference in New Issue
Block a user