Skip to content

Commit

Permalink
pkp/pkp-lib#7495 Refine permission logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jardakotesovec committed Oct 2, 2024
1 parent a8018a4 commit 32fb72d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,6 @@ export const PublicationConfig = {
},
galleys: {
getPrimaryItems: ({submission, selectedPublication, permissions}) => {
if (!permissions.canAccessProduction) {
return [];
}
return [
{
component: 'GalleyManager',
Expand Down Expand Up @@ -378,7 +375,7 @@ export function useWorkflowAuthorConfig() {
return [];
}

if (!permissions.canAccessSelectedStage) {
if (!permissions.accessibleStages.includes(selectedMenuState.stageId)) {
if (getterFnName === 'getPrimaryItems') {
return [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,9 +756,6 @@ export const PublicationConfig = {
},
galleys: {
getPrimaryItems: ({submission, selectedPublication, permissions}) => {
if (!permissions.canAccessProduction) {
return [];
}
return [
{
component: 'GalleyManager',
Expand All @@ -778,10 +775,6 @@ export const PublicationConfig = {
pageInitConfig,
permissions,
}) => {
if (!permissions.canAccessProduction) {
return [];
}

return [
{
component: 'PublicationForm',
Expand All @@ -802,10 +795,6 @@ export const PublicationConfig = {
pageInitConfig,
permissions,
}) => {
if (!permissions.canAccessProduction) {
return [];
}

return [
{
component: 'PublicationForm',
Expand Down Expand Up @@ -847,7 +836,7 @@ export function useWorkflowEditorialConfig() {
return [];
}

if (!permissions.canAccessSelectedStage) {
if (!permissions.accessibleStages.includes(selectedMenuState.stageId)) {
if (getterFnName === 'getPrimaryItems') {
return [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function useWorkflowNavigationConfig(pageInitConfig) {
return reviewMenuItems;
}

function getWorkflowItems(submission) {
function getWorkflowItems({submission}) {
const {getActiveStage} = useSubmission();

const activeStage = getActiveStage(submission);
Expand Down Expand Up @@ -151,7 +151,7 @@ export function useWorkflowNavigationConfig(pageInitConfig) {
];
}

function getPublicationItemsAuthor(submission) {
function getPublicationItemsAuthor({submission, permissions}) {
const items = [];

items.push({
Expand Down Expand Up @@ -196,9 +196,7 @@ export function useWorkflowNavigationConfig(pageInitConfig) {
});
}

// TODO: REAL VALUE
const canAccessProductionStage = true;
if (canAccessProductionStage) {
if (permissions.canAccessProduction) {
items.push({
key: 'galleys',
label: t('submission.layout.galleys'),
Expand All @@ -213,7 +211,7 @@ export function useWorkflowNavigationConfig(pageInitConfig) {
return items;
}

function getPublicationItemsEditorial(submission) {
function getPublicationItemsEditorial({submission, permissions}) {
const items = [];

items.push({
Expand Down Expand Up @@ -280,46 +278,48 @@ export function useWorkflowNavigationConfig(pageInitConfig) {
},
});

items.push({
key: 'galleys',
label: t('submission.layout.galleys'),
action: 'selectPublicationMenu',
actionArgs: {
publicationMenu: 'galleys',
title: getPublicationTitle(t('submission.layout.galleys')),
},
});
if (permissions.canAccessProduction) {
items.push({
key: 'galleys',
label: t('submission.layout.galleys'),
action: 'selectPublicationMenu',
actionArgs: {
publicationMenu: 'galleys',
title: getPublicationTitle(t('submission.layout.galleys')),
},
});

items.push({
label: t('publication.publicationLicense'),
key: 'license',
action: 'selectPublicationMenu',
actionArgs: {
publicationMenu: 'license',
title: getPublicationTitle(t('publication.publicationLicense')),
},
});
items.push({
label: t('publication.publicationLicense'),
key: 'license',
action: 'selectPublicationMenu',
actionArgs: {
publicationMenu: 'license',
title: getPublicationTitle(t('publication.publicationLicense')),
},
});

items.push({
label: t('issue.issue'),
key: 'issue',
action: 'selectPublicationMenu',
actionArgs: {
publicationMenu: 'issue',
title: getPublicationTitle(t('issue.issue')),
},
});
items.push({
label: t('issue.issue'),
key: 'issue',
action: 'selectPublicationMenu',
actionArgs: {
publicationMenu: 'issue',
title: getPublicationTitle(t('issue.issue')),
},
});
}

return items;
}

function getMenuItems(submission) {
function getMenuItems({submission, permissions}) {
const menuItems = [
{
key: 'workflow',
label: 'Workflow',
icon: 'Dashboard',
items: getWorkflowItems(submission),
items: getWorkflowItems({submission, permissions}),
},
{
key: 'publication',
Expand All @@ -328,8 +328,8 @@ export function useWorkflowNavigationConfig(pageInitConfig) {
items:
pageInitConfig.dashboardPage ===
DashboardPageTypes.EDITORIAL_DASHBOARD
? getPublicationItemsEditorial(submission)
: getPublicationItemsAuthor(submission),
? getPublicationItemsEditorial({submission, permissions})
: getPublicationItemsAuthor({submission, permissions}),
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const useSubmissionSummaryStore = defineComponentStore(
// Access to activity log
let canAccessEditorialHistory = false;

let canAccessSelectedStage = false;
let accessibleStages = [];

if (!submission.value) {
return {
Expand All @@ -130,7 +130,7 @@ export const useSubmissionSummaryStore = defineComponentStore(
canEditPublication,
canPublish,
canAccessEditorialHistory,
canAccessSelectedStage,
accessibleStages,
};
}

Expand All @@ -140,21 +140,11 @@ export const useSubmissionSummaryStore = defineComponentStore(
pkp.const.WORKFLOW_STAGE_ID_PRODUCTION,
);

const selectedStage = selectedMenuState.value?.stageId
? getStageById(submission.value, selectedMenuState.value?.stageId)
: null;

console.log('selectedStage:', selectedStage);
if (selectedStage) {
console.log(
'checking perms:',
selectedStage,
selectedStage.currentUserAssignedRoles,
);
if (selectedStage.currentUserAssignedRoles.length) {
canAccessSelectedStage = true;
submission.value.stages.forEach((stage) => {
if (stage.currentUserAssignedRoles.length) {
accessibleStages.push(stage.id);
}
}
});

// TODO this will be replaced by with one flag from backend
productionStage.stageAssignments
Expand All @@ -178,15 +168,18 @@ export const useSubmissionSummaryStore = defineComponentStore(
}

if (
hasIntersection(activeStage.currentUserAssignedRoles, EditorialRoles)
hasIntersection(activeStage.currentUserAssignedRoles, [
...EditorialRoles,
pkp.const.ROLE_ID_AUTHOR,
])
) {
canAccessPublication = true;

if (
hasIntersection(
productionStage.currentUserAssignedRoles,
EditorialRoles,
)
hasIntersection(productionStage.currentUserAssignedRoles, [
...EditorialRoles,
pkp.const.ROLE_ID_AUTHOR,
])
) {
canAccessProduction = true;
}
Expand Down Expand Up @@ -217,7 +210,7 @@ export const useSubmissionSummaryStore = defineComponentStore(
canEditPublication,
canPublish,
canAccessEditorialHistory,
canAccessSelectedStage,
accessibleStages,
};
});

Expand All @@ -229,7 +222,11 @@ export const useSubmissionSummaryStore = defineComponentStore(
if (!submission.value) {
return [];
}
return getMenuItems(submission.value);

return getMenuItems({
submission: submission.value,
permissions: permissions.value,
});
});

function navigateToMenu({key}) {
Expand Down

0 comments on commit 32fb72d

Please sign in to comment.