From a26927abe56a593fb481ceb353b6117156f5f43e Mon Sep 17 00:00:00 2001 From: hanshuaikang <1758504262@qq.com> Date: Thu, 17 Aug 2023 15:18:41 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feature:=20=E4=BC=98=E5=8C=96=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E5=A4=84=E7=90=86=E4=BA=BA=E6=97=A0=E6=9D=83=E9=99=90?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E4=BD=93=E9=AA=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- itsm/ticket/models/ticket.py | 48 ++++++++++++++++++++++++++++++------ itsm/ticket/views/ticket.py | 10 ++++++-- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/itsm/ticket/models/ticket.py b/itsm/ticket/models/ticket.py index 8b557322a..ed12b5d8f 100644 --- a/itsm/ticket/models/ticket.py +++ b/itsm/ticket/models/ticket.py @@ -140,6 +140,7 @@ WEBHOOK_STATE, BK_PLUGIN_STATE, SUSPENDED, + SHOW_BY_CONDITION, ) from itsm.component.constants.trigger import ( CREATE_TICKET, @@ -156,7 +157,6 @@ GLOBAL_LEAVE_STATE, GLOBAL_ENTER_STATE, ) -from common.shortuuid import uuid as _uu from itsm.component.utils.client_backend_query import ( get_user_leader, get_user_departments, @@ -181,6 +181,7 @@ conditions_conversion, rsp_conversion, build_conditions_by_mako_template, + show_conditions_validate, ) from itsm.component.utils.graph import dfs_paths from itsm.component.utils.misc import transform_single_username, transform_username @@ -1533,7 +1534,6 @@ def pc_ticket_url(self): ) def generate_ticket_url(self, state_id, receivers): - cache_key = _uu() status = Status.objects.filter(ticket_id=self.id, state_id=state_id).first() if not status: logger.info( @@ -1552,16 +1552,13 @@ def generate_ticket_url(self, state_id, receivers): "state_id": state_id, } ) - client = Cache() - self.notify_url = "{site_url}/#/ticket/{ticket_id}/?token={token}&cache_key={cache_key}&step_id={step_id}".format( # noqa + self.notify_url = "{site_url}/#/ticket/{ticket_id}/?token={token}&step_id={step_id}".format( + # noqa site_url=settings.TICKET_NOTIFY_HOST.rstrip("/"), ticket_id=self.id, token=ticket_token, - cache_key=cache_key, step_id=status.id, ) - data = json.dumps({"state_id": state_id, "ticket_id": self.id}) - client.set(cache_key, data, 60 * 60 * 24 * 30) @property def service_type_name(self): @@ -2531,6 +2528,43 @@ def get_state_fields(self, state_id, need_serialize=True): return fields + def get_ticket_detail(self): + fields = [] + + state_fields = self.get_state_fields(self.first_state_id, need_serialize=False) + # 隐藏字段过滤 + for f in state_fields: + if f.show_type == SHOW_BY_CONDITION: + key_value = { + "params_%s" + % item["key"]: format_exp_value(item["type"], item["_value"]) + for item in self.fields.values("key", "_value", "type") + } + if show_conditions_validate(f.show_conditions, key_value): + continue + + fields.append( + { + "id": f.id, + "key": f.key, + "name": f.name, + "choice": f.choice, + "type": f.type, + "value": f.display_value, + } + ) + + detail = { + "title": self.title, + "sn": self.sn, + "creator": self.creator, + "current_status": self.current_status, + "create_at": self.create_at, + "fields": fields, + } + + return detail + def activity_for_state(self, state_id): """ 将state_id转换为pipeline的节点id diff --git a/itsm/ticket/views/ticket.py b/itsm/ticket/views/ticket.py index 41a710a9a..bee8bdaeb 100644 --- a/itsm/ticket/views/ticket.py +++ b/itsm/ticket/views/ticket.py @@ -1687,7 +1687,7 @@ def table_fields(self, request, *args, **kwargs): return Response(FieldSerializer(ticket.table_fields(), many=True).data) @action(detail=True, methods=["get"]) - def is_processor(self, request, *args, **kwargs): + def get_step_process_info(self, request, *args, **kwargs): ticket = self.get_object() step_id = request.query_params.get("step_id", None) processed_user = "" @@ -1701,8 +1701,14 @@ def is_processor(self, request, *args, **kwargs): processed_user = status.processed_user break + detail = ticket.get_ticket_detail() if is_processor else None + return Response( - {"is_processor": is_processor, "processed_user": processed_user} + { + "is_processor": is_processor, + "processed_user": processed_user, + "detail": detail, + } ) @action(detail=True, methods=["post"]) From 825941c8581f69a65e80ac5f4fd9e58000cbed21 Mon Sep 17 00:00:00 2001 From: hanshuaikang <1758504262@qq.com> Date: Thu, 17 Aug 2023 17:34:18 +0800 Subject: [PATCH 2/2] =?UTF-8?q?minor:=20value=20=E6=9B=B4=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=20display=5Fvalue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- itsm/ticket/models/ticket.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/itsm/ticket/models/ticket.py b/itsm/ticket/models/ticket.py index ed12b5d8f..0135dcfd1 100644 --- a/itsm/ticket/models/ticket.py +++ b/itsm/ticket/models/ticket.py @@ -2550,7 +2550,8 @@ def get_ticket_detail(self): "name": f.name, "choice": f.choice, "type": f.type, - "value": f.display_value, + "display_value": f.display_value, + "value": f._value, } )