make it work from g()
This commit is contained in:
@@ -40,7 +40,7 @@ async def update_admin(user: str, **kwargs) -> Admin:
|
||||
# new_settings = await get_admin()
|
||||
# return new_settings
|
||||
|
||||
async def get_admin() -> List[Admin]:
|
||||
async def get_admin() -> Admin:
|
||||
row = await db.fetchone("SELECT * FROM admin")
|
||||
return Admin(**row) if row else None
|
||||
|
||||
|
||||
@@ -2,93 +2,151 @@ from os import getenv
|
||||
|
||||
from sqlalchemy.exc import OperationalError # type: ignore
|
||||
|
||||
from lnbits.config import conf
|
||||
from lnbits.helpers import urlsafe_short_hash
|
||||
|
||||
|
||||
async def m001_create_admin_table(db):
|
||||
user = None
|
||||
site_title = None
|
||||
site_tagline = None
|
||||
site_description = None
|
||||
allowed_users = None
|
||||
admin_users = None
|
||||
default_wallet_name = None
|
||||
data_folder = None
|
||||
disabled_ext = None
|
||||
force_https = True
|
||||
service_fee = 0
|
||||
funding_source = ""
|
||||
# users/server
|
||||
user = conf.admin_users[0]
|
||||
admin_users = ",".join(conf.admin_users)
|
||||
allowed_users = ",".join(conf.allowed_users)
|
||||
admin_ext = ",".join(conf.admin_ext)
|
||||
disabled_ext = ",".join(conf.disabled_ext)
|
||||
funding_source = conf.funding_source
|
||||
#operational
|
||||
data_folder = conf.data_folder
|
||||
database_url = conf.database_url
|
||||
force_https = conf.force_https
|
||||
service_fee = conf.service_fee
|
||||
hide_api = conf.hide_api
|
||||
denomination = conf.denomination
|
||||
# Theme'ing
|
||||
site_title = conf.site_title
|
||||
site_tagline = conf.site_tagline
|
||||
site_description = conf.site_description
|
||||
default_wallet_name = conf.default_wallet_name
|
||||
theme = ",".join(conf.theme)
|
||||
ad_space = ",".join(conf.ad_space)
|
||||
|
||||
if getenv("LNBITS_SITE_TITLE"):
|
||||
site_title = getenv("LNBITS_SITE_TITLE")
|
||||
# if getenv("LNBITS_ADMIN_EXTENSIONS"):
|
||||
# admin_ext = getenv("LNBITS_ADMIN_EXTENSIONS")
|
||||
|
||||
if getenv("LNBITS_SITE_TAGLINE"):
|
||||
site_tagline = getenv("LNBITS_SITE_TAGLINE")
|
||||
# if getenv("LNBITS_DATABASE_URL"):
|
||||
# database_url = getenv("LNBITS_DATABASE_URL")
|
||||
|
||||
if getenv("LNBITS_SITE_DESCRIPTION"):
|
||||
site_description = getenv("LNBITS_SITE_DESCRIPTION")
|
||||
# if getenv("LNBITS_HIDE_API"):
|
||||
# hide_api = getenv("LNBITS_HIDE_API")
|
||||
|
||||
if getenv("LNBITS_ALLOWED_USERS"):
|
||||
allowed_users = getenv("LNBITS_ALLOWED_USERS")
|
||||
# if getenv("LNBITS_THEME_OPTIONS"):
|
||||
# theme = getenv("LNBITS_THEME_OPTIONS")
|
||||
|
||||
if getenv("LNBITS_ADMIN_USERS"):
|
||||
admin_users = "".join(getenv("LNBITS_ADMIN_USERS").split())
|
||||
user = admin_users.split(',')[0]
|
||||
# if getenv("LNBITS_AD_SPACE"):
|
||||
# ad_space = getenv("LNBITS_AD_SPACE")
|
||||
|
||||
if getenv("LNBITS_DEFAULT_WALLET_NAME"):
|
||||
default_wallet_name = getenv("LNBITS_DEFAULT_WALLET_NAME")
|
||||
# if getenv("LNBITS_SITE_TITLE"):
|
||||
# site_title = getenv("LNBITS_SITE_TITLE")
|
||||
|
||||
if getenv("LNBITS_DATA_FOLDER"):
|
||||
data_folder = getenv("LNBITS_DATA_FOLDER")
|
||||
# if getenv("LNBITS_SITE_TAGLINE"):
|
||||
# site_tagline = getenv("LNBITS_SITE_TAGLINE")
|
||||
|
||||
if getenv("LNBITS_DISABLED_EXTENSIONS"):
|
||||
disabled_ext = getenv("LNBITS_DISABLED_EXTENSIONS")
|
||||
# if getenv("LNBITS_SITE_DESCRIPTION"):
|
||||
# site_description = getenv("LNBITS_SITE_DESCRIPTION")
|
||||
|
||||
if getenv("LNBITS_FORCE_HTTPS"):
|
||||
force_https = getenv("LNBITS_FORCE_HTTPS")
|
||||
# if getenv("LNBITS_ALLOWED_USERS"):
|
||||
# allowed_users = getenv("LNBITS_ALLOWED_USERS")
|
||||
|
||||
if getenv("LNBITS_SERVICE_FEE"):
|
||||
service_fee = getenv("LNBITS_SERVICE_FEE")
|
||||
# if getenv("LNBITS_ADMIN_USERS"):
|
||||
# admin_users = "".join(getenv("LNBITS_ADMIN_USERS").split())
|
||||
# user = admin_users.split(',')[0]
|
||||
|
||||
# if getenv("LNBITS_DEFAULT_WALLET_NAME"):
|
||||
# default_wallet_name = getenv("LNBITS_DEFAULT_WALLET_NAME")
|
||||
|
||||
if getenv("LNBITS_BACKEND_WALLET_CLASS"):
|
||||
funding_source = getenv("LNBITS_BACKEND_WALLET_CLASS")
|
||||
# if getenv("LNBITS_DATA_FOLDER"):
|
||||
# data_folder = getenv("LNBITS_DATA_FOLDER")
|
||||
|
||||
# if getenv("LNBITS_DISABLED_EXTENSIONS"):
|
||||
# disabled_ext = getenv("LNBITS_DISABLED_EXTENSIONS")
|
||||
|
||||
# if getenv("LNBITS_FORCE_HTTPS"):
|
||||
# force_https = getenv("LNBITS_FORCE_HTTPS")
|
||||
|
||||
# if getenv("LNBITS_SERVICE_FEE"):
|
||||
# service_fee = getenv("LNBITS_SERVICE_FEE")
|
||||
|
||||
# if getenv("LNBITS_DENOMINATION"):
|
||||
# denomination = getenv("LNBITS_DENOMINATION", "sats")
|
||||
|
||||
# if getenv("LNBITS_BACKEND_WALLET_CLASS"):
|
||||
# funding_source = getenv("LNBITS_BACKEND_WALLET_CLASS")
|
||||
|
||||
await db.execute(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS admin (
|
||||
"user" TEXT,
|
||||
"user" TEXT PRIMARY KEY,
|
||||
admin_users TEXT,
|
||||
allowed_users TEXT,
|
||||
admin_ext TEXT,
|
||||
disabled_ext TEXT,
|
||||
funding_source TEXT,
|
||||
data_folder TEXT,
|
||||
database_url TEXT,
|
||||
force_https BOOLEAN,
|
||||
service_fee REAL,
|
||||
hide_api BOOLEAN,
|
||||
denomination TEXT,
|
||||
site_title TEXT,
|
||||
site_tagline TEXT,
|
||||
site_description TEXT,
|
||||
admin_users TEXT,
|
||||
allowed_users TEXT,
|
||||
default_wallet_name TEXT,
|
||||
data_folder TEXT,
|
||||
disabled_ext TEXT,
|
||||
force_https BOOLEAN,
|
||||
service_fee REAL,
|
||||
funding_source TEXT
|
||||
theme TEXT,
|
||||
ad_space TEXT
|
||||
);
|
||||
"""
|
||||
)
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO admin ("user", site_title, site_tagline, site_description, admin_users, allowed_users, default_wallet_name, data_folder, disabled_ext, force_https, service_fee, funding_source)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(
|
||||
user.strip(),
|
||||
INSERT INTO admin (
|
||||
"user",
|
||||
admin_users,
|
||||
allowed_users,
|
||||
admin_ext,
|
||||
disabled_ext,
|
||||
funding_source,
|
||||
data_folder,
|
||||
database_url,
|
||||
force_https,
|
||||
service_fee,
|
||||
hide_api,
|
||||
denomination,
|
||||
site_title,
|
||||
site_tagline,
|
||||
site_description,
|
||||
admin_users[1:],
|
||||
allowed_users,
|
||||
default_wallet_name,
|
||||
data_folder,
|
||||
theme,
|
||||
ad_space)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(
|
||||
user,
|
||||
admin_users,
|
||||
allowed_users,
|
||||
admin_ext,
|
||||
disabled_ext,
|
||||
funding_source,
|
||||
data_folder,
|
||||
database_url,
|
||||
force_https,
|
||||
service_fee,
|
||||
funding_source,
|
||||
hide_api,
|
||||
denomination,
|
||||
site_title,
|
||||
site_tagline,
|
||||
site_description,
|
||||
default_wallet_name,
|
||||
theme,
|
||||
ad_space,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ from sqlite3 import Row
|
||||
from typing import List, Optional
|
||||
|
||||
from fastapi import Query
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class UpdateAdminSettings(BaseModel):
|
||||
@@ -19,18 +19,27 @@ class UpdateAdminSettings(BaseModel):
|
||||
funding_source: Optional[str]
|
||||
|
||||
class Admin(BaseModel):
|
||||
# users
|
||||
user: str
|
||||
admin_users: Optional[str]
|
||||
allowed_users: Optional[str]
|
||||
admin_ext: Optional[str]
|
||||
disabled_ext: Optional[str]
|
||||
funding_source: Optional[str]
|
||||
# ops
|
||||
data_folder: Optional[str]
|
||||
database_url: Optional[str]
|
||||
force_https: bool = Field(default=True)
|
||||
service_fee: float = Field(default=0)
|
||||
hide_api: bool = Field(default=False)
|
||||
# Change theme
|
||||
site_title: Optional[str]
|
||||
site_tagline: Optional[str]
|
||||
site_description: Optional[str]
|
||||
allowed_users: Optional[str]
|
||||
admin_users: str
|
||||
default_wallet_name: str
|
||||
data_folder: str
|
||||
disabled_ext: str
|
||||
force_https: Optional[bool] = Query(True)
|
||||
service_fee: float
|
||||
funding_source: str
|
||||
default_wallet_name: Optional[str]
|
||||
denomination: str = Field(default="sats")
|
||||
theme: Optional[str]
|
||||
ad_space: Optional[str]
|
||||
|
||||
@classmethod
|
||||
def from_row(cls, row: Row) -> "Admin":
|
||||
|
||||
@@ -19,15 +19,17 @@ templates = Jinja2Templates(directory="templates")
|
||||
@admin_ext.get("/", response_class=HTMLResponse)
|
||||
async def index(request: Request, user: User = Depends(check_user_exists)):
|
||||
admin = await get_admin()
|
||||
print(g())
|
||||
funding = [f.dict() for f in await get_funding()]
|
||||
|
||||
error, balance = await g().WALLET.status()
|
||||
print("ADMIN", admin.dict())
|
||||
print(g().admin_conf)
|
||||
return admin_renderer().TemplateResponse(
|
||||
"admin/index.html", {
|
||||
"request": request,
|
||||
"user": user.dict(),
|
||||
"admin": admin.dict(),
|
||||
"funding": funding
|
||||
"funding": funding,
|
||||
"settings": g().admin_conf.dict(),
|
||||
"balance": balance
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user