From 54de3b98065bd811323e738a5499d2dba05e2032 Mon Sep 17 00:00:00 2001 From: "hu.sima" Date: Wed, 13 Dec 2023 09:39:52 +0800 Subject: [PATCH] fix(api): remove path when save messager url --- .../api/lib/common_setting/company_info.py | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/cmdb-api/api/lib/common_setting/company_info.py b/cmdb-api/api/lib/common_setting/company_info.py index c700fea..7031a2f 100644 --- a/cmdb-api/api/lib/common_setting/company_info.py +++ b/cmdb-api/api/lib/common_setting/company_info.py @@ -1,4 +1,6 @@ # -*- coding:utf-8 -*- +from urllib.parse import urlparse + from api.extensions import cache from api.models.common_setting import CompanyInfo @@ -11,6 +13,7 @@ class CompanyInfoCRUD(object): @staticmethod def create(**kwargs): + CompanyInfoCRUD.check_data(**kwargs) res = CompanyInfo.create(**kwargs) CompanyInfoCache.refresh(res.info) return res @@ -22,10 +25,26 @@ class CompanyInfoCRUD(object): if not existed: existed = CompanyInfoCRUD.create(**kwargs) else: + CompanyInfoCRUD.check_data(**kwargs) existed = existed.update(**kwargs) CompanyInfoCache.refresh(existed.info) return existed + @staticmethod + def check_data(**kwargs): + info = kwargs.get('info', {}) + info['messenger'] = CompanyInfoCRUD.check_messenger(info.get('messenger', None)) + + kwargs['info'] = info + + @staticmethod + def check_messenger(messenger): + if not messenger: + return messenger + + parsed_url = urlparse(messenger) + return f"{parsed_url.scheme}://{parsed_url.netloc}" + class CompanyInfoCache(object): key = 'CompanyInfoCache::' @@ -41,4 +60,4 @@ class CompanyInfoCache(object): @classmethod def refresh(cls, info): - cache.set(cls.key, info) \ No newline at end of file + cache.set(cls.key, info)