mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
one-way imap password setting via API, ObfuscatedPasswordField
This commit is contained in:
parent
ea1ea0816f
commit
2849414445
@ -692,7 +692,21 @@ class AcknowledgeTasksViewSerializer(serializers.Serializer):
|
|||||||
return tasks
|
return tasks
|
||||||
|
|
||||||
|
|
||||||
|
class ObfuscatedPasswordField(serializers.Field):
|
||||||
|
"""
|
||||||
|
Sends *** string instead of password in the clear
|
||||||
|
"""
|
||||||
|
|
||||||
|
def to_representation(self, value):
|
||||||
|
return re.sub(".", "*", value)
|
||||||
|
|
||||||
|
def to_internal_value(self, data):
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
class MailAccountSerializer(serializers.ModelSerializer):
|
class MailAccountSerializer(serializers.ModelSerializer):
|
||||||
|
password = ObfuscatedPasswordField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = MailAccount
|
model = MailAccount
|
||||||
depth = 1
|
depth = 1
|
||||||
@ -708,6 +722,9 @@ class MailAccountSerializer(serializers.ModelSerializer):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def update(self, instance, validated_data):
|
def update(self, instance, validated_data):
|
||||||
|
if "password" in validated_data:
|
||||||
|
if len(validated_data.get("password").replace("*", "")) == 0:
|
||||||
|
validated_data.pop("password")
|
||||||
super().update(instance, validated_data)
|
super().update(instance, validated_data)
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user