mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-23 20:42:02 +00:00
Revert "Use UniqueTogetherValidator instead of custom validate function"
This reverts commit 6df035e0f1c6a4be53bca23c839429b4fbaaf7f5.
This commit is contained in:
@@ -5485,8 +5485,16 @@ class TestLighthouseConfigViewSet:
|
||||
assert any(field in error["source"]["pointer"] for error in errors)
|
||||
|
||||
def test_lighthouse_config_create_duplicate(
|
||||
self, authenticated_client, valid_config_payload, lighthouse_config_fixture
|
||||
self, authenticated_client, valid_config_payload
|
||||
):
|
||||
# Create first config
|
||||
response = authenticated_client.post(
|
||||
reverse("lighthouseconfig-list"),
|
||||
data=valid_config_payload,
|
||||
content_type=API_JSON_CONTENT_TYPE,
|
||||
)
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
|
||||
# Try to create second config for same tenant
|
||||
response = authenticated_client.post(
|
||||
reverse("lighthouseconfig-list"),
|
||||
@@ -5495,7 +5503,7 @@ class TestLighthouseConfigViewSet:
|
||||
)
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
assert (
|
||||
"Lighthouse configuration already exists for this tenant"
|
||||
"AI configuration already exists for this tenant"
|
||||
in response.json()["errors"][0]["detail"]
|
||||
)
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ from django.contrib.auth.models import update_last_login
|
||||
from django.contrib.auth.password_validation import validate_password
|
||||
from drf_spectacular.utils import extend_schema_field
|
||||
from jwt.exceptions import InvalidKeyError
|
||||
from rest_framework.validators import UniqueTogetherValidator
|
||||
from rest_framework_json_api import serializers
|
||||
from rest_framework_json_api.serializers import ValidationError
|
||||
from rest_framework_simplejwt.exceptions import TokenError
|
||||
@@ -2182,13 +2181,16 @@ class LighthouseConfigCreateSerializer(RLSSerializer, BaseWriteSerializer):
|
||||
"business_context",
|
||||
"is_active",
|
||||
]
|
||||
validators = [
|
||||
UniqueTogetherValidator(
|
||||
queryset=LighthouseConfig.objects.all(),
|
||||
fields=["name"],
|
||||
message="Lighthouse configuration already exists for this tenant.",
|
||||
|
||||
def validate(self, attrs):
|
||||
tenant_id = self.context.get("request").tenant_id
|
||||
if LighthouseConfig.objects.filter(tenant_id=tenant_id).exists():
|
||||
raise serializers.ValidationError(
|
||||
{
|
||||
"tenant_id": "AI configuration already exists for this tenant. Use PUT to update."
|
||||
}
|
||||
)
|
||||
]
|
||||
return super().validate(attrs)
|
||||
|
||||
def create(self, validated_data):
|
||||
api_key = validated_data.pop("api_key")
|
||||
|
||||
Reference in New Issue
Block a user