Skip to content

Commit

Permalink
feat(backend): 单据流程设置支持集群维度 TencentBlueKing#6749
Browse files Browse the repository at this point in the history
  • Loading branch information
iSecloud committed Sep 10, 2024
1 parent 4fba8d1 commit b3aaf33
Show file tree
Hide file tree
Showing 14 changed files with 453 additions and 137 deletions.
14 changes: 12 additions & 2 deletions dbm-ui/backend/iam_app/dataclass/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ class ActionEnum:
common_labels=[CommonActionLabel.BIZ_MAINTAIN],
)

TICKET_CONFIG_SET = ActionMeta(
GLOBAL_TICKET_CONFIG_SET = ActionMeta(
id="ticket_config_set",
name=_("单据流程设置"),
name=_("全局单据流程设置"),
name_en="ticket_config_set",
type="edit",
related_actions=[GLOBAL_MANAGE.id],
Expand All @@ -163,6 +163,16 @@ class ActionEnum:
hidden=True,
)

BIZ_TICKET_CONFIG_SET = ActionMeta(
id="biz_ticket_config_set",
name=_("业务单据流程设置"),
name_en="biz_ticket_config_set",
type="edit",
related_actions=[DB_MANAGE.id],
related_resource_types=[ResourceEnum.BUSINESS, ResourceEnum.DBTYPE],
group=_("业务配置"),
)

RESOURCE_MANAGE = ActionMeta(
id="resource_manage",
name=_("资源管理访问"),
Expand Down
36 changes: 35 additions & 1 deletion dbm-ui/backend/iam_app/handlers/drf_perm/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from backend.iam_app.dataclass.actions import ActionEnum
from backend.iam_app.dataclass.resources import ResourceEnum
from backend.iam_app.handlers.drf_perm.base import (
BizDBTypeResourceActionPermission,
IAMPermission,
MoreResourceActionPermission,
RejectPermission,
Expand All @@ -29,7 +30,7 @@
from backend.ticket.builders.common.base import fetch_cluster_ids
from backend.ticket.constants import TicketType
from backend.ticket.exceptions import ApprovalWrongOperatorException
from backend.ticket.models import Ticket
from backend.ticket.models import Ticket, TicketFlowsConfig
from backend.utils.basic import get_target_items_from_details

logger = logging.getLogger("root")
Expand Down Expand Up @@ -172,3 +173,36 @@ def has_permission(self, request, view):
)

return True


def ticket_flows_config_permission(action, request):
dbtype_cov = TicketType.get_db_type_by_ticket
permission: IAMPermission = None

if action in ["update_ticket_flow_config", "create_ticket_flow_config"]:
if request.data.get("bk_biz_id"):
permission = BizDBTypeResourceActionPermission(
[ActionEnum.BIZ_TICKET_CONFIG_SET],
instance_biz_getter=lambda req, view: [req.data["bk_biz_id"]],
instance_dbtype_getter=lambda req, view: list(set([dbtype_cov(d) for d in req.data["ticket_types"]])),
)
else:
permission = ResourceActionPermission(
[ActionEnum.GLOBAL_TICKET_CONFIG_SET],
ResourceEnum.DBTYPE,
instance_ids_getter=lambda req, view: [req.data["bk_biz_id"]],
)
elif action == "delete_ticket_flow_config":
configs = list(TicketFlowsConfig.objects.filter(id__in=request.data["config_ids"]))
groups, bk_biz_ids = [c.group for c in configs], [c.bk_biz_id for c in configs]
# 只允许一个业务下的一种db类型
if len(set(groups)) > 1 or len(set(bk_biz_ids)) > 1:
permission = RejectPermission()
else:
permission = BizDBTypeResourceActionPermission(
[ActionEnum.BIZ_TICKET_CONFIG_SET],
instance_biz_getter=lambda req, view: bk_biz_ids,
instance_dbtype_getter=lambda req, view: groups,
)

return [permission]
9 changes: 4 additions & 5 deletions dbm-ui/backend/iam_app/handlers/permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,10 @@ def insert_external_permission_field(
)

# 填充权限字段
if isinstance(response.data, list):
response.data = [{"permission": permission_result, **d} for d in response.data]
elif isinstance(response.data, dict):
response.data.setdefault("permission", {})
response.data["permission"].update(permission_result)
data_list = response.data if isinstance(response.data, list) else [response.data]
for data in data_list:
data.setdefault("permission", {})
data["permission"].update(permission_result)

return response

Expand Down
202 changes: 143 additions & 59 deletions dbm-ui/backend/iam_app/migration_json_files/initial.json
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@
"operation": "upsert_action",
"data": {
"id": "ticket_config_set",
"name": "单据流程设置",
"name": "全局单据流程设置",
"name_en": "ticket_config_set",
"type": "edit",
"related_resource_types": [
Expand All @@ -1038,10 +1038,52 @@
"hidden": true,
"group": "全局设置",
"subgroup": "",
"description": "单据流程设置",
"description": "全局单据流程设置",
"description_en": "ticket_config_set"
}
},
{
"operation": "upsert_action",
"data": {
"id": "biz_ticket_config_set",
"name": "业务单据流程设置",
"name_en": "biz_ticket_config_set",
"type": "edit",
"related_resource_types": [
{
"system_id": "bk_cmdb",
"id": "biz",
"selection_mode": "instance",
"related_instance_selections": [
{
"system_id": "bk_cmdb",
"id": "business"
}
]
},
{
"system_id": "bk_dbm",
"id": "dbtype",
"selection_mode": "instance",
"related_instance_selections": [
{
"system_id": "bk_dbm",
"id": "dbtype_list"
}
]
}
],
"related_actions": [
"db_manage"
],
"version": 1,
"hidden": false,
"group": "业务配置",
"subgroup": "",
"description": "业务单据流程设置",
"description_en": "biz_ticket_config_set"
}
},
{
"operation": "upsert_action",
"data": {
Expand Down Expand Up @@ -6827,7 +6869,7 @@
"operation": "upsert_action",
"data": {
"id": "tendbcluster_data_migrate",
"name": "TenDB Cluster 数据迁移",
"name": "TenDB Cluster DB克隆",
"name_en": "TENDBCLUSTER_DATA_MIGRATE",
"type": "execute",
"related_resource_types": [
Expand All @@ -6848,7 +6890,7 @@
"hidden": false,
"group": "TenDBCluster",
"subgroup": "数据处理",
"description": "TenDB Cluster 数据迁移",
"description": "TenDB Cluster DB克隆",
"description_en": "TENDBCLUSTER_DATA_MIGRATE"
}
},
Expand Down Expand Up @@ -7174,9 +7216,38 @@
{
"operation": "upsert_action",
"data": {
"id": "sqlserver_data_migrate",
"name": "SQLServer 数据迁移",
"name_en": "SQLSERVER_DATA_MIGRATE",
"id": "sqlserver_full_migrate",
"name": "SQLServer 全备迁移",
"name_en": "SQLSERVER_FULL_MIGRATE",
"type": "execute",
"related_resource_types": [
{
"system_id": "bk_dbm",
"id": "sqlserver",
"selection_mode": "all",
"related_instance_selections": [
{
"system_id": "bk_dbm",
"id": "sqlserver_list"
}
]
}
],
"related_actions": [],
"version": 1,
"hidden": false,
"group": "SQLServer",
"subgroup": "数据处理",
"description": "SQLServer 全备迁移",
"description_en": "SQLSERVER_FULL_MIGRATE"
}
},
{
"operation": "upsert_action",
"data": {
"id": "sqlserver_incr_migrate",
"name": "SQLServer 增量迁移",
"name_en": "SQLSERVER_INCR_MIGRATE",
"type": "execute",
"related_resource_types": [
{
Expand All @@ -7196,8 +7267,8 @@
"hidden": false,
"group": "SQLServer",
"subgroup": "数据处理",
"description": "SQLServer 数据迁移",
"description_en": "SQLSERVER_DATA_MIGRATE"
"description": "SQLServer 增量迁移",
"description_en": "SQLSERVER_INCR_MIGRATE"
}
},
{
Expand Down Expand Up @@ -9708,57 +9779,13 @@
}
]
},
{
"name": "资源管理",
"name_en": "资源管理",
"actions": [
{
"id": "resource_manage"
}
],
"sub_groups": [
{
"name": "资源池",
"name_en": "资源池",
"actions": [
{
"id": "resource_pool_manage"
},
{
"id": "resource_operation_view"
}
]
},
{
"name": "污点池",
"name_en": "污点池",
"actions": [
{
"id": "dirty_pool_manage"
}
]
},
{
"name": "资源规格",
"name_en": "资源规格",
"actions": [
{
"id": "spec_create"
},
{
"id": "spec_update"
},
{
"id": "spec_delete"
}
]
}
]
},
{
"name": "业务配置",
"name_en": "业务配置",
"actions": [
{
"id": "biz_ticket_config_set"
},
{
"id": "dba_administrator_edit"
},
Expand Down Expand Up @@ -9820,6 +9847,53 @@
}
]
},
{
"name": "资源管理",
"name_en": "资源管理",
"actions": [
{
"id": "resource_manage"
}
],
"sub_groups": [
{
"name": "资源池",
"name_en": "资源池",
"actions": [
{
"id": "resource_pool_manage"
},
{
"id": "resource_operation_view"
}
]
},
{
"name": "污点池",
"name_en": "污点池",
"actions": [
{
"id": "dirty_pool_manage"
}
]
},
{
"name": "资源规格",
"name_en": "资源规格",
"actions": [
{
"id": "spec_create"
},
{
"id": "spec_update"
},
{
"id": "spec_delete"
}
]
}
]
},
{
"name": "MySQL",
"name_en": "MySQL",
Expand Down Expand Up @@ -10824,7 +10898,10 @@
"id": "sqlserver_clear_dbs"
},
{
"id": "sqlserver_data_migrate"
"id": "sqlserver_full_migrate"
},
{
"id": "sqlserver_incr_migrate"
},
{
"id": "sqlserver_rollback"
Expand Down Expand Up @@ -11527,7 +11604,10 @@
"id": "sqlserver_reset"
},
{
"id": "sqlserver_data_migrate"
"id": "sqlserver_full_migrate"
},
{
"id": "sqlserver_incr_migrate"
},
{
"id": "sqlserver_rollback"
Expand Down Expand Up @@ -12830,7 +12910,11 @@
"required": true
},
{
"id": "sqlserver_data_migrate",
"id": "sqlserver_full_migrate",
"required": true
},
{
"id": "sqlserver_incr_migrate",
"required": true
},
{
Expand Down
Loading

0 comments on commit b3aaf33

Please sign in to comment.