Fixes from tests

This commit is contained in:
OzzieIsaacs 2020-05-21 22:26:06 +02:00
parent a20a155d39
commit 0cf1cc5587
7 changed files with 244 additions and 799 deletions

View file

@ -522,6 +522,7 @@ def _configuration_gdrive_helper(to_save):
def _configuration_oauth_helper(to_save):
active_oauths = 0
reboot_required = False
for element in oauthblueprints:
if to_save["config_" + str(element['id']) + "_oauth_client_id"] != element['oauth_client_id'] \
or to_save["config_" + str(element['id']) + "_oauth_client_secret"] != element['oauth_client_secret']:
@ -538,6 +539,7 @@ def _configuration_oauth_helper(to_save):
{"oauth_client_id": to_save["config_" + str(element['id']) + "_oauth_client_id"],
"oauth_client_secret": to_save["config_" + str(element['id']) + "_oauth_client_secret"],
"active": element["active"]})
return reboot_required
def _configuration_logfile_helper(to_save, gdriveError):
reboot_required = False
@ -552,7 +554,7 @@ def _configuration_logfile_helper(to_save, gdriveError):
return reboot_required, _configuration_result(_('Access Logfile Location is not Valid, Please Enter Correct Path'), gdriveError)
return reboot_required, None
def _configuration_ldap_helper(gdriveError, to_save):
def _configuration_ldap_helper(to_save, gdriveError):
reboot_required = False
reboot_required |= _config_string(to_save, "config_ldap_provider_url")
reboot_required |= _config_int(to_save, "config_ldap_port")
@ -575,36 +577,36 @@ def _configuration_ldap_helper(gdriveError, to_save):
or not config.config_ldap_port \
or not config.config_ldap_dn \
or not config.config_ldap_user_object:
return _configuration_result(_('Please Enter a LDAP Provider, '
return reboot_required, _configuration_result(_('Please Enter a LDAP Provider, '
'Port, DN and User Object Identifier'), gdriveError)
if config.config_ldap_authentication > constants.LDAP_AUTH_ANONYMOUS:
if config.config_ldap_authentication > constants.LDAP_AUTH_UNAUTHENTICATE:
if not config.config_ldap_serv_username or not bool(config.config_ldap_serv_password):
return _configuration_result('Please Enter a LDAP Service Account and Password', gdriveError)
return reboot_required, _configuration_result('Please Enter a LDAP Service Account and Password', gdriveError)
else:
if not config.config_ldap_serv_username:
return _configuration_result('Please Enter a LDAP Service Account', gdriveError)
return reboot_required, _configuration_result('Please Enter a LDAP Service Account', gdriveError)
if config.config_ldap_group_object_filter:
if config.config_ldap_group_object_filter.count("%s") != 1:
return _configuration_result(_('LDAP Group Object Filter Needs to Have One "%s" Format Identifier'),
return reboot_required, _configuration_result(_('LDAP Group Object Filter Needs to Have One "%s" Format Identifier'),
gdriveError)
if config.config_ldap_group_object_filter.count("(") != config.config_ldap_group_object_filter.count(")"):
return _configuration_result(_('LDAP Group Object Filter Has Unmatched Parenthesis'),
return reboot_required, _configuration_result(_('LDAP Group Object Filter Has Unmatched Parenthesis'),
gdriveError)
if config.config_ldap_user_object.count("%s") != 1:
return _configuration_result(_('LDAP User Object Filter needs to Have One "%s" Format Identifier'),
return reboot_required, _configuration_result(_('LDAP User Object Filter needs to Have One "%s" Format Identifier'),
gdriveError)
if config.config_ldap_user_object.count("(") != config.config_ldap_user_object.count(")"):
return _configuration_result(_('LDAP User Object Filter Has Unmatched Parenthesis'),
return reboot_required, _configuration_result(_('LDAP User Object Filter Has Unmatched Parenthesis'),
gdriveError)
if config.config_ldap_cert_path and not os.path.isdir(config.config_ldap_cert_path):
return _configuration_result(_('LDAP Certificate Location is not Valid, Please Enter Correct Path'),
return reboot_required, _configuration_result(_('LDAP Certificate Location is not Valid, Please Enter Correct Path'),
gdriveError)
return reboot_required
return reboot_required, None
def _configuration_update_helper():
@ -612,7 +614,7 @@ def _configuration_update_helper():
db_change = False
to_save = request.form.to_dict()
to_save['config_calibre_dir'] = re.sub('[[\\/]metadata\.db$', '', to_save['config_calibre_dir'], flags=re.IGNORECASE)
to_save['config_calibre_dir'] = re.sub('[\\/]metadata\.db$', '', to_save['config_calibre_dir'], flags=re.IGNORECASE)
db_change |= _config_string(to_save, "config_calibre_dir")
# Google drive setup
@ -673,7 +675,7 @@ def _configuration_update_helper():
# OAuth configuration
if config.config_login_type == constants.LOGIN_OAUTH:
_configuration_oauth_helper(to_save)
reboot_required |= _configuration_oauth_helper(to_save)
reboot, message = _configuration_logfile_helper(to_save, gdriveError)
if message:
@ -694,7 +696,7 @@ def _configuration_update_helper():
return _configuration_result('%s' % e, gdriveError)
if db_change:
if not db.setup_db(config, ub.app_DB_path):
if not calibre_db.setup_db(config, ub.app_DB_path):
return _configuration_result(_('DB Location is not Valid, Please Enter Correct Path'), gdriveError)
if not os.access(os.path.join(config.config_calibre_dir, "metadata.db"), os.W_OK):
flash(_(u"DB is not Writeable"), category="warning")

View file

@ -39,7 +39,7 @@ try:
except ImportError:
pass
from . import logger, gdriveutils, config, db, ub
from . import logger, gdriveutils, config, ub, calibre_db
from .web import admin_required
@ -155,7 +155,7 @@ def on_received_watch_confirmation():
log.info('Setting up new DB')
# prevent error on windows, as os.rename does on exisiting files
move(os.path.join(tmpDir, "tmp_metadata.db"), dbpath)
db.setup_db(config, ub.app_DB_path)
calibre_db.setup_db(config, ub.app_DB_path)
except Exception as e:
log.exception(e)
updateMetaData()

View file

@ -879,7 +879,7 @@ def get_cc_columns(filter_config_custom_read=False):
for col in tmpcc:
if filter_config_custom_read and config.config_read_column and config.config_read_column == col.id:
continue
if r and r.match(col.label):
if r and r.match(col.name):
continue
cc.append(col)

View file

@ -143,7 +143,7 @@ def HandleSyncRequest():
# We reload the book database so that the user get's a fresh view of the library
# in case of external changes (e.g: adding a book through Calibre).
db.reconnect_db(config, ub.app_DB_path)
calibre_db.reconnect_db(config, ub.app_DB_path)
archived_books = (
ub.session.query(ub.ArchivedBook)

View file

@ -121,9 +121,9 @@ for ex in default_exceptions:
if feature_support['ldap']:
# Only way of catching the LDAPException upon logging in with LDAP server down
@app.errorhandler(services.ldap.LDAPException)
def handle_LDAP_exception(e):
log.debug('LDAP server not accssible while trying to login to opds feed %s', e)
return error_http(e)
def handle_exception(e):
log.debug('LDAP server not accessible while trying to login to opds feed')
return error_http(FailedDependency())
# @app.errorhandler(InvalidRequestError)
#@app.errorhandler(OperationalError)
@ -889,7 +889,7 @@ def ratings_list():
if current_user.check_visibility(constants.SIDEBAR_RATING):
entries = calibre_db.session.query(db.Ratings, func.count('books_ratings_link.book').label('count'),
(db.Ratings.rating / 2).label('name')) \
.join(calibre_db.books_ratings_link).join(db.Books).filter(common_filters()) \
.join(db.books_ratings_link).join(db.Books).filter(common_filters()) \
.group_by(text('books_ratings_link.rating')).order_by(db.Ratings.rating).all()
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=list(),
title=_(u"Ratings list"), page="ratingslist", data="ratings")

View file

@ -333,7 +333,6 @@ class WorkerThread(threading.Thread):
task = {'task':'add_format','id': bookid, 'format': new_format}
self.db_queue.put(task)
# To Do how to handle error?
print('finished')
'''cur_book.data.append(new_format)
try:

File diff suppressed because it is too large Load diff