mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-24 17:10:31 +00:00
Kobo sync token is now also created if accessed from localhost(fixes #1990)
Create kobo sync token button is now "unclicked" after closing dialog Additional localhost route is catched If book format is deleted this also deletes the book synced to kobo status
This commit is contained in:
parent
e8e2f789e5
commit
3b216bfa07
12
cps/admin.py
12
cps/admin.py
@ -1426,14 +1426,14 @@ def _delete_user(content):
|
|||||||
for kobo_entry in kobo_entries:
|
for kobo_entry in kobo_entries:
|
||||||
ub.session.delete(kobo_entry)
|
ub.session.delete(kobo_entry)
|
||||||
ub.session_commit()
|
ub.session_commit()
|
||||||
log.info(u"User {} deleted".format(content.name))
|
log.info("User {} deleted".format(content.name))
|
||||||
return(_(u"User '%(nick)s' deleted", nick=content.name))
|
return(_("User '%(nick)s' deleted", nick=content.name))
|
||||||
else:
|
else:
|
||||||
log.warning(_(u"Can't delete Guest User"))
|
log.warning(_("Can't delete Guest User"))
|
||||||
raise Exception(_(u"Can't delete Guest User"))
|
raise Exception(_("Can't delete Guest User"))
|
||||||
else:
|
else:
|
||||||
log.warning(u"No admin user remaining, can't delete user")
|
log.warning("No admin user remaining, can't delete user")
|
||||||
raise Exception(_(u"No admin user remaining, can't delete user"))
|
raise Exception(_("No admin user remaining, can't delete user"))
|
||||||
|
|
||||||
|
|
||||||
def _handle_edit_user(to_save, content, languages, translations, kobo_support):
|
def _handle_edit_user(to_save, content, languages, translations, kobo_support):
|
||||||
|
@ -341,6 +341,7 @@ def delete_book_from_table(book_id, book_format, jsonResponse):
|
|||||||
else:
|
else:
|
||||||
calibre_db.session.query(db.Data).filter(db.Data.book == book.id).\
|
calibre_db.session.query(db.Data).filter(db.Data.book == book.id).\
|
||||||
filter(db.Data.format == book_format).delete()
|
filter(db.Data.format == book_format).delete()
|
||||||
|
kobo_sync_status.remove_synced_book(book.id, True)
|
||||||
calibre_db.session.commit()
|
calibre_db.session.commit()
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
log.debug_or_exception(ex)
|
log.debug_or_exception(ex)
|
||||||
|
@ -118,20 +118,16 @@ kobo_auth = Blueprint("kobo_auth", __name__, url_prefix="/kobo_auth")
|
|||||||
@kobo_auth.route("/generate_auth_token/<int:user_id>")
|
@kobo_auth.route("/generate_auth_token/<int:user_id>")
|
||||||
@login_required
|
@login_required
|
||||||
def generate_auth_token(user_id):
|
def generate_auth_token(user_id):
|
||||||
|
warning = False
|
||||||
host_list = request.host.rsplit(':')
|
host_list = request.host.rsplit(':')
|
||||||
if len(host_list) == 1:
|
if len(host_list) == 1:
|
||||||
host = ':'.join(host_list)
|
host = ':'.join(host_list)
|
||||||
else:
|
else:
|
||||||
host = ':'.join(host_list[0:-1])
|
host = ':'.join(host_list[0:-1])
|
||||||
if host.startswith('127.') or host.lower() == 'localhost' or host.startswith('[::ffff:7f'):
|
if host.startswith('127.') or host.lower() == 'localhost' or host.startswith('[::ffff:7f') or host == "[::1]":
|
||||||
warning = _('PLease access calibre-web from non localhost to get valid api_endpoint for kobo device')
|
warning = _('Please access Calibre-Web from non localhost to get valid api_endpoint for kobo device')
|
||||||
return render_title_template(
|
|
||||||
"generate_kobo_auth_url.html",
|
# Generate auth token if none is existing for this user
|
||||||
title=_(u"Kobo Setup"),
|
|
||||||
warning = warning
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
# Invalidate any prevously generated Kobo Auth token for this user.
|
|
||||||
auth_token = ub.session.query(ub.RemoteAuthToken).filter(
|
auth_token = ub.session.query(ub.RemoteAuthToken).filter(
|
||||||
ub.RemoteAuthToken.user_id == user_id
|
ub.RemoteAuthToken.user_id == user_id
|
||||||
).filter(ub.RemoteAuthToken.token_type==1).first()
|
).filter(ub.RemoteAuthToken.token_type==1).first()
|
||||||
@ -156,17 +152,15 @@ def generate_auth_token(user_id):
|
|||||||
return render_title_template(
|
return render_title_template(
|
||||||
"generate_kobo_auth_url.html",
|
"generate_kobo_auth_url.html",
|
||||||
title=_(u"Kobo Setup"),
|
title=_(u"Kobo Setup"),
|
||||||
kobo_auth_url=url_for(
|
auth_token=auth_token.auth_token,
|
||||||
"kobo.TopLevelEndpoint", auth_token=auth_token.auth_token, _external=True
|
warning = warning
|
||||||
),
|
|
||||||
warning = False
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@kobo_auth.route("/deleteauthtoken/<int:user_id>", methods=["POST"])
|
@kobo_auth.route("/deleteauthtoken/<int:user_id>", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def delete_auth_token(user_id):
|
def delete_auth_token(user_id):
|
||||||
# Invalidate any prevously generated Kobo Auth token for this user.
|
# Invalidate any previously generated Kobo Auth token for this user
|
||||||
ub.session.query(ub.RemoteAuthToken).filter(ub.RemoteAuthToken.user_id == user_id)\
|
ub.session.query(ub.RemoteAuthToken).filter(ub.RemoteAuthToken.user_id == user_id)\
|
||||||
.filter(ub.RemoteAuthToken.token_type==1).delete()
|
.filter(ub.RemoteAuthToken.token_type==1).delete()
|
||||||
|
|
||||||
|
@ -535,6 +535,7 @@ $(function() {
|
|||||||
|
|
||||||
$("#modal_kobo_token")
|
$("#modal_kobo_token")
|
||||||
.on("show.bs.modal", function(e) {
|
.on("show.bs.modal", function(e) {
|
||||||
|
$(e.relatedTarget).one('focus', function(e){$(this).blur();});
|
||||||
var $modalBody = $(this).find(".modal-body");
|
var $modalBody = $(this).find(".modal-body");
|
||||||
|
|
||||||
// Prevent static assets from loading multiple times
|
// Prevent static assets from loading multiple times
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
{% extends "fragment.html" %}
|
{% extends "fragment.html" %}
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<div class="well">
|
<div class="well">
|
||||||
<p>
|
<p>
|
||||||
{{_('Open the .kobo/Kobo eReader.conf file in a text editor and add (or edit):')}}</a>
|
{% if not warning %}
|
||||||
|
{{_('Open the .kobo/Kobo eReader.conf file in a text editor and add (or edit):')}}
|
||||||
|
</p><p>
|
||||||
|
api_endpoint={{url_for("kobo.TopLevelEndpoint", auth_token=auth_token, _external=True)}}
|
||||||
|
{% else %}
|
||||||
|
{{warning}}
|
||||||
|
</p><p>{{_('Kobo Token:')}} {{ auth_token }}
|
||||||
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
|
||||||
{% if not warning %}api_endpoint={{kobo_auth_url}}{% else %}{{warning}}{% endif %}</a>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user