Make CredentialType conditionally editable/readonly.

* CredentialTypes should not be editable *or* deletable if they're
  "managed_by_tower".
* CredentialTypes should not be deletable if they're in use by one or
  more Credentials.
* CredentialType.inputs should not be editable if they're in use by one
  or more Credentials.

see: #6077
This commit is contained in:
Ryan Petrello
2017-05-08 11:09:52 -04:00
parent 6728bb2315
commit 1568fddde1
4 changed files with 58 additions and 11 deletions

View File

@@ -1504,6 +1504,12 @@ class CredentialTypeDetail(RetrieveUpdateDestroyAPIView):
new_in_320 = True
new_in_api_v2 = True
def destroy(self, request, *args, **kwargs):
instance = self.get_object()
if instance.managed_by_tower or instance.credentials.exists():
raise PermissionDenied(detail=_("Credential types that are in use cannot be deleted."))
return super(CredentialTypeDetail, self).destroy(request, *args, **kwargs)
class CredentialList(ListCreateAPIView):