From b2ee8c82162c46534bd510b1aac797ae4c75f6c0 Mon Sep 17 00:00:00 2001 From: "fangfang.dong" Date: Wed, 21 Jun 2023 18:33:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE=20?= =?UTF-8?q?-=20=E7=BB=88=E7=AB=AF=E8=AE=BE=E7=BD=AE=20-=20=E7=AB=AF?= =?UTF-8?q?=E7=82=B9=E8=A7=84=E5=88=99:=20=E6=96=B0=E5=A2=9E=E5=AD=97?= =?UTF-8?q?=E6=AE=B5is=5Factive=E6=8E=A7=E5=88=B6=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=90=AF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0050_auto_20220606_1745.py | 4 ++-- .../migrations/0063_auto_20230621_1133.py | 22 +++++++++++++++++++ apps/terminal/models/component/endpoint.py | 5 +++-- apps/terminal/serializers/endpoint.py | 2 +- 4 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 apps/terminal/migrations/0063_auto_20230621_1133.py diff --git a/apps/terminal/migrations/0050_auto_20220606_1745.py b/apps/terminal/migrations/0050_auto_20220606_1745.py index d0eb6ea5d..a47defba9 100644 --- a/apps/terminal/migrations/0050_auto_20220606_1745.py +++ b/apps/terminal/migrations/0050_auto_20220606_1745.py @@ -15,7 +15,7 @@ class Migration(migrations.Migration): field=models.CharField( choices=[('koko', 'KoKo'), ('guacamole', 'Guacamole'), ('omnidb', 'OmniDB'), ('xrdp', 'Xrdp'), ('lion', 'Lion'), ('core', 'Core'), ('celery', 'Celery'), ('magnus', 'Magnus'), - ('razor', 'Razor'), ('tinker', 'Tinker'), ('video_worker', 'Video Worker')], default='koko', - max_length=64, verbose_name='type'), + ('razor', 'Razor'), ('tinker', 'Tinker'), ('video_worker', 'Video Worker'), ('chen', 'Chen')], + default='koko', max_length=64, verbose_name='type'), ), ] diff --git a/apps/terminal/migrations/0063_auto_20230621_1133.py b/apps/terminal/migrations/0063_auto_20230621_1133.py new file mode 100644 index 000000000..85553e8f3 --- /dev/null +++ b/apps/terminal/migrations/0063_auto_20230621_1133.py @@ -0,0 +1,22 @@ +# Generated by Django 3.2.19 on 2023-06-21 10:25 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('terminal', '0062_applet_edition'), + ] + + operations = [ + migrations.AlterModelOptions( + name='endpointrule', + options={'ordering': ('priority', 'is_active', 'name'), 'verbose_name': 'Endpoint rule'}, + ), + migrations.AddField( + model_name='endpointrule', + name='is_active', + field=models.BooleanField(default=True, verbose_name='Is active'), + ), + ] diff --git a/apps/terminal/models/component/endpoint.py b/apps/terminal/models/component/endpoint.py index c5aab12d9..f19f72949 100644 --- a/apps/terminal/models/component/endpoint.py +++ b/apps/terminal/models/component/endpoint.py @@ -98,17 +98,18 @@ class EndpointRule(JMSBaseModel): on_delete=models.SET_NULL, verbose_name=_("Endpoint"), ) comment = models.TextField(default='', blank=True, verbose_name=_('Comment')) + is_active = models.BooleanField(default=True, verbose_name=_('Is active')) class Meta: verbose_name = _('Endpoint rule') - ordering = ('priority', 'name') + ordering = ('priority', 'is_active', 'name') def __str__(self): return f'{self.name}({self.priority})' @classmethod def match(cls, target_instance, target_ip, protocol): - for endpoint_rule in cls.objects.all().prefetch_related('endpoint'): + for endpoint_rule in cls.objects.prefetch_related('endpoint').filter(is_active=True): if not contains_ip(target_ip, endpoint_rule.ip_group): continue if not endpoint_rule.endpoint: diff --git a/apps/terminal/serializers/endpoint.py b/apps/terminal/serializers/endpoint.py index d7534adeb..82de09fce 100644 --- a/apps/terminal/serializers/endpoint.py +++ b/apps/terminal/serializers/endpoint.py @@ -79,7 +79,7 @@ class EndpointRuleSerializer(BulkModelSerializer): fields_small = fields_mini + ['ip_group', 'priority'] fields_fk = ['endpoint'] fields = fields_mini + fields_small + fields_fk + [ - 'comment', 'date_created', 'date_updated', 'created_by' + 'comment', 'date_created', 'date_updated', 'created_by', 'is_active' ] extra_kwargs = { 'priority': {'default': 50}