Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IfRecordDeleted: a more precise query for deletion status #1968

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions invenio_rdm_records/services/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
from functools import partial, reduce
from itertools import chain

from flask import g
from flask_principal import UserNeed
from invenio_communities.config import COMMUNITIES_ROLES
from invenio_communities.generators import CommunityRoleNeed, CommunityRoles
from invenio_communities.proxies import current_roles
from invenio_records_permissions.generators import ConditionalGenerator, Generator
Expand All @@ -26,7 +24,6 @@
from ..records import RDMDraft
from ..records.systemfields.access.grants import Grant
from ..records.systemfields.deletion_status import RecordDeletionStatusEnum
from ..requests import CommunityInclusion
from ..requests.access import AccessRequestTokenNeed
from ..tokens.permissions import RATNeed

Expand Down Expand Up @@ -184,21 +181,21 @@ def make_query(self, generators, **kwargs):

def query_filter(self, **kwargs):
"""Filters for current identity."""
q_then = dsl.Q("match_all")
q_else = dsl.Q(
q_record_not_deleted = dsl.Q(
"term", **{"deletion_status": RecordDeletionStatusEnum.PUBLISHED.value}
)
q_record_deleted = ~q_record_not_deleted
then_query = self.make_query(self.then_, **kwargs)
else_query = self.make_query(self.else_, **kwargs)

if then_query and else_query:
return (q_then & then_query) | (q_else & else_query)
return (q_record_deleted & then_query) | (q_record_not_deleted & else_query)
elif then_query:
return (q_then & then_query) | q_else
return (q_record_deleted & then_query) | q_record_not_deleted
elif else_query:
return q_else & else_query
return q_record_not_deleted & else_query
else:
return q_else
return q_record_not_deleted


class RecordOwners(Generator):
Expand Down
Loading