diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index a74e85f9..d00d22cf 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -17,7 +17,7 @@ from . import version_checks, updaters, exceptions, util from octoprint.server.util.flask import restricted_access -from octoprint.server import admin_permission, user_permission +from octoprint.server import admin_permission from octoprint.util import dict_merge import octoprint.settings @@ -43,8 +43,6 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, def refresh_checks(name, plugin): self._refresh_configured_checks = True - self._send_client_message("update_versions") - self._plugin_lifecycle_manager.add_callback("enabled", refresh_checks) self._plugin_lifecycle_manager.add_callback("disabled", refresh_checks) @@ -94,8 +92,6 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, #~~ BluePrint API @octoprint.plugin.BlueprintPlugin.route("/check", methods=["GET"]) - @restricted_access - @user_permission.require(403) def check_for_update(self): if "check" in flask.request.values: check_targets = map(str.strip, flask.request.values["check"].split(",")) @@ -105,7 +101,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, if "force" in flask.request.values and flask.request.values["force"] in octoprint.settings.valid_boolean_trues: force = True else: - force = False + force=False try: information, update_available, update_possible = self.get_current_versions(check_targets=check_targets, force=force) @@ -132,8 +128,9 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, else: check_targets = None - if "force" in json_data and json_data["force"] in octoprint.settings.valid_boolean_trues: - force = True + if "force" in json_data: + from octoprint.settings import valid_boolean_trues + force = (json_data["force"] in valid_boolean_trues) else: force = False @@ -385,7 +382,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, if target in checks: # TODO make this cleaner, right now it saves too much to disk checks[target]["current"] = target_version - self._settings.set(["checks", target], checks[target]) + self._settings.set(["checks"], checks) # we have to save here (even though that makes us save quite often) since otherwise the next # load will overwrite our changes we just made diff --git a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js index cf5cd7f8..74472574 100644 --- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js @@ -89,82 +89,6 @@ $(function() { self.config_cacheTtl(self.settings.settings.plugins.softwareupdate.cache_ttl()); }; - self.fromCheckResponse = function(data) { - var versions = []; - _.each(data.information, function(value, key) { - value["key"] = key; - - if (!value.hasOwnProperty("displayName") || value.displayName == "") { - value.displayName = value.key; - } - if (!value.hasOwnProperty("displayVersion") || value.displayVersion == "") { - value.displayVersion = value.information.local.name; - } - - versions.push(value); - }); - self.versions.updateItems(versions); - - if (data.status == "updateAvailable" || data.status == "updatePossible") { - var text = gettext("There are updates available for the following components:"); - - text += ""; - - text += "" + gettext("Those components marked with can be updated directly.") + ""; - - var options = { - title: gettext("Update Available"), - text: text, - hide: false - }; - var eventListeners = {}; - - if (data.status == "updatePossible" && self.loginState.isAdmin()) { - // if user is admin, add action buttons - options["confirm"] = { - confirm: true, - buttons: [{ - text: gettext("Ignore"), - click: function() { - self._markNotificationAsSeen(data.information); - self._showPopup({ - text: gettext("You can make this message display again via \"Settings\" > \"SoftwareUpdate\" > \"Check for update now\"") - }); - } - }, { - text: gettext("Update now"), - addClass: "btn-primary", - click: self.update - }] - }; - options["buttons"] = { - closer: false, - sticker: false - }; - } - - if (ignoreSeen || !self._hasNotificationBeenSeen(data.information)) { - self._showPopup(options, eventListeners); - } - } else if (data.status == "current" && showIfNothingNew) { - self._showPopup({ - title: gettext("Everything is up-to-date"), - hide: false, - type: "success" - }); - } - }; - self.performCheck = function(showIfNothingNew, force, ignoreSeen) { if (!self.loginState.isUser()) return; @@ -177,7 +101,81 @@ $(function() { url: url, type: "GET", dataType: "json", - success: self.fromCheckResponse + success: function(data) { + var versions = []; + _.each(data.information, function(value, key) { + value["key"] = key; + + if (!value.hasOwnProperty("displayName") || value.displayName == "") { + value.displayName = value.key; + } + if (!value.hasOwnProperty("displayVersion") || value.displayVersion == "") { + value.displayVersion = value.information.local.name; + } + + versions.push(value); + }); + self.versions.updateItems(versions); + + if (data.status == "updateAvailable" || data.status == "updatePossible") { + var text = gettext("There are updates available for the following components:"); + + text += ""; + + text += "" + gettext("Those components marked with can be updated directly.") + ""; + + var options = { + title: gettext("Update Available"), + text: text, + hide: false + }; + var eventListeners = {}; + + if (data.status == "updatePossible" && self.loginState.isAdmin()) { + // if user is admin, add action buttons + options["confirm"] = { + confirm: true, + buttons: [{ + text: gettext("Ignore"), + click: function() { + self._markNotificationAsSeen(data.information); + self._showPopup({ + text: gettext("You can make this message display again via \"Settings\" > \"SoftwareUpdate\" > \"Check for update now\"") + }); + } + }, { + text: gettext("Update now"), + addClass: "btn-primary", + click: self.update + }] + }; + options["buttons"] = { + closer: false, + sticker: false + }; + } + + if (ignoreSeen || !self._hasNotificationBeenSeen(data.information)) { + self._showPopup(options, eventListeners); + } + } else if (data.status == "current" && showIfNothingNew) { + self._showPopup({ + title: gettext("Everything is up-to-date"), + hide: false, + type: "success" + }); + } + } }); }; @@ -423,10 +421,6 @@ $(function() { self.updateInProgress = false; break; } - case "update_versions": { - self.performCheck(); - break; - } } if (options != undefined) {