mirror of https://github.com/jumpserver/jumpserver
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,7 +42,10 @@ 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)
|
||||||
self.sync_accounts_secret(instance, diff)
|
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)
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue