diff --git a/cps/admin.py b/cps/admin.py index d32d6d7c..5b18bb64 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -289,15 +289,30 @@ def list_users(): @login_required @admin_required def delete_user(): - user_id = request.values.get('userid', -1) - content = ub.session.query(ub.User).filter(ub.User.id == int(user_id)).one_or_none() - try: - message = _delete_user(content) - return Response(json.dumps({'type': "success", 'message': message}), mimetype='application/json') - except Exception as ex: - return Response(json.dumps({'type': "danger", 'message':str(ex)}), mimetype='application/json') - log.error("User not found") - return Response(json.dumps({'type': "danger", 'message':_("User not found")}), mimetype='application/json') + user_ids = request.form.to_dict(flat=False) + if "userid[]" in user_ids: + users = ub.session.query(ub.User).filter(ub.User.id.in_(user_ids['userid[]'])).all() + elif "userid" in user_ids: + users = ub.session.query(ub.User).filter(ub.User.id == user_ids['userid'][0]).all() + count = 0 + errors = list() + success = list() + if not users: + log.error("User not found") + return Response(json.dumps({'type': "danger", 'message': _("User not found")}), mimetype='application/json') + for user in users: + try: + message = _delete_user(user) + count += 1 + except Exception as ex: + errors.append({'type': "danger", 'message': str(ex)}) + + if count == 1: + success = [{'type': "success", 'message': message}] + elif count > 1: + success = [{'type': "success", 'message': _("{} users deleted successfully").format(count)}] + success.extend(errors) + return Response(json.dumps(success), mimetype='application/json') @admi.route("/ajax/getlocale") @login_required @@ -367,9 +382,9 @@ 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 Response(json.dumps([{'type': "danger", 'message':_(u"No admin user remaining, can't remove admin role", - nick=user.name)}), mimetype='application/json') + nick=user.name)}]), mimetype='application/json') user.role &= ~int(vals['field_index']) elif param.startswith('sidebar'): if user.name == "Guest" and int(vals['field_index']) == constants.SIDEBAR_READ_AND_UNREAD: diff --git a/cps/db.py b/cps/db.py index 1a305d33..39adcd4b 100644 --- a/cps/db.py +++ b/cps/db.py @@ -625,7 +625,10 @@ class CalibreDB(): outcome = list() elementlist = {ele.id: ele for ele in inputlist} for entry in state: - outcome.append(elementlist[entry]) + try: + outcome.append(elementlist[entry]) + except KeyError: + pass del elementlist[entry] for entry in elementlist: outcome.append(elementlist[entry]) diff --git a/cps/editbooks.py b/cps/editbooks.py index 67ab06d9..45e0f9fe 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -1185,6 +1185,6 @@ def merge_list_book(): element.format, element.uncompressed_size, to_name)) - delete_book(from_book.id,"", True) # json_resp = + delete_book(from_book.id,"", True) return json.dumps({'success': True}) return "" diff --git a/cps/static/js/main.js b/cps/static/js/main.js index 7231c51c..92c83f60 100644 --- a/cps/static/js/main.js +++ b/cps/static/js/main.js @@ -178,6 +178,19 @@ $("#delete_confirm").click(function() { } }); + $("#books-table").bootstrapTable("refresh"); + /*$.ajax({ + method:"get", + url: window.location.pathname + "/../../ajax/listbooks", + async: true, + timeout: 900, + success:function(data) { + + + $("#book-table").bootstrapTable("load", data); + loadSuccess(); + } + });*/ } }); } else { diff --git a/cps/static/js/table.js b/cps/static/js/table.js index 3f3b431f..97dee842 100644 --- a/cps/static/js/table.js +++ b/cps/static/js/table.js @@ -511,22 +511,36 @@ $(function() { var data = $(this).data("val"); checkboxHeader(val, name, data); }); + $(".button_head").on("click",function() { + var result = $('#user-table').bootstrapTable('getSelections').map(a => a.id); + confirmDialog( + "btndeluser", + "GeneralDeleteModal", + 0, + function() { + $.ajax({ + method:"post", + url: window.location.pathname + "/../../ajax/deleteuser", + data: {"userid": result}, + success: function (data) { + selections = selections.filter( ( el ) => !result.includes( el ) ); + // selections = selections.filter(item => item !== userId); + handleListServerResponse(data); + }, + error: function (data) { + handleListServerResponse({type:"danger", message:data.responseText}) + }, + }); + } + ); + }); function user_handle (userId) { $.ajax({ method:"post", url: window.location.pathname + "/../../ajax/deleteuser", data: {"userid":userId} }); - $.ajax({ - method:"get", - url: window.location.pathname + "/../../ajax/listusers", - async: true, - timeout: 900, - success:function(data) { - $("#user-table").bootstrapTable("load", data); - loadSuccess(); - } - }); + $("#user-table").bootstrapTable("refresh"); } $("#user-table").on("click-cell.bs.table", function (field, value, row, $element) { @@ -642,23 +656,13 @@ function handleListServerResponse (data, disableButtons) { $("#flash_success").remove(); $("#flash_danger").remove(); if (!jQuery.isEmptyObject(data)) { - $( ".navbar" ).after( '
Start Time: 2021-04-12 21:44:07
+Start Time: 2021-04-21 07:09:48
Stop Time: 2021-04-13 00:22:44
+Stop Time: 2021-04-21 09:55:49
Duration: 2h 7 min
+Duration: 2h 16 min