From 224bb6c6bbb2a0e5735389914a37435ab0faa145 Mon Sep 17 00:00:00 2001 From: "hu.sima" Date: Wed, 3 Jan 2024 14:24:31 +0800 Subject: [PATCH 1/2] fix(api): common department edit method --- cmdb-api/api/lib/common_setting/department.py | 10 +++++++++- cmdb-api/api/views/common_setting/department.py | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cmdb-api/api/lib/common_setting/department.py b/cmdb-api/api/lib/common_setting/department.py index 9d117857..fe8c782c 100644 --- a/cmdb-api/api/lib/common_setting/department.py +++ b/cmdb-api/api/lib/common_setting/department.py @@ -24,7 +24,15 @@ def get_all_department_list(to_dict=True): *criterion ).order_by(Department.department_id.asc()) results = query.all() - return [r.to_dict() for r in results] if to_dict else results + if to_dict: + datas = [] + for r in results: + d = r.to_dict() + if r.department_id == 0: + d['department_name'] = ErrFormat.company_wide + datas.append(d) + return datas + return results def get_all_employee_list(block=0, to_dict=True): diff --git a/cmdb-api/api/views/common_setting/department.py b/cmdb-api/api/views/common_setting/department.py index 9a8dd4a7..7e3d4c81 100644 --- a/cmdb-api/api/views/common_setting/department.py +++ b/cmdb-api/api/views/common_setting/department.py @@ -85,7 +85,7 @@ def delete(self, _id): class DepartmentParentView(APIView): url_prefix = (f'{prefix}/allow_parent',) - def get(self): + def put(self): department_id = request.args.get('department_id', None) if department_id is None: abort(400, ErrFormat.department_id_is_required) From cdbab0da3dedb573fe2ed686201e8a0782d076ad Mon Sep 17 00:00:00 2001 From: "hu.sima" Date: Wed, 3 Jan 2024 14:30:01 +0800 Subject: [PATCH 2/2] fix(api): common department edit method --- cmdb-api/api/views/common_setting/department.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmdb-api/api/views/common_setting/department.py b/cmdb-api/api/views/common_setting/department.py index 7e3d4c81..ba4091a0 100644 --- a/cmdb-api/api/views/common_setting/department.py +++ b/cmdb-api/api/views/common_setting/department.py @@ -62,7 +62,7 @@ def post(self): class DepartmentIDView(APIView): url_prefix = (f'{prefix}/',) - def get(self, _id): + def put(self, _id): form = DepartmentForm(MultiDict(request.json)) if not form.validate(): abort(400, ','.join(['{}: {}'.format(filed, ','.join(msg)) @@ -85,7 +85,7 @@ def delete(self, _id): class DepartmentParentView(APIView): url_prefix = (f'{prefix}/allow_parent',) - def put(self): + def get(self): department_id = request.args.get('department_id', None) if department_id is None: abort(400, ErrFormat.department_id_is_required)