mirror of
https://github.com/ansible/awx.git
synced 2026-05-06 00:47:37 -02:30
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:
@@ -1857,10 +1857,14 @@ class CredentialTypeSerializer(BaseSerializer):
|
||||
if self.instance and self.instance.managed_by_tower:
|
||||
raise serializers.ValidationError(
|
||||
{"detail": _("Modifications not allowed for credential types managed by Tower")})
|
||||
if self.instance and self.instance.credentials.exists():
|
||||
if 'inputs' in attrs and attrs['inputs'] != self.instance.inputs:
|
||||
raise serializers.ValidationError(
|
||||
{"inputs": _("Modifications to inputs are not allowed for credential types that are in use")})
|
||||
fields = attrs.get('inputs', {}).get('fields', [])
|
||||
for field in fields:
|
||||
if field.get('ask_at_runtime', False):
|
||||
raise serializers.ValidationError({"detail": _("'ask_at_runtime' is not supported for custom credentials.")})
|
||||
raise serializers.ValidationError({"inputs": _("'ask_at_runtime' is not supported for custom credentials.")})
|
||||
return super(CredentialTypeSerializer, self).validate(attrs)
|
||||
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user