Refactor MongoClient import: standardize import statements across push_notifications, tenant, and verify_audit_chain modules
This commit is contained in:
@@ -6,13 +6,13 @@ Handles Web Push notifications for users via Service Workers
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import datetime
|
import datetime
|
||||||
from pymongo import MongoClient
|
|
||||||
from bson import ObjectId
|
from bson import ObjectId
|
||||||
import requests
|
import requests
|
||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import settings as cfg
|
import settings as cfg
|
||||||
|
from settings import MongoClient
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|||||||
+13
-6
@@ -146,10 +146,17 @@ class TenantContext:
|
|||||||
self.config = get_tenant_config(potential_subdomain)
|
self.config = get_tenant_config(potential_subdomain)
|
||||||
return self._get_db_name(potential_subdomain)
|
return self._get_db_name(potential_subdomain)
|
||||||
|
|
||||||
# Fallback to default tenant if no tenant identifier found
|
# Fallback to default tenant if no tenant identifier found.
|
||||||
self.tenant_id = 'default'
|
# If no explicit 'default' tenant config exists, use configured MongoDB DB.
|
||||||
self.config = get_tenant_config('default')
|
if 'default' in TENANT_REGISTRY:
|
||||||
return self._get_db_name('default')
|
self.tenant_id = 'default'
|
||||||
|
self.config = get_tenant_config('default')
|
||||||
|
return self._get_db_name('default')
|
||||||
|
|
||||||
|
self.tenant_id = None
|
||||||
|
self.config = {}
|
||||||
|
self.db_name = cfg.MONGODB_DB
|
||||||
|
return self.db_name
|
||||||
|
|
||||||
def _get_db_name(self, tenant_id):
|
def _get_db_name(self, tenant_id):
|
||||||
"""
|
"""
|
||||||
@@ -214,8 +221,8 @@ def get_tenant_db(mongo_client):
|
|||||||
ctx = get_tenant_context()
|
ctx = get_tenant_context()
|
||||||
if ctx:
|
if ctx:
|
||||||
return ctx.get_database(mongo_client)
|
return ctx.get_database(mongo_client)
|
||||||
# Fallback to default database
|
# Fallback to configured default database
|
||||||
return mongo_client['inventar_default']
|
return mongo_client[cfg.MONGODB_DB]
|
||||||
|
|
||||||
|
|
||||||
def register_tenant(tenant_id, config=None):
|
def register_tenant(tenant_id, config=None):
|
||||||
|
|||||||
@@ -4,9 +4,8 @@
|
|||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pymongo import MongoClient
|
|
||||||
|
|
||||||
import settings as cfg
|
import settings as cfg
|
||||||
|
from settings import MongoClient
|
||||||
import audit_log as al
|
import audit_log as al
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user