Skip to content

Commit

Permalink
feat: 通知人员过滤 --story=119869910
Browse files Browse the repository at this point in the history
  • Loading branch information
benero committed Sep 25, 2024
1 parent bcb7450 commit 4c9286c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
18 changes: 15 additions & 3 deletions common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
import re
from django.conf import settings

# 开发框架公用方法
# 1. 页面输入内容转义(防止xss攻击)
Expand Down Expand Up @@ -91,5 +91,17 @@ def cmp(a, b):
return (a > b) - (a < b)


def strip_tags(value):
return re.sub(r'<[^>]*?>', '', value)
def notice_receiver_filter(receivers):
"""
通知名单过滤
"""
if not receivers:
return receivers

receiver_type = "list"
if isinstance(receivers, str):
receiver_type = "str"
receivers = receivers.strip().split(",")

receivers = [i for i in receivers if i not in settings.NOTICE_IGNORE_LIST]
return receivers if receiver_type == "list" else ",".join(receivers)
7 changes: 5 additions & 2 deletions config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import base64
import datetime
import importlib
import os
from urllib.parse import urljoin, urlparse

from blueapps.conf.default_settings import * # noqa
Expand Down Expand Up @@ -959,5 +960,7 @@ def redirect_func(request):
BK_SHARED_RES_URL = os.getenv("BKPAAS_SHARED_RES_URL") or os.getenv("BKAPP_SHARED_RES_URL")
BK_PLATFORM_NAME = os.getenv("BKAPP_PLATFORM_NAME", "")

# 本地开发环境跳转豁免配置
BKAPP_SKIP_SECURE = os.getenv("BKAPP_SKIP_SECURE", False)
# 通知过滤
NOTICE_IGNORE_LIST = os.getenv("BKAPP_NOTICE_IGNORE_LIST", [])
if isinstance(NOTICE_IGNORE_LIST, str):
NOTICE_IGNORE_LIST = [i.lower().strip() for i in NOTICE_IGNORE_LIST.split(",")]
7 changes: 7 additions & 0 deletions itsm/component/bkchat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.http import JsonResponse

from common.log import logger
from common.utils import notice_receiver_filter
from config.default import CLOSE_NOTIFY
from itsm.component.constants import APPROVE_RESULT, API, RUNNING, SHOW_BY_CONDITION
from itsm.component.exceptions import ComponentCallError
Expand Down Expand Up @@ -112,6 +113,12 @@ def send_fast_approval_message(title, content, receivers, ticket, state_id):

# 更新详情url
ticket.generate_ticket_url(state_id, receivers)

# 接收人过滤
receivers = notice_receiver_filter(receivers)
if not receivers:
logger.info(f"[fast approval] receivers is empty after filter, ticket_id=>{ticket_id}")
return

# 构造data信息
data = {
Expand Down
7 changes: 3 additions & 4 deletions itsm/component/misc_middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,10 @@ def __init__(self, redirect_to, *args, **kwargs):

class HttpsMiddleware(MiddlewareMixin):
def process_request(self, request):
if settings.ENVIRONMENT == "dev":
return None

if settings.RUN_VER == "ieod":
# 本地开发环境跳转豁免
if settings.BKAPP_SKIP_SECURE:
return None

# 对于openapi 跳转豁免
if request.path.startswith(EXEMPT_HTTPS_REDIRECT):
return None
Expand Down
3 changes: 2 additions & 1 deletion itsm/component/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from django.utils.translation import ugettext as _

from common.log import logger
from common.utils import notice_receiver_filter
from itsm.component.constants import GENERAL_NOTICE
from itsm.component.esb.esbclient import client_backend
from itsm.component.exceptions import ComponentCallError
Expand All @@ -39,7 +40,7 @@
class BaseNotifier(object):
def __init__(self, title, receivers, message, notify_type=GENERAL_NOTICE):
self.title = title
self.receivers = receivers
self.receivers = notice_receiver_filter(receivers)
self.message = message
self.notify_type = notify_type

Expand Down
1 change: 0 additions & 1 deletion itsm/openapi/workflow/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def clean_states(self, states):
'end_at',
'update_at',
'notify',
'extras',
'updated_by',
'service',
'axis',
Expand Down

0 comments on commit 4c9286c

Please sign in to comment.