Allow users to ignore update notification & setting to disable outright

Old default behaviour of showing logged in users the update
notification stays default, but can now be disabled via the software
update plugin settings.

Additionally added the ignore button to the notification for users as
well (and made ignore entry in local storage user specific to still
show notification to other logged in users), plus a small hint that
in order to apply updates an admin is needed. Additionally now hiding
the notification on log out.

Closes #1739
This commit is contained in:
Gina Häußge committed 2017-03-29 14:47:49 +02:00
1 parent e97c9f954d
commit fda67f48ff
3 files changed
+82 -9

No files matched your search

@@ -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"]
@@ -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 = "<div class='softwareupdate_notification'>" + gettext("There are updates available for the following components:");
@@ -303,7 +319,11 @@ $(function() {
});
text += "</ul>";
text += "<small>" + gettext("Those components marked with <i class=\"icon-ok\"></i> can be updated directly.") + "</small>";
text += "<p><small>" + gettext("Those components marked with <i class=\"icon-ok\"></i> can be updated directly.") + "</small></p>";
if (!self.loginState.isAdmin()) {
text += "<p><small>" + gettext("To have updates applied, get in touch with an administrator of this OctoPrint instance.") + "</small></p>";
}
text += "</div>";
@@ -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 = {
@@ -86,6 +86,14 @@
</div>
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: config_notifyUsers"> {{ _('Show update notifications to users') }}
<span class="help-block">{{ _('If you uncheck this, only logged in admins will see update notifications. Update notifications shown to users do not include the "Update now" button.') }}</span>
</label>
</div>
</div>
</form>
</div>
<div class="modal-footer">