mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-07-19 09:16:57 +00:00
perf: 账号模版更新时, 优化同步更新账号逻辑 (#10611)
Co-authored-by: feng <1304903146@qq.com>
This commit is contained in:
parent
ed117ceac3
commit
9d8c1bb317
@ -23,8 +23,12 @@ class AccountTemplateSerializer(BaseAccountSerializer):
|
|||||||
def sync_accounts_secret(self, instance, diff):
|
def sync_accounts_secret(self, instance, diff):
|
||||||
if not self._is_sync_account or 'secret' not in diff:
|
if not self._is_sync_account or 'secret' not in diff:
|
||||||
return
|
return
|
||||||
|
query_data = {
|
||||||
accounts = Account.objects.filter(source_id=instance.id)
|
'source_id': instance.id,
|
||||||
|
'username': instance.username,
|
||||||
|
'secret_type': instance.secret_type
|
||||||
|
}
|
||||||
|
accounts = Account.objects.filter(**query_data)
|
||||||
instance.bulk_sync_account_secret(accounts, self.context['request'].user.id)
|
instance.bulk_sync_account_secret(accounts, self.context['request'].user.id)
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
@ -38,6 +42,9 @@ class AccountTemplateSerializer(BaseAccountSerializer):
|
|||||||
if getattr(instance, k, None) != v
|
if getattr(instance, k, None) != v
|
||||||
}
|
}
|
||||||
instance = super().update(instance, validated_data)
|
instance = super().update(instance, validated_data)
|
||||||
|
if {'username', 'secret_type'} & set(diff.keys()):
|
||||||
|
Account.objects.filter(source_id=instance.id).update(source_id=None)
|
||||||
|
else:
|
||||||
self.sync_accounts_secret(instance, diff)
|
self.sync_accounts_secret(instance, diff)
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user