Skip to content

Commit

Permalink
UIIN-2896 Show callout when user doesn't have permissions to use edit…
Browse files Browse the repository at this point in the history
… MARC shortcut
  • Loading branch information
BogdanDenis committed May 22, 2024
1 parent 92818ca commit 174b87b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
10 changes: 9 additions & 1 deletion src/ViewHoldingsRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,15 @@ class ViewHoldingsRecord extends React.Component {
{
name: 'editMARC',
handler: handleKeyCommand(() => {
if (!stripes.hasPerm('ui-quick-marc.quick-marc-editor.all') || !this.isMARCSource()) {
if (!this.isMARCSource()) {
return;
}

if (!stripes.hasPerm('ui-quick-marc.quick-marc-holdings-editor.all')) {
this.calloutRef.current.sendCallout({
type: 'error',
message: <FormattedMessage id="ui-inventory.shortcut.editMARC.noPermission" />,
});
return;
}

Expand Down
10 changes: 9 additions & 1 deletion src/ViewInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,15 @@ class ViewInstance extends React.Component {
{
name: 'editMARC',
handler: handleKeyCommand(() => {
if (!stripes.hasPerm('ui-quick-marc.quick-marc-editor.all') || !isMARCSource(selectedInstance.source)) {
if (!isMARCSource(selectedInstance.source)) {
return;
}

if (!stripes.hasPerm('ui-quick-marc.quick-marc-editor.all')) {
this.calloutRef.current.sendCallout({
type: 'error',
message: <FormattedMessage id="ui-inventory.shortcut.editMARC.noPermission" />,
});
return;
}

Expand Down
23 changes: 20 additions & 3 deletions src/components/ViewSource/ViewSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ import {
useHistory,
} from 'react-router-dom';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import {
useIntl,
FormattedMessage,
} from 'react-intl';

import {
Button,
LoadingView,
HasCommand,
checkScope,
} from '@folio/stripes/components';
import { useStripes } from '@folio/stripes/core';
import {
useCallout,
useStripes,
} from '@folio/stripes/core';
import {
MarcView,
PrintPopup,
Expand All @@ -44,9 +50,11 @@ const ViewSource = ({
tenantId,
marcType,
}) => {
const intl = useIntl();
const stripes = useStripes();
const location = useLocation();
const history = useHistory();
const callout = useCallout();
const [isShownPrintPopup, setIsShownPrintPopup] = useState(false);
const openPrintPopup = () => setIsShownPrintPopup(true);
const closePrintPopup = () => setIsShownPrintPopup(false);
Expand Down Expand Up @@ -76,7 +84,16 @@ const ViewSource = ({
{
name: 'editMARC',
handler: handleKeyCommand(() => {
if (stripes.hasPerm('ui-quick-marc.quick-marc-editor.all')) redirectToMARCEdit();
if ((marcType === MARC_TYPES.BIB && !stripes.hasPerm('ui-quick-marc.quick-marc-editor.all'))
|| (marcType === MARC_TYPES.HOLDINGS && !stripes.hasPerm('ui-quick-marc.quick-marc-holdings-editor.all'))) {
callout.sendCallout({
type: 'error',
message: intl.formatMessage({ id: 'ui-inventory.shortcut.editMARC.noPermission' }),
});
return;
}

redirectToMARCEdit();
}),
},
], [stripes, redirectToMARCEdit]);
Expand Down
3 changes: 2 additions & 1 deletion translations/ui-inventory/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -877,5 +877,6 @@

"shortcut.nextSubfield": "quickMARC only: Move to the next subfield in a text box",
"shortcut.prevSubfield": "quickMARC only: Move to the previous subfield in a text box",
"shortcut.editMARC": "Edit MARC record"
"shortcut.editMARC": "Edit MARC record",
"shortcut.editMARC.noPermission": "You do not have permission to edit the record."
}

0 comments on commit 174b87b

Please sign in to comment.