From cd0fc917d7bd024bdd770b1ecf0c05da588db785 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Thu, 27 Sep 2018 22:04:57 +0200 Subject: [PATCH 1/2] Bugfix template rights at creating user Added errormessages for shelf actions Additional ids for better testability --- cps/templates/shelf.html | 20 +++++++++++--------- cps/web.py | 15 ++++++++++++++- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/cps/templates/shelf.html b/cps/templates/shelf.html index d70383ff..28cd20bb 100644 --- a/cps/templates/shelf.html +++ b/cps/templates/shelf.html @@ -4,9 +4,9 @@

{{title}}

{% if g.user.is_authenticated %} {% if (g.user.role_edit_shelfs() and shelf.is_public ) or not shelf.is_public %} -
{{ _('Delete this Shelf') }}
- {{ _('Edit Shelf') }} - {{ _('Change order') }} +
{{ _('Delete this Shelf') }}
+ {{ _('Edit Shelf') }} + {{ _('Change order') }} {% endif %} {% endif %}
@@ -14,11 +14,13 @@ {% for entry in entries %}
- {% if entry.has_cover is defined %} - - - - {% endif %} + + {% if entry.has_cover %} + {{ entry.title }} + {% else %} + {{ entry.title }} + {% endif %} +

{{entry.title|shortentitle}}

@@ -56,7 +58,7 @@
diff --git a/cps/web.py b/cps/web.py index 9b56b926..5de0a730 100644 --- a/cps/web.py +++ b/cps/web.py @@ -2419,18 +2419,22 @@ def add_to_shelf(shelf_id, book_id): if shelf is None: app.logger.info("Invalid shelf specified") if not request.is_xhr: + flash(_(u"Invalid shelf specified"), category="error") return redirect(url_for('index')) return "Invalid shelf specified", 400 if not shelf.is_public and not shelf.user_id == int(current_user.id): app.logger.info("Sorry you are not allowed to add a book to the the shelf: %s" % shelf.name) if not request.is_xhr: + flash(_(u"Sorry you are not allowed to add a book to the the shelf: %(shelfname)s", shelfname=shelf.name), + category="error") return redirect(url_for('index')) return "Sorry you are not allowed to add a book to the the shelf: %s" % shelf.name, 403 if shelf.is_public and not current_user.role_edit_shelfs(): app.logger.info("User is not allowed to edit public shelves") if not request.is_xhr: + flash(_(u"You are not allowed to edit public shelves"), category="error") return redirect(url_for('index')) return "User is not allowed to edit public shelves", 403 @@ -2439,6 +2443,7 @@ def add_to_shelf(shelf_id, book_id): if book_in_shelf: app.logger.info("Book is already part of the shelf: %s" % shelf.name) if not request.is_xhr: + flash(_(u"Book is already part of the shelf: %(shelfname)s", shelfname=shelf.name), category="error") return redirect(url_for('index')) return "Book is already part of the shelf: %s" % shelf.name, 400 @@ -2453,7 +2458,10 @@ def add_to_shelf(shelf_id, book_id): ub.session.commit() if not request.is_xhr: flash(_(u"Book has been added to shelf: %(sname)s", sname=shelf.name), category="success") - return redirect(request.environ["HTTP_REFERER"]) + if "HTTP_REFERER" in request.environ: + return redirect(request.environ["HTTP_REFERER"]) + else: + return redirect(url_for('index')) return "", 204 @@ -3109,6 +3117,11 @@ def new_user(): content.sidebar_view += ub.SIDEBAR_AUTHOR if "show_detail_random" in to_save: content.sidebar_view += ub.DETAIL_RANDOM + if "show_sorted" in to_save: + content.sidebar_view += ub.SIDEBAR_SORTED + if "show_recent" in to_save: + content.sidebar_view += ub.SIDEBAR_RECENT + content.role = 0 if "admin_role" in to_save: content.role = content.role + ub.ROLE_ADMIN From c36b1ed58ae66e8ccc4a3cfa6511589ace9c839f Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sat, 29 Sep 2018 15:44:42 +0200 Subject: [PATCH 2/2] Added additional ids and classes for easier testing --- cps/templates/config_view_edit.html | 2 +- cps/templates/layout.html | 4 ++-- cps/templates/user_edit.html | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cps/templates/config_view_edit.html b/cps/templates/config_view_edit.html index 83fb4beb..5cbf8e65 100644 --- a/cps/templates/config_view_edit.html +++ b/cps/templates/config_view_edit.html @@ -160,7 +160,7 @@
- + {{_('Back')}}
diff --git a/cps/templates/layout.html b/cps/templates/layout.html index f821c08b..8ccce35c 100644 --- a/cps/templates/layout.html +++ b/cps/templates/layout.html @@ -165,11 +165,11 @@ {% if g.user.is_authenticated or g.user.is_anonymous %} {% for shelf in g.public_shelfes %} -
  • {{shelf.name}}
  • +
  • {{shelf.name|shortentitle(40)}}
  • {% endfor %} {% for shelf in g.user.shelf %} -
  • {{shelf.name}}
  • +
  • {{shelf.name|shortentitle(40)}}
  • {% endfor %} {% if not g.user.is_anonymous %} diff --git a/cps/templates/user_edit.html b/cps/templates/user_edit.html index c3fccc40..ecf8042e 100644 --- a/cps/templates/user_edit.html +++ b/cps/templates/user_edit.html @@ -140,7 +140,7 @@ {% if g.user and g.user.role_admin() and not profile and not new_user and not content.role_anonymous() %}
    {% endif %} @@ -149,8 +149,8 @@ {% if not profile %} {{_('Back')}} - {% endif %} + {% if downloads %}