Skip to content

Commit fc6fe66

Browse files
committed
fix(backend): 去掉超管对待审批、待执行的确认权限 #8883
1 parent 1b11a0a commit fc6fe66

File tree

6 files changed

+25
-70
lines changed

6 files changed

+25
-70
lines changed

dbm-ui/backend/db_meta/enums/spec.py

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -54,70 +54,3 @@ class SpecMachineType(str, StructuredEnum):
5454
DORIS_FOLLOWER = EnumField("doris_follower", _("doris_follower"))
5555
DORIS_OBSERVER = EnumField("doris_observer", _("doris_observer"))
5656
DORIS_BACKEND = EnumField("doris_backend", _("doris_backend"))
57-
58-
59-
# TODO: 规格迁移脚本函数,迁移完成后删除
60-
def migrate_spec():
61-
from django.db import transaction
62-
63-
from backend.configuration.constants import DBType
64-
from backend.db_meta.enums import ClusterType, MachineType
65-
from backend.db_meta.models.spec import Spec
66-
67-
# 原规格层级和新规格层级的映射
68-
MIGRATE_SPEC_MACHINE_MAP = {
69-
MachineType.SINGLE: SpecMachineType.BACKEND,
70-
MachineType.BACKEND: SpecMachineType.BACKEND,
71-
MachineType.PROXY: SpecMachineType.PROXY,
72-
MachineType.SPIDER: SpecMachineType.PROXY,
73-
MachineType.REMOTE: SpecMachineType.BACKEND,
74-
ClusterType.TendisTwemproxyRedisInstance: {
75-
MachineType.TENDISCACHE: SpecMachineType.TendisTwemproxyRedisInstance,
76-
MachineType.TWEMPROXY: SpecMachineType.PROXY,
77-
},
78-
ClusterType.TwemproxyTendisSSDInstance: {
79-
MachineType.TENDISSSD: SpecMachineType.TwemproxyTendisSSDInstance,
80-
MachineType.TWEMPROXY: SpecMachineType.PROXY,
81-
},
82-
ClusterType.TendisPredixyTendisplusCluster: {
83-
MachineType.TENDISPLUS: SpecMachineType.TendisPredixyTendisplusCluster,
84-
MachineType.PREDIXY: SpecMachineType.PROXY,
85-
},
86-
ClusterType.TendisPredixyRedisCluster: {
87-
MachineType.TENDISCACHE: SpecMachineType.TendisTwemproxyRedisInstance,
88-
MachineType.PREDIXY: SpecMachineType.PROXY,
89-
},
90-
ClusterType.TendisRedisInstance: {
91-
MachineType.TENDISCACHE: SpecMachineType.TendisTwemproxyRedisInstance,
92-
},
93-
MachineType.SQLSERVER_HA: SpecMachineType.SQLSERVER,
94-
MachineType.SQLSERVER_SINGLE: SpecMachineType.SQLSERVER,
95-
MachineType.MONGOS: SpecMachineType.MONGOS,
96-
MachineType.MONGODB: SpecMachineType.MONGODB,
97-
MachineType.MONOG_CONFIG: SpecMachineType.MONOG_CONFIG,
98-
}
99-
100-
specs = Spec.objects.all()
101-
with transaction.atomic():
102-
for spec in specs:
103-
db_type = ClusterType.cluster_type_to_db_type(spec.spec_cluster_type)
104-
if db_type in [
105-
DBType.Es,
106-
DBType.Kafka,
107-
DBType.Hdfs,
108-
DBType.InfluxDB,
109-
DBType.Pulsar,
110-
DBType.Vm,
111-
DBType.Doris,
112-
DBType.Riak,
113-
]:
114-
continue
115-
116-
if db_type == DBType.Redis:
117-
spec.spec_machine_type = MIGRATE_SPEC_MACHINE_MAP[spec.spec_cluster_type][spec.spec_machine_type]
118-
spec.spec_cluster_type = db_type
119-
spec.save()
120-
else:
121-
spec.spec_machine_type = MIGRATE_SPEC_MACHINE_MAP[spec.spec_machine_type]
122-
spec.spec_cluster_type = db_type
123-
spec.save()

dbm-ui/backend/db_services/dbbase/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class QueryClusterInstanceCountSerializer(serializers.Serializer):
205205

206206
class QueryClusterCapSerializer(serializers.Serializer):
207207
bk_biz_id = serializers.IntegerField(help_text=_("业务ID"))
208-
cluster_type = serializers.ChoiceField(help_text=_("集群类型"), choices=ClusterType.get_choices())
208+
cluster_type = serializers.CharField(help_text=_("集群类型(多个以逗号分隔)"))
209209

210210

211211
class QueryClusterCapResponseSerializer(serializers.Serializer):

dbm-ui/backend/db_services/dbbase/views.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,5 +398,12 @@ def query_cluster_stat(self, request, *args, **kwargs):
398398
from backend.db_periodic_task.local_tasks.db_meta.sync_cluster_stat import sync_cluster_stat_by_cluster_type
399399

400400
data = self.params_validate(self.get_serializer_class())
401-
cluster_stat_map = sync_cluster_stat_by_cluster_type(data["bk_biz_id"], data["cluster_type"])
401+
cluster_stat_map = {}
402+
for cluster_type in data["cluster_type"].split(","):
403+
cluster_stat_map.update(sync_cluster_stat_by_cluster_type(data["bk_biz_id"], cluster_type))
404+
405+
cluster_domain_qs = Cluster.objects.filter(bk_biz_id=3).values("immute_domain", "id")
406+
cluster_domain_map = {cluster["immute_domain"]: cluster["id"] for cluster in cluster_domain_qs}
407+
cluster_stat_map = {cluster_domain_map[domain]: cap for domain, cap in cluster_stat_map.items()}
408+
402409
return Response(cluster_stat_map)

dbm-ui/backend/ticket/todos/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ def update_context(self, params):
4747
self.todo.context.update(remark=params["remark"])
4848
self.todo.save(update_fields=["context"])
4949

50+
@property
51+
def allow_superuser_process(self):
52+
# 是否允许超管操作,默认允许.
53+
return True
54+
5055
def process(self, username, action, params):
5156
# 当状态已经被确认,则不允许重复操作
5257
if self.todo.status not in TODO_RUNNING_STATUS:
@@ -57,7 +62,7 @@ def process(self, username, action, params):
5762
self._process(username, action, params)
5863
return
5964
# 允许超级用户和操作人确认
60-
is_superuser = User.objects.get(username=username).is_superuser
65+
is_superuser = User.objects.get(username=username).is_superuser and self.allow_superuser_process
6166
if not is_superuser and username not in self.todo.operators:
6267
raise TodoWrongOperatorException(_("{}不在处理人: {}中,无法处理").format(username, self.todo.operators))
6368

dbm-ui/backend/ticket/todos/itsm_todo.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class ItsmTodoContext(BaseTodoContext):
2828
class ItsmTodo(todos.TodoActor):
2929
"""来自审批中的待办"""
3030

31+
@property
32+
def allow_superuser_process(self):
33+
# 单据未执行前(待审批、待执行时)超管不拥有特权。规避超管误点的风险
34+
return False
35+
3136
def process(self, username, action, params):
3237
# itsm的todo允许本人操作
3338
if username == self.todo.ticket.creator and self.todo.status in TODO_RUNNING_STATUS:

dbm-ui/backend/ticket/todos/pause_todo.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class ResourceReplenishTodoContext(BaseTodoContext):
3232
class PauseTodo(todos.TodoActor):
3333
"""来自主流程的待办"""
3434

35+
@property
36+
def allow_superuser_process(self):
37+
# 单据未执行前(待审批、待执行时)超管不拥有特权。规避超管误点的风险
38+
return False
39+
3540
def _process(self, username, action, params):
3641
"""确认/终止"""
3742
if action == ActionType.TERMINATE:

0 commit comments

Comments
 (0)