Make the Web object load from mode settings instead of global settings

This commit is contained in:
Micah Lee 2019-11-02 14:35:51 -07:00
parent 1b635b1646
commit 30df0c4bd8
6 changed files with 10 additions and 16 deletions

View file

@ -292,7 +292,7 @@ class ReceiveModeRequest(Request):
date_dir = now.strftime("%Y-%m-%d") date_dir = now.strftime("%Y-%m-%d")
time_dir = now.strftime("%H.%M.%S") time_dir = now.strftime("%H.%M.%S")
self.receive_mode_dir = os.path.join( self.receive_mode_dir = os.path.join(
self.web.common.settings.get("data_dir"), date_dir, time_dir self.web.settings.get("website", "data_dir"), date_dir, time_dir
) )
# Create that directory, which shouldn't exist yet # Create that directory, which shouldn't exist yet

View file

@ -18,8 +18,8 @@ class ShareModeWeb(SendBaseModeWeb):
self.common.log("ShareModeWeb", "init") self.common.log("ShareModeWeb", "init")
# Allow downloading individual files if "Stop sharing after files have been sent" is unchecked # Allow downloading individual files if "Stop sharing after files have been sent" is unchecked
self.download_individual_files = not self.common.settings.get( self.download_individual_files = not self.web.settings.get(
"close_after_first_download" "share", "autostop_sharing"
) )
def define_routes(self): def define_routes(self):

View file

@ -60,9 +60,7 @@ class Web:
REQUEST_OTHER = 13 REQUEST_OTHER = 13
REQUEST_INVALID_PASSWORD = 14 REQUEST_INVALID_PASSWORD = 14
def __init__( def __init__(self, common, is_gui, mode_settings, mode="share"):
self, common, is_gui, tab_settings_get=None, tab_settings_set=None, mode="share"
):
""" """
tab_settings_get and tab_settings_set are getter and setter functions for tab settings tab_settings_get and tab_settings_set are getter and setter functions for tab settings
""" """
@ -70,8 +68,7 @@ class Web:
self.common = common self.common = common
self.common.log("Web", "__init__", f"is_gui={is_gui}, mode={mode}") self.common.log("Web", "__init__", f"is_gui={is_gui}, mode={mode}")
self.settings_get = tab_settings_get self.settings = mode_settings
self.settings_set = tab_settings_set
# The flask app # The flask app
self.app = Flask( self.app = Flask(
@ -195,7 +192,7 @@ class Web:
return None return None
# If public mode is disabled, require authentication # If public mode is disabled, require authentication
if not self.common.settings.get("public_mode"): if not self.settings.get("general", "public"):
@self.auth.login_required @self.auth.login_required
def _check_login(): def _check_login():
@ -293,10 +290,7 @@ class Web:
for header, value in self.security_headers: for header, value in self.security_headers:
r.headers.set(header, value) r.headers.set(header, value)
# Set a CSP header unless in website mode and the user has disabled it # Set a CSP header unless in website mode and the user has disabled it
if ( if not self.settings.get("website", "disable_csp") or self.mode != "website":
not self.common.settings.get("csp_header_disabled")
or self.mode != "website"
):
r.headers.set( r.headers.set(
"Content-Security-Policy", "Content-Security-Policy",
"default-src 'self'; style-src 'self'; script-src 'self'; img-src 'self' data:;", "default-src 'self'; style-src 'self'; script-src 'self'; img-src 'self' data:;",

View file

@ -36,7 +36,7 @@ class ReceiveMode(Mode):
Custom initialization for ReceiveMode. Custom initialization for ReceiveMode.
""" """
# Create the Web object # Create the Web object
self.web = Web(self.common, True, "receive") self.web = Web(self.common, True, self.settings, "receive")
# Header # Header
self.header_label.setText(strings._("gui_new_tab_receive_button")) self.header_label.setText(strings._("gui_new_tab_receive_button"))

View file

@ -45,7 +45,7 @@ class ShareMode(Mode):
self.compress_thread = None self.compress_thread = None
# Create the Web object # Create the Web object
self.web = Web(self.common, True, "share") self.web = Web(self.common, True, self.settings, "share")
# Header # Header
self.header_label.setText(strings._("gui_new_tab_share_button")) self.header_label.setText(strings._("gui_new_tab_share_button"))

View file

@ -47,7 +47,7 @@ class WebsiteMode(Mode):
Custom initialization for ReceiveMode. Custom initialization for ReceiveMode.
""" """
# Create the Web object # Create the Web object
self.web = Web(self.common, True, "website") self.web = Web(self.common, True, self.settings, "website")
# Header # Header
self.header_label.setText(strings._("gui_new_tab_website_button")) self.header_label.setText(strings._("gui_new_tab_website_button"))