fix edit, delete interpretation

This commit is contained in:
SvyatoslavArtymovych 2023-06-02 10:17:55 +03:00
parent ddc7090158
commit 544f512d79
4 changed files with 11 additions and 8 deletions

View File

@ -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)

View File

@ -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(

View File

@ -146,7 +146,7 @@
</div>
{% 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 %}
<div class="relative mt-1">
<button id="callDeleteInterpretationModal" data-popover-target="popover-delete" data-interpretation-id="{{interpretation.id}}" type="button" data-modal-target="delete_interpretation_modal" data-modal-toggle="delete_interpretation_modal" class="space-x-0.5 flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"> <path stroke-linecap="round" stroke-linejoin="round" d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0" /> </svg>

View File

@ -63,8 +63,8 @@ export function editInterpretations() {
let newActionPath: string = '';
newActionPath = defaultActionPath.replace(
'0/interpretation_edit',
`${interpretationId}/interpretation_edit`,
'0/edit_interpretation',
`${interpretationId}/edit_interpretation`,
);
editInterpretationForm.setAttribute('action', `${newActionPath}`);