mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-07-05 02:56:31 +00:00
perf: 修改 account signal version
This commit is contained in:
parent
9cd0a348fc
commit
f046ea3560
@ -2,10 +2,10 @@ from django.db import models
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from simple_history.models import HistoricalRecords
|
from simple_history.models import HistoricalRecords
|
||||||
|
|
||||||
from common.utils import lazyproperty
|
|
||||||
from ..const import AliasAccount, Source
|
|
||||||
from assets.models.base import AbsConnectivity
|
from assets.models.base import AbsConnectivity
|
||||||
|
from common.utils import lazyproperty
|
||||||
from .base import BaseAccount
|
from .base import BaseAccount
|
||||||
|
from ..const import AliasAccount, Source
|
||||||
|
|
||||||
__all__ = ['Account', 'AccountTemplate']
|
__all__ = ['Account', 'AccountTemplate']
|
||||||
|
|
||||||
@ -98,6 +98,14 @@ class Account(AbsConnectivity, BaseAccount):
|
|||||||
""" 排除自己和以自己为 su-from 的账号 """
|
""" 排除自己和以自己为 su-from 的账号 """
|
||||||
return self.asset.accounts.exclude(id=self.id).exclude(su_from=self)
|
return self.asset.accounts.exclude(id=self.id).exclude(su_from=self)
|
||||||
|
|
||||||
|
def secret_changed(self):
|
||||||
|
history = self.history.first()
|
||||||
|
if not history:
|
||||||
|
return True
|
||||||
|
if history.secret != self.secret or history.secret_type != self.secret_type:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class AccountTemplate(BaseAccount):
|
class AccountTemplate(BaseAccount):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
from django.db.models.signals import post_save
|
|
||||||
from django.db.models.signals import pre_save
|
from django.db.models.signals import pre_save
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
|
|
||||||
from assets.models import Asset
|
|
||||||
from common.decorators import on_transaction_commit
|
|
||||||
from common.utils import get_logger
|
from common.utils import get_logger
|
||||||
from .models import Account
|
from .models import Account
|
||||||
|
|
||||||
@ -11,16 +8,10 @@ logger = get_logger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
@receiver(pre_save, sender=Account)
|
@receiver(pre_save, sender=Account)
|
||||||
def on_account_pre_create(sender, instance, **kwargs):
|
def on_account_pre_create(sender, instance, update_fields=(), **kwargs):
|
||||||
# 升级版本号
|
# 这是创建时
|
||||||
|
if instance.version == 0 or instance.secret_changed():
|
||||||
instance.version += 1
|
instance.version += 1
|
||||||
|
|
||||||
# 即使在 root 组织也不怕
|
# 即使在 root 组织也不怕
|
||||||
instance.org_id = instance.asset.org_id
|
instance.org_id = instance.asset.org_id
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=Asset)
|
|
||||||
@on_transaction_commit
|
|
||||||
def on_asset_create(sender, instance, created=False, **kwargs):
|
|
||||||
if not created:
|
|
||||||
return
|
|
||||||
# PushAccountManager.trigger_by_asset_create(instance)
|
|
||||||
|
@ -227,7 +227,7 @@ class Migration(migrations.Migration):
|
|||||||
verbose_name='Creator')),
|
verbose_name='Creator')),
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
'verbose_name': 'AdHoc',
|
'verbose_name': 'Adhoc',
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
|
Loading…
Reference in New Issue
Block a user