-
Details
+
{% trans "Details" %}
+ {% if object.is_eraseserver %}
+
+
{% trans "Is a erase server" %}
+
+
+ {% endif %}
+
-
Type
+
{% trans "Type" %}
{{ object.type }}
@@ -86,12 +93,12 @@
-
Annotations
+
{% trans "Annotations" %}
diff --git a/evidence/forms.py b/evidence/forms.py
index cf90a71..dab7a60 100644
--- a/evidence/forms.py
+++ b/evidence/forms.py
@@ -162,3 +162,56 @@ class ImportForm(forms.Form):
return table
return
+
+
+class EraseServerForm(forms.Form):
+ erase_server = forms.BooleanField(label=_("Is a Erase Server"), required=False)
+
+ def __init__(self, *args, **kwargs):
+ self.pk = None
+ self.uuid = kwargs.pop('uuid', None)
+ self.user = kwargs.pop('user')
+ instance = Annotation.objects.filter(
+ uuid=self.uuid,
+ type=Annotation.Type.ERASE_SERVER,
+ key='ERASE_SERVER',
+ owner=self.user.institution
+ ).first()
+
+ if instance:
+ kwargs["initial"]["erase_server"] = instance.value
+ self.pk = instance.pk
+
+ super().__init__(*args, **kwargs)
+
+ def clean(self):
+ self.erase_server = self.cleaned_data.get('erase_server', False)
+ self.instance = Annotation.objects.filter(
+ uuid=self.uuid,
+ type=Annotation.Type.ERASE_SERVER,
+ key='ERASE_SERVER',
+ owner=self.user.institution
+ ).first()
+
+ return True
+
+ def save(self, user, commit=True):
+ if not commit:
+ return
+
+ if not self.erase_server:
+ if self.instance:
+ self.instance.delete()
+ return
+
+ if self.instance:
+ return
+
+ Annotation.objects.create(
+ uuid=self.uuid,
+ type=Annotation.Type.ERASE_SERVER,
+ key='ERASE_SERVER',
+ value=self.erase_server,
+ owner=self.user.institution,
+ user=self.user
+ )
diff --git a/evidence/migrations/0002_alter_annotation_type.py b/evidence/migrations/0002_alter_annotation_type.py
new file mode 100644
index 0000000..24957bc
--- /dev/null
+++ b/evidence/migrations/0002_alter_annotation_type.py
@@ -0,0 +1,25 @@
+# Generated by Django 5.0.6 on 2024-10-28 12:56
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("evidence", "0001_initial"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="annotation",
+ name="type",
+ field=models.SmallIntegerField(
+ choices=[
+ (0, "System"),
+ (1, "User"),
+ (2, "Document"),
+ (3, "EraseServer"),
+ ]
+ ),
+ ),
+ ]
diff --git a/evidence/models.py b/evidence/models.py
index 8c5d6f9..fef6a92 100644
--- a/evidence/models.py
+++ b/evidence/models.py
@@ -14,6 +14,7 @@ class Annotation(models.Model):
SYSTEM= 0, "System"
USER = 1, "User"
DOCUMENT = 2, "Document"
+ ERASE_SERVER = 3, "EraseServer"
created = models.DateTimeField(auto_now_add=True)
uuid = models.UUIDField()
diff --git a/evidence/templates/ev_details.html b/evidence/templates/ev_details.html
index 94c3058..6a40962 100644
--- a/evidence/templates/ev_details.html
+++ b/evidence/templates/ev_details.html
@@ -12,13 +12,16 @@
@@ -83,3 +86,24 @@
{% endblock %}
+
+{% block extrascript %}
+
+{% endblock %}
diff --git a/evidence/urls.py b/evidence/urls.py
index 87ccdd5..9a4e2a2 100644
--- a/evidence/urls.py
+++ b/evidence/urls.py
@@ -18,6 +18,7 @@ urlpatterns = [
path("upload", views.UploadView.as_view(), name="upload"),
path("import", views.ImportView.as_view(), name="import"),
path("", views.EvidenceView.as_view(), name="details"),
+ path("/eraseserver", views.EraseServerView.as_view(), name="erase_server"),
path("/download", views.DownloadEvidenceView.as_view(), name="download"),
path('annotation//del', views.AnnotationDeleteView.as_view(), name='delete_annotation'),
]
diff --git a/evidence/views.py b/evidence/views.py
index 81ff767..201a621 100644
--- a/evidence/views.py
+++ b/evidence/views.py
@@ -11,18 +11,14 @@ from django.views.generic.edit import (
FormView,
)
-
from dashboard.mixins import DashboardView, Http403
from evidence.models import Evidence, Annotation
-from evidence.forms import UploadForm, UserTagForm, ImportForm
-# from django.shortcuts import render
-# from rest_framework import viewsets
-# from snapshot.serializers import SnapshotSerializer
-
-
-# class SnapshotViewSet(viewsets.ModelViewSet):
-# queryset = Snapshot.objects.all()
-# serializer_class = SnapshotSerializer
+from evidence.forms import (
+ UploadForm,
+ UserTagForm,
+ ImportForm,
+ EraseServerForm
+)
class ListEvidencesView(DashboardView, TemplateView):
@@ -167,3 +163,48 @@ class AnnotationDeleteView(DashboardView, DeleteView):
return redirect(url_name, **kwargs_view)
+
+
+class EraseServerView(DashboardView, FormView):
+ template_name = "ev_eraseserver.html"
+ section = "evidences"
+ title = _("Evidences")
+ breadcrumb = "Evidences / Details"
+ success_url = reverse_lazy('evidence:list')
+ form_class = EraseServerForm
+
+ def get(self, request, *args, **kwargs):
+ self.pk = kwargs['pk']
+ self.object = Evidence(self.pk)
+ if self.object.owner != self.request.user.institution:
+ raise Http403
+
+ self.object.get_annotations()
+ return super().get(request, *args, **kwargs)
+
+ def get_context_data(self, **kwargs):
+ context = super().get_context_data(**kwargs)
+ context.update({
+ 'object': self.object,
+ })
+ return context
+
+ def get_form_kwargs(self):
+ self.pk = self.kwargs.get('pk')
+ kwargs = super().get_form_kwargs()
+ kwargs['uuid'] = self.pk
+ kwargs['user'] = self.request.user
+ return kwargs
+
+ def form_valid(self, form):
+ form.save(self.request.user)
+ response = super().form_valid(form)
+ return response
+
+ def form_invalid(self, form):
+ response = super().form_invalid(form)
+ return response
+
+ def get_success_url(self):
+ success_url = reverse_lazy('evidence:details', args=[self.pk])
+ return success_url
diff --git a/lot/migrations/0002_alter_lot_closed.py b/lot/migrations/0002_alter_lot_closed.py
new file mode 100644
index 0000000..a694df6
--- /dev/null
+++ b/lot/migrations/0002_alter_lot_closed.py
@@ -0,0 +1,18 @@
+# Generated by Django 5.0.6 on 2024-10-28 12:56
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("lot", "0001_initial"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="lot",
+ name="closed",
+ field=models.BooleanField(default=False),
+ ),
+ ]