feat: 系统设置 - 终端设置 - 端点规则: 新增字段is_active控制是否启用

pull/10806/head
fangfang.dong 1 year ago
parent b2bff22387
commit b2ee8c8216

@ -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'),
),
]

@ -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'),
),
]

@ -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:

@ -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}

Loading…
Cancel
Save