86_User_suggestions_and_feedback #106

Merged
mpeltriaux merged 12 commits from 86_User_suggestions_and_feedback into master 2022-02-04 14:47:24 +01:00
13 changed files with 56 additions and 26 deletions
Showing only changes of commit 298a632cac - Show all commits

View File

@ -3,6 +3,8 @@ from django.contrib import admin
from compensation.models import Compensation, CompensationAction, CompensationState, Payment, \ from compensation.models import Compensation, CompensationAction, CompensationState, Payment, \
EcoAccountDeduction, EcoAccount EcoAccountDeduction, EcoAccount
from konova.admin import BaseObjectAdmin, BaseResourceAdmin from konova.admin import BaseObjectAdmin, BaseResourceAdmin
from konova.utils.message_templates import COMPENSATION_REMOVED_TEMPLATE
from user.models import UserAction
class AbstractCompensationAdmin(BaseObjectAdmin): class AbstractCompensationAdmin(BaseObjectAdmin):
@ -42,6 +44,17 @@ class CompensationAdmin(AbstractCompensationAdmin):
"intervention", "intervention",
] ]
def restore_deleted_data(self, request, queryset):
super().restore_deleted_data(request, queryset)
for entry in queryset:
# Remove delete log entry from related intervention log history
logs = entry.intervention.log.filter(
action=UserAction.EDITED,
comment=COMPENSATION_REMOVED_TEMPLATE.format(entry.identifier)
)
logs.delete()
class EcoAccountAdmin(AbstractCompensationAdmin): class EcoAccountAdmin(AbstractCompensationAdmin):
list_display = [ list_display = [

View File

@ -20,7 +20,8 @@ from compensation.utils.quality import CompensationQualityChecker
from konova.models import BaseObject, AbstractDocument, Deadline, generate_document_file_upload_path, \ from konova.models import BaseObject, AbstractDocument, Deadline, generate_document_file_upload_path, \
GeoReferencedMixin GeoReferencedMixin
from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE
from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, COMPENSATION_REMOVED_TEMPLATE from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, COMPENSATION_REMOVED_TEMPLATE, \
DOCUMENT_REMOVED_TEMPLATE
from user.models import UserActionLogEntry from user.models import UserActionLogEntry
@ -358,7 +359,7 @@ class CompensationDocument(AbstractDocument):
max_length=1000, max_length=1000,
) )
def delete(self, *args, **kwargs): def delete(self, user=None, *args, **kwargs):
""" """
Custom delete functionality for CompensationDocuments. Custom delete functionality for CompensationDocuments.
Removes the folder from the file system if there are no further documents for this entry. Removes the folder from the file system if there are no further documents for this entry.
@ -380,6 +381,9 @@ class CompensationDocument(AbstractDocument):
folder_path = self.file.path.split("/")[:-1] folder_path = self.file.path.split("/")[:-1]
folder_path = "/".join(folder_path) folder_path = "/".join(folder_path)
if user:
self.instance.mark_as_edited(user, edit_comment=DOCUMENT_REMOVED_TEMPLATE.format(self.title))
# Remove the file itself # Remove the file itself
super().delete(*args, **kwargs) super().delete(*args, **kwargs)

View File

@ -9,7 +9,7 @@ import shutil
from django.urls import reverse from django.urls import reverse
from konova.utils.message_templates import DEDUCTION_REMOVED from konova.utils.message_templates import DEDUCTION_REMOVED, DOCUMENT_REMOVED_TEMPLATE
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.core.validators import MinValueValidator from django.core.validators import MinValueValidator
from django.db import models from django.db import models
@ -199,7 +199,7 @@ class EcoAccountDocument(AbstractDocument):
max_length=1000, max_length=1000,
) )
def delete(self, *args, **kwargs): def delete(self, user=None, *args, **kwargs):
""" """
Custom delete functionality for EcoAccountDocuments. Custom delete functionality for EcoAccountDocuments.
Removes the folder from the file system if there are no further documents for this entry. Removes the folder from the file system if there are no further documents for this entry.
@ -221,6 +221,9 @@ class EcoAccountDocument(AbstractDocument):
folder_path = self.file.path.split("/")[:-1] folder_path = self.file.path.split("/")[:-1]
folder_path = "/".join(folder_path) folder_path = "/".join(folder_path)
if user:
self.instance.mark_as_edited(user, edit_comment=DOCUMENT_REMOVED_TEMPLATE.format(self.title))
# Remove the file itself # Remove the file itself
super().delete(*args, **kwargs) super().delete(*args, **kwargs)

View File

@ -18,7 +18,7 @@ from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
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, DATA_UNSHARED_EXPLANATION, \ from konova.utils.message_templates import FORM_INVALID, IDENTIFIER_REPLACED, DATA_UNSHARED_EXPLANATION, \
CHECKED_RECORDED_RESET, COMPENSATION_ADDED_TEMPLATE, COMPENSATION_REMOVED_TEMPLATE CHECKED_RECORDED_RESET, COMPENSATION_ADDED_TEMPLATE, COMPENSATION_REMOVED_TEMPLATE, DOCUMENT_ADDED
from konova.utils.user_checks import in_group from konova.utils.user_checks import in_group
@ -277,7 +277,7 @@ def new_document_view(request: HttpRequest, id: str):
form = NewCompensationDocumentForm(request.POST or None, request.FILES or None, instance=comp, request=request) form = NewCompensationDocumentForm(request.POST or None, request.FILES or None, instance=comp, request=request)
return form.process_request( return form.process_request(
request, request,
msg_success=_("Document added"), msg_success=DOCUMENT_ADDED,
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data" redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
) )

View File

@ -30,7 +30,7 @@ from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
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, DATA_UNSHARED, DATA_UNSHARED_EXPLANATION, \ from konova.utils.message_templates import IDENTIFIER_REPLACED, FORM_INVALID, DATA_UNSHARED, DATA_UNSHARED_EXPLANATION, \
CANCEL_ACC_RECORDED_OR_DEDUCTED, DEDUCTION_REMOVED, DEDUCTION_ADDED CANCEL_ACC_RECORDED_OR_DEDUCTED, DEDUCTION_REMOVED, DEDUCTION_ADDED, DOCUMENT_ADDED
from konova.utils.user_checks import in_group from konova.utils.user_checks import in_group
@ -493,7 +493,7 @@ def new_document_view(request: HttpRequest, id: str):
form = NewEcoAccountDocumentForm(request.POST or None, request.FILES or None, instance=acc, request=request) form = NewEcoAccountDocumentForm(request.POST or None, request.FILES or None, instance=acc, request=request)
return form.process_request( return form.process_request(
request, request,
msg_success=_("Document added"), msg_success=DOCUMENT_ADDED,
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data", redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data",
) )

View File

@ -18,7 +18,7 @@ from ema.managers import EmaManager
from ema.utils.quality import EmaQualityChecker from ema.utils.quality import EmaQualityChecker
from konova.models import AbstractDocument, generate_document_file_upload_path, RecordableObjectMixin, ShareableObjectMixin from konova.models import AbstractDocument, generate_document_file_upload_path, RecordableObjectMixin, ShareableObjectMixin
from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE
from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, DOCUMENT_REMOVED_TEMPLATE
class Ema(AbstractCompensation, ShareableObjectMixin, RecordableObjectMixin): class Ema(AbstractCompensation, ShareableObjectMixin, RecordableObjectMixin):
@ -143,7 +143,7 @@ class EmaDocument(AbstractDocument):
max_length=1000, max_length=1000,
) )
def delete(self, *args, **kwargs): def delete(self, user=None, *args, **kwargs):
""" """
Custom delete functionality for EcoAccountDocuments. Custom delete functionality for EcoAccountDocuments.
Removes the folder from the file system if there are no further documents for this entry. Removes the folder from the file system if there are no further documents for this entry.
@ -165,6 +165,9 @@ class EmaDocument(AbstractDocument):
folder_path = self.file.path.split("/")[:-1] folder_path = self.file.path.split("/")[:-1]
folder_path = "/".join(folder_path) folder_path = "/".join(folder_path)
if user:
self.instance.mark_as_edited(user, edit_comment=DOCUMENT_REMOVED_TEMPLATE.format(self.title))
# Remove the file itself # Remove the file itself
super().delete(*args, **kwargs) super().delete(*args, **kwargs)

View File

@ -20,7 +20,8 @@ from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
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, DATA_UNSHARED, DATA_UNSHARED_EXPLANATION from konova.utils.message_templates import IDENTIFIER_REPLACED, FORM_INVALID, DATA_UNSHARED, DATA_UNSHARED_EXPLANATION, \
DOCUMENT_ADDED
from konova.utils.user_checks import in_group from konova.utils.user_checks import in_group
@ -356,7 +357,7 @@ def document_new_view(request: HttpRequest, id: str):
form = NewEmaDocumentForm(request.POST or None, request.FILES or None, instance=ema, request=request) form = NewEmaDocumentForm(request.POST or None, request.FILES or None, instance=ema, request=request)
return form.process_request( return form.process_request(
request, request,
msg_success=_("Document added"), msg_success=DOCUMENT_ADDED,
redirect_url=reverse("ema:detail", args=(id,)) + "#related_data" redirect_url=reverse("ema:detail", args=(id,)) + "#related_data"
) )

View File

@ -26,7 +26,7 @@ from konova.models import generate_document_file_upload_path, AbstractDocument,
ShareableObjectMixin, \ ShareableObjectMixin, \
RecordableObjectMixin, CheckableObjectMixin, GeoReferencedMixin RecordableObjectMixin, CheckableObjectMixin, GeoReferencedMixin
from konova.settings import LANIS_LINK_TEMPLATE, LANIS_ZOOM_LUT, DEFAULT_SRID_RLP from konova.settings import LANIS_LINK_TEMPLATE, LANIS_ZOOM_LUT, DEFAULT_SRID_RLP
from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, DEDUCTION_ADDED from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, DEDUCTION_ADDED, DOCUMENT_REMOVED_TEMPLATE
from user.models import UserActionLogEntry from user.models import UserActionLogEntry
@ -302,7 +302,7 @@ class InterventionDocument(AbstractDocument):
max_length=1000, max_length=1000,
) )
def delete(self, *args, **kwargs): def delete(self, user=None, *args, **kwargs):
""" """
Custom delete functionality for InterventionDocuments. Custom delete functionality for InterventionDocuments.
Removes the folder from the file system if there are no further documents for this entry. Removes the folder from the file system if there are no further documents for this entry.
@ -324,6 +324,9 @@ class InterventionDocument(AbstractDocument):
folder_path = self.file.path.split("/")[:-1] folder_path = self.file.path.split("/")[:-1]
folder_path = "/".join(folder_path) folder_path = "/".join(folder_path)
if user:
self.instance.mark_as_edited(user, edit_comment=DOCUMENT_REMOVED_TEMPLATE.format(self.title))
# Remove the file itself # Remove the file itself
super().delete(*args, **kwargs) super().delete(*args, **kwargs)

View File

@ -9,6 +9,8 @@ Created on: 15.11.21
import shutil import shutil
from django.contrib.gis.db import models from django.contrib.gis.db import models
from django.core.exceptions import ObjectDoesNotExist
from konova.models import BaseResource, AbstractDocument, generate_document_file_upload_path from konova.models import BaseResource, AbstractDocument, generate_document_file_upload_path
from konova.utils.message_templates import REVOCATION_REMOVED from konova.utils.message_templates import REVOCATION_REMOVED
@ -21,10 +23,13 @@ class Revocation(BaseResource):
legal = models.ForeignKey("Legal", null=False, blank=False, on_delete=models.CASCADE, help_text="Refers to 'Widerspruch am'", related_name="revocations") legal = models.ForeignKey("Legal", null=False, blank=False, on_delete=models.CASCADE, help_text="Refers to 'Widerspruch am'", related_name="revocations")
comment = models.TextField(null=True, blank=True) comment = models.TextField(null=True, blank=True)
def delete(self, user = None, *args, **kwargs): def delete(self, user=None, *args, **kwargs):
# Make sure related objects are being removed as well # Make sure related objects are being removed as well
if self.document: try:
self.document.delete(*args, **kwargs) self.document.delete(*args, **kwargs)
except ObjectDoesNotExist:
# No file to delete
pass
if user is not None: if user is not None:
self.legal.intervention.mark_as_edited(user, edit_comment=REVOCATION_REMOVED) self.legal.intervention.mark_as_edited(user, edit_comment=REVOCATION_REMOVED)

View File

@ -17,7 +17,7 @@ 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, \
CHECKED_RECORDED_RESET, DEDUCTION_REMOVED, DEDUCTION_ADDED, REVOCATION_ADDED, REVOCATION_REMOVED, \ CHECKED_RECORDED_RESET, DEDUCTION_REMOVED, DEDUCTION_ADDED, REVOCATION_ADDED, REVOCATION_REMOVED, \
COMPENSATION_REMOVED_TEMPLATE COMPENSATION_REMOVED_TEMPLATE, DOCUMENT_ADDED
from konova.utils.user_checks import in_group from konova.utils.user_checks import in_group
@ -131,7 +131,7 @@ def new_document_view(request: HttpRequest, id: str):
form = NewInterventionDocumentForm(request.POST or None, request.FILES or None, instance=intervention, request=request) form = NewInterventionDocumentForm(request.POST or None, request.FILES or None, instance=intervention, request=request)
return form.process_request( return form.process_request(
request, request,
msg_success=_("Document added"), msg_success=DOCUMENT_ADDED,
redirect_url=reverse("intervention:detail", args=(id,)) + "#related_data" redirect_url=reverse("intervention:detail", args=(id,)) + "#related_data"
) )

View File

@ -99,13 +99,6 @@ class BaseObjectAdmin(BaseResourceAdmin):
for entry in queryset: for entry in queryset:
entry.deleted.delete() entry.deleted.delete()
# Remove delete log entry from related intervention log history
logs = entry.intervention.log.filter(
action=UserAction.EDITED,
comment=COMPENSATION_REMOVED_TEMPLATE.format(entry.identifier)
)
logs.delete()
# Outcommented for a cleaner admin backend on production # Outcommented for a cleaner admin backend on production

View File

@ -10,6 +10,7 @@ from django.utils.translation import gettext_lazy as _
from konova.forms import RemoveModalForm from konova.forms import RemoveModalForm
from konova.models import AbstractDocument from konova.models import AbstractDocument
from konova.utils.message_templates import DOCUMENT_REMOVED_TEMPLATE
def get_document(doc: AbstractDocument): def get_document(doc: AbstractDocument):
@ -49,5 +50,5 @@ def remove_document(request: HttpRequest, doc: AbstractDocument):
form = RemoveModalForm(request.POST or None, instance=doc, request=request) form = RemoveModalForm(request.POST or None, instance=doc, request=request)
return form.process_request( return form.process_request(
request=request, request=request,
msg_success=_("Document '{}' deleted").format(title) msg_success=DOCUMENT_REMOVED_TEMPLATE.format(title)
) )

View File

@ -37,6 +37,10 @@ PAYMENT_REMOVED = _("Payment removed")
REVOCATION_ADDED = _("Revocation added") REVOCATION_ADDED = _("Revocation added")
REVOCATION_REMOVED = _("Revocation removed") REVOCATION_REMOVED = _("Revocation removed")
# DOCUMENTS
DOCUMENT_REMOVED_TEMPLATE = _("Document '{}' deleted")
DOCUMENT_ADDED = _("Document added")
# Edited # Edited
EDITED_GENERAL_DATA = _("Edited general data") EDITED_GENERAL_DATA = _("Edited general data")
ADDED_COMPENSATION_STATE = _("Added compensation state") ADDED_COMPENSATION_STATE = _("Added compensation state")