diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index b3a0b7f3..e35356fa 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -213,6 +213,8 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, "check_providers": {}, "cache_ttl": 24 * 60, + + "notify_users": True } def on_settings_load(self): @@ -260,7 +262,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, def on_settings_save(self, data): for key in self.get_settings_defaults(): - if key in ("checks", "cache_ttl", "octoprint_checkout_folder", "octoprint_type", "octoprint_release_channel"): + if key in ("checks", "cache_ttl", "notify_user", "octoprint_checkout_folder", "octoprint_type", "octoprint_release_channel"): continue if key in data: self._settings.set([key], data[key]) @@ -269,6 +271,9 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, self._settings.set_int(["cache_ttl"], data["cache_ttl"]) self._version_cache_ttl = self._settings.get_int(["cache_ttl"]) * 60 + if "notify_users" in data: + self._settings.set_boolean(["notify_users"], data["notify_users"]) + checks = self._get_configured_checks() if "octoprint" in checks: check = checks["octoprint"] diff --git a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js index 019b4240..62bd0003 100644 --- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js @@ -112,6 +112,7 @@ $(function() { self.octoprintUnreleased = ko.observable(); self.config_cacheTtl = ko.observable(); + self.config_notifyUsers = ko.observable(); self.config_checkoutFolder = ko.observable(); self.config_checkType = ko.observable(); self.config_updateMethod = ko.observable(); @@ -153,9 +154,20 @@ $(function() { self.performCheck(); }; - self._showPopup = function(options, eventListeners) { + self.onUserLoggedOut = function() { self._closePopup(); - self.popup = new PNotify(options); + }; + + self._showPopup = function(options, eventListeners, singleButtonNotify) { + singleButtonNotify = singleButtonNotify || false; + + self._closePopup(); + + if (singleButtonNotify) { + self.popup = PNotify.singleButtonNotify(options); + } else { + self.popup = new PNotify(options); + } if (eventListeners) { var popupObj = self.popup.get(); @@ -192,6 +204,7 @@ $(function() { plugins: { softwareupdate: { cache_ttl: parseInt(self.config_cacheTtl()), + notify_users: self.config_notifyUsers(), octoprint_checkout_folder: self.config_checkoutFolder(), octoprint_type: self.config_checkType(), octoprint_release_channel: self.config_releaseChannel() @@ -231,6 +244,7 @@ $(function() { self.config_updateMethod(updateMethod); self.config_cacheTtl(self.settings.settings.plugins.softwareupdate.cache_ttl()); + self.config_notifyUsers(self.settings.settings.plugins.softwareupdate.notify_users()); self.config_checkoutFolder(self.settings.settings.plugins.softwareupdate.octoprint_checkout_folder()); self.config_checkType(self.settings.settings.plugins.softwareupdate.octoprint_type()); self.config_releaseChannel(self.settings.settings.plugins.softwareupdate.octoprint_release_channel()); @@ -288,6 +302,8 @@ $(function() { } } + if (!self.loginState.isAdmin() && !self.settings.settings.plugins.softwareupdate.notify_users()) return; + if (data.status == "updateAvailable" || data.status == "updatePossible") { var text = "
" + gettext("There are updates available for the following components:"); @@ -303,7 +319,11 @@ $(function() { }); text += ""; - text += "" + gettext("Those components marked with can be updated directly.") + ""; + text += "

" + gettext("Those components marked with can be updated directly.") + "

"; + + if (!self.loginState.isAdmin()) { + text += "

" + gettext("To have updates applied, get in touch with an administrator of this OctoPrint instance.") + "

"; + } text += "
"; @@ -314,8 +334,9 @@ $(function() { }; var eventListeners = {}; + var singleButtonNotify = false; if (data.status == "updatePossible" && self.loginState.isAdmin()) { - // if user is admin, add action buttons + // if update is possible and user is admin, add action buttons for ignore and update options["confirm"] = { confirm: true, buttons: [{ @@ -336,10 +357,27 @@ $(function() { closer: false, sticker: false }; + } else { + // if update is not possible or user is not admin, only add ignore button + options["confirm"] = { + confirm: true, + buttons: [{ + text: gettext("Ignore"), + click: function(notice) { + notice.remove(); + self._markNotificationAsSeen(data.information); + } + }] + }; + options["buttons"] = { + closer: false, + sticker: false + }; + singleButtonNotify = true; } if ((ignoreSeen || !self._hasNotificationBeenSeen(data.information)) && !OctoPrint.coreui.wizardOpen) { - self._showPopup(options, eventListeners); + self._showPopup(options, eventListeners, singleButtonNotify); } } else if (data.status == "current") { if (showIfNothingNew) { @@ -355,7 +393,8 @@ $(function() { }; self.performCheck = function(showIfNothingNew, force, ignoreSeen) { - if (!self.loginState.isUser()) return; + if (!self.loginState.isAdmin() && !self.settings.settings.plugins.softwareupdate.notify_users()) return; + self.checking(true); OctoPrint.plugins.softwareupdate.check(force) .done(function(data) { @@ -369,7 +408,18 @@ $(function() { self._markNotificationAsSeen = function(data) { if (!Modernizr.localstorage) return false; - localStorage["plugin.softwareupdate.seen_information"] = JSON.stringify(self._informationToRemoteVersions(data)); + if (!self.loginState.isUser()) + return false; + + var currentString = localStorage["plugin.softwareupdate.seen_information"]; + var current; + if (currentString === undefined) { + current = {}; + } else { + current = JSON.parse(currentString); + } + current[self.loginState.username()] = self._informationToRemoteVersions(data); + localStorage["plugin.softwareupdate.seen_information"] = JSON.stringify(current); }; self._hasNotificationBeenSeen = function(data) { @@ -380,11 +430,19 @@ $(function() { return false; var knownData = JSON.parse(localStorage["plugin.softwareupdate.seen_information"]); + + if (!self.loginState.isUser()) + return true; + + var userData = knownData[self.loginState.username()]; + if (userData === undefined) + return false; + var freshData = self._informationToRemoteVersions(data); var hasBeenSeen = true; _.each(freshData, function(value, key) { - if (!_.has(knownData, key) || knownData[key] != freshData[key]) { + if (!_.has(userData, key) || userData[key] != freshData[key]) { hasBeenSeen = false; } }); @@ -400,6 +458,8 @@ $(function() { }; self.performUpdate = function(force, items) { + if (!self.loginState.isAdmin()) return; + self.updateInProgress = true; var options = { diff --git a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 index 27adb7e6..85763090 100644 --- a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 +++ b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 @@ -86,6 +86,14 @@ +
+
+ +
+