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
This commit is contained in:
Ozzie Isaacs 2021-01-31 14:54:45 +01:00
parent f45ea1a31c
commit eeb7974e05
4 changed files with 78 additions and 23 deletions

View File

@ -217,25 +217,34 @@ def view_configuration():
@admin_required @admin_required
def edit_user_table(): def edit_user_table():
visibility = current_user.view_settings.get('useredit', {}) visibility = current_user.view_settings.get('useredit', {})
allUser = ub.session.query(ub.User).all() allUser = ub.session.query(ub.User)
return render_title_template("user_table.html", users=allUser, visiblility=visibility, if not config.config_anonbrowse:
title=_(u"Edit Users"), page="usertable") 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") @admi.route("/axjax/listusers")
@login_required @login_required
@admin_required @admin_required
def list_users(): def list_users():
off = request.args.get("offset") or 0 off = request.args.get("offset") or 0
limit = request.args.get("limit") or 10 limit = request.args.get("limit") or 40
total_count = ub.session.query(ub.User).count()
search = request.args.get("search") 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: 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() filtered_count = users.length()
# entries, filtered_count, pagination = calibre_db.get_search_results(search, off, order, limit)
else: else:
users = ub.session.query(ub.User).offset(off).limit(limit).all() users = all_user.offset(off).limit(limit).all()
filtered_count = total_count filtered_count = total_count
table_entries = {'totalNotFiltered': total_count, 'total': filtered_count, "rows": users} table_entries = {'totalNotFiltered': total_count, 'total': filtered_count, "rows": users}
@ -251,7 +260,11 @@ def list_users():
@admin_required @admin_required
def edit_list_user(param): def edit_list_user(param):
vals = request.form.to_dict() 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 param =='nickname':
if not ub.session.query(ub.User).filter(ub.User.nickname == vals['value']).scalar(): if not ub.session.query(ub.User).filter(ub.User.nickname == vals['value']).scalar():
user.nickname = vals['value'] user.nickname = vals['value']

View File

@ -51,10 +51,12 @@ body h2 {
color:#444; 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; } .book-remove:hover { color: #23527c; }
.user-remove:hover { color: #23527c; }
.btn-default a { color: #444; } .btn-default a { color: #444; }
.btn-default a:hover { .btn-default a:hover {

View File

@ -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) { function (e, rowsAfter, rowsBefore) {
var rows = rowsAfter; var rows = rowsAfter;
@ -440,7 +441,7 @@ $(function() {
var ids = $.map(!$.isArray(rows) ? [rows] : rows, function (row) { var ids = $.map(!$.isArray(rows) ? [rows] : rows, function (row) {
return row.id; return row.id;
}); });
}); });*/
}); });
/* Function for deleting domain restrictions */ /* Function for deleting domain restrictions */
@ -472,6 +473,15 @@ function EbookActions (value, row) {
].join(""); ].join("");
} }
/* Function for deleting books */
function UserActions (value, row) {
return [
"<div class=\"user-remove\" data-toggle=\"modal\" data-target=\"#GeneralDeleteModal\" data-ajax=\"1\" data-delete-id=\"" + row.id + "\" title=\"Remove\">",
"<i class=\"glyphicon glyphicon-trash\"></i>",
"</div>"
].join("");
}
/* Function for keeping checked rows */ /* Function for keeping checked rows */
function responseHandler(res) { function responseHandler(res) {
$.each(res.rows, function (i, row) { $.each(res.rows, function (i, row) {
@ -479,3 +489,23 @@ function responseHandler(res) {
}); });
return res; return res;
} }
function singleUserFormatter(value, row) {
return '<button type="button" className="btn btn-default"><a href="/admin/user/' + row.id + '">' + this.buttontext + '</a></button>'
}
function checkboxFormatter(value, row, index){
if(value & this.column)
return '<input type="checkbox" class="chk" checked onchange="checkboxChange(this, '+index+')">';
else
return '<input type="checkbox" class="chk" onchange="checkboxChange(this, '+index+')">';
}
function checkboxChange(checkbox, index){
$('#user-table').bootstrapTable('updateCell', {
index: index,
field: 'role',
value: checkbox.checked,
reinit: false
});
}

View File

@ -20,22 +20,32 @@
data-url="{{url_for('admin.list_users')}}"> data-url="{{url_for('admin.list_users')}}">
<thead> <thead>
<tr> <tr>
<th data-buttontext="{{_('Edit User')}}" data-formatter="singleUserFormatter"></th>
<th data-field="state" data-checkbox="true" data-sortable="true"></th> <th data-field="state" data-checkbox="true" data-sortable="true"></th>
<th data-field="id" id="id" data-visible="false" data-switchable="false"></th> <th data-field="id" id="id" data-visible="false" data-switchable="false"></th>
{{ user_table_row('nickname', _('Enter Username'),_('Username'), true) }} {{ user_table_row('nickname', _('Enter Username'), _('Username'), true) }}
{{ user_table_row('email', _('Enter E-mail Address'),_('E-mail Address'), 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('kindle_mail', _('Enter Kindle E-mail Address'), _('Kindle E-mail'), true) }}
<th data-field="admin" data-checkbox="true" data-sortable="true"></th> <th data-field="role" data-column="{{all_roles.admin_role}}" data-formatter="checkboxFormatter">{{_('Admin')}}</th>
<th data-field="upload" data-checkbox="true" data-sortable="true"></th> <th data-field="role" data-column="{{all_roles.download_role}}" data-formatter="checkboxFormatter">{{_('Upload')}}</th>
<th data-field="download" data-checkbox="true" data-sortable="true"></th> <th data-field="role" data-column="{{all_roles.upload_role}}" data-formatter="checkboxFormatter">{{_('Download')}}</th>
<th data-field="view_books" data-checkbox="true" data-sortable="true"></th> <th data-field="role" data-column="{{all_roles.edit_role}}" data-formatter="checkboxFormatter">{{_('Edit')}}</th>
<th data-field="edit" data-checkbox="true" data-sortable="true"></th> <th data-field="role" data-column="{{all_roles.passwd_role}}" data-formatter="checkboxFormatter">{{_('Change Password')}}</th>
<th data-field="delete" data-checkbox="true" data-sortable="true"></th> <th data-field="role" data-column="{{all_roles.edit_shelf_role}}" data-formatter="checkboxFormatter">{{_('Edit Public Shelfs')}}</th>
<th data-field="public_shelf" data-checkbox="true" data-sortable="true"></th> <th data-field="role" data-column="{{all_roles.delete_role}}" data-formatter="checkboxFormatter">{{_('Delete')}}</th>
<th data-field="role" data-column="{{all_roles.viewer_role}}" data-formatter="checkboxFormatter">{{_('View')}}</th>
{{ 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) }}
<th data-align="right" data-formatter="UserActions" data-switchable="false">{{_('Delete User')}}</th>
</tr> </tr>
</thead> </thead>
</table> </table>
{% endblock %} {% endblock %}
{% block modal %}
{{ delete_confirm_modal() }}
{% endblock %}
{% block js %} {% block js %}
<script src="{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-table.min.js') }}"></script> <script src="{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-table.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-table-editable.min.js') }}"></script> <script src="{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-table-editable.min.js') }}"></script>