Commit 12c32640 authored by cbartondock's avatar cbartondock

Merge branch 'master' of https://github.com/janeczku/calibre-web

parents f2cd93dc bd3ccfd0
...@@ -38,7 +38,6 @@ from sqlalchemy import and_ ...@@ -38,7 +38,6 @@ from sqlalchemy import and_
from sqlalchemy.orm.attributes import flag_modified from sqlalchemy.orm.attributes import flag_modified
from sqlalchemy.exc import IntegrityError, OperationalError, InvalidRequestError from sqlalchemy.exc import IntegrityError, OperationalError, InvalidRequestError
from sqlalchemy.sql.expression import func, or_, text from sqlalchemy.sql.expression import func, or_, text
# from sqlalchemy.func import field
from . import constants, logger, helper, services from . import constants, logger, helper, services
from .cli import filepicker from .cli import filepicker
...@@ -303,6 +302,7 @@ def list_users(): ...@@ -303,6 +302,7 @@ def list_users():
@admin_required @admin_required
def delete_user(): def delete_user():
user_ids = request.form.to_dict(flat=False) user_ids = request.form.to_dict(flat=False)
users = None
if "userid[]" in user_ids: if "userid[]" in user_ids:
users = ub.session.query(ub.User).filter(ub.User.id.in_(user_ids['userid[]'])).all() users = ub.session.query(ub.User).filter(ub.User.id.in_(user_ids['userid[]'])).all()
elif "userid" in user_ids: elif "userid" in user_ids:
...@@ -394,27 +394,42 @@ def edit_list_user(param): ...@@ -394,27 +394,42 @@ def edit_list_user(param):
elif param == 'kindle_mail': elif param == 'kindle_mail':
user.kindle_mail = valid_email(vals['value']) if vals['value'] else "" user.kindle_mail = valid_email(vals['value']) if vals['value'] else ""
elif param.endswith('role'): elif param.endswith('role'):
if user.name == "Guest" and int(vals['field_index']) in \ value = int(vals['field_index'])
if user.name == "Guest" and value in \
[constants.ROLE_ADMIN, constants.ROLE_PASSWD, constants.ROLE_EDIT_SHELFS]: [constants.ROLE_ADMIN, constants.ROLE_PASSWD, constants.ROLE_EDIT_SHELFS]:
raise Exception(_("Guest can't have this role")) raise Exception(_("Guest can't have this role"))
if vals['value'] == 'true': # check for valid value, last on checks for power of 2 value
user.role |= int(vals['field_index']) if value > 0 and value <= constants.ROLE_VIEWER and (value & value-1 == 0 or value == 1):
if vals['value'] == 'true':
user.role |= value
elif vals['value'] == 'false':
if value == constants.ROLE_ADMIN:
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",
'message':_(u"No admin user remaining, can't remove admin role",
nick=user.name)}]), mimetype='application/json')
user.role &= ~value
else:
raise Exception(_("Value has to be true or false"))
else: else:
if int(vals['field_index']) == constants.ROLE_ADMIN: raise Exception(_("Invalid role"))
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",
'message':_(u"No admin user remaining, can't remove admin role",
nick=user.name)}]), mimetype='application/json')
user.role &= ~int(vals['field_index'])
elif param.startswith('sidebar'): elif param.startswith('sidebar'):
if user.name == "Guest" and int(vals['field_index']) == constants.SIDEBAR_READ_AND_UNREAD: value = int(vals['field_index'])
if user.name == "Guest" and value == constants.SIDEBAR_READ_AND_UNREAD:
raise Exception(_("Guest can't have this view")) raise Exception(_("Guest can't have this view"))
if vals['value'] == 'true': # check for valid value, last on checks for power of 2 value
user.sidebar_view |= int(vals['field_index']) if value > 0 and value <= constants.SIDEBAR_LIST and (value & value-1 == 0 or value == 1):
if vals['value'] == 'true':
user.sidebar_view |= value
elif vals['value'] == 'false':
user.sidebar_view &= ~value
else:
raise Exception(_("Value has to be true or false"))
else: else:
user.sidebar_view &= ~int(vals['field_index']) raise Exception(_("Invalid view"))
elif param == 'locale': elif param == 'locale':
if user.name == "Guest": if user.name == "Guest":
raise Exception(_("Guest's Locale is determined automatically and can't be set")) raise Exception(_("Guest's Locale is determined automatically and can't be set"))
...@@ -664,6 +679,8 @@ def restriction_deletion(element, list_func): ...@@ -664,6 +679,8 @@ def restriction_deletion(element, list_func):
def prepare_tags(user, action, tags_name, id_list): def prepare_tags(user, action, tags_name, id_list):
if "tags" in tags_name: if "tags" in tags_name:
tags = calibre_db.session.query(db.Tags).filter(db.Tags.id.in_(id_list)).all() tags = calibre_db.session.query(db.Tags).filter(db.Tags.id.in_(id_list)).all()
if not tags:
raise Exception(_("Tag not found"))
new_tags_list = [x.name for x in tags] new_tags_list = [x.name for x in tags]
else: else:
tags = calibre_db.session.query(db.cc_classes[config.config_restricted_column])\ tags = calibre_db.session.query(db.cc_classes[config.config_restricted_column])\
...@@ -672,8 +689,10 @@ def prepare_tags(user, action, tags_name, id_list): ...@@ -672,8 +689,10 @@ def prepare_tags(user, action, tags_name, id_list):
saved_tags_list = user.__dict__[tags_name].split(",") if len(user.__dict__[tags_name]) else [] saved_tags_list = user.__dict__[tags_name].split(",") if len(user.__dict__[tags_name]) else []
if action == "remove": if action == "remove":
saved_tags_list = [x for x in saved_tags_list if x not in new_tags_list] saved_tags_list = [x for x in saved_tags_list if x not in new_tags_list]
else: elif action == "add":
saved_tags_list.extend(x for x in new_tags_list if x not in saved_tags_list) saved_tags_list.extend(x for x in new_tags_list if x not in saved_tags_list)
else:
raise Exception(_("Invalid Action"))
return ",".join(saved_tags_list) return ",".join(saved_tags_list)
...@@ -957,7 +976,10 @@ def _configuration_gdrive_helper(to_save): ...@@ -957,7 +976,10 @@ def _configuration_gdrive_helper(to_save):
) )
# always show google drive settings, but in case of error deny support # always show google drive settings, but in case of error deny support
config.config_use_google_drive = (not gdrive_error) and ("config_use_google_drive" in to_save) new_gdrive_value = (not gdrive_error) and ("config_use_google_drive" in to_save)
if config.config_use_google_drive and not new_gdrive_value:
config.config_google_drive_watch_changes_response = {}
config.config_use_google_drive = new_gdrive_value
if _config_string(to_save, "config_google_drive_folder"): if _config_string(to_save, "config_google_drive_folder"):
gdriveutils.deleteDatabaseOnChange() gdriveutils.deleteDatabaseOnChange()
return gdrive_error return gdrive_error
...@@ -1210,7 +1232,6 @@ def _configuration_result(error_flash=None, gdrive_error=None, configured=True): ...@@ -1210,7 +1232,6 @@ def _configuration_result(error_flash=None, gdrive_error=None, configured=True):
log.error(gdrive_error) log.error(gdrive_error)
gdrive_error = _(gdrive_error) gdrive_error = _(gdrive_error)
else: else:
# if config.config_use_google_drive and\
if not gdrive_authenticate and gdrive_support: if not gdrive_authenticate and gdrive_support:
gdrivefolders = gdriveutils.listRootFolders() gdrivefolders = gdriveutils.listRootFolders()
......
...@@ -221,7 +221,7 @@ def listRootFolders(): ...@@ -221,7 +221,7 @@ def listRootFolders():
drive = getDrive(Gdrive.Instance().drive) drive = getDrive(Gdrive.Instance().drive)
folder = "'root' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed = false" folder = "'root' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed = false"
fileList = drive.ListFile({'q': folder}).GetList() fileList = drive.ListFile({'q': folder}).GetList()
except (ServerNotFoundError, ssl.SSLError) as e: except (ServerNotFoundError, ssl.SSLError, RefreshError) as e:
log.info("GDrive Error %s" % e) log.info("GDrive Error %s" % e)
fileList = [] fileList = []
return fileList return fileList
......
...@@ -318,7 +318,6 @@ $(function() { ...@@ -318,7 +318,6 @@ $(function() {
}, },
url: getPath() + "/ajax/listrestriction/" + type + "/" + userId, url: getPath() + "/ajax/listrestriction/" + type + "/" + userId,
rowStyle: function(row) { rowStyle: function(row) {
// console.log('Reihe :' + row + " Index :" + index);
if (row.id.charAt(0) === "a") { if (row.id.charAt(0) === "a") {
return {classes: "bg-primary"}; return {classes: "bg-primary"};
} else { } else {
...@@ -613,30 +612,31 @@ function loadSuccess() { ...@@ -613,30 +612,31 @@ function loadSuccess() {
} }
function move_header_elements() { function move_header_elements() {
$(".header_select").each(function () { $(".header_select").each(function () {
var item = $(this).parent(); var item = $(this).parent();
var parent = item.parent().parent(); var parent = item.parent().parent();
if (parent.prop('nodeName') === "TH") { if (parent.prop('nodeName') === "TH") {
item.prependTo(parent); item.prependTo(parent);
} }
}); });
$(".form-check").each(function () { $(".form-check").each(function () {
var item = $(this).parent(); var item = $(this).parent();
var parent = item.parent().parent(); var parent = item.parent().parent();
if (parent.prop('nodeName') === "TH") { if (parent.prop('nodeName') === "TH") {
item.prependTo(parent); item.prependTo(parent);
} }
}); });
$(".multi_select").each(function () { $(".multi_select").each(function () {
var item = $(this); var item = $(this);
var parent = item.parent().parent(); var parent = item.parent().parent();
if (parent.prop('nodeName') === "TH") { if (parent.prop('nodeName') === "TH") {
item.prependTo(parent); item.prependTo(parent);
item.addClass("myselect"); item.addClass("myselect");
} }
}); });
$(".multi_selector").selectpicker(); $(".multi_selector").selectpicker();
if (! $._data($(".multi_head").get(0), "events") ) {
// Functions have to be here, otherwise the callbacks are not fired if visible columns are changed // Functions have to be here, otherwise the callbacks are not fired if visible columns are changed
$(".multi_head").on("click", function () { $(".multi_head").on("click", function () {
var val = $(this).data("set"); var val = $(this).data("set");
...@@ -662,23 +662,27 @@ function move_header_elements() { ...@@ -662,23 +662,27 @@ function move_header_elements() {
} }
); );
}); });
}
$("#user_delete_selection").click(function () { $("#user_delete_selection").click(function () {
$("#user-table").bootstrapTable("uncheckAll"); $("#user-table").bootstrapTable("uncheckAll");
}); });
$("#select_locale").on("change", function () { $("#select_locale").on("change", function () {
selectHeader(this, "locale"); selectHeader(this, "locale");
}); });
$("#select_default_language").on("change", function () { $("#select_default_language").on("change", function () {
selectHeader(this, "default_language"); selectHeader(this, "default_language");
}); });
if (! $._data($(".check_head").get(0), "events") ) {
$(".check_head").on("change", function () { $(".check_head").on("change", function () {
var val = $(this).data("set"); var val = $(this).data("set");
var name = $(this).data("name"); var name = $(this).data("name");
var data = $(this).data("val"); var data = $(this).data("val");
checkboxHeader(val, name, data); checkboxHeader(val, name, data);
}); });
}
if (! $._data($(".button_head").get(0), "events") ) {
$(".button_head").on("click", function () { $(".button_head").on("click", function () {
var result = $('#user-table').bootstrapTable('getSelections').map(a => a.id); var result = $('#user-table').bootstrapTable('getSelections').map(a => a.id);
confirmDialog( confirmDialog(
...@@ -701,6 +705,7 @@ function move_header_elements() { ...@@ -701,6 +705,7 @@ function move_header_elements() {
} }
); );
}); });
}
} }
function handleListServerResponse (data) { function handleListServerResponse (data) {
...@@ -716,7 +721,6 @@ function handleListServerResponse (data) { ...@@ -716,7 +721,6 @@ function handleListServerResponse (data) {
$("#user-table").bootstrapTable("refresh"); $("#user-table").bootstrapTable("refresh");
} }
function checkboxChange(checkbox, userId, field, field_index) { function checkboxChange(checkbox, userId, field, field_index) {
$.ajax({ $.ajax({
method: "post", method: "post",
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
<div class="form-check"> <div class="form-check">
<div> <div>
<input type="radio" class="check_head" data-set="false" data-val={{value.get(array_field)}} name="options_{{array_field}}" data-name="{{parameter}}" disabled>{{_('Deny')}} <input type="radio" class="check_head" data-set="false" data-val={{value.get(array_field)}} name="options_{{array_field}}" id="false_{{array_field}}" data-name="{{parameter}}" disabled>{{_('Deny')}}
</div> </div>
<div> <div>
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment