diff --git a/apiserver/paasng/paasng/bk_plugins/pluginscenter/itsm_adaptor/utils.py b/apiserver/paasng/paasng/bk_plugins/pluginscenter/itsm_adaptor/utils.py index 077fccf558..6b756434d3 100644 --- a/apiserver/paasng/paasng/bk_plugins/pluginscenter/itsm_adaptor/utils.py +++ b/apiserver/paasng/paasng/bk_plugins/pluginscenter/itsm_adaptor/utils.py @@ -37,6 +37,7 @@ PluginRelease, PluginVisibleRange, ) +from paasng.bk_plugins.pluginscenter.models.instances import is_release_strategy_organization_changed if typing.TYPE_CHECKING: from paasng.bk_plugins.pluginscenter.models.instances import ItsmDetail @@ -58,7 +59,7 @@ def submit_create_approval_ticket(pd: PluginDefinition, plugin: PluginInstance, # 组装提单数据,包含插件的基本信息 basic_fields = _get_basic_fields(pd, plugin) - title_fields = [{"key": "title", "value": f"插件[{plugin.id}]创建审批"}] + title_fields = [{"key": "title", "value": f"插件[{plugin.name}]创建审批"}] fields = basic_fields + title_fields # 提交 itsm 申请单据 @@ -80,7 +81,7 @@ def submit_online_approval_ticket(pd: PluginDefinition, plugin: PluginInstance, # 组装提单数据,包含插件的基本信息和版本信息 basic_fields = _get_basic_fields(pd, plugin) advanced_fields = _get_advanced_fields(pd, plugin, version) - title_fields = [{"key": "title", "value": f"插件[{plugin.id}]上线审批"}] + title_fields = [{"key": "title", "value": f"插件[{plugin.name}]上线审批"}] fields = basic_fields + advanced_fields + title_fields # 查询上线审批服务ID @@ -131,11 +132,12 @@ def submit_canary_release_ticket( # 组装提单数据,包含插件的基本信息和灰度发布信息 basic_fields = _get_basic_fields(pd, plugin) - title_fields = [{"key": "title", "value": f"插件[{plugin.id}]灰度发布审批"}] + title_fields = [{"key": "title", "value": f"插件[{plugin.name}]灰度发布审批"}] itsm_fields = basic_fields + title_fields + canary_fields - service_name = release_strategy.get_itsm_service_name() + service_name = release_strategy.get_itsm_service_name(is_release_strategy_organization_changed(version)) service_id = ApprovalService.objects.get(service_name=service_name).service_id + # 灰度审批是由插件的管理员审批,需要单独添加审批字段 if release_strategy.strategy == ReleaseStrategy.GRAY: plugin_admins = members_api.fetch_role_members(plugin, PluginRole.ADMINISTRATOR) @@ -196,7 +198,7 @@ def submit_visible_range_ticket( # 组装提单数据,包含插件的基本信息、可见范围修改前的值,修改后的值 basic_fields = _get_basic_fields(pd, plugin) - title_fields = [{"key": "title", "value": f"插件[{plugin.id}]可见范围修改审批"}] + title_fields = [{"key": "title", "value": f"插件[{plugin.name}]可见范围修改审批"}] fields = basic_fields + title_fields + visible_range_fields # 提交 itsm 申请单据 diff --git a/apiserver/paasng/paasng/bk_plugins/pluginscenter/models/instances.py b/apiserver/paasng/paasng/bk_plugins/pluginscenter/models/instances.py index 4109b6978b..b915705fa3 100644 --- a/apiserver/paasng/paasng/bk_plugins/pluginscenter/models/instances.py +++ b/apiserver/paasng/paasng/bk_plugins/pluginscenter/models/instances.py @@ -403,12 +403,13 @@ class PluginReleaseStrategy(AuditedModel): organization = models.JSONField(verbose_name="组织架构", blank=True, null=True) itsm_detail: Optional[ItsmDetail] = ItsmDetailField(default=None, null=True) - def get_itsm_service_name(self): + def get_itsm_service_name(self, is_organization_changed: bool) -> str: """根据发布策略的设置获取对应的 ITSM 审批流程""" if self.strategy == constants.ReleaseStrategy.FULL: return ApprovalServiceName.CODECC_FULL_RELEASE_APPROVAL - if self.organization: + # 灰度范围包括了组织且组织信息变更了,则需要上级审批 + if self.organization and is_organization_changed: return ApprovalServiceName.CODECC_ORG_GRAY_RELEASE_APPROVAL return ApprovalServiceName.CODECC_GRAY_RELEASE_APPROVAL @@ -519,3 +520,26 @@ def get_display_text(self): if self.specific: return f"{username} {action_text} {self.specific} {subject_text}" return f"{username} {action_text}{subject_text}" + + +def is_release_strategy_organization_changed(release: PluginRelease) -> bool: + """检查发布策略的组织是否变更""" + + # 如果没有最新的发布策略,返回 True + latest_release_strategy = release.latest_release_strategy + if not latest_release_strategy: + return True + + # 找到倒数第二的发布策略 + try: + second_release_strategy = release.release_strategies.exclude(id=latest_release_strategy.id).latest("created") + except release.release_strategies.model.DoesNotExist: + # 如果找不到倒数第二个策略,返回 True + return True + + # 获取两个发布策略的组织 ID 集合 + latest_org_ids = {s["id"] for s in latest_release_strategy.organization} + second_org_ids = {s["id"] for s in second_release_strategy.organization} + + # 前后两个组织的 ID 不完全相等 + return latest_org_ids != second_org_ids