diff --git a/apps/assets/api/platform.py b/apps/assets/api/platform.py index 4098dc29a..fc038ee67 100644 --- a/apps/assets/api/platform.py +++ b/apps/assets/api/platform.py @@ -17,11 +17,11 @@ class AssetPlatformViewSet(JMSModelViewSet): 'default': PlatformSerializer, 'categories': GroupedChoiceSerailizer } - filterset_fields = ['name'] + filterset_fields = ['name', 'category', 'type'] search_fields = ['name'] rbac_perms = { 'categories': 'assets.view_platform', - 'type_constraints': 'assets-view_platform' + 'type_constraints': 'assets.view_platform' } @action(methods=['GET'], detail=False) diff --git a/apps/assets/apps.py b/apps/assets/apps.py index e1bb43544..712033455 100644 --- a/apps/assets/apps.py +++ b/apps/assets/apps.py @@ -13,4 +13,4 @@ class AssetsConfig(AppConfig): def ready(self): super().ready() - from . import signal_handlers + # from . import signal_handlers diff --git a/apps/assets/serializers/asset/common.py b/apps/assets/serializers/asset/common.py index 9363cbe3c..284ec2e0d 100644 --- a/apps/assets/serializers/asset/common.py +++ b/apps/assets/serializers/asset/common.py @@ -6,7 +6,7 @@ from django.utils.translation import ugettext_lazy as _ from common.drf.serializers import JMSWritableNestedModelSerializer from common.drf.fields import ChoiceDisplayField from ..account import AccountSerializer -from ...models import Asset, Node, Platform, Protocol, Label, Domain, Account +from ...models import Asset, Node, Platform, Protocol, Label, Domain from ...const import Category, AllTypes __all__ = [ diff --git a/utils/generate_fake_data/generate.py b/utils/generate_fake_data/generate.py index 97340e8e6..5fdfddc5c 100644 --- a/utils/generate_fake_data/generate.py +++ b/utils/generate_fake_data/generate.py @@ -12,7 +12,7 @@ sys.path.insert(0, APPS_DIR) os.environ.setdefault("DJANGO_SETTINGS_MODULE", "jumpserver.settings") django.setup() -from resources.assets import AssetsGenerator, NodesGenerator, SystemUsersGenerator, AdminUsersGenerator +from resources.assets import AssetsGenerator, NodesGenerator from resources.users import UserGroupGenerator, UserGenerator from resources.perms import AssetPermissionGenerator from resources.terminal import CommandGenerator, SessionGenerator @@ -21,8 +21,6 @@ from resources.terminal import CommandGenerator, SessionGenerator resource_generator_mapper = { 'asset': AssetsGenerator, 'node': NodesGenerator, - 'system_user': SystemUsersGenerator, - 'admin_user': AdminUsersGenerator, 'user': UserGenerator, 'user_group': UserGroupGenerator, 'asset_permission': AssetPermissionGenerator, diff --git a/utils/generate_fake_data/resources/assets.py b/utils/generate_fake_data/resources/assets.py index e14df6932..7144b1b5c 100644 --- a/utils/generate_fake_data/resources/assets.py +++ b/utils/generate_fake_data/resources/assets.py @@ -5,6 +5,7 @@ import forgery_py from .base import FakeDataGenerator from assets.models import * +from assets.const import AllTypes class NodesGenerator(FakeDataGenerator): @@ -17,13 +18,34 @@ class NodesGenerator(FakeDataGenerator): parent.create_child() +class PlatformGenerator(FakeDataGenerator): + resource = 'platform' + category_type: dict + categories: list + + def pre_generate(self): + self.category_type = dict(AllTypes.category_types()) + self.categories = list(self.category_type.keys()) + + def do_generate(self, batch, batch_size): + platforms = [] + for i in batch: + data = { + 'name': forgery_py.name.company_name(), + 'category': '' + } + platforms.append(Platform(**data)) + Platform.objects.bulk_create(platforms, ignore_conflicts=True) + + class AssetsGenerator(FakeDataGenerator): resource = 'asset' - admin_user_ids: list node_ids: list + platform_ids: list def pre_generate(self): self.node_ids = list(Node.objects.all().values_list('id', flat=True)) + self.platform_ids = list(Platform.objects.all().values_list('id', flat=True)) def set_assets_nodes(self, assets): for asset in assets: @@ -39,8 +61,8 @@ class AssetsGenerator(FakeDataGenerator): hostname = f'{hostname}-{ip}' data = dict( ip=ip, - hostname=hostname, - admin_user_id=choice(self.admin_user_ids), + name=hostname, + platform_id=choice(self.platform_ids), created_by='Fake', org_id=self.org.id ) diff --git a/utils/generate_fake_data/resources/users.py b/utils/generate_fake_data/resources/users.py index c973fec5e..34a9d9703 100644 --- a/utils/generate_fake_data/resources/users.py +++ b/utils/generate_fake_data/resources/users.py @@ -4,7 +4,6 @@ import forgery_py from .base import FakeDataGenerator from users.models import * -from orgs.models import OrganizationMember class UserGroupGenerator(FakeDataGenerator):