diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index 9039c0121..98727b3ff 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -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 = {} diff --git a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js index 4547b3eba..11eee8226 100644 --- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js @@ -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" ] }); }); diff --git a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_wizard.jinja2 b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_wizard_settings.jinja2 similarity index 100% rename from src/octoprint/plugins/softwareupdate/templates/softwareupdate_wizard.jinja2 rename to src/octoprint/plugins/softwareupdate/templates/softwareupdate_wizard_settings.jinja2 diff --git a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_wizard_update.jinja2 b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_wizard_update.jinja2 new file mode 100644 index 000000000..6c3f77080 --- /dev/null +++ b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_wizard_update.jinja2 @@ -0,0 +1,9 @@ +

{{ _('Update?') }}

+ +{% trans %}

+ You are about to set up OctoPrint + but is available. It is strongly + recommended to update to the latest version before you continue. +

{% endtrans %} + +{{ _('Update') }} diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 7841c03a3..2015d0e5e 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -382,6 +382,7 @@ default_settings = { ], "usersettings": ["access", "interface"], "wizard": [ + "plugin_softwareupdate_update", "plugin_backup", "plugin_corewizard_acl", "plugin_corewizard_onlinecheck",