Skip to content

Commit 2bb29f3

Browse files
committed
feat(views): Display 'accepted version' on communities tab if no request
* This change adds a "View comments" link for the new versions of an already accepted record * The 'accepted version' indicates that the link points to the exact request related to the actual record that was accepted * fix(RecordCommunitiesList): Fix component structuring
1 parent 655befe commit 2bb29f3

2 files changed

Lines changed: 67 additions & 51 deletions

File tree

invenio_app_rdm/records_ui/views/records.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ def get_record_community(record):
108108
def get_record_requests(record, identity):
109109
"""Return all requests that concern this record.
110110
111-
Output: {<Community-UUID>: <Request-UUID>}
111+
Output: {<Community-UUID>: {'request_id': <Request-UUID>, 'is_current': boolean}}
112+
The boolean indicates if the request is the current record's request.
112113
"""
113114
can_review = current_rdm_records.records_service.check_permission(
114115
identity, "review", record=record._record
@@ -119,6 +120,17 @@ def get_record_requests(record, identity):
119120
if type(identity) is AnonymousIdentity:
120121
return {} # secret link users do not have permissions to search requests
121122

123+
# Get all accepted requests that led to the record being added to the community
124+
parent = record._record.parent
125+
community_requests = parent.communities.get_accepted_requests()
126+
community_requests = {
127+
str(r.community_id): {"request_id": str(r.request_id), "is_current": False}
128+
for r in community_requests
129+
}
130+
131+
# Get the requests that concern only the current record, i.e. submission or inclusion regardless of their status
132+
# This takes precedence over only considering accepted requests because there may be an unaccepted request in this
133+
# version of the record that should be shown instead of the accepted request.
122134
record_requests = current_requests_service.search(
123135
identity,
124136
extra_filter=dsl.Q(
@@ -138,8 +150,14 @@ def get_record_requests(record, identity):
138150
),
139151
params={"sort": "oldest"},
140152
)
153+
record_requests = {
154+
r["receiver"]["community"]: {"request_id": r["id"], "is_current": True}
155+
for r in record_requests
156+
}
141157

142-
return {r["receiver"]["community"]: r["id"] for r in record_requests}
158+
community_requests.update(record_requests)
159+
# Return a dictionary with the community id mapped to a dictionary with the request id and a boolean indicating if it is the current record request
160+
return community_requests
143161

144162

145163
class PreviewFile:

invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/landing_page/RecordCommunitiesList.js

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -66,56 +66,54 @@ export class RecordCommunitiesList extends Component {
6666
<Image wrapped size="mini" src={community.links.logo} alt="" />
6767
</Grid.Column>
6868
<Grid.Column width={13} className="pl-0">
69-
<Item.Content>
70-
<Item.Header className="ui">
71-
<Header as="a" href={community.links.self_html} size="small">
72-
{community.metadata.title}
73-
{/* Show the icon for communities allowing children, and for subcommunities */}
74-
{(community.children?.allow ||
75-
community.parent !== undefined) && (
76-
<p className="ml-5 display-inline-block">
77-
<Popup
78-
content="Verified community"
79-
trigger={
80-
<Icon
81-
size="small"
82-
color="green"
83-
name="check circle outline"
84-
/>
85-
}
86-
position="top center"
87-
/>
88-
</p>
89-
)}
90-
</Header>
91-
{community.parent && (
92-
<HeaderSubheader>
93-
{i18next.t("Part of")}{" "}
94-
<a href={`/communities/${community.parent.slug}`}>
95-
{i18next.t(community.parent.metadata.title)}
96-
</a>
97-
</HeaderSubheader>
98-
)}
99-
{viewRequest && (
100-
<div>
101-
<small>
102-
<b>
103-
<a
104-
// building request link as the self_html of the request is
105-
// /requests/<uuid> which doesn't resolve as missing
106-
// /communities/ or /me/. We prefer /communities/ here
107-
href={`${community.links.self_html}requests/${
108-
recordRequests[community.id]
109-
}`}
110-
>
111-
<Icon name="discussions" className="mr-5" />
112-
{i18next.t("View comments")}
113-
</a>
114-
</b>
115-
</small>
116-
</div>
69+
<Item.Content className="ui">
70+
<Header as="a" href={community.links.self_html} size="small">
71+
{community.metadata.title}
72+
{/* Show the icon for communities allowing children, and for subcommunities */}
73+
{(community.children?.allow ||
74+
community.parent !== undefined) && (
75+
<p className="ml-5 display-inline-block">
76+
<Popup
77+
content="Verified community"
78+
trigger={
79+
<Icon
80+
size="small"
81+
color="green"
82+
name="check circle outline"
83+
/>
84+
}
85+
position="top center"
86+
/>
87+
</p>
11788
)}
118-
</Item.Header>
89+
</Header>
90+
{community.parent && (
91+
<HeaderSubheader>
92+
{i18next.t("Part of")}{" "}
93+
<a href={`/communities/${community.parent.slug}`}>
94+
{i18next.t(community.parent.metadata.title)}
95+
</a>
96+
</HeaderSubheader>
97+
)}
98+
{viewRequest && (
99+
<p>
100+
<small>
101+
<a
102+
// building request link as the self_html of the request is
103+
// /requests/<uuid> which doesn't resolve as missing
104+
// /communities/ or /me/. We prefer /communities/ here
105+
href={`${community.links.self_html}requests/${
106+
recordRequests[community.id]?.request_id
107+
}`}
108+
>
109+
<Icon name="discussions" className="mr-5" />
110+
<strong>{i18next.t("View comments")}</strong>
111+
{!recordRequests[community.id]?.is_current &&
112+
i18next.t(" (accepted version)")}
113+
</a>
114+
</small>
115+
</p>
116+
)}
119117
</Item.Content>
120118
</Grid.Column>
121119
</Grid.Row>

0 commit comments

Comments
 (0)