diff --git a/compensation/templates/compensation/detail/compensation/includes/documents.html b/compensation/templates/compensation/detail/compensation/includes/documents.html index 0615d4be..e12de4e9 100644 --- a/compensation/templates/compensation/detail/compensation/includes/documents.html +++ b/compensation/templates/compensation/detail/compensation/includes/documents.html @@ -27,6 +27,9 @@ {% trans 'Title' %} + + {% trans 'Created on' %} + {% trans 'Comment' %} @@ -43,18 +46,24 @@ {% for doc in obj.documents.all %} - + {{ doc.title }} + + {{ doc.date_of_creation }} +
{{ doc.comment }}
- + {% if is_default_member and has_access %} - + {% endif %} diff --git a/compensation/urls/compensation.py b/compensation/urls/compensation.py index 9c23117b..ea50b011 100644 --- a/compensation/urls/compensation.py +++ b/compensation/urls/compensation.py @@ -28,7 +28,8 @@ urlpatterns = [ # Documents path('/document/new/', new_document_view, name='new-doc'), - path('document/', get_document_view, name='get-doc'), - path('document//remove/', remove_document_view, name='remove-doc'), + path('/document/', get_document_view, name='get-doc'), + path('/document//remove/', remove_document_view, name='remove-doc'), + path('/document//edit/', edit_document_view, name='edit-doc'), ] \ No newline at end of file diff --git a/compensation/views/compensation.py b/compensation/views/compensation.py index 95f4ac0b..40ea9335 100644 --- a/compensation/views/compensation.py +++ b/compensation/views/compensation.py @@ -12,7 +12,7 @@ from compensation.tables import CompensationTable from intervention.models import Intervention from konova.contexts import BaseContext from konova.decorators import * -from konova.forms import RemoveModalForm, SimpleGeomForm, RemoveDeadlineModalForm +from konova.forms import RemoveModalForm, SimpleGeomForm, RemoveDeadlineModalForm, EditDocumentModalForm from konova.models import Deadline from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER from konova.utils.documents import get_document, remove_document @@ -20,7 +20,7 @@ from konova.utils.generators import generate_qr_code from konova.utils.message_templates import FORM_INVALID, IDENTIFIER_REPLACED, DATA_UNSHARED_EXPLANATION, \ CHECKED_RECORDED_RESET, COMPENSATION_ADDED_TEMPLATE, COMPENSATION_REMOVED_TEMPLATE, DOCUMENT_ADDED, \ COMPENSATION_STATE_REMOVED, COMPENSATION_STATE_ADDED, COMPENSATION_ACTION_REMOVED, COMPENSATION_ACTION_ADDED, \ - DEADLINE_ADDED, DEADLINE_REMOVED + DEADLINE_ADDED, DEADLINE_REMOVED, DOCUMENT_EDITED from konova.utils.user_checks import in_group @@ -286,45 +286,42 @@ def new_document_view(request: HttpRequest, id: str): @login_required @default_group_required -def get_document_view(request: HttpRequest, doc_id: str): +@shared_access_required(Compensation, "id") +def get_document_view(request: HttpRequest, id: str, doc_id: str): """ Returns the document as downloadable file Wraps the generic document fetcher function from konova.utils. Args: request (HttpRequest): The incoming request + id (str): The compensation id doc_id (str): The document id Returns: """ + comp = get_object_or_404(Compensation, id=id) doc = get_object_or_404(CompensationDocument, id=doc_id) - user = request.user - instance = doc.instance - # File download only possible if related instance is shared with user - if not instance.users.filter(id=user.id): - messages.info( - request, - DATA_UNSHARED - ) - return redirect("compensation:detail", id=instance.id) return get_document(doc) @login_required @default_group_required -def remove_document_view(request: HttpRequest, doc_id: str): +@shared_access_required(Compensation, "id") +def remove_document_view(request: HttpRequest, id: str, doc_id: str): """ Removes the document from the database and file system Wraps the generic functionality from konova.utils. Args: request (HttpRequest): The incoming request + id (str): The compensation id doc_id (str): The document id Returns: """ + comp = get_object_or_404(Compensation, id=id) doc = get_object_or_404(CompensationDocument, id=doc_id) return remove_document( request, @@ -332,6 +329,32 @@ def remove_document_view(request: HttpRequest, doc_id: str): ) +@login_required +@default_group_required +@shared_access_required(Compensation, "id") +def edit_document_view(request: HttpRequest, id: str, doc_id: str): + """ Removes the document from the database and file system + + Wraps the generic functionality from konova.utils. + + Args: + request (HttpRequest): The incoming request + id (str): The compensation id + doc_id (str): The document id + + Returns: + + """ + comp = get_object_or_404(Compensation, id=id) + doc = get_object_or_404(CompensationDocument, id=doc_id) + form = EditDocumentModalForm(request.POST or None, request.FILES or None, instance=comp, document=doc, request=request) + return form.process_request( + request, + DOCUMENT_EDITED, + reverse("compensation:detail", args=(id,)) + "#related_data" + ) + + @login_required @default_group_required @shared_access_required(Compensation, "id") diff --git a/ema/views.py b/ema/views.py index 343953f3..0650f4c9 100644 --- a/ema/views.py +++ b/ema/views.py @@ -383,15 +383,6 @@ def get_document_view(request: HttpRequest, id: str, doc_id: str): """ ema = get_object_or_404(Ema, id=id) doc = get_object_or_404(EmaDocument, id=doc_id) - user = request.user - instance = doc.instance - # File download only possible if related instance is shared with user - if not instance.users.filter(id=user.id): - messages.info( - request, - DATA_UNSHARED - ) - return redirect("ema:detail", id=instance.id) return get_document(doc) diff --git a/intervention/views.py b/intervention/views.py index 2945c337..00440bb8 100644 --- a/intervention/views.py +++ b/intervention/views.py @@ -161,7 +161,6 @@ def get_revocation_view(request: HttpRequest, doc_id: str): return redirect("intervention:detail", id=doc.instance.id) return get_document(doc) - @login_required @default_group_required @shared_access_required(Intervention, "id") @@ -180,15 +179,6 @@ def get_document_view(request: HttpRequest, id: str, doc_id: str): """ intervention = get_object_or_404(Intervention, id=id) doc = get_object_or_404(InterventionDocument, id=doc_id) - user = request.user - instance = doc.instance - # File download only possible if related instance is shared with user - if not instance.users.filter(id=user.id): - messages.info( - request, - DATA_UNSHARED - ) - return redirect("intervention:detail", id=instance.id) return get_document(doc)