mirror of https://github.com/jumpserver/jumpserver
commit
c4fb3a8c04
|
@ -5,7 +5,6 @@ from django.db.models.signals import (
|
|||
)
|
||||
from django.dispatch import receiver
|
||||
|
||||
from orgs.utils import ensure_in_real_or_default_org
|
||||
from common.const.signals import POST_ADD, POST_REMOVE, PRE_REMOVE
|
||||
from common.utils import get_logger
|
||||
from common.decorator import on_transaction_commit
|
||||
|
@ -19,12 +18,6 @@ from assets.tasks import (
|
|||
logger = get_logger(__file__)
|
||||
|
||||
|
||||
@receiver(m2m_changed, sender=SystemUser.assets.through)
|
||||
@ensure_in_real_or_default_org
|
||||
def on_asset_system_user_change(sender, **kwargs):
|
||||
pass
|
||||
|
||||
|
||||
def update_asset_hardware_info_on_created(asset):
|
||||
logger.debug("Update asset `{}` hardware info".format(asset))
|
||||
update_assets_hardware_info_util.delay([asset])
|
||||
|
|
|
@ -12,7 +12,7 @@ logger = get_logger(__name__)
|
|||
|
||||
|
||||
@receiver(pre_create_historical_record, sender=AuthBookHistory)
|
||||
def pre_create_historical_record_callback(sender, instance=None, history_instance=None, **kwargs):
|
||||
def pre_create_historical_record_callback(sender, history_instance=None, **kwargs):
|
||||
attrs_to_copy = ['username', 'password', 'private_key']
|
||||
|
||||
for attr in attrs_to_copy:
|
||||
|
@ -48,3 +48,5 @@ def on_authbook_post_create(sender, instance, **kwargs):
|
|||
def on_authbook_pre_create(sender, instance, **kwargs):
|
||||
# 升级版本号
|
||||
instance.version = instance.history.all().count() + 1
|
||||
# 即使在 root 组织也不怕
|
||||
instance.org_id = instance.asset.org_id
|
||||
|
|
|
@ -11,7 +11,7 @@ from common.utils import get_logger
|
|||
from common.decorator import on_transaction_commit
|
||||
from assets.models import Asset, SystemUser, Node, AuthBook
|
||||
from users.models import User
|
||||
from orgs.utils import get_current_org, tmp_to_root_org
|
||||
from orgs.utils import tmp_to_root_org
|
||||
from assets.tasks import (
|
||||
push_system_user_to_assets_manual,
|
||||
push_system_user_to_assets,
|
||||
|
@ -40,14 +40,16 @@ def on_system_user_assets_change(instance, action, model, pk_set, **kwargs):
|
|||
system_user_ids = pk_set
|
||||
asset_ids = [instance.id]
|
||||
|
||||
# 通过 through 创建的没有 org_id
|
||||
current_org_id = get_current_org().id
|
||||
org_id = instance.org_id
|
||||
|
||||
# 关联创建的 authbook 没有系统用户id
|
||||
with tmp_to_root_org():
|
||||
authbooks = AuthBook.objects.filter(
|
||||
asset_id__in=asset_ids,
|
||||
systemuser_id__in=system_user_ids
|
||||
)
|
||||
authbooks.update(org_id=current_org_id)
|
||||
if action == POST_ADD:
|
||||
authbooks.update(org_id=org_id)
|
||||
|
||||
save_action_mapper = {
|
||||
'pre_add': pre_save,
|
||||
|
@ -57,13 +59,13 @@ def on_system_user_assets_change(instance, action, model, pk_set, **kwargs):
|
|||
}
|
||||
|
||||
for ab in authbooks:
|
||||
ab.org_id = current_org_id
|
||||
ab.org_id = org_id
|
||||
|
||||
post_action = save_action_mapper[action]
|
||||
save_action = save_action_mapper[action]
|
||||
logger.debug('Send AuthBook post save signal: {} -> {}'.format(action, ab.id))
|
||||
post_action.send(sender=AuthBook, instance=ab, created=True)
|
||||
save_action.send(sender=AuthBook, instance=ab, created=True)
|
||||
|
||||
if action == 'post_add':
|
||||
if action == POST_ADD:
|
||||
for system_user_id in system_user_ids:
|
||||
push_system_user_to_assets.delay(system_user_id, asset_ids)
|
||||
|
||||
|
|
Loading…
Reference in New Issue