🐛 Fix werkzeug 2.1 compatibility and remove redundant code (#4630)

See #4629
This commit is contained in:
Charlie Powell authored and GitHub committed 2022-09-28 15:07:24 +02:00
1 parent b133eea894
commit 05ea0b29a4
8 files changed
+6 -69

No files matched your search

@@ -85,7 +85,7 @@ class AclSubwizard:
):
abort(404)
data = request.get_json()
data = request.get_json(silent=True)
if data is None:
data = request.values
+1 -1
View File
@@ -291,7 +291,7 @@ def serverStatus():
error_message="You have made too many failed login attempts. Please try again later.",
)
def login():
data = request.get_json()
data = request.get_json(silent=True)
if not data:
data = request.values
-26
View File
@@ -34,9 +34,6 @@ def get_groups():
@no_firstrun_access
@Permissions.ADMIN.require(403)
def add_group():
if "application/json" not in request.headers["Content-Type"]:
abort(400, description="Expected content-type JSON")
data = request.get_json()
if "key" not in data:
@@ -82,9 +79,6 @@ def get_group(key):
@no_firstrun_access
@Permissions.ADMIN.require(403)
def update_group(key):
if "application/json" not in request.headers["Content-Type"]:
abort(400, description="Expected content-type JSON")
data = request.get_json()
try:
@@ -138,12 +132,7 @@ def get_users():
@no_firstrun_access
@Permissions.ADMIN.require(403)
def add_user():
if "application/json" not in request.headers["Content-Type"]:
abort(400, description="Expected content-type JSON")
data = request.get_json()
if data is None:
abort(400, description="Malformed JSON body in request")
if "name" not in data:
abort(400, description="name is missing")
@@ -192,14 +181,8 @@ def get_user(username):
def update_user(username):
user = userManager.find_user(username)
if user is not None:
if "application/json" not in request.headers["Content-Type"]:
abort(400, description="Expected content-type JSON")
data = request.get_json()
if data is None:
abort(400, description="Malformed JSON body in request")
# change groups
if "groups" in data:
groups = data["groups"]
@@ -246,14 +229,8 @@ def change_password_for_user(username):
or current_user.has_permission(Permissions.ADMIN)
)
):
if "application/json" not in request.headers["Content-Type"]:
abort(400, description="Expected content-type JSON")
data = request.get_json()
if data is None:
abort(400, description="Malformed JSON body in request")
if "password" not in data or not data["password"]:
abort(400, description="new password is missing")
@@ -308,9 +285,6 @@ def change_settings_for_user(username):
data = request.get_json()
if data is None:
abort(400, description="Malformed JSON body in request")
try:
userManager.change_user_settings(username, data)
return jsonify(SUCCESS)
-6
View File
@@ -396,14 +396,8 @@ def printerCommand():
if not printer.is_operational():
abort(409, description="Printer is not operational")
if "application/json" not in request.headers["Content-Type"]:
abort(400, description="Expected content type JSON")
data = request.get_json()
if data is None:
abort(400, description="Malformed JSON body in request")
if "command" in data and "commands" in data:
abort(400, description="'command' and 'commands' are mutually exclusive")
elif ("command" in data or "commands" in data) and "script" in data:
+1 -12
View File
@@ -54,13 +54,7 @@ def printerProfilesList():
@no_firstrun_access
@Permissions.SETTINGS.require(403)
def printerProfilesAdd():
if "application/json" not in request.headers["Content-Type"]:
abort(400, description="Expected content-type JSON")
json_data = request.get_json()
if json_data is None:
abort(400, description="Malformed JSON body in request")
json_data = request.get_json() # Werkzeug should return 400 if invalid JSON
if "profile" not in json_data:
abort(400, description="profile is missing")
@@ -136,12 +130,7 @@ def printerProfilesDelete(identifier):
@no_firstrun_access
@Permissions.SETTINGS.require(403)
def printerProfilesUpdate(identifier):
if "application/json" not in request.headers["Content-Type"]:
abort(400, description="Expected content-type JSON")
json_data = request.get_json()
if json_data is None:
abort(400, description="Malformed JSON body in request")
if "profile" not in json_data:
abort(400, description="profile missing")
+1 -4
View File
@@ -387,11 +387,8 @@ def _get_plugin_settings():
@no_firstrun_access
@Permissions.SETTINGS.require(403)
def setSettings():
if "application/json" not in request.headers["Content-Type"]:
abort(400, description="Expected content-type JSON")
data = request.get_json()
if data is None or not isinstance(data, dict):
if not isinstance(data, dict):
abort(400, description="Malformed JSON body in request")
response = _saveSettings(data)
+1 -11
View File
@@ -160,12 +160,7 @@ def slicingGetSlicerProfile(slicer, name):
@no_firstrun_access
@Permissions.SETTINGS.require(403)
def slicingAddSlicerProfile(slicer, name):
if "application/json" not in request.headers["Content-Type"]:
abort(400, description="Expected content-type JSON")
json_data = request.get_json()
if json_data is None:
abort(400, description="Malformed JSON body in request")
data = {}
display_name = None
@@ -199,8 +194,7 @@ def slicingAddSlicerProfile(slicer, name):
@no_firstrun_access
@Permissions.SETTINGS.require(403)
def slicingPatchSlicerProfile(slicer, name):
if "application/json" not in request.headers["Content-Type"]:
abort(400, description="Expected content-type JSON")
json_data = request.get_json()
try:
profile = slicingManager.load_profile(slicer, name, require_configured=False)
@@ -209,10 +203,6 @@ def slicingPatchSlicerProfile(slicer, name):
except UnknownProfile:
return abort(404)
json_data = request.get_json()
if json_data is None:
abort(400, description="Malformed JSON body in request")
data = {}
display_name = None
description = None
+1 -8
View File
@@ -1664,15 +1664,8 @@ def get_remote_address(request):
def get_json_command_from_request(request, valid_commands):
content_type = request.headers.get("Content-Type", None)
if content_type is None or "application/json" not in content_type:
flask.abort(400, description="Expected content-type JSON")
data = request.get_json()
if data is None:
flask.abort(
400, description="Malformed JSON body or wrong content-type in request"
)
if "command" not in data or data["command"] not in valid_commands:
flask.abort(400, description="command is invalid")