add erase server definition
This commit is contained in:
parent
fcb07a7337
commit
b2cda37dd0
|
@ -109,6 +109,22 @@ class Device:
|
|||
annotation = annotations.first()
|
||||
self.last_evidence = Evidence(annotation.uuid)
|
||||
|
||||
def is_eraseserver(self):
|
||||
if not self.uuids:
|
||||
self.get_uuids()
|
||||
if not self.uuids:
|
||||
return False
|
||||
|
||||
annotation = Annotation.objects.filter(
|
||||
uuid__in=self.uuids,
|
||||
owner=self.owner,
|
||||
type=Annotation.Type.ERASE_SERVER
|
||||
).first()
|
||||
|
||||
if annotation:
|
||||
return True
|
||||
return False
|
||||
|
||||
def last_uuid(self):
|
||||
return self.uuids[0]
|
||||
|
||||
|
|
|
@ -12,22 +12,22 @@
|
|||
<div class="col">
|
||||
<ul class="nav nav-tabs nav-tabs-bordered">
|
||||
<li class="nav-items">
|
||||
<a href="#details" class="nav-link active" data-bs-toggle="tab" data-bs-target="#details">General details</a>
|
||||
<a href="#details" class="nav-link active" data-bs-toggle="tab" data-bs-target="#details">{% trans "General details" %}</a>
|
||||
</li>
|
||||
<li class="nav-items">
|
||||
<a href="#annotations" class="nav-link" data-bs-toggle="tab" data-bs-target="#annotations">User annotations</a>
|
||||
<a href="#annotations" class="nav-link" data-bs-toggle="tab" data-bs-target="#annotations">{% trans "User annotations" %}</a>
|
||||
</li>
|
||||
<li class="nav-items">
|
||||
<a href="#documents" class="nav-link" data-bs-toggle="tab" data-bs-target="#documents">Documents</a>
|
||||
<a href="#documents" class="nav-link" data-bs-toggle="tab" data-bs-target="#documents">{% trans "Documents" %}</a>
|
||||
</li>
|
||||
<li class="nav-items">
|
||||
<a href="#lots" class="nav-link" data-bs-toggle="tab" data-bs-target="#lots">Lots</a>
|
||||
<a href="#lots" class="nav-link" data-bs-toggle="tab" data-bs-target="#lots">{% trans "Lots" %}</a>
|
||||
</li>
|
||||
<li class="nav-items">
|
||||
<a href="#components" class="nav-link" data-bs-toggle="tab" data-bs-target="#components">Components</a>
|
||||
<a href="#components" class="nav-link" data-bs-toggle="tab" data-bs-target="#components">{% trans "Components" %}</a>
|
||||
</li>
|
||||
<li class="nav-items">
|
||||
<a href="#evidences" class="nav-link" data-bs-toggle="tab" data-bs-target="#evidences">Evidences</a>
|
||||
<a href="#evidences" class="nav-link" data-bs-toggle="tab" data-bs-target="#evidences">{% trans "Evidences" %}</a>
|
||||
</li>
|
||||
<li class="nav-items">
|
||||
<a href="#web" class="nav-link" href="">Web</a>
|
||||
|
@ -38,14 +38,21 @@
|
|||
<div class="tab-content pt-2">
|
||||
|
||||
<div class="tab-pane fade show active" id="details">
|
||||
<h5 class="card-title">Details</h5>
|
||||
<h5 class="card-title">{% trans "Details" %}</h5>
|
||||
<div class="row mb-3">
|
||||
<div class="col-lg-3 col-md-4 label ">Phid</div>
|
||||
<div class="col-lg-9 col-md-8">{{ object.id }}</div>
|
||||
</div>
|
||||
|
||||
{% if object.is_eraseserver %}
|
||||
<div class="row mb-3">
|
||||
<div class="col-lg-3 col-md-4 label">{% trans "Is a erase server" %}</div>
|
||||
<div class="col-lg-9 col-md-8"></div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-3 col-md-4 label ">Type</div>
|
||||
<div class="col-lg-3 col-md-4 label ">{% trans "Type" %}</div>
|
||||
<div class="col-lg-9 col-md-8">{{ object.type }}</div>
|
||||
</div>
|
||||
|
||||
|
@ -86,12 +93,12 @@
|
|||
<div class="btn-group dropdown ml-1 mt-1" uib-dropdown="">
|
||||
<a href="{% url 'device:add_annotation' object.pk %}" class="btn btn-primary">
|
||||
<i class="bi bi-plus"></i>
|
||||
Add new annotation
|
||||
{% trans "Add new annotation" %}
|
||||
<span class="caret"></span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<h5 class="card-title mt-2">Annotations</h5>
|
||||
<h5 class="card-title mt-2">{% trans "Annotations" %}</h5>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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"),
|
||||
]
|
||||
),
|
||||
),
|
||||
]
|
|
@ -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()
|
||||
|
|
|
@ -12,13 +12,16 @@
|
|||
<div class="col">
|
||||
<ul class="nav nav-tabs nav-tabs-bordered">
|
||||
<li class="nav-items">
|
||||
<button class="nav-link active" data-bs-toggle="tab" data-bs-target="#device">Devices</button>
|
||||
<button class="nav-link active" data-bs-toggle="tab" data-bs-target="#device">{% trans "Devices" %}</button>
|
||||
</li>
|
||||
<li class="nav-items">
|
||||
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#tag">Tag</button>
|
||||
<li class="nav-items">
|
||||
<a href="{% url 'evidence:download' object.uuid %}" class="nav-link">Download File</a>
|
||||
<a href="#tag" class="nav-link" data-bs-toggle="tab" data-bs-target="#tag">{% trans "Tag" %}</a>
|
||||
</li>
|
||||
<li class="nav-items">
|
||||
<a href="{% url 'evidence:erase_server' object.uuid %}" class="nav-link">{% trans "Erase Server" %}</a>
|
||||
</li>
|
||||
<li class="nav-items">
|
||||
<a href="{% url 'evidence:download' object.uuid %}" class="nav-link">{% trans "Download File" %}</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -83,3 +86,24 @@
|
|||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extrascript %}
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
// Obtener el hash de la URL (ejemplo: #components)
|
||||
const hash = window.location.hash;
|
||||
|
||||
// Verificar si hay un hash en la URL
|
||||
if (hash) {
|
||||
// Buscar el botón o enlace que corresponde al hash y activarlo
|
||||
const tabTrigger = document.querySelector(`[data-bs-target="${hash}"]`);
|
||||
|
||||
if (tabTrigger) {
|
||||
// Crear una instancia de tab de Bootstrap para activar el tab
|
||||
const tab = new bootstrap.Tab(tabTrigger);
|
||||
tab.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -18,6 +18,7 @@ urlpatterns = [
|
|||
path("upload", views.UploadView.as_view(), name="upload"),
|
||||
path("import", views.ImportView.as_view(), name="import"),
|
||||
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('annotation/<int:pk>/del', views.AnnotationDeleteView.as_view(), name='delete_annotation'),
|
||||
]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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),
|
||||
),
|
||||
]
|
Loading…
Reference in New Issue