Skip to content

Commit

Permalink
Prevent assigning parent assets to primary assets (#1302)
Browse files Browse the repository at this point in the history
  • Loading branch information
nas-tabchiche authored Jan 3, 2025
1 parent 1fd9902 commit 3288ac1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,18 @@ class AssetViewSet(BaseModelViewSet):
]
search_fields = ["name", "description", "business_value"]

def _perform_write(self, serializer):
type = serializer.validated_data.get("type")
if type == Asset.Type.PRIMARY:
serializer.validated_data["parent_assets"] = []
serializer.save()

def perform_create(self, serializer):
return self._perform_write(serializer)

def perform_update(self, serializer):
return self._perform_write(serializer)

@action(detail=False, name="Get type choices")
def type(self, request):
return Response(dict(Asset.Type.choices))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
/>
<AutocompleteSelect
disabled={data.type === 'PR'}
hidden={data.type === 'PR'}
multiple
{form}
options={getOptions({ objects: model.foreignKeys['parent_assets'], self: object })}
Expand Down

0 comments on commit 3288ac1

Please sign in to comment.