summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2022-02-19 22:19:57 +0800
committerFrederick Yin <fkfd@fkfd.me>2022-02-19 22:19:57 +0800
commitf2194946f34e5b3259430ffaed72dc658123a46a (patch)
tree49a8f696956d1fb200523c4439b11d357b434c4f
parentc1055feea07781fb33624b278e2b21811718aa19 (diff)
Logger.read_admin/tenant
-rw-r--r--jimbrella/admin.py6
-rw-r--r--jimbrella/logger.py14
2 files changed, 13 insertions, 7 deletions
diff --git a/jimbrella/admin.py b/jimbrella/admin.py
index 9d7d98b..f0b2f69 100644
--- a/jimbrella/admin.py
+++ b/jimbrella/admin.py
@@ -3,7 +3,7 @@ from user_agents import parse as user_agent
from datetime import datetime
from dateutil.parser import isoparse
from .umbrellas import Umbrellas
-from .admin_log import AdminLog
+from .logger import Logger
from .users import Users
from .exceptions import *
from .config import config
@@ -12,7 +12,7 @@ from .utils import human_datetime, human_timedelta, CST
bp = Blueprint("admin", __name__, url_prefix="/admin")
db = Umbrellas(config.get("general", "db_path"))
users = Users(config.get("general", "db_path"))
-admin_log = AdminLog(config.get("general", "db_path"))
+logger = Logger(config.get("general", "db_path"))
@bp.before_request
@@ -131,5 +131,5 @@ def umbrellas_edit():
@bp.route("/logs")
def logs():
- logs = admin_log.read()
+ logs = logger.read_admin()
return render_template("admin/admin_logs.html", logs=logs)
diff --git a/jimbrella/logger.py b/jimbrella/logger.py
index dc5f83c..e3d5f62 100644
--- a/jimbrella/logger.py
+++ b/jimbrella/logger.py
@@ -12,23 +12,29 @@ class Logger:
"""
self.path = path
- def read(self, maxlogs=20, serial=None) -> Union[dict, list]:
+ def read(self, table, maxlogs=20, serial=None) -> Union[dict, list]:
db = sqlite3.connect(self.path)
db.row_factory = sqlite3.Row
if serial is None:
- data = db.execute("SELECT * FROM AdminLog ORDER BY serial DESC").fetchmany(
+ data = db.execute(f"SELECT * FROM {table} ORDER BY serial DESC").fetchmany(
maxlogs
)
else:
data = db.execute(
- "SELECT * FROM AdminLog WHERE serial = ?", (serial,)
+ f"SELECT * FROM {table} WHERE serial = ?", (serial,)
).fetchone()
db.close()
return data
+ def read_admin(self, maxlogs=20, serial=None) -> Union[dict, list]:
+ return self.read("AdminLog", maxlogs, serial)
+
+ def read_tenant(self, maxlogs=20, serial=None) -> Union[dict, list]:
+ return self.read("TenantLog", maxlogs, serial)
+
def log_admin(
- self, date: str, actor: str, umumbbid: int, umb_a: dict, umb_b: dict, note=""
+ self, date: str, actor: str, umbid: int, umb_a: dict, umb_b: dict, note=""
) -> None:
"""Logs admin operations in a database so they can be recalled and possibly undone.