2020-10-21 20:12:22 +02:00
|
|
|
'use strict';
|
|
|
|
|
2020-10-22 16:43:51 +02:00
|
|
|
const { prop } = require('lodash/fp');
|
2021-04-29 13:51:12 +02:00
|
|
|
const { contentTypes: contentTypesUtils } = require('@strapi/utils');
|
2020-10-22 16:43:51 +02:00
|
|
|
const { getService } = require('../utils');
|
|
|
|
|
2020-10-21 20:12:22 +02:00
|
|
|
module.exports = {
|
2020-10-22 16:43:51 +02:00
|
|
|
canConfigureContentType({ userAbility, contentType }) {
|
|
|
|
const action = contentTypesUtils.isSingleType(contentType)
|
|
|
|
? 'plugins::content-manager.single-types.configure-view'
|
|
|
|
: 'plugins::content-manager.collection-types.configure-view';
|
2020-10-21 20:12:22 +02:00
|
|
|
|
|
|
|
return userAbility.can(action);
|
|
|
|
},
|
2020-10-22 16:43:51 +02:00
|
|
|
|
2021-03-25 14:59:44 +01:00
|
|
|
async registerPermissions() {
|
2020-10-22 16:43:51 +02:00
|
|
|
const displayedContentTypes = getService('content-types').findDisplayedContentTypes();
|
|
|
|
|
|
|
|
const contentTypesUids = displayedContentTypes.map(prop('uid'));
|
|
|
|
|
|
|
|
const draftAndPublishContentTypesUids = displayedContentTypes
|
|
|
|
.filter(contentTypesUtils.hasDraftAndPublish)
|
|
|
|
.map(prop('uid'));
|
|
|
|
|
|
|
|
const actions = [
|
|
|
|
{
|
|
|
|
section: 'contentTypes',
|
|
|
|
displayName: 'Create',
|
|
|
|
uid: 'explorer.create',
|
|
|
|
pluginName: 'content-manager',
|
|
|
|
subjects: contentTypesUids,
|
2021-03-25 14:59:44 +01:00
|
|
|
options: {
|
|
|
|
applyToProperties: ['fields'],
|
|
|
|
},
|
2020-10-22 16:43:51 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
section: 'contentTypes',
|
|
|
|
displayName: 'Read',
|
|
|
|
uid: 'explorer.read',
|
|
|
|
pluginName: 'content-manager',
|
|
|
|
subjects: contentTypesUids,
|
2021-03-25 14:59:44 +01:00
|
|
|
options: {
|
|
|
|
applyToProperties: ['fields'],
|
|
|
|
},
|
2020-10-22 16:43:51 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
section: 'contentTypes',
|
|
|
|
displayName: 'Update',
|
|
|
|
uid: 'explorer.update',
|
|
|
|
pluginName: 'content-manager',
|
|
|
|
subjects: contentTypesUids,
|
2021-03-25 14:59:44 +01:00
|
|
|
options: {
|
|
|
|
applyToProperties: ['fields'],
|
|
|
|
},
|
2020-10-22 16:43:51 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
section: 'contentTypes',
|
|
|
|
displayName: 'Delete',
|
|
|
|
uid: 'explorer.delete',
|
|
|
|
pluginName: 'content-manager',
|
|
|
|
subjects: contentTypesUids,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
section: 'contentTypes',
|
|
|
|
displayName: 'Publish',
|
|
|
|
uid: 'explorer.publish',
|
|
|
|
pluginName: 'content-manager',
|
|
|
|
subjects: draftAndPublishContentTypesUids,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
section: 'plugins',
|
|
|
|
displayName: 'Configure view',
|
|
|
|
uid: 'single-types.configure-view',
|
|
|
|
subCategory: 'single types',
|
|
|
|
pluginName: 'content-manager',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
section: 'plugins',
|
|
|
|
displayName: 'Configure view',
|
|
|
|
uid: 'collection-types.configure-view',
|
|
|
|
subCategory: 'collection types',
|
|
|
|
pluginName: 'content-manager',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
section: 'plugins',
|
|
|
|
displayName: 'Configure Layout',
|
|
|
|
uid: 'components.configure-layout',
|
|
|
|
subCategory: 'components',
|
|
|
|
pluginName: 'content-manager',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2021-03-25 14:59:44 +01:00
|
|
|
await strapi.admin.services.permission.actionProvider.registerMany(actions);
|
2020-10-22 16:43:51 +02:00
|
|
|
},
|
2020-10-21 20:12:22 +02:00
|
|
|
};
|