-
Notifications
You must be signed in to change notification settings - Fork 81
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
results: added support for drafts #1700
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,10 @@ | |
from invenio_communities.communities.entity_resolvers import pick_fields | ||
from invenio_communities.communities.schema import CommunityGhostSchema | ||
from invenio_communities.proxies import current_communities | ||
from invenio_records_resources.services.records.results import ExpandableField | ||
from invenio_records_resources.services.records.results import ( | ||
ExpandableField, | ||
RecordList, | ||
) | ||
from invenio_users_resources.proxies import current_user_resources | ||
|
||
from .dummy import DummyExpandingService | ||
|
@@ -69,3 +72,33 @@ def get_value_service(self, value): | |
def pick(self, identity, resolved_rec): | ||
"""Pick fields defined in the entity resolver.""" | ||
return resolved_rec | ||
|
||
|
||
class RDMRecordList(RecordList): | ||
"""Record list with custom fields.""" | ||
|
||
@property | ||
def hits(self): | ||
"""Iterator over the hits.""" | ||
for hit in self._results: | ||
# Load dump | ||
record_dict = hit.to_dict() | ||
if record_dict["is_published"]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: wouldn't it be better to rely on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's what caused the issue in the first place. the "search" method can be used for drafts or records, however, the method lives inside the record's service. So using |
||
record = self._service.record_cls.loads(record_dict) | ||
else: | ||
record = self._service.draft_cls.loads(record_dict) | ||
|
||
# Project the record | ||
projection = self._schema.dump( | ||
record, | ||
context=dict( | ||
identity=self._identity, | ||
record=record, | ||
), | ||
) | ||
if self._links_item_tpl: | ||
projection["links"] = self._links_item_tpl.expand( | ||
self._identity, record | ||
) | ||
|
||
yield projection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue was that drafts are searched through the records service, which in turn uses the default
RecordList
class to project the search results.The default implementation uses
self._service.record_cls
unconditionally, which in turn projects the result always to a record. This is not correct if the service shares the search for records and drafts. For instance, an unpublished draft always had the attributeis_draft=False
because the attributeis_draft
of aRecord
is always set toFalse
.