Skip to content

Commit

Permalink
Added logging of ip address (#3237)
Browse files Browse the repository at this point in the history
Refactored Response(json.dumps -> make_response(jsonify..)
Update mimetypes - Allow different mimetypes for download and file upload check (#3245, #3243)
Bugfixes from tests
Updated optional-requirements
  • Loading branch information
OzzieIsaacs committed Dec 7, 2024
1 parent 14e57e3 commit 42924d9
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 127 deletions.
6 changes: 3 additions & 3 deletions cps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
mimetypes.add_type('application/xhtml+xml', '.xhtml')
mimetypes.add_type('application/epub+zip', '.epub')
mimetypes.add_type('application/epub+zip', '.kepub')
mimetypes.add_type('text/xml', '.fb2')
mimetypes.add_type('application/fb2+zip', '.fb2')
mimetypes.add_type('application/octet-stream', '.mobi')
mimetypes.add_type('application/octet-stream', '.prc')
mimetypes.add_type('application/vnd.amazon.ebook', '.azw')
mimetypes.add_type('application/x-mobi8-ebook', '.azw3')
mimetypes.add_type('application/x-rar', '.cbr')
mimetypes.add_type('application/zip', '.cbz')
mimetypes.add_type('application/x-cbr', '.cbr')
mimetypes.add_type('application/x-cbz', '.cbz')
mimetypes.add_type('application/x-tar', '.cbt')
mimetypes.add_type('application/x-7z-compressed', '.cb7')
mimetypes.add_type('image/vnd.djv', '.djv')
Expand Down
24 changes: 11 additions & 13 deletions cps/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
from functools import wraps
from urllib.parse import urlparse

from flask import Blueprint, flash, redirect, url_for, abort, request, make_response, send_from_directory, g, Response
from flask import Blueprint, flash, redirect, url_for, abort, request, make_response, \
send_from_directory, g, jsonify
from markupsafe import Markup
from .cw_login import current_user
from flask_babel import gettext as _
Expand Down Expand Up @@ -378,10 +379,7 @@ def list_users():
user.default = get_user_locale_language(user.default_language)

table_entries = {'totalNotFiltered': total_count, 'total': filtered_count, "rows": users}
js_list = json.dumps(table_entries, cls=db.AlchemyEncoder)
response = make_response(js_list)
response.headers["Content-Type"] = "application/json; charset=utf-8"
return response
return make_response(json.dumps(table_entries, cls=db.AlchemyEncoder))


@admi.route("/ajax/deleteuser", methods=['POST'])
Expand All @@ -400,7 +398,7 @@ def delete_user():
success = list()
if not users:
log.error("User not found")
return Response(json.dumps({'type': "danger", 'message': _("User not found")}), mimetype='application/json')
return make_response(jsonify(type="danger", message=_("User not found")))
for user in users:
try:
message = _delete_user(user)
Expand All @@ -416,7 +414,7 @@ def delete_user():
log.info("Users {} deleted".format(user_ids))
success = [{'type': "success", 'message': _("{} users deleted successfully").format(count)}]
success.extend(errors)
return Response(json.dumps(success), mimetype='application/json')
return make_response(jsonify(success))


@admi.route("/ajax/getlocale")
Expand Down Expand Up @@ -498,10 +496,10 @@ def edit_list_user(param):
if not ub.session.query(ub.User). \
filter(ub.User.role.op('&')(constants.ROLE_ADMIN) == constants.ROLE_ADMIN,
ub.User.id != user.id).count():
return Response(
json.dumps([{'type': "danger",
return make_response(
jsonify([{'type': "danger",
'message': _("No admin user remaining, can't remove admin role",
nick=user.name)}]), mimetype='application/json')
nick=user.name)}]))
user.role &= ~value
else:
raise Exception(_("Value has to be true or false"))
Expand Down Expand Up @@ -947,7 +945,7 @@ def do_full_kobo_sync(userid):
count = ub.session.query(ub.KoboSyncedBooks).filter(userid == ub.KoboSyncedBooks.user_id).delete()
message = _("{} sync entries deleted").format(count)
ub.session_commit(message)
return Response(json.dumps([{"type": "success", "message": message}]), mimetype='application/json')
return make_response(jsonify(type="success", message=message))


def check_valid_read_column(column):
Expand Down Expand Up @@ -1264,7 +1262,7 @@ def _configuration_ldap_helper(to_save):
@admin_required
def simulatedbchange():
db_change, db_valid = _db_simulate_change()
return Response(json.dumps({"change": db_change, "valid": db_valid}), mimetype='application/json')
return make_response(jsonify(change=db_change, valid=db_valid))


@admi.route("/admin/user/new", methods=["GET", "POST"])
Expand Down Expand Up @@ -1896,7 +1894,7 @@ def _configuration_result(error_flash=None, reboot=False):
resp['result'] = [{'type': "success", 'message': _("Calibre-Web configuration updated")}]
resp['reboot'] = reboot
resp['config_upload'] = config.config_upload_formats
return Response(json.dumps(resp), mimetype='application/json')
return make_response(jsonify(resp))


def _db_configuration_result(error_flash=None, gdrive_error=None):
Expand Down
Loading

0 comments on commit 42924d9

Please sign in to comment.