Skip to content

Commit

Permalink
fix: asset class check for restricting asset relations (#1527)
Browse files Browse the repository at this point in the history
  • Loading branch information
sainak authored and Ashesh3 committed Aug 23, 2023
1 parent df5f2c5 commit ab70bbf
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions care/facility/api/serializers/bed.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ def validate(self, attrs):
not facilities.filter(id=asset.current_location.facility.id).exists()
) or (not facilities.filter(id=bed.facility.id).exists()):
raise PermissionError()
if asset.asset_class not in [AssetClasses.HL7MONITOR, AssetClasses.ONVIF]:
if asset.asset_class not in [
AssetClasses.HL7MONITOR.name,
AssetClasses.ONVIF.name,
]:
raise ValidationError({"asset": "Asset is not a monitor or camera"})
attrs["asset"] = asset
attrs["bed"] = bed
Expand All @@ -112,7 +115,7 @@ def validate(self, attrs):
{"asset": "Should be in the same facility as the bed"}
)
if (
asset.asset_class in ["HL7MONITOR", "VENTILATOR"]
asset.asset_class == AssetClasses.HL7MONITOR.name
and AssetBed.objects.filter(
bed=bed, asset__asset_class=asset.asset_class
).exists()
Expand Down Expand Up @@ -262,8 +265,8 @@ def create(self, validated_data):
)
.exclude(
asset_class__in=[
AssetClasses.HL7MONITOR,
AssetClasses.ONVIF,
AssetClasses.HL7MONITOR.name,
AssetClasses.ONVIF.name,
]
)
.values_list("external_id", flat=True)
Expand Down

0 comments on commit ab70bbf

Please sign in to comment.