-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #437 from 0RAJA/feat_notice_group_var
feat: 通知组内新增变量 --story=119072639
- Loading branch information
Showing
16 changed files
with
197 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
### V1.15.0 版本更新日志 | ||
|
||
[TODO] | ||
### 新增 | ||
|
||
- [ 新增 ] 通知组内新增变量 | ||
|
||
### V1.14.0 版本更新日志 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# -*- coding: utf-8 -*- | ||
import abc | ||
from typing import List, Union | ||
|
||
from bk_resource import resource | ||
from django.db.models import QuerySet | ||
|
||
from apps.notice.constants import MemberVariable | ||
from apps.notice.models import NoticeGroup | ||
|
||
|
||
class MemberVariableParserBase(abc.ABC): | ||
def is_skip(self, member: str) -> bool: | ||
"""默认跳过变量""" | ||
return MemberVariable.match(member) is not None | ||
|
||
@abc.abstractmethod | ||
def parse_member(self, member: Union[str, MemberVariable]) -> str: | ||
"""解析成员""" | ||
raise NotImplementedError() | ||
|
||
def parse_group(self, group: NoticeGroup) -> List[str]: | ||
""" | ||
处理组成员 | ||
""" | ||
|
||
parsed_members = set() | ||
for member in group.group_member: | ||
if self.is_skip(member): | ||
continue | ||
member = self.parse_member(member) | ||
if member: | ||
parsed_members.add(member) | ||
return list(parsed_members) | ||
|
||
def parse_groups(self, groups: Union[QuerySet["NoticeGroup"], List["NoticeGroup"]]) -> List[str]: | ||
""" | ||
解析处理组成员 | ||
""" | ||
|
||
return list({member for group in groups for member in self.parse_group(group)}) | ||
|
||
|
||
class MemberVariableParser(MemberVariableParserBase): | ||
""" | ||
成员变量解析器 | ||
""" | ||
|
||
def __init__(self, operator: str): | ||
""" | ||
:param operator: 责任人 | ||
""" | ||
|
||
self.operator = operator | ||
|
||
def parse_member(self, member: Union[str, MemberVariable]) -> str: | ||
match member: | ||
case MemberVariable.OPERATOR: | ||
return self.operator | ||
case MemberVariable.OPERATOR_LEADER: | ||
return resource.user_manage.retrieve_leader(id=self.operator) | ||
return member | ||
|
||
|
||
class IgnoreMemberVariableParser(MemberVariableParserBase): | ||
""" | ||
忽略成员变量解析器 | ||
""" | ||
|
||
def parse_member(self, member: Union[str, MemberVariable]) -> str: | ||
return member |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.utils.translation import gettext_lazy | ||
from rest_framework import serializers | ||
|
||
|
||
class ChoiceListSerializer(serializers.Serializer): | ||
""" | ||
Choice List | ||
""" | ||
|
||
label = serializers.CharField(label=gettext_lazy("Label"), allow_blank=True, allow_null=True) | ||
value = serializers.CharField(label=gettext_lazy("Value")) | ||
config = serializers.JSONField(label=gettext_lazy("Config"), required=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ msgid "" | |
msgstr "" | ||
"Project-Id-Version: PACKAGE VERSION\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-08-26 10:55+0800\n" | ||
"POT-Creation-Date: 2024-09-12 13:19+0800\n" | ||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: LANGUAGE <[email protected]>\n" | ||
|
@@ -1506,6 +1506,9 @@ msgstr "Risk" | |
msgid "异常" | ||
msgstr "Error" | ||
|
||
msgid "责任人上级" | ||
msgstr "Person Superior" | ||
|
||
msgid "通知组名称重复" | ||
msgstr "Notice Group Name Duplicate" | ||
|
||
|
@@ -1608,6 +1611,9 @@ msgstr "Create Notice Group" | |
msgid "更新通知组" | ||
msgstr "Update Notice Group" | ||
|
||
msgid "Get Notice Common" | ||
msgstr "Get Strategy Common" | ||
|
||
msgid "此为系统邮件,由蓝鲸审计中心自动发送,请勿回复" | ||
msgstr "Sent by Blueking Audit Center" | ||
|
||
|
@@ -1630,6 +1636,9 @@ msgstr "Notice Group Name Invalid with %s" | |
msgid "内置通知组禁止删除" | ||
msgstr "Build in notice group is not allowed to delete" | ||
|
||
msgid "Member Variable" | ||
msgstr "Member Variable" | ||
|
||
msgid "权限中心异常" | ||
msgstr "IAM Error" | ||
|
||
|
@@ -1946,6 +1955,15 @@ msgstr "Admin Required" | |
msgid "Token Invalid" | ||
msgstr "Token Invalid" | ||
|
||
msgid "Label" | ||
msgstr "Label" | ||
|
||
msgid "Value" | ||
msgstr "Value" | ||
|
||
msgid "Config" | ||
msgstr "Config" | ||
|
||
msgid "数据拉取" | ||
msgstr "Data Pull" | ||
|
||
|
@@ -3469,9 +3487,6 @@ msgstr "Strategy Count" | |
msgid "Key" | ||
msgstr "Key" | ||
|
||
msgid "Value" | ||
msgstr "Value" | ||
|
||
msgid "Method" | ||
msgstr "Method" | ||
|
||
|
@@ -3502,9 +3517,6 @@ msgstr "Detects" | |
msgid "System ID" | ||
msgstr "System ID" | ||
|
||
msgid "Label" | ||
msgstr "Label" | ||
|
||
msgid "Children" | ||
msgstr "Children" | ||
|
||
|
@@ -3514,9 +3526,6 @@ msgstr "Action ID" | |
msgid "Field Type" | ||
msgstr "Field Type" | ||
|
||
msgid "Config" | ||
msgstr "Config" | ||
|
||
msgid "Strategy Operator" | ||
msgstr "Strategy Operator" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ msgid "" | |
msgstr "" | ||
"Project-Id-Version: PACKAGE VERSION\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-08-26 10:55+0800\n" | ||
"POT-Creation-Date: 2024-09-12 13:19+0800\n" | ||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: LANGUAGE <[email protected]>\n" | ||
|
@@ -1506,6 +1506,9 @@ msgstr "风险" | |
msgid "异常" | ||
msgstr "异常" | ||
|
||
msgid "责任人上级" | ||
msgstr "责任人上级" | ||
|
||
msgid "通知组名称重复" | ||
msgstr "通知组名称重复" | ||
|
||
|
@@ -1608,6 +1611,9 @@ msgstr "创建通知组" | |
msgid "更新通知组" | ||
msgstr "更新通知组" | ||
|
||
msgid "Get Notice Common" | ||
msgstr "获取策略通用参数" | ||
|
||
msgid "此为系统邮件,由蓝鲸审计中心自动发送,请勿回复" | ||
msgstr "此为系统邮件,由蓝鲸审计中心自动发送,请勿回复" | ||
|
||
|
@@ -1630,6 +1636,9 @@ msgstr "通知组名称不能包含特殊字符 %s" | |
msgid "内置通知组禁止删除" | ||
msgstr "内置通知组禁止删除" | ||
|
||
msgid "Member Variable" | ||
msgstr "成员变量" | ||
|
||
msgid "权限中心异常" | ||
msgstr "权限中心异常" | ||
|
||
|
@@ -1946,6 +1955,15 @@ msgstr "管理员请求" | |
msgid "Token Invalid" | ||
msgstr "Token验证失败" | ||
|
||
msgid "Label" | ||
msgstr "标签" | ||
|
||
msgid "Value" | ||
msgstr "值" | ||
|
||
msgid "Config" | ||
msgstr "配置" | ||
|
||
msgid "数据拉取" | ||
msgstr "数据拉取" | ||
|
||
|
@@ -3469,9 +3487,6 @@ msgstr "策略数量" | |
msgid "Key" | ||
msgstr "键" | ||
|
||
msgid "Value" | ||
msgstr "值" | ||
|
||
msgid "Method" | ||
msgstr "方法" | ||
|
||
|
@@ -3502,9 +3517,6 @@ msgstr "识别条件" | |
msgid "System ID" | ||
msgstr "系统ID" | ||
|
||
msgid "Label" | ||
msgstr "标签" | ||
|
||
msgid "Children" | ||
msgstr "子数据" | ||
|
||
|
@@ -3514,9 +3526,6 @@ msgstr "操作ID" | |
msgid "Field Type" | ||
msgstr "字段类型" | ||
|
||
msgid "Config" | ||
msgstr "配置" | ||
|
||
msgid "Strategy Operator" | ||
msgstr "策略操作符" | ||
|
||
|
Oops, something went wrong.