Skip to content

Commit

Permalink
pkp/pkp-lib#10760 Consider publication status for galley manager actions
Browse files Browse the repository at this point in the history
  • Loading branch information
jardakotesovec committed Jan 6, 2025
1 parent 70156e6 commit 5ad866c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/managers/GalleyManager/galleyManagerStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {useLegacyGridUrl} from '@/composables/useLegacyGridUrl';
export const useGalleyManagerStore = defineComponentStore(
'galleyManager',
(props) => {
const {submission} = toRefs(props);
const {submission, publication} = toRefs(props);

const galleys = computed(() => {
return sortingEnabled.value
Expand All @@ -20,7 +20,10 @@ export const useGalleyManagerStore = defineComponentStore(
/** Reload files when data on screen changes */

/** Columns */
const _galleyConfigurationFns = useGalleyManagerConfiguration({submission});
const _galleyConfigurationFns = useGalleyManagerConfiguration({
submission,
publication,
});
const columns = computed(() => _galleyConfigurationFns.getColumns());

/**
Expand Down Expand Up @@ -112,6 +115,7 @@ export const useGalleyManagerStore = defineComponentStore(
return {
config: _galleyConfigurationFns.config.value,
galleys: galleys,
publication: publication.value,
};
}

Expand Down
14 changes: 11 additions & 3 deletions src/managers/GalleyManager/useGalleyManagerActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,22 @@ export function useGalleyManagerActions({galleyGridComponent}) {
return actions;
}

function getItemActions({config}) {
function getItemActions({config, publication}) {
const actions = [];

if (config.permittedActions.includes(Actions.GALLEY_EDIT)) {
const label =
publication.status === pkp.const.STATUS_PUBLISHED
? t('common.view')
: t('common.edit');

const icon =
publication.status === pkp.const.STATUS_PUBLISHED ? 'View' : 'Edit';

actions.push({
label: t('common.edit'),
label,
name: Actions.GALLEY_EDIT,
icon: 'Edit',
icon,
});
}

Expand Down
27 changes: 22 additions & 5 deletions src/managers/GalleyManager/useGalleyManagerConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ export const GalleyManagerConfiguration = {
Actions.GALLEY_EDIT,
Actions.GALLEY_SORT,
],
actionsRequiresUnpublishedState: [
Actions.GALLEY_ADD,
Actions.GALLEY_CHANGE_FILE,
Actions.GALLEY_DELETE,
Actions.GALLEY_SORT,
],
};

export function useGalleyManagerConfiguration({submission}) {
export function useGalleyManagerConfiguration({submission, publication}) {
const {t} = useLocalize();
const {hasCurrentUserAtLeastOneAssignedRoleInStage} = useCurrentUser();

Expand Down Expand Up @@ -77,8 +83,20 @@ export function useGalleyManagerConfiguration({submission}) {
}

const config = computed(() => {
const permittedActions = GalleyManagerConfiguration.actions.filter(
(action) => {
const permittedActions = GalleyManagerConfiguration.actions
.filter((action) => {
if (
publication.value.status === pkp.const.STATUS_PUBLISHED &&
GalleyManagerConfiguration.actionsRequiresUnpublishedState.includes(
action,
)
) {
return false;
}

return true;
})
.filter((action) => {
return GalleyManagerConfiguration.permissions.some((perm) => {
return (
perm.actions.includes(action) &&
Expand All @@ -89,8 +107,7 @@ export function useGalleyManagerConfiguration({submission}) {
)
);
});
},
);
});
return {permittedActions};
});

Expand Down

0 comments on commit 5ad866c

Please sign in to comment.