From eeb7974e05fd333ebf8dc1a597d57033be856ea9 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 31 Jan 2021 14:54:45 +0100 Subject: [PATCH] User table: Added button for single user edit Added delete-trash-icon (not working) Roles are displayed correct per user Guest user is not visible if anonymous browsing is disabled --- cps/admin.py | 33 +++++++++++++++++++++++---------- cps/static/css/style.css | 4 +++- cps/static/js/table.js | 34 ++++++++++++++++++++++++++++++++-- cps/templates/user_table.html | 30 ++++++++++++++++++++---------- 4 files changed, 78 insertions(+), 23 deletions(-) diff --git a/cps/admin.py b/cps/admin.py index c7210f3f..014f32ef 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -217,25 +217,34 @@ def view_configuration(): @admin_required def edit_user_table(): visibility = current_user.view_settings.get('useredit', {}) - allUser = ub.session.query(ub.User).all() - return render_title_template("user_table.html", users=allUser, visiblility=visibility, - title=_(u"Edit Users"), page="usertable") + allUser = ub.session.query(ub.User) + if not config.config_anonbrowse: + allUser = allUser.filter(ub.User.role.op('&')(constants.ROLE_ANONYMOUS) != constants.ROLE_ANONYMOUS) + + return render_title_template("user_table.html", + users=allUser.all(), + visiblility=visibility, + all_roles = constants.ALL_ROLES, + title=_(u"Edit Users"), + page="usertable") @admi.route("/axjax/listusers") @login_required @admin_required def list_users(): off = request.args.get("offset") or 0 - limit = request.args.get("limit") or 10 - - total_count = ub.session.query(ub.User).count() + limit = request.args.get("limit") or 40 search = request.args.get("search") + + all_user = ub.session.query(ub.User) + if not config.config_anonbrowse: + all_user = all_user.filter(ub.User.role.op('&')(constants.ROLE_ANONYMOUS) != constants.ROLE_ANONYMOUS) + total_count = all_user.count() if search: - users = ub.session.query(ub.User).filter().offset(off).limit(limit).all() + users = all_user.filter().offset(off).limit(limit).all() filtered_count = users.length() - # entries, filtered_count, pagination = calibre_db.get_search_results(search, off, order, limit) else: - users = ub.session.query(ub.User).offset(off).limit(limit).all() + users = all_user.offset(off).limit(limit).all() filtered_count = total_count table_entries = {'totalNotFiltered': total_count, 'total': filtered_count, "rows": users} @@ -251,7 +260,11 @@ def list_users(): @admin_required def edit_list_user(param): vals = request.form.to_dict() - user = ub.session.query(ub.User).filter(ub.User.id == vals['pk']).one_or_none() # ub.User.query calibre_db.get_book(vals['pk']) + all_user = ub.session.query(ub.User) + if not config.config_anonbrowse: + all_user = all_user.filter(ub.User.role.op('&')(constants.ROLE_ANONYMOUS) != constants.ROLE_ANONYMOUS) + + user = all_user.filter(ub.User.id == vals['pk']).one_or_none() if param =='nickname': if not ub.session.query(ub.User).filter(ub.User.nickname == vals['value']).scalar(): user.nickname = vals['value'] diff --git a/cps/static/css/style.css b/cps/static/css/style.css index 8c99aaa0..664cdb9a 100644 --- a/cps/static/css/style.css +++ b/cps/static/css/style.css @@ -51,10 +51,12 @@ body h2 { color:#444; } -a, .danger,.book-remove, .editable-empty, .editable-empty:hover { color: #45b29d; } +a, .danger, .book-remove, .user-remove, .editable-empty, .editable-empty:hover { color: #45b29d; } .book-remove:hover { color: #23527c; } +.user-remove:hover { color: #23527c; } + .btn-default a { color: #444; } .btn-default a:hover { diff --git a/cps/static/js/table.js b/cps/static/js/table.js index 116a72d6..51134fa1 100644 --- a/cps/static/js/table.js +++ b/cps/static/js/table.js @@ -429,7 +429,8 @@ $(function() { }, }); - $("#user-table").on("check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table", + + /*$("#user-table").on("check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table", function (e, rowsAfter, rowsBefore) { var rows = rowsAfter; @@ -440,7 +441,7 @@ $(function() { var ids = $.map(!$.isArray(rows) ? [rows] : rows, function (row) { return row.id; }); - }); + });*/ }); /* Function for deleting domain restrictions */ @@ -472,6 +473,15 @@ function EbookActions (value, row) { ].join(""); } +/* Function for deleting books */ +function UserActions (value, row) { + return [ + "
", + "", + "
" + ].join(""); +} + /* Function for keeping checked rows */ function responseHandler(res) { $.each(res.rows, function (i, row) { @@ -479,3 +489,23 @@ function responseHandler(res) { }); return res; } + +function singleUserFormatter(value, row) { + return '' +} + +function checkboxFormatter(value, row, index){ + if(value & this.column) + return ''; + else + return ''; +} + +function checkboxChange(checkbox, index){ + $('#user-table').bootstrapTable('updateCell', { + index: index, + field: 'role', + value: checkbox.checked, + reinit: false + }); +} diff --git a/cps/templates/user_table.html b/cps/templates/user_table.html index 40c0f731..043b3339 100644 --- a/cps/templates/user_table.html +++ b/cps/templates/user_table.html @@ -20,22 +20,32 @@ data-url="{{url_for('admin.list_users')}}"> + - {{ user_table_row('nickname', _('Enter Username'),_('Username'), true) }} - {{ user_table_row('email', _('Enter E-mail Address'),_('E-mail Address'), true) }} - {{ user_table_row('kindle_mail', _('Enter Kindle E-mail Address'),_('Kindle E-mail'), true) }} - - - - - - - + {{ user_table_row('nickname', _('Enter Username'), _('Username'), true) }} + {{ user_table_row('email', _('Enter E-mail Address'), _('E-mail Address'), true) }} + {{ user_table_row('kindle_mail', _('Enter Kindle E-mail Address'), _('Kindle E-mail'), true) }} + {{_('Admin')}} + {{_('Upload')}} + {{_('Download')}} + {{_('Edit')}} + {{_('Change Password')}} + {{_('Edit Public Shelfs')}} + {{_('Delete')}} + {{_('View')}} + {{ user_table_row('denied_tags', _("Enter Users's Locale"), _("Users's Locale"), true) }} + {{ user_table_row('allowed_tags', _("Enter Users's Locale"), _("Users's Locale"), true) }} + {{ user_table_row('allowed_column_value', _("Enter Users's Locale"), _("Users's Locale"), true) }} + {{ user_table_row('denied_column_value', _("Enter Users's Locale"), _("Users's Locale"), true) }} + {{_('Delete User')}} {% endblock %} +{% block modal %} +{{ delete_confirm_modal() }} +{% endblock %} {% block js %}