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:
Gina Häußge 2016-11-07 11:55:08 +01:00
parent 4689a405a3
commit 970880dee6
2 changed files with 12 additions and 0 deletions

View file

@ -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"])

View file

@ -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]