diff --git a/app/add_admins.py b/app/add_admins.py index b3f8112..e9e2fba 100644 --- a/app/add_admins.py +++ b/app/add_admins.py @@ -10,5 +10,5 @@ def add() -> None: """Add users as admin.""" for username in Configuration.HALDIS_ADMINS: user = User() - user.configure(username, True, 0) + user.configure(username, True, 0, associations=["zeus"]) db.session.add(user) diff --git a/app/models/user.py b/app/models/user.py index 8e78b2f..13634bb 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -1,4 +1,6 @@ "Script for everything User related in the database" +from typing import List + from models import db @@ -8,6 +10,10 @@ class User(db.Model): username = db.Column(db.String(80), unique=True, nullable=False) admin = db.Column(db.Boolean) bias = db.Column(db.Integer) + # Assocation logic + associations = db.Column(db.String(120)) + + # Relations runs = db.relation( "Order", backref="courier", @@ -16,11 +22,17 @@ class User(db.Model): ) orderItems = db.relationship("OrderItem", backref="user", lazy="dynamic") - def configure(self, username: str, admin: bool, bias: int) -> None: - "Configure the User" + def association_list(self) -> List[str]: + return self.associations.split(",") + + def configure(self, username: str, admin: bool, bias: int, associations: List[str] = None) -> None: + """Configure the User""" + if associations is None: + associations = [] self.username = username self.admin = admin self.bias = bias + self.associations = ",".join(associations) # pylint: disable=C0111, R0201 def is_authenticated(self) -> bool: diff --git a/app/templates/layout.html b/app/templates/layout.html index 72b85b7..3ba9722 100644 --- a/app/templates/layout.html +++ b/app/templates/layout.html @@ -14,6 +14,12 @@ {% set navbar = navbar + [('admin.index', 'Admin')] -%} {% endif -%} +{% if not current_user.is_anonymous() -%} + {% for association in current_user.association_list() %} + {% set navbar = navbar + [('general_bp.home', association)] -%} + {% endfor -%} +{% endif -%} + {% set active_page = active_page|default('index') -%} {% block title %} diff --git a/app/zeus.py b/app/zeus.py index ebc16ab..09a4b04 100644 --- a/app/zeus.py +++ b/app/zeus.py @@ -77,7 +77,7 @@ def login_and_redirect_user(user) -> Response: def create_user(username) -> User: "Create a temporary user if it is needed" user = User() - user.configure(username, False, 1) + user.configure(username, False, 1, associations=["zeus"]) db.session.add(user) db.session.commit() return user