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

deposit form: add sharing of drafts #2668

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
value='{{ files | tojson }}'>
{%- endif %}

{%- if config %}
<input type="hidden" name="deposits-record-restriction-grace-period"
value='{{ config.RDM_RECORDS_RESTRICTION_GRACE_PERIOD.days | tojson }}'>
<input type="hidden" name="deposits-allow-record-restriction"
value='{{ config.RDM_RECORDS_ALLOW_RESTRICTION_AFTER_GRACE_PERIOD | tojson }}'>
{%- endif %}
<input type="hidden" name="deposits-record-restriction-grace-period"
value='{{ config.RDM_RECORDS_RESTRICTION_GRACE_PERIOD.days | tojson }}'>
<input type="hidden" name="deposits-allow-record-restriction"
value='{{ config.RDM_RECORDS_ALLOW_RESTRICTION_AFTER_GRACE_PERIOD | tojson }}'>
<input type="hidden" name="config-groups-enabled"
value='{{ config.USERS_RESOURCES_GROUPS_ENABLED | tojson }}'>

{%- if forms_config %}
<input type="hidden" name="deposits-config"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
data-is-preview-submission-request="{{ is_preview_submission_request | tojson }}"
data-current-user-id="{{ current_user.id }}"
data-record-owner-username='{{ record_owner_username }}'
data-access-links-search-config='{{ search_app_access_links_config(app_id="InvenioAppRdm.AccessLinks", endpoint=record.links.access_links) | tojson }}'
data-groups-enabled='{{ config.USERS_RESOURCES_GROUPS_ENABLED | tojson }}'
>
<div class="ui placeholder">
Expand Down
2 changes: 2 additions & 0 deletions invenio_app_rdm/records_ui/views/deposits.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ def deposit_create(community=None):
files_locked=False,
permissions=get_record_permissions(
[
"manage",
"manage_files",
"delete_draft",
"manage_record_access",
Expand Down Expand Up @@ -465,6 +466,7 @@ def deposit_edit(pid_value, draft=None, draft_files=None, files_locked=True):
files_locked=files_locked,
permissions=draft.has_permissions_to(
[
"manage",
"new_version",
"delete_draft",
"manage_files",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { FundingField } from "@js/invenio_vocabularies";
import { Card, Container, Grid, Ref, Sticky } from "semantic-ui-react";
import PropTypes from "prop-types";
import Overridable from "react-overridable";
import { ShareDraftButton } from "./ShareDraftButton";

export class RDMDepositForm extends Component {
constructor(props) {
Expand Down Expand Up @@ -105,6 +106,7 @@ export class RDMDepositForm extends Component {
filesLocked,
recordRestrictionGracePeriod,
allowRecordRestriction,
groupsEnabled,
} = this.props;
const customFieldsUI = this.config.custom_fields.ui;
return (
Expand Down Expand Up @@ -622,6 +624,16 @@ export class RDMDepositForm extends Component {
<Grid.Column width={16} className="pt-10">
<PublishButton fluid />
</Grid.Column>

<Grid.Column width={16} className="pt-0">
{(record.is_draft === null || permissions.can_manage) && (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it be null? Shouldn't it be true/false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_draft is null after just clicking on the "New upload" and rendering an empty deposit form

<ShareDraftButton
record={record}
permissions={permissions}
groupsEnabled={groupsEnabled}
/>
)}
</Grid.Column>
</Grid>
</Card.Content>
</Card>
Expand Down Expand Up @@ -663,6 +675,7 @@ export class RDMDepositForm extends Component {
}

RDMDepositForm.propTypes = {
groupsEnabled: PropTypes.bool.isRequired,
config: PropTypes.object.isRequired,
recordRestrictionGracePeriod: PropTypes.object.isRequired,
allowRecordRestriction: PropTypes.bool.isRequired,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// This file is part of InvenioRDM
// Copyright (C) 2024 CERN.
//
// Invenio RDM Records is free software; you can redistribute it and/or modify it
// under the terms of the MIT License; see LICENSE file for more details.

import React, { Component } from "react";
import PropTypes from "prop-types";
import { connect as connectFormik } from "formik";
import { connect } from "react-redux";
import _get from "lodash/get";
import { ShareButton } from "../landing_page/ShareOptions/ShareButton";

class ShareDraftButtonComponent extends Component {
isDisabled = (values, isSubmitting, numberOfFiles) => {
const { disabled } = this.props;
if (disabled) return true;

const filesEnabled = _get(values, "files.enabled", false);
const filesMissing = filesEnabled && !numberOfFiles;
const dataEmpty = Object.keys(values.expanded).length === 0;

return isSubmitting || filesMissing || dataEmpty;
};

render() {
const { numberOfFiles, record, permissions, groupsEnabled, formik } = this.props;
const { values, isSubmitting } = formik;

record.expanded = values.expanded;
record.links = values.links;
record.parent.access["settings"] = values.parent?.access?.settings;

return (
<ShareButton
disabled={this.isDisabled(values, isSubmitting, numberOfFiles)}
record={record}
permissions={permissions}
groupsEnabled={groupsEnabled}
/>
);
}
}

ShareDraftButtonComponent.propTypes = {
disabled: PropTypes.bool,
record: PropTypes.object.isRequired,
permissions: PropTypes.object.isRequired,
groupsEnabled: PropTypes.bool.isRequired,
formik: PropTypes.object.isRequired,
numberOfFiles: PropTypes.number.isRequired,
};

ShareDraftButtonComponent.defaultProps = {
disabled: false,
};

const mapStateToProps = (state) => ({
numberOfFiles: Object.values(state.files.entries).length,
});

export const ShareDraftButton = connect(
mapStateToProps,
null
)(connectFormik(ShareDraftButtonComponent));
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ReactDOM.render(
"deposits-record-restriction-grace-period"
)}
allowRecordRestriction={getInputFromDOM("deposits-allow-record-restriction")}
groupsEnabled={getInputFromDOM("config-groups-enabled")}
/>
</OverridableContext.Provider>,
document.getElementById("deposit-form")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export class RecordManagement extends Component {
isDraft,
isPreviewSubmissionRequest,
currentUserId,
accessLinksSearchConfig,
recordOwnerUsername,
groupsEnabled,
} = this.props;
Expand Down Expand Up @@ -87,7 +86,6 @@ export class RecordManagement extends Component {
<ShareButton
disabled={!permissions.can_update_draft}
record={record}
accessLinksSearchConfig={accessLinksSearchConfig}
permissions={permissions}
groupsEnabled={groupsEnabled}
/>
Expand Down Expand Up @@ -121,5 +119,4 @@ RecordManagement.propTypes = {
isPreviewSubmissionRequest: PropTypes.bool.isRequired,
currentUserId: PropTypes.string.isRequired,
recordOwnerUsername: PropTypes.object.isRequired,
accessLinksSearchConfig: PropTypes.object.isRequired,
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ export const dropdownOptions = [
{
key: "view",
name: "view",
text: i18next.t("Can view all versions"),
title: i18next.t("Can view all versions"),
text: i18next.t("Can view"),
title: i18next.t("Can view"),
value: "view",
description: i18next.t("Can view restricted files of all versions of this record."),
},
{
key: "preview",
name: "preview",
text: i18next.t("Can preview all drafts"),
title: i18next.t("Can preview all drafts"),
text: i18next.t("Can preview drafts"),
title: i18next.t("Can preview drafts"),
value: "preview",
description: i18next.t(
"Can view drafts and restricted files of all versions of this record."
Expand All @@ -37,8 +37,8 @@ export const dropdownOptions = [
{
key: "edit",
name: "edit",
text: i18next.t("Can edit all versions"),
title: i18next.t("Can edit all versions"),
text: i18next.t("Can edit"),
title: i18next.t("Can edit"),
value: "edit",
description: i18next.t(
"Can edit drafts and view restricted files of all versions of this record."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class AccessUsersGroups extends Component {
}`}
>
<b className="mr-10">
{recOwner.profile.full_name || recOwner.username}
{recOwner.profile?.full_name || recOwner.username}
</b>
{recOwner.is_current_user && (
<Label size="tiny" className="primary">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export const accessDropdownOptions = [
{
key: "manage",
name: "manage",
text: i18next.t("Can manage all versions"),
title: i18next.t("Can manage all versions"),
text: i18next.t("Can manage"),
title: i18next.t("Can manage"),
value: "manage",
description: i18next.t(
"Can manage access, edit drafts and view restricted files of all versions of this record."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ import { ShareModal } from "./ShareModal";
import { i18next } from "@translations/invenio_app_rdm/i18next";
import PropTypes from "prop-types";

export const ShareButton = ({
disabled,
record,
accessLinksSearchConfig,
permissions,
groupsEnabled,
}) => {
export const ShareButton = ({ disabled, record, permissions, groupsEnabled }) => {
const [modalOpen, setModalOpen] = useState(false);
const handleOpen = () => setModalOpen(true);
const handleClose = () => setModalOpen(false);
Expand Down Expand Up @@ -50,7 +44,6 @@ export const ShareButton = ({
handleClose={handleClose}
record={record}
permissions={permissions}
accessLinksSearchConfig={accessLinksSearchConfig}
groupsEnabled={groupsEnabled}
/>
</>
Expand All @@ -60,7 +53,6 @@ export const ShareButton = ({
ShareButton.propTypes = {
disabled: PropTypes.bool,
record: PropTypes.object.isRequired,
accessLinksSearchConfig: PropTypes.object.isRequired,
permissions: PropTypes.object.isRequired,
groupsEnabled: PropTypes.bool.isRequired,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class ShareModal extends Component {
this.setState({ record: updatedRecord });
};

panes = (record, accessLinksSearchConfig, permissions) => {
panes = (record, permissions) => {
const { handleClose, groupsEnabled } = this.props;
const { linksResults, groupsResults, usersResults } = this.state;

Expand Down Expand Up @@ -175,7 +175,7 @@ export class ShareModal extends Component {
};

render() {
const { open, handleClose, accessLinksSearchConfig, permissions } = this.props;
const { open, handleClose, permissions } = this.props;
const { record, activeTab } = this.state;
return (
<Modal
Expand All @@ -197,7 +197,7 @@ export class ShareModal extends Component {

<Tab
menu={{ secondary: true, pointing: true }}
panes={this.panes(record, accessLinksSearchConfig, permissions)}
panes={this.panes(record, permissions)}
onTabChange={this.handleTabChange}
/>
{(activeTab === 0 || activeTab === 1 || activeTab === 2) && (
Expand All @@ -220,6 +220,5 @@ ShareModal.propTypes = {
open: PropTypes.bool.isRequired,
groupsEnabled: PropTypes.bool.isRequired,
handleClose: PropTypes.func.isRequired,
accessLinksSearchConfig: PropTypes.object.isRequired,
permissions: PropTypes.object.isRequired,
};
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ function renderRecordManagement(element) {
)}
currentUserId={recordManagementAppDiv.dataset.currentUserId}
recordOwnerUsername={recordManagementAppDiv.dataset.recordOwnerUsername}
accessLinksSearchConfig={JSON.parse(
recordManagementAppDiv.dataset.accessLinksSearchConfig
)}
groupsEnabled={JSON.parse(recordManagementAppDiv.dataset.groupsEnabled)}
/>
</OverridableContext.Provider>,
Expand Down