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
This commit is contained in:
1 parent
4689a405a3
commit
970880dee6
2 files changed
+12
No files matched your search
@@ -8,6 +8,7 @@ __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from flask import request, jsonify, make_response
|
from flask import request, jsonify, make_response
|
||||||
|
from flask.ext.login import current_user
|
||||||
from werkzeug.exceptions import BadRequest
|
from werkzeug.exceptions import BadRequest
|
||||||
|
|
||||||
from octoprint.events import eventManager, Events
|
from octoprint.events import eventManager, Events
|
||||||
@@ -30,11 +31,18 @@ def _etag(lm=None):
|
|||||||
lm = _lastmodified()
|
lm = _lastmodified()
|
||||||
|
|
||||||
connection_options = printer.__class__.get_connection_options()
|
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
|
import hashlib
|
||||||
hash = hashlib.sha1()
|
hash = hashlib.sha1()
|
||||||
hash.update(str(lm))
|
hash.update(str(lm))
|
||||||
hash.update(repr(connection_options))
|
hash.update(repr(connection_options))
|
||||||
|
hash.update(repr(plugins))
|
||||||
|
hash.update(repr(roles))
|
||||||
return hash.hexdigest()
|
return hash.hexdigest()
|
||||||
|
|
||||||
@api.route("/settings", methods=["GET"])
|
@api.route("/settings", methods=["GET"])
|
||||||
|
|||||||
@@ -464,6 +464,10 @@ class User(UserMixin):
|
|||||||
|
|
||||||
return self._get_setting(path)
|
return self._get_setting(path)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def roles(self):
|
||||||
|
return list(self._roles)
|
||||||
|
|
||||||
def set_setting(self, key, value):
|
def set_setting(self, key, value):
|
||||||
if not isinstance(key, (tuple, list)):
|
if not isinstance(key, (tuple, list)):
|
||||||
path = [key]
|
path = [key]
|
||||||
|
|||||||
Reference in new issue
Block a user