mirror of
https://github.com/strapi/strapi.git
synced 2025-08-09 09:14:49 +00:00
fix: remove review workflows from users and permissions
This commit is contained in:
parent
41844c2867
commit
f0d5be0b37
@ -98,6 +98,8 @@ export function WorkflowAttributes({
|
|||||||
defaultMessage: 'Collection Types',
|
defaultMessage: 'Collection Types',
|
||||||
}),
|
}),
|
||||||
children: collectionTypes
|
children: collectionTypes
|
||||||
|
// Filter plugin::users-permissions.user content type
|
||||||
|
.filter(({ uid }) => uid !== 'plugin::users-permissions.user')
|
||||||
.sort((a, b) => formatter.compare(a.info.displayName, b.info.displayName))
|
.sort((a, b) => formatter.compare(a.info.displayName, b.info.displayName))
|
||||||
.map((contentType) => ({
|
.map((contentType) => ({
|
||||||
label: contentType.info.displayName,
|
label: contentType.info.displayName,
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In 4.13.0 we decided users&permissions user content type will no longer be assigned to a workflow
|
||||||
|
* This migration cleanly un-assigns the user content type if it was assigned to a workflow
|
||||||
|
*/
|
||||||
|
const { isNil } = require('lodash/fp');
|
||||||
|
const { getService } = require('../utils');
|
||||||
|
const workflowContentTypesManager = require('../services/review-workflows/workflows/content-types');
|
||||||
|
|
||||||
|
async function migrateWorkflowsFilterUsersContentType({ oldContentTypes, contentTypes }) {
|
||||||
|
const userHadWorkflowStage = !isNil(
|
||||||
|
oldContentTypes['plugin::users-permissions.user']?.attributes.strapi_stage
|
||||||
|
);
|
||||||
|
const userHasWorkflowStage = !isNil(
|
||||||
|
contentTypes['plugin::users-permissions.user']?.attributes.strapi_stage
|
||||||
|
);
|
||||||
|
|
||||||
|
// If the user content type no longer has a workflow stage, it means
|
||||||
|
// this is the version where we decided to disable RW from the user content type
|
||||||
|
if (userHadWorkflowStage && !userHasWorkflowStage) {
|
||||||
|
const workflowService = getService('workflows', { strapi });
|
||||||
|
|
||||||
|
// Find if the user content type is assigned to a workflow
|
||||||
|
const assignedWorkflow = await workflowService.getAssignedWorkflow(
|
||||||
|
'plugin::users-permissions.user'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (assignedWorkflow) {
|
||||||
|
await workflowContentTypesManager({ strapi }).unassignContentType(
|
||||||
|
assignedWorkflow,
|
||||||
|
'plugin::users-permissions.user'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = migrateWorkflowsFilterUsersContentType;
|
@ -11,6 +11,7 @@ const migrateDeletedCTInWorkflows = require('./migrations/review-workflows-delet
|
|||||||
const createAuditLogsService = require('./services/audit-logs');
|
const createAuditLogsService = require('./services/audit-logs');
|
||||||
const reviewWorkflowsMiddlewares = require('./middlewares/review-workflows');
|
const reviewWorkflowsMiddlewares = require('./middlewares/review-workflows');
|
||||||
const { getService } = require('./utils');
|
const { getService } = require('./utils');
|
||||||
|
const migrateWorkflowsFilterUsersContentType = require('./migrations/review-workflows-filter-user-content-type');
|
||||||
|
|
||||||
module.exports = async ({ strapi }) => {
|
module.exports = async ({ strapi }) => {
|
||||||
const auditLogsIsEnabled = strapi.config.get('admin.auditLogs.enabled', true);
|
const auditLogsIsEnabled = strapi.config.get('admin.auditLogs.enabled', true);
|
||||||
@ -28,7 +29,8 @@ module.exports = async ({ strapi }) => {
|
|||||||
.register(migrateReviewWorkflowStagesColor)
|
.register(migrateReviewWorkflowStagesColor)
|
||||||
.register(migrateReviewWorkflowName)
|
.register(migrateReviewWorkflowName)
|
||||||
.register(migrateWorkflowsContentTypes)
|
.register(migrateWorkflowsContentTypes)
|
||||||
.register(migrateDeletedCTInWorkflows);
|
.register(migrateDeletedCTInWorkflows)
|
||||||
|
.register(migrateWorkflowsFilterUsersContentType);
|
||||||
const reviewWorkflowService = getService('review-workflows');
|
const reviewWorkflowService = getService('review-workflows');
|
||||||
|
|
||||||
reviewWorkflowsMiddlewares.contentTypeMiddleware(strapi);
|
reviewWorkflowsMiddlewares.contentTypeMiddleware(strapi);
|
||||||
|
@ -45,7 +45,7 @@ module.exports = ({ strapi }) => {
|
|||||||
await stagesService.updateEntitiesStage(uid, { toStageId: stageId });
|
await stagesService.updateEntitiesStage(uid, { toStageId: stageId });
|
||||||
// Transfer content types from the previous workflow(s)
|
// Transfer content types from the previous workflow(s)
|
||||||
await mapAsync(srcWorkflows, (srcWorkflow) =>
|
await mapAsync(srcWorkflows, (srcWorkflow) =>
|
||||||
this.transferContentTypes(srcWorkflow, uid)
|
this.removeContentTypeFromWorkflow(srcWorkflow, uid)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
await updateContentTypeConfig(uid, true);
|
await updateContentTypeConfig(uid, true);
|
||||||
@ -56,7 +56,7 @@ module.exports = ({ strapi }) => {
|
|||||||
toStageId: stageId,
|
toStageId: stageId,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// transferContentTypes can cause race conditions if called in parallel when updating the same workflow
|
// removeContentTypeFromWorkflow can cause race conditions if called in parallel when updating the same workflow
|
||||||
{ concurrency: 1 }
|
{ concurrency: 1 }
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ module.exports = ({ strapi }) => {
|
|||||||
* @param {Workflow} srcWorkflow - The workflow to transfer from
|
* @param {Workflow} srcWorkflow - The workflow to transfer from
|
||||||
* @param {string} uid - The content type uid
|
* @param {string} uid - The content type uid
|
||||||
*/
|
*/
|
||||||
async transferContentTypes(srcWorkflow, uid) {
|
async removeContentTypeFromWorkflow(srcWorkflow, uid) {
|
||||||
// Update assignedContentTypes of the previous workflow
|
// Update assignedContentTypes of the previous workflow
|
||||||
await strapi.entityService.update(WORKFLOW_MODEL_UID, srcWorkflow.id, {
|
await strapi.entityService.update(WORKFLOW_MODEL_UID, srcWorkflow.id, {
|
||||||
data: {
|
data: {
|
||||||
@ -79,6 +79,16 @@ module.exports = ({ strapi }) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all configurations related to a content type assigned on a workflow
|
||||||
|
* @param {*} srcWorkflow
|
||||||
|
* @param {*} uid
|
||||||
|
*/
|
||||||
|
async unassignContentType(srcWorkflow, uid) {
|
||||||
|
await this.removeContentTypeFromWorkflow(srcWorkflow, uid);
|
||||||
|
await updateContentTypeConfig(uid, false);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { getOr, keys, pickBy, pipe, has, clamp } = require('lodash/fp');
|
const { getOr, keys, pickBy, pipe, has, clamp, filter } = require('lodash/fp');
|
||||||
const {
|
const {
|
||||||
ENTITY_STAGE_ATTRIBUTE,
|
ENTITY_STAGE_ATTRIBUTE,
|
||||||
MAX_WORKFLOWS,
|
MAX_WORKFLOWS,
|
||||||
MAX_STAGES_PER_WORKFLOW,
|
MAX_STAGES_PER_WORKFLOW,
|
||||||
} = require('../constants/workflows');
|
} = require('../constants/workflows');
|
||||||
|
|
||||||
|
const RW_EXCLUDED_CONTENT_TYPES = ['plugin::users-permissions.user'];
|
||||||
|
|
||||||
const getVisibleContentTypesUID = pipe([
|
const getVisibleContentTypesUID = pipe([
|
||||||
// Pick only content-types visible in the content-manager and option is not false
|
// Pick only content-types visible in the content-manager and option is not false
|
||||||
pickBy(
|
pickBy(
|
||||||
@ -16,6 +18,7 @@ const getVisibleContentTypesUID = pipe([
|
|||||||
),
|
),
|
||||||
// Get UIDs
|
// Get UIDs
|
||||||
keys,
|
keys,
|
||||||
|
filter((uid) => !RW_EXCLUDED_CONTENT_TYPES.includes(uid)),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const hasStageAttribute = has(['attributes', ENTITY_STAGE_ATTRIBUTE]);
|
const hasStageAttribute = has(['attributes', ENTITY_STAGE_ATTRIBUTE]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user