Skip to content

Commit

Permalink
Merge pull request #1171 from hanshuaikang/feature/develop_by_han
Browse files Browse the repository at this point in the history
feature: 优化历史处理人无权限时的体验问题
  • Loading branch information
hanshuaikang authored Aug 17, 2023
2 parents 372fe1c + 825941c commit 4082b07
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
49 changes: 42 additions & 7 deletions itsm/ticket/models/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
WEBHOOK_STATE,
BK_PLUGIN_STATE,
SUSPENDED,
SHOW_BY_CONDITION,
)
from itsm.component.constants.trigger import (
CREATE_TICKET,
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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):
Expand Down Expand Up @@ -2531,6 +2528,44 @@ 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,
"display_value": f.display_value,
"value": f._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
Expand Down
10 changes: 8 additions & 2 deletions itsm/ticket/views/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand All @@ -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"])
Expand Down

0 comments on commit 4082b07

Please sign in to comment.