mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-24 01:06:17 +00:00
Feature: option for auto-remove inbox tags on save (#5562)
This commit is contained in:
@@ -638,6 +638,11 @@ class DocumentSerializer(
|
||||
allow_null=True,
|
||||
)
|
||||
|
||||
remove_inbox_tags = serializers.BooleanField(
|
||||
default=False,
|
||||
write_only=True,
|
||||
)
|
||||
|
||||
def get_original_file_name(self, obj):
|
||||
return obj.original_filename
|
||||
|
||||
@@ -681,12 +686,48 @@ class DocumentSerializer(
|
||||
custom_field_instance.field,
|
||||
doc_id,
|
||||
)
|
||||
if (
|
||||
"remove_inbox_tags" in validated_data
|
||||
and validated_data["remove_inbox_tags"]
|
||||
):
|
||||
tag_ids_being_added = (
|
||||
[
|
||||
tag.id
|
||||
for tag in validated_data["tags"]
|
||||
if tag not in instance.tags.all()
|
||||
]
|
||||
if "tags" in validated_data
|
||||
else []
|
||||
)
|
||||
inbox_tags_not_being_added = Tag.objects.filter(is_inbox_tag=True).exclude(
|
||||
id__in=tag_ids_being_added,
|
||||
)
|
||||
if "tags" in validated_data:
|
||||
validated_data["tags"] = [
|
||||
tag
|
||||
for tag in validated_data["tags"]
|
||||
if tag not in inbox_tags_not_being_added
|
||||
]
|
||||
else:
|
||||
validated_data["tags"] = [
|
||||
tag
|
||||
for tag in instance.tags.all()
|
||||
if tag not in inbox_tags_not_being_added
|
||||
]
|
||||
super().update(instance, validated_data)
|
||||
return instance
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.truncate_content = kwargs.pop("truncate_content", False)
|
||||
|
||||
# return full permissions if we're doing a PATCH or PUT
|
||||
context = kwargs.get("context")
|
||||
if (
|
||||
context.get("request").method == "PATCH"
|
||||
or context.get("request").method == "PUT"
|
||||
):
|
||||
kwargs["full_perms"] = True
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
class Meta:
|
||||
@@ -714,6 +755,7 @@ class DocumentSerializer(
|
||||
"set_permissions",
|
||||
"notes",
|
||||
"custom_fields",
|
||||
"remove_inbox_tags",
|
||||
)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user