Skip to content

Commit

Permalink
fix(apis/web/permission): 修复应用权限搜索问题
Browse files Browse the repository at this point in the history
  • Loading branch information
F-cq committed Nov 21, 2024
1 parent 7dc7b1e commit e9dbd28
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 5 additions & 6 deletions src/dashboard/apigateway/apigateway/apis/web/permission/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,10 @@ class AppPermissionListApi(AppPermissionQuerySetMixin, generics.ListAPIView):

def get_queryset(self):
query_params = self.request.query_params
grant_dimension = query_params.get("grant_dimension")
if grant_dimension and grant_dimension not in [GrantDimensionEnum.RESOURCE.value, GrantDimensionEnum.API.value]:
return []

app_gateway_permissions = AppGatewayPermissionFilter(self.request.GET, queryset=self.get_gateway_queryset()).qs
# 如果查询维度为资源 或者 授权类型不为 INITIALIZE(网关维度都为INITIALIZE)或者 查询某个资源 都要忽略掉网关维度的
if (
grant_dimension == GrantDimensionEnum.RESOURCE.value
query_params.get("grant_dimension") == GrantDimensionEnum.RESOURCE.value
or (query_params.get("grant_type") and query_params.get("grant_type") != GrantTypeEnum.INITIALIZE.value)
or query_params.get("resource_id")
):
Expand All @@ -141,7 +137,7 @@ def get_queryset(self):
app_resource_permissions = AppResourcePermissionFilter(
self.request.GET, queryset=self.get_resource_queryset()
).qs
if grant_dimension == GrantDimensionEnum.API.value:
if query_params.get("grant_dimension") == GrantDimensionEnum.API.value:
app_resource_permissions = []

return self.get_app_permissions(app_gateway_permissions, app_resource_permissions)
Expand All @@ -150,6 +146,9 @@ def get(self, request, *args, **kwargs):
"""
权限列表(gateway+resource)
"""
slz = AppPermissionQueryInputSLZ(data=request.query_params)
slz.is_valid(raise_exception=True)

queryset = self.get_queryset()
page = self.paginate_queryset(queryset)
resource_ids = [perm["resource_id"] for perm in page if perm.get("resource_id")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def test_list(self, fake_gateway, request_view):
},
"expected": {
"count": 2,
"status_code": 200,
},
},
{
Expand All @@ -76,6 +77,7 @@ def test_list(self, fake_gateway, request_view):
},
"expected": {
"count": 1,
"status_code": 200,
},
},
{
Expand All @@ -84,6 +86,7 @@ def test_list(self, fake_gateway, request_view):
},
"expected": {
"count": 0,
"status_code": 400,
},
},
]
Expand All @@ -98,8 +101,9 @@ def test_list(self, fake_gateway, request_view):
)

result = response.json()
assert response.status_code == 200, result
assert result["data"]["count"] == test["expected"]["count"]
assert response.status_code == test["expected"]["status_code"], result
if response.status_code == 200:
assert result["data"]["count"] == test["expected"]["count"]


class TestAppResourcePermissionViewSet:
Expand Down

0 comments on commit e9dbd28

Please sign in to comment.