feat(permission): replace OA roles with post-bound roles and assignee posts
Unify effective roles via post-role bindings, remove dedicated OA role UI, and update OA assignee resolution plus related SQL/docs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
a3c73d76bb
commit
06db3bc966
66 files changed
+55337
-38647
No files matched your search
@@ -0,0 +1,16 @@
|
||||
"""有效角色解析:直接角色 ∪ 职位继承角色(纯逻辑断言,无 DB 依赖部分)。"""
|
||||
from app.services.web_auth_roles import _map_role_name_to_web, NO_ROLE_WEB_ROLE
|
||||
|
||||
|
||||
def test_map_role_name_super_admin():
|
||||
assert _map_role_name_to_web("超级管理员") == "super_admin"
|
||||
assert _map_role_name_to_web("系统管理员") == "super_admin"
|
||||
|
||||
|
||||
def test_map_role_name_admin_default():
|
||||
assert _map_role_name_to_web("质检员") == "admin"
|
||||
assert _map_role_name_to_web("") == "admin"
|
||||
|
||||
|
||||
def test_guest_constant():
|
||||
assert NO_ROLE_WEB_ROLE == "guest"
|
||||
@@ -82,10 +82,10 @@ class TestOaAssignee(unittest.TestCase):
|
||||
advanced={"supervisorFallbackToDeptLeader": False},
|
||||
)
|
||||
|
||||
def test_oa_role_gm(self):
|
||||
def test_posts_resolve(self):
|
||||
db = MagicMock()
|
||||
with patch(
|
||||
"app.services.oa_assignee.oa_crud.list_oa_role_user_ids",
|
||||
"app.services.oa_assignee.user_crud.list_user_ids_bound_to_posts",
|
||||
return_value=["gm_user", "inactive"],
|
||||
), patch(
|
||||
"app.services.oa_assignee._active_user_id",
|
||||
@@ -94,17 +94,17 @@ class TestOaAssignee(unittest.TestCase):
|
||||
users, meta = resolve_assignees(
|
||||
db,
|
||||
tenant_no="zkxw",
|
||||
assignee_config={"assigneeType": "oa_roles", "oaRoleIds": ["gm_role_id"]},
|
||||
assignee_config={"assigneeType": "posts", "postIds": ["post_gm"]},
|
||||
initiator_user_id="zhang",
|
||||
)
|
||||
self.assertEqual(users, ["gm_user"])
|
||||
self.assertEqual(meta.get("resolve_source"), "oa_roles")
|
||||
self.assertEqual(meta.get("resolve_source"), "posts")
|
||||
|
||||
def test_never_reads_sys_role(self):
|
||||
db = MagicMock()
|
||||
with patch(
|
||||
"app.services.oa_assignee.oa_crud.list_oa_role_user_ids",
|
||||
return_value=["oa_only"],
|
||||
"app.services.oa_assignee.user_crud.list_user_ids_bound_to_posts",
|
||||
return_value=["post_only"],
|
||||
) as mock_list, patch(
|
||||
"app.services.oa_assignee._active_user_id",
|
||||
side_effect=lambda _db, uid, _tn: uid,
|
||||
@@ -112,12 +112,11 @@ class TestOaAssignee(unittest.TestCase):
|
||||
users, _meta = resolve_assignees(
|
||||
db,
|
||||
tenant_no="zkxw",
|
||||
assignee_config={"assigneeType": "oa_roles", "oaRoleIds": ["r1"]},
|
||||
assignee_config={"assigneeType": "posts", "postIds": ["p1"]},
|
||||
initiator_user_id="zhang",
|
||||
)
|
||||
self.assertEqual(users, ["oa_only"])
|
||||
self.assertEqual(users, ["post_only"])
|
||||
mock_list.assert_called_once()
|
||||
# 业务路径不得查询 sys_role
|
||||
for call in db.query.call_args_list:
|
||||
args = call[0] if call[0] else ()
|
||||
for a in args:
|
||||
@@ -139,7 +138,7 @@ class TestOaAssignee(unittest.TestCase):
|
||||
def test_normalize_prefers_assignee_types(self):
|
||||
self.assertEqual(
|
||||
normalize_cc_assignee_types(
|
||||
{"assigneeTypes": ["users", "dept_leader", "users", "bad"], "assigneeType": "oa_roles"}
|
||||
{"assigneeTypes": ["users", "dept_leader", "users", "bad"], "assigneeType": "posts"}
|
||||
),
|
||||
["users", "dept_leader"],
|
||||
)
|
||||
|
||||
@@ -192,7 +192,7 @@ class TestOaPublishValidate(unittest.TestCase):
|
||||
def test_draft_requires_fillable_and_assignee(self):
|
||||
db = MagicMock()
|
||||
with patch(
|
||||
"app.services.oa_publish.validate_oa_roles_referenced",
|
||||
"app.services.oa_publish.validate_posts_referenced",
|
||||
return_value=[],
|
||||
):
|
||||
errs = validate_draft_for_publish(
|
||||
@@ -214,7 +214,7 @@ class TestOaPublishValidate(unittest.TestCase):
|
||||
def test_valid_draft_passes_form_and_flow(self):
|
||||
db = MagicMock()
|
||||
with patch(
|
||||
"app.services.oa_publish.validate_oa_roles_referenced",
|
||||
"app.services.oa_publish.validate_posts_referenced",
|
||||
return_value=[],
|
||||
):
|
||||
errs = validate_draft_for_publish(
|
||||
@@ -264,7 +264,7 @@ class TestConditionPublish(unittest.TestCase):
|
||||
def test_invalid_field_reference(self):
|
||||
db = MagicMock()
|
||||
with patch(
|
||||
"app.services.oa_publish.validate_oa_roles_referenced",
|
||||
"app.services.oa_publish.validate_posts_referenced",
|
||||
return_value=[],
|
||||
):
|
||||
errs = validate_draft_for_publish(
|
||||
@@ -290,7 +290,7 @@ class TestConditionPublish(unittest.TestCase):
|
||||
def test_field_not_flagged_rejected(self):
|
||||
db = MagicMock()
|
||||
with patch(
|
||||
"app.services.oa_publish.validate_oa_roles_referenced",
|
||||
"app.services.oa_publish.validate_posts_referenced",
|
||||
return_value=[],
|
||||
):
|
||||
errs = validate_draft_for_publish(
|
||||
|
||||
Reference in new issue
Block a user