mirror of
https://github.com/strapi/strapi.git
synced 2025-12-29 16:16:20 +00:00
feat: populate stage permissions by default
This commit is contained in:
parent
eb78a7f390
commit
5f8ee9e3a9
@ -16,4 +16,16 @@ module.exports = {
|
||||
'You’ve reached the limit of stages for this workflow in your plan. Try deleting some stages or contact Sales to enable more stages.',
|
||||
DUPLICATED_STAGE_NAME: 'Stage names must be unique.',
|
||||
},
|
||||
WORKFLOW_POPULATE: {
|
||||
stages: {
|
||||
populate: {
|
||||
permissions: {
|
||||
fields: ["action", "actionParameters"],
|
||||
populate: {
|
||||
role: { fields: ["id", "name"] },
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@ -40,6 +40,12 @@ module.exports = {
|
||||
inversedBy: 'stages',
|
||||
configurable: false,
|
||||
},
|
||||
permissions: {
|
||||
type: 'relation',
|
||||
target: 'admin::permission',
|
||||
relation: 'manyToMany',
|
||||
configurable: false,
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@ -7,7 +7,7 @@ const {
|
||||
validateWorkflowCreate,
|
||||
validateWorkflowUpdate,
|
||||
} = require('../../validation/review-workflows');
|
||||
const { WORKFLOW_MODEL_UID } = require('../../constants/workflows');
|
||||
const { WORKFLOW_MODEL_UID, WORKFLOW_POPULATE } = require('../../constants/workflows');
|
||||
|
||||
/**
|
||||
*
|
||||
@ -61,22 +61,25 @@ module.exports = {
|
||||
ctx.state.userAbility
|
||||
);
|
||||
const { populate } = await sanitizedQuery.update(query);
|
||||
|
||||
const workflowBody = await validateWorkflowUpdate(body.data);
|
||||
|
||||
const workflow = await workflowService.findById(id, { populate: ['stages'] });
|
||||
// Find if workflow exists
|
||||
const workflow = await workflowService.findById(id, { populate: WORKFLOW_POPULATE });
|
||||
if (!workflow) {
|
||||
return ctx.notFound();
|
||||
}
|
||||
const getPermittedFieldToUpdate = sanitizeUpdateInput(workflow);
|
||||
|
||||
// Sanitize input data
|
||||
const getPermittedFieldToUpdate = sanitizeUpdateInput(workflow);
|
||||
const dataToUpdate = await getPermittedFieldToUpdate(workflowBody);
|
||||
|
||||
// Update workflow
|
||||
const updatedWorkflow = await workflowService.update(workflow, {
|
||||
data: dataToUpdate,
|
||||
populate,
|
||||
});
|
||||
|
||||
// Send sanitized response
|
||||
ctx.body = {
|
||||
data: await sanitizeOutput(updatedWorkflow),
|
||||
};
|
||||
@ -96,7 +99,7 @@ module.exports = {
|
||||
);
|
||||
const { populate } = await sanitizedQuery.delete(query);
|
||||
|
||||
const workflow = await workflowService.findById(id, { populate: ['stages'] });
|
||||
const workflow = await workflowService.findById(id, { populate: WORKFLOW_POPULATE });
|
||||
if (!workflow) {
|
||||
return ctx.notFound("Workflow doesn't exist");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user