Some database and config updates. Trying to adjust the base profile menubar.
This commit is contained in:
@@ -1,13 +1,18 @@
|
|||||||
|
from copy import deepcopy
|
||||||
|
|
||||||
from fastapi import Depends
|
from fastapi import Depends
|
||||||
from typing import Annotated, Generator
|
from typing import Annotated, Generator
|
||||||
from os.path import isfile
|
from os.path import isfile
|
||||||
|
|
||||||
import ZEO
|
import ZEO
|
||||||
import ZODB
|
import ZODB
|
||||||
|
import json
|
||||||
from ZODB.Connection import Connection
|
from ZODB.Connection import Connection
|
||||||
import transaction
|
import transaction
|
||||||
|
import logging
|
||||||
|
|
||||||
from .config import Settings # assuming Settings has zeo_file: str
|
from .config import Settings # assuming Settings has zeo_file: str
|
||||||
|
from ..common.util import convert_from_persistent
|
||||||
|
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
|
|
||||||
@@ -64,3 +69,11 @@ def get_transaction_manager():
|
|||||||
# Annotated dependencies for routers
|
# Annotated dependencies for routers
|
||||||
DbDependency = Annotated[ZODB.DB, Depends(get_db)]
|
DbDependency = Annotated[ZODB.DB, Depends(get_db)]
|
||||||
#ConnectionDependency = Annotated[Connection, Depends(get_connection)]
|
#ConnectionDependency = Annotated[Connection, Depends(get_connection)]
|
||||||
|
|
||||||
|
def get_server_config_from_db(db: DbDependency) -> dict:
|
||||||
|
with db.transaction() as conn:
|
||||||
|
db_config = convert_from_persistent(conn.root.config)
|
||||||
|
if type(db_config) is not dict:
|
||||||
|
raise RuntimeError("The config property is not a dict.")
|
||||||
|
db_config['server_callsign'] = conn.root.server_callsign
|
||||||
|
return db_config
|
||||||
@@ -5,7 +5,7 @@ from fastapi.templating import Jinja2Templates
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
from .database import init_db
|
from .database import init_db, get_db, get_server_config_from_db
|
||||||
from .routers import public, profile, messages, send
|
from .routers import public, profile, messages, send
|
||||||
from .logging import init_logging
|
from .logging import init_logging
|
||||||
|
|
||||||
@@ -22,6 +22,8 @@ app = FastAPI(
|
|||||||
# Define templates EARLY (before importing dashboard)
|
# Define templates EARLY (before importing dashboard)
|
||||||
templates = Jinja2Templates(directory=BASE_DIR / "templates")
|
templates = Jinja2Templates(directory=BASE_DIR / "templates")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def b64decode_filter(value: str) -> str:
|
def b64decode_filter(value: str) -> str:
|
||||||
try:
|
try:
|
||||||
decoded_bytes = base64.b64decode(value)
|
decoded_bytes = base64.b64decode(value)
|
||||||
@@ -60,6 +62,12 @@ from .routers.jobs import dashboard_router as jobs_html_router
|
|||||||
|
|
||||||
# initialize database
|
# initialize database
|
||||||
init_db()
|
init_db()
|
||||||
|
db = get_db()
|
||||||
|
server_config = get_server_config_from_db(db)
|
||||||
|
templates.env.globals['server_name'] = server_config['server_name']
|
||||||
|
templates.env.globals['server_callsign'] = server_config['server_callsign']
|
||||||
|
templates.env.globals['motd'] = server_config['motd']
|
||||||
|
templates.env.globals['server_operator'] = server_config['operator']
|
||||||
|
|
||||||
# Include routers
|
# Include routers
|
||||||
app.include_router(public.router)
|
app.include_router(public.router)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<body class="bg-light">
|
<body class="bg-light">
|
||||||
<nav class="navbar navbar-dark bg-primary mb-4">
|
<nav class="navbar navbar-dark bg-primary mb-4">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<a class="navbar-brand" href="{{ url_for('dashboard') }}">PacketServer BBS</a>
|
<a class="navbar-brand" href="{{ url_for('dashboard') }}">{{ server_name }}</a>
|
||||||
<span class="navbar-text">
|
<span class="navbar-text">
|
||||||
Logged in as: <strong>{{ current_user }}</strong>
|
Logged in as: <strong>{{ current_user }}</strong>
|
||||||
{# Basic Auth note #}
|
{# Basic Auth note #}
|
||||||
|
|||||||
@@ -73,13 +73,14 @@ class Server:
|
|||||||
if 'config' not in conn.root():
|
if 'config' not in conn.root():
|
||||||
logging.debug("no config, writing blank default config")
|
logging.debug("no config, writing blank default config")
|
||||||
conn.root.config = PersistentMapping(deepcopy(default_server_config))
|
conn.root.config = PersistentMapping(deepcopy(default_server_config))
|
||||||
conn.root.server_callsign = self.callsign
|
|
||||||
conn.root.config['blacklist'] = PersistentList()
|
conn.root.config['blacklist'] = PersistentList()
|
||||||
|
logging.debug(f"Setting server callsign in db to: {self.callsign}")
|
||||||
|
conn.root.server_callsign = self.callsign
|
||||||
for key in ['motd', 'operator']:
|
for key in ['motd', 'operator']:
|
||||||
if key not in conn.root.config:
|
if key not in conn.root.config:
|
||||||
conn.root.config[key] = ""
|
conn.root.config[key] = ""
|
||||||
if 'server_name' not in conn.root.config:
|
if 'server_name' not in conn.root.config:
|
||||||
conn.root.config.server_name = default_server_name
|
conn.root.config['server_name'] = default_server_name
|
||||||
if 'SYSTEM' not in conn.root.config['blacklist']:
|
if 'SYSTEM' not in conn.root.config['blacklist']:
|
||||||
logging.debug("Adding 'SYSTEM' to blacklist in case someone feels like violating FCC rules.")
|
logging.debug("Adding 'SYSTEM' to blacklist in case someone feels like violating FCC rules.")
|
||||||
conn.root.config['blacklist'].append('SYSTEM')
|
conn.root.config['blacklist'].append('SYSTEM')
|
||||||
|
|||||||
Reference in New Issue
Block a user