From 5fcd83b587cd020346c830bbc5146b6f02062050 Mon Sep 17 00:00:00 2001 From: Bai Date: Thu, 2 Feb 2023 14:37:21 +0800 Subject: [PATCH 01/15] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=20swagger=20api=20=E6=97=B6=EF=BC=8CAssetSerializer?= =?UTF-8?q?=20category,=20type=20=E5=AD=97=E6=AE=B5=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=20=5Fchoices=20=E5=B1=9E=E6=80=A7=E6=97=B6?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/acls/serializers/login_acl.py | 4 ++-- apps/assets/serializers/asset/common.py | 4 ++-- apps/perms/serializers/permission.py | 4 +--- apps/tickets/serializers/ticket/ticket.py | 4 ++-- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/apps/acls/serializers/login_acl.py b/apps/acls/serializers/login_acl.py index 99b1f1077..59b9cf0ad 100644 --- a/apps/acls/serializers/login_acl.py +++ b/apps/acls/serializers/login_acl.py @@ -52,10 +52,10 @@ class LoginACLSerializer(BulkModelSerializer): action = self.fields.get("action") if not action: return - choices = action._choices + choices = action.choices if not has_valid_xpack_license(): choices.pop(LoginACL.ActionChoices.review, None) - action._choices = choices + action.choices = choices def get_rules_serializer(self): return RuleSerializer() diff --git a/apps/assets/serializers/asset/common.py b/apps/assets/serializers/asset/common.py index 82a163d84..e51c4558f 100644 --- a/apps/assets/serializers/asset/common.py +++ b/apps/assets/serializers/asset/common.py @@ -139,9 +139,9 @@ class AssetSerializer(BulkOrgResourceModelSerializer, WritableNestedModelSeriali return category = request.path.strip('/').split('/')[-1].rstrip('s') field_category = self.fields.get('category') - field_category._choices = Category.filter_choices(category) + field_category.choices = Category.filter_choices(category) field_type = self.fields.get('type') - field_type._choices = AllTypes.filter_choices(category) + field_type.choices = AllTypes.filter_choices(category) @classmethod def setup_eager_loading(cls, queryset): diff --git a/apps/perms/serializers/permission.py b/apps/perms/serializers/permission.py index 63ba3a765..fef9929b8 100644 --- a/apps/perms/serializers/permission.py +++ b/apps/perms/serializers/permission.py @@ -70,9 +70,7 @@ class AssetPermissionSerializer(BulkOrgResourceModelSerializer): actions = self.fields.get("actions") if not actions: return - choices = actions._choices - actions._choices = choices - actions.default = list(choices.keys()) + actions.default = list(actions.choices.keys()) @classmethod def setup_eager_loading(cls, queryset): diff --git a/apps/tickets/serializers/ticket/ticket.py b/apps/tickets/serializers/ticket/ticket.py index 334031e5e..4a36ccf4f 100644 --- a/apps/tickets/serializers/ticket/ticket.py +++ b/apps/tickets/serializers/ticket/ticket.py @@ -39,9 +39,9 @@ class TicketSerializer(OrgResourceModelSerializerMixin): tp = self.fields.get('type') if not tp: return - choices = tp._choices + choices = tp.choices choices.pop(TicketType.general, None) - tp._choices = choices + tp.choices = choices @classmethod def setup_eager_loading(cls, queryset): From d78725f7c5ac51db0ceb43166302b50e1d62b1c2 Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Thu, 2 Feb 2023 14:52:44 +0800 Subject: [PATCH 02/15] perf: choice validate (#9404) Co-authored-by: feng <1304903146@qq.com> --- apps/common/serializers/fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/common/serializers/fields.py b/apps/common/serializers/fields.py index 96ff7c103..84d4d5927 100644 --- a/apps/common/serializers/fields.py +++ b/apps/common/serializers/fields.py @@ -66,7 +66,7 @@ class LabeledChoiceField(ChoiceField): def to_internal_value(self, data): if isinstance(data, dict): - return data.get("value") + data = data.get("value") return super(LabeledChoiceField, self).to_internal_value(data) From 6429b56a54282f0a1ddb77535aa65da63522eb80 Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Thu, 2 Feb 2023 15:01:56 +0800 Subject: [PATCH 03/15] =?UTF-8?q?fix:=20=E8=B5=84=E4=BA=A7=E5=85=8B?= =?UTF-8?q?=E9=9A=86=E8=B4=A6=E5=8F=B7bug=20(#9407)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: feng <1304903146@qq.com> --- apps/accounts/serializers/account/account.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/accounts/serializers/account/account.py b/apps/accounts/serializers/account/account.py index cc13aced8..36dff55a9 100644 --- a/apps/accounts/serializers/account/account.py +++ b/apps/accounts/serializers/account/account.py @@ -17,8 +17,8 @@ class AccountSerializerCreateValidateMixin: replace_attrs: callable def to_internal_value(self, data): + self.id = data.pop('id', None) ret = super().to_internal_value(data) - self.id = ret.pop('id', None) self.push_now = ret.pop('push_now', False) self.template = ret.pop('template', False) return ret From 88edc9191cc0292933cf510b1a10a895888f485e Mon Sep 17 00:00:00 2001 From: Bai Date: Thu, 2 Feb 2023 14:53:18 +0800 Subject: [PATCH 04/15] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=20ACL=20?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=20priority,=20date=5Fupdated,=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/acls/migrations/0008_commandgroup_comment.py | 6 +++--- apps/acls/models/base.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/acls/migrations/0008_commandgroup_comment.py b/apps/acls/migrations/0008_commandgroup_comment.py index 82e44912c..8937d2a93 100644 --- a/apps/acls/migrations/0008_commandgroup_comment.py +++ b/apps/acls/migrations/0008_commandgroup_comment.py @@ -20,14 +20,14 @@ class Migration(migrations.Migration): ), migrations.AlterModelOptions( name='commandfilteracl', - options={'ordering': ('priority', 'name'), 'verbose_name': 'Command acl'}, + options={'ordering': ('priority', 'date_updated', 'name'), 'verbose_name': 'Command acl'}, ), migrations.AlterModelOptions( name='loginacl', - options={'ordering': ('priority', 'name'), 'verbose_name': 'Login acl'}, + options={'ordering': ('priority', 'date_updated', 'name'), 'verbose_name': 'Login acl'}, ), migrations.AlterModelOptions( name='loginassetacl', - options={'ordering': ('priority', 'name'), 'verbose_name': 'Login asset acl'}, + options={'ordering': ('priority', 'date_updated', 'name'), 'verbose_name': 'Login asset acl'}, ), ] diff --git a/apps/acls/models/base.py b/apps/acls/models/base.py index 7ba48b3c6..53a566048 100644 --- a/apps/acls/models/base.py +++ b/apps/acls/models/base.py @@ -82,7 +82,7 @@ class BaseACL(JMSBaseModel): objects = ACLManager.from_queryset(BaseACLQuerySet)() class Meta: - ordering = ('priority', 'name') + ordering = ('priority', 'date_updated', 'name') abstract = True def is_action(self, action): From 1c55bde8c8fc567b1086db148eefc52e6cf7f7a6 Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 2 Feb 2023 15:03:48 +0800 Subject: [PATCH 05/15] =?UTF-8?q?perf:=20=E5=8F=91=E5=B8=83=E6=9C=BA?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E6=96=B0=E5=A2=9E=20CORE=5FHOST=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/automations/deploy_applet_host/__init__.py | 5 +++-- apps/terminal/serializers/applet_host.py | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/terminal/automations/deploy_applet_host/__init__.py b/apps/terminal/automations/deploy_applet_host/__init__.py index c5e903f35..00f63463b 100644 --- a/apps/terminal/automations/deploy_applet_host/__init__.py +++ b/apps/terminal/automations/deploy_applet_host/__init__.py @@ -53,14 +53,15 @@ class DeployAppletHostManager: if not download_host: download_host = site_url options = self.deployment.host.deploy_options - site_url = site_url.rstrip("/") + core_host = options.get("CORE_HOST", site_url) + core_host = core_host.rstrip("/") download_host = download_host.rstrip("/") def handler(plays): for play in plays: play["vars"].update(options) play["vars"]["APPLET_DOWNLOAD_HOST"] = download_host - play["vars"]["CORE_HOST"] = site_url + play["vars"]["CORE_HOST"] = core_host play["vars"]["BOOTSTRAP_TOKEN"] = bootstrap_token play["vars"]["HOST_ID"] = host_id play["vars"]["HOST_NAME"] = self.deployment.host.name diff --git a/apps/terminal/serializers/applet_host.py b/apps/terminal/serializers/applet_host.py index 9ec4b8104..cf7895a71 100644 --- a/apps/terminal/serializers/applet_host.py +++ b/apps/terminal/serializers/applet_host.py @@ -1,3 +1,4 @@ +from django.conf import settings from django.utils.translation import gettext_lazy as _ from rest_framework import serializers @@ -27,6 +28,8 @@ class DeployOptionsSerializer(serializers.Serializer): (1, _("Disabled")), (0, _("Enabled")), ) + + CORE_HOST = serializers.CharField(default=settings.SITE_URL, label=_('API Server'), max_length=1024) RDS_Licensing = serializers.BooleanField(default=False, label=_("RDS Licensing")) RDS_LicenseServer = serializers.CharField(default='127.0.0.1', label=_('RDS License Server'), max_length=1024) RDS_LicensingMode = serializers.ChoiceField(choices=LICENSE_MODE_CHOICES, default=4, label=_('RDS Licensing Mode')) From 3341d55d1b37183808e0e9535fd41f6d2346881d Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 2 Feb 2023 15:26:19 +0800 Subject: [PATCH 06/15] =?UTF-8?q?perf:=20APPLET=5FDOWNLOAD=5FHOST=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/automations/deploy_applet_host/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/terminal/automations/deploy_applet_host/__init__.py b/apps/terminal/automations/deploy_applet_host/__init__.py index 00f63463b..164340098 100644 --- a/apps/terminal/automations/deploy_applet_host/__init__.py +++ b/apps/terminal/automations/deploy_applet_host/__init__.py @@ -50,11 +50,11 @@ class DeployAppletHostManager: host_id = str(self.deployment.host.id) if not site_url: site_url = "http://localhost:8080" - if not download_host: - download_host = site_url options = self.deployment.host.deploy_options core_host = options.get("CORE_HOST", site_url) core_host = core_host.rstrip("/") + if not download_host: + download_host = core_host download_host = download_host.rstrip("/") def handler(plays): From e3e727f97260de3794f6db0f5cbbb81885bc7eb0 Mon Sep 17 00:00:00 2001 From: Aaron3S Date: Thu, 2 Feb 2023 15:55:37 +0800 Subject: [PATCH 07/15] =?UTF-8?q?perf:=20=E9=BB=98=E8=AE=A4=E5=B1=95?= =?UTF-8?q?=E5=BC=80=E7=BC=96=E8=BE=91=E5=99=A8=E6=89=80=E6=9C=89=E7=9B=AE?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/ops/api/playbook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/ops/api/playbook.py b/apps/ops/api/playbook.py index 36c1c4994..322129b8b 100644 --- a/apps/ops/api/playbook.py +++ b/apps/ops/api/playbook.py @@ -193,7 +193,7 @@ class PlaybookFileBrowserAPIView(APIView): "id": os.path.join(relative_path, d) if not os.path.join(relative_path, d).startswith( '.') else d, "isParent": True, - "open": False, + "open": True, "pId": relative_path if not relative_path.startswith('.') else 'root', "temp": False } From 64e48712a578c17f54f51389919806906fe67fb1 Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Thu, 2 Feb 2023 16:16:38 +0800 Subject: [PATCH 08/15] perf: gateway migrate (#9412) Co-authored-by: feng <1304903146@qq.com> --- apps/assets/migrations/0100_auto_20220711_1413.py | 3 +-- apps/assets/migrations/0101_auto_20220811_1511.py | 1 - apps/assets/migrations/0103_auto_20220902_1021.py | 14 ++++++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/apps/assets/migrations/0100_auto_20220711_1413.py b/apps/assets/migrations/0100_auto_20220711_1413.py index 16e75cbae..2412c6df0 100644 --- a/apps/assets/migrations/0100_auto_20220711_1413.py +++ b/apps/assets/migrations/0100_auto_20220711_1413.py @@ -1,8 +1,7 @@ # Generated by Django 3.2.12 on 2022-07-11 06:13 import time -from django.db import migrations, models -from assets.models import Platform +from django.db import migrations def migrate_asset_accounts(apps, schema_editor): diff --git a/apps/assets/migrations/0101_auto_20220811_1511.py b/apps/assets/migrations/0101_auto_20220811_1511.py index 9ca39774e..0287a8414 100644 --- a/apps/assets/migrations/0101_auto_20220811_1511.py +++ b/apps/assets/migrations/0101_auto_20220811_1511.py @@ -1,5 +1,4 @@ # Generated by Django 3.2.14 on 2022-08-11 07:11 -import assets.models.platform import django.db.models from django.db import migrations, models diff --git a/apps/assets/migrations/0103_auto_20220902_1021.py b/apps/assets/migrations/0103_auto_20220902_1021.py index 8d324fa12..dfc731736 100644 --- a/apps/assets/migrations/0103_auto_20220902_1021.py +++ b/apps/assets/migrations/0103_auto_20220902_1021.py @@ -18,6 +18,8 @@ def _create_account_obj(secret, secret_type, gateway, asset, account_model): def migrate_gateway_to_asset(apps, schema_editor): db_alias = schema_editor.connection.alias + node_model = apps.get_model('assets', 'Node') + org_model = apps.get_model('orgs', 'Organization') gateway_model = apps.get_model('assets', 'Gateway') platform_model = apps.get_model('assets', 'Platform') gateway_platform = platform_model.objects.using(db_alias).get(name=GATEWAY_NAME) @@ -28,6 +30,16 @@ def migrate_gateway_to_asset(apps, schema_editor): asset_model = apps.get_model('assets', 'Asset') protocol_model = apps.get_model('assets', 'Protocol') gateways = gateway_model.objects.all() + + org_ids = gateways.order_by('org_id').values_list('org_id', flat=True).distinct() + node_dict = {} + for org_id in org_ids: + org = org_model.objects.using(db_alias).filter(id=org_id).first() + node = node_model.objects.using(db_alias).filter( + org_id=org_id, value=org.name, full_value=f'/{org.name}' + ).first() + node_dict[org_id] = node + for gateway in gateways: comment = gateway.comment if gateway.comment else '' data = { @@ -40,6 +52,8 @@ def migrate_gateway_to_asset(apps, schema_editor): 'platform': gateway_platform, } asset = asset_model.objects.using(db_alias).create(**data) + node = node_dict.get(str(gateway.org_id)) + asset.nodes.set([node]) asset_dict[gateway.id] = asset protocol_model.objects.using(db_alias).create(name='ssh', port=gateway.port, asset=asset) hosts = [host_model(asset_ptr=asset) for asset in asset_dict.values()] From be151523f4c329762ad9eb8cc48bd0dee5771f75 Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Thu, 2 Feb 2023 16:40:00 +0800 Subject: [PATCH 09/15] perf: user filter (#9413) Co-authored-by: feng <1304903146@qq.com> --- apps/users/filters.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/apps/users/filters.py b/apps/users/filters.py index 8359f8d2e..434faf847 100644 --- a/apps/users/filters.py +++ b/apps/users/filters.py @@ -6,12 +6,8 @@ from rbac.models import Role class UserFilter(BaseFilterSet): - system_roles = filters.ModelChoiceFilter( - queryset=Role.objects.filter(scope='system'), method='filter_system_roles' - ) - org_roles = filters.ModelChoiceFilter( - queryset=Role.objects.filter(scope='org'), method='filter_org_roles' - ) + system_roles = filters.CharFilter(method='filter_system_roles') + org_roles = filters.CharFilter(method='filter_org_roles') class Meta: model = User @@ -22,16 +18,18 @@ class UserFilter(BaseFilterSet): @staticmethod def filter_system_roles(queryset, name, value): - queryset = queryset.prefetch_related('role_bindings')\ - .filter(role_bindings__role_id=value.id)\ - .distinct() + queryset = queryset.prefetch_related('role_bindings') \ + .filter( + role_bindings__role__name=value, + role_bindings__role__scope='system' + ).distinct() return queryset @staticmethod def filter_org_roles(queryset, name, value): queryset = queryset.prefetch_related('role_bindings') \ - .filter(role_bindings__role_id=value.id) \ - .distinct() + .filter( + role_bindings__role__name=value, + role_bindings__role__scope='org' + ).distinct() return queryset - - From a045eb99361a458eccb8b5436a9b3e012b8708f1 Mon Sep 17 00:00:00 2001 From: Bai Date: Thu, 2 Feb 2023 16:06:15 +0800 Subject: [PATCH 10/15] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E5=88=97=E8=A1=A8=E6=8E=92=E5=BA=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/ops/migrations/0025_auto_20230117_1130.py | 2 +- apps/rbac/api/role.py | 1 - apps/rbac/migrations/0012_alter_role_options.py | 17 +++++++++++++++++ apps/rbac/models/role.py | 1 + 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 apps/rbac/migrations/0012_alter_role_options.py diff --git a/apps/ops/migrations/0025_auto_20230117_1130.py b/apps/ops/migrations/0025_auto_20230117_1130.py index b6d3881e7..7a5aa33b8 100644 --- a/apps/ops/migrations/0025_auto_20230117_1130.py +++ b/apps/ops/migrations/0025_auto_20230117_1130.py @@ -13,7 +13,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='playbook', name='create_method', - field=models.CharField(choices=[('blank', 'Blank'), ('upload', 'Upload'), ('vcs', 'VCS')], default='blank', max_length=128, verbose_name='CreateMethod'), + field=models.CharField(choices=[('blank', 'Blank'), ('vcs', 'VCS')], default='blank', max_length=128, verbose_name='CreateMethod'), ), migrations.AddField( model_name='playbook', diff --git a/apps/rbac/api/role.py b/apps/rbac/api/role.py index 0a4d52706..255299516 100644 --- a/apps/rbac/api/role.py +++ b/apps/rbac/api/role.py @@ -4,7 +4,6 @@ from rest_framework.exceptions import PermissionDenied from rest_framework.decorators import action from common.api import JMSModelViewSet -from common.api import PaginatedResponseMixin from ..filters import RoleFilter from ..serializers import RoleSerializer, RoleUserSerializer from ..models import Role, SystemRole, OrgRole diff --git a/apps/rbac/migrations/0012_alter_role_options.py b/apps/rbac/migrations/0012_alter_role_options.py new file mode 100644 index 000000000..ba98b699e --- /dev/null +++ b/apps/rbac/migrations/0012_alter_role_options.py @@ -0,0 +1,17 @@ +# Generated by Django 3.2.16 on 2023-02-02 08:03 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('rbac', '0011_remove_redundant_permission'), + ] + + operations = [ + migrations.AlterModelOptions( + name='role', + options={'ordering': ('scope', 'name'), 'verbose_name': 'Role'}, + ), + ] diff --git a/apps/rbac/models/role.py b/apps/rbac/models/role.py index 1eff7c15c..e5a18b5e6 100644 --- a/apps/rbac/models/role.py +++ b/apps/rbac/models/role.py @@ -43,6 +43,7 @@ class Role(JMSBaseModel): class Meta: unique_together = [('name', 'scope')] + ordering = ('scope', 'name') verbose_name = _('Role') def __str__(self): From 2d514c0db07d5836f96d4bb6d1905a3010f855c8 Mon Sep 17 00:00:00 2001 From: Bai Date: Thu, 2 Feb 2023 16:09:50 +0800 Subject: [PATCH 11/15] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E5=88=97=E8=A1=A8=E6=8E=92=E5=BA=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/rbac/migrations/0012_alter_role_options.py | 2 +- apps/rbac/models/role.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/rbac/migrations/0012_alter_role_options.py b/apps/rbac/migrations/0012_alter_role_options.py index ba98b699e..6c7ce1525 100644 --- a/apps/rbac/migrations/0012_alter_role_options.py +++ b/apps/rbac/migrations/0012_alter_role_options.py @@ -12,6 +12,6 @@ class Migration(migrations.Migration): operations = [ migrations.AlterModelOptions( name='role', - options={'ordering': ('scope', 'name'), 'verbose_name': 'Role'}, + options={'ordering': ('-builtin', 'scope', 'name'), 'verbose_name': 'Role'}, ), ] diff --git a/apps/rbac/models/role.py b/apps/rbac/models/role.py index e5a18b5e6..796b1ab63 100644 --- a/apps/rbac/models/role.py +++ b/apps/rbac/models/role.py @@ -43,7 +43,7 @@ class Role(JMSBaseModel): class Meta: unique_together = [('name', 'scope')] - ordering = ('scope', 'name') + ordering = ('-builtin', 'scope', 'name') verbose_name = _('Role') def __str__(self): From c3d01591e755988422587e21013f96af14f3895f Mon Sep 17 00:00:00 2001 From: Bai Date: Thu, 2 Feb 2023 16:28:54 +0800 Subject: [PATCH 12/15] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E5=88=97=E8=A1=A8viewset=E6=8E=92=E5=BA=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/rbac/api/role.py | 4 ++-- apps/rbac/models/role.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/rbac/api/role.py b/apps/rbac/api/role.py index 255299516..dd0220692 100644 --- a/apps/rbac/api/role.py +++ b/apps/rbac/api/role.py @@ -17,6 +17,7 @@ __all__ = [ class RoleViewSet(JMSModelViewSet): queryset = Role.objects.all() + ordering = ('-builtin', 'scope', 'name') serializer_classes = { 'default': RoleSerializer, 'users': RoleUserSerializer, @@ -61,8 +62,7 @@ class RoleViewSet(JMSModelViewSet): return super().perform_update(serializer) def get_queryset(self): - queryset = super().get_queryset() \ - .annotate(permissions_amount=Count('permissions')) + queryset = super().get_queryset().annotate(permissions_amount=Count('permissions')) return queryset @action(methods=['GET'], detail=True) diff --git a/apps/rbac/models/role.py b/apps/rbac/models/role.py index 796b1ab63..1eff7c15c 100644 --- a/apps/rbac/models/role.py +++ b/apps/rbac/models/role.py @@ -43,7 +43,6 @@ class Role(JMSBaseModel): class Meta: unique_together = [('name', 'scope')] - ordering = ('-builtin', 'scope', 'name') verbose_name = _('Role') def __str__(self): From 4c9d16b4c1e3f23fdfe7297293c7680a17829f03 Mon Sep 17 00:00:00 2001 From: Bai Date: Thu, 2 Feb 2023 16:41:41 +0800 Subject: [PATCH 13/15] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E5=88=97=E8=A1=A8viewset=E6=8E=92=E5=BA=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/rbac/migrations/0012_alter_role_options.py | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 apps/rbac/migrations/0012_alter_role_options.py diff --git a/apps/rbac/migrations/0012_alter_role_options.py b/apps/rbac/migrations/0012_alter_role_options.py deleted file mode 100644 index 6c7ce1525..000000000 --- a/apps/rbac/migrations/0012_alter_role_options.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.2.16 on 2023-02-02 08:03 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('rbac', '0011_remove_redundant_permission'), - ] - - operations = [ - migrations.AlterModelOptions( - name='role', - options={'ordering': ('-builtin', 'scope', 'name'), 'verbose_name': 'Role'}, - ), - ] From 1083f5f6f24c2473653e815f00d81a37eaf28ff2 Mon Sep 17 00:00:00 2001 From: Aaron3S Date: Thu, 2 Feb 2023 15:57:06 +0800 Subject: [PATCH 14/15] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20task=20?= =?UTF-8?q?=E7=9A=84=20verbose=5Fname?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/audits/tasks.py | 5 +++-- apps/authentication/tasks.py | 5 +++-- apps/common/utils/verify_code.py | 4 ++-- apps/perms/tasks.py | 5 +++-- apps/terminal/tasks.py | 13 +++++++------ apps/users/tasks.py | 18 +++++++++--------- 6 files changed, 27 insertions(+), 23 deletions(-) diff --git a/apps/audits/tasks.py b/apps/audits/tasks.py index 5b58c5fd2..1dc507c25 100644 --- a/apps/audits/tasks.py +++ b/apps/audits/tasks.py @@ -9,6 +9,7 @@ from ops.celery.decorator import ( ) from .models import UserLoginLog, OperateLog, FTPLog from common.utils import get_log_keep_day +from django.utils.translation import gettext_lazy as _ def clean_login_log_period(): @@ -32,8 +33,8 @@ def clean_ftp_log_period(): FTPLog.objects.filter(date_start__lt=expired_day).delete() -@register_as_period_task(interval=3600*24) -@shared_task +@register_as_period_task(interval=3600 * 24) +@shared_task(verbose_name=_('Clean audits log')) def clean_audits_log_period(): clean_login_log_period() clean_operation_log_period() diff --git a/apps/authentication/tasks.py b/apps/authentication/tasks.py index 08472e931..978e4ace0 100644 --- a/apps/authentication/tasks.py +++ b/apps/authentication/tasks.py @@ -5,9 +5,10 @@ from celery import shared_task from ops.celery.decorator import register_as_period_task from django.contrib.sessions.models import Session from django.utils import timezone +from django.utils.translation import gettext_lazy as _ -@register_as_period_task(interval=3600*24) -@shared_task +@register_as_period_task(interval=3600 * 24) +@shared_task(verbose_name=_('Clean expired session')) def clean_django_sessions(): Session.objects.filter(expire_date__lt=timezone.now()).delete() diff --git a/apps/common/utils/verify_code.py b/apps/common/utils/verify_code.py index 85589de69..0dbf810fd 100644 --- a/apps/common/utils/verify_code.py +++ b/apps/common/utils/verify_code.py @@ -8,12 +8,12 @@ from common.sdk.sms.endpoint import SMS from common.exceptions import JMSException from common.utils.random import random_string from common.utils import get_logger - +from django.utils.translation import gettext_lazy as _ logger = get_logger(__file__) -@shared_task +@shared_task(verbose_name=_('Send email')) def send_async(sender): sender.gen_and_send() diff --git a/apps/perms/tasks.py b/apps/perms/tasks.py index 57b9f48bd..cd4e7bd86 100644 --- a/apps/perms/tasks.py +++ b/apps/perms/tasks.py @@ -19,12 +19,13 @@ from perms.notifications import ( PermedAssetsWillExpireUserMsg, AssetPermsWillExpireForOrgAdminMsg, ) +from django.utils.translation import gettext_lazy as _ logger = get_logger(__file__) @register_as_period_task(interval=settings.PERM_EXPIRED_CHECK_PERIODIC) -@shared_task() +@shared_task(verbose_name=_('Check asset permission expired')) @atomic() @tmp_to_root_org() def check_asset_permission_expired(): @@ -36,7 +37,7 @@ def check_asset_permission_expired(): @register_as_period_task(crontab=CRONTAB_AT_AM_TEN) -@shared_task() +@shared_task(verbose_name=_('Send asset permission expired notification')) @atomic() @tmp_to_root_org() def check_asset_permission_will_expired(): diff --git a/apps/terminal/tasks.py b/apps/terminal/tasks.py index 4e67d1fc7..63b449320 100644 --- a/apps/terminal/tasks.py +++ b/apps/terminal/tasks.py @@ -21,13 +21,14 @@ from .models import ( Status, Session, Command, Task, AppletHostDeployment ) from .utils import find_session_replay_local +from django.utils.translation import gettext_lazy as _ CACHE_REFRESH_INTERVAL = 10 RUNNING = False logger = get_task_logger(__name__) -@shared_task +@shared_task(verbose_name=_('Periodic delete terminal status')) @register_as_period_task(interval=3600) @after_app_ready_start @after_app_shutdown_clean_periodic @@ -36,7 +37,7 @@ def delete_terminal_status_period(): Status.objects.filter(date_created__lt=yesterday).delete() -@shared_task +@shared_task(verbose_name=_('Clean orphan session')) @register_as_period_task(interval=600) @after_app_ready_start @after_app_shutdown_clean_periodic @@ -55,7 +56,7 @@ def clean_orphan_session(): session.save() -@shared_task +@shared_task(verbose_name=_('Periodic clean expired session')) @register_as_period_task(interval=3600 * 24) @after_app_ready_start @after_app_shutdown_clean_periodic @@ -81,7 +82,7 @@ def clean_expired_session_period(): logger.info("Clean session replay done") -@shared_task +@shared_task(verbose_name=_('Upload session replay to external storage')) def upload_session_replay_to_external_storage(session_id): logger.info(f'Start upload session to external storage: {session_id}') session = Session.objects.filter(id=session_id).first() @@ -108,14 +109,14 @@ def upload_session_replay_to_external_storage(session_id): return -@shared_task +@shared_task(verbose_name=_('Run applet host deployment')) def run_applet_host_deployment(did): with tmp_to_builtin_org(system=1): deployment = AppletHostDeployment.objects.get(id=did) deployment.start() -@shared_task +@shared_task(verbose_name=_('Install applet')) def run_applet_host_deployment_install_applet(did, applet_id): with tmp_to_builtin_org(system=1): deployment = AppletHostDeployment.objects.get(id=did) diff --git a/apps/users/tasks.py b/apps/users/tasks.py index cddf0d2ec..2e19678ad 100644 --- a/apps/users/tasks.py +++ b/apps/users/tasks.py @@ -16,12 +16,12 @@ from .models import User from users.notifications import UserExpirationReminderMsg from settings.utils import LDAPServerUtil, LDAPImportUtil from common.const.crontab import CRONTAB_AT_AM_TEN, CRONTAB_AT_PM_TWO - +from django.utils.translation import gettext_lazy as _ logger = get_logger(__file__) -@shared_task +@shared_task(verbose_name=_('Check password expired')) def check_password_expired(): users = User.get_nature_users().filter(source=User.Source.local) for user in users: @@ -35,7 +35,7 @@ def check_password_expired(): PasswordExpirationReminderMsg(user).publish_async() -@shared_task +@shared_task(verbose_name=_('Periodic check password expired')) @after_app_ready_start def check_password_expired_periodic(): tasks = { @@ -49,11 +49,11 @@ def check_password_expired_periodic(): create_or_update_celery_periodic_tasks(tasks) -@shared_task +@shared_task(verbose_name=_('Check user expired')) def check_user_expired(): date_expired_lt = timezone.now() + timezone.timedelta(days=User.DATE_EXPIRED_WARNING_DAYS) - users = User.get_nature_users()\ - .filter(source=User.Source.local)\ + users = User.get_nature_users() \ + .filter(source=User.Source.local) \ .filter(date_expired__lt=date_expired_lt) for user in users: @@ -66,7 +66,7 @@ def check_user_expired(): UserExpirationReminderMsg(user).publish_async() -@shared_task +@shared_task(verbose_name=_('Periodic check user expired')) @after_app_ready_start def check_user_expired_periodic(): tasks = { @@ -80,7 +80,7 @@ def check_user_expired_periodic(): create_or_update_celery_periodic_tasks(tasks) -@shared_task +@shared_task(verbose_name=_('Import ldap user')) def import_ldap_user(): logger.info("Start import ldap user task") util_server = LDAPServerUtil() @@ -101,7 +101,7 @@ def import_ldap_user(): logger.info('Imported {} users successfully'.format(len(users))) -@shared_task +@shared_task(verbose_name=_('Periodic import ldap user')) @after_app_ready_start def import_ldap_user_periodic(): if not settings.AUTH_LDAP: From d0bd35d88c9e1b3c7a37febeef94cae2a18948df Mon Sep 17 00:00:00 2001 From: Bai Date: Thu, 2 Feb 2023 17:05:05 +0800 Subject: [PATCH 15/15] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=B5=8B?= =?UTF-8?q?=E8=AF=95ldap=20attr=20map=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/settings/serializers/auth/ldap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/settings/serializers/auth/ldap.py b/apps/settings/serializers/auth/ldap.py index a6cc22455..472627e8a 100644 --- a/apps/settings/serializers/auth/ldap.py +++ b/apps/settings/serializers/auth/ldap.py @@ -15,7 +15,7 @@ class LDAPTestConfigSerializer(serializers.Serializer): AUTH_LDAP_BIND_PASSWORD = EncryptedField(required=False, allow_blank=True) AUTH_LDAP_SEARCH_OU = serializers.CharField() AUTH_LDAP_SEARCH_FILTER = serializers.CharField() - AUTH_LDAP_USER_ATTR_MAP = serializers.CharField() + AUTH_LDAP_USER_ATTR_MAP = serializers.JSONField() AUTH_LDAP_START_TLS = serializers.BooleanField(required=False) AUTH_LDAP = serializers.BooleanField(required=False)