From 75aaf48de7391d5c5353d2c7a3a78982eddbf4c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 5 Sep 2023 15:57:21 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20Make=20invalid=20base=20folders?= =?UTF-8?q?=20visible=20through=20popup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In case of invalid/unusable folder configurations, OctoPrint will roll back to its default so as to not prevent server startup altogether (which would be a big issue for less technical people). However, this creates the problem that unless a user fiddling around with base folder paths actually checks the log and base folder config whether things are still as originally configured, they won't see issues immediately, e.g. caused by network shares not yet being available during OctoPrint's startup. Thus, we now will log such issues not only in the log but will also show a popup to connecting admins, that will inform them about which folders failed their validation and were rolled back. This will only work on the same startup, not following startups, but it should give a bit more heads-ups to people fiddling around with network shares specificially - hopefully. Implements #4881 --- src/octoprint/server/api/system.py | 19 +++++++ src/octoprint/settings/__init__.py | 5 +- src/octoprint/static/js/app/client/system.js | 5 ++ .../static/js/app/viewmodels/system.js | 49 +++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) diff --git a/src/octoprint/server/api/system.py b/src/octoprint/server/api/system.py index 2d927fd1a..2478787ac 100644 --- a/src/octoprint/server/api/system.py +++ b/src/octoprint/server/api/system.py @@ -62,6 +62,25 @@ def getSystemInfo(): return jsonify(systeminfo=systeminfo) +@api.route("/system/startup", methods=["GET"]) +@no_firstrun_access +@Permissions.SYSTEM.require(403) +def getStartupInformation(): + from octoprint.server import safe_mode + from octoprint.settings import settings + + result = {} + + if safe_mode is not None: + result["safe_mode"] = safe_mode + + flagged_basefolders = settings().flagged_basefolders + if flagged_basefolders: + result["flagged_basefolders"] = flagged_basefolders + + return jsonify(startup=result) + + def _usageForFolders(): data = {} for folder_name in s().get(["folder"]).keys(): diff --git a/src/octoprint/settings/__init__.py b/src/octoprint/settings/__init__.py index 84c94db89..8685a6e5c 100644 --- a/src/octoprint/settings/__init__.py +++ b/src/octoprint/settings/__init__.py @@ -494,6 +494,8 @@ class Settings: self._path_update_callbacks = defaultdict(list) self._deprecated_paths = defaultdict(dict) + self.flagged_basefolders = {} + self._init_basedir(basedir) if configfile is not None: @@ -1805,7 +1807,7 @@ class Settings: check_writable=check_writable, deep_check_writable=deep_check_writable, ) - except Exception: + except Exception as exc: if folder != default_folder and allow_fallback: self._logger.exception( "Invalid configured {} folder at {}, attempting to " @@ -1820,6 +1822,7 @@ class Settings: deep_check_writable=deep_check_writable, ) folder = default_folder + self.flagged_basefolders[type] = str(exc) try: self.remove(["folder", type]) diff --git a/src/octoprint/static/js/app/client/system.js b/src/octoprint/static/js/app/client/system.js index 2e95d64a1..796e44566 100644 --- a/src/octoprint/static/js/app/client/system.js +++ b/src/octoprint/static/js/app/client/system.js @@ -8,6 +8,7 @@ var url = "api/system"; var commandUrl = "api/system/commands"; var infoUrl = "api/system/info"; + var startupUrl = "api/system/startup"; var OctoPrintSystemClient = function (base) { this.base = base; @@ -29,6 +30,10 @@ return this.base.get(infoUrl, opts); }; + OctoPrintSystemClient.prototype.getStartupData = function (opts) { + return this.base.get(startupUrl, opts); + }; + OctoPrintClient.registerComponent("system", OctoPrintSystemClient); return OctoPrintSystemClient; }); diff --git a/src/octoprint/static/js/app/viewmodels/system.js b/src/octoprint/static/js/app/viewmodels/system.js index 365602cb2..d54991378 100644 --- a/src/octoprint/static/js/app/viewmodels/system.js +++ b/src/octoprint/static/js/app/viewmodels/system.js @@ -8,8 +8,11 @@ $(function () { self.lastCommandResponse = undefined; self.systemActions = ko.observableArray([]); + self._startupNotification = undefined; + self.requestData = function () { self.requestCommandData(); + self.requestStartupData(); }; self.requestCommandData = function () { @@ -52,6 +55,52 @@ $(function () { self.systemActions(actions); }; + self.requestStartupData = function () { + if (!self.loginState.hasPermission(self.access.permissions.SYSTEM)) { + return $.Deferred().reject().promise(); + } + + return OctoPrint.system.getStartupData().done(self.fromStartupResponse); + }; + + self.fromStartupResponse = function (response) { + const startupData = response.startup; + + if (startupData.flagged_basefolders) { + if (self._startupNotification) self._startupNotification.remove(); + + let html = + "

" + + gettext( + "The following folder(s) were found to be unusable by OctoPrint during startup and have been turned back to the default:" + ) + + "

"; + html += ""; + html += + "

" + + gettext( + "Please check the permissions of these folders and make sure they are writable by the user running OctoPrint. In case of network shares, make sure they have been mounted before OctoPrint starts." + ) + + "

"; + + self._startupNotification = new PNotify({ + title: gettext("Warning"), + text: html, + type: "warning", + hide: false + }); + } + }; + self.triggerCommand = function (commandSpec) { if (!self.loginState.hasPermission(self.access.permissions.SYSTEM)) { return $.Deferred().reject().promise();