fix: 修复创建命令过滤规则失败的问题

pull/7583/head
Michael Bai 3 years ago committed by Jiangjie.Bai
parent 1faba95a48
commit 6adeafd1d2

@ -133,9 +133,10 @@ class CommandFilterRule(OrgModelMixin):
s = r'{}'.format('|'.join(regex)) s = r'{}'.format('|'.join(regex))
return s return s
def compile_regex(self, regex): @staticmethod
def compile_regex(regex, ignore_case):
try: try:
if self.ignore_case: if ignore_case:
pattern = re.compile(regex, re.IGNORECASE) pattern = re.compile(regex, re.IGNORECASE)
else: else:
pattern = re.compile(regex) pattern = re.compile(regex)
@ -146,7 +147,7 @@ class CommandFilterRule(OrgModelMixin):
return True, '', pattern return True, '', pattern
def match(self, data): def match(self, data):
succeed, error, pattern = self.compile_regex(regex=self.pattern) succeed, error, pattern = self.compile_regex(self.pattern, self.ignore_case)
if not succeed: if not succeed:
return self.ACTION_UNKNOWN, '' return self.ACTION_UNKNOWN, ''

@ -66,7 +66,8 @@ class CommandFilterRuleSerializer(BulkOrgResourceModelSerializer):
regex = CommandFilterRule.construct_command_regex(content) regex = CommandFilterRule.construct_command_regex(content)
else: else:
regex = content regex = content
succeed, error, pattern = CommandFilterRule.compile_regex(regex) ignore_case = self.initial_data.get('ignore_case')
succeed, error, pattern = CommandFilterRule.compile_regex(regex, ignore_case)
if not succeed: if not succeed:
raise serializers.ValidationError(error) raise serializers.ValidationError(error)
return content return content

Loading…
Cancel
Save