Merge pull request #10806 from jumpserver/pr@dev@feat_terminal_endpointrule

feat: 系统设置 - 终端设置 - 端点规则: 新增字段is_active控制是否启用
This commit is contained in:
老广 2023-06-21 18:36:37 +08:00 committed by GitHub
commit eeba0a4bfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 5 deletions

View File

@ -15,7 +15,7 @@ class Migration(migrations.Migration):
field=models.CharField( field=models.CharField(
choices=[('koko', 'KoKo'), ('guacamole', 'Guacamole'), ('omnidb', 'OmniDB'), ('xrdp', 'Xrdp'), choices=[('koko', 'KoKo'), ('guacamole', 'Guacamole'), ('omnidb', 'OmniDB'), ('xrdp', 'Xrdp'),
('lion', 'Lion'), ('core', 'Core'), ('celery', 'Celery'), ('magnus', 'Magnus'), ('lion', 'Lion'), ('core', 'Core'), ('celery', 'Celery'), ('magnus', 'Magnus'),
('razor', 'Razor'), ('tinker', 'Tinker'), ('video_worker', 'Video Worker')], default='koko', ('razor', 'Razor'), ('tinker', 'Tinker'), ('video_worker', 'Video Worker'), ('chen', 'Chen')],
max_length=64, verbose_name='type'), default='koko', max_length=64, verbose_name='type'),
), ),
] ]

View File

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

View File

@ -98,17 +98,18 @@ class EndpointRule(JMSBaseModel):
on_delete=models.SET_NULL, verbose_name=_("Endpoint"), on_delete=models.SET_NULL, verbose_name=_("Endpoint"),
) )
comment = models.TextField(default='', blank=True, verbose_name=_('Comment')) comment = models.TextField(default='', blank=True, verbose_name=_('Comment'))
is_active = models.BooleanField(default=True, verbose_name=_('Is active'))
class Meta: class Meta:
verbose_name = _('Endpoint rule') verbose_name = _('Endpoint rule')
ordering = ('priority', 'name') ordering = ('priority', 'is_active', 'name')
def __str__(self): def __str__(self):
return f'{self.name}({self.priority})' return f'{self.name}({self.priority})'
@classmethod @classmethod
def match(cls, target_instance, target_ip, protocol): 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): if not contains_ip(target_ip, endpoint_rule.ip_group):
continue continue
if not endpoint_rule.endpoint: if not endpoint_rule.endpoint:

View File

@ -79,7 +79,7 @@ class EndpointRuleSerializer(BulkModelSerializer):
fields_small = fields_mini + ['ip_group', 'priority'] fields_small = fields_mini + ['ip_group', 'priority']
fields_fk = ['endpoint'] fields_fk = ['endpoint']
fields = fields_mini + fields_small + fields_fk + [ 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 = { extra_kwargs = {
'priority': {'default': 50} 'priority': {'default': 50}