diff --git a/apps/assets/backends/db.py b/apps/assets/backends/db.py index f702060fb..40fa41444 100644 --- a/apps/assets/backends/db.py +++ b/apps/assets/backends/db.py @@ -26,5 +26,4 @@ class AuthBookBackend(BaseBackend): } obj = AuthBook.objects.create(**kwargs) obj.set_auth(**auth_info) - obj.set_version_and_latest() return obj diff --git a/apps/assets/models/authbook.py b/apps/assets/models/authbook.py index 991729250..0243b43fb 100644 --- a/apps/assets/models/authbook.py +++ b/apps/assets/models/authbook.py @@ -60,10 +60,6 @@ class AuthBook(AssetUser): self.version = 1 self.save() - def set_version_and_latest(self): - self.set_version() - self.set_to_latest() - def get_related_assets(self): return [self.asset] diff --git a/apps/assets/serializers/asset_user.py b/apps/assets/serializers/asset_user.py index 18b5ea982..1e05b8f5b 100644 --- a/apps/assets/serializers/asset_user.py +++ b/apps/assets/serializers/asset_user.py @@ -53,7 +53,7 @@ class AssetUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer): if not validated_data.get("name") and validated_data.get("username"): validated_data["name"] = validated_data["username"] instance = AssetUserManager.create(**validated_data) - instance.set_version_and_latest() + instance.set_to_latest() return instance diff --git a/apps/assets/signals_handler.py b/apps/assets/signals_handler.py index ea5f8f4ad..594da38b7 100644 --- a/apps/assets/signals_handler.py +++ b/apps/assets/signals_handler.py @@ -9,7 +9,7 @@ from django.dispatch import receiver from common.utils import get_logger, timeit from common.decorator import on_transaction_commit -from .models import Asset, SystemUser, Node +from .models import Asset, SystemUser, Node, AuthBook from .tasks import ( update_assets_hardware_info_util, test_asset_connectivity_util, @@ -189,3 +189,9 @@ def on_asset_nodes_remove(sender, instance=None, action='', model=None, def on_node_update_or_created(sender, **kwargs): # 刷新节点 Node.refresh_nodes() + + +@receiver(post_save, sender=AuthBook) +def on_authbook_created(sender, instance=None, created=True, **kwargs): + if created and instance: + instance.set_version()