From 98133c0c3cf7e401cf5b85f7c4e9298bfcb4d00a Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Wed, 24 Nov 2021 19:48:40 +0800 Subject: New config entry "jimbrella_dir" Add explanation for jimbrella_dir --- config.toml | 2 ++ jimbrella/admin.py | 2 +- jimbrella/config.py | 17 ++++++++++------- jimbrella/lockfile.py | 4 ++-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/config.toml b/config.toml index b38abdc..a5e45ac 100644 --- a/config.toml +++ b/config.toml @@ -1,3 +1,5 @@ +# "Root" directory for JImbrella +# All local paths below are relative to this directory jimbrella_dir = "/opt/jimbrella" [flask] diff --git a/jimbrella/admin.py b/jimbrella/admin.py index eaf0e54..49cbf55 100644 --- a/jimbrella/admin.py +++ b/jimbrella/admin.py @@ -17,7 +17,7 @@ def check_privilege(): # only clients who have obtained a session and sent it in the Cookie header # will have a decryptable username here if "username" not in session: - return redirect(url_for("auth.login")) + return redirect(url_for("auth.auth", action="login")) username = session["username"] user = users.find(username) # under normal circumstances it must exist diff --git a/jimbrella/config.py b/jimbrella/config.py index dd4aa00..48265e9 100644 --- a/jimbrella/config.py +++ b/jimbrella/config.py @@ -1,4 +1,5 @@ import os +from pathlib import Path import toml config_path = ( @@ -11,18 +12,20 @@ f = open(config_path) config = toml.load(f) f.close() +JIMBRELLA_DIR = Path(config["jimbrella_dir"]) + FLASK_SECRET_KEY = config["flask"]["secret_key"] ACCEPT_NEW_USERS = config["user"]["accept_new_users"] -JFORM_TAKEAWAY_URL = config["jform"]["takeaway_url"] -JFORM_GIVEBACK_URL = config["jform"]["giveback_url"] -JFORM_BOOKMARK_DIR = config["jform"]["bookmark_dir"] +JFORM_TAKEAWAY_URL = JIMBRELLA_DIR / Path(config["jform"]["takeaway_url"]) +JFORM_GIVEBACK_URL = JIMBRELLA_DIR / Path(config["jform"]["giveback_url"]) +JFORM_BOOKMARK_DIR = JIMBRELLA_DIR / Path(config["jform"]["bookmark_dir"]) -DATABASE_PATH = config["db"]["db_path"] -USERS_PATH = config["db"]["users_path"] +DATABASE_PATH = JIMBRELLA_DIR / Path(config["db"]["db_path"]) +USERS_PATH = JIMBRELLA_DIR / Path(config["db"]["users_path"]) DUE_HOURS = config["rules"]["due_hours"] -LOG_PATH = config["logging"]["log_path"] -ADMIN_LOG_PATH = config["logging"]["admin_log_path"] +LOG_PATH = JIMBRELLA_DIR / Path(config["logging"]["log_path"]) +ADMIN_LOG_PATH = JIMBRELLA_DIR / Path(config["logging"]["admin_log_path"]) diff --git a/jimbrella/lockfile.py b/jimbrella/lockfile.py index b898142..987f0e3 100644 --- a/jimbrella/lockfile.py +++ b/jimbrella/lockfile.py @@ -11,8 +11,8 @@ class Lockfile: """ def __init__(self, filepath): - self.filepath = filepath - self.lockpath = filepath + ".lock" + self.filepath = str(filepath) + self.lockpath = self.filepath + ".lock" def lock(self): """Continue attempting to lock until locked.""" -- cgit v1.2.3