-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: app permission * fix(urls.py): delete old urls(apis), use (gateways) instead (#151)
- Loading branch information
Showing
30 changed files
with
1,868 additions
and
1,784 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/dashboard/apigateway/apigateway/apis/web/permission/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# TencentBlueKing is pleased to support the open source community by making | ||
# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. | ||
# Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. | ||
# Licensed under the MIT License (the "License"); you may not use this file except | ||
# in compliance with the License. You may obtain a copy of the License at | ||
# | ||
# http://opensource.org/licenses/MIT | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed under | ||
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
# either express or implied. See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# We undertake not to change the open source license (MIT license) applicable | ||
# to the current version of the project delivered to anyone in the future. | ||
# |
107 changes: 107 additions & 0 deletions
107
src/dashboard/apigateway/apigateway/apis/web/permission/filters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# TencentBlueKing is pleased to support the open source community by making | ||
# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. | ||
# Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. | ||
# Licensed under the MIT License (the "License"); you may not use this file except | ||
# in compliance with the License. You may obtain a copy of the License at | ||
# | ||
# http://opensource.org/licenses/MIT | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed under | ||
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
# either express or implied. See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# We undertake not to change the open source license (MIT license) applicable | ||
# to the current version of the project delivered to anyone in the future. | ||
# | ||
from django_filters import rest_framework as filters | ||
|
||
from apigateway.apps.permission.constants import GrantDimensionEnum, GrantTypeEnum | ||
from apigateway.apps.permission.models import ( | ||
AppAPIPermission, | ||
AppPermissionApply, | ||
AppPermissionRecord, | ||
AppResourcePermission, | ||
) | ||
|
||
|
||
class AppResourcePermissionFilter(filters.FilterSet): | ||
bk_app_code = filters.CharFilter() | ||
query = filters.CharFilter(method="query_filter") | ||
grant_type = filters.ChoiceFilter(choices=GrantTypeEnum.choices()) | ||
resource_id = filters.NumberFilter() | ||
order_by = filters.OrderingFilter( | ||
choices=[(field, field) for field in ["bk_app_code", "-bk_app_code", "expires", "-expires"]] | ||
) | ||
|
||
class Meta: | ||
model = AppResourcePermission | ||
fields = [ | ||
"bk_app_code", | ||
"query", | ||
"grant_type", | ||
"resource_id", | ||
"order_by", | ||
] | ||
|
||
def query_filter(self, queryset, name, value): | ||
return queryset.filter(bk_app_code__icontains=value) | ||
|
||
|
||
class AppPermissionApplyFilter(filters.FilterSet): | ||
bk_app_code = filters.CharFilter(lookup_expr="icontains") | ||
applied_by = filters.CharFilter() | ||
grant_dimension = filters.OrderingFilter(choices=GrantDimensionEnum.get_choices()) | ||
|
||
class Meta: | ||
model = AppPermissionApply | ||
fields = [ | ||
"bk_app_code", | ||
"applied_by", | ||
"grant_dimension", | ||
] | ||
|
||
|
||
class AppGatewayPermissionFilter(filters.FilterSet): | ||
bk_app_code = filters.CharFilter() | ||
query = filters.CharFilter(method="query_filter") | ||
resource_id = filters.NumberFilter() | ||
order_by = filters.OrderingFilter( | ||
choices=[(field, field) for field in ["bk_app_code", "-bk_app_code", "expires", "-expires"]] | ||
) | ||
|
||
class Meta: | ||
model = AppAPIPermission | ||
fields = [ | ||
"bk_app_code", | ||
"query", | ||
"resource_id", | ||
"order_by", | ||
] | ||
|
||
def query_filter(self, queryset, name, value): | ||
return queryset.filter(bk_app_code__icontains=value) | ||
|
||
|
||
class AppPermissionRecordFilter(filters.FilterSet): | ||
time_start = filters.DateTimeFilter(method="time_start_filter") | ||
time_end = filters.DateTimeFilter(method="time_end_filter") | ||
bk_app_code = filters.CharFilter() | ||
grant_dimension = filters.OrderingFilter(choices=GrantDimensionEnum.get_choices()) | ||
|
||
class Meta: | ||
model = AppPermissionRecord | ||
fields = [ | ||
"time_start", | ||
"time_end", | ||
"bk_app_code", | ||
"grant_dimension", | ||
] | ||
|
||
def time_start_filter(self, queryset, name, value): | ||
return queryset.filter(handled_time__gte=value) | ||
|
||
def time_end_filter(self, queryset, name, value): | ||
return queryset.filter(handled_time__lt=value) |
Oops, something went wrong.