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

feat: 规则审计-策略新增/编辑-后端接口 --story=121513458 #515

Merged
Merged
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
16 changes: 6 additions & 10 deletions src/backend/services/web/strategy_v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ def _validate_strategy_type(self, validated_request_data: dict):
raise serializers.ValidationError(
gettext("control_id and control_version are required when strategy_type is model"),
)
# check control
if not ControlVersion.objects.filter(
control_id=validated_request_data["control_id"],
control_version=validated_request_data["control_version"],
).exists():
raise serializers.ValidationError(gettext("Control Version not Exists"))
elif strategy_type == StrategyType.RULE.value:
if validated_request_data.get("configs", {}).get("config_type") != RuleAuditConfigType.LINK_TABLE:
return
Expand Down Expand Up @@ -211,11 +217,6 @@ def validate(self, attrs: dict) -> dict:
data = super().validate(attrs)
# check type
self._validate_strategy_type(data)
# check control
if not ControlVersion.objects.filter(
control_id=data["control_id"], control_version=data["control_version"]
).exists():
raise serializers.ValidationError(gettext("Control Version not Exists"))
# check name
if Strategy.objects.filter(strategy_name=attrs["strategy_name"]).exists():
raise serializers.ValidationError(gettext("Strategy Name Duplicate"))
Expand Down Expand Up @@ -294,11 +295,6 @@ def validate(self, attrs: dict) -> dict:
data = super().validate(attrs)
# check type
self._validate_strategy_type(data)
# check control
if not ControlVersion.objects.filter(
control_id=data["control_id"], control_version=data["control_version"]
).exists():
raise serializers.ValidationError(gettext("Control Version not Exists"))
# check name
if (
Strategy.objects.filter(strategy_name=attrs["strategy_name"])
Expand Down
Loading