✨ SWU: Offer to update in first run wizard
This will now be the very first step of the first run wizard, IF OctoPrint is detected as outdated. Implements #3936
This commit is contained in:
1 parent
32a52bdb0f
commit
5cde163f2b
5 files changed
+95
-17
No files matched your search
@@ -637,6 +637,17 @@ class SoftwareUpdatePlugin(
|
||||
if save:
|
||||
self._save_update_log()
|
||||
|
||||
def _is_octoprint_outdated_and_can_update(self):
|
||||
information, update_available, update_possible = self.get_current_versions()
|
||||
if not update_available or not update_possible or "octoprint" not in information:
|
||||
return False
|
||||
|
||||
octoprint_information = information["octoprint"]
|
||||
return (
|
||||
octoprint_information["updateAvailable"]
|
||||
and octoprint_information["updatePossible"]
|
||||
)
|
||||
|
||||
# ~~ SettingsPlugin API
|
||||
|
||||
def get_settings_defaults(self):
|
||||
@@ -1089,9 +1100,13 @@ class SoftwareUpdatePlugin(
|
||||
)(view)()
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/check", methods=["GET"])
|
||||
@no_firstrun_access
|
||||
@Permissions.PLUGIN_SOFTWAREUPDATE_CHECK.require(403)
|
||||
def check_for_update(self):
|
||||
if (
|
||||
not Permissions.PLUGIN_SOFTWAREUPDATE_CHECK.can()
|
||||
and not self._settings.global_get(["server", "firstRun"])
|
||||
):
|
||||
flask.abort(403)
|
||||
|
||||
request_data = flask.request.values
|
||||
|
||||
if "targets" in request_data or "check" in request_data:
|
||||
@@ -1241,9 +1256,13 @@ class SoftwareUpdatePlugin(
|
||||
)(view)()
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/update", methods=["POST"])
|
||||
@no_firstrun_access
|
||||
@Permissions.PLUGIN_SOFTWAREUPDATE_UPDATE.require(403)
|
||||
def perform_update(self):
|
||||
if (
|
||||
not Permissions.PLUGIN_SOFTWAREUPDATE_UPDATE.can()
|
||||
and not self._settings.global_get(["server", "firstRun"])
|
||||
):
|
||||
flask.abort(403)
|
||||
|
||||
throttled = self._get_throttled()
|
||||
if (
|
||||
throttled
|
||||
@@ -1394,20 +1413,49 @@ class SoftwareUpdatePlugin(
|
||||
def get_template_configs(self):
|
||||
from flask_babel import gettext
|
||||
|
||||
return [{"type": "settings", "name": gettext("Software Update")}]
|
||||
templates = [
|
||||
{"type": "settings", "name": gettext("Software Update")},
|
||||
]
|
||||
|
||||
if self._is_wizard_update_required():
|
||||
templates.append(
|
||||
{
|
||||
"type": "wizard",
|
||||
"name": gettext("Update?"),
|
||||
"template": "softwareupdate_wizard_update.jinja2",
|
||||
"suffix": "_update",
|
||||
}
|
||||
)
|
||||
|
||||
if self._is_settings_wizard_required():
|
||||
templates.append(
|
||||
{
|
||||
"type": "wizard",
|
||||
"name": gettext("Software Update"),
|
||||
"template": "softwareupdate_wizard_settings.jinja2",
|
||||
"suffix": "_settings",
|
||||
}
|
||||
)
|
||||
|
||||
return templates
|
||||
|
||||
##~~ WizardPlugin API
|
||||
|
||||
def is_wizard_required(self):
|
||||
def _is_wizard_update_required(self):
|
||||
firstrun = self._settings.global_get(["server", "firstRun"])
|
||||
return firstrun and self._is_octoprint_outdated_and_can_update()
|
||||
|
||||
def _is_settings_wizard_required(self):
|
||||
checks = self._get_configured_checks()
|
||||
check = checks.get("octoprint", None)
|
||||
checkout_folder = self._get_octoprint_checkout_folder(checks=checks)
|
||||
return (
|
||||
check
|
||||
and "method" in check
|
||||
and check["method"] == "update_script"
|
||||
and not checkout_folder
|
||||
)
|
||||
return check and check.get("method") == "update_script" and not checkout_folder
|
||||
|
||||
def is_wizard_required(self):
|
||||
return self._is_wizard_update_required() or self._is_settings_wizard_required()
|
||||
|
||||
def get_wizard_version(self):
|
||||
return 1
|
||||
|
||||
##~~ EventHandlerPlugin API
|
||||
|
||||
@@ -1442,6 +1490,8 @@ class SoftwareUpdatePlugin(
|
||||
if check_targets is None:
|
||||
check_targets = list(checks.keys())
|
||||
|
||||
# TODO: caching doesn't take check_targets into account!
|
||||
|
||||
update_available = False
|
||||
update_possible = False
|
||||
information = {}
|
||||
|
||||
@@ -130,6 +130,13 @@ $(function () {
|
||||
[],
|
||||
0
|
||||
);
|
||||
|
||||
self.octoprintData = {
|
||||
item: undefined,
|
||||
current: ko.observable("unknown"),
|
||||
available: ko.observable("unknown")
|
||||
};
|
||||
|
||||
self.updatelog = ko.observableArray([]);
|
||||
|
||||
self.availableAndPossible = ko.pureComputed(function () {
|
||||
@@ -361,6 +368,12 @@ $(function () {
|
||||
});
|
||||
};
|
||||
|
||||
if (key === "octoprint") {
|
||||
self.octoprintData.item = value;
|
||||
self.octoprintData.current(value.information.local.name);
|
||||
self.octoprintData.available(value.information.remote.name);
|
||||
}
|
||||
|
||||
versions.push(value);
|
||||
});
|
||||
self.versions.updateItems(versions);
|
||||
@@ -671,8 +684,10 @@ $(function () {
|
||||
|
||||
self.performUpdate = function (force, items) {
|
||||
if (
|
||||
!self.loginState.hasPermission(
|
||||
self.access.permissions.PLUGIN_SOFTWAREUPDATE_UPDATE
|
||||
!(
|
||||
self.loginState.hasPermission(
|
||||
self.access.permissions.PLUGIN_SOFTWAREUPDATE_UPDATE
|
||||
) || CONFIG_FIRST_RUN
|
||||
)
|
||||
)
|
||||
return;
|
||||
@@ -735,8 +750,10 @@ $(function () {
|
||||
self.update = function (force, items) {
|
||||
if (
|
||||
self.updateInProgress ||
|
||||
!self.loginState.hasPermission(
|
||||
self.access.permissions.PLUGIN_SOFTWAREUPDATE_UPDATE
|
||||
!(
|
||||
self.loginState.hasPermission(
|
||||
self.access.permissions.PLUGIN_SOFTWAREUPDATE_UPDATE
|
||||
) || CONFIG_FIRST_RUN
|
||||
)
|
||||
) {
|
||||
self._updateClicked = false;
|
||||
@@ -1154,7 +1171,8 @@ $(function () {
|
||||
elements: [
|
||||
"#settings_plugin_softwareupdate",
|
||||
"#softwareupdate_confirmation_dialog",
|
||||
"#wizard_plugin_softwareupdate"
|
||||
"#wizard_plugin_softwareupdate_update",
|
||||
"#wizard_plugin_softwareupdate_settings"
|
||||
]
|
||||
});
|
||||
});
|
||||
File renamed without changes.
@@ -0,0 +1,9 @@
|
||||
<h3>{{ _('Update?') }}</h3>
|
||||
|
||||
{% trans %}<p>
|
||||
You are about to set up OctoPrint <span data-bind="text: octoprintData.current"></span>
|
||||
but <span data-bind="text: octoprintData.available"></span> is available. It is strongly
|
||||
recommended to update to the latest version before you continue.
|
||||
</p>{% endtrans %}
|
||||
|
||||
<a href="javascript:void(0)" data-bind="click: function() { $root.update(false, [$root.octoprintData.item]) }" class="btn btn-primary btn-block">{{ _('Update') }}</a>
|
||||
@@ -382,6 +382,7 @@ default_settings = {
|
||||
],
|
||||
"usersettings": ["access", "interface"],
|
||||
"wizard": [
|
||||
"plugin_softwareupdate_update",
|
||||
"plugin_backup",
|
||||
"plugin_corewizard_acl",
|
||||
"plugin_corewizard_onlinecheck",
|
||||
|
||||
Reference in new issue
Block a user