added logging for evidence tag changes
This commit is contained in:
parent
e81c072bd4
commit
743e8d314a
|
@ -10,6 +10,7 @@ from device.models import Device
|
|||
from evidence.parse import Build
|
||||
from evidence.models import SystemProperty, UserProperty
|
||||
from utils.save_snapshots import move_json, save_in_disk
|
||||
from action.models import DeviceLog
|
||||
|
||||
|
||||
class UploadForm(forms.Form):
|
||||
|
@ -98,19 +99,31 @@ class UserTagForm(forms.Form):
|
|||
return
|
||||
|
||||
if self.instance:
|
||||
old_value = self.instance.value
|
||||
if not self.tag:
|
||||
message =_("<Deleted> Evidence Tag. Old Value: '{}'").format(old_value)
|
||||
self.instance.delete()
|
||||
self.instance.value = self.tag
|
||||
self.instance.save()
|
||||
return
|
||||
else:
|
||||
self.instance.value = self.tag
|
||||
self.instance.save()
|
||||
if old_value != self.tag:
|
||||
message=_("<Updated> Evidence Tag. Old Value: '{}'. New Value: '{}'").format(old_value, self.tag)
|
||||
else:
|
||||
message =_("<Created> Evidence Tag. Value: '{}'").format(self.tag)
|
||||
SystemProperty.objects.create(
|
||||
uuid=self.uuid,
|
||||
key='CUSTOM_ID',
|
||||
value=self.tag,
|
||||
owner=self.user.institution,
|
||||
user=self.user
|
||||
)
|
||||
|
||||
SystemProperty.objects.create(
|
||||
uuid=self.uuid,
|
||||
key='CUSTOM_ID',
|
||||
value=self.tag,
|
||||
owner=self.user.institution,
|
||||
user=self.user
|
||||
)
|
||||
DeviceLog.objects.create(
|
||||
snapshot_uuid=self.uuid,
|
||||
event= message,
|
||||
user=self.user,
|
||||
institution=self.user.institution
|
||||
)
|
||||
|
||||
|
||||
class ImportForm(forms.Form):
|
||||
|
|
|
@ -94,7 +94,7 @@
|
|||
</div>
|
||||
{% if form.tag.value %}
|
||||
<div class="col-1">
|
||||
<a class="btn btn-yellow" href="{% url 'device:delete_user_property' form.pk %}">{% translate "Delete" %}</a>
|
||||
<a class="btn btn-yellow" href="{% url 'evidence:delete_tag' form.pk %}">{% translate "Delete" %}</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
|
@ -20,4 +20,5 @@ urlpatterns = [
|
|||
path("<uuid:pk>", views.EvidenceView.as_view(), name="details"),
|
||||
path("<uuid:pk>/eraseserver", views.EraseServerView.as_view(), name="erase_server"),
|
||||
path("<uuid:pk>/download", views.DownloadEvidenceView.as_view(), name="download"),
|
||||
path("tag/<str:pk>/delete", views.DeleteEvidenceTagView.as_view(), name="delete_tag"),
|
||||
]
|
||||
|
|
|
@ -12,6 +12,7 @@ from django.views.generic.edit import (
|
|||
FormView,
|
||||
)
|
||||
|
||||
from action.models import DeviceLog
|
||||
from dashboard.mixins import DashboardView, Http403
|
||||
from evidence.models import SystemProperty, UserProperty, Evidence
|
||||
from evidence.forms import (
|
||||
|
@ -184,3 +185,35 @@ class EraseServerView(DashboardView, FormView):
|
|||
def get_success_url(self):
|
||||
success_url = reverse_lazy('evidence:details', args=[self.pk])
|
||||
return success_url
|
||||
|
||||
|
||||
class DeleteEvidenceTagView(DashboardView, DeleteView):
|
||||
model = SystemProperty
|
||||
|
||||
def get_queryset(self):
|
||||
# only those with 'CUSTOM_ID'
|
||||
return SystemProperty.objects.filter(owner=self.request.user.institution, key='CUSTOM_ID')
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
|
||||
message = _("<Deleted> Evidence Tag: {}").format(self.object.value)
|
||||
DeviceLog.objects.create(
|
||||
snapshot_uuid=self.object.uuid,
|
||||
event=message,
|
||||
user=self.request.user,
|
||||
institution=self.request.user.institution
|
||||
)
|
||||
self.object.delete()
|
||||
|
||||
messages.info(self.request, _("Evicende Tag deleted successfully."))
|
||||
return self.handle_success()
|
||||
|
||||
def handle_success(self):
|
||||
return redirect(self.get_success_url())
|
||||
|
||||
def get_success_url(self):
|
||||
return self.request.META.get(
|
||||
'HTTP_REFERER',
|
||||
reverse_lazy('evidence:details', args=[self.object.uuid])
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue