feat: populate stage permissions by default

This commit is contained in:
Marc-Roig 2023-08-04 14:55:35 +02:00
parent eb78a7f390
commit 5f8ee9e3a9
No known key found for this signature in database
GPG Key ID: FB4E2C43A0BEE249
3 changed files with 26 additions and 5 deletions

View File

@ -16,4 +16,16 @@ module.exports = {
'Youve 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"] },
}
}
}
}
},
};

View File

@ -40,6 +40,12 @@ module.exports = {
inversedBy: 'stages',
configurable: false,
},
permissions: {
type: 'relation',
target: 'admin::permission',
relation: 'manyToMany',
configurable: false,
}
},
},
};

View File

@ -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");
}