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