jumpserver/apps/terminal/signal_handlers.py

27 lines
690 B
Python
Raw Normal View History

2017-12-29 18:29:29 +00:00
# -*- coding: utf-8 -*-
#
2022-11-01 10:40:42 +00:00
from django.db.models.signals import post_save
from django.dispatch import receiver
2022-11-08 02:41:06 +00:00
from orgs.utils import tmp_to_builtin_org
2022-11-01 10:40:42 +00:00
from .models import Applet, AppletHost
@receiver(post_save, sender=AppletHost)
def on_applet_host_create(sender, instance, created=False, **kwargs):
2022-11-01 12:37:04 +00:00
if not created:
return
applets = Applet.objects.all()
instance.applets.set(applets)
2022-11-08 02:41:06 +00:00
with tmp_to_builtin_org(system=1):
instance.generate_accounts()
2022-11-01 10:40:42 +00:00
@receiver(post_save, sender=Applet)
def on_applet_create(sender, instance, created=False, **kwargs):
2022-11-01 12:37:04 +00:00
if not created:
return
hosts = AppletHost.objects.all()
instance.hosts.set(hosts)