🚸 Make invalid base folders visible through popup
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
This commit is contained in:
1 parent
9712deca34
commit
75aaf48de7
4 files changed
+77
-1
No files matched your search
@@ -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():
|
||||
|
||||
@@ -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])
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
@@ -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 =
|
||||
"<p>" +
|
||||
gettext(
|
||||
"The following folder(s) were found to be unusable by OctoPrint during startup and have been turned back to the default:"
|
||||
) +
|
||||
"</p>";
|
||||
html += "<ul>";
|
||||
_.each(startupData.flagged_basefolders, (value, key) => {
|
||||
html +=
|
||||
"<li><code>" +
|
||||
_.escape(key) +
|
||||
"</code>: " +
|
||||
_.escape(value) +
|
||||
"</li>";
|
||||
});
|
||||
html += "</ul>";
|
||||
html +=
|
||||
"<p>" +
|
||||
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 <em>before</em> OctoPrint starts."
|
||||
) +
|
||||
"</p>";
|
||||
|
||||
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();
|
||||
|
||||
Reference in new issue
Block a user