Skip to content

Commit

Permalink
Prevent assigning an incompatible software to a device
Browse files Browse the repository at this point in the history
  • Loading branch information
tsagadar authored and b-rowan committed Sep 24, 2024
1 parent bcbe6ea commit d9fba15
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions goosebit/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import semver
from anyio import Path
from tortoise import Model, fields
from tortoise.exceptions import ValidationError

from goosebit.api.telemetry.metrics import devices_count

Expand Down Expand Up @@ -75,6 +76,13 @@ class Device(Model):
tags = fields.ManyToManyField("models.Tag", related_name="devices", through="device_tags")

async def save(self, *args, **kwargs):
# Check if the software is compatible with the hardware before saving
if self.assigned_software and self.hardware:
# Check if the assigned software is compatible with the hardware
is_compatible = await self.assigned_software.compatibility.filter(id=self.hardware_id).exists()
if not is_compatible:
raise ValidationError("The assigned software is not compatible with the device's hardware.")

is_new = self._saved_in_db is False
await super().save(*args, **kwargs)
if is_new:
Expand Down

0 comments on commit d9fba15

Please sign in to comment.