From 970880dee6098e51fd947132ce982ca888f21d47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 7 Nov 2016 11:55:08 +0100 Subject: [PATCH] Added user roles and enabled plugins to settings ETag Otherwise the cache of /api/settings would not be properly invalidated on a change in either the user login state or the set of active plugins. See also #1576 --- src/octoprint/server/api/settings.py | 8 ++++++++ src/octoprint/users.py | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index ac2c3fa6..b4d862ae 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -8,6 +8,7 @@ __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms import logging from flask import request, jsonify, make_response +from flask.ext.login import current_user from werkzeug.exceptions import BadRequest from octoprint.events import eventManager, Events @@ -30,11 +31,18 @@ def _etag(lm=None): lm = _lastmodified() connection_options = printer.__class__.get_connection_options() + plugins = sorted(octoprint.plugin.plugin_manager().enabled_plugins) + if current_user is not None and not current_user.is_anonymous(): + roles = sorted(current_user.roles) + else: + roles = [] import hashlib hash = hashlib.sha1() hash.update(str(lm)) hash.update(repr(connection_options)) + hash.update(repr(plugins)) + hash.update(repr(roles)) return hash.hexdigest() @api.route("/settings", methods=["GET"]) diff --git a/src/octoprint/users.py b/src/octoprint/users.py index a615d222..0147329e 100644 --- a/src/octoprint/users.py +++ b/src/octoprint/users.py @@ -464,6 +464,10 @@ class User(UserMixin): return self._get_setting(path) + @property + def roles(self): + return list(self._roles) + def set_setting(self, key, value): if not isinstance(key, (tuple, list)): path = [key]