Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:申请加入用户组时,二级资源拥有者离职,上升到一级管理员审批 #2838

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion saas/backend/biz/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ def get_grade_manager_members_by_group_id(self, group_id: int) -> str:
"""获取分级管理员"""
return self.svc.get_role_by_group_id(group_id).members

@cachedmethod(timeout=60) # 缓存1分钟
def get_grade_or_parent_manager_members_by_group_id(self, group_id: int) -> List[str]:
"""获取分级管理员,如果为空,获取父级管理员"""
return self.svc.get_role_parent_member_by_group_id(group_id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不应该将 “查询不到就查询父级管理员的逻辑” 放到 svc 层面,这个逻辑是业务逻辑,应该在 biz 层处理,即函数里处理

可以调用 svc 获取分级管理,判空,若为空,在获取父管理员成员

可以在 get_grade_manager_members_by_group_id 函数上添加参数,比如 fallback_to_parent_if_empty = False

需要查看调用点,如果只有一个,默认值可以是 True,如果有其他,则需要保持旧调用点不需要变动


从当前来看,svc 不需要增加任何函数



class ApprovedPassApplicationBiz:
"""审批通过处理"""
Expand Down Expand Up @@ -445,7 +450,7 @@ def _get_approval_process_with_node_processor(
elif node.processor_type == RoleType.GRADE_MANAGER.value:
# 如果是自定义权限, 需要后续流程中填充审批人
if "group_id" in kwargs:
processors = self.approval_processor_biz.get_grade_manager_members_by_group_id(
processors = self.approval_processor_biz.get_grade_or_parent_manager_members_by_group_id(
group_id=kwargs["group_id"]
)
# NOTE: 由于资源实例审批人节点的逻辑涉及到复杂的拆分, 合并逻辑, 不在这里处理
Expand Down
18 changes: 18 additions & 0 deletions saas/backend/service/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,3 +656,21 @@ def transfer_groups_role(self, group_ids: List[int], role_id: int):
RoleRelatedObject.objects.filter(
object_type=RoleRelatedObjectType.TEMPLATE.value, object_id__in=template_ids
).update(role_id=role_id)

def get_role_parent_member_by_group_id(self, group_id: int):
"""通过用户组ID查询其对应角色的用户,为空则查询上一级角色对应的用户"""
# 查询用户组的来源角色
role_related_object = RoleRelatedObject.objects.get(
object_type=RoleRelatedObjectType.GROUP.value, object_id=group_id
)
# 查询角色
role = Role.objects.get(id=role_related_object.role_id)

relation = RoleRelation.objects.filter(role_id=role.id).first()

# 当前角色管理员不存在并存在上级角色
if not role.members and relation:
parent_role = Role.objects.get(id=relation.parent_id)
return parent_role.members

return role.members