mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-25 00:33:58 -04:00
Put organisations on the user model
As in other places, putting a model layer between the view and the API client makes the code cleaner and clearer.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
from flask import redirect, render_template, session, url_for
|
||||
from flask_login import current_user, login_required
|
||||
|
||||
from app import user_api_client
|
||||
from app.main import main
|
||||
from app.utils import PermanentRedirect
|
||||
|
||||
@@ -19,11 +18,10 @@ def services_or_dashboard():
|
||||
@main.route("/accounts")
|
||||
@login_required
|
||||
def choose_account():
|
||||
orgs_and_services = user_api_client.get_organisations_and_services_for_user(current_user)
|
||||
orgs_and_services = current_user.orgs_and_services
|
||||
|
||||
return render_template(
|
||||
'views/choose-account.html',
|
||||
organisations=orgs_and_services['organisations'],
|
||||
services_without_organisations=orgs_and_services['services_without_organisations'],
|
||||
can_add_service=current_user.is_gov_user,
|
||||
)
|
||||
@@ -40,13 +38,13 @@ def show_accounts_or_dashboard():
|
||||
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):
|
||||
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))
|
||||
|
||||
if len(current_user.services) == 1 and not current_user.organisations:
|
||||
if len(current_user.services) == 1 and not current_user.organisation_ids:
|
||||
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]))
|
||||
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]))
|
||||
|
||||
return redirect(url_for('.choose_account'))
|
||||
|
||||
@@ -31,12 +31,9 @@ def find_users_by_email():
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
def user_information(user_id):
|
||||
user = User.from_id(user_id)
|
||||
services = user_api_client.get_services_for_user(user)
|
||||
return render_template(
|
||||
'views/find-users/user-information.html',
|
||||
user=user,
|
||||
services=services,
|
||||
user=User.from_id(user_id),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ from app import (
|
||||
service_api_client,
|
||||
template_folder_api_client,
|
||||
template_statistics_client,
|
||||
user_api_client,
|
||||
)
|
||||
from app.main import main
|
||||
from app.main.forms import (
|
||||
@@ -370,7 +369,7 @@ def choose_template_to_copy(
|
||||
'views/templates/copy.html',
|
||||
services_templates_and_folders=TemplateLists([
|
||||
Service(service) for service in
|
||||
user_api_client.get_services_for_user(current_user)
|
||||
current_user.all_services
|
||||
], user=current_user),
|
||||
search_form=SearchByNameForm(),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user