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) diff --git a/cmdb-api/api/lib/common_setting/employee.py b/cmdb-api/api/lib/common_setting/employee.py index 671170f..19f7791 100644 --- a/cmdb-api/api/lib/common_setting/employee.py +++ b/cmdb-api/api/lib/common_setting/employee.py @@ -563,6 +563,7 @@ class EmployeeCRUD(object): for column in direct_columns: tmp[column] = d.get(column, '') notice_info = d.get('notice_info', {}) + notice_info = copy.deepcopy(notice_info) if notice_info else {} tmp.update(**notice_info) results.append(tmp) return results