feat(devops): Serializer validate software and org

ref: #670 #659
This commit is contained in:
2025-03-05 01:34:29 +09:30
parent 75412df8b6
commit 0a5778258b

View File

@ -4,6 +4,8 @@ from access.serializers.organization import Organization, OrganizationBaseSerial
from api.serializers import common
from core import exceptions as centurion_exceptions
from devops.models.feature_flag import FeatureFlag
from itam.serializers.software import Software, SoftwareBaseSerializer
@ -91,6 +93,42 @@ class ModelSerializer(
]
def is_valid(self, raise_exception = False):
is_valid = super().is_valid( raise_exception = raise_exception )
valid_software_orgs = Software.objects.filter(
feature_flagging__enabled = True,
feature_flagging__software = self.validated_data['software']
).distinct().values_list(
'feature_flagging__organization',
flat = True
)
if len(valid_software_orgs) == 0:
raise centurion_exceptions.ValidationError(
detail = {
'software': 'Software not enabled for Feature flagging'
},
code = 'feature_flagging_disabled'
)
if self.validated_data['organization'].id not in valid_software_orgs:
raise centurion_exceptions.ValidationError(
detail = {
'organization': 'Feature flagging not enabled for this software within this organization'
},
code = 'feature_flagging_wrong_organizaiton'
)
return is_valid
class ViewSerializer(ModelSerializer):