Browse Source

fix: swagger

pull/7677/head
xinwen 3 years ago committed by Jiangjie.Bai
parent
commit
f460916e84
  1. 1
      apps/assets/api/domain.py
  2. 3
      apps/common/mixins/api/permission.py
  3. 5
      apps/perms/api/application/user_group_permission.py
  4. 9
      apps/perms/api/asset/user_group_permission.py
  5. 4
      apps/rbac/api/role.py
  6. 2
      apps/settings/api/ldap.py
  7. 3
      apps/terminal/api/command.py
  8. 2
      apps/tickets/api/relation.py

1
apps/assets/api/domain.py

@ -37,6 +37,7 @@ class GatewayViewSet(OrgBulkModelViewSet):
class GatewayTestConnectionApi(SingleObjectMixin, APIView):
queryset = Gateway.objects.all()
object = None
rbac_perms = {
'POST': 'assets.change_gateway'

3
apps/common/mixins/api/permission.py

@ -25,6 +25,9 @@ class RoleAdminMixin:
@lazyproperty
def user(self):
user_id = self.kwargs.get(self.user_id_url_kwarg)
if hasattr(self, 'swagger_fake_view') and not user_id:
return self.request.user # NOQA
user_model = get_user_model()
return user_model.objects.get(id=user_id)

5
apps/perms/api/application/user_group_permission.py

@ -26,7 +26,10 @@ class UserGroupGrantedApplicationsApi(CommonApiMixin, ListAPIView):
}
def get_queryset(self):
user_group_id = self.kwargs.get('pk', '')
user_group_id = self.kwargs.get('pk')
if not user_group_id:
return Application.objects.none()
queryset = Application.objects\
.filter(Q(granted_by_permissions__user_groups__id=user_group_id))\
.distinct().only(*self.only_fields)

9
apps/perms/api/asset/user_group_permission.py

@ -40,7 +40,9 @@ class UserGroupGrantedAssetsApi(ListAPIView):
}
def get_queryset(self):
user_group_id = self.kwargs.get('pk', '')
user_group_id = self.kwargs.get('pk')
if not user_group_id:
return Asset.objects.none()
asset_perm_ids = list(AssetPermission.objects.valid().filter(
user_groups__id=user_group_id
@ -127,7 +129,10 @@ class UserGroupGrantedNodesApi(ListAPIView):
}
def get_queryset(self):
user_group_id = self.kwargs.get('pk', '')
user_group_id = self.kwargs.get('pk')
if not user_group_id:
return Node.objects.none()
nodes = Node.objects.filter(
Q(granted_by_permissions__user_groups__id=user_group_id) |
Q(assets__granted_by_permissions__user_groups__id=user_group_id)

4
apps/rbac/api/role.py

@ -61,6 +61,7 @@ class OrgRoleViewSet(RoleViewSet):
# Sub view set
class RolePermissionsViewSet(PermissionViewSet):
filterset_fields = []
rbac_perms = (
('get_tree', 'role.view_role'),
)
@ -69,6 +70,9 @@ class RolePermissionsViewSet(PermissionViewSet):
def get_queryset(self):
role_id = self.kwargs.get('role_pk')
if not role_id:
return Role.objects.none()
role = Role.objects.get(id=role_id)
self.scope = role.scope
self.check_disabled = role.builtin

2
apps/settings/api/ldap.py

@ -101,7 +101,7 @@ class LDAPUserListApi(generics.ListAPIView):
def get_queryset(self):
if hasattr(self, 'swagger_fake_view'):
return []
return User.objects.none()
cache_police = self.request.query_params.get('cache_police', True)
if cache_police in LDAP_USE_CACHE_FLAGS:
users = self.get_queryset_from_cache()

3
apps/terminal/api/command.py

@ -166,6 +166,9 @@ class CommandViewSet(JMSBulkModelViewSet):
def get_queryset(self):
command_storage_id = self.request.query_params.get('command_storage_id')
if not command_storage_id:
return Command.objects.none()
storage = CommandStorage.objects.get(id=command_storage_id)
if not storage.is_valid():
raise StorageInvalid

2
apps/tickets/api/relation.py

@ -11,7 +11,7 @@ from orgs.utils import tmp_to_root_org
class TicketSessionRelationViewSet(CreateModelMixin, JMSGenericViewSet):
queryset = TicketSession
queryset = TicketSession.objects.all()
serializer_class = TicketSessionRelationSerializer

Loading…
Cancel
Save