mirror of
https://github.com/strapi/strapi.git
synced 2025-12-24 21:54:24 +00:00
wIP
This commit is contained in:
parent
2390c740a4
commit
3c9daba9a1
@ -25,10 +25,6 @@
|
||||
"via": "review",
|
||||
"collection": "like"
|
||||
},
|
||||
"author": {
|
||||
"model": "user",
|
||||
"plugin": "users-permissions"
|
||||
},
|
||||
"restaurant": {
|
||||
"model": "restaurant"
|
||||
}
|
||||
|
||||
@ -3,7 +3,9 @@
|
||||
const { getService } = require('../../utils');
|
||||
|
||||
module.exports = async () => {
|
||||
console.log('before');
|
||||
await getService('components').syncConfigurations();
|
||||
await getService('content-types').syncConfigurations();
|
||||
await getService('permission').registerPermissions();
|
||||
console.log('after');
|
||||
};
|
||||
|
||||
@ -4,8 +4,11 @@
|
||||
"description": "A powerful UI to easily manage your data.",
|
||||
"strapi": {
|
||||
"icon": "plug",
|
||||
"name": "content-manager",
|
||||
"displayName": "Content Manager",
|
||||
"description": "content-manager.plugin.description",
|
||||
"required": true
|
||||
"required": true,
|
||||
"kind": "plugin"
|
||||
},
|
||||
"dependencies": {
|
||||
"@buffetjs/core": "3.3.6",
|
||||
|
||||
5
packages/core/content-manager/server/bootstrap.js
vendored
Normal file
5
packages/core/content-manager/server/bootstrap.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const bootstrap = require('../config/functions/bootstrap');
|
||||
|
||||
module.exports = bootstrap;
|
||||
6
packages/core/content-manager/server/config.js
Normal file
6
packages/core/content-manager/server/config.js
Normal file
@ -0,0 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
default: {},
|
||||
validator: () => {},
|
||||
};
|
||||
@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = [];
|
||||
17
packages/core/content-manager/server/controllers/index.js
Normal file
17
packages/core/content-manager/server/controllers/index.js
Normal file
@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
const collectionTypes = require('../../controllers/collection-types');
|
||||
const components = require('../../controllers/components');
|
||||
const contentTypes = require('../../controllers/content-types');
|
||||
const relations = require('../../controllers/relations');
|
||||
const singleTypes = require('../../controllers/single-types');
|
||||
const uid = require('../../controllers/uid');
|
||||
|
||||
module.exports = {
|
||||
'collection-types': collectionTypes,
|
||||
components,
|
||||
'content-types': contentTypes,
|
||||
relations,
|
||||
'single-types': singleTypes,
|
||||
uid,
|
||||
};
|
||||
11
packages/core/content-manager/server/policies/index.js
Normal file
11
packages/core/content-manager/server/policies/index.js
Normal file
@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
const hasDraftAndPublish = require('../../config/policies/has-draft-and-publish');
|
||||
const hasPermissions = require('../../config/policies/hasPermissions');
|
||||
const routing = require('../../config/policies/routing');
|
||||
|
||||
module.exports = {
|
||||
'has-draft-and-publish': hasDraftAndPublish,
|
||||
hasPermissions,
|
||||
routing,
|
||||
};
|
||||
5
packages/core/content-manager/server/routes/index.js
Normal file
5
packages/core/content-manager/server/routes/index.js
Normal file
@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const routes = require('../../config/routes');
|
||||
|
||||
module.exports = routes.routes;
|
||||
19
packages/core/content-manager/server/services/index.js
Normal file
19
packages/core/content-manager/server/services/index.js
Normal file
@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
const components = require('../../services/components');
|
||||
const contentTypes = require('../../services/content-types');
|
||||
const dataMapper = require('../../services/data-mapper');
|
||||
const metrics = require('../../services/metrics');
|
||||
const permissionChecker = require('../../services/permission-checker');
|
||||
const permission = require('../../services/permission');
|
||||
const uid = require('../../services/uid');
|
||||
|
||||
module.exports = {
|
||||
components,
|
||||
'content-types': contentTypes,
|
||||
'data-mapper': dataMapper,
|
||||
metrics,
|
||||
'permission-checker': permissionChecker,
|
||||
permission,
|
||||
uid,
|
||||
};
|
||||
@ -19,7 +19,7 @@ const configurationService = createConfigurationService({
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
module.exports = ({ strapi }) => ({
|
||||
findAllComponents() {
|
||||
const { toContentManagerModel } = getService('data-mapper');
|
||||
|
||||
@ -89,4 +89,4 @@ module.exports = {
|
||||
syncConfigurations() {
|
||||
return configurationService.syncConfigurations();
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
@ -17,7 +17,7 @@ const configurationService = createConfigurationService({
|
||||
},
|
||||
});
|
||||
|
||||
const service = {
|
||||
const service = ({ strapi }) => ({
|
||||
findAllContentTypes() {
|
||||
const { toContentManagerModel } = getService('data-mapper');
|
||||
|
||||
@ -68,6 +68,6 @@ const service = {
|
||||
syncConfigurations() {
|
||||
return configurationService.syncConfigurations();
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
module.exports = service;
|
||||
|
||||
@ -18,7 +18,7 @@ const dtoFields = [
|
||||
'pluginOptions',
|
||||
];
|
||||
|
||||
module.exports = {
|
||||
module.exports = () => ({
|
||||
toContentManagerModel(contentType) {
|
||||
return {
|
||||
...contentType,
|
||||
@ -39,7 +39,7 @@ module.exports = {
|
||||
},
|
||||
|
||||
toDto: pick(dtoFields),
|
||||
};
|
||||
});
|
||||
|
||||
const formatContentTypeLabel = contentType => {
|
||||
const name = prop('info.name', contentType) || contentType.modelName;
|
||||
|
||||
@ -34,7 +34,7 @@ const findCreatorRoles = entity => {
|
||||
return [];
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
module.exports = ({ strapi }) => ({
|
||||
async assocCreatorRoles(entity) {
|
||||
if (!entity) {
|
||||
return entity;
|
||||
@ -137,4 +137,4 @@ module.exports = {
|
||||
|
||||
return strapi.entityService.update({ params, data }, { model });
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
const { intersection, prop } = require('lodash/fp');
|
||||
const { getRelationalFields } = require('@strapi/utils').relations;
|
||||
|
||||
const sendDidConfigureListView = async (contentType, configuration) => {
|
||||
const sendDidConfigureListView = strapi => async (contentType, configuration) => {
|
||||
const displayedFields = prop('length', configuration.layouts.list);
|
||||
const relationalFields = getRelationalFields(contentType);
|
||||
const displayedRelationalFields = intersection(relationalFields, configuration.layouts.list)
|
||||
@ -27,6 +27,6 @@ const sendDidConfigureListView = async (contentType, configuration) => {
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
sendDidConfigureListView,
|
||||
};
|
||||
module.exports = ({ strapi }) => ({
|
||||
sendDidConfigureListView: sendDidConfigureListView(strapi),
|
||||
});
|
||||
|
||||
@ -9,7 +9,7 @@ const ACTIONS = {
|
||||
unpublish: 'plugins::content-manager.explorer.publish',
|
||||
};
|
||||
|
||||
const createPermissionChecker = ({ userAbility, model }) => {
|
||||
const createPermissionChecker = strapi => ({ userAbility, model }) => {
|
||||
const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
|
||||
ability: userAbility,
|
||||
model,
|
||||
@ -64,6 +64,6 @@ const createPermissionChecker = ({ userAbility, model }) => {
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
create: createPermissionChecker,
|
||||
};
|
||||
module.exports = ({ strapi }) => ({
|
||||
create: createPermissionChecker(strapi),
|
||||
});
|
||||
|
||||
@ -4,7 +4,7 @@ const { prop } = require('lodash/fp');
|
||||
const { contentTypes: contentTypesUtils } = require('@strapi/utils');
|
||||
const { getService } = require('../utils');
|
||||
|
||||
module.exports = {
|
||||
module.exports = ({ strapi }) => ({
|
||||
canConfigureContentType({ userAbility, contentType }) {
|
||||
const action = contentTypesUtils.isSingleType(contentType)
|
||||
? 'plugins::content-manager.single-types.configure-view'
|
||||
@ -15,7 +15,6 @@ module.exports = {
|
||||
|
||||
async registerPermissions() {
|
||||
const displayedContentTypes = getService('content-types').findDisplayedContentTypes();
|
||||
|
||||
const contentTypesUids = displayedContentTypes.map(prop('uid'));
|
||||
|
||||
const draftAndPublishContentTypesUids = displayedContentTypes
|
||||
@ -92,4 +91,4 @@ module.exports = {
|
||||
|
||||
await strapi.admin.services.permission.actionProvider.registerMany(actions);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
const _ = require('lodash');
|
||||
const slugify = require('@sindresorhus/slugify');
|
||||
|
||||
module.exports = {
|
||||
module.exports = ({ strapi }) => ({
|
||||
async generateUIDField({ contentTypeUID, field, data }) {
|
||||
const contentType = strapi.contentTypes[contentTypeUID];
|
||||
const { attributes } = contentType;
|
||||
@ -60,4 +60,4 @@ module.exports = {
|
||||
if (count > 0) return false;
|
||||
return true;
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
20
packages/core/content-manager/strapi-server.js
Normal file
20
packages/core/content-manager/strapi-server.js
Normal file
@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
const bootstrap = require('./server/bootstrap');
|
||||
const contentTypes = require('./server/content-types');
|
||||
const policies = require('./server/policies');
|
||||
const services = require('./server/services');
|
||||
const routes = require('./server/routes');
|
||||
const controllers = require('./server/controllers');
|
||||
|
||||
module.exports = () => {
|
||||
return {
|
||||
register: () => {},
|
||||
bootstrap,
|
||||
routes,
|
||||
controllers,
|
||||
contentTypes,
|
||||
policies,
|
||||
services,
|
||||
};
|
||||
};
|
||||
@ -154,7 +154,6 @@ class DatabaseManager {
|
||||
if (!pluginName) {
|
||||
return strapi.models;
|
||||
}
|
||||
console.log('pluginName', pluginName);
|
||||
return pluginName === 'admin' ? strapi.admin.models : strapi.plugins[pluginName].models;
|
||||
}
|
||||
|
||||
|
||||
@ -335,6 +335,8 @@ class Strapi {
|
||||
}
|
||||
});
|
||||
|
||||
console.log('this.config.autoReload', this.config.autoReload);
|
||||
|
||||
await this.container.load();
|
||||
|
||||
const modules = await loadModules(this);
|
||||
@ -519,7 +521,7 @@ class Strapi {
|
||||
}
|
||||
|
||||
module.exports = options => {
|
||||
const strapi = new Strapi(options);
|
||||
const strapi = new Strapi({ ...options, autoReload: false });
|
||||
global.strapi = strapi;
|
||||
return strapi;
|
||||
};
|
||||
|
||||
@ -12,7 +12,7 @@ module.exports = policiesDefinition => {
|
||||
return policies.get(policyName);
|
||||
},
|
||||
getAll() {
|
||||
return Array.from(policies.values());
|
||||
return Object.fromEntries(policies);
|
||||
},
|
||||
get size() {
|
||||
return policies.size;
|
||||
|
||||
@ -23,6 +23,7 @@ ${e.errors}
|
||||
uid: `application::${apiName}.${definition.schema.info.singularName}`,
|
||||
apiName,
|
||||
collectionName: definition.schema.collectionName || definition.schema.info.singularName,
|
||||
globalId: getGlobalId(definition.schema, definition.schema.info.singularName),
|
||||
});
|
||||
} else if (pluginName) {
|
||||
Object.assign(createdContentType.schema, {
|
||||
@ -31,11 +32,13 @@ ${e.errors}
|
||||
collectionName:
|
||||
createdContentType.schema.collectionName ||
|
||||
`${pluginName}_${definition.schema.info.singularName}`.toLowerCase(),
|
||||
globalId: getGlobalId(definition.schema, definition.schema.info.singularName, pluginName),
|
||||
});
|
||||
} else {
|
||||
Object.assign(createdContentType.schema, {
|
||||
uid: `strapi::${definition.schema.info.singularName}`,
|
||||
plugin: 'admin',
|
||||
globalId: getGlobalId(definition.schema, definition.schema.info.singularName, 'admin'),
|
||||
});
|
||||
}
|
||||
|
||||
@ -55,6 +58,12 @@ ${e.errors}
|
||||
return createdContentType;
|
||||
};
|
||||
|
||||
const getGlobalId = (model, modelName, prefix) => {
|
||||
let globalId = prefix ? `${prefix}-${modelName}` : modelName;
|
||||
|
||||
return model.globalId || _.upperFirst(_.camelCase(globalId));
|
||||
};
|
||||
|
||||
const pickSchema = model => {
|
||||
const schema = _.cloneDeep(
|
||||
_.pick(model, [
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const _ = require('lodash');
|
||||
const { mapKeys, toLower } = require('lodash/fp');
|
||||
const { getConfigUrls } = require('@strapi/utils');
|
||||
const { createContentType } = require('../domain/content-type');
|
||||
|
||||
@ -35,8 +36,9 @@ module.exports = function(strapi) {
|
||||
ct.schema.info.singularName = _.camelCase(modelName);
|
||||
ct.schema.info.pluralName = `${_.camelCase(modelName)}s`;
|
||||
|
||||
strapi.contentTypes[model.uid] = createContentType(ct, { apiName });
|
||||
Object.assign(model, strapi.contentTypes[model.uid].schema);
|
||||
const createdContentType = createContentType(ct, { apiName });
|
||||
Object.assign(model, createdContentType.schema);
|
||||
strapi.contentTypes[model.uid] = model;
|
||||
|
||||
const { service, controller } = createCoreApi({ model, api, strapi });
|
||||
|
||||
@ -97,8 +99,10 @@ module.exports = function(strapi) {
|
||||
ct.schema.info.singularName = _.camelCase(modelName);
|
||||
ct.schema.info.pluralName = `${_.camelCase(modelName)}s`;
|
||||
|
||||
strapi.contentTypes[model.uid] = createContentType(ct);
|
||||
Object.assign(model, strapi.contentTypes[model.uid].schema);
|
||||
const createdContentType = createContentType(ct);
|
||||
|
||||
Object.assign(model, createdContentType.schema);
|
||||
strapi.contentTypes[model.uid] = model;
|
||||
});
|
||||
|
||||
// Object.keys(strapi.plugins).forEach(pluginName => {
|
||||
@ -107,7 +111,7 @@ module.exports = function(strapi) {
|
||||
// controllers: plugin.controllers || [],
|
||||
// services: plugin.services || [],
|
||||
// models: plugin.models || [],
|
||||
// // });
|
||||
// });
|
||||
|
||||
// Object.keys(plugin.controllers).forEach(key => {
|
||||
// let controller = plugin.controllers[key];
|
||||
@ -137,15 +141,16 @@ module.exports = function(strapi) {
|
||||
strapi.plugins[ct.schema.plugin].models[ct.schema.modelName] = ct.schema;
|
||||
});
|
||||
|
||||
// const policies = strapi.container.plugins.policies.getAll();
|
||||
// console.log('policies', policies);
|
||||
// Object.assign(strapi.container.plugins, policies);
|
||||
// for (const plugin in policies) {
|
||||
// console.log('plugin policies', plugin);
|
||||
// strapi.plugins[plugin].config = strapi.plugins[plugin].config || {};
|
||||
// strapi.plugins[plugin].config.policies = strapi.plugins[plugin].config.policies || {};
|
||||
// Object.assign(strapi.plugins[plugin].config.policies, policies[plugin]);
|
||||
// }
|
||||
strapi.plugins.i18n;
|
||||
strapi.plugins.get;
|
||||
|
||||
const policies = strapi.container.plugins.policies.getAll();
|
||||
Object.assign(strapi.container.plugins, policies);
|
||||
for (const plugin in policies) {
|
||||
strapi.plugins[plugin].config = strapi.plugins[plugin].config || {};
|
||||
strapi.plugins[plugin].config.policies = strapi.plugins[plugin].config.policies || {};
|
||||
Object.assign(strapi.plugins[plugin].config.policies, mapKeys(toLower, policies[plugin]));
|
||||
}
|
||||
|
||||
// const pluginServices = strapi.container.plugins.services.getAll();
|
||||
// for (const plugin in pluginServices) {
|
||||
|
||||
@ -12,7 +12,6 @@ const findPackagePath = require('../../load/package-path');
|
||||
*/
|
||||
module.exports = async function(strapi) {
|
||||
const installedMiddlewares = strapi.config.get('installedMiddlewares');
|
||||
console.log('installedMiddlewares', installedMiddlewares);
|
||||
const appPath = strapi.config.get('appPath');
|
||||
|
||||
let middlewares = {};
|
||||
@ -38,7 +37,6 @@ module.exports = async function(strapi) {
|
||||
*/
|
||||
const createLoaders = strapi => {
|
||||
const loadMiddlewaresInDir = async (dir, middlewares) => {
|
||||
console.log('dir', dir);
|
||||
const files = await glob('*/*(index|defaults).*(js|json)', {
|
||||
cwd: dir,
|
||||
});
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const { join } = require('path');
|
||||
const { defaultsDeep } = require('lodash/fp');
|
||||
const { defaultsDeep, mapKeys, toLower } = require('lodash/fp');
|
||||
const { env } = require('@strapi/utils');
|
||||
const createServiceProvider = require('../base-providers/service-provider');
|
||||
const createContentTypeProvider = require('../base-providers/content-type-provider');
|
||||
@ -65,7 +65,7 @@ ${e.errors.join('\n')}
|
||||
bootstrap: () => cleanPluginServer.bootstrap(strapi),
|
||||
register: () => cleanPluginServer.register(strapi),
|
||||
destroy: cleanPluginServer.destroy,
|
||||
controllers: cleanPluginServer.controllers,
|
||||
controllers: mapKeys(toLower)(cleanPluginServer.controllers),
|
||||
routes: cleanPluginServer.routes,
|
||||
service: (...args) => this.services.get(...args),
|
||||
services: new Proxy(
|
||||
|
||||
@ -24,7 +24,6 @@ module.exports = strapi => {
|
||||
*/
|
||||
|
||||
async initialize() {
|
||||
console.log('INITIAILIZE');
|
||||
const { defaultIndex, maxAge, path: publicPath } = strapi.config.middleware.settings.public;
|
||||
const staticDir = path.resolve(strapi.dir, publicPath || strapi.config.paths.static);
|
||||
|
||||
|
||||
@ -33,7 +33,6 @@ const resolvePolicy = policyName => {
|
||||
};
|
||||
|
||||
const searchLocalPolicy = (policy, plugin, apiName) => {
|
||||
console.log('search policy', policy);
|
||||
let [absoluteApiName, policyName] = policy.split('.');
|
||||
let absoluteApi = _.get(strapi.api, absoluteApiName);
|
||||
const resolver = policyResolvers.find(({ name }) => name === 'plugin');
|
||||
@ -103,17 +102,11 @@ const policyResolvers = [
|
||||
return _.startsWith(policy, PLUGIN_PREFIX);
|
||||
},
|
||||
exists(policy) {
|
||||
console.log('policy exists', policy);
|
||||
return this.is(policy) && !_.isUndefined(this.get(policy));
|
||||
},
|
||||
get(policy) {
|
||||
console.log('policy get', policy);
|
||||
const [plugin = '', policyName = ''] = stripPolicy(policy, PLUGIN_PREFIX).split('.');
|
||||
console.log('policyName', policyName);
|
||||
console.log('plugin', plugin);
|
||||
const foundPolicy = getPolicyIn(_.get(strapi, ['plugins', plugin]), policyName);
|
||||
console.log('self', strapi.plugins[plugin]);
|
||||
console.log('foundPolicy', foundPolicy);
|
||||
return foundPolicy;
|
||||
},
|
||||
},
|
||||
@ -136,18 +129,6 @@ const get = (policy, plugin, apiName) => {
|
||||
|
||||
const resolvedPolicy = resolvePolicy(policyName);
|
||||
|
||||
if (plugin === 'i18n') {
|
||||
console.log('plugin', plugin);
|
||||
console.log('policy', policy);
|
||||
}
|
||||
|
||||
// console.log('policyName', policyName);
|
||||
// console.log('policy', policy);
|
||||
// console.log('plugin', plugin);
|
||||
// console.log('apiName', apiName);
|
||||
// console.log('args', args);
|
||||
// console.log('resolvedPolicy', resolvedPolicy);
|
||||
|
||||
if (resolvedPolicy !== undefined) {
|
||||
return isPolicyFactory(policy) ? resolvedPolicy(...args) : resolvedPolicy;
|
||||
}
|
||||
|
||||
@ -211,7 +211,6 @@ module.exports = async () => {
|
||||
await pluginStore.set({ key: 'advanced', value });
|
||||
}
|
||||
|
||||
console.log(strapi.plugins['users-permissions'].services);
|
||||
await strapi.plugins['users-permissions'].services['users-permissions'].initialize();
|
||||
|
||||
if (!_.get(strapi.plugins['users-permissions'], 'config.jwtSecret')) {
|
||||
|
||||
@ -337,7 +337,6 @@ module.exports = ({ strapi }) => ({
|
||||
},
|
||||
|
||||
async initialize() {
|
||||
console.log('strapi', strapi.app);
|
||||
const roleCount = await strapi.query('role', 'users-permissions').count();
|
||||
|
||||
if (roleCount === 0) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user