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

UIIN-2896 Show callout when user doesn't have permissions to use edit MARC shortcut (follow-up) #2485

Merged
merged 2 commits into from
May 23, 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
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."
}
Loading