mirror of
https://github.com/strapi/strapi.git
synced 2025-11-11 07:39:16 +00:00
Merge branch 'v4/backend' into v4/graphql-schema-generation-refactor
This commit is contained in:
commit
466161ca70
@ -17,7 +17,7 @@ module.exports = strapi => ({
|
|||||||
const loadFeaturesRoutes = () => {
|
const loadFeaturesRoutes = () => {
|
||||||
for (const [feature, getFeatureRoutes] of Object.entries(routes)) {
|
for (const [feature, getFeatureRoutes] of Object.entries(routes)) {
|
||||||
if (features.isEnabled(feature)) {
|
if (features.isEnabled(feature)) {
|
||||||
strapi.admin.config.routes.push(...getFeatureRoutes); // TODO
|
strapi.admin.routes.push(...getFeatureRoutes); // TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
35
packages/core/admin/ee/server/bootstrap.js
vendored
Normal file
35
packages/core/admin/ee/server/bootstrap.js
vendored
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// eslint-disable-next-line node/no-extraneous-require
|
||||||
|
const { features } = require('@strapi/strapi/lib/utils/ee');
|
||||||
|
const executeCEBootstrap = require('../../server/bootstrap');
|
||||||
|
const { getService } = require('../../server/utils');
|
||||||
|
|
||||||
|
const SSO_ACTIONS = [
|
||||||
|
{
|
||||||
|
uid: 'provider-login.read',
|
||||||
|
displayName: 'Read',
|
||||||
|
pluginName: 'admin',
|
||||||
|
section: 'settings',
|
||||||
|
category: 'single sign on',
|
||||||
|
subCategory: 'options',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
uid: 'provider-login.update',
|
||||||
|
displayName: 'Update',
|
||||||
|
pluginName: 'admin',
|
||||||
|
section: 'settings',
|
||||||
|
category: 'single sign on',
|
||||||
|
subCategory: 'options',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
module.exports = async () => {
|
||||||
|
const { actionProvider } = getService('permission');
|
||||||
|
|
||||||
|
if (features.isEnabled('sso')) {
|
||||||
|
await actionProvider.registerMany(SSO_ACTIONS);
|
||||||
|
}
|
||||||
|
|
||||||
|
await executeCEBootstrap();
|
||||||
|
};
|
||||||
@ -1,24 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
features: {
|
|
||||||
sso: [
|
|
||||||
{
|
|
||||||
uid: 'provider-login.read',
|
|
||||||
displayName: 'Read',
|
|
||||||
pluginName: 'admin',
|
|
||||||
section: 'settings',
|
|
||||||
category: 'single sign on',
|
|
||||||
subCategory: 'options',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
uid: 'provider-login.update',
|
|
||||||
displayName: 'Update',
|
|
||||||
pluginName: 'admin',
|
|
||||||
section: 'settings',
|
|
||||||
category: 'single sign on',
|
|
||||||
subCategory: 'options',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
// eslint-disable-next-line node/no-extraneous-require
|
|
||||||
const { features } = require('@strapi/strapi/lib/utils/ee');
|
|
||||||
const executeCEBootstrap = require('../../../../server/config/functions/bootstrap');
|
|
||||||
const {
|
|
||||||
features: { sso: ssoActions },
|
|
||||||
} = require('../admin-actions');
|
|
||||||
|
|
||||||
const { getService } = require('../../../../server/utils');
|
|
||||||
|
|
||||||
module.exports = async () => {
|
|
||||||
const { actionProvider } = getService('permission');
|
|
||||||
|
|
||||||
if (features.isEnabled('sso')) {
|
|
||||||
await actionProvider.registerMany(ssoActions);
|
|
||||||
}
|
|
||||||
|
|
||||||
await executeCEBootstrap();
|
|
||||||
};
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
functions: {
|
|
||||||
bootstrap: require('./functions/bootstrap'),
|
|
||||||
},
|
|
||||||
routes: require('./routes').routes,
|
|
||||||
};
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
{
|
|
||||||
"routes": [
|
|
||||||
{
|
|
||||||
"method": "POST",
|
|
||||||
"path": "/roles",
|
|
||||||
"handler": "role.create",
|
|
||||||
"config": {
|
|
||||||
"policies": []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "DELETE",
|
|
||||||
"path": "/roles/:id",
|
|
||||||
"handler": "role.deleteOne",
|
|
||||||
"config": {
|
|
||||||
"policies": []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "POST",
|
|
||||||
"path": "/roles/batch-delete",
|
|
||||||
"handler": "role.deleteMany",
|
|
||||||
"config": {
|
|
||||||
"policies": []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// TODO: update load middleware to not load the admin middleware from here
|
// TODO: update load middleware to not load the admin middleware from here
|
||||||
config: require('./config'),
|
bootstrap: require('./bootstrap'),
|
||||||
|
routes: require('./routes'),
|
||||||
services: require('./services'),
|
services: require('./services'),
|
||||||
controllers: require('./controllers'),
|
controllers: require('./controllers'),
|
||||||
};
|
};
|
||||||
|
|||||||
28
packages/core/admin/ee/server/routes.js
Normal file
28
packages/core/admin/ee/server/routes.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = [
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
path: '/roles',
|
||||||
|
handler: 'role.create',
|
||||||
|
config: {
|
||||||
|
policies: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'DELETE',
|
||||||
|
path: '/roles/:id',
|
||||||
|
handler: 'role.deleteOne',
|
||||||
|
config: {
|
||||||
|
policies: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
path: '/roles/batch-delete',
|
||||||
|
handler: 'role.deleteMany',
|
||||||
|
config: {
|
||||||
|
policies: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
@ -18,7 +18,7 @@ module.exports = strapi => ({
|
|||||||
if (isValid) {
|
if (isValid) {
|
||||||
// request is made by an admin
|
// request is made by an admin
|
||||||
const admin = await strapi
|
const admin = await strapi
|
||||||
.query('strapi::user')
|
.query('admin::user')
|
||||||
.findOne({ where: { id: payload.id }, populate: ['roles'] });
|
.findOne({ where: { id: payload.id }, populate: ['roles'] });
|
||||||
|
|
||||||
if (!admin || !(admin.isActive === true)) {
|
if (!admin || !(admin.isActive === true)) {
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { merge } = require('lodash/fp');
|
const { merge } = require('lodash/fp');
|
||||||
const { getService } = require('../../utils');
|
const { getService } = require('./utils');
|
||||||
const adminActions = require('../admin-actions');
|
const adminActions = require('./config/admin-actions');
|
||||||
const adminConditions = require('../admin-conditions');
|
const adminConditions = require('./config/admin-conditions');
|
||||||
|
|
||||||
const defaultAdminAuthSettings = {
|
const defaultAdminAuthSettings = {
|
||||||
providers: {
|
providers: {
|
||||||
@ -1,15 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
functions: {
|
|
||||||
bootstrap: require('./functions/bootstrap'),
|
|
||||||
register: require('./functions/register'),
|
|
||||||
},
|
|
||||||
policies: {
|
policies: {
|
||||||
hasPermissions: require('./policies/hasPermissions'),
|
hasPermissions: require('./policies/hasPermissions'),
|
||||||
isAuthenticatedAdmin: require('./policies/isAuthenticatedAdmin'),
|
isAuthenticatedAdmin: require('./policies/isAuthenticatedAdmin'),
|
||||||
},
|
},
|
||||||
routes: require('./routes').routes,
|
|
||||||
layout: require('./layout'),
|
layout: require('./layout'),
|
||||||
...require('./settings'),
|
...require('./settings'),
|
||||||
};
|
};
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
const { has, isObject } = require('lodash/fp');
|
const { has, isObject } = require('lodash/fp');
|
||||||
|
|
||||||
const permissionModelUID = 'strapi::permission';
|
const permissionModelUID = 'admin::permission';
|
||||||
|
|
||||||
const hasAttribute = attribute => has(`attributes.${attribute}`);
|
const hasAttribute = attribute => has(`attributes.${attribute}`);
|
||||||
const hasFieldsAttribute = hasAttribute('fields');
|
const hasFieldsAttribute = hasAttribute('fields');
|
||||||
|
|||||||
@ -1,319 +0,0 @@
|
|||||||
{
|
|
||||||
"routes": [
|
|
||||||
{
|
|
||||||
"method": "GET",
|
|
||||||
"path": "/plugins",
|
|
||||||
"handler": "admin.plugins",
|
|
||||||
"config": {
|
|
||||||
"policies": [
|
|
||||||
"admin::isAuthenticatedAdmin",
|
|
||||||
["admin::hasPermissions", ["admin::marketplace.read"]]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "GET",
|
|
||||||
"path": "/init",
|
|
||||||
"handler": "admin.init"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "GET",
|
|
||||||
"path": "/project-type",
|
|
||||||
"handler": "admin.getProjectType"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "GET",
|
|
||||||
"path": "/information",
|
|
||||||
"handler": "admin.information",
|
|
||||||
"config": {
|
|
||||||
"policies": ["admin::isAuthenticatedAdmin"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "POST",
|
|
||||||
"path": "/plugins/install",
|
|
||||||
"handler": "admin.installPlugin",
|
|
||||||
"config": {
|
|
||||||
"policies": [
|
|
||||||
"admin::isAuthenticatedAdmin",
|
|
||||||
["admin::hasPermissions", ["admin::marketplace.plugins.install"]]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "DELETE",
|
|
||||||
"path": "/plugins/uninstall/:plugin",
|
|
||||||
"handler": "admin.uninstallPlugin",
|
|
||||||
"config": {
|
|
||||||
"policies": [
|
|
||||||
"admin::isAuthenticatedAdmin",
|
|
||||||
["admin::hasPermissions", ["admin::marketplace.plugins.uninstall"]]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "POST",
|
|
||||||
"path": "/login",
|
|
||||||
"handler": "authentication.login"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "POST",
|
|
||||||
"path": "/renew-token",
|
|
||||||
"handler": "authentication.renewToken"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "POST",
|
|
||||||
"path": "/register-admin",
|
|
||||||
"handler": "authentication.registerAdmin"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "GET",
|
|
||||||
"path": "/registration-info",
|
|
||||||
"handler": "authentication.registrationInfo"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "POST",
|
|
||||||
"path": "/register",
|
|
||||||
"handler": "authentication.register"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "POST",
|
|
||||||
"path": "/forgot-password",
|
|
||||||
"handler": "authentication.forgotPassword"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "POST",
|
|
||||||
"path": "/reset-password",
|
|
||||||
"handler": "authentication.resetPassword"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "GET",
|
|
||||||
"path": "/webhooks",
|
|
||||||
"handler": "Webhooks.listWebhooks",
|
|
||||||
"config": {
|
|
||||||
"policies": [
|
|
||||||
"admin::isAuthenticatedAdmin",
|
|
||||||
["admin::hasPermissions", ["admin::webhooks.read"]]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "POST",
|
|
||||||
"path": "/webhooks",
|
|
||||||
"handler": "Webhooks.createWebhook",
|
|
||||||
"config": {
|
|
||||||
"policies": [
|
|
||||||
"admin::isAuthenticatedAdmin",
|
|
||||||
["admin::hasPermissions", ["admin::webhooks.create"]]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "GET",
|
|
||||||
"path": "/webhooks/:id",
|
|
||||||
"handler": "Webhooks.getWebhook",
|
|
||||||
"config": {
|
|
||||||
"policies": [
|
|
||||||
"admin::isAuthenticatedAdmin",
|
|
||||||
["admin::hasPermissions", ["admin::webhooks.read"]]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "PUT",
|
|
||||||
"path": "/webhooks/:id",
|
|
||||||
"handler": "Webhooks.updateWebhook",
|
|
||||||
"config": {
|
|
||||||
"policies": [
|
|
||||||
"admin::isAuthenticatedAdmin",
|
|
||||||
["admin::hasPermissions", ["admin::webhooks.update"]]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "DELETE",
|
|
||||||
"path": "/webhooks/:id",
|
|
||||||
"handler": "Webhooks.deleteWebhook",
|
|
||||||
"config": {
|
|
||||||
"policies": [
|
|
||||||
"admin::isAuthenticatedAdmin",
|
|
||||||
["admin::hasPermissions", ["admin::webhooks.delete"]]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "POST",
|
|
||||||
"path": "/webhooks/batch-delete",
|
|
||||||
"handler": "Webhooks.deleteWebhooks",
|
|
||||||
"config": {
|
|
||||||
"policies": [
|
|
||||||
"admin::isAuthenticatedAdmin",
|
|
||||||
["admin::hasPermissions", ["admin::webhooks.delete"]]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "POST",
|
|
||||||
"path": "/webhooks/:id/trigger",
|
|
||||||
"handler": "Webhooks.triggerWebhook",
|
|
||||||
"config": {
|
|
||||||
"policies": []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "GET",
|
|
||||||
"path": "/users/me",
|
|
||||||
"handler": "authenticated-user.getMe",
|
|
||||||
"config": {
|
|
||||||
"policies": ["admin::isAuthenticatedAdmin"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "PUT",
|
|
||||||
"path": "/users/me",
|
|
||||||
"handler": "authenticated-user.updateMe",
|
|
||||||
"config": {
|
|
||||||
"policies": ["admin::isAuthenticatedAdmin"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "GET",
|
|
||||||
"path": "/users/me/permissions",
|
|
||||||
"handler": "authenticated-user.getOwnPermissions",
|
|
||||||
"config": {
|
|
||||||
"policies": ["admin::isAuthenticatedAdmin"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "POST",
|
|
||||||
"path": "/users",
|
|
||||||
"handler": "user.create",
|
|
||||||
"config": {
|
|
||||||
"policies": [
|
|
||||||
"admin::isAuthenticatedAdmin",
|
|
||||||
["admin::hasPermissions", ["admin::users.create"]]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "GET",
|
|
||||||
"path": "/users",
|
|
||||||
"handler": "user.find",
|
|
||||||
"config": {
|
|
||||||
"policies": [
|
|
||||||
"admin::isAuthenticatedAdmin",
|
|
||||||
["admin::hasPermissions", ["admin::users.read"]]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "GET",
|
|
||||||
"path": "/users/:id",
|
|
||||||
"handler": "user.findOne",
|
|
||||||
"config": {
|
|
||||||
"policies": [
|
|
||||||
"admin::isAuthenticatedAdmin",
|
|
||||||
["admin::hasPermissions", ["admin::users.read"]]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "PUT",
|
|
||||||
"path": "/users/:id",
|
|
||||||
"handler": "user.update",
|
|
||||||
"config": {
|
|
||||||
"policies": [
|
|
||||||
"admin::isAuthenticatedAdmin",
|
|
||||||
["admin::hasPermissions", ["admin::users.update"]]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "DELETE",
|
|
||||||
"path": "/users/:id",
|
|
||||||
"handler": "user.deleteOne",
|
|
||||||
"config": {
|
|
||||||
"policies": [["admin::hasPermissions", ["admin::users.delete"]]]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "POST",
|
|
||||||
"path": "/users/batch-delete",
|
|
||||||
"handler": "user.deleteMany",
|
|
||||||
"config": {
|
|
||||||
"policies": [["admin::hasPermissions", ["admin::users.delete"]]]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "GET",
|
|
||||||
"path": "/roles/:id/permissions",
|
|
||||||
"handler": "role.getPermissions",
|
|
||||||
"config": {
|
|
||||||
"policies": [
|
|
||||||
"admin::isAuthenticatedAdmin",
|
|
||||||
["admin::hasPermissions", ["admin::roles.read"]]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "PUT",
|
|
||||||
"path": "/roles/:id/permissions",
|
|
||||||
"handler": "role.updatePermissions",
|
|
||||||
"config": {
|
|
||||||
"policies": [
|
|
||||||
"admin::isAuthenticatedAdmin",
|
|
||||||
["admin::hasPermissions", ["admin::roles.update"]]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "GET",
|
|
||||||
"path": "/roles/:id",
|
|
||||||
"handler": "role.findOne",
|
|
||||||
"config": {
|
|
||||||
"policies": [
|
|
||||||
"admin::isAuthenticatedAdmin",
|
|
||||||
["admin::hasPermissions", ["admin::roles.read"]]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "GET",
|
|
||||||
"path": "/roles",
|
|
||||||
"handler": "role.findAll",
|
|
||||||
"config": {
|
|
||||||
"policies": [
|
|
||||||
"admin::isAuthenticatedAdmin",
|
|
||||||
["admin::hasPermissions", ["admin::roles.read"]]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "PUT",
|
|
||||||
"path": "/roles/:id",
|
|
||||||
"handler": "role.update",
|
|
||||||
"config": {
|
|
||||||
"policies": [
|
|
||||||
"admin::isAuthenticatedAdmin",
|
|
||||||
["admin::hasPermissions", ["admin::roles.update"]]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "GET",
|
|
||||||
"path": "/permissions",
|
|
||||||
"handler": "permission.getAll",
|
|
||||||
"config": {
|
|
||||||
"policies": ["admin::isAuthenticatedAdmin"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "POST",
|
|
||||||
"path": "/permissions/check",
|
|
||||||
"handler": "permission.check",
|
|
||||||
"config": {
|
|
||||||
"policies": ["admin::isAuthenticatedAdmin"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
collectionName: 'strapi_permissions',
|
collectionName: 'admin_permissions',
|
||||||
info: {
|
info: {
|
||||||
name: 'Permission',
|
name: 'Permission',
|
||||||
description: '',
|
description: '',
|
||||||
@ -52,7 +52,7 @@ module.exports = {
|
|||||||
type: 'relation',
|
type: 'relation',
|
||||||
relation: 'manyToOne',
|
relation: 'manyToOne',
|
||||||
inversedBy: 'permissions',
|
inversedBy: 'permissions',
|
||||||
target: 'strapi::role',
|
target: 'admin::role',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
collectionName: 'strapi_roles',
|
collectionName: 'admin_roles',
|
||||||
info: {
|
info: {
|
||||||
name: 'Role',
|
name: 'Role',
|
||||||
description: '',
|
description: '',
|
||||||
@ -46,14 +46,14 @@ module.exports = {
|
|||||||
type: 'relation',
|
type: 'relation',
|
||||||
relation: 'manyToMany',
|
relation: 'manyToMany',
|
||||||
mappedBy: 'roles',
|
mappedBy: 'roles',
|
||||||
target: 'strapi::user',
|
target: 'admin::user',
|
||||||
},
|
},
|
||||||
permissions: {
|
permissions: {
|
||||||
configurable: false,
|
configurable: false,
|
||||||
type: 'relation',
|
type: 'relation',
|
||||||
relation: 'oneToMany',
|
relation: 'oneToMany',
|
||||||
mappedBy: 'role',
|
mappedBy: 'role',
|
||||||
target: 'strapi::permission',
|
target: 'admin::permission',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
collectionName: 'strapi_users',
|
collectionName: 'admin_users',
|
||||||
info: {
|
info: {
|
||||||
name: 'User',
|
name: 'User',
|
||||||
description: '',
|
description: '',
|
||||||
@ -79,7 +79,7 @@ module.exports = {
|
|||||||
type: 'relation',
|
type: 'relation',
|
||||||
relation: 'manyToMany',
|
relation: 'manyToMany',
|
||||||
inversedBy: 'users',
|
inversedBy: 'users',
|
||||||
target: 'strapi::role',
|
target: 'admin::role',
|
||||||
// FIXME: Allow setting this
|
// FIXME: Allow setting this
|
||||||
collectionName: 'strapi_users_roles',
|
collectionName: 'strapi_users_roles',
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
permission: require('./Permission'),
|
permission: { schema: require('./Permission') },
|
||||||
user: require('./User'),
|
user: { schema: require('./User') },
|
||||||
role: require('./Role'),
|
role: { schema: require('./Role') },
|
||||||
};
|
};
|
||||||
|
|||||||
10
packages/core/admin/server/destroy.js
Normal file
10
packages/core/admin/server/destroy.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const { getService } = require('./utils');
|
||||||
|
|
||||||
|
module.exports = async () => {
|
||||||
|
const { conditionProvider, actionProvider } = getService('permission');
|
||||||
|
|
||||||
|
await conditionProvider.clear();
|
||||||
|
await actionProvider.clear();
|
||||||
|
};
|
||||||
@ -1,18 +1,17 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { getService } = require('./utils');
|
const bootstrap = require('./bootstrap');
|
||||||
|
const register = require('./register');
|
||||||
|
const destroy = require('./destroy');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// TODO: update load middleware to not load the admin middleware from here
|
// TODO: update load middleware to not load the admin middleware from here
|
||||||
// TODO: load bootstrap / register independently
|
register,
|
||||||
async destroy() {
|
bootstrap,
|
||||||
const { conditionProvider, actionProvider } = getService('permission');
|
destroy,
|
||||||
|
|
||||||
await conditionProvider.clear();
|
|
||||||
await actionProvider.clear();
|
|
||||||
},
|
|
||||||
config: require('./config'),
|
config: require('./config'),
|
||||||
|
routes: require('./routes'),
|
||||||
services: require('./services'),
|
services: require('./services'),
|
||||||
controllers: require('./controllers'),
|
controllers: require('./controllers'),
|
||||||
models: require('./content-types'),
|
contentTypes: require('./content-types'),
|
||||||
};
|
};
|
||||||
|
|||||||
292
packages/core/admin/server/routes.js
Normal file
292
packages/core/admin/server/routes.js
Normal file
@ -0,0 +1,292 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = [
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
path: '/plugins',
|
||||||
|
handler: 'admin.plugins',
|
||||||
|
config: {
|
||||||
|
policies: [
|
||||||
|
'admin::isAuthenticatedAdmin',
|
||||||
|
['admin::hasPermissions', ['admin::marketplace.read']],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
path: '/init',
|
||||||
|
handler: 'admin.init',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
path: '/project-type',
|
||||||
|
handler: 'admin.getProjectType',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
path: '/information',
|
||||||
|
handler: 'admin.information',
|
||||||
|
config: {
|
||||||
|
policies: ['admin::isAuthenticatedAdmin'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
path: '/plugins/install',
|
||||||
|
handler: 'admin.installPlugin',
|
||||||
|
config: {
|
||||||
|
policies: [
|
||||||
|
'admin::isAuthenticatedAdmin',
|
||||||
|
['admin::hasPermissions', ['admin::marketplace.plugins.install']],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'DELETE',
|
||||||
|
path: '/plugins/uninstall/:plugin',
|
||||||
|
handler: 'admin.uninstallPlugin',
|
||||||
|
config: {
|
||||||
|
policies: [
|
||||||
|
'admin::isAuthenticatedAdmin',
|
||||||
|
['admin::hasPermissions', ['admin::marketplace.plugins.uninstall']],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
path: '/login',
|
||||||
|
handler: 'authentication.login',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
path: '/renew-token',
|
||||||
|
handler: 'authentication.renewToken',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
path: '/register-admin',
|
||||||
|
handler: 'authentication.registerAdmin',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
path: '/registration-info',
|
||||||
|
handler: 'authentication.registrationInfo',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
path: '/register',
|
||||||
|
handler: 'authentication.register',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
path: '/forgot-password',
|
||||||
|
handler: 'authentication.forgotPassword',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
path: '/reset-password',
|
||||||
|
handler: 'authentication.resetPassword',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
path: '/webhooks',
|
||||||
|
handler: 'Webhooks.listWebhooks',
|
||||||
|
config: {
|
||||||
|
policies: [
|
||||||
|
'admin::isAuthenticatedAdmin',
|
||||||
|
['admin::hasPermissions', ['admin::webhooks.read']],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
path: '/webhooks',
|
||||||
|
handler: 'Webhooks.createWebhook',
|
||||||
|
config: {
|
||||||
|
policies: [
|
||||||
|
'admin::isAuthenticatedAdmin',
|
||||||
|
['admin::hasPermissions', ['admin::webhooks.create']],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
path: '/webhooks/:id',
|
||||||
|
handler: 'Webhooks.getWebhook',
|
||||||
|
config: {
|
||||||
|
policies: [
|
||||||
|
'admin::isAuthenticatedAdmin',
|
||||||
|
['admin::hasPermissions', ['admin::webhooks.read']],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'PUT',
|
||||||
|
path: '/webhooks/:id',
|
||||||
|
handler: 'Webhooks.updateWebhook',
|
||||||
|
config: {
|
||||||
|
policies: [
|
||||||
|
'admin::isAuthenticatedAdmin',
|
||||||
|
['admin::hasPermissions', ['admin::webhooks.update']],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'DELETE',
|
||||||
|
path: '/webhooks/:id',
|
||||||
|
handler: 'Webhooks.deleteWebhook',
|
||||||
|
config: {
|
||||||
|
policies: [
|
||||||
|
'admin::isAuthenticatedAdmin',
|
||||||
|
['admin::hasPermissions', ['admin::webhooks.delete']],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
path: '/webhooks/batch-delete',
|
||||||
|
handler: 'Webhooks.deleteWebhooks',
|
||||||
|
config: {
|
||||||
|
policies: [
|
||||||
|
'admin::isAuthenticatedAdmin',
|
||||||
|
['admin::hasPermissions', ['admin::webhooks.delete']],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
path: '/webhooks/:id/trigger',
|
||||||
|
handler: 'Webhooks.triggerWebhook',
|
||||||
|
config: {
|
||||||
|
policies: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
path: '/users/me',
|
||||||
|
handler: 'authenticated-user.getMe',
|
||||||
|
config: {
|
||||||
|
policies: ['admin::isAuthenticatedAdmin'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'PUT',
|
||||||
|
path: '/users/me',
|
||||||
|
handler: 'authenticated-user.updateMe',
|
||||||
|
config: {
|
||||||
|
policies: ['admin::isAuthenticatedAdmin'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
path: '/users/me/permissions',
|
||||||
|
handler: 'authenticated-user.getOwnPermissions',
|
||||||
|
config: {
|
||||||
|
policies: ['admin::isAuthenticatedAdmin'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
path: '/users',
|
||||||
|
handler: 'user.create',
|
||||||
|
config: {
|
||||||
|
policies: ['admin::isAuthenticatedAdmin', ['admin::hasPermissions', ['admin::users.create']]],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
path: '/users',
|
||||||
|
handler: 'user.find',
|
||||||
|
config: {
|
||||||
|
policies: ['admin::isAuthenticatedAdmin', ['admin::hasPermissions', ['admin::users.read']]],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
path: '/users/:id',
|
||||||
|
handler: 'user.findOne',
|
||||||
|
config: {
|
||||||
|
policies: ['admin::isAuthenticatedAdmin', ['admin::hasPermissions', ['admin::users.read']]],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'PUT',
|
||||||
|
path: '/users/:id',
|
||||||
|
handler: 'user.update',
|
||||||
|
config: {
|
||||||
|
policies: ['admin::isAuthenticatedAdmin', ['admin::hasPermissions', ['admin::users.update']]],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'DELETE',
|
||||||
|
path: '/users/:id',
|
||||||
|
handler: 'user.deleteOne',
|
||||||
|
config: {
|
||||||
|
policies: [['admin::hasPermissions', ['admin::users.delete']]],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
path: '/users/batch-delete',
|
||||||
|
handler: 'user.deleteMany',
|
||||||
|
config: {
|
||||||
|
policies: [['admin::hasPermissions', ['admin::users.delete']]],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
path: '/roles/:id/permissions',
|
||||||
|
handler: 'role.getPermissions',
|
||||||
|
config: {
|
||||||
|
policies: ['admin::isAuthenticatedAdmin', ['admin::hasPermissions', ['admin::roles.read']]],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'PUT',
|
||||||
|
path: '/roles/:id/permissions',
|
||||||
|
handler: 'role.updatePermissions',
|
||||||
|
config: {
|
||||||
|
policies: ['admin::isAuthenticatedAdmin', ['admin::hasPermissions', ['admin::roles.update']]],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
path: '/roles/:id',
|
||||||
|
handler: 'role.findOne',
|
||||||
|
config: {
|
||||||
|
policies: ['admin::isAuthenticatedAdmin', ['admin::hasPermissions', ['admin::roles.read']]],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
path: '/roles',
|
||||||
|
handler: 'role.findAll',
|
||||||
|
config: {
|
||||||
|
policies: ['admin::isAuthenticatedAdmin', ['admin::hasPermissions', ['admin::roles.read']]],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'PUT',
|
||||||
|
path: '/roles/:id',
|
||||||
|
handler: 'role.update',
|
||||||
|
config: {
|
||||||
|
policies: ['admin::isAuthenticatedAdmin', ['admin::hasPermissions', ['admin::roles.update']]],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
path: '/permissions',
|
||||||
|
handler: 'permission.getAll',
|
||||||
|
config: {
|
||||||
|
policies: ['admin::isAuthenticatedAdmin'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
path: '/permissions/check',
|
||||||
|
handler: 'permission.check',
|
||||||
|
config: {
|
||||||
|
policies: ['admin::isAuthenticatedAdmin'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
@ -27,7 +27,7 @@ const validatePassword = (password, hash) => bcrypt.compare(password, hash);
|
|||||||
* @param {string} options.password
|
* @param {string} options.password
|
||||||
*/
|
*/
|
||||||
const checkCredentials = async ({ email, password }) => {
|
const checkCredentials = async ({ email, password }) => {
|
||||||
const user = await strapi.query('strapi::user').findOne({ where: { email } });
|
const user = await strapi.query('admin::user').findOne({ where: { email } });
|
||||||
|
|
||||||
if (!user || !user.password) {
|
if (!user || !user.password) {
|
||||||
return [null, false, { message: 'Invalid credentials' }];
|
return [null, false, { message: 'Invalid credentials' }];
|
||||||
@ -52,7 +52,7 @@ const checkCredentials = async ({ email, password }) => {
|
|||||||
* @param {string} param.email user email for which to reset the password
|
* @param {string} param.email user email for which to reset the password
|
||||||
*/
|
*/
|
||||||
const forgotPassword = async ({ email } = {}) => {
|
const forgotPassword = async ({ email } = {}) => {
|
||||||
const user = await strapi.query('strapi::user').findOne({ where: { email, isActive: true } });
|
const user = await strapi.query('admin::user').findOne({ where: { email, isActive: true } });
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return;
|
return;
|
||||||
@ -94,7 +94,7 @@ const forgotPassword = async ({ email } = {}) => {
|
|||||||
*/
|
*/
|
||||||
const resetPassword = async ({ resetPasswordToken, password } = {}) => {
|
const resetPassword = async ({ resetPasswordToken, password } = {}) => {
|
||||||
const matchingUser = await strapi
|
const matchingUser = await strapi
|
||||||
.query('strapi::user')
|
.query('admin::user')
|
||||||
.findOne({ where: { resetPasswordToken, isActive: true } });
|
.findOne({ where: { resetPasswordToken, isActive: true } });
|
||||||
|
|
||||||
if (!matchingUser) {
|
if (!matchingUser) {
|
||||||
|
|||||||
@ -26,7 +26,7 @@ const permissionDomain = require('../../domain/permission/index');
|
|||||||
* @returns {Promise<array>}
|
* @returns {Promise<array>}
|
||||||
*/
|
*/
|
||||||
const deleteByRolesIds = async rolesIds => {
|
const deleteByRolesIds = async rolesIds => {
|
||||||
const permissionsToDelete = await strapi.query('strapi::permission').findMany({
|
const permissionsToDelete = await strapi.query('admin::permission').findMany({
|
||||||
select: ['id'],
|
select: ['id'],
|
||||||
where: {
|
where: {
|
||||||
role: { id: rolesIds },
|
role: { id: rolesIds },
|
||||||
@ -45,7 +45,7 @@ const deleteByRolesIds = async rolesIds => {
|
|||||||
*/
|
*/
|
||||||
const deleteByIds = async ids => {
|
const deleteByIds = async ids => {
|
||||||
for (const id of ids) {
|
for (const id of ids) {
|
||||||
await strapi.query('strapi::permission').delete({ where: { id } });
|
await strapi.query('admin::permission').delete({ where: { id } });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ const deleteByIds = async ids => {
|
|||||||
const createMany = async permissions => {
|
const createMany = async permissions => {
|
||||||
const createdPermissions = [];
|
const createdPermissions = [];
|
||||||
for (const permission of permissions) {
|
for (const permission of permissions) {
|
||||||
const newPerm = await strapi.query('strapi::permission').create({ data: permission });
|
const newPerm = await strapi.query('admin::permission').create({ data: permission });
|
||||||
createdPermissions.push(newPerm);
|
createdPermissions.push(newPerm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ const createMany = async permissions => {
|
|||||||
*/
|
*/
|
||||||
const update = async (params, attributes) => {
|
const update = async (params, attributes) => {
|
||||||
const updatedPermission = await strapi
|
const updatedPermission = await strapi
|
||||||
.query('strapi::permission')
|
.query('admin::permission')
|
||||||
.update({ where: params, data: attributes });
|
.update({ where: params, data: attributes });
|
||||||
|
|
||||||
return permissionDomain.toPermission(updatedPermission);
|
return permissionDomain.toPermission(updatedPermission);
|
||||||
@ -84,7 +84,7 @@ const update = async (params, attributes) => {
|
|||||||
* @returns {Promise<Permission[]>}
|
* @returns {Promise<Permission[]>}
|
||||||
*/
|
*/
|
||||||
const findMany = async (params = {}) => {
|
const findMany = async (params = {}) => {
|
||||||
const rawPermissions = await strapi.query('strapi::permission').findMany(params);
|
const rawPermissions = await strapi.query('admin::permission').findMany(params);
|
||||||
|
|
||||||
return permissionDomain.toPermission(rawPermissions);
|
return permissionDomain.toPermission(rawPermissions);
|
||||||
};
|
};
|
||||||
@ -141,13 +141,13 @@ const cleanPermissionsInDatabase = async () => {
|
|||||||
|
|
||||||
const contentTypeService = getService('content-type');
|
const contentTypeService = getService('content-type');
|
||||||
|
|
||||||
const total = await strapi.query('strapi::permission').count();
|
const total = await strapi.query('admin::permission').count();
|
||||||
const pageCount = Math.ceil(total / pageSize);
|
const pageCount = Math.ceil(total / pageSize);
|
||||||
|
|
||||||
for (let page = 0; page < pageCount; page++) {
|
for (let page = 0; page < pageCount; page++) {
|
||||||
// 1. Find invalid permissions and collect their ID to delete them later
|
// 1. Find invalid permissions and collect their ID to delete them later
|
||||||
const results = await strapi
|
const results = await strapi
|
||||||
.query('strapi::permission')
|
.query('admin::permission')
|
||||||
.findMany({ limit: pageSize, offset: page * pageSize });
|
.findMany({ limit: pageSize, offset: page * pageSize });
|
||||||
|
|
||||||
const permissions = permissionDomain.toPermission(results);
|
const permissions = permissionDomain.toPermission(results);
|
||||||
@ -193,7 +193,7 @@ const ensureBoundPermissionsInDatabase = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const contentTypes = Object.values(strapi.contentTypes);
|
const contentTypes = Object.values(strapi.contentTypes);
|
||||||
const editorRole = await strapi.query('strapi::role').findOne({
|
const editorRole = await strapi.query('admin::role').findOne({
|
||||||
where: { code: EDITOR_CODE },
|
where: { code: EDITOR_CODE },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -57,7 +57,7 @@ const create = async attributes => {
|
|||||||
code: attributes.code || autoGeneratedCode,
|
code: attributes.code || autoGeneratedCode,
|
||||||
};
|
};
|
||||||
|
|
||||||
return strapi.query('strapi::role').create({ data: rolesWithCode });
|
return strapi.query('admin::role').create({ data: rolesWithCode });
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,7 +67,7 @@ const create = async attributes => {
|
|||||||
* @returns {Promise<role>}
|
* @returns {Promise<role>}
|
||||||
*/
|
*/
|
||||||
const findOne = (params = {}, populate) => {
|
const findOne = (params = {}, populate) => {
|
||||||
return strapi.query('strapi::role').findOne({ where: params, populate });
|
return strapi.query('admin::role').findOne({ where: params, populate });
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,7 +77,7 @@ const findOne = (params = {}, populate) => {
|
|||||||
* @returns {Promise<role>}
|
* @returns {Promise<role>}
|
||||||
*/
|
*/
|
||||||
const findOneWithUsersCount = async (params = {}, populate) => {
|
const findOneWithUsersCount = async (params = {}, populate) => {
|
||||||
const role = await strapi.query('strapi::role').findOne({ where: params, populate });
|
const role = await strapi.query('admin::role').findOne({ where: params, populate });
|
||||||
|
|
||||||
if (role) {
|
if (role) {
|
||||||
role.usersCount = await getUsersCount(role.id);
|
role.usersCount = await getUsersCount(role.id);
|
||||||
@ -93,7 +93,7 @@ const findOneWithUsersCount = async (params = {}, populate) => {
|
|||||||
* @returns {Promise<array>}
|
* @returns {Promise<array>}
|
||||||
*/
|
*/
|
||||||
const find = (params = {}, populate) => {
|
const find = (params = {}, populate) => {
|
||||||
return strapi.query('strapi::role').findMany({ where: params, populate });
|
return strapi.query('admin::role').findMany({ where: params, populate });
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -101,7 +101,7 @@ const find = (params = {}, populate) => {
|
|||||||
* @returns {Promise<array>}
|
* @returns {Promise<array>}
|
||||||
*/
|
*/
|
||||||
const findAllWithUsersCount = async populate => {
|
const findAllWithUsersCount = async populate => {
|
||||||
const roles = await strapi.query('strapi::role').findMany({ populate });
|
const roles = await strapi.query('admin::role').findMany({ populate });
|
||||||
for (let role of roles) {
|
for (let role of roles) {
|
||||||
role.usersCount = await getUsersCount(role.id);
|
role.usersCount = await getUsersCount(role.id);
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ const update = async (params, attributes) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return strapi.query('strapi::role').update({ where: params, data: sanitizedAttributes });
|
return strapi.query('admin::role').update({ where: params, data: sanitizedAttributes });
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -141,7 +141,7 @@ const update = async (params, attributes) => {
|
|||||||
* @returns {Promise<boolean>}
|
* @returns {Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
const exists = async (params = {}) => {
|
const exists = async (params = {}) => {
|
||||||
const count = await strapi.query('strapi::role').count({ where: params });
|
const count = await strapi.query('admin::role').count({ where: params });
|
||||||
return count > 0;
|
return count > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ const exists = async (params = {}) => {
|
|||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
const count = async (params = {}) => {
|
const count = async (params = {}) => {
|
||||||
return strapi.query('strapi::role').count(params);
|
return strapi.query('admin::role').count(params);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -186,7 +186,7 @@ const deleteByIds = async (ids = []) => {
|
|||||||
|
|
||||||
const deletedRoles = [];
|
const deletedRoles = [];
|
||||||
for (const id of ids) {
|
for (const id of ids) {
|
||||||
const deletedRole = await strapi.query('strapi::role').delete({ where: { id } });
|
const deletedRole = await strapi.query('admin::role').delete({ where: { id } });
|
||||||
|
|
||||||
if (deletedRole) {
|
if (deletedRole) {
|
||||||
deletedRoles.push(deletedRole);
|
deletedRoles.push(deletedRole);
|
||||||
@ -201,7 +201,7 @@ const deleteByIds = async (ids = []) => {
|
|||||||
* @param roleId
|
* @param roleId
|
||||||
*/
|
*/
|
||||||
const getUsersCount = async roleId => {
|
const getUsersCount = async roleId => {
|
||||||
return strapi.query('strapi::user').count({ where: { roles: { id: roleId } } });
|
return strapi.query('admin::user').count({ where: { roles: { id: roleId } } });
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Returns admin role
|
/** Returns admin role
|
||||||
|
|||||||
@ -37,9 +37,7 @@ const create = async attributes => {
|
|||||||
|
|
||||||
const user = createUser(userInfo);
|
const user = createUser(userInfo);
|
||||||
|
|
||||||
const createdUser = await strapi
|
const createdUser = await strapi.query('admin::user').create({ data: user, populate: ['roles'] });
|
||||||
.query('strapi::user')
|
|
||||||
.create({ data: user, populate: ['roles'] });
|
|
||||||
|
|
||||||
getService('metrics').sendDidInviteUser();
|
getService('metrics').sendDidInviteUser();
|
||||||
|
|
||||||
@ -82,7 +80,7 @@ const updateById = async (id, attributes) => {
|
|||||||
if (_.has(attributes, 'password')) {
|
if (_.has(attributes, 'password')) {
|
||||||
const hashedPassword = await getService('auth').hashPassword(attributes.password);
|
const hashedPassword = await getService('auth').hashPassword(attributes.password);
|
||||||
|
|
||||||
return strapi.query('strapi::user').update({
|
return strapi.query('admin::user').update({
|
||||||
where: { id },
|
where: { id },
|
||||||
data: {
|
data: {
|
||||||
...attributes,
|
...attributes,
|
||||||
@ -92,7 +90,7 @@ const updateById = async (id, attributes) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return strapi.query('strapi::user').update({
|
return strapi.query('admin::user').update({
|
||||||
where: { id },
|
where: { id },
|
||||||
data: attributes,
|
data: attributes,
|
||||||
populate: ['roles'],
|
populate: ['roles'],
|
||||||
@ -139,7 +137,7 @@ const isLastSuperAdminUser = async userId => {
|
|||||||
* @returns {Promise<boolean>}
|
* @returns {Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
const exists = async (attributes = {}) => {
|
const exists = async (attributes = {}) => {
|
||||||
return (await strapi.query('strapi::user').count({ where: attributes })) > 0;
|
return (await strapi.query('admin::user').count({ where: attributes })) > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -148,7 +146,7 @@ const exists = async (attributes = {}) => {
|
|||||||
* @returns {Promise<registrationInfo>} - Returns user email, firstname and lastname
|
* @returns {Promise<registrationInfo>} - Returns user email, firstname and lastname
|
||||||
*/
|
*/
|
||||||
const findRegistrationInfo = async registrationToken => {
|
const findRegistrationInfo = async registrationToken => {
|
||||||
const user = await strapi.query('strapi::user').findOne({ where: { registrationToken } });
|
const user = await strapi.query('admin::user').findOne({ where: { registrationToken } });
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@ -164,7 +162,7 @@ const findRegistrationInfo = async registrationToken => {
|
|||||||
* @param {Object} params.userInfo user info
|
* @param {Object} params.userInfo user info
|
||||||
*/
|
*/
|
||||||
const register = async ({ registrationToken, userInfo }) => {
|
const register = async ({ registrationToken, userInfo }) => {
|
||||||
const matchingUser = await strapi.query('strapi::user').findOne({ where: { registrationToken } });
|
const matchingUser = await strapi.query('admin::user').findOne({ where: { registrationToken } });
|
||||||
|
|
||||||
if (!matchingUser) {
|
if (!matchingUser) {
|
||||||
throw strapi.errors.badRequest('Invalid registration info');
|
throw strapi.errors.badRequest('Invalid registration info');
|
||||||
@ -183,7 +181,7 @@ const register = async ({ registrationToken, userInfo }) => {
|
|||||||
* Find one user
|
* Find one user
|
||||||
*/
|
*/
|
||||||
const findOne = async (where = {}, populate = ['roles']) => {
|
const findOne = async (where = {}, populate = ['roles']) => {
|
||||||
return strapi.query('strapi::user').findOne({ where, populate });
|
return strapi.query('admin::user').findOne({ where, populate });
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Find many users (paginated)
|
/** Find many users (paginated)
|
||||||
@ -193,7 +191,7 @@ const findOne = async (where = {}, populate = ['roles']) => {
|
|||||||
const findPage = async (query = {}) => {
|
const findPage = async (query = {}) => {
|
||||||
const { page = 1, pageSize = 100, populate = ['roles'] } = query;
|
const { page = 1, pageSize = 100, populate = ['roles'] } = query;
|
||||||
|
|
||||||
return strapi.query('strapi::user').findPage({
|
return strapi.query('admin::user').findPage({
|
||||||
where: query.filters,
|
where: query.filters,
|
||||||
_q: query._q,
|
_q: query._q,
|
||||||
populate,
|
populate,
|
||||||
@ -208,7 +206,7 @@ const findPage = async (query = {}) => {
|
|||||||
*/
|
*/
|
||||||
const deleteById = async id => {
|
const deleteById = async id => {
|
||||||
// Check at least one super admin remains
|
// Check at least one super admin remains
|
||||||
const userToDelete = await strapi.query('strapi::user').findOne({
|
const userToDelete = await strapi.query('admin::user').findOne({
|
||||||
where: { id },
|
where: { id },
|
||||||
populate: ['roles'],
|
populate: ['roles'],
|
||||||
});
|
});
|
||||||
@ -229,7 +227,7 @@ const deleteById = async id => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return strapi.query('strapi::user').delete({ where: { id }, populate: ['roles'] });
|
return strapi.query('admin::user').delete({ where: { id }, populate: ['roles'] });
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Delete a user
|
/** Delete a user
|
||||||
@ -239,7 +237,7 @@ const deleteById = async id => {
|
|||||||
const deleteByIds = async ids => {
|
const deleteByIds = async ids => {
|
||||||
// Check at least one super admin remains
|
// Check at least one super admin remains
|
||||||
const superAdminRole = await getService('role').getSuperAdminWithUsersCount();
|
const superAdminRole = await getService('role').getSuperAdminWithUsersCount();
|
||||||
const nbOfSuperAdminToDelete = await strapi.query('strapi::user').count({
|
const nbOfSuperAdminToDelete = await strapi.query('admin::user').count({
|
||||||
where: {
|
where: {
|
||||||
id: ids,
|
id: ids,
|
||||||
roles: { id: superAdminRole.id },
|
roles: { id: superAdminRole.id },
|
||||||
@ -255,7 +253,7 @@ const deleteByIds = async ids => {
|
|||||||
|
|
||||||
const deletedUsers = [];
|
const deletedUsers = [];
|
||||||
for (const id of ids) {
|
for (const id of ids) {
|
||||||
const deletedUser = await strapi.query('strapi::user').delete({
|
const deletedUser = await strapi.query('admin::user').delete({
|
||||||
where: { id },
|
where: { id },
|
||||||
populate: ['roles'],
|
populate: ['roles'],
|
||||||
});
|
});
|
||||||
@ -270,7 +268,7 @@ const deleteByIds = async ids => {
|
|||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
const countUsersWithoutRole = async () => {
|
const countUsersWithoutRole = async () => {
|
||||||
return strapi.query('strapi::user').count({
|
return strapi.query('admin::user').count({
|
||||||
where: {
|
where: {
|
||||||
roles: {
|
roles: {
|
||||||
id: { $null: true },
|
id: { $null: true },
|
||||||
@ -285,14 +283,14 @@ const countUsersWithoutRole = async () => {
|
|||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
const count = async (where = {}) => {
|
const count = async (where = {}) => {
|
||||||
return strapi.query('strapi::user').count({ where });
|
return strapi.query('admin::user').count({ where });
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Assign some roles to several users
|
/** Assign some roles to several users
|
||||||
* @returns {undefined}
|
* @returns {undefined}
|
||||||
*/
|
*/
|
||||||
const assignARoleToAll = async roleId => {
|
const assignARoleToAll = async roleId => {
|
||||||
const users = await strapi.query('strapi::user').findMany({
|
const users = await strapi.query('admin::user').findMany({
|
||||||
select: ['id'],
|
select: ['id'],
|
||||||
where: {
|
where: {
|
||||||
roles: { id: { $null: true } },
|
roles: { id: { $null: true } },
|
||||||
@ -301,7 +299,7 @@ const assignARoleToAll = async roleId => {
|
|||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
users.map(user => {
|
users.map(user => {
|
||||||
return strapi.query('strapi::user').update({
|
return strapi.query('admin::user').update({
|
||||||
where: { id: user.id },
|
where: { id: user.id },
|
||||||
data: { roles: [roleId] },
|
data: { roles: [roleId] },
|
||||||
});
|
});
|
||||||
|
|||||||
@ -28,7 +28,7 @@ const findCreatorRoles = entity => {
|
|||||||
|
|
||||||
if (has(createdByPath, entity)) {
|
if (has(createdByPath, entity)) {
|
||||||
const creatorId = prop(createdByPath, entity);
|
const creatorId = prop(createdByPath, entity);
|
||||||
return strapi.query('strapi::role').findMany({ where: { users: { id: creatorId } } });
|
return strapi.query('admin::role').findMany({ where: { users: { id: creatorId } } });
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
|
|||||||
@ -36,7 +36,7 @@ const VALID_UID_TARGETS = ['string', 'text'];
|
|||||||
const FORBIDDEN_ATTRIBUTE_NAMES = ['__component', '__contentType'];
|
const FORBIDDEN_ATTRIBUTE_NAMES = ['__component', '__contentType'];
|
||||||
|
|
||||||
const PREFIX = 'strapi::';
|
const PREFIX = 'strapi::';
|
||||||
const STRAPI_USER = 'strapi::user';
|
const STRAPI_USER = 'admin::user';
|
||||||
const UPLOAD_FILE = 'plugin::upload.file';
|
const UPLOAD_FILE = 'plugin::upload.file';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@ -14,7 +14,7 @@ const loadModules = require('./core/loaders/load-modules');
|
|||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const bootstrap = require('./core/loaders/bootstrap');
|
const bootstrap = require('./core/loaders/bootstrap');
|
||||||
const initializeMiddlewares = require('./middlewares');
|
const initializeMiddlewares = require('./middlewares');
|
||||||
const createStrapiFs = require('./core/fs');
|
const createStrapiFs = require('./services/fs');
|
||||||
const createEventHub = require('./services/event-hub');
|
const createEventHub = require('./services/event-hub');
|
||||||
const createWebhookRunner = require('./services/webhook-runner');
|
const createWebhookRunner = require('./services/webhook-runner');
|
||||||
const { webhookModel, createWebhookStore } = require('./services/webhook-store');
|
const { webhookModel, createWebhookStore } = require('./services/webhook-store');
|
||||||
@ -34,7 +34,6 @@ const modulesRegistry = require('./core/registries/modules');
|
|||||||
const pluginsRegistry = require('./core/registries/plugins');
|
const pluginsRegistry = require('./core/registries/plugins');
|
||||||
const createConfigProvider = require('./core/registries/config');
|
const createConfigProvider = require('./core/registries/config');
|
||||||
const loadPlugins = require('./core/load-plugins');
|
const loadPlugins = require('./core/load-plugins');
|
||||||
// const { nameToSlug } = require('../../utils/lib');
|
|
||||||
|
|
||||||
const LIFECYCLES = {
|
const LIFECYCLES = {
|
||||||
REGISTER: 'register',
|
REGISTER: 'register',
|
||||||
@ -60,7 +59,6 @@ class Strapi {
|
|||||||
this.app = new Koa();
|
this.app = new Koa();
|
||||||
this.router = new Router();
|
this.router = new Router();
|
||||||
this.server = createHTTPServer(this, this.app);
|
this.server = createHTTPServer(this, this.app);
|
||||||
this.contentTypes = {}; // to remove V3
|
|
||||||
this.fs = createStrapiFs(this);
|
this.fs = createStrapiFs(this);
|
||||||
this.eventHub = createEventHub();
|
this.eventHub = createEventHub();
|
||||||
this.startupLogger = createStartupLogger(this);
|
this.startupLogger = createStartupLogger(this);
|
||||||
@ -82,6 +80,18 @@ class Strapi {
|
|||||||
return this.container.get('services').get(uid);
|
return this.container.get('services').get(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
controller(uid) {
|
||||||
|
return this.container.get('controllers').get(uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
contentType(name) {
|
||||||
|
return this.container.get('content-types').get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
get contentTypes() {
|
||||||
|
return this.container.get('content-types').getAll();
|
||||||
|
}
|
||||||
|
|
||||||
plugin(name) {
|
plugin(name) {
|
||||||
return this.container.get('plugins').get(name);
|
return this.container.get('plugins').get(name);
|
||||||
}
|
}
|
||||||
@ -219,6 +229,8 @@ class Strapi {
|
|||||||
loadAdmin() {
|
loadAdmin() {
|
||||||
this.admin = require('@strapi/admin/strapi-server');
|
this.admin = require('@strapi/admin/strapi-server');
|
||||||
|
|
||||||
|
strapi.container.get('content-types').add(`admin::`, strapi.admin.contentTypes);
|
||||||
|
|
||||||
// TODO: rename into just admin and ./config/admin.js
|
// TODO: rename into just admin and ./config/admin.js
|
||||||
const userAdminConfig = strapi.config.get('server.admin');
|
const userAdminConfig = strapi.config.get('server.admin');
|
||||||
this.config.set('server.admin', _.merge(this.admin.config, userAdminConfig));
|
this.config.set('server.admin', _.merge(this.admin.config, userAdminConfig));
|
||||||
@ -252,7 +264,6 @@ class Strapi {
|
|||||||
this.components = modules.components;
|
this.components = modules.components;
|
||||||
|
|
||||||
this.middleware = modules.middlewares;
|
this.middleware = modules.middlewares;
|
||||||
this.hook = modules.hook;
|
|
||||||
|
|
||||||
await bootstrap(this);
|
await bootstrap(this);
|
||||||
|
|
||||||
@ -371,12 +382,7 @@ class Strapi {
|
|||||||
await execLifecycle(this.config.get(configPath));
|
await execLifecycle(this.config.get(configPath));
|
||||||
|
|
||||||
// admin
|
// admin
|
||||||
const adminFunc = _.get(this.admin.config, configPath);
|
await this.admin[lifecycleName]();
|
||||||
return execLifecycle(adminFunc).catch(err => {
|
|
||||||
strapi.log.error(`${lifecycleName} function in admin failed`);
|
|
||||||
console.error(err);
|
|
||||||
strapi.stop();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getModel(uid) {
|
getModel(uid) {
|
||||||
|
|||||||
@ -16,17 +16,8 @@ const loadConfigDir = require('./config-loader');
|
|||||||
const { version: strapiVersion } = require(path.join(__dirname, '../../../package.json'));
|
const { version: strapiVersion } = require(path.join(__dirname, '../../../package.json'));
|
||||||
|
|
||||||
const CONFIG_PATHS = {
|
const CONFIG_PATHS = {
|
||||||
admin: 'admin',
|
|
||||||
api: 'api',
|
|
||||||
config: 'config',
|
config: 'config',
|
||||||
controllers: 'controllers',
|
|
||||||
models: 'models',
|
|
||||||
plugins: 'plugins',
|
|
||||||
policies: 'policies',
|
|
||||||
tmp: '.tmp',
|
|
||||||
services: 'services',
|
|
||||||
static: 'public',
|
static: 'public',
|
||||||
validators: 'validators',
|
|
||||||
views: 'views',
|
views: 'views',
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -48,15 +39,6 @@ const defaultConfig = {
|
|||||||
},
|
},
|
||||||
settings: {},
|
settings: {},
|
||||||
},
|
},
|
||||||
hook: {
|
|
||||||
timeout: 1000,
|
|
||||||
load: {
|
|
||||||
before: ['responseTime', 'logger', 'cors', 'responses', 'gzip'],
|
|
||||||
order: [],
|
|
||||||
after: ['parser', 'router'],
|
|
||||||
},
|
|
||||||
settings: {},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = (dir, initialConfig = {}) => {
|
module.exports = (dir, initialConfig = {}) => {
|
||||||
@ -80,7 +62,6 @@ module.exports = (dir, initialConfig = {}) => {
|
|||||||
strapi: strapiVersion,
|
strapi: strapiVersion,
|
||||||
},
|
},
|
||||||
installedMiddlewares: getPrefixedDeps('@strapi/middleware', pkgJSON),
|
installedMiddlewares: getPrefixedDeps('@strapi/middleware', pkgJSON),
|
||||||
installedHooks: getPrefixedDeps('@strapi/hook', pkgJSON),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const baseConfig = omit('plugins', loadConfigDir(configDir)); // plugin config will be loaded later
|
const baseConfig = omit('plugins', loadConfigDir(configDir)); // plugin config will be loaded later
|
||||||
|
|||||||
@ -19,11 +19,11 @@ const createContentType = (uid, definition) => {
|
|||||||
throw new Error(`Content Type Definition is invalid for ${uid}'.\n${e.errors}`);
|
throw new Error(`Content Type Definition is invalid for ${uid}'.\n${e.errors}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const createdContentType = cloneDeep(definition);
|
const { schema, actions, lifecycles } = cloneDeep(definition);
|
||||||
|
|
||||||
// general info
|
// general info
|
||||||
Object.assign(createdContentType.schema, {
|
Object.assign(schema, {
|
||||||
kind: createdContentType.schema.kind || 'collectionType',
|
kind: schema.kind || 'collectionType',
|
||||||
__schema__: pickSchema(definition.schema),
|
__schema__: pickSchema(definition.schema),
|
||||||
modelType: 'contentType',
|
modelType: 'contentType',
|
||||||
modelName: definition.schema.info.singularName,
|
modelName: definition.schema.info.singularName,
|
||||||
@ -31,27 +31,26 @@ const createContentType = (uid, definition) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (uid.startsWith('api::')) {
|
if (uid.startsWith('api::')) {
|
||||||
Object.assign(createdContentType.schema, {
|
Object.assign(schema, {
|
||||||
uid,
|
uid,
|
||||||
apiName: uid.split('::')[1].split('.')[0],
|
apiName: uid.split('::')[1].split('.')[0],
|
||||||
collectionName: definition.schema.collectionName || definition.schema.info.singularName,
|
collectionName: schema.collectionName || schema.info.singularName,
|
||||||
globalId: getGlobalId(definition.schema, definition.schema.info.singularName),
|
globalId: getGlobalId(schema, schema.info.singularName),
|
||||||
});
|
});
|
||||||
} else if (uid.startsWith('plugin::')) {
|
} else if (uid.startsWith('plugin::')) {
|
||||||
const pluginName = uid.split('::')[1].split('.')[0];
|
const pluginName = uid.split('::')[1].split('.')[0];
|
||||||
Object.assign(createdContentType.schema, {
|
Object.assign(schema, {
|
||||||
uid,
|
uid,
|
||||||
plugin: pluginName, // TODO: to be set in load-plugins.js
|
plugin: pluginName, // TODO: to be set in load-plugins.js
|
||||||
collectionName:
|
collectionName:
|
||||||
createdContentType.schema.collectionName ||
|
schema.collectionName || `${pluginName}_${schema.info.singularName}`.toLowerCase(),
|
||||||
`${pluginName}_${definition.schema.info.singularName}`.toLowerCase(),
|
globalId: getGlobalId(schema, schema.info.singularName, pluginName),
|
||||||
globalId: getGlobalId(definition.schema, definition.schema.info.singularName, pluginName),
|
|
||||||
});
|
});
|
||||||
} else if (uid.startsWith('strapi::')) {
|
} else if (uid.startsWith('admin::')) {
|
||||||
Object.assign(createdContentType.schema, {
|
Object.assign(schema, {
|
||||||
uid,
|
uid,
|
||||||
plugin: 'admin',
|
plugin: 'admin',
|
||||||
globalId: getGlobalId(definition.schema, definition.schema.info.singularName, 'admin'),
|
globalId: getGlobalId(schema, schema.info.singularName, 'admin'),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@ -59,7 +58,7 @@ const createContentType = (uid, definition) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.defineProperty(createdContentType.schema, 'privateAttributes', {
|
Object.defineProperty(schema, 'privateAttributes', {
|
||||||
get() {
|
get() {
|
||||||
// FIXME: to fix
|
// FIXME: to fix
|
||||||
// return strapi.getModel(model.uid).privateAttributes;
|
// return strapi.getModel(model.uid).privateAttributes;
|
||||||
@ -68,7 +67,7 @@ const createContentType = (uid, definition) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
Object.assign(createdContentType.schema.attributes, {
|
Object.assign(schema.attributes, {
|
||||||
[CREATED_AT_ATTRIBUTE]: {
|
[CREATED_AT_ATTRIBUTE]: {
|
||||||
type: 'datetime',
|
type: 'datetime',
|
||||||
default: () => new Date(),
|
default: () => new Date(),
|
||||||
@ -80,8 +79,8 @@ const createContentType = (uid, definition) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (hasDraftAndPublish(createdContentType.schema)) {
|
if (hasDraftAndPublish(schema)) {
|
||||||
createdContentType.schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {
|
schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {
|
||||||
type: 'datetime',
|
type: 'datetime',
|
||||||
configurable: false,
|
configurable: false,
|
||||||
writable: true,
|
writable: true,
|
||||||
@ -89,12 +88,12 @@ const createContentType = (uid, definition) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const isPrivate = !_.get(createdContentType.schema, 'options.populateCreatorFields', false);
|
const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);
|
||||||
|
|
||||||
createdContentType.schema.attributes[CREATED_BY_ATTRIBUTE] = {
|
schema.attributes[CREATED_BY_ATTRIBUTE] = {
|
||||||
type: 'relation',
|
type: 'relation',
|
||||||
relation: 'oneToOne',
|
relation: 'oneToOne',
|
||||||
target: 'strapi::user',
|
target: 'admin::user',
|
||||||
configurable: false,
|
configurable: false,
|
||||||
writable: false,
|
writable: false,
|
||||||
visible: false,
|
visible: false,
|
||||||
@ -102,10 +101,10 @@ const createContentType = (uid, definition) => {
|
|||||||
private: isPrivate,
|
private: isPrivate,
|
||||||
};
|
};
|
||||||
|
|
||||||
createdContentType.schema.attributes[UPDATED_BY_ATTRIBUTE] = {
|
schema.attributes[UPDATED_BY_ATTRIBUTE] = {
|
||||||
type: 'relation',
|
type: 'relation',
|
||||||
relation: 'oneToOne',
|
relation: 'oneToOne',
|
||||||
target: 'strapi::user',
|
target: 'admin::user',
|
||||||
configurable: false,
|
configurable: false,
|
||||||
writable: false,
|
writable: false,
|
||||||
visible: false,
|
visible: false,
|
||||||
@ -113,7 +112,11 @@ const createContentType = (uid, definition) => {
|
|||||||
private: isPrivate,
|
private: isPrivate,
|
||||||
};
|
};
|
||||||
|
|
||||||
return createdContentType;
|
return {
|
||||||
|
...schema,
|
||||||
|
actions: actions,
|
||||||
|
lifecycles: lifecycles,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const getGlobalId = (model, modelName, prefix) => {
|
const getGlobalId = (model, modelName, prefix) => {
|
||||||
|
|||||||
@ -3,9 +3,28 @@
|
|||||||
const { keyBy, mapValues } = require('lodash');
|
const { keyBy, mapValues } = require('lodash');
|
||||||
const { yup } = require('@strapi/utils');
|
const { yup } = require('@strapi/utils');
|
||||||
|
|
||||||
// To replace by directly using implemented lifecycles
|
const LIFECYCLES = [
|
||||||
const lifecycles = ['beforeCreate', 'afterCreate'];
|
'beforeCreate',
|
||||||
const lifecyclesShape = mapValues(keyBy(lifecycles), () =>
|
'afterCreate',
|
||||||
|
'beforeFindOne',
|
||||||
|
'afterFindOne',
|
||||||
|
'beforeFindMany',
|
||||||
|
'afterFindMany',
|
||||||
|
'beforeCount',
|
||||||
|
'afterCount',
|
||||||
|
'beforeCreateMany',
|
||||||
|
'afterCreateMany',
|
||||||
|
'beforeUpdate',
|
||||||
|
'afterUpdate',
|
||||||
|
'beforeUpdateMany',
|
||||||
|
'afterUpdateMany',
|
||||||
|
'beforeDelete',
|
||||||
|
'afterDelete',
|
||||||
|
'beforeDeleteMany',
|
||||||
|
'afterDeleteMany',
|
||||||
|
];
|
||||||
|
|
||||||
|
const lifecyclesShape = mapValues(keyBy(LIFECYCLES), () =>
|
||||||
yup
|
yup
|
||||||
.mixed()
|
.mixed()
|
||||||
.nullable()
|
.nullable()
|
||||||
|
|||||||
@ -33,7 +33,7 @@ const createModule = (namespace, rawModule, strapi) => {
|
|||||||
await rawModule.destroy(strapi);
|
await rawModule.destroy(strapi);
|
||||||
},
|
},
|
||||||
load() {
|
load() {
|
||||||
strapi.container.get('content-types').add(namespace, rawModule.contentTypes);
|
strapi.container.get('content-types').add(namespace + '.', rawModule.contentTypes);
|
||||||
strapi.container.get('services').add(namespace, rawModule.services);
|
strapi.container.get('services').add(namespace, rawModule.services);
|
||||||
strapi.container.get('policies').add(namespace, rawModule.policies);
|
strapi.container.get('policies').add(namespace, rawModule.policies);
|
||||||
strapi.container.get('middlewares').add(namespace, rawModule.middlewares);
|
strapi.container.get('middlewares').add(namespace, rawModule.middlewares);
|
||||||
|
|||||||
@ -4,7 +4,6 @@ const _ = require('lodash');
|
|||||||
const { toLower, kebabCase } = require('lodash/fp');
|
const { toLower, kebabCase } = require('lodash/fp');
|
||||||
const { getConfigUrls } = require('@strapi/utils');
|
const { getConfigUrls } = require('@strapi/utils');
|
||||||
const pluralize = require('pluralize');
|
const pluralize = require('pluralize');
|
||||||
const { createContentType } = require('../domain/content-type');
|
|
||||||
|
|
||||||
const { createCoreApi } = require('../../core-api');
|
const { createCoreApi } = require('../../core-api');
|
||||||
|
|
||||||
@ -30,55 +29,26 @@ const validateContentTypesUnicity = schemas => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.exports = function(strapi) {
|
module.exports = function(strapi) {
|
||||||
strapi.contentTypes = {};
|
|
||||||
|
|
||||||
// validate Content-Types unicity
|
// validate Content-Types unicity
|
||||||
const allApisSchemas = Object.values(strapi.api).flatMap(api => Object.values(api.models));
|
const allApisSchemas = Object.values(strapi.api).flatMap(api => Object.values(api.models));
|
||||||
validateContentTypesUnicity(allApisSchemas);
|
validateContentTypesUnicity(allApisSchemas);
|
||||||
|
|
||||||
// TODO: to change with new loading system
|
|
||||||
// Register api content types
|
|
||||||
for (const apiName in strapi.api) {
|
|
||||||
const api = strapi.api[apiName];
|
|
||||||
|
|
||||||
const v4ContentTypes = _.mapValues(api.models, (model, modelName) => {
|
|
||||||
model.info.displayName = model.info.displayName || model.info.name;
|
|
||||||
model.info.singularName = model.info.singularName || modelName;
|
|
||||||
model.info.pluralName = model.info.pluralName || pluralize(modelName);
|
|
||||||
|
|
||||||
return {
|
|
||||||
schema: model,
|
|
||||||
actions: {},
|
|
||||||
lifecycles: {},
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
strapi.container.get('content-types').add(`api::${apiName}`, v4ContentTypes);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: remove v3
|
|
||||||
// Set models.
|
|
||||||
strapi.models = {};
|
|
||||||
for (const apiName in strapi.api) {
|
|
||||||
const api = strapi.api[apiName];
|
|
||||||
for (let modelName in api.models) {
|
|
||||||
let model = api.models[modelName];
|
|
||||||
const contentType = strapi.container
|
|
||||||
.get('content-types')
|
|
||||||
.get(`api::${apiName}.${model.info.singularName}`);
|
|
||||||
Object.assign(model, contentType.schema);
|
|
||||||
strapi.contentTypes[model.uid] = contentType.schema;
|
|
||||||
|
|
||||||
strapi.models[modelName] = model;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// set default services and default controllers
|
// set default services and default controllers
|
||||||
for (const apiName in strapi.api) {
|
for (const apiName in strapi.api) {
|
||||||
const api = strapi.api[apiName];
|
const api = strapi.api[apiName];
|
||||||
for (const modelName in api.models) {
|
for (const modelName in api.models) {
|
||||||
const model = api.models[modelName];
|
const model = api.models[modelName];
|
||||||
const { service, controller } = createCoreApi({ model, api, strapi });
|
model.info.displayName = model.info.displayName || model.info.name;
|
||||||
|
model.info.singularName = model.info.singularName || modelName;
|
||||||
|
model.info.pluralName = model.info.pluralName || pluralize(modelName);
|
||||||
|
|
||||||
|
strapi.container.get('content-types').add(`api::${apiName}.`, {
|
||||||
|
[modelName]: { schema: model, actions: model.actions, lifecycles: model.lifecycles },
|
||||||
|
});
|
||||||
|
|
||||||
|
const contentType = strapi.contentType(`api::${apiName}.${modelName}`);
|
||||||
|
|
||||||
|
const { service, controller } = createCoreApi({ model: contentType, api, strapi });
|
||||||
_.set(strapi.api[apiName], ['services', modelName], service);
|
_.set(strapi.api[apiName], ['services', modelName], service);
|
||||||
_.set(strapi.api[apiName], ['controllers', modelName], controller);
|
_.set(strapi.api[apiName], ['controllers', modelName], controller);
|
||||||
}
|
}
|
||||||
@ -95,42 +65,13 @@ module.exports = function(strapi) {
|
|||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
// Set user's services.
|
|
||||||
strapi.services = Object.keys(strapi.api || []).reduce((acc, apiName) => {
|
|
||||||
strapi.container.get('services').add(`api::${apiName}`, strapi.api[apiName].services);
|
|
||||||
for (let serviceName in strapi.api[apiName].services) {
|
|
||||||
acc[serviceName] = strapi.api[apiName].services[serviceName];
|
|
||||||
}
|
|
||||||
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
// Set routes.
|
// Set routes.
|
||||||
strapi.config.routes = Object.keys(strapi.api || []).reduce((acc, key) => {
|
strapi.config.routes = Object.keys(strapi.api || []).reduce((acc, key) => {
|
||||||
return acc.concat(_.get(strapi.api[key], 'config.routes') || {});
|
return acc.concat(_.get(strapi.api[key], 'config.routes') || {});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Init admin models.
|
|
||||||
Object.keys(strapi.admin.models || []).forEach(modelName => {
|
|
||||||
let model = strapi.admin.models[modelName];
|
|
||||||
// mutate model
|
|
||||||
const ct = { schema: model, actions: {}, lifecycles: {} };
|
|
||||||
ct.schema.info.displayName = model.info.name;
|
|
||||||
ct.schema.info.singularName = modelName;
|
|
||||||
ct.schema.info.pluralName = pluralize(modelName);
|
|
||||||
|
|
||||||
const createdContentType = createContentType(`strapi::${ct.schema.info.singularName}`, ct);
|
|
||||||
|
|
||||||
Object.assign(model, createdContentType.schema);
|
|
||||||
strapi.contentTypes[model.uid] = model;
|
|
||||||
});
|
|
||||||
|
|
||||||
// TODO: delete v3 code
|
// TODO: delete v3 code
|
||||||
_.forEach(strapi.plugins, plugin => {
|
_.forEach(strapi.plugins, plugin => {
|
||||||
_.forEach(plugin.contentTypes, (ct, ctUID) => {
|
|
||||||
strapi.contentTypes[ctUID] = ct.schema;
|
|
||||||
});
|
|
||||||
|
|
||||||
_.forEach(plugin.middlewares, (middleware, middlewareUID) => {
|
_.forEach(plugin.middlewares, (middleware, middlewareUID) => {
|
||||||
const middlewareName = toLower(middlewareUID.split('.')[1]);
|
const middlewareName = toLower(middlewareUID.split('.')[1]);
|
||||||
strapi.middleware[middlewareName] = middleware;
|
strapi.middleware[middlewareName] = middleware;
|
||||||
|
|||||||
@ -1,21 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const fse = require('fs-extra');
|
|
||||||
|
|
||||||
const walk = require('./walk');
|
|
||||||
|
|
||||||
const loadFunctions = dir => {
|
|
||||||
if (!fse.existsSync(dir)) return {};
|
|
||||||
|
|
||||||
return walk(dir, { loader: loadFunction });
|
|
||||||
};
|
|
||||||
|
|
||||||
const loadFunction = file => {
|
|
||||||
try {
|
|
||||||
return require(file);
|
|
||||||
} catch (error) {
|
|
||||||
throw `Could not load function ${file}: ${error.message}`;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = loadFunctions;
|
|
||||||
@ -1,36 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const assert = require('assert');
|
|
||||||
const path = require('path');
|
|
||||||
const _ = require('lodash');
|
|
||||||
const fse = require('fs-extra');
|
|
||||||
|
|
||||||
module.exports = dir => {
|
|
||||||
if (!fse.existsSync(dir)) return {};
|
|
||||||
|
|
||||||
const root = {};
|
|
||||||
const paths = fse.readdirSync(dir, { withFileTypes: true }).filter(fd => fd.isFile());
|
|
||||||
|
|
||||||
for (let fd of paths) {
|
|
||||||
const { name } = fd;
|
|
||||||
const fullPath = dir + path.sep + name;
|
|
||||||
|
|
||||||
const ext = path.extname(name);
|
|
||||||
const key = path.basename(name, ext);
|
|
||||||
root[_.toLower(key)] = loadPolicy(fullPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
return root;
|
|
||||||
};
|
|
||||||
|
|
||||||
const loadPolicy = file => {
|
|
||||||
try {
|
|
||||||
const policy = require(file);
|
|
||||||
|
|
||||||
assert(typeof policy === 'function', 'Policy must be a function.');
|
|
||||||
|
|
||||||
return policy;
|
|
||||||
} catch (error) {
|
|
||||||
throw `Could not load policy ${file}: ${error.message}`;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const assert = require('assert');
|
|
||||||
const path = require('path');
|
|
||||||
const fse = require('fs-extra');
|
|
||||||
|
|
||||||
module.exports = function walk(dir, { loader } = {}) {
|
|
||||||
assert(typeof loader === 'function', 'opts.loader must be a function');
|
|
||||||
|
|
||||||
const root = {};
|
|
||||||
const paths = fse.readdirSync(dir, { withFileTypes: true });
|
|
||||||
|
|
||||||
for (let fd of paths) {
|
|
||||||
const { name } = fd;
|
|
||||||
const fullPath = dir + path.sep + name;
|
|
||||||
|
|
||||||
if (fd.isDirectory()) {
|
|
||||||
root[name] = walk(fullPath, { loader });
|
|
||||||
} else {
|
|
||||||
const ext = path.extname(name);
|
|
||||||
const key = path.basename(name, ext);
|
|
||||||
root[key] = loader(fullPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return root;
|
|
||||||
};
|
|
||||||
@ -22,17 +22,23 @@ const contentTypesRegistry = () => {
|
|||||||
return contentTypes[ctUID];
|
return contentTypes[ctUID];
|
||||||
},
|
},
|
||||||
getAll(prefix = '') {
|
getAll(prefix = '') {
|
||||||
|
if (!prefix) {
|
||||||
|
return contentTypes;
|
||||||
|
}
|
||||||
|
|
||||||
return pickBy((ct, ctUID) => ctUID.startsWith(prefix))(contentTypes);
|
return pickBy((ct, ctUID) => ctUID.startsWith(prefix))(contentTypes);
|
||||||
},
|
},
|
||||||
add(namespace, rawContentTypes) {
|
add(namespace, rawContentTypes) {
|
||||||
validateKeySameToSingularName(rawContentTypes);
|
validateKeySameToSingularName(rawContentTypes);
|
||||||
|
|
||||||
for (const rawCtName in rawContentTypes) {
|
for (const rawCtName in rawContentTypes) {
|
||||||
const rawContentType = rawContentTypes[rawCtName];
|
const uid = `${namespace}${rawCtName}`;
|
||||||
const uid = `${namespace}.${rawContentType.schema.info.singularName}`;
|
|
||||||
if (has(uid, contentTypes)) {
|
if (has(uid, contentTypes)) {
|
||||||
throw new Error(`Content-type ${uid} has already been registered.`);
|
throw new Error(`Content-type ${uid} has already been registered.`);
|
||||||
}
|
}
|
||||||
contentTypes[uid] = createContentType(uid, rawContentType);
|
|
||||||
|
contentTypes[uid] = createContentType(uid, rawContentTypes[rawCtName]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -8,13 +8,20 @@
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const Router = require('koa-router');
|
const Router = require('koa-router');
|
||||||
const createEndpointComposer = require('./utils/composeEndpoint');
|
const createEndpointComposer = require('./utils/composeEndpoint');
|
||||||
/**
|
|
||||||
* Router hook
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = strapi => {
|
module.exports = strapi => {
|
||||||
const composeEndpoint = createEndpointComposer(strapi);
|
const composeEndpoint = createEndpointComposer(strapi);
|
||||||
|
|
||||||
|
const registerAdminRoutes = strapi => {
|
||||||
|
const router = new Router({ prefix: '/admin' });
|
||||||
|
|
||||||
|
strapi.admin.routes.forEach(route => {
|
||||||
|
composeEndpoint(route, { plugin: 'admin', router });
|
||||||
|
});
|
||||||
|
|
||||||
|
strapi.app.use(router.routes()).use(router.allowedMethods());
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
initialize() {
|
initialize() {
|
||||||
_.forEach(strapi.config.routes, value => {
|
_.forEach(strapi.config.routes, value => {
|
||||||
@ -23,16 +30,7 @@ module.exports = strapi => {
|
|||||||
|
|
||||||
strapi.router.prefix(strapi.config.get('middleware.settings.router.prefix', ''));
|
strapi.router.prefix(strapi.config.get('middleware.settings.router.prefix', ''));
|
||||||
|
|
||||||
if (_.has(strapi.admin, 'config.routes')) {
|
registerAdminRoutes(strapi);
|
||||||
const router = new Router({ prefix: '/admin' });
|
|
||||||
|
|
||||||
_.get(strapi.admin, 'config.routes', []).forEach(route => {
|
|
||||||
composeEndpoint(route, { plugin: 'admin', router });
|
|
||||||
});
|
|
||||||
|
|
||||||
// Mount admin router on Strapi router
|
|
||||||
strapi.app.use(router.routes()).use(router.allowedMethods());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strapi.plugins) {
|
if (strapi.plugins) {
|
||||||
// Parse each plugin's routes.
|
// Parse each plugin's routes.
|
||||||
|
|||||||
@ -14,7 +14,7 @@ module.exports = async function isInitialized(strapi) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// test if there is at least one admin
|
// test if there is at least one admin
|
||||||
const anyAdministrator = await strapi.query('strapi::user').findOne({ select: ['id'] });
|
const anyAdministrator = await strapi.query('admin::user').findOne({ select: ['id'] });
|
||||||
|
|
||||||
return !isNil(anyAdministrator);
|
return !isNil(anyAdministrator);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@ -37,7 +37,7 @@
|
|||||||
"cross-spawn": "^7.0.3",
|
"cross-spawn": "^7.0.3",
|
||||||
"debug": "^4.1.1",
|
"debug": "^4.1.1",
|
||||||
"delegates": "^1.0.0",
|
"delegates": "^1.0.0",
|
||||||
"dotenv": "8.2.0",
|
"dotenv": "10.0.0",
|
||||||
"execa": "^1.0.0",
|
"execa": "^1.0.0",
|
||||||
"fs-extra": "^9.1.0",
|
"fs-extra": "^9.1.0",
|
||||||
"glob": "^7.1.2",
|
"glob": "^7.1.2",
|
||||||
|
|||||||
@ -93,7 +93,7 @@ describe('Sanitize Entity', () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const models = {
|
const contentTypes = {
|
||||||
user: userModel,
|
user: userModel,
|
||||||
article: articleModel,
|
article: articleModel,
|
||||||
userRel: userRelModel,
|
userRel: userRelModel,
|
||||||
@ -103,7 +103,7 @@ describe('Sanitize Entity', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
global.strapi = {
|
global.strapi = {
|
||||||
getModel(name) {
|
getModel(name) {
|
||||||
return models[name];
|
return contentTypes[name];
|
||||||
},
|
},
|
||||||
config: {
|
config: {
|
||||||
get: jest.fn,
|
get: jest.fn,
|
||||||
@ -156,7 +156,7 @@ describe('Sanitize Entity', () => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
test.each(tests)(`Test n°%#`, (options, expected) => {
|
test.each(tests)(`Test n°%#`, (options, expected) => {
|
||||||
const { user: model } = models;
|
const { user: model } = contentTypes;
|
||||||
expect(sanitizeEntity(input, { ...options, model })).toStrictEqual(expected);
|
expect(sanitizeEntity(input, { ...options, model })).toStrictEqual(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -198,12 +198,12 @@ describe('Sanitize Entity', () => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
const model = {
|
const model = {
|
||||||
...models.user,
|
...contentTypes.user,
|
||||||
options: {
|
options: {
|
||||||
...models.user.options,
|
...contentTypes.user.options,
|
||||||
privateAttributes: ['firstname'],
|
privateAttributes: ['firstname'],
|
||||||
},
|
},
|
||||||
privateAttributes: [].concat(models.user.privateAttributes, ['firstname'], ['id']),
|
privateAttributes: [].concat(contentTypes.user.privateAttributes, ['firstname'], ['id']),
|
||||||
};
|
};
|
||||||
|
|
||||||
test.each(tests)(`Test n°%#`, (options, expected) => {
|
test.each(tests)(`Test n°%#`, (options, expected) => {
|
||||||
@ -256,14 +256,14 @@ describe('Sanitize Entity', () => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
test.each(tests)(`Test n°%#`, (source, options, expected) => {
|
test.each(tests)(`Test n°%#`, (source, options, expected) => {
|
||||||
const { userRel: model } = models;
|
const { userRel: model } = contentTypes;
|
||||||
expect(sanitizeEntity(source, { ...options, model })).toStrictEqual(expected);
|
expect(sanitizeEntity(source, { ...options, model })).toStrictEqual(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('With Dynamic Zone', () => {
|
describe('With Dynamic Zone', () => {
|
||||||
test('Dynamic zone null', () => {
|
test('Dynamic zone null', () => {
|
||||||
const { userDz: model } = models;
|
const { userDz: model } = contentTypes;
|
||||||
const dataSource = { ...inputWithDz, dz: null };
|
const dataSource = { ...inputWithDz, dz: null };
|
||||||
|
|
||||||
const expected = _.pick(dataSource, ['id', 'firstname', 'lastname', 'dz']);
|
const expected = _.pick(dataSource, ['id', 'firstname', 'lastname', 'dz']);
|
||||||
@ -272,7 +272,7 @@ describe('Sanitize Entity', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Dynamic zone with a basic component', () => {
|
test('Dynamic zone with a basic component', () => {
|
||||||
const { userDz: model } = models;
|
const { userDz: model } = contentTypes;
|
||||||
|
|
||||||
const expected = {
|
const expected = {
|
||||||
..._.pick(inputWithDz, ['id', 'firstname', 'lastname']),
|
..._.pick(inputWithDz, ['id', 'firstname', 'lastname']),
|
||||||
@ -295,7 +295,7 @@ describe('Sanitize Entity', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test(`It returns the input data as-is if it's not an object or an array`, () => {
|
test(`It returns the input data as-is if it's not an object or an array`, () => {
|
||||||
const { user: model } = models;
|
const { user: model } = contentTypes;
|
||||||
expect(sanitizeEntity('foobar', { model })).toBe('foobar');
|
expect(sanitizeEntity('foobar', { model })).toBe('foobar');
|
||||||
expect(sanitizeEntity(undefined, { model })).toBeUndefined();
|
expect(sanitizeEntity(undefined, { model })).toBeUndefined();
|
||||||
expect(sanitizeEntity(null, { model })).toBeNull();
|
expect(sanitizeEntity(null, { model })).toBeNull();
|
||||||
@ -309,7 +309,7 @@ describe('Sanitize Entity', () => {
|
|||||||
_.pick(input, 'id', 'firstname', 'lastname'),
|
_.pick(input, 'id', 'firstname', 'lastname'),
|
||||||
];
|
];
|
||||||
|
|
||||||
const { user: model } = models;
|
const { user: model } = contentTypes;
|
||||||
|
|
||||||
expect(sanitizeEntity(dataSource, { model })).toStrictEqual(expected);
|
expect(sanitizeEntity(dataSource, { model })).toStrictEqual(expected);
|
||||||
});
|
});
|
||||||
@ -318,7 +318,7 @@ describe('Sanitize Entity', () => {
|
|||||||
const dataSource = { ...inputWithRelation, article: null };
|
const dataSource = { ...inputWithRelation, article: null };
|
||||||
const expected = _.omit(dataSource, ['email', 'password']);
|
const expected = _.omit(dataSource, ['email', 'password']);
|
||||||
|
|
||||||
const { userRel: model } = models;
|
const { userRel: model } = contentTypes;
|
||||||
|
|
||||||
expect(sanitizeEntity(dataSource, { model })).toStrictEqual(expected);
|
expect(sanitizeEntity(dataSource, { model })).toStrictEqual(expected);
|
||||||
});
|
});
|
||||||
@ -332,7 +332,7 @@ describe('Sanitize Entity', () => {
|
|||||||
toJSON: jest.fn(() => null),
|
toJSON: jest.fn(() => null),
|
||||||
};
|
};
|
||||||
|
|
||||||
const { user: model } = models;
|
const { user: model } = contentTypes;
|
||||||
|
|
||||||
expect(sanitizeEntity(dataSource, { model })).toStrictEqual(
|
expect(sanitizeEntity(dataSource, { model })).toStrictEqual(
|
||||||
_.omit(input, ['email', 'password'])
|
_.omit(input, ['email', 'password'])
|
||||||
@ -346,7 +346,7 @@ describe('Sanitize Entity', () => {
|
|||||||
test('It should handle custom fields', () => {
|
test('It should handle custom fields', () => {
|
||||||
const dataSource = { ...input, foo: 'bar' };
|
const dataSource = { ...input, foo: 'bar' };
|
||||||
const expected = _.omit(dataSource, ['email', 'password']);
|
const expected = _.omit(dataSource, ['email', 'password']);
|
||||||
const { user: model } = models;
|
const { user: model } = contentTypes;
|
||||||
|
|
||||||
expect(sanitizeEntity(dataSource, { model })).toStrictEqual(expected);
|
expect(sanitizeEntity(dataSource, { model })).toStrictEqual(expected);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -34,13 +34,10 @@ module.exports = async () => {
|
|||||||
if (!strapi.config.get('plugin.users-permissions.jwtSecret')) {
|
if (!strapi.config.get('plugin.users-permissions.jwtSecret')) {
|
||||||
const jwtSecret = uuid();
|
const jwtSecret = uuid();
|
||||||
strapi.config.set('plugin.users-permissions.jwtSecret', jwtSecret);
|
strapi.config.set('plugin.users-permissions.jwtSecret', jwtSecret);
|
||||||
strapi.reload.isWatching = false;
|
|
||||||
|
|
||||||
if (!process.env.JWT_SECRET) {
|
if (!process.env.JWT_SECRET) {
|
||||||
await strapi.fs.appendFile('.env', `JWT_SECRET=${jwtSecret}\n`);
|
strapi.fs.appendFile('.env', `JWT_SECRET=${jwtSecret}\n`);
|
||||||
}
|
}
|
||||||
|
|
||||||
strapi.reload.isWatching = true;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,7 @@ const findEntityAndCheckPermissions = async (ability, action, model, id) => {
|
|||||||
const pm = strapi.admin.services.permission.createPermissionsManager({ ability, action, model });
|
const pm = strapi.admin.services.permission.createPermissionsManager({ ability, action, model });
|
||||||
|
|
||||||
const roles = _.has(entity, `${CREATED_BY_ATTRIBUTE}.id`)
|
const roles = _.has(entity, `${CREATED_BY_ATTRIBUTE}.id`)
|
||||||
? await strapi.query('strapi::role').findMany({
|
? await strapi.query('admin::role').findMany({
|
||||||
where: {
|
where: {
|
||||||
users: { id: entity[CREATED_BY_ATTRIBUTE].id },
|
users: { id: entity[CREATED_BY_ATTRIBUTE].id },
|
||||||
},
|
},
|
||||||
|
|||||||
@ -10,7 +10,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
initialize() {
|
initialize() {
|
||||||
_.forEach(strapi.admin.config.routes, value => {
|
_.forEach(strapi.admin.routes, value => {
|
||||||
if (_.get(value.config, 'policies')) {
|
if (_.get(value.config, 'policies')) {
|
||||||
value.config.policies.unshift('plugin::users-permissions.permissions');
|
value.config.policies.unshift('plugin::users-permissions.permissions');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8112,10 +8112,10 @@ dot-prop@^5.1.0, dot-prop@^5.2.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
is-obj "^2.0.0"
|
is-obj "^2.0.0"
|
||||||
|
|
||||||
dotenv@8.2.0:
|
dotenv@10.0.0:
|
||||||
version "8.2.0"
|
version "10.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a"
|
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
|
||||||
integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==
|
integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==
|
||||||
|
|
||||||
dotenv@8.5.1:
|
dotenv@8.5.1:
|
||||||
version "8.5.1"
|
version "8.5.1"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user