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 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion saas/backend/biz/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ 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)

class ApprovedPassApplicationBiz:
"""审批通过处理"""
Expand Down Expand Up @@ -445,7 +449,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