Docs for user API

Also some fixes on said API and some fixes in the docs
This commit is contained in:
Gina Häußge committed 2016-09-28 11:18:43 +02:00
1 parent 82ae3f6f6e
commit 4e69b260a1
4 files changed
+329 -17

No files matched your search

+14 -7
View File
@@ -12,7 +12,7 @@ from flask.ext.login import current_user
import octoprint.users as users
from octoprint.server import SUCCESS, admin_permission, userManager
from octoprint.server.api import api
from octoprint.server.api import api, valid_boolean_trues
from octoprint.server.util.flask import restricted_access
@@ -44,12 +44,19 @@ def addUser():
except BadRequest:
return make_response("Malformed JSON body in request", 400)
if not "name" in data:
return make_response("Missing mandatory name field", 400)
if not "password" in data:
return make_response("Missing mandatory password field", 400)
if not "active" in data:
return make_response("Missing mandatory active field", 400)
name = data["name"]
password = data["password"]
active = data["active"]
active = data["active"] in valid_boolean_trues
roles = ["user"]
if "admin" in data.keys() and data["admin"]:
if "admin" in data and data["admin"] in valid_boolean_trues:
roles.append("admin")
try:
@@ -94,13 +101,13 @@ def updateUser(username):
# change roles
roles = ["user"]
if "admin" in data.keys() and data["admin"]:
if "admin" in data and data["admin"] in valid_boolean_trues:
roles.append("admin")
userManager.changeUserRoles(username, roles)
# change activation
if "active" in data.keys():
userManager.changeUserActivation(username, data["active"])
if "active" in data:
userManager.changeUserActivation(username, data["active"] in valid_boolean_trues)
return getUsers()
else:
abort(404)
@@ -135,7 +142,7 @@ def changePasswordForUser(username):
except BadRequest:
return make_response("Malformed JSON body in request", 400)
if not "password" in data.keys() or not data["password"]:
if not "password" in data or not data["password"]:
return make_response("password is missing from request", 400)
try: