Skip to content

Commit 70156e6

Browse files
pkp/pkp-lib#10760 Refine GalleyManager
1 parent 8d6954b commit 70156e6

File tree

9 files changed

+111
-59
lines changed

9 files changed

+111
-59
lines changed

src/composables/useCurrentUser.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ export function useCurrentUser() {
3131
}
3232
});
3333

34-
console.log('hasCurrentUserAtLeastOneAssignedRoleInStage');
35-
console.log(
36-
assignedRoleIds,
37-
roles.some((role) => assignedRoleIds.includes(role)),
38-
);
3934
return roles.some((role) => assignedRoleIds.includes(role));
4035
}
4136

src/managers/FileManager/useFileManagerConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const FileManagerConfigurations = {
1111
{
1212
roles: [pkp.const.ROLE_ID_AUTHOR],
1313
actions: [
14-
Actions.FILE_FILE_LIST,
14+
Actions.FILE_LIST,
1515
Actions.FILE_EDIT,
1616
Actions.FILE_DOWNLOAD_ALL,
1717
],

src/managers/GalleyManager/GalleyManagerCellActions.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<template>
22
<TableCell class="w-28">
3-
<TableRowRortControls
3+
<TableRowSortControls
44
v-if="galleyManagerStore.sortingEnabled"
55
@up="galleyManagerStore.sortMoveUp(galley.id)"
66
@down="galleyManagerStore.sortMoveDown(galley.id)"
77
/>
88
<DropdownActions
9-
v-else
9+
v-if="
10+
!galleyManagerStore.sortingEnabled &&
11+
galleyManagerStore.itemActions.length
12+
"
1013
:label="t('common.moreActions')"
1114
:display-as-ellipsis="true"
1215
:actions="galleyManagerStore.itemActions"
@@ -16,7 +19,7 @@
1619
</template>
1720
<script setup>
1821
import {useGalleyManagerStore} from './galleyManagerStore';
19-
import TableRowRortControls from './TableRowSortControls.vue';
22+
import TableRowSortControls from './TableRowSortControls.vue';
2023
2124
defineProps({
2225
galley: {type: Object, required: true},

src/managers/GalleyManager/TableRowSortControls.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<template>
22
<div class="flex items-center justify-center">
33
<button
4-
class="inline-flex items-center justify-center rounded p-1.5 text-primary hover:bg-primary hover:text-on-dark"
4+
class="inline-flex items-center justify-center rounded text-primary hover:bg-primary hover:text-on-dark"
55
@click="emit('up')"
66
>
77
<Icon class="h-6 w-6" icon="ChevronUp"></Icon>
88
</button>
99
<button
10-
class="inline-flex items-center justify-center rounded p-1.5 text-primary hover:bg-primary hover:text-on-dark"
10+
class="inline-flex items-center justify-center rounded text-primary hover:bg-primary hover:text-on-dark"
1111
@click="emit('down')"
1212
>
1313
<Icon class="h-6 w-6" icon="ChevronDown"></Icon>

src/managers/GalleyManager/galleyManagerStore.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {defineComponentStore} from '@/utils/defineComponentStore';
2-
import {ref, computed} from 'vue';
2+
import {ref, computed, toRefs} from 'vue';
33
import {useFetch, getCSRFToken} from '@/composables/useFetch';
44
import {useModal} from '@/composables/useModal';
55
import {useGalleyManagerActions} from './useGalleyManagerActions';
@@ -9,6 +9,8 @@ import {useLegacyGridUrl} from '@/composables/useLegacyGridUrl';
99
export const useGalleyManagerStore = defineComponentStore(
1010
'galleyManager',
1111
(props) => {
12+
const {submission} = toRefs(props);
13+
1214
const galleys = computed(() => {
1315
return sortingEnabled.value
1416
? galleysOrdered.value
@@ -18,7 +20,7 @@ export const useGalleyManagerStore = defineComponentStore(
1820
/** Reload files when data on screen changes */
1921

2022
/** Columns */
21-
const _galleyConfigurationFns = useGalleyManagerConfiguration();
23+
const _galleyConfigurationFns = useGalleyManagerConfiguration({submission});
2224
const columns = computed(() => _galleyConfigurationFns.getColumns());
2325

2426
/**
@@ -108,7 +110,8 @@ export const useGalleyManagerStore = defineComponentStore(
108110
});
109111
function getActionArgs() {
110112
return {
111-
canEdit: props.canEdit,
113+
config: _galleyConfigurationFns.config.value,
114+
galleys: galleys,
112115
};
113116
}
114117

src/managers/GalleyManager/useGalleyManagerActions.js

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,73 +3,70 @@ import {useLegacyGridUrl} from '@/composables/useLegacyGridUrl';
33
import {useModal} from '@/composables/useModal';
44
import {useFetch, getCSRFToken} from '@/composables/useFetch';
55
export const Actions = {
6+
GALLEY_LIST: 'galleyList',
67
GALLEY_ADD: 'galleyAdd',
78
GALLEY_EDIT: 'galleyEdit',
89
GALLEY_CHANGE_FILE: 'galleyChangeFile',
910
GALLEY_DELETE: 'galleyDelete',
11+
GALLEY_SORT: 'galleySort',
1012
};
1113

1214
export function useGalleyManagerActions({galleyGridComponent}) {
1315
const {t} = useLocalize();
1416

15-
function getBottomActions({canEdit}) {
17+
function getBottomActions({config}) {
1618
const actions = [];
1719

18-
if (!canEdit) {
19-
return [];
20+
if (config.permittedActions.includes(Actions.GALLEY_ADD)) {
21+
actions.push({
22+
component: 'GalleyManagerActionButton',
23+
props: {label: t('grid.action.addGalley'), action: Actions.GALLEY_ADD},
24+
isLink: true,
25+
});
2026
}
2127

22-
actions.push({
23-
component: 'GalleyManagerActionButton',
24-
props: {label: t('grid.action.addGalley'), action: Actions.GALLEY_ADD},
25-
isLink: true,
26-
});
27-
2828
return actions;
2929
}
3030

31-
function getTopItems({canEdit}) {
31+
function getTopItems({config, galleys}) {
3232
const actions = [];
33-
if (!canEdit) {
34-
return [];
35-
}
36-
37-
actions.push({component: 'GalleyManagerSortButton'});
3833

34+
if (
35+
config.permittedActions.includes(Actions.GALLEY_SORT) &&
36+
galleys.value.length
37+
) {
38+
actions.push({component: 'GalleyManagerSortButton'});
39+
}
3940
return actions;
4041
}
4142

42-
function getItemActions({canEdit}) {
43+
function getItemActions({config}) {
4344
const actions = [];
4445

45-
if (!canEdit) {
46-
return [
47-
{
48-
label: t('common.view'),
49-
name: Actions.GALLEY_EDIT,
50-
icon: 'View',
51-
},
52-
];
46+
if (config.permittedActions.includes(Actions.GALLEY_EDIT)) {
47+
actions.push({
48+
label: t('common.edit'),
49+
name: Actions.GALLEY_EDIT,
50+
icon: 'Edit',
51+
});
5352
}
5453

55-
actions.push({
56-
label: t('common.edit'),
57-
name: Actions.GALLEY_EDIT,
58-
icon: 'Edit',
59-
});
60-
61-
actions.push({
62-
label: t('submission.changeFile'),
63-
name: Actions.GALLEY_CHANGE_FILE,
64-
icon: 'New',
65-
});
54+
if (config.permittedActions.includes(Actions.GALLEY_CHANGE_FILE)) {
55+
actions.push({
56+
label: t('submission.changeFile'),
57+
name: Actions.GALLEY_CHANGE_FILE,
58+
icon: 'New',
59+
});
60+
}
6661

67-
actions.push({
68-
label: t('common.delete'),
69-
name: Actions.GALLEY_DELETE,
70-
icon: 'Cancel',
71-
isWarnable: true,
72-
});
62+
if (config.permittedActions.includes(Actions.GALLEY_DELETE)) {
63+
actions.push({
64+
label: t('common.delete'),
65+
name: Actions.GALLEY_DELETE,
66+
icon: 'Cancel',
67+
isWarnable: true,
68+
});
69+
}
7370

7471
return actions;
7572
}

src/managers/GalleyManager/useGalleyManagerConfiguration.js

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,46 @@
11
import {useLocalize} from '@/composables/useLocalize';
22
import {useApp} from '@/composables/useApp';
3+
import {Actions} from './useGalleyManagerActions';
4+
import {useCurrentUser} from '@/composables/useCurrentUser';
5+
import {computed} from 'vue';
36

4-
export function useGalleyManagerConfiguration() {
7+
export const GalleyManagerConfiguration = {
8+
permissions: [
9+
{
10+
roles: [pkp.const.ROLE_ID_AUTHOR],
11+
actions: [Actions.GALLEY_LIST],
12+
},
13+
{
14+
roles: [
15+
pkp.const.ROLE_ID_SUB_EDITOR,
16+
pkp.const.ROLE_ID_MANAGER,
17+
pkp.const.ROLE_ID_SITE_ADMIN,
18+
pkp.const.ROLE_ID_ASSISTANT,
19+
],
20+
actions: [
21+
Actions.GALLEY_LIST,
22+
Actions.GALLEY_ADD,
23+
Actions.GALLEY_CHANGE_FILE,
24+
Actions.GALLEY_DELETE,
25+
Actions.GALLEY_EDIT,
26+
Actions.GALLEY_SORT,
27+
],
28+
},
29+
],
30+
actions: [
31+
Actions.GALLEY_LIST,
32+
Actions.GALLEY_ADD,
33+
Actions.GALLEY_CHANGE_FILE,
34+
Actions.GALLEY_DELETE,
35+
Actions.GALLEY_EDIT,
36+
Actions.GALLEY_SORT,
37+
],
38+
};
39+
40+
export function useGalleyManagerConfiguration({submission}) {
541
const {t} = useLocalize();
42+
const {hasCurrentUserAtLeastOneAssignedRoleInStage} = useCurrentUser();
43+
644
const {isOPS} = useApp();
745
function getGalleyGridComponent() {
846
if (isOPS()) {
@@ -38,5 +76,23 @@ export function useGalleyManagerConfiguration() {
3876
return columns;
3977
}
4078

41-
return {getColumns, getGalleyGridComponent};
79+
const config = computed(() => {
80+
const permittedActions = GalleyManagerConfiguration.actions.filter(
81+
(action) => {
82+
return GalleyManagerConfiguration.permissions.some((perm) => {
83+
return (
84+
perm.actions.includes(action) &&
85+
hasCurrentUserAtLeastOneAssignedRoleInStage(
86+
submission.value,
87+
pkp.const.WORKFLOW_STAGE_ID_PRODUCTION,
88+
perm.roles,
89+
)
90+
);
91+
});
92+
},
93+
);
94+
return {permittedActions};
95+
});
96+
97+
return {getColumns, getGalleyGridComponent, config};
4298
}

src/pages/workflow/composables/useWorkflowConfig/workflowConfigAuthorOJS.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ export const PublicationConfig = {
322322
props: {
323323
submission,
324324
publication: selectedPublication,
325-
canEditPublication: permissions.canEditPublication,
326325
},
327326
},
328327
];

src/pages/workflow/composables/useWorkflowConfig/workflowConfigEditorialOJS.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,6 @@ export const PublicationConfig = {
888888
props: {
889889
submission,
890890
publication: selectedPublication,
891-
canEdit: permissions.canEditPublication,
892891
},
893892
},
894893
];

0 commit comments

Comments
 (0)