mirror of https://github.com/jumpserver/jumpserver
merge: with remote branch
commit
79ce1215f5
|
@ -1,16 +1,16 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
import django_filters
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
import django_filters
|
||||
|
||||
from common.utils import get_logger
|
||||
from common.drf.filters import BaseFilterSet
|
||||
from common.utils import get_logger, get_object_or_none
|
||||
from common.mixins.api import SuggestionMixin
|
||||
from orgs.mixins.api import OrgBulkModelViewSet
|
||||
from orgs.mixins import generics
|
||||
from assets.models import Asset, Node, Gateway
|
||||
from assets import serializers
|
||||
from assets.models import Asset, Gateway
|
||||
from assets.tasks import (
|
||||
update_assets_hardware_info_manual, test_assets_connectivity_manual,
|
||||
)
|
||||
|
|
|
@ -1,22 +1,34 @@
|
|||
from rest_framework.generics import ListAPIView
|
||||
from rest_framework.mixins import ListModelMixin
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
|
||||
from common.drf.api import JMSGenericViewSet
|
||||
from assets.serializers import CategorySerializer, TypeSerializer
|
||||
from assets.const import AllTypes
|
||||
|
||||
__all__ = ['CategoryListApi', 'TypeListApi']
|
||||
__all__ = ['CategoryViewSet']
|
||||
|
||||
|
||||
class CategoryListApi(ListAPIView):
|
||||
serializer_class = CategorySerializer
|
||||
class CategoryViewSet(ListModelMixin, JMSGenericViewSet):
|
||||
serializer_classes = {
|
||||
'default': CategorySerializer,
|
||||
'types': TypeSerializer
|
||||
}
|
||||
permission_classes = ()
|
||||
|
||||
def get_queryset(self):
|
||||
return AllTypes.categories()
|
||||
|
||||
@action(methods=['get'], detail=False)
|
||||
def types(self, request, *args, **kwargs):
|
||||
queryset = AllTypes.types()
|
||||
serializer = self.get_serializer(queryset, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
class TypeListApi(ListAPIView):
|
||||
serializer_class = TypeSerializer
|
||||
permission_classes = ()
|
||||
@action(methods=['get'], detail=False)
|
||||
def constraints(self, request, *args, **kwargs):
|
||||
category = request.query_params.get('category')
|
||||
tp = request.query_params.get('type')
|
||||
constraints = AllTypes.get_constraints(category, tp)
|
||||
return Response(constraints)
|
||||
|
||||
def get_queryset(self):
|
||||
return AllTypes.types()
|
||||
|
|
|
@ -26,28 +26,6 @@ class AssetPlatformViewSet(JMSModelViewSet):
|
|||
'ops_methods': 'assets.view_platform'
|
||||
}
|
||||
|
||||
@action(methods=['GET'], detail=False)
|
||||
def categories(self, request, *args, **kwargs):
|
||||
data = AllTypes.grouped_choices_to_objs()
|
||||
serializer = self.get_serializer(data, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
@action(methods=['GET'], detail=False, url_path='type-constraints')
|
||||
def type_constraints(self, request, *args, **kwargs):
|
||||
category = request.query_params.get('category')
|
||||
tp = request.query_params.get('type')
|
||||
limits = AllTypes.get_constraints(category, tp)
|
||||
return Response(limits)
|
||||
|
||||
@action(methods=['GET'], detail=False, url_path='ops-methods')
|
||||
def ops_methods(self, request, *args, **kwargs):
|
||||
category = request.query_params.get('category')
|
||||
tp = request.query_params.get('type')
|
||||
method = request.query_params.get('method')
|
||||
methods = filter_platform_methods(category, tp, method)
|
||||
serializer = PlatformOpsMethodSerializer(methods, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
def check_object_permissions(self, request, obj):
|
||||
if request.method.lower() in ['delete', 'put', 'patch'] and obj.internal:
|
||||
self.permission_denied(
|
||||
|
|
|
@ -44,34 +44,38 @@ class AllTypes(ChoicesMixin, metaclass=IncludesTextChoicesMeta):
|
|||
return constraints
|
||||
|
||||
@classmethod
|
||||
def types(cls):
|
||||
def types(cls, with_constraints=True):
|
||||
types = []
|
||||
for category, tps in cls.category_types():
|
||||
for tp in tps:
|
||||
types.append(cls.serialize_type(category, tp))
|
||||
types.extend([cls.serialize_type(category, tp, with_constraints) for tp in tps])
|
||||
return types
|
||||
|
||||
@classmethod
|
||||
def categories(cls):
|
||||
def categories(cls, with_constraints=True):
|
||||
categories = []
|
||||
for category, tps in cls.category_types():
|
||||
category_data = {
|
||||
'id': category.value,
|
||||
'name': category.label,
|
||||
'children': [cls.serialize_type(category, tp) for tp in tps]
|
||||
'children': [cls.serialize_type(category, tp, with_constraints) for tp in tps]
|
||||
}
|
||||
categories.append(category_data)
|
||||
return categories
|
||||
|
||||
@classmethod
|
||||
def serialize_type(cls, category, tp):
|
||||
return {
|
||||
def serialize_type(cls, category, tp, with_constraints=True):
|
||||
data = {
|
||||
'id': tp.value,
|
||||
'name': tp.label,
|
||||
'category': category,
|
||||
'constraints': cls.get_constraints(category, tp)
|
||||
}
|
||||
|
||||
if with_constraints:
|
||||
data['constraints'] = cls.get_constraints(category, tp)
|
||||
else:
|
||||
data['constraints'] = []
|
||||
return data
|
||||
|
||||
@classmethod
|
||||
def category_types(cls):
|
||||
return (
|
||||
|
|
|
@ -20,7 +20,7 @@ class GatheredUser(OrgModelMixin):
|
|||
date_updated = models.DateTimeField(auto_now=True, verbose_name=_("Date updated"))
|
||||
|
||||
@property
|
||||
def hostname(self):
|
||||
def name(self):
|
||||
return self.asset.name
|
||||
|
||||
@property
|
||||
|
|
|
@ -8,6 +8,6 @@ from .domain import *
|
|||
from .gathered_user import *
|
||||
from .favorite_asset import *
|
||||
from .account import *
|
||||
from .backup import *
|
||||
from assets.serializers.account.backup import *
|
||||
from .platform import *
|
||||
from .cagegory import *
|
||||
|
|
|
@ -7,7 +7,7 @@ from orgs.mixins.serializers import BulkOrgResourceModelSerializer
|
|||
from ops.mixin import PeriodTaskSerializerMixin
|
||||
from common.utils import get_logger
|
||||
|
||||
from ..models import AccountBackupPlan, AccountBackupPlanExecution
|
||||
from assets.models import AccountBackupPlan, AccountBackupPlanExecution
|
||||
|
||||
logger = get_logger(__file__)
|
||||
|
|
@ -12,11 +12,10 @@ class GatheredUserSerializer(OrgResourceModelSerializerMixin):
|
|||
model = GatheredUser
|
||||
fields_mini = ['id']
|
||||
fields_small = fields_mini + [
|
||||
'username', 'ip_last_login',
|
||||
'present',
|
||||
'username', 'ip_last_login', 'present', 'name',
|
||||
'date_last_login', 'date_created', 'date_updated'
|
||||
]
|
||||
fields_fk = ['asset', 'name', 'ip']
|
||||
fields_fk = ['asset', 'ip']
|
||||
fields = fields_small + fields_fk
|
||||
read_only_fields = fields
|
||||
extra_kwargs = {
|
||||
|
|
|
@ -90,7 +90,7 @@ class AssetAccountHandler(BaseAccountHandler):
|
|||
category_dict = {}
|
||||
for i in AllTypes.grouped_choices_to_objs():
|
||||
for j in i['children']:
|
||||
category_dict[j['value']] = j['display_name']
|
||||
category_dict[j['value']] = j['label']
|
||||
|
||||
header_fields = cls.get_header_fields(AccountSecretSerializer(qs.first()))
|
||||
account_category_map = defaultdict(list)
|
||||
|
|
|
@ -7,6 +7,7 @@ from .. import api
|
|||
app_name = 'assets'
|
||||
|
||||
router = BulkRouter()
|
||||
router.register(r'categories', api.CategoryViewSet, 'category')
|
||||
router.register(r'assets', api.AssetViewSet, 'asset')
|
||||
router.register(r'hosts', api.HostViewSet, 'host')
|
||||
router.register(r'devices', api.DeviceViewSet, 'device')
|
||||
|
@ -28,11 +29,8 @@ router.register(r'favorite-assets', api.FavoriteAssetViewSet, 'favorite-asset')
|
|||
router.register(r'account-backup-plans', api.AccountBackupPlanViewSet, 'account-backup')
|
||||
router.register(r'account-backup-plan-executions', api.AccountBackupPlanExecutionViewSet, 'account-backup-execution')
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
# path('assets/<uuid:pk>/gateways/', api.AssetGatewayListApi.as_view(), name='asset-gateway-list'),
|
||||
path('categories/', api.CategoryListApi.as_view(), name='category-list'),
|
||||
path('categories/types/', api.TypeListApi.as_view(), name='type-list'),
|
||||
path('assets/<uuid:pk>/tasks/', api.AssetTaskCreateApi.as_view(), name='asset-task-create'),
|
||||
path('assets/tasks/', api.AssetsTaskCreateApi.as_view(), name='assets-task-create'),
|
||||
path('assets/<uuid:pk>/perm-users/', api.AssetPermUserListApi.as_view(), name='asset-perm-user-list'),
|
||||
|
|
|
@ -32,7 +32,7 @@ urlpatterns = [
|
|||
path('mfa/verify/', api.MFAChallengeVerifyApi.as_view(), name='mfa-verify'),
|
||||
path('mfa/challenge/', api.MFAChallengeVerifyApi.as_view(), name='mfa-challenge'),
|
||||
path('mfa/select/', api.MFASendCodeApi.as_view(), name='mfa-select'),
|
||||
path('mfa/send-code/', api.MFASendCodeApi.as_view(), name='mfa-send-codej'),
|
||||
path('mfa/send-code/', api.MFASendCodeApi.as_view(), name='mfa-send-code'),
|
||||
path('password/verify/', api.UserPasswordVerifyApi.as_view(), name='user-password-verify'),
|
||||
path('login-confirm-ticket/status/', api.TicketStatusApi.as_view(), name='login-confirm-ticket-status'),
|
||||
]
|
||||
|
|
|
@ -87,7 +87,7 @@ class CeleryTaskSerializer(serializers.Serializer):
|
|||
|
||||
|
||||
class ChoiceSerializer(serializers.Serializer):
|
||||
display_name = serializers.CharField(label=_("Display name"))
|
||||
label = serializers.CharField(label=_("Label"))
|
||||
value = serializers.CharField(label=_("Value"))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue