mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-01-09 20:01:18 +00:00
Get exists from actions annotations fallback to exists()
This commit is contained in:
@@ -22,7 +22,8 @@ def apply_assignment_to_document(
|
||||
"""
|
||||
Apply assignment actions to a Document instance.
|
||||
"""
|
||||
if action.assign_tags.exists():
|
||||
has_assign_tags = getattr(action, "has_assign_tags", action.assign_tags.exists())
|
||||
if has_assign_tags:
|
||||
tag_ids_to_add: set[int] = set()
|
||||
for tag in action.assign_tags.all():
|
||||
tag_ids_to_add.add(tag.pk)
|
||||
@@ -60,12 +61,33 @@ def apply_assignment_to_document(
|
||||
extra={"group": logging_group},
|
||||
)
|
||||
|
||||
has_assign_view_users = getattr(
|
||||
action,
|
||||
"has_assign_view_users",
|
||||
action.assign_view_users.exists(),
|
||||
)
|
||||
has_assign_view_groups = getattr(
|
||||
action,
|
||||
"has_assign_view_groups",
|
||||
action.assign_view_groups.exists(),
|
||||
)
|
||||
has_assign_change_users = getattr(
|
||||
action,
|
||||
"has_assign_change_users",
|
||||
action.assign_change_users.exists(),
|
||||
)
|
||||
has_assign_change_groups = getattr(
|
||||
action,
|
||||
"has_assign_change_groups",
|
||||
action.assign_change_groups.exists(),
|
||||
)
|
||||
|
||||
if any(
|
||||
[
|
||||
action.assign_view_users.exists(),
|
||||
action.assign_view_groups.exists(),
|
||||
action.assign_change_users.exists(),
|
||||
action.assign_change_groups.exists(),
|
||||
has_assign_view_users,
|
||||
has_assign_view_groups,
|
||||
has_assign_change_users,
|
||||
has_assign_change_groups,
|
||||
],
|
||||
):
|
||||
permissions = {
|
||||
@@ -84,7 +106,13 @@ def apply_assignment_to_document(
|
||||
merge=True,
|
||||
)
|
||||
|
||||
if action.assign_custom_fields.exists():
|
||||
has_assign_custom_fields = getattr(
|
||||
action,
|
||||
"has_assign_custom_fields",
|
||||
action.assign_custom_fields.exists(),
|
||||
)
|
||||
|
||||
if has_assign_custom_fields:
|
||||
for field in action.assign_custom_fields.all():
|
||||
value_field_name = CustomFieldInstance.get_value_field_name(
|
||||
data_type=field.data_type,
|
||||
@@ -118,7 +146,8 @@ def apply_assignment_to_overrides(
|
||||
"""
|
||||
Apply assignment actions to DocumentMetadataOverrides.
|
||||
"""
|
||||
if action.assign_tags.exists():
|
||||
has_assign_tags = getattr(action, "has_assign_tags", action.assign_tags.exists())
|
||||
if has_assign_tags:
|
||||
if overrides.tag_ids is None:
|
||||
overrides.tag_ids = []
|
||||
tag_ids_to_add: set[int] = set()
|
||||
@@ -143,12 +172,33 @@ def apply_assignment_to_overrides(
|
||||
if action.assign_title:
|
||||
overrides.title = action.assign_title
|
||||
|
||||
has_assign_view_users = getattr(
|
||||
action,
|
||||
"has_assign_view_users",
|
||||
action.assign_view_users.exists(),
|
||||
)
|
||||
has_assign_view_groups = getattr(
|
||||
action,
|
||||
"has_assign_view_groups",
|
||||
action.assign_view_groups.exists(),
|
||||
)
|
||||
has_assign_change_users = getattr(
|
||||
action,
|
||||
"has_assign_change_users",
|
||||
action.assign_change_users.exists(),
|
||||
)
|
||||
has_assign_change_groups = getattr(
|
||||
action,
|
||||
"has_assign_change_groups",
|
||||
action.assign_change_groups.exists(),
|
||||
)
|
||||
|
||||
if any(
|
||||
[
|
||||
action.assign_view_users.exists(),
|
||||
action.assign_view_groups.exists(),
|
||||
action.assign_change_users.exists(),
|
||||
action.assign_change_groups.exists(),
|
||||
has_assign_view_users,
|
||||
has_assign_view_groups,
|
||||
has_assign_change_users,
|
||||
has_assign_change_groups,
|
||||
],
|
||||
):
|
||||
overrides.view_users = list(
|
||||
@@ -176,7 +226,13 @@ def apply_assignment_to_overrides(
|
||||
),
|
||||
)
|
||||
|
||||
if action.assign_custom_fields.exists():
|
||||
has_assign_custom_fields = getattr(
|
||||
action,
|
||||
"has_assign_custom_fields",
|
||||
action.assign_custom_fields.exists(),
|
||||
)
|
||||
|
||||
if has_assign_custom_fields:
|
||||
if overrides.custom_fields is None:
|
||||
overrides.custom_fields = {}
|
||||
overrides.custom_fields.update(
|
||||
@@ -242,12 +298,33 @@ def apply_removal_to_document(
|
||||
object=document,
|
||||
merge=False,
|
||||
)
|
||||
elif any(
|
||||
has_remove_view_users = getattr(
|
||||
action,
|
||||
"has_remove_view_users",
|
||||
action.remove_view_users.exists(),
|
||||
)
|
||||
has_remove_view_groups = getattr(
|
||||
action,
|
||||
"has_remove_view_groups",
|
||||
action.remove_view_groups.exists(),
|
||||
)
|
||||
has_remove_change_users = getattr(
|
||||
action,
|
||||
"has_remove_change_users",
|
||||
action.remove_change_users.exists(),
|
||||
)
|
||||
has_remove_change_groups = getattr(
|
||||
action,
|
||||
"has_remove_change_groups",
|
||||
action.remove_change_groups.exists(),
|
||||
)
|
||||
|
||||
if any(
|
||||
[
|
||||
action.remove_view_users.exists(),
|
||||
action.remove_view_groups.exists(),
|
||||
action.remove_change_users.exists(),
|
||||
action.remove_change_groups.exists(),
|
||||
has_remove_view_users,
|
||||
has_remove_view_groups,
|
||||
has_remove_change_users,
|
||||
has_remove_change_groups,
|
||||
],
|
||||
):
|
||||
for user in action.remove_view_users.all():
|
||||
@@ -259,9 +336,14 @@ def apply_removal_to_document(
|
||||
for group in action.remove_change_groups.all():
|
||||
remove_perm("change_document", group, document)
|
||||
|
||||
has_remove_custom_fields = getattr(
|
||||
action,
|
||||
"has_remove_custom_fields",
|
||||
action.remove_custom_fields.exists(),
|
||||
)
|
||||
if action.remove_all_custom_fields:
|
||||
CustomFieldInstance.objects.filter(document=document).hard_delete()
|
||||
elif action.remove_custom_fields.exists():
|
||||
elif has_remove_custom_fields:
|
||||
CustomFieldInstance.objects.filter(
|
||||
field__in=action.remove_custom_fields.all(),
|
||||
document=document,
|
||||
@@ -309,6 +391,27 @@ def apply_removal_to_overrides(
|
||||
):
|
||||
overrides.owner_id = None
|
||||
|
||||
has_remove_view_users = getattr(
|
||||
action,
|
||||
"has_remove_view_users",
|
||||
action.remove_view_users.exists(),
|
||||
)
|
||||
has_remove_view_groups = getattr(
|
||||
action,
|
||||
"has_remove_view_groups",
|
||||
action.remove_view_groups.exists(),
|
||||
)
|
||||
has_remove_change_users = getattr(
|
||||
action,
|
||||
"has_remove_change_users",
|
||||
action.remove_change_users.exists(),
|
||||
)
|
||||
has_remove_change_groups = getattr(
|
||||
action,
|
||||
"has_remove_change_groups",
|
||||
action.remove_change_groups.exists(),
|
||||
)
|
||||
|
||||
if action.remove_all_permissions:
|
||||
overrides.view_users = None
|
||||
overrides.view_groups = None
|
||||
@@ -316,10 +419,10 @@ def apply_removal_to_overrides(
|
||||
overrides.change_groups = None
|
||||
elif any(
|
||||
[
|
||||
action.remove_view_users.exists(),
|
||||
action.remove_view_groups.exists(),
|
||||
action.remove_change_users.exists(),
|
||||
action.remove_change_groups.exists(),
|
||||
has_remove_view_users,
|
||||
has_remove_view_groups,
|
||||
has_remove_change_users,
|
||||
has_remove_change_groups,
|
||||
],
|
||||
):
|
||||
if overrides.view_users:
|
||||
@@ -339,9 +442,15 @@ def apply_removal_to_overrides(
|
||||
):
|
||||
overrides.change_groups.remove(group.pk)
|
||||
|
||||
has_remove_custom_fields = getattr(
|
||||
action,
|
||||
"has_remove_custom_fields",
|
||||
action.remove_custom_fields.exists(),
|
||||
)
|
||||
|
||||
if action.remove_all_custom_fields:
|
||||
overrides.custom_fields = None
|
||||
elif action.remove_custom_fields.exists() and overrides.custom_fields:
|
||||
elif has_remove_custom_fields and overrides.custom_fields:
|
||||
for field in action.remove_custom_fields.filter(
|
||||
pk__in=overrides.custom_fields.keys(),
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user