Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent assigning parent assets to primary assets #1302

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading