Skip to content

Commit

Permalink
Merge pull request #515 from 0RAJA/feat_rule_audit_strategy
Browse files Browse the repository at this point in the history
feat: 规则审计-策略新增/编辑-后端接口 --story=121513458
  • Loading branch information
0RAJA authored Jan 9, 2025
2 parents 587e1ed + 963b126 commit 31658d1
Showing 1 changed file with 6 additions and 10 deletions.
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

0 comments on commit 31658d1

Please sign in to comment.