96-add-serial-number-in-public-web #24

Merged
cayop merged 10 commits from 96-add-serial-number-in-public-web into main 2024-11-06 16:30:19 +00:00
1 changed files with 18 additions and 8 deletions
Showing only changes of commit a67fda6b51 - Show all commits

View File

@ -11,7 +11,7 @@ from user.models import User, Institution
class Annotation(models.Model): class Annotation(models.Model):
class Type(models.IntegerChoices): class Type(models.IntegerChoices):
SYSTEM= 0, "System" SYSTEM = 0, "System"
USER = 1, "User" USER = 1, "User"
DOCUMENT = 2, "Document" DOCUMENT = 2, "Document"
ERASE_SERVER = 3, "EraseServer" ERASE_SERVER = 3, "EraseServer"
@ -19,14 +19,16 @@ class Annotation(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
uuid = models.UUIDField() uuid = models.UUIDField()
owner = models.ForeignKey(Institution, on_delete=models.CASCADE) owner = models.ForeignKey(Institution, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True) user = models.ForeignKey(
type = models.SmallIntegerField(choices=Type) User, on_delete=models.SET_NULL, null=True, blank=True)
type = models.SmallIntegerField(choices=Type)
key = models.CharField(max_length=STR_EXTEND_SIZE) key = models.CharField(max_length=STR_EXTEND_SIZE)
value = models.CharField(max_length=STR_EXTEND_SIZE) value = models.CharField(max_length=STR_EXTEND_SIZE)
class Meta: class Meta:
constraints = [ constraints = [
models.UniqueConstraint(fields=["type", "key", "uuid"], name="unique_type_key_uuid") models.UniqueConstraint(
fields=["type", "key", "uuid"], name="unique_type_key_uuid")
] ]
@ -37,8 +39,8 @@ class Evidence:
self.doc = None self.doc = None
self.created = None self.created = None
self.dmi = None self.dmi = None
self.annotations = [] self.annotations = []
self.components = [] self.components = []
self.default = "n/a" self.default = "n/a"
self.get_owner() self.get_owner()
@ -87,7 +89,7 @@ class Evidence:
return self.components return self.components
def get_manufacturer(self): def get_manufacturer(self):
if self.doc.get("type") == "WebSnapshot": if self.is_new_snapshot():
kv = self.doc.get('kv', {}) kv = self.doc.get('kv', {})
if len(kv) < 1: if len(kv) < 1:
return "" return ""
@ -99,7 +101,7 @@ class Evidence:
return self.dmi.manufacturer().strip() return self.dmi.manufacturer().strip()
def get_model(self): def get_model(self):
if self.doc.get("type") == "WebSnapshot": if self.is_new_snapshot():
kv = self.doc.get('kv', {}) kv = self.doc.get('kv', {})
if len(kv) < 2: if len(kv) < 2:
return "" return ""
@ -122,6 +124,11 @@ class Evidence:
return k return k
return "" return ""
def get_serial_number(self):
if self.is_legacy():
return self.doc['device']['serialNumber']
return self.dmi.serial_number().strip()
@classmethod @classmethod
def get_all(cls, user): def get_all(cls, user):
return Annotation.objects.filter( return Annotation.objects.filter(
@ -136,3 +143,6 @@ class Evidence:
def is_legacy(self): def is_legacy(self):
return self.doc.get("software") != "workbench-script" return self.doc.get("software") != "workbench-script"
def is_new_snapshot(self):
return self.doc.get("type") == "WebSnapshot"