workflow_base_service.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. import json
  2. from django.conf import settings
  3. from django.db.models import Q
  4. from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
  5. from apps.workflow.models import Workflow, WorkflowUserPermission
  6. from service.base_service import BaseService
  7. from service.common.common_service import common_service_ins
  8. from service.common.log_service import auto_log
  9. from service.account.account_base_service import AccountBaseService, account_base_service_ins
  10. from service.workflow.workflow_state_service import workflow_state_service_ins
  11. from service.workflow.workflow_transition_service import workflow_transition_service_ins
  12. class WorkflowBaseService(BaseService):
  13. """
  14. 流程服务
  15. """
  16. def __init__(self):
  17. pass
  18. @classmethod
  19. @auto_log
  20. def get_workflow_list(cls, name: str, page: int, per_page: int, workflow_id_list: list, username: str, from_admin:int =1)->tuple:
  21. """
  22. 获取工作流列表
  23. get workflow list by params
  24. :param name:
  25. :param page:
  26. :param per_page:
  27. :param workflow_id_list:workflow id list
  28. :param username
  29. :param from_admin 管理后台
  30. :return:
  31. """
  32. query_params = Q(is_deleted=False)
  33. if name:
  34. query_params &= Q(name__contains=name)
  35. if from_admin:
  36. # 获取有管理权限的工作流列表
  37. flag, result = cls.get_workflow_manage_list(username)
  38. if flag is False:
  39. workflow_id_list = []
  40. workflow_manage_list = result.get('workflow_list')
  41. workflow_manage_id_list = [workflow_manage.get('id') for workflow_manage in workflow_manage_list]
  42. workflow_id_list = list(set(workflow_manage_id_list) - (set(workflow_manage_id_list) - set(workflow_id_list)))
  43. query_params &= Q(id__in=workflow_id_list)
  44. workflow_queryset = Workflow.objects.filter(query_params).order_by('id')
  45. paginator = Paginator(workflow_queryset, per_page)
  46. try:
  47. workflow_result_paginator = paginator.page(page)
  48. except PageNotAnInteger:
  49. workflow_result_paginator = paginator.page(1)
  50. except EmptyPage:
  51. # If page is out of range (e.g. 9999), deliver last page of results
  52. workflow_result_paginator = paginator.page(paginator.num_pages)
  53. workflow_result_object_list = workflow_result_paginator.object_list
  54. workflow_result_restful_list = []
  55. workflow_result_id_list = []
  56. for workflow_result_object in workflow_result_object_list:
  57. workflow_result_id_list.append(workflow_result_object.id)
  58. workflow_info = dict(
  59. id=workflow_result_object.id,
  60. name=workflow_result_object.name,
  61. description=workflow_result_object.description
  62. )
  63. if from_admin:
  64. workflow_info.update(dict(
  65. notices=workflow_result_object.notices,
  66. view_permission_check=workflow_result_object.view_permission_check,
  67. limit_expression=workflow_result_object.limit_expression,
  68. display_form_str=workflow_result_object.display_form_str,
  69. creator=workflow_result_object.creator, gmt_created=str(workflow_result_object.gmt_created)[:19],
  70. title_template=workflow_result_object.title_template,
  71. content_template=workflow_result_object.content_template
  72. ))
  73. workflow_result_restful_list.append(workflow_info)
  74. # 获取工作流管理员信息
  75. if from_admin:
  76. workflow_admin_queryset = WorkflowUserPermission.objects.filter(workflow_id__in=workflow_result_id_list, permission='admin').all()
  77. for workflow_result_restful in workflow_result_restful_list:
  78. workflow_admin_list = []
  79. for workflow_admin_object in workflow_admin_queryset:
  80. if workflow_admin_object.workflow_id == workflow_result_restful['id']:
  81. workflow_admin_list.append(workflow_admin_object.user)
  82. workflow_result_restful['workflow_admin'] = ','.join(workflow_admin_list)
  83. return True, dict(workflow_result_restful_list=workflow_result_restful_list,
  84. paginator_info=dict(per_page=per_page, page=page, total=paginator.count))
  85. @classmethod
  86. @auto_log
  87. def get_workflow_manage_list(cls, username: str)->tuple:
  88. """
  89. 获取有管理权限的工作流列表
  90. :param username:
  91. :return:
  92. """
  93. # 如果是超级管理员,拥有所有工作流的权限
  94. flag, result = account_base_service_ins.admin_permission_check(username=username)
  95. if flag:
  96. workflow_queryset = Workflow.objects.filter(is_deleted=0).all()
  97. else:
  98. # 作为工作流创建人+工作流管理员的工作流
  99. workflow_admin_queryset = WorkflowUserPermission.objects.filter(permission='admin', user_type='user', user=username).all()
  100. workflow_admin_id_list = [workflow_admin.workflow_id for workflow_admin in workflow_admin_queryset]
  101. workflow_queryset = Workflow.objects.filter(
  102. Q(creator=username) | Q(id__in=workflow_admin_id_list)).all()
  103. workflow_restful_list = [workflow.get_dict() for workflow in workflow_queryset]
  104. return True, dict(workflow_list=workflow_restful_list)
  105. @classmethod
  106. @auto_log
  107. def check_new_permission(cls, username: str, workflow_id: int)->tuple:
  108. """
  109. 判断用户是否有新建工单的权限
  110. check whether user can create ticket
  111. :param username:
  112. :param workflow_id:
  113. :return:
  114. """
  115. # 获取workflow的限制表达式
  116. flag, workflow_obj = cls.get_by_id(workflow_id)
  117. if not workflow_obj:
  118. return False, workflow_obj
  119. limit_expression = workflow_obj.limit_expression
  120. if not limit_expression:
  121. return True, 'no limit_expression set'
  122. #'限制周期({"period":24} 24小时), 限制次数({"count":1}在限制周期内只允许提交1次), 限制级别({"level":1} 针对(1单个用户 2全局)限制周期限制次数,默认特定用户);允许特定人员提交({"allow_persons":"zhangsan,lisi"}只允许张三提交工单,{"allow_depts":"1,2"}只允许部门id为1和2的用户提交工单,{"allow_roles":"1,2"}只允许角色id为1和2的用户提交工单)
  123. limit_expression_dict = json.loads(limit_expression)
  124. limit_period = limit_expression_dict.get('period')
  125. limit_level = limit_expression_dict.get('level')
  126. limit_count = limit_expression_dict.get('count')
  127. limit_allow_persons = limit_expression_dict.get('allow_persons')
  128. limit_allow_depts = limit_expression_dict.get('allow_depts')
  129. limit_allow_roles = limit_expression_dict.get('allow_roles')
  130. from service.ticket.ticket_base_service import ticket_base_service_ins
  131. if limit_period:
  132. if limit_level:
  133. if limit_level == 1:
  134. flag, result = ticket_base_service_ins.get_ticket_count_by_args(
  135. workflow_id=workflow_id, username=username, period=limit_period)
  136. count_result = result.get('count_result')
  137. elif limit_level == 2:
  138. flag, result = ticket_base_service_ins.get_ticket_count_by_args(
  139. workflow_id=workflow_id, period=limit_period)
  140. count_result = result.get('count_result')
  141. else:
  142. return False, 'level in limit_expression is invalid'
  143. if count_result is False:
  144. return False, result
  145. if not limit_count:
  146. return False, 'count is need when level is not none'
  147. if count_result >= limit_count:
  148. return False, '{} tickets can be created in {}hours when workflow_id is {}'\
  149. .format(limit_count, limit_period, workflow_id)
  150. if limit_allow_persons:
  151. if username not in limit_allow_persons.split(','):
  152. return False, '{} can not create ticket base on workflow_id:{}'.format(workflow_id)
  153. if limit_allow_depts:
  154. # 获取用户所属部门,包含上级部门
  155. flag, user_all_dept_id_list = AccountBaseService.get_user_up_dept_id_list(username)
  156. if flag is False:
  157. return False, user_all_dept_id_list
  158. # 只要user_all_dept_id_list中的某个部门包含在允许范围内即可
  159. limit_allow_dept_str_list = limit_allow_depts.split(',')
  160. limit_allow_dept_id_list = [int(limit_allow_dept_str) for limit_allow_dept_str in limit_allow_dept_str_list]
  161. limit_allow_dept_id_list = list(set(limit_allow_dept_id_list)) #去重
  162. total_list = user_all_dept_id_list + limit_allow_dept_id_list
  163. if len(total_list) == len(set(total_list)):
  164. # 去重后长度相等,说明两个list完全没有重复,即用户所在部门id肯定不在允许的部门id列表内
  165. return False, 'user is not in allow dept'
  166. if limit_allow_roles:
  167. # 获取用户所有的角色
  168. flag, user_role_list = account_base_service_ins.get_user_role_id_list(username)
  169. if flag is False:
  170. return False, user_role_list
  171. limit_allow_role_str_list = limit_allow_roles.split(',')
  172. limit_allow_role_id_list = [int(limit_allow_role_str) for limit_allow_role_str in limit_allow_role_str_list]
  173. limit_allow_role_id_list = list(set(limit_allow_role_id_list))
  174. total_list = limit_allow_role_id_list + user_role_list
  175. if len(total_list) == len(set(total_list)):
  176. return False, 'user is not in allow role'
  177. return True, ''
  178. @classmethod
  179. @auto_log
  180. def get_by_id(cls, workflow_id: int)->tuple:
  181. """
  182. 获取工作流 by id
  183. get workflow object by workflow id
  184. :param workflow_id:
  185. :return:
  186. """
  187. workflow_obj = Workflow.objects.filter(is_deleted=0, id=workflow_id).first()
  188. if not workflow_obj:
  189. return False, 'workflow is not existed or has been deleted'
  190. return True, workflow_obj
  191. @classmethod
  192. @auto_log
  193. def get_full_info_by_id(cls, workflow_id: int)->tuple:
  194. """
  195. 获取工作流详细详情,包括关联数据。管理员, 干预人,查看权限人,查看权限部门,授权应用
  196. :param workflow_id:
  197. :return:
  198. """
  199. workflow_obj = Workflow.objects.filter(is_deleted=0, id=workflow_id).first()
  200. # 权限人
  201. permission_queryset = WorkflowUserPermission.objects.filter(workflow_id=workflow_id).all()
  202. adminer_list = []
  203. intervener_list = []
  204. viewer_username_list = []
  205. viewer_dept_id_list = []
  206. app_for_api_id_list = []
  207. for permission_obj in permission_queryset:
  208. if permission_obj.permission == 'admin':
  209. adminer_list.append(permission_obj.user)
  210. elif permission_obj.permission == 'intervene':
  211. intervener_list.append(permission_obj.user)
  212. elif permission_obj.permission == 'view':
  213. if permission_obj.user_type == 'user':
  214. viewer_username_list.append(permission_obj.user)
  215. if permission_obj.user_type == 'department':
  216. viewer_dept_id_list.append(permission_obj.user)
  217. elif permission_obj.permission == 'api':
  218. app_for_api_id_list.append(permission_obj.user)
  219. workflow_info_dict = workflow_obj.get_dict()
  220. workflow_info_dict['workflow_admin'] = adminer_list
  221. workflow_info_dict['intervener'] = intervener_list
  222. workflow_info_dict['view_persons'] = viewer_username_list
  223. workflow_info_dict['view_depts'] = viewer_dept_id_list
  224. workflow_info_dict['api_permission_apps'] = app_for_api_id_list
  225. return True, workflow_info_dict
  226. @classmethod
  227. @auto_log
  228. def add_workflow(cls, name: str, description: str, notices: str, view_permission_check: int, limit_expression: str,
  229. display_form_str: str, creator: str, workflow_admin: str, title_template: str,
  230. content_template: str, intervener: str, view_depts:str, view_persons:str, api_permission_apps:str)->tuple:
  231. """
  232. 新增工作流
  233. add workflow
  234. :param name:
  235. :param description:
  236. :param notices:
  237. :param view_permission_check:
  238. :param limit_expression:
  239. :param display_form_str:
  240. :param creator:
  241. :param workflow_admin:
  242. :param title_template:
  243. :param content_template:
  244. :return:
  245. """
  246. workflow_obj = Workflow(name=name, description=description, notices=notices,
  247. view_permission_check=view_permission_check, limit_expression=limit_expression,
  248. display_form_str=display_form_str, creator=creator, title_template=title_template,
  249. content_template=content_template)
  250. workflow_obj.save()
  251. intervener_list = intervener.split(',') if intervener else []
  252. workflow_admin_list = workflow_admin.split(',') if workflow_admin else []
  253. view_depts_list = view_depts.split(',') if view_depts else []
  254. view_persons_list = view_persons.split(',') if view_persons else []
  255. api_permission_app_list = api_permission_apps.split(',') if api_permission_apps else []
  256. workflow_id = workflow_obj.id
  257. need_add_permission_queryset = []
  258. for need_add_intervener in intervener_list:
  259. need_add_permission_queryset.append(WorkflowUserPermission(
  260. workflow_id=workflow_id, permission='intervene', user_type='user', user=need_add_intervener))
  261. for need_add_admin in workflow_admin_list:
  262. need_add_permission_queryset.append(WorkflowUserPermission(
  263. workflow_id=workflow_id, permission='admin', user_type='user', user=need_add_admin))
  264. for need_add_view_depts in view_depts_list:
  265. need_add_permission_queryset.append(WorkflowUserPermission(
  266. workflow_id=workflow_id, permission='view', user_type='department', user=need_add_view_depts))
  267. for need_add_view_persons in view_persons_list:
  268. need_add_permission_queryset.append(WorkflowUserPermission(
  269. workflow_id=workflow_id, permission='view', user_type='user', user=need_add_view_persons))
  270. for need_add_app in api_permission_app_list:
  271. need_add_permission_queryset.append(WorkflowUserPermission(
  272. workflow_id=workflow_id, permission='api', user_type='app', user=need_add_app))
  273. WorkflowUserPermission.objects.bulk_create(need_add_permission_queryset)
  274. return True, dict(workflow_id=workflow_obj.id)
  275. @classmethod
  276. @auto_log
  277. def edit_workflow(cls, workflow_id: int, name: str, description: str, notices: str, view_permission_check: int,
  278. limit_expression: str, display_form_str: str, workflow_admin: str, title_template: str,
  279. content_template: str, intervener: str, view_depts: str, view_persons: str, api_permission_apps:str)->tuple:
  280. """
  281. 更新工作流
  282. update workfow
  283. :param workflow_id:
  284. :param name:
  285. :param description:
  286. :param notices:
  287. :param view_permission_check:
  288. :param limit_expression:
  289. :param display_form_str:
  290. :param workflow_admin:
  291. :param title_template:
  292. :param content_template:
  293. :return:
  294. """
  295. workflow_obj = Workflow.objects.filter(id=workflow_id)
  296. if workflow_obj:
  297. workflow_obj.update(name=name, description=description, notices=notices,
  298. view_permission_check=view_permission_check,
  299. limit_expression=limit_expression, display_form_str=display_form_str,
  300. title_template=title_template, content_template=content_template)
  301. # 更新管理员信息
  302. workflow_permission_existed_queryset = WorkflowUserPermission.objects.filter(workflow_id=workflow_id).all()
  303. existed_intervener, existed_workflow_admin, existed_view_depts, existed_view_persons, \
  304. existed_app_permission_apps = [], [], [], [], []
  305. for workflow_permission_existed in workflow_permission_existed_queryset:
  306. if workflow_permission_existed.permission == 'intervene':
  307. existed_intervener.append(workflow_permission_existed.user)
  308. if workflow_permission_existed.permission == 'admin':
  309. existed_workflow_admin.append(workflow_permission_existed.user)
  310. if workflow_permission_existed.permission == 'view' and workflow_permission_existed.user_type == 'department':
  311. existed_view_depts.append(workflow_permission_existed.user)
  312. if workflow_permission_existed.permission == 'view' and workflow_permission_existed.user_type == 'user':
  313. existed_view_persons.append(workflow_permission_existed.user)
  314. if workflow_permission_existed.permission == 'api' and workflow_permission_existed.user_type == 'app':
  315. existed_app_permission_apps.append(workflow_permission_existed.user)
  316. # need del
  317. intervener_list = intervener.split(',') if intervener else []
  318. workflow_admin_list = workflow_admin.split(',') if workflow_admin else []
  319. view_depts_list = view_depts.split(',') if view_depts else []
  320. view_persons_list = view_persons.split(',') if view_persons else []
  321. api_list = api_permission_apps.split(',') if api_permission_apps else []
  322. flag, need_del_intervener_list = common_service_ins.list_subtraction(existed_intervener, intervener_list)
  323. flag, need_del_admin_list = common_service_ins.list_subtraction(existed_workflow_admin, workflow_admin_list)
  324. flag, need_del_view_depts_list = common_service_ins.list_subtraction(existed_view_depts, view_depts_list)
  325. flag, need_del_view_persons_list = common_service_ins.list_subtraction(existed_view_persons, view_persons_list)
  326. flag, need_del_app_list = common_service_ins.list_subtraction(existed_app_permission_apps, api_list)
  327. WorkflowUserPermission.objects.filter(
  328. Q(workflow_id=workflow_id, permission='intervene', user_type='user', user__in=need_del_intervener_list) |
  329. Q(workflow_id=workflow_id, permission='admin', user_type='user', user__in=need_del_admin_list) |
  330. Q(workflow_id=workflow_id, permission='view', user_type='user', user__in=need_del_view_persons_list) |
  331. Q(workflow_id=workflow_id, permission='view', user_type='department', user__in=need_del_view_depts_list) |
  332. Q(workflow_id=workflow_id, permission='api', user_type='app', user__in=need_del_app_list)
  333. ).update(is_deleted=1)
  334. # need add
  335. flag, need_add_intervener_list = common_service_ins.list_subtraction(intervener_list, existed_intervener)
  336. flag, need_add_admin_list = common_service_ins.list_subtraction(workflow_admin_list, existed_workflow_admin)
  337. flag, need_add_view_depts_list = common_service_ins.list_subtraction(view_depts_list, existed_view_depts)
  338. flag, need_add_view_persons_list = common_service_ins.list_subtraction(view_persons_list, existed_view_persons)
  339. flag, need_add_app_list = common_service_ins.list_subtraction(api_list, existed_app_permission_apps)
  340. need_add_permission_queryset = []
  341. for need_add_intervener in need_add_intervener_list:
  342. need_add_permission_queryset.append(WorkflowUserPermission(
  343. workflow_id=workflow_id, permission='intervene', user_type='user', user=need_add_intervener))
  344. for need_add_admin in need_add_admin_list:
  345. need_add_permission_queryset.append(WorkflowUserPermission(
  346. workflow_id=workflow_id, permission='admin', user_type='user', user=need_add_admin))
  347. for need_add_view_depts in need_add_view_depts_list:
  348. need_add_permission_queryset.append(WorkflowUserPermission(
  349. workflow_id=workflow_id, permission='view', user_type='department', user=need_add_view_depts))
  350. for need_add_view_persons in need_add_view_persons_list:
  351. need_add_permission_queryset.append(WorkflowUserPermission(
  352. workflow_id=workflow_id, permission='view', user_type='user', user=need_add_view_persons))
  353. for need_add_app in need_add_app_list:
  354. need_add_permission_queryset.append(WorkflowUserPermission(
  355. workflow_id=workflow_id, permission='api', user_type='app', user=need_add_app))
  356. WorkflowUserPermission.objects.bulk_create(need_add_permission_queryset)
  357. return True, ''
  358. @classmethod
  359. @auto_log
  360. def delete_workflow(cls, workflow_id: int)->tuple:
  361. """
  362. 删除工作流
  363. delete workflow
  364. :param workflow_id:
  365. :return:
  366. """
  367. workflow_obj = Workflow.objects.filter(id=workflow_id)
  368. if workflow_obj:
  369. workflow_obj.update(is_deleted=True)
  370. return True, ''
  371. @classmethod
  372. @auto_log
  373. def get_simple_description(cls, workflow_id: int)->tuple:
  374. """
  375. 获取简单描述
  376. :param workflow_id:
  377. :return:
  378. """
  379. flag, workflow_detail = cls.get_by_id(workflow_id)
  380. if flag is False:
  381. return flag, workflow_detail
  382. flag, state_list = workflow_state_service_ins.get_workflow_states(workflow_id)
  383. if flag is False:
  384. return flag, state_list
  385. flag, transition_list = workflow_transition_service_ins.get_transition_by_args(dict(workflow_id=workflow_id))
  386. if flag is False:
  387. return flag, transition_list
  388. workflow_basic_info = dict(id=workflow_detail.id, name=workflow_detail.name)
  389. workflow_state_info = []
  390. for state in state_list:
  391. workflow_state_info.append(dict(id=state.id, name=state.name))
  392. workflow_transition_info = []
  393. for transition in transition_list:
  394. workflow_transition_info.append(
  395. dict(id=transition.id, name=transition.name, source_state_id=transition.source_state_id,
  396. destination_state_id=transition.destination_state_id,
  397. condition_expression=transition.condition_expression,
  398. attribute_type_id=transition.attribute_type_id, timer=transition.timer
  399. ))
  400. result = dict(workflow_basic_info=workflow_basic_info, workflow_state_info=workflow_state_info,
  401. workflow_transition_info=workflow_transition_info)
  402. return True, result
  403. @classmethod
  404. @auto_log
  405. def get_permission_list_by_args(cls, app_namelist, role):
  406. pass
  407. @classmethod
  408. @auto_log
  409. def can_intervene(cls, workflow_id, username):
  410. """
  411. 判断用户是否有对此工作流对应工单的干预权限
  412. :param workflow_id:
  413. :param username:
  414. :return:
  415. """
  416. # todo: intervene列表, 创建人,管理员
  417. workflow_query_obj = Workflow.objects.filter(id=workflow_id).first()
  418. if not workflow_query_obj:
  419. return False, 'workflow is not existed'
  420. if username == workflow_query_obj.creator:
  421. return True, True
  422. permission_queryset = WorkflowUserPermission.objects.filter(permission__in=['admin', 'intervene'],
  423. user_type='user').all()
  424. for permission in permission_queryset:
  425. if permission.user == username:
  426. return True, True
  427. return True, False
  428. @classmethod
  429. @auto_log
  430. def get_statistics(cls, workflow_id, start_time, end_time):
  431. """
  432. 对应工单数量统计数据
  433. :param workflow_id:
  434. :param start_time:
  435. :param end_time:
  436. :return:
  437. """
  438. from django.db.models import Count
  439. query_params = {'is_deleted': 0, 'workflow_id': workflow_id}
  440. if start_time:
  441. query_params['gmt_created__gte'] = start_time
  442. if end_time:
  443. query_params['gmt_created__lte'] = end_time
  444. from apps.ticket.models import TicketRecord
  445. queryset_result = TicketRecord.objects.filter(**query_params).extra(
  446. select={'year': 'year(gmt_created)', 'month': 'month(gmt_created)', 'day': 'day(gmt_created)',
  447. 'workflow_id': 'workflow_id'}).values('year', 'month', 'day', 'workflow_id').annotate(
  448. count_len=Count('gmt_created')).order_by()
  449. result_list = []
  450. for queryset in queryset_result:
  451. date_str = '%d-%02d-%02d' % (queryset['year'], queryset['month'], queryset['day'])
  452. result_list.append(dict(day=date_str, count=queryset['count_len']))
  453. # 按日期排序
  454. result_list = sorted(result_list, key=lambda r: r['day'])
  455. return True, dict(result_list=result_list)
  456. @classmethod
  457. @auto_log
  458. def hook_host_valid_check(cls, url):
  459. """
  460. check the hook host is valid or not
  461. """
  462. try:
  463. host_allowed_list = settings.HOOK_HOST_ALLOWED
  464. except Exception as e:
  465. # 兼容历史版本,未设置该配置则允许所有
  466. return True, ''
  467. if host_allowed_list:
  468. from urllib.parse import urlparse
  469. res = urlparse(url)
  470. host = res.netloc
  471. if host in host_allowed_list:
  472. return True, ''
  473. return False, 'hook host is not allowed, please contact the administrator to alter the configure'
  474. workflow_base_service_ins = WorkflowBaseService()