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.parse import Build
|
||||||
from evidence.models import SystemProperty, UserProperty
|
from evidence.models import SystemProperty, UserProperty
|
||||||
from utils.save_snapshots import move_json, save_in_disk
|
from utils.save_snapshots import move_json, save_in_disk
|
||||||
|
from action.models import DeviceLog
|
||||||
|
|
||||||
|
|
||||||
class UploadForm(forms.Form):
|
class UploadForm(forms.Form):
|
||||||
|
@ -98,19 +99,31 @@ class UserTagForm(forms.Form):
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.instance:
|
if self.instance:
|
||||||
|
old_value = self.instance.value
|
||||||
if not self.tag:
|
if not self.tag:
|
||||||
|
message =_("<Deleted> Evidence Tag. Old Value: '{}'").format(old_value)
|
||||||
self.instance.delete()
|
self.instance.delete()
|
||||||
self.instance.value = self.tag
|
else:
|
||||||
self.instance.save()
|
self.instance.value = self.tag
|
||||||
return
|
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(
|
DeviceLog.objects.create(
|
||||||
uuid=self.uuid,
|
snapshot_uuid=self.uuid,
|
||||||
key='CUSTOM_ID',
|
event= message,
|
||||||
value=self.tag,
|
user=self.user,
|
||||||
owner=self.user.institution,
|
institution=self.user.institution
|
||||||
user=self.user
|
)
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ImportForm(forms.Form):
|
class ImportForm(forms.Form):
|
||||||
|
|
|
@ -94,7 +94,7 @@
|
||||||
</div>
|
</div>
|
||||||
{% if form.tag.value %}
|
{% if form.tag.value %}
|
||||||
<div class="col-1">
|
<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>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -20,4 +20,5 @@ urlpatterns = [
|
||||||
path("<uuid:pk>", views.EvidenceView.as_view(), name="details"),
|
path("<uuid:pk>", views.EvidenceView.as_view(), name="details"),
|
||||||
path("<uuid:pk>/eraseserver", views.EraseServerView.as_view(), name="erase_server"),
|
path("<uuid:pk>/eraseserver", views.EraseServerView.as_view(), name="erase_server"),
|
||||||
path("<uuid:pk>/download", views.DownloadEvidenceView.as_view(), name="download"),
|
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,
|
FormView,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from action.models import DeviceLog
|
||||||
from dashboard.mixins import DashboardView, Http403
|
from dashboard.mixins import DashboardView, Http403
|
||||||
from evidence.models import SystemProperty, UserProperty, Evidence
|
from evidence.models import SystemProperty, UserProperty, Evidence
|
||||||
from evidence.forms import (
|
from evidence.forms import (
|
||||||
|
@ -184,3 +185,35 @@ class EraseServerView(DashboardView, FormView):
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
success_url = reverse_lazy('evidence:details', args=[self.pk])
|
success_url = reverse_lazy('evidence:details', args=[self.pk])
|
||||||
return success_url
|
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