variables and function semantic renaming
This commit is contained in:
parent
41926ea85a
commit
296fab8cf6
|
@ -7,7 +7,7 @@ app_name = 'api'
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('v1/snapshot/', views.NewSnapshotView.as_view(), name='new_snapshot'),
|
path('v1/snapshot/', views.NewSnapshotView.as_view(), name='new_snapshot'),
|
||||||
path('v1/annotation/<str:pk>/', views.AddAnnotationView.as_view(), name='new_annotation'),
|
path('v1/property/<str:pk>/', views.AddPropertyView.as_view(), name='new_property'),
|
||||||
path('v1/device/<str:pk>/', views.DetailsDeviceView.as_view(), name='device'),
|
path('v1/device/<str:pk>/', views.DetailsDeviceView.as_view(), name='device'),
|
||||||
path('v1/tokens/', views.TokenView.as_view(), name='tokens'),
|
path('v1/tokens/', views.TokenView.as_view(), name='tokens'),
|
||||||
path('v1/tokens/new', views.TokenNewView.as_view(), name='new_token'),
|
path('v1/tokens/new', views.TokenNewView.as_view(), name='new_token'),
|
||||||
|
|
38
api/views.py
38
api/views.py
|
@ -21,7 +21,7 @@ from django.views.generic.edit import (
|
||||||
from utils.save_snapshots import move_json, save_in_disk
|
from utils.save_snapshots import move_json, save_in_disk
|
||||||
from django.views.generic.edit import View
|
from django.views.generic.edit import View
|
||||||
from dashboard.mixins import DashboardView
|
from dashboard.mixins import DashboardView
|
||||||
from evidence.models import Annotation
|
from evidence.models import SystemProperty, UserProperty, Property
|
||||||
from evidence.parse_details import ParseSnapshot
|
from evidence.parse_details import ParseSnapshot
|
||||||
from evidence.parse import Build
|
from evidence.parse import Build
|
||||||
from device.models import Device
|
from device.models import Device
|
||||||
|
@ -90,11 +90,11 @@ class NewSnapshotView(ApiMixing):
|
||||||
logger.error("%s", txt)
|
logger.error("%s", txt)
|
||||||
return JsonResponse({'status': txt}, status=500)
|
return JsonResponse({'status': txt}, status=500)
|
||||||
|
|
||||||
exist_annotation = Annotation.objects.filter(
|
exist_property = SystemProperty.objects.filter(
|
||||||
uuid=data['uuid']
|
uuid=data['uuid']
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
if exist_annotation:
|
if exist_property:
|
||||||
txt = "error: the snapshot {} exist".format(data['uuid'])
|
txt = "error: the snapshot {} exist".format(data['uuid'])
|
||||||
logger.warning("%s", txt)
|
logger.warning("%s", txt)
|
||||||
return JsonResponse({'status': txt}, status=500)
|
return JsonResponse({'status': txt}, status=500)
|
||||||
|
@ -111,25 +111,25 @@ class NewSnapshotView(ApiMixing):
|
||||||
text = "fail: It is not possible to parse snapshot"
|
text = "fail: It is not possible to parse snapshot"
|
||||||
return JsonResponse({'status': text}, status=500)
|
return JsonResponse({'status': text}, status=500)
|
||||||
|
|
||||||
annotation = Annotation.objects.filter(
|
property = SystemProperty.objects.filter(
|
||||||
uuid=data['uuid'],
|
uuid=data['uuid'],
|
||||||
type=Annotation.Type.SYSTEM,
|
type=Property.Type.SYSTEM,
|
||||||
# TODO this is hardcoded, it should select the user preferred algorithm
|
# TODO this is hardcoded, it should select the user preferred algorithm
|
||||||
key="hidalgo1",
|
key="hidalgo1",
|
||||||
owner=self.tk.owner.institution
|
owner=self.tk.owner.institution
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
|
|
||||||
if not annotation:
|
if not property:
|
||||||
logger.error("Error: No annotation for uuid: %s", data["uuid"])
|
logger.error("Error: No property for uuid: %s", data["uuid"])
|
||||||
return JsonResponse({'status': 'fail'}, status=500)
|
return JsonResponse({'status': 'fail'}, status=500)
|
||||||
|
|
||||||
url_args = reverse_lazy("device:details", args=(annotation.value,))
|
url_args = reverse_lazy("device:details", args=(property.value,))
|
||||||
url = request.build_absolute_uri(url_args)
|
url = request.build_absolute_uri(url_args)
|
||||||
|
|
||||||
response = {
|
response = {
|
||||||
"status": "success",
|
"status": "success",
|
||||||
"dhid": annotation.value[:6].upper(),
|
"dhid": property.value[:6].upper(),
|
||||||
"url": url,
|
"url": url,
|
||||||
# TODO replace with public_url when available
|
# TODO replace with public_url when available
|
||||||
"public_url": url
|
"public_url": url
|
||||||
|
@ -255,22 +255,21 @@ class DetailsDeviceView(ApiMixing):
|
||||||
"components": snapshot.get("components"),
|
"components": snapshot.get("components"),
|
||||||
})
|
})
|
||||||
|
|
||||||
uuids = Annotation.objects.filter(
|
uuids = SystemProperty.objects.filter(
|
||||||
owner=self.tk.owner.institution,
|
owner=self.tk.owner.institution,
|
||||||
value=self.pk
|
value=self.pk
|
||||||
).values("uuid")
|
).values("uuid")
|
||||||
|
|
||||||
annotations = Annotation.objects.filter(
|
properties = UserProperty.objects.filter(
|
||||||
uuid__in=uuids,
|
uuid__in=uuids,
|
||||||
owner=self.tk.owner.institution,
|
owner=self.tk.owner.institution,
|
||||||
type = Annotation.Type.USER
|
|
||||||
).values_list("key", "value")
|
).values_list("key", "value")
|
||||||
|
|
||||||
data.update({"annotations": list(annotations)})
|
data.update({"properties": list(properties)})
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
class AddAnnotationView(ApiMixing):
|
class AddPropertyView(ApiMixing):
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
response = self.auth()
|
response = self.auth()
|
||||||
|
@ -279,13 +278,13 @@ class AddAnnotationView(ApiMixing):
|
||||||
|
|
||||||
self.pk = kwargs['pk']
|
self.pk = kwargs['pk']
|
||||||
institution = self.tk.owner.institution
|
institution = self.tk.owner.institution
|
||||||
self.annotation = Annotation.objects.filter(
|
self.property = SystemProperty.objects.filter(
|
||||||
owner=institution,
|
owner=institution,
|
||||||
value=self.pk,
|
value=self.pk,
|
||||||
type=Annotation.Type.SYSTEM
|
type=Property.Type.SYSTEM
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
if not self.annotation:
|
if not self.property:
|
||||||
return JsonResponse({}, status=404)
|
return JsonResponse({}, status=404)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -296,10 +295,9 @@ class AddAnnotationView(ApiMixing):
|
||||||
logger.error("Invalid Snapshot of user %s", self.tk.owner)
|
logger.error("Invalid Snapshot of user %s", self.tk.owner)
|
||||||
return JsonResponse({'error': 'Invalid JSON'}, status=500)
|
return JsonResponse({'error': 'Invalid JSON'}, status=500)
|
||||||
|
|
||||||
Annotation.objects.create(
|
UserProperty.objects.create(
|
||||||
uuid=self.annotation.uuid,
|
uuid=self.property.uuid,
|
||||||
owner=self.tk.owner.institution,
|
owner=self.tk.owner.institution,
|
||||||
type = Annotation.Type.USER,
|
|
||||||
key = key,
|
key = key,
|
||||||
value = value
|
value = value
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,7 +6,7 @@ from django.core.exceptions import PermissionDenied
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.views.generic.base import TemplateView
|
from django.views.generic.base import TemplateView
|
||||||
from device.models import Device
|
from device.models import Device
|
||||||
from evidence.models import Annotation
|
from evidence.models import SystemProperty
|
||||||
from lot.models import LotTag
|
from lot.models import LotTag
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ class DashboardView(LoginRequiredMixin):
|
||||||
dev_ids = self.request.session.pop("devices", [])
|
dev_ids = self.request.session.pop("devices", [])
|
||||||
|
|
||||||
self._devices = []
|
self._devices = []
|
||||||
for x in Annotation.objects.filter(value__in=dev_ids).filter(
|
for x in SystemProperty.objects.filter(value__in=dev_ids).filter(
|
||||||
owner=self.request.user.institution
|
owner=self.request.user.institution
|
||||||
).distinct():
|
).distinct():
|
||||||
self._devices.append(Device(id=x.value))
|
self._devices.append(Device(id=x.value))
|
||||||
|
|
|
@ -6,7 +6,7 @@ from django.shortcuts import Http404
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
||||||
from dashboard.mixins import InventaryMixin, DetailsMixin
|
from dashboard.mixins import InventaryMixin, DetailsMixin
|
||||||
from evidence.models import Annotation
|
from evidence.models import Property
|
||||||
from evidence.xapian import search
|
from evidence.xapian import search
|
||||||
from device.models import Device
|
from device.models import Device
|
||||||
from lot.models import Lot
|
from lot.models import Lot
|
||||||
|
@ -74,7 +74,7 @@ class SearchView(InventaryMixin):
|
||||||
|
|
||||||
for x in matches:
|
for x in matches:
|
||||||
# devices.append(self.get_annotations(x))
|
# devices.append(self.get_annotations(x))
|
||||||
dev = self.get_annotations(x)
|
dev = self.get_property(x)
|
||||||
if dev.id not in dev_id:
|
if dev.id not in dev_id:
|
||||||
devices.append(dev)
|
devices.append(dev)
|
||||||
dev_id.append(dev.id)
|
dev_id.append(dev.id)
|
||||||
|
@ -83,7 +83,7 @@ class SearchView(InventaryMixin):
|
||||||
# TODO fix of pagination, the count is not correct
|
# TODO fix of pagination, the count is not correct
|
||||||
return devices, count
|
return devices, count
|
||||||
|
|
||||||
def get_annotations(self, xp):
|
def get_properties(self, xp):
|
||||||
snap = xp.document.get_data()
|
snap = xp.document.get_data()
|
||||||
uuid = json.loads(snap).get('uuid')
|
uuid = json.loads(snap).get('uuid')
|
||||||
return Device.get_annotation_from_uuid(uuid, self.request.user.institution)
|
return Device.get_annotation_from_uuid(uuid, self.request.user.institution)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
from utils.device import create_annotation, create_doc, create_index
|
from utils.device import create_property, create_doc, create_index
|
||||||
from utils.save_snapshots import move_json, save_in_disk
|
from utils.save_snapshots import move_json, save_in_disk
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from django.db import models, connection
|
from django.db import models, connection
|
||||||
|
|
||||||
from utils.constants import ALGOS
|
from utils.constants import ALGOS
|
||||||
from evidence.models import Annotation, Evidence
|
from evidence.models import SystemProperty, UserProperty, Property, Evidence
|
||||||
from lot.models import DeviceLot
|
from lot.models import DeviceLot
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ class Device:
|
||||||
self.shortid = self.pk[:6].upper()
|
self.shortid = self.pk[:6].upper()
|
||||||
self.algorithm = None
|
self.algorithm = None
|
||||||
self.owner = None
|
self.owner = None
|
||||||
self.annotations = []
|
self.properties = []
|
||||||
self.hids = []
|
self.hids = []
|
||||||
self.uuids = []
|
self.uuids = []
|
||||||
self.evidences = []
|
self.evidences = []
|
||||||
|
@ -38,76 +38,75 @@ class Device:
|
||||||
self.get_last_evidence()
|
self.get_last_evidence()
|
||||||
|
|
||||||
def initial(self):
|
def initial(self):
|
||||||
self.get_annotations()
|
self.get_properties()
|
||||||
self.get_uuids()
|
self.get_uuids()
|
||||||
self.get_hids()
|
self.get_hids()
|
||||||
self.get_evidences()
|
self.get_evidences()
|
||||||
self.get_lots()
|
self.get_lots()
|
||||||
|
|
||||||
def get_annotations(self):
|
def get_properties(self):
|
||||||
if self.annotations:
|
if self.properties:
|
||||||
return self.annotations
|
return self.properties
|
||||||
|
|
||||||
self.annotations = Annotation.objects.filter(
|
self.properties = SystemProperty.objects.filter(
|
||||||
type=Annotation.Type.SYSTEM,
|
type=Property.Type.SYSTEM,
|
||||||
value=self.id
|
value=self.id
|
||||||
).order_by("-created")
|
).order_by("-created")
|
||||||
|
|
||||||
if self.annotations.count():
|
if self.properties.count():
|
||||||
self.algorithm = self.annotations[0].key
|
self.algorithm = self.properties[0].key
|
||||||
self.owner = self.annotations[0].owner
|
self.owner = self.properties[0].owner
|
||||||
|
|
||||||
return self.annotations
|
return self.properties
|
||||||
|
|
||||||
def get_user_annotations(self):
|
def get_user_properties(self):
|
||||||
if not self.uuids:
|
if not self.uuids:
|
||||||
self.get_uuids()
|
self.get_uuids()
|
||||||
|
|
||||||
annotations = Annotation.objects.filter(
|
user_properties = UserProperty.objects.filter(
|
||||||
uuid__in=self.uuids,
|
uuid__in=self.uuids,
|
||||||
owner=self.owner,
|
owner=self.owner,
|
||||||
type=Annotation.Type.USER
|
|
||||||
)
|
)
|
||||||
return annotations
|
return user_properties
|
||||||
|
|
||||||
def get_user_documents(self):
|
def get_user_documents(self):
|
||||||
if not self.uuids:
|
if not self.uuids:
|
||||||
self.get_uuids()
|
self.get_uuids()
|
||||||
|
|
||||||
annotations = Annotation.objects.filter(
|
properties = SystemProperty.objects.filter(
|
||||||
uuid__in=self.uuids,
|
uuid__in=self.uuids,
|
||||||
owner=self.owner,
|
owner=self.owner,
|
||||||
type=Annotation.Type.DOCUMENT
|
type=Property.Type.DOCUMENT
|
||||||
)
|
)
|
||||||
return annotations
|
return properties
|
||||||
|
|
||||||
def get_uuids(self):
|
def get_uuids(self):
|
||||||
for a in self.get_annotations():
|
for a in self.get_properties():
|
||||||
if a.uuid not in self.uuids:
|
if a.uuid not in self.uuids:
|
||||||
self.uuids.append(a.uuid)
|
self.uuids.append(a.uuid)
|
||||||
|
|
||||||
def get_hids(self):
|
def get_hids(self):
|
||||||
annotations = self.get_annotations()
|
properties = self.get_properties()
|
||||||
|
|
||||||
algos = list(ALGOS.keys())
|
algos = list(ALGOS.keys())
|
||||||
algos.append('CUSTOM_ID')
|
algos.append('CUSTOM_ID')
|
||||||
self.hids = list(set(annotations.filter(
|
self.hids = list(set(properties.filter(
|
||||||
type=Annotation.Type.SYSTEM,
|
type=Property.Type.SYSTEM,
|
||||||
key__in=algos,
|
key__in=algos,
|
||||||
).values_list("value", flat=True)))
|
).values_list("value", flat=True)))
|
||||||
|
|
||||||
def get_evidences(self):
|
def get_properties(self):
|
||||||
if not self.uuids:
|
if not self.uuids:
|
||||||
self.get_uuids()
|
self.get_uuids()
|
||||||
|
|
||||||
self.evidences = [Evidence(u) for u in self.uuids]
|
self.properties = [SystemProperty(u) for u in self.uuids]
|
||||||
|
|
||||||
def get_last_evidence(self):
|
def get_last_evidence(self):
|
||||||
annotations = self.get_annotations()
|
properties = self.get_properties()
|
||||||
if not annotations.count():
|
if not properties.count():
|
||||||
return
|
return
|
||||||
annotation = annotations.first()
|
property = property.first()
|
||||||
self.last_evidence = Evidence(annotation.uuid)
|
self.last_evidence = Evidence(property.uuid)
|
||||||
|
|
||||||
def is_eraseserver(self):
|
def is_eraseserver(self):
|
||||||
if not self.uuids:
|
if not self.uuids:
|
||||||
|
@ -115,13 +114,13 @@ class Device:
|
||||||
if not self.uuids:
|
if not self.uuids:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
annotation = Annotation.objects.filter(
|
property = SystemProperty.objects.filter(
|
||||||
uuid__in=self.uuids,
|
uuid__in=self.uuids,
|
||||||
owner=self.owner,
|
owner=self.owner,
|
||||||
type=Annotation.Type.ERASE_SERVER
|
type=Property.Type.ERASE_SERVER
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
if annotation:
|
if property:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -164,7 +163,7 @@ class Device:
|
||||||
row_num = 1
|
row_num = 1
|
||||||
""".format(
|
""".format(
|
||||||
institution=institution.id,
|
institution=institution.id,
|
||||||
type=Annotation.Type.SYSTEM,
|
type=Property.Type.SYSTEM,
|
||||||
)
|
)
|
||||||
if limit:
|
if limit:
|
||||||
sql += " limit {} offset {}".format(int(limit), int(offset))
|
sql += " limit {} offset {}".format(int(limit), int(offset))
|
||||||
|
|
|
@ -12,7 +12,7 @@ from django.views.generic.edit import (
|
||||||
)
|
)
|
||||||
from django.views.generic.base import TemplateView
|
from django.views.generic.base import TemplateView
|
||||||
from dashboard.mixins import DashboardView, Http403
|
from dashboard.mixins import DashboardView, Http403
|
||||||
from evidence.models import Annotation
|
from evidence.models import UserProperty, SystemProperty
|
||||||
from lot.models import LotTag
|
from lot.models import LotTag
|
||||||
from device.models import Device
|
from device.models import Device
|
||||||
from device.forms import DeviceFormSet
|
from device.forms import DeviceFormSet
|
||||||
|
@ -69,7 +69,7 @@ class EditDeviceView(DashboardView, UpdateView):
|
||||||
title = _("Update Device")
|
title = _("Update Device")
|
||||||
breadcrumb = "Device / Update Device"
|
breadcrumb = "Device / Update Device"
|
||||||
success_url = reverse_lazy('dashboard:unassigned_devices')
|
success_url = reverse_lazy('dashboard:unassigned_devices')
|
||||||
model = Annotation
|
model = SystemProperty
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
def get_form_kwargs(self):
|
||||||
pk = self.kwargs.get('pk')
|
pk = self.kwargs.get('pk')
|
||||||
|
@ -87,7 +87,7 @@ class DetailsView(DashboardView, TemplateView):
|
||||||
template_name = "details.html"
|
template_name = "details.html"
|
||||||
title = _("Device")
|
title = _("Device")
|
||||||
breadcrumb = "Device / Details"
|
breadcrumb = "Device / Details"
|
||||||
model = Annotation
|
model = SystemProperty
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
self.pk = kwargs['pk']
|
self.pk = kwargs['pk']
|
||||||
|
@ -172,7 +172,7 @@ class AddUserPropertyView(DashboardView, CreateView):
|
||||||
title = _("New User Property")
|
title = _("New User Property")
|
||||||
breadcrumb = "Device / New Property"
|
breadcrumb = "Device / New Property"
|
||||||
success_url = reverse_lazy('dashboard:unassigned_devices')
|
success_url = reverse_lazy('dashboard:unassigned_devices')
|
||||||
model = Annotation
|
model = UserProperty
|
||||||
fields = ("key", "value")
|
fields = ("key", "value")
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
|
@ -205,21 +205,21 @@ class AddDocumentView(DashboardView, CreateView):
|
||||||
title = _("New Document")
|
title = _("New Document")
|
||||||
breadcrumb = "Device / New document"
|
breadcrumb = "Device / New document"
|
||||||
success_url = reverse_lazy('dashboard:unassigned_devices')
|
success_url = reverse_lazy('dashboard:unassigned_devices')
|
||||||
model = Annotation
|
model = SystemProperty
|
||||||
fields = ("key", "value")
|
fields = ("key", "value")
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
form.instance.owner = self.request.user.institution
|
form.instance.owner = self.request.user.institution
|
||||||
form.instance.user = self.request.user
|
form.instance.user = self.request.user
|
||||||
form.instance.uuid = self.annotation.uuid
|
form.instance.uuid = self.annotation.uuid
|
||||||
form.instance.type = Annotation.Type.DOCUMENT
|
form.instance.type = Property.Type.DOCUMENT
|
||||||
response = super().form_valid(form)
|
response = super().form_valid(form)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
def get_form_kwargs(self):
|
||||||
pk = self.kwargs.get('pk')
|
pk = self.kwargs.get('pk')
|
||||||
institution = self.request.user.institution
|
institution = self.request.user.institution
|
||||||
self.annotation = Annotation.objects.filter(
|
self.annotation = SystemProperty.objects.filter(
|
||||||
owner=institution,
|
owner=institution,
|
||||||
value=pk,
|
value=pk,
|
||||||
type=Annotation.Type.SYSTEM
|
type=Annotation.Type.SYSTEM
|
||||||
|
|
|
@ -4,11 +4,11 @@ import pandas as pd
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from utils.device import create_annotation, create_doc, create_index
|
from utils.device import create_property, create_doc, create_index
|
||||||
from utils.forms import MultipleFileField
|
from utils.forms import MultipleFileField
|
||||||
from device.models import Device
|
from device.models import Device
|
||||||
from evidence.parse import Build
|
from evidence.parse import Build
|
||||||
from evidence.models import Annotation
|
from evidence.models import SystemProperty
|
||||||
from utils.save_snapshots import move_json, save_in_disk
|
from utils.save_snapshots import move_json, save_in_disk
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,11 +30,11 @@ class UploadForm(forms.Form):
|
||||||
try:
|
try:
|
||||||
file_json = json.loads(file_data)
|
file_json = json.loads(file_data)
|
||||||
Build(file_json, None, check=True)
|
Build(file_json, None, check=True)
|
||||||
exist_annotation = Annotation.objects.filter(
|
exists_property = SystemProperty.objects.filter(
|
||||||
uuid=file_json['uuid']
|
uuid=file_json['uuid']
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
if exist_annotation:
|
if exists_property:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_("The snapshot already exists"),
|
_("The snapshot already exists"),
|
||||||
code="duplicate_snapshot",
|
code="duplicate_snapshot",
|
||||||
|
@ -86,7 +86,7 @@ class UserTagForm(forms.Form):
|
||||||
if not data:
|
if not data:
|
||||||
return False
|
return False
|
||||||
self.tag = data
|
self.tag = data
|
||||||
self.instance = Annotation.objects.filter(
|
self.instance = SystemProperty.objects.filter(
|
||||||
uuid=self.uuid,
|
uuid=self.uuid,
|
||||||
type=Annotation.Type.SYSTEM,
|
type=Annotation.Type.SYSTEM,
|
||||||
key='CUSTOM_ID',
|
key='CUSTOM_ID',
|
||||||
|
@ -106,9 +106,9 @@ class UserTagForm(forms.Form):
|
||||||
self.instance.save()
|
self.instance.save()
|
||||||
return
|
return
|
||||||
|
|
||||||
Annotation.objects.create(
|
SystemProperty.objects.create(
|
||||||
uuid=self.uuid,
|
uuid=self.uuid,
|
||||||
type=Annotation.Type.SYSTEM,
|
type=Property.Type.SYSTEM,
|
||||||
key='CUSTOM_ID',
|
key='CUSTOM_ID',
|
||||||
value=self.tag,
|
value=self.tag,
|
||||||
owner=self.user.institution,
|
owner=self.user.institution,
|
||||||
|
|
|
@ -65,22 +65,22 @@ class Evidence:
|
||||||
self.doc = None
|
self.doc = None
|
||||||
self.created = None
|
self.created = None
|
||||||
self.dmi = None
|
self.dmi = None
|
||||||
self.annotations = []
|
self.properties = []
|
||||||
self.components = []
|
self.components = []
|
||||||
self.default = "n/a"
|
self.default = "n/a"
|
||||||
|
|
||||||
self.get_owner()
|
self.get_owner()
|
||||||
self.get_time()
|
self.get_time()
|
||||||
|
|
||||||
def get_annotations(self):
|
def get_properties(self):
|
||||||
self.annotations = Annotation.objects.filter(
|
self.properties = SystemProperty.objects.filter(
|
||||||
uuid=self.uuid
|
uuid=self.uuid
|
||||||
).order_by("created")
|
).order_by("created")
|
||||||
|
|
||||||
def get_owner(self):
|
def get_owner(self):
|
||||||
if not self.annotations:
|
if not self.properties:
|
||||||
self.get_annotations()
|
self.get_properties()
|
||||||
a = self.annotations.first()
|
a = self.properties.first()
|
||||||
if a:
|
if a:
|
||||||
self.owner = a.owner
|
self.owner = a.owner
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ class Evidence:
|
||||||
self.created = self.doc.get("endTime")
|
self.created = self.doc.get("endTime")
|
||||||
|
|
||||||
if not self.created:
|
if not self.created:
|
||||||
self.created = self.annotations.last().created
|
self.created = self.properties.last().created
|
||||||
|
|
||||||
def get_components(self):
|
def get_components(self):
|
||||||
if self.is_legacy():
|
if self.is_legacy():
|
||||||
|
@ -157,9 +157,9 @@ class Evidence:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_all(cls, user):
|
def get_all(cls, user):
|
||||||
return Annotation.objects.filter(
|
return SystemProperty.objects.filter(
|
||||||
owner=user.institution,
|
owner=user.institution,
|
||||||
type=Annotation.Type.SYSTEM,
|
type=SystemProperty.Type.SYSTEM,
|
||||||
key="hidalgo1",
|
key="hidalgo1",
|
||||||
).order_by("-created").values_list("uuid", "created").distinct()
|
).order_by("-created").values_list("uuid", "created").distinct()
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ from dmidecode import DMIParse
|
||||||
from json_repair import repair_json
|
from json_repair import repair_json
|
||||||
from evidence.parse_details import get_lshw_child
|
from evidence.parse_details import get_lshw_child
|
||||||
|
|
||||||
from evidence.models import Annotation
|
from evidence.models import SystemProperty
|
||||||
from evidence.xapian import index
|
from evidence.xapian import index
|
||||||
from utils.constants import CHASSIS_DH
|
from utils.constants import CHASSIS_DH
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ class Build:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.index()
|
self.index()
|
||||||
self.create_annotations()
|
self.create_properties()
|
||||||
|
|
||||||
def index(self):
|
def index(self):
|
||||||
snap = json.dumps(self.json)
|
snap = json.dumps(self.json)
|
||||||
|
@ -72,24 +72,24 @@ class Build:
|
||||||
|
|
||||||
return hashlib.sha3_256(hid.encode()).hexdigest()
|
return hashlib.sha3_256(hid.encode()).hexdigest()
|
||||||
|
|
||||||
def create_annotations(self):
|
def create_properties(self):
|
||||||
annotation = Annotation.objects.filter(
|
property = SystemProperty.objects.filter(
|
||||||
uuid=self.uuid,
|
uuid=self.uuid,
|
||||||
owner=self.user.institution,
|
owner=self.user.institution,
|
||||||
type=Annotation.Type.SYSTEM,
|
type=Property.Type.SYSTEM,
|
||||||
)
|
)
|
||||||
|
|
||||||
if annotation:
|
if property:
|
||||||
txt = "Warning: Snapshot %s already registered (annotation exists)"
|
txt = "Warning: Snapshot %s already registered (property exists)"
|
||||||
logger.warning(txt, self.uuid)
|
logger.warning(txt, self.uuid)
|
||||||
return
|
return
|
||||||
|
|
||||||
for k, v in self.algorithms.items():
|
for k, v in self.algorithms.items():
|
||||||
Annotation.objects.create(
|
SystemProperty.objects.create(
|
||||||
uuid=self.uuid,
|
uuid=self.uuid,
|
||||||
owner=self.user.institution,
|
owner=self.user.institution,
|
||||||
user=self.user,
|
user=self.user,
|
||||||
type=Annotation.Type.SYSTEM,
|
type=Property.Type.SYSTEM,
|
||||||
key=k,
|
key=k,
|
||||||
value=v
|
value=v
|
||||||
)
|
)
|
||||||
|
|
|
@ -20,5 +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('annotation/<int:pk>/del', views.AnnotationDeleteView.as_view(), name='delete_annotation'),
|
path('user_property/<int:pk>/del', views.UserPropertyDeleteView.as_view(), name='delete_user_property'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -13,7 +13,7 @@ from django.views.generic.edit import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from dashboard.mixins import DashboardView, Http403
|
from dashboard.mixins import DashboardView, Http403
|
||||||
from evidence.models import Evidence, Annotation
|
from evidence.models import Property, SystemProperty, UserProperty
|
||||||
from evidence.forms import (
|
from evidence.forms import (
|
||||||
UploadForm,
|
UploadForm,
|
||||||
UserTagForm,
|
UserTagForm,
|
||||||
|
@ -95,7 +95,7 @@ class EvidenceView(DashboardView, FormView):
|
||||||
if self.object.owner != self.request.user.institution:
|
if self.object.owner != self.request.user.institution:
|
||||||
raise Http403
|
raise Http403
|
||||||
|
|
||||||
self.object.get_annotations()
|
self.object.get_properties()
|
||||||
return super().get(request, *args, **kwargs)
|
return super().get(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
@ -141,8 +141,8 @@ class DownloadEvidenceView(DashboardView, TemplateView):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
class AnnotationDeleteView(DashboardView, DeleteView):
|
class UserPropertyDeleteView(DashboardView, DeleteView):
|
||||||
model = Annotation
|
model = UserProperty
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
self.pk = kwargs['pk']
|
self.pk = kwargs['pk']
|
||||||
|
@ -182,7 +182,7 @@ class EraseServerView(DashboardView, FormView):
|
||||||
if self.object.owner != self.request.user.institution:
|
if self.object.owner != self.request.user.institution:
|
||||||
raise Http403
|
raise Http403
|
||||||
|
|
||||||
self.object.get_annotations()
|
self.object.get_properties()
|
||||||
return super().get(request, *args, **kwargs)
|
return super().get(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
|
|
@ -6,7 +6,7 @@ import logging
|
||||||
|
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from evidence.xapian import index
|
from evidence.xapian import index
|
||||||
from evidence.models import Annotation
|
from evidence.models import SystemProperty, Property
|
||||||
from device.models import Device
|
from device.models import Device
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ def create_doc(data):
|
||||||
return doc
|
return doc
|
||||||
|
|
||||||
|
|
||||||
def create_annotation(doc, user, commit=False):
|
def create_property(doc, user, commit=False):
|
||||||
if not doc or not doc.get('uuid') or not doc.get("CUSTOMER_ID"):
|
if not doc or not doc.get('uuid') or not doc.get("CUSTOMER_ID"):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
@ -81,20 +81,20 @@ def create_annotation(doc, user, commit=False):
|
||||||
'value': doc['CUSTOMER_ID'],
|
'value': doc['CUSTOMER_ID'],
|
||||||
}
|
}
|
||||||
if commit:
|
if commit:
|
||||||
annotation = Annotation.objects.filter(
|
property = SystemProperty.objects.filter(
|
||||||
uuid=doc["uuid"],
|
uuid=doc["uuid"],
|
||||||
owner=user.institution,
|
owner=user.institution,
|
||||||
type=Annotation.Type.SYSTEM,
|
type=Property.Type.SYSTEM,
|
||||||
)
|
)
|
||||||
|
|
||||||
if annotation:
|
if property:
|
||||||
txt = "Warning: Snapshot %s already registered (annotation exists)"
|
txt = "Warning: Snapshot %s already registered (system property exists)"
|
||||||
logger.warning(txt, doc["uuid"])
|
logger.warning(txt, doc["uuid"])
|
||||||
return annotation
|
return property
|
||||||
|
|
||||||
return Annotation.objects.create(**data)
|
return SystemProperty.objects.create(**data)
|
||||||
|
|
||||||
return Annotation(**data)
|
return SystemProperty(**data)
|
||||||
|
|
||||||
|
|
||||||
def create_index(doc, user):
|
def create_index(doc, user):
|
||||||
|
|
Loading…
Reference in New Issue