Botched the initial Flask-Login update -- is_active(), is_authenticated(), and is_anonymous() got converted into properties, so we should do the same

This commit is contained in:
Kyle Evans 2016-10-07 11:37:36 -05:00
parent 943d7ce31a
commit 37f51ef983
6 changed files with 22 additions and 19 deletions

View file

@ -1400,8 +1400,8 @@ class SettingsPlugin(OctoPrintPlugin):
if key in node:
node[key] = None
conditions = dict(user=lambda: current_user is not None and not current_user.is_anonymous(),
admin=lambda: current_user is not None and not current_user.is_anonymous() and current_user.is_admin(),
conditions = dict(user=lambda: current_user is not None and not current_user.is_anonymous,
admin=lambda: current_user is not None and not current_user.is_anonymous and current_user.is_admin,
never=lambda: False)
for level, condition in conditions.items():

View file

@ -86,9 +86,9 @@ def on_identity_loaded(sender, identity):
return
identity.provides.add(UserNeed(user.get_id()))
if user.is_user():
if user.is_user:
identity.provides.add(RoleNeed("user"))
if user.is_admin():
if user.is_admin:
identity.provides.add(RoleNeed("admin"))
def load_user(id):

View file

@ -60,7 +60,7 @@ def pluginData(name):
return make_response("More than one api provider registered for {name}, can't proceed".format(name=name), 500)
api_plugin = api_plugins[0]
if api_plugin.is_api_adminonly() and not current_user.is_admin():
if api_plugin.is_api_adminonly() and not current_user.is_admin:
return make_response("Forbidden", 403)
response = api_plugin.on_api_get(request)
@ -87,7 +87,7 @@ def pluginCommand(name):
if valid_commands is None:
return make_response("Method not allowed", 405)
if api_plugin.is_api_adminonly() and not current_user.is_admin():
if api_plugin.is_api_adminonly() and not current_user.is_admin:
return make_response("Forbidden", 403)
command, data, response = get_json_command_from_request(request, valid_commands)

View file

@ -72,7 +72,7 @@ def getUser(username):
if not userManager.enabled:
return jsonify(SUCCESS)
if current_user is not None and not current_user.is_anonymous() and (current_user.get_name() == username or current_user.is_admin()):
if current_user is not None and not current_user.is_anonymous and (current_user.get_name() == username or current_user.is_admin):
user = userManager.findUser(username)
if user is not None:
return jsonify(user.asDict())
@ -133,7 +133,7 @@ def changePasswordForUser(username):
if not userManager.enabled:
return jsonify(SUCCESS)
if current_user is not None and not current_user.is_anonymous() and (current_user.get_name() == username or current_user.is_admin()):
if current_user is not None and not current_user.is_anonymous and (current_user.get_name() == username or current_user.is_admin):
if not "application/json" in request.headers["Content-Type"]:
return make_response("Expected content-type JSON", 400)
@ -161,7 +161,7 @@ def getSettingsForUser(username):
if not userManager.enabled:
return jsonify(SUCCESS)
if current_user is None or current_user.is_anonymous() or (current_user.get_name() != username and not current_user.is_admin()):
if current_user is None or current_user.is_anonymous or (current_user.get_name() != username and not current_user.is_admin):
return make_response("Forbidden", 403)
try:
@ -175,7 +175,7 @@ def changeSettingsForUser(username):
if not userManager.enabled:
return jsonify(SUCCESS)
if current_user is None or current_user.is_anonymous() or (current_user.get_name() != username and not current_user.is_admin()):
if current_user is None or current_user.is_anonymous or (current_user.get_name() != username and not current_user.is_admin):
return make_response("Forbidden", 403)
try:
@ -195,7 +195,7 @@ def deleteApikeyForUser(username):
if not userManager.enabled:
return jsonify(SUCCESS)
if current_user is not None and not current_user.is_anonymous() and (current_user.get_name() == username or current_user.is_admin()):
if current_user is not None and not current_user.is_anonymous and (current_user.get_name() == username or current_user.is_admin):
try:
userManager.deleteApikey(username)
except users.UnknownUser:
@ -211,7 +211,7 @@ def generateApikeyForUser(username):
if not userManager.enabled:
return jsonify(SUCCESS)
if current_user is not None and not current_user.is_anonymous() and (current_user.get_name() == username or current_user.is_admin()):
if current_user is not None and not current_user.is_anonymous and (current_user.get_name() == username or current_user.is_admin):
try:
apikey = userManager.generateApiKey(username)
except users.UnknownUser:

View file

@ -971,7 +971,7 @@ def admin_validator(request):
"""
user = _get_flask_user_from_request(request)
if user is None or not user.is_authenticated() or not user.is_admin():
if user is None or not user.is_authenticated or not user.is_admin:
raise tornado.web.HTTPError(403)
@ -986,7 +986,7 @@ def user_validator(request):
"""
user = _get_flask_user_from_request(request)
if user is None or not user.is_authenticated():
if user is None or not user.is_authenticated:
raise tornado.web.HTTPError(403)

View file

@ -428,9 +428,9 @@ class User(UserMixin):
def asDict(self):
return {
"name": self._username,
"active": self.is_active(),
"admin": self.is_admin(),
"user": self.is_user(),
"active": self.is_active,
"admin": self.is_admin,
"user": self.is_user,
"apikey": self._apikey,
"settings": self._settings
}
@ -444,12 +444,15 @@ class User(UserMixin):
def get_name(self):
return self._username
@property
def is_active(self):
return self._active
@property
def is_user(self):
return "user" in self._roles
@property
def is_admin(self):
return "admin" in self._roles
@ -496,7 +499,7 @@ class User(UserMixin):
return True
def __repr__(self):
return "User(id=%s,name=%s,active=%r,user=%r,admin=%r)" % (self.get_id(), self.get_name(), self.is_active(), self.is_user(), self.is_admin())
return "User(id=%s,name=%s,active=%r,user=%r,admin=%r)" % (self.get_id(), self.get_name(), self.is_active, self.is_user, self.is_admin)
class SessionUser(User):
def __init__(self, user):
@ -526,7 +529,7 @@ class SessionUser(User):
return self._session
def __repr__(self):
return "SessionUser(id=%s,name=%s,active=%r,user=%r,admin=%r,session=%s,created=%s)" % (self.get_id(), self.get_name(), self.is_active(), self.is_user(), self.is_admin(), self._session, self._created)
return "SessionUser(id=%s,name=%s,active=%r,user=%r,admin=%r,session=%s,created=%s)" % (self.get_id(), self.get_name(), self.is_active, self.is_user, self.is_admin, self._session, self._created)
##~~ DummyUser object to use when accessControl is disabled