Skip to content

Commit

Permalink
feat(UI): add a consultant view to the view options
Browse files Browse the repository at this point in the history
Signed-off-by: GustaafL <[email protected]>
  • Loading branch information
GustaafL committed Oct 23, 2023
1 parent 2080385 commit dbd0dd4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
12 changes: 0 additions & 12 deletions flexmeasures/data/tests/test_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"
22 changes: 14 additions & 8 deletions flexmeasures/ui/templates/defaults.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

Expand Down

0 comments on commit dbd0dd4

Please sign in to comment.