From dbd0dd4c5b8c620316820ca624257901d22b6072 Mon Sep 17 00:00:00 2001 From: GustaafL Date: Mon, 23 Oct 2023 20:16:01 +0200 Subject: [PATCH] feat(UI): add a consultant view to the view options Signed-off-by: GustaafL --- flexmeasures/data/tests/test_accounts.py | 12 ------------ flexmeasures/ui/templates/defaults.jinja | 22 ++++++++++++++-------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/flexmeasures/data/tests/test_accounts.py b/flexmeasures/data/tests/test_accounts.py index 7d9e3bcf2..2566041cc 100644 --- a/flexmeasures/data/tests/test_accounts.py +++ b/flexmeasures/data/tests/test_accounts.py @@ -2,9 +2,7 @@ get_accounts, get_number_of_assets_in_account, get_account_roles, - get_consultant_client_accounts, ) -from flexmeasures.data.models.user import Account def test_get_accounts(db, setup_assets): @@ -31,13 +29,3 @@ def test_get_account_roles(db, setup_assets): assert get_account_roles(9999999) == [] # non-existing account id multiple_roles = get_account_roles(5) assert [i.name for i in multiple_roles] == ["Prosumer", "Supplier", "Dummy"] - - -def test_get_consultant_client_accounts(): - consultant_account = Account.query.filter( - Account.name == "Test Consultant Account" - ).one_or_none() - - accounts = get_consultant_client_accounts(consultant_account.id) - print(accounts) - assert accounts[0]["name"] == "Test ConsultantClient Account" diff --git a/flexmeasures/ui/templates/defaults.jinja b/flexmeasures/ui/templates/defaults.jinja index c2467c6b6..a4274e4b1 100644 --- a/flexmeasures/ui/templates/defaults.jinja +++ b/flexmeasures/ui/templates/defaults.jinja @@ -34,14 +34,20 @@ {% endfor %} -{% set admin_view = True if current_user.is_authenticated and (current_user.has_role('admin') or FLEXMEASURES_MODE == "demo") else False %} -{% do navigation_bar.append(('accounts', 'accounts', 'Accounts', '', 'cubes')) if admin_view %} -{% do navigation_bar.append(('assets', 'assets', 'Assets', '', 'list-ul')) if admin_view %} -{% do navigation_bar.append(('users', 'users', 'Users', '', 'users')) if admin_view %} -{% do navigation_bar.append(('tasks', 'tasks', 'Tasks', '', 'tasks')) if admin_view %} - -{% set non_admin_view = True if current_user.is_authenticated and not (current_user.has_role('admin') or FLEXMEASURES_MODE == "demo") else False %} -{% do navigation_bar.append(("accounts/{}".format(current_user.account.id), 'accounts', 'My Account', '', 'cubes')) if non_admin_view %} +{% set view = "admin" if current_user.is_authenticated and (current_user.has_role('admin') or FLEXMEASURES_MODE == "demo") %} +{% do navigation_bar.append(('accounts', 'accounts', 'Accounts', '', 'cubes')) if view == "admin" %} +{% do navigation_bar.append(('assets', 'assets', 'Assets', '', 'list-ul')) if view == "admin" %} +{% do navigation_bar.append(('users', 'users', 'Users', '', 'users')) if view == "admin" %} +{% do navigation_bar.append(('tasks', 'tasks', 'Tasks', '', 'tasks')) if view == "admin" %} + +{% set view = "non_admin" if current_user.is_authenticated and not (current_user.has_role('admin') or FLEXMEASURES_MODE == "demo" or current_user.has_role('customer-manager')) %} +{% do navigation_bar.append(("accounts/{}".format(current_user.account.id), 'accounts', 'My Account', '', 'cubes')) if view == "non_admin" %} + +{% set view = "consultant" if current_user.is_authenticated and (current_user.has_role('customer-manager') or FLEXMEASURES_MODE == "demo") %} +{% do navigation_bar.append(('accounts', 'accounts', 'Accounts', '', 'cubes')) if view == "consultant" %} +{% do navigation_bar.append(('assets', 'assets', 'Assets', '', 'list-ul')) if view == "consultant" %} +{% do navigation_bar.append(('users', 'users', 'Users', '', 'users')) if view == "consultant" %} +{% do navigation_bar.append(('tasks', 'tasks', 'Tasks', '', 'tasks')) if view == "consultant" %} {% do navigation_bar.append(('logged-in-user', 'logged-in-user', '', user_name, 'user')) if current_user.is_authenticated %}