Skip to content

Commit

Permalink
fix(organization): 修复展示没有协同关系的租户
Browse files Browse the repository at this point in the history
  • Loading branch information
neronkl committed Sep 6, 2023
1 parent 6c588b6 commit b8b7c12
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/bk-user/bkuser/apis/web/organization/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,17 @@ class TenantListApi(CurrentUserTenantMixin, generics.ListAPIView):
queryset = Tenant.objects.all()
serializer_class = TenantListOutputSLZ

def get_tenants(self):
"""
获取当前租户以及有协同关系的租户
"""
queryset = self.filter_queryset(self.get_queryset())
# TODO 过滤出与当前租户有协同关系的租户
current_tenant_id: str = self.get_current_tenant_id()
return queryset.filter(id__in=[current_tenant_id])

def get_serializer_context(self):
tenant_ids = list(self.queryset.values_list("id", flat=True))
tenant_ids = list(self.get_tenants().values_list("id", flat=True))
tenant_root_departments_map = TenantDepartmentHandler.get_tenant_root_department_map_by_tenant_id(
tenant_ids, self.get_current_tenant_id()
)
Expand All @@ -129,10 +138,9 @@ def get_serializer_context(self):
responses={status.HTTP_200_OK: TenantListOutputSLZ(many=True)},
)
def get(self, request, *args, **kwargs):
queryset = self.filter_queryset(self.get_queryset())
queryset = self.get_tenants()
# 将当前租户置顶
current_tenant_id: str = self.get_current_tenant_id()

current_tenant_id = self.get_current_tenant_id()
# 通过比对租户id, 当等于当前登录用户的租户id,将其排序到查询集的顶部, 否则排序到查询集的底部
sorted_queryset = sorted(queryset, key=lambda t: t.id != current_tenant_id)

Expand Down

0 comments on commit b8b7c12

Please sign in to comment.