Neue Verwaltung der Gruppenzuordnung 1:n

This commit is contained in:
concierge committed 2026-10-30 09:02:46 +01:00
1 parent fa02a7ade0
commit 02c017d53d
34 files changed
+1306 -251

No files matched your search

+17 -12
View File
@@ -15,9 +15,11 @@ class GroupsService:
def load_from_db(cls, tenant_id):
"""Lädt alle Gruppen eines Mandanten aus der Datenbank in den Cache"""
groups = GroupModel.get_all_by_tenant(tenant_id)
if tenant_id not in cls._cache:
cls._cache[tenant_id] = {}
memberships = GroupModel.get_account_ids_by_group(tenant_id)
# Vollständig neu aufbauen, damit gelöschte Gruppen nicht im Cache
# zurückbleiben.
cls._cache[tenant_id] = {}
for group in groups:
cls._cache[tenant_id][group['id']] = {
'id': group['id'],
@@ -27,7 +29,7 @@ class GroupsService:
'last_lat': group['last_lat'],
'last_lon': group['last_lon'],
'last_pos_at': group['last_pos_at'],
'account_id': group['account_id'],
'account_ids': memberships.get(group['id'], []),
'created_at': group['created_at'],
'updated_at': group['updated_at']
}
@@ -43,7 +45,7 @@ class GroupsService:
@classmethod
def get_by_id(cls, tenant_id, group_id):
"""Gibt eine spezifische Gruppe aus dem Cache zurück"""
if tenant_id not in cls._cache:
if tenant_id not in cls._cache or not cls._cache[tenant_id]:
cls.load_from_db(tenant_id)
return cls._cache.get(tenant_id, {}).get(group_id)
@@ -64,16 +66,19 @@ class GroupsService:
group = cls.get_by_id(tenant_id, group_id)
if not group:
return False
return group.get('account_id') == account_id
account_ids = {int(value) for value in group.get('account_ids', [])}
return int(account_id) in account_ids
@classmethod
def get_accounts_for_group(cls, group_id, tenant_id):
"""Gibt alle mit einer Gruppe verknüpften Accounts zurück"""
group = cls.get_by_id(tenant_id, group_id)
if not group or not group.get('account_id'):
return []
account = AccountModel.get_by_id(group['account_id'], tenant_id)
return [account] if account else []
account_ids = GroupModel.get_account_ids_for_group(group_id, tenant_id)
accounts = []
for account_id in account_ids:
account = AccountModel.get_by_id(account_id, tenant_id)
if account:
accounts.append(account)
return accounts
@classmethod
def get_streets_for_group(cls, group_id, tenant_id):