完善组织树操作与空响应处理
This commit is contained in:
@@ -85,7 +85,10 @@ MENU_PERMISSION_TREE = [
|
||||
ORG_ROOT_CODE = "ORG_ROOT"
|
||||
ORG_ROOT_NAME = "总公司"
|
||||
VALID_CHILD_NODE_TYPES = {
|
||||
"COMPANY": {"BRANCH": "总公司下只能新增分公司"},
|
||||
"COMPANY": {
|
||||
"BRANCH": "总公司下只能新增分公司或直属部门",
|
||||
"DEPARTMENT": "总公司下只能新增分公司或直属部门",
|
||||
},
|
||||
"BRANCH": {"DEPARTMENT": "分公司下只能新增部门"},
|
||||
"DEPARTMENT": {"GROUP": "部门下只能新增小组"},
|
||||
"GROUP": {},
|
||||
|
||||
@@ -398,6 +398,32 @@ class SystemPermissionManagementTest(unittest.TestCase):
|
||||
self.assertEqual(tree[0].children[0].parent_id, self.company.id)
|
||||
self.assertEqual(tree[0].children[0].node_type, "BRANCH")
|
||||
|
||||
def test_create_org_node_allows_company_direct_department(self) -> None:
|
||||
from app.schemas.system_permissions import OrgNodeCreate
|
||||
from app.services.system_permissions import create_org_node, build_org_tree
|
||||
|
||||
direct_department = create_org_node(
|
||||
self.db,
|
||||
OrgNodeCreate(
|
||||
parent_id=self.company.id,
|
||||
node_type="DEPARTMENT",
|
||||
node_label="总公司直属部门",
|
||||
dept_code="DIRECT-DEPT",
|
||||
dept_type="ADMIN",
|
||||
manager_employee_id=None,
|
||||
sort_no=1,
|
||||
remark=None,
|
||||
status="ACTIVE",
|
||||
),
|
||||
)
|
||||
|
||||
tree = build_org_tree(self.db)
|
||||
self.assertEqual(direct_department.parent_id, self.company.id)
|
||||
self.assertEqual(direct_department.node_type, "DEPARTMENT")
|
||||
self.assertTrue(
|
||||
any(child.node_label == "总公司直属部门" and child.node_type == "DEPARTMENT" for child in tree[0].children)
|
||||
)
|
||||
|
||||
def test_create_org_node_rejects_invalid_child_level(self) -> None:
|
||||
from fastapi import HTTPException
|
||||
from app.schemas.system_permissions import OrgNodeCreate
|
||||
@@ -408,9 +434,9 @@ class SystemPermissionManagementTest(unittest.TestCase):
|
||||
self.db,
|
||||
OrgNodeCreate(
|
||||
parent_id=self.company.id,
|
||||
node_type="DEPARTMENT",
|
||||
node_label="错误部门",
|
||||
dept_code="BAD-DEPT",
|
||||
node_type="GROUP",
|
||||
node_label="错误小组",
|
||||
dept_code="BAD-GROUP",
|
||||
dept_type="ADMIN",
|
||||
manager_employee_id=None,
|
||||
sort_no=1,
|
||||
@@ -419,7 +445,7 @@ class SystemPermissionManagementTest(unittest.TestCase):
|
||||
),
|
||||
)
|
||||
self.assertEqual(ctx.exception.status_code, 400)
|
||||
self.assertIn("总公司下只能新增分公司", str(ctx.exception.detail))
|
||||
self.assertIn("总公司下只能新增分公司或直属部门", str(ctx.exception.detail))
|
||||
|
||||
def test_delete_org_node_rejects_nodes_with_children_or_bound_employees(self) -> None:
|
||||
from fastapi import HTTPException
|
||||
|
||||
Reference in New Issue
Block a user