mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 17:00:55 +00:00
fix: send src stage when updating stages
This commit is contained in:
parent
3c1b898f8c
commit
1ae2af1f65
@ -5,7 +5,7 @@ const {
|
|||||||
reduceAsync,
|
reduceAsync,
|
||||||
errors: { ApplicationError, ValidationError },
|
errors: { ApplicationError, ValidationError },
|
||||||
} = require('@strapi/utils');
|
} = require('@strapi/utils');
|
||||||
const { map, pick } = require('lodash/fp');
|
const { map, pick, isEqual } = require('lodash/fp');
|
||||||
|
|
||||||
const { STAGE_MODEL_UID, ENTITY_STAGE_ATTRIBUTE, ERRORS } = require('../../constants/workflows');
|
const { STAGE_MODEL_UID, ENTITY_STAGE_ATTRIBUTE, ERRORS } = require('../../constants/workflows');
|
||||||
const { getService } = require('../../utils');
|
const { getService } = require('../../utils');
|
||||||
@ -77,15 +77,16 @@ module.exports = ({ strapi }) => {
|
|||||||
return stages;
|
return stages;
|
||||||
},
|
},
|
||||||
|
|
||||||
async update(stageId, stageData) {
|
async update(srcStage, destStage) {
|
||||||
let stagePermissions = [];
|
let stagePermissions = [];
|
||||||
|
const stageId = destStage.id;
|
||||||
|
|
||||||
// TODO: Do not delete permissions if they are not changed
|
// TODO: Do not delete permissions if they are not changed
|
||||||
// Delete old permissions
|
// Delete old permissions
|
||||||
await this.deleteStagePermissions(stageId);
|
await this.deleteStagePermissions([srcStage]);
|
||||||
|
|
||||||
if (stageData.permissions) {
|
if (destStage.permissions) {
|
||||||
const permissions = await mapAsync(stageData.permissions, (permission) =>
|
const permissions = await mapAsync(destStage.permissions, (permission) =>
|
||||||
stagePermissionsService.register(permission.role, permission.action, stageId)
|
stagePermissionsService.register(permission.role, permission.action, stageId)
|
||||||
);
|
);
|
||||||
stagePermissions = permissions.flat().map((p) => p.id);
|
stagePermissions = permissions.flat().map((p) => p.id);
|
||||||
@ -93,7 +94,7 @@ module.exports = ({ strapi }) => {
|
|||||||
|
|
||||||
const stage = await strapi.entityService.update(STAGE_MODEL_UID, stageId, {
|
const stage = await strapi.entityService.update(STAGE_MODEL_UID, stageId, {
|
||||||
data: {
|
data: {
|
||||||
...stageData,
|
...destStage,
|
||||||
permissions: stagePermissions,
|
permissions: stagePermissions,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -152,7 +153,10 @@ module.exports = ({ strapi }) => {
|
|||||||
const createdStagesIds = map('id', createdStages);
|
const createdStagesIds = map('id', createdStages);
|
||||||
|
|
||||||
// Update the workflow stages
|
// Update the workflow stages
|
||||||
await mapAsync(updated, (stage) => this.update(stage.id, stage));
|
await mapAsync(updated, (destStage) => {
|
||||||
|
const srcStage = srcStages.find((s) => s.id === destStage.id);
|
||||||
|
return this.update(srcStage, destStage);
|
||||||
|
});
|
||||||
|
|
||||||
// Delete the stages that are not in the new stages list
|
// Delete the stages that are not in the new stages list
|
||||||
await mapAsync(deleted, async (stage) => {
|
await mapAsync(deleted, async (stage) => {
|
||||||
@ -302,12 +306,19 @@ module.exports = ({ strapi }) => {
|
|||||||
*/
|
*/
|
||||||
function getDiffBetweenStages(sourceStages, comparisonStages) {
|
function getDiffBetweenStages(sourceStages, comparisonStages) {
|
||||||
const result = comparisonStages.reduce(
|
const result = comparisonStages.reduce(
|
||||||
|
// ...
|
||||||
|
|
||||||
(acc, stageToCompare) => {
|
(acc, stageToCompare) => {
|
||||||
const srcStage = sourceStages.find((stage) => stage.id === stageToCompare.id);
|
const srcStage = sourceStages.find((stage) => stage.id === stageToCompare.id);
|
||||||
|
|
||||||
if (!srcStage) {
|
if (!srcStage) {
|
||||||
acc.created.push(stageToCompare);
|
acc.created.push(stageToCompare);
|
||||||
} else if (srcStage.name !== stageToCompare.name || srcStage.color !== stageToCompare.color) {
|
} else if (
|
||||||
|
!isEqual(
|
||||||
|
pick(['name', 'color', 'permissions'], srcStage),
|
||||||
|
pick(['name', 'color', 'permissions'], stageToCompare)
|
||||||
|
)
|
||||||
|
) {
|
||||||
acc.updated.push(stageToCompare);
|
acc.updated.push(stageToCompare);
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user