Skip to content

Commit c8bae98

Browse files
jrcastro2kpsherva
authored andcommitted
landing_page: add manage button
* closes zenodo/rdm-project#262
1 parent 0a4a2e0 commit c8bae98

File tree

7 files changed

+66
-4
lines changed

7 files changed

+66
-4
lines changed

invenio_app_rdm/communities_ui/views/communities.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
def communities_detail(pid_value, community, community_ui):
1717
"""Community detail page."""
1818
permissions = community.has_permissions_to(
19-
["update", "read", "search_requests", "search_invites"]
19+
["update", "read", "search_requests", "search_invites", "moderate"]
2020
)
2121
endpoint = "/api/communities/{pid_value}/records"
2222

invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/details/side_bar/manage_menu.html

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
data-is-draft="{{ is_draft | tojson }}"
1818
data-is-preview-submission-request="{{ is_preview_submission_request | tojson }}"
1919
data-current-user-id="{{ current_user.id }}"
20+
data-record-owner-username='{{ record_owner_username }}'
2021
data-access-links-search-config='{{ search_app_access_links_config(app_id="InvenioAppRdm.AccessLinks", endpoint=record.links.access_links) | tojson }}'
2122
>
2223
<div class="ui placeholder">

invenio_app_rdm/records_ui/templates/semantic-ui/invenio_app_rdm/records/tombstone.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ <h1 class="ui header inline-block">
2424

2525
<p>
2626
{%- trans sitename=config.THEME_SITENAME %}
27-
The record you are trying to access was removed from {{ sitename }}. The
27+
The record you are trying to access was removed from {{ sitename }}. The
2828
metadata of the record is kept for archival purposes.
2929
{%- endtrans %}
3030
</p>

invenio_app_rdm/records_ui/views/records.py

+7
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ def record_detail(
174174
if record is not None and emitter is not None:
175175
emitter(current_app, record=record._record, via_api=False)
176176

177+
# NOTE: this should maybe be an expandable field instead
178+
record_owner = record._record.parent.access.owner.resolve()
179+
177180
resolved_community, _ = get_record_community(record_ui)
178181
return render_template(
179182
current_app.config.get("APP_RDM_RECORD_LANDING_PAGE_TEMPLATE"),
@@ -191,6 +194,7 @@ def record_detail(
191194
"review",
192195
"view",
193196
"media_read_files",
197+
"moderate",
194198
]
195199
),
196200
custom_fields_ui=custom_fields["ui"],
@@ -200,6 +204,9 @@ def record_detail(
200204
community=resolved_community,
201205
external_resources=get_external_resources(record_ui),
202206
user_avatar=avatar,
207+
record_owner_username=record_owner.username
208+
if record_owner is not None
209+
else None, # record created with system_identity have not owners e.g demo
203210
)
204211

205212

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// This file is part of InvenioRDM
2+
// Copyright (C) 2023 CERN.
3+
//
4+
// Invenio RDM Records is free software; you can redistribute it and/or modify it
5+
// under the terms of the MIT License; see LICENSE file for more details.
6+
7+
import React from "react";
8+
import { Dropdown } from "semantic-ui-react";
9+
import { i18next } from "@translations/invenio_app_rdm/i18next";
10+
import PropTypes from "prop-types";
11+
12+
export const ManageButton = ({ recid, recordOwnerUsername }) => {
13+
return (
14+
<Dropdown
15+
fluid
16+
text={i18next.t("Manage")}
17+
icon="cog"
18+
floating
19+
labeled
20+
button
21+
className="icon text-align-center"
22+
>
23+
<Dropdown.Menu>
24+
<Dropdown.Item
25+
as="a"
26+
href={`/administration/records?q=id:${recid}`}
27+
target="_blank"
28+
key="manage_record"
29+
text={i18next.t("Manage record")}
30+
/>
31+
<Dropdown.Item
32+
as="a"
33+
href={`/administration/users?q=username:${recordOwnerUsername}`}
34+
target="_blank"
35+
key="manage_user"
36+
text={i18next.t("Manage user")}
37+
/>
38+
</Dropdown.Menu>
39+
</Dropdown>
40+
);
41+
};
42+
43+
ManageButton.propTypes = {
44+
recid: PropTypes.string.isRequired,
45+
recordOwnerUsername: PropTypes.string.isRequired,
46+
};

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ShareButton } from "./ShareOptions/ShareButton";
1515
import { NewVersionButton } from "@js/invenio_rdm_records/";
1616
import PropTypes from "prop-types";
1717
import Overridable from "react-overridable";
18+
import { ManageButton } from "./ManageButton";
1819

1920
export class RecordManagement extends Component {
2021
constructor(props) {
@@ -32,19 +33,24 @@ export class RecordManagement extends Component {
3233
isPreviewSubmissionRequest,
3334
currentUserId,
3435
accessLinksSearchConfig,
36+
recordOwnerUsername,
3537
} = this.props;
3638
const { error } = this.state;
3739
const { id: recid } = record;
38-
3940
const handleError = (errorMessage) => {
4041
console.error(errorMessage);
4142
this.setState({ error: errorMessage });
4243
};
4344

4445
return (
4546
<Grid columns={1} className="record-management">
46-
{permissions.can_edit && !isDraft && (
47+
{permissions.can_moderate && (
4748
<Grid.Column className="pb-5">
49+
<ManageButton recid={recid} recordOwnerUsername={recordOwnerUsername} />
50+
</Grid.Column>
51+
)}
52+
{permissions.can_edit && !isDraft && (
53+
<Grid.Column className={permissions.can_manage ? "pb-5 pt-5" : "pb-5"}>
4854
<EditButton recid={recid} onError={handleError} />
4955
</Grid.Column>
5056
)}
@@ -111,5 +117,6 @@ RecordManagement.propTypes = {
111117
isDraft: PropTypes.bool.isRequired,
112118
isPreviewSubmissionRequest: PropTypes.bool.isRequired,
113119
currentUserId: PropTypes.string.isRequired,
120+
recordOwnerUsername: PropTypes.object.isRequired,
114121
accessLinksSearchConfig: PropTypes.object.isRequired,
115122
};

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

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ function renderRecordManagement(element) {
4242
recordManagementAppDiv.dataset.isPreviewSubmissionRequest
4343
)}
4444
currentUserId={recordManagementAppDiv.dataset.currentUserId}
45+
recordOwnerUsername={recordManagementAppDiv.dataset.recordOwnerUsername}
4546
accessLinksSearchConfig={JSON.parse(
4647
recordManagementAppDiv.dataset.accessLinksSearchConfig
4748
)}

0 commit comments

Comments
 (0)