From 964010839569b37e665fe6824e7f760c00c45548 Mon Sep 17 00:00:00 2001 From: Kostiantyn Stoliarskyi Date: Fri, 2 Jun 2023 09:14:21 +0300 Subject: [PATCH 01/10] fix sub_coll modal --- app/templates/book/modals/add_sub_collection_modal.html | 8 -------- 1 file changed, 8 deletions(-) diff --git a/app/templates/book/modals/add_sub_collection_modal.html b/app/templates/book/modals/add_sub_collection_modal.html index 37d366b..46199f9 100644 --- a/app/templates/book/modals/add_sub_collection_modal.html +++ b/app/templates/book/modals/add_sub_collection_modal.html @@ -23,14 +23,6 @@ -
-
-
- - -
-
-
From ddc7090158a7c8668fb09e24012faa949ac605b3 Mon Sep 17 00:00:00 2001 From: SvyatoslavArtymovych Date: Fri, 2 Jun 2023 09:55:13 +0300 Subject: [PATCH 02/10] hide delete book for editor --- app/templates/book/settings.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/templates/book/settings.html b/app/templates/book/settings.html index 67f75fc..8b5e0d1 100644 --- a/app/templates/book/settings.html +++ b/app/templates/book/settings.html @@ -76,7 +76,9 @@
- + {% if book.user_id == current_user %} + + {% endif %}
From 9da0eea31ae6980fe13d96dff0015f68fd6c0b8c Mon Sep 17 00:00:00 2001 From: Kostiantyn Stoliarskyi Date: Fri, 2 Jun 2023 10:08:33 +0300 Subject: [PATCH 03/10] fix route on book stat --- app/views/book/book.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/views/book/book.py b/app/views/book/book.py index 0fe409b..e51a28a 100644 --- a/app/views/book/book.py +++ b/app/views/book/book.py @@ -1,9 +1,4 @@ -from flask import ( - render_template, - flash, - redirect, - url_for, -) +from flask import render_template, flash, redirect, url_for, request from flask_login import login_required, current_user from sqlalchemy import and_, or_ @@ -180,11 +175,12 @@ def delete(book_id: int): @bp.route("//statistics", methods=["GET"]) def statistic_view(book_id: int): book = db.session.get(m.Book, book_id) + active_tab = request.args.get("active_tab") if not book or book.is_deleted: log(log.WARNING, "Book with id [%s] not found", book_id) flash("Book not found", "danger") return redirect(url_for("book.my_library")) - return render_template("book/stat.html", book=book) + return render_template("book/stat.html", book=book, active_tab=active_tab) @bp.route("/favorite_books", methods=["GET"]) From 544f512d79f9a49e0158bcb61f7748a0bdc44296 Mon Sep 17 00:00:00 2001 From: SvyatoslavArtymovych Date: Fri, 2 Jun 2023 10:17:55 +0300 Subject: [PATCH 04/10] fix edit, delete interpretation --- app/controllers/book_verify.py | 10 +++++----- app/controllers/require_permission.py | 3 +++ app/templates/book/interpretation_view.html | 2 +- src/editInterpretations.ts | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/controllers/book_verify.py b/app/controllers/book_verify.py index ad1cac5..2eb6589 100644 --- a/app/controllers/book_verify.py +++ b/app/controllers/book_verify.py @@ -46,7 +46,7 @@ def book_validator() -> Response | None: return redirect(url_for("book.my_library")) collection_id = request_args.get("collection_id") - if collection_id: + if collection_id is not None: collection: m.Collection = db.session.get(m.Collection, collection_id) if not collection or collection.is_deleted: log(log.WARNING, "Collection with id [%s] not found", collection_id) @@ -54,7 +54,7 @@ def book_validator() -> Response | None: return redirect(url_for("book.collection_view", book_id=book_id)) sub_collection_id = request_args.get("sub_collection_id") - if sub_collection_id: + if sub_collection_id is not None: sub_collection: m.Collection = db.session.get(m.Collection, sub_collection_id) if not sub_collection or sub_collection.is_deleted: log(log.WARNING, "Sub_collection with id [%s] not found", sub_collection_id) @@ -66,7 +66,7 @@ def book_validator() -> Response | None: ) section_id = request_args.get("section_id") - if section_id: + if section_id is not None: section: m.Section = db.session.get(m.Section, section_id) if not section: log(log.WARNING, "Section with id [%s] not found", section) @@ -74,7 +74,7 @@ def book_validator() -> Response | None: return redirect(url_for("book.collection_view", book_id=book_id)) interpretation_id = request_args.get("interpretation_id") - if interpretation_id: + if interpretation_id is not None: interpretation: m.Interpretation = db.session.get( m.Interpretation, interpretation_id ) @@ -88,7 +88,7 @@ def book_validator() -> Response | None: ) comment_id = request_args.get("comment_id") - if comment_id: + if comment_id is not None: comment: m.Comment = db.session.get(m.Comment, comment_id) if not comment or comment.is_deleted: log(log.WARNING, "Comment with id [%s] not found", comment_id) diff --git a/app/controllers/require_permission.py b/app/controllers/require_permission.py index 435df99..4014871 100644 --- a/app/controllers/require_permission.py +++ b/app/controllers/require_permission.py @@ -42,6 +42,9 @@ def check_permissions( if type(entity) == m.Comment: log(log.INFO, "Entity is Comment. Replace it by entity.interpretation") entity = entity.interpretation + elif type(entity) == m.Interpretation and entity.user_id == current_user.id: + log(log.INFO, "User [%s] is interpretation creator [%s]", current_user, entity) + return None if not entity or not entity.access_groups: log( diff --git a/app/templates/book/interpretation_view.html b/app/templates/book/interpretation_view.html index 7c56ad0..a4ea015 100644 --- a/app/templates/book/interpretation_view.html +++ b/app/templates/book/interpretation_view.html @@ -146,7 +146,7 @@ {% endif %} - {% if interpretation.book.owner == current_user or access_to_delete_interpretation %} + {% if interpretation.book.owner == current_user or interpretation.user_id == current_user.id or access_to_delete_interpretation %}