-
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
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
Oops, something went wrong.