Merge pull request '#32 Disable file download' (#34) from 32_Disable_file_download into master

Reviewed-on: SGD-Nord/konova#34
This commit is contained in:
Michel Peltriaux 2021-10-25 09:37:51 +02:00
commit e2409fdbde
6 changed files with 55 additions and 8 deletions

View File

@ -14,7 +14,7 @@ from konova.decorators import *
from konova.forms import RemoveModalForm, SimpleGeomForm, NewDocumentForm from konova.forms import RemoveModalForm, SimpleGeomForm, NewDocumentForm
from konova.utils.documents import get_document, remove_document from konova.utils.documents import get_document, remove_document
from konova.utils.generators import generate_qr_code from konova.utils.generators import generate_qr_code
from konova.utils.message_templates import FORM_INVALID, IDENTIFIER_REPLACED from konova.utils.message_templates import FORM_INVALID, IDENTIFIER_REPLACED, DATA_UNSHARED_EXPLANATION
from konova.utils.user_checks import in_group from konova.utils.user_checks import in_group
@ -173,6 +173,9 @@ def detail_view(request: HttpRequest, id: str):
sum_after_states = after_states.aggregate(Sum("surface"))["surface__sum"] or 0 sum_after_states = after_states.aggregate(Sum("surface"))["surface__sum"] or 0
diff_states = abs(sum_before_states - sum_after_states) diff_states = abs(sum_before_states - sum_after_states)
if not is_data_shared:
messages.info(request, DATA_UNSHARED_EXPLANATION)
context = { context = {
"obj": comp, "obj": comp,
"geom_form": geom_form, "geom_form": geom_form,
@ -268,6 +271,15 @@ def get_document_view(request: HttpRequest, doc_id: str):
""" """
doc = get_object_or_404(CompensationDocument, id=doc_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) return get_document(doc)

View File

@ -25,7 +25,7 @@ from konova.forms import RemoveModalForm, SimpleGeomForm, NewDocumentForm, Recor
from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP
from konova.utils.documents import get_document, remove_document from konova.utils.documents import get_document, remove_document
from konova.utils.generators import generate_qr_code from konova.utils.generators import generate_qr_code
from konova.utils.message_templates import IDENTIFIER_REPLACED, FORM_INVALID from konova.utils.message_templates import IDENTIFIER_REPLACED, FORM_INVALID, DATA_UNSHARED, DATA_UNSHARED_EXPLANATION
from konova.utils.user_checks import in_group from konova.utils.user_checks import in_group
@ -197,6 +197,9 @@ def detail_view(request: HttpRequest, id: str):
) )
actions = acc.actions.all() actions = acc.actions.all()
if not is_data_shared:
messages.info(request, DATA_UNSHARED_EXPLANATION)
context = { context = {
"obj": acc, "obj": acc,
"geom_form": geom_form, "geom_form": geom_form,
@ -401,6 +404,15 @@ def get_document_view(request: HttpRequest, doc_id: str):
""" """
doc = get_object_or_404(EcoAccountDocument, id=doc_id) doc = get_object_or_404(EcoAccountDocument, 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:acc-detail", id=instance.id)
return get_document(doc) return get_document(doc)

View File

@ -17,7 +17,7 @@ from konova.forms import RemoveModalForm, NewDocumentForm, SimpleGeomForm, Recor
from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP
from konova.utils.documents import get_document, remove_document from konova.utils.documents import get_document, remove_document
from konova.utils.generators import generate_qr_code from konova.utils.generators import generate_qr_code
from konova.utils.message_templates import IDENTIFIER_REPLACED, FORM_INVALID from konova.utils.message_templates import IDENTIFIER_REPLACED, FORM_INVALID, DATA_UNSHARED, DATA_UNSHARED_EXPLANATION
from konova.utils.user_checks import in_group from konova.utils.user_checks import in_group
@ -136,6 +136,9 @@ def detail_view(request: HttpRequest, id: str):
sum_after_states = after_states.aggregate(Sum("surface"))["surface__sum"] or 0 sum_after_states = after_states.aggregate(Sum("surface"))["surface__sum"] or 0
diff_states = abs(sum_before_states - sum_after_states) diff_states = abs(sum_before_states - sum_after_states)
if not is_data_shared:
messages.info(request, DATA_UNSHARED_EXPLANATION)
context = { context = {
"obj": ema, "obj": ema,
"geom_form": geom_form, "geom_form": geom_form,
@ -343,6 +346,15 @@ def get_document_view(request: HttpRequest, doc_id: str):
""" """
doc = get_object_or_404(EmaDocument, id=doc_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) return get_document(doc)

View File

@ -14,7 +14,8 @@ from konova.forms import SimpleGeomForm, NewDocumentForm, RemoveModalForm, Recor
from konova.sub_settings.django_settings import DEFAULT_DATE_FORMAT from konova.sub_settings.django_settings import DEFAULT_DATE_FORMAT
from konova.utils.documents import remove_document, get_document from konova.utils.documents import remove_document, get_document
from konova.utils.generators import generate_qr_code from konova.utils.generators import generate_qr_code
from konova.utils.message_templates import INTERVENTION_INVALID, FORM_INVALID, IDENTIFIER_REPLACED from konova.utils.message_templates import INTERVENTION_INVALID, FORM_INVALID, IDENTIFIER_REPLACED, \
DATA_UNSHARED_EXPLANATION
from konova.utils.user_checks import in_group from konova.utils.user_checks import in_group
@ -158,6 +159,15 @@ def get_document_view(request: HttpRequest, doc_id: str):
""" """
doc = get_object_or_404(InterventionDocument, id=doc_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) return get_document(doc)
@ -234,7 +244,7 @@ def detail_view(request: HttpRequest, id: str):
} }
if not is_data_shared: if not is_data_shared:
messages.info(request, _("Remember: This data has not been shared with you, yet. This means you can only read but can not edit or perform any actions like running a check or recording.")) messages.info(request, DATA_UNSHARED_EXPLANATION)
context = BaseContext(request, context).context context = BaseContext(request, context).context
return render(request, template, context) return render(request, template, context)

View File

@ -13,4 +13,5 @@ PARAMS_INVALID = _("Invalid parameters")
INTERVENTION_INVALID = _("There are errors in this intervention.") INTERVENTION_INVALID = _("There are errors in this intervention.")
IDENTIFIER_REPLACED = _("The identifier '{}' had to be changed to '{}' since another entry has been added in the meanwhile, which uses this identifier") IDENTIFIER_REPLACED = _("The identifier '{}' had to be changed to '{}' since another entry has been added in the meanwhile, which uses this identifier")
DATA_UNSHARED = _("This data is not shared with you") DATA_UNSHARED = _("This data is not shared with you")
DATA_UNSHARED_EXPLANATION = _("Remember: This data has not been shared with you, yet. This means you can only read but can not edit or perform any actions like running a check or recording.")
MISSING_GROUP_PERMISSION = _("You need to be part of another user group.") MISSING_GROUP_PERMISSION = _("You need to be part of another user group.")

View File

@ -79,7 +79,7 @@ class UserContactForm(BaseModalForm):
widget=forms.TextInput( widget=forms.TextInput(
attrs={ attrs={
"readonly": True, "readonly": True,
"style": "width:100%", "class": "form-control",
} }
), ),
) )
@ -90,7 +90,7 @@ class UserContactForm(BaseModalForm):
widget=forms.TextInput( widget=forms.TextInput(
attrs={ attrs={
"readonly": True, "readonly": True,
"style": "width:100%", "class": "form-control",
} }
), ),
) )
@ -101,7 +101,7 @@ class UserContactForm(BaseModalForm):
widget=forms.TextInput( widget=forms.TextInput(
attrs={ attrs={
"readonly": True, "readonly": True,
"style": "width:100%", "class": "form-control",
} }
), ),
) )