From 48add095a0ebfff8701e8e6f25e7e9dc9b9903c9 Mon Sep 17 00:00:00 2001 From: Maximilian Moser Date: Thu, 19 Sep 2024 13:29:26 +0200 Subject: [PATCH] deposit: provide permissions to publish button * backport of #2733 * originally authored by David E. --- .../controls/PublishButton/PublishButton.js | 53 ++++++++++++++----- .../SubmitReviewOrPublishButton.js | 5 +- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/controls/PublishButton/PublishButton.js b/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/controls/PublishButton/PublishButton.js index 6e88f0a31..5ba771835 100644 --- a/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/controls/PublishButton/PublishButton.js +++ b/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/controls/PublishButton/PublishButton.js @@ -1,6 +1,7 @@ // This file is part of Invenio-RDM-Records // Copyright (C) 2020-2023 CERN. // Copyright (C) 2020-2022 Northwestern University. +// Copyright (C) 2020-2022 Graz University of Technology. // // 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. @@ -12,7 +13,7 @@ import _omit from "lodash/omit"; import PropTypes from "prop-types"; import React, { Component } from "react"; import { connect } from "react-redux"; -import { Button, Icon, Message, Modal } from "semantic-ui-react"; +import { Button, Icon, Message, Modal, Popup } from "semantic-ui-react"; import { DepositFormSubmitActions, DepositFormSubmitContext, @@ -40,10 +41,14 @@ class PublishButtonComponent extends Component { this.closeConfirmModal(); }; - isDisabled = (values, isSubmitting, numberOfFiles) => { + isDisabled = (values, isSubmitting, numberOfFiles, permissions) => { const filesEnabled = _get(values, "files.enabled", false); const filesMissing = filesEnabled && !numberOfFiles; - return isSubmitting || filesMissing; + return isSubmitting || filesMissing || !this.hasPermissions(permissions); + }; + + hasPermissions = (permissions) => { + return permissions.can_publish; }; render() { @@ -54,26 +59,44 @@ class PublishButtonComponent extends Component { publishWithoutCommunity, formik, publishModalExtraContent, + permissions, ...ui } = this.props; const { isConfirmModalOpen } = this.state; const { values, isSubmitting, handleSubmit } = formik; const uiProps = _omit(ui, ["dispatch"]); + const publishDisabled = this.isDisabled( + values, + isSubmitting, + numberOfFiles, + permissions + ); + const popupText = !this.hasPermissions(permissions) + ? i18next.t("You don't have permission to publish") + : i18next.t("Required fields are missing."); return ( <> -