diff --git a/packages/strapi-mongoose/lib/index.js b/packages/strapi-mongoose/lib/index.js index 32d5abe8ff..194f195853 100755 --- a/packages/strapi-mongoose/lib/index.js +++ b/packages/strapi-mongoose/lib/index.js @@ -96,7 +96,9 @@ module.exports = function (strapi) { _.forEach(preLifecycle, (fn, key) => { if (_.isFunction(target[model.toLowerCase()][fn])) { - collection.schema.pre(key, target[model.toLowerCase()][fn]); + collection.schema.pre(key, function (next) { + target[model.toLowerCase()][fn](this).then(next).catch(err => strapi.log.error(err)); + }); } }); diff --git a/packages/strapi-plugin-content-manager/admin/src/components/EditForm/index.js b/packages/strapi-plugin-content-manager/admin/src/components/EditForm/index.js index ba074d9482..f88abc527e 100755 --- a/packages/strapi-plugin-content-manager/admin/src/components/EditForm/index.js +++ b/packages/strapi-plugin-content-manager/admin/src/components/EditForm/index.js @@ -64,7 +64,7 @@ class EditForm extends React.Component { const validationsIndex = findIndex(this.props.formValidations, ['name', attr]); const validations = get(this.props.formValidations[validationsIndex], 'validations') || {}; - const layout = Object.keys(get(currentLayout, attr, {})).reduce((acc, current) => { + const layout = Object.keys(get(currentLayout, `attributes.${attr}`, {})).reduce((acc, current) => { acc[current] = isFunction(currentLayout[attr][current]) ? currentLayout[attr][current](this) : currentLayout[attr][current]; diff --git a/packages/strapi-plugin-content-manager/admin/src/containers/Edit/index.js b/packages/strapi-plugin-content-manager/admin/src/containers/Edit/index.js index e3bdcda825..0a20a81aa5 100755 --- a/packages/strapi-plugin-content-manager/admin/src/containers/Edit/index.js +++ b/packages/strapi-plugin-content-manager/admin/src/containers/Edit/index.js @@ -122,7 +122,6 @@ export class Edit extends React.Component { componentWillReceiveProps(nextProps) { if (this.props.editSuccess !== nextProps.editSuccess) { if (!isEmpty(this.props.location.search)) { - strapi.notification.success('content-manager.success.record.save'); router.push(replace(this.props.location.search, '?redirectUrl=', '')); } else { router.push(replace(this.props.location.pathname, 'create', '')); diff --git a/packages/strapi-plugin-content-manager/admin/src/containers/Edit/sagas.js b/packages/strapi-plugin-content-manager/admin/src/containers/Edit/sagas.js index c07e5de029..8a3fd2a15c 100755 --- a/packages/strapi-plugin-content-manager/admin/src/containers/Edit/sagas.js +++ b/packages/strapi-plugin-content-manager/admin/src/containers/Edit/sagas.js @@ -71,6 +71,8 @@ export function* editRecord(action) { params, }); + console.log(recordCleaned); + yield put(recordEdited()); strapi.notification.success('content-manager.success.record.save'); } catch (err) { diff --git a/packages/strapi-plugin-content-manager/admin/src/containers/List/actions.js b/packages/strapi-plugin-content-manager/admin/src/containers/List/actions.js index 0daef010c6..5b62e8ffb3 100755 --- a/packages/strapi-plugin-content-manager/admin/src/containers/List/actions.js +++ b/packages/strapi-plugin-content-manager/admin/src/containers/List/actions.js @@ -21,24 +21,27 @@ import { SET_CURRENT_MODEL_NAME, } from './constants'; -export function changeLimit(limit) { +export function changeLimit(limit, source) { return { type: CHANGE_LIMIT, - limit, + limit: limit <= 0 ? 20 : limit, + source, }; } -export function changePage(page) { +export function changePage(page, source) { return { type: CHANGE_PAGE, - page, + page: page <= 0 ? 1 : page, + source, }; } -export function changeSort(sort) { +export function changeSort(sort, source) { return { type: CHANGE_SORT, sort, + source, }; } diff --git a/packages/strapi-plugin-content-manager/admin/src/containers/List/index.js b/packages/strapi-plugin-content-manager/admin/src/containers/List/index.js index 8ce577012a..557df64b94 100755 --- a/packages/strapi-plugin-content-manager/admin/src/containers/List/index.js +++ b/packages/strapi-plugin-content-manager/admin/src/containers/List/index.js @@ -83,7 +83,7 @@ export class List extends React.Component { } if (!isEmpty(nextProps.location.search) && this.props.location.search !== nextProps.location.search) { - this.props.loadRecords(); + this.props.loadRecords(this.state.source); } } @@ -97,11 +97,11 @@ export class List extends React.Component { getQueryParameters('sort')) || 'id'; if (!isEmpty(props.location.search)) { - this.props.changePage(toInteger(getQueryParameters('page'))); - this.props.changeLimit(toInteger(getQueryParameters('limit'))); + this.props.changePage(toInteger(getQueryParameters('page')), this.state.source); + this.props.changeLimit(toInteger(getQueryParameters('limit')), this.state.source); } - this.props.changeSort(sort); + this.props.changeSort(sort, this.state.source); // Load records this.props.loadRecords(this.state.source); @@ -114,7 +114,7 @@ export class List extends React.Component { } handleChangeLimit = ({ target }) => { - this.props.changeLimit(parseInt(target.value)); + this.props.changeLimit(toInteger(target.value), this.state.source); router.push({ pathname: this.props.location.pathname, search: `?page=${this.props.currentPage}&limit=${target.value}&sort=${this.props.sort}&source=${this.state.source}`, @@ -126,7 +126,7 @@ export class List extends React.Component { pathname: this.props.location.pathname, search: `?page=${page}&limit=${this.props.limit}&sort=${this.props.sort}&source=${this.state.source}`, }); - this.props.changePage(page); + this.props.changePage(page, this.state.source); } handleChangeSort = (sort) => { @@ -134,7 +134,7 @@ export class List extends React.Component { pathname: this.props.location.pathname, search: `?page=${this.props.currentPage}&limit=${this.props.limit}&sort=${sort}&source=${this.state.source}`, }); - this.props.changeSort(sort); + this.props.changeSort(sort, this.state.source); } handleDelete = (e) => { diff --git a/packages/strapi-plugin-content-manager/config/policies/routing.js b/packages/strapi-plugin-content-manager/config/policies/routing.js new file mode 100644 index 0000000000..5cd7c26b37 --- /dev/null +++ b/packages/strapi-plugin-content-manager/config/policies/routing.js @@ -0,0 +1,13 @@ +const _ = require('lodash'); + +module.exports = async (ctx, next) => { + const { source } = ctx.request.query; + + ctx.request.query.redirectQuery = {}; + + if (source && _.get(strapi.plugins, [source, 'config', 'layout', 'actions', ctx.request.route.action])) { + ctx.request.query.redirectQuery = _.get(strapi.plugins, [source, 'config', 'layout', 'actions']); + } + + await next(); +}; diff --git a/packages/strapi-plugin-content-manager/config/routes.json b/packages/strapi-plugin-content-manager/config/routes.json index 5b3b7b5028..7d2fb0a68f 100755 --- a/packages/strapi-plugin-content-manager/config/routes.json +++ b/packages/strapi-plugin-content-manager/config/routes.json @@ -5,7 +5,7 @@ "path": "/models", "handler": "ContentManager.models", "config": { - "policies": [] + "policies": ["routing"] } }, { @@ -13,7 +13,7 @@ "path": "/explorer/:model", "handler": "ContentManager.find", "config": { - "policies": [] + "policies": ["routing"] } }, { @@ -21,7 +21,7 @@ "path": "/explorer/:model/count", "handler": "ContentManager.count", "config": { - "policies": [] + "policies": ["routing"] } }, { @@ -29,14 +29,14 @@ "path": "/explorer/:model/:id", "handler": "ContentManager.findOne", "config": { - "policies": [] + "policies": ["routing"] } },{ "method": "POST", "path": "/explorer/:model", "handler": "ContentManager.create", "config": { - "policies": [] + "policies": ["routing"] } }, { @@ -44,7 +44,7 @@ "path": "/explorer/:model/:id", "handler": "ContentManager.update", "config": { - "policies": [] + "policies": ["routing"] } }, { @@ -52,7 +52,7 @@ "path": "/explorer/:model/:id", "handler": "ContentManager.delete", "config": { - "policies": [] + "policies": ["routing"] } } ] diff --git a/packages/strapi-plugin-content-manager/controllers/ContentManager.js b/packages/strapi-plugin-content-manager/controllers/ContentManager.js index c9ef86c0e8..4a8e5dd51a 100755 --- a/packages/strapi-plugin-content-manager/controllers/ContentManager.js +++ b/packages/strapi-plugin-content-manager/controllers/ContentManager.js @@ -35,10 +35,12 @@ module.exports = { }, find: async ctx => { - const { limit, skip = 0, sort, query, queryAttribute, source } = ctx.request.query; + const { limit, skip = 0, sort, query, queryAttribute, source, redirectQuery } = ctx.request.query; + + console.log(redirectQuery); // Find entries using `queries` system - const entries = await strapi.query(ctx.params.model, source).find({ + const entries = await strapi.query(ctx.params.model, source)[redirectQuery['find'] || 'find']({ limit, skip, sort, @@ -50,10 +52,10 @@ module.exports = { }, count: async ctx => { - const { source } = ctx.request.query; + const { source, redirectQuery } = ctx.request.query; // Count using `queries` system - const count = await strapi.query(ctx.params.model, source).count(); + const count = await strapi.query(ctx.params.model, source)[redirectQuery['count'] || 'count'](); ctx.body = { count: _.isNumber(count) ? count : _.toNumber(count) @@ -61,10 +63,10 @@ module.exports = { }, findOne: async ctx => { - const { source } = ctx.request.query; + const { source, redirectQuery } = ctx.request.query; // Find an entry using `queries` system - const entry = await strapi.query(ctx.params.model, source).findOne({ + const entry = await strapi.query(ctx.params.model, source)[redirectQuery['findOne'] || 'findOne']({ id: ctx.params.id }); @@ -77,10 +79,10 @@ module.exports = { }, create: async ctx => { - const { source } = ctx.request.query; + const { source, redirectQuery } = ctx.request.query; // Create an entry using `queries` system - const entryCreated = await strapi.query(ctx.params.model, source).create({ + const entryCreated = await strapi.query(ctx.params.model, source)[redirectQuery['create'] || 'create']({ values: ctx.request.body }); @@ -88,10 +90,10 @@ module.exports = { }, update: async ctx => { - const { source } = ctx.request.query; + const { source, redirectQuery } = ctx.request.query; // Add current model to the flow of updates. - const entry = strapi.query(ctx.params.model, source).update({ + const entry = strapi.query(ctx.params.model, source)[redirectQuery['update'] || 'update']({ id: ctx.params.id, values: ctx.request.body }); @@ -101,10 +103,10 @@ module.exports = { }, delete: async ctx => { - const { source } = ctx.request.query; + const { source, redirectQuery } = ctx.request.query; const params = ctx.params; - const response = await strapi.query(params.model, source).findOne({ + const response = await strapi.query(params.model, source)[redirectQuery['findOne'] || 'findOne']({ id: params.id }); @@ -121,11 +123,11 @@ module.exports = { if (!_.isEmpty(params.values)) { // Run update to remove all relationships. - await strapi.query(params.model, source).update(params); + await strapi.query(params.model, source)[redirectQuery['update'] || 'update'](params); } // Delete an entry using `queries` system - const entryDeleted = await strapi.query(params.model, source).delete({ + const entryDeleted = await strapi.query(params.model, source)[redirectQuery['delete'] || 'delete']({ id: params.id }); diff --git a/packages/strapi-plugin-users-permissions/config/layout.js b/packages/strapi-plugin-users-permissions/config/layout.js index fa3acc903b..660b1c9627 100644 --- a/packages/strapi-plugin-users-permissions/config/layout.js +++ b/packages/strapi-plugin-users-permissions/config/layout.js @@ -1,22 +1,27 @@ module.exports = { user: { - username: { - className: 'col-md-6' + actions: { + create: 'create' }, - email: { - className: 'col-md-6' - }, - username: { - className: 'col-md-6' - }, - provider: { - className: 'd-none' - }, - resetPasswordToken: { - className: 'd-none' - }, - role: { - className: 'd-none' + attributes: { + username: { + className: 'col-md-6' + }, + email: { + className: 'col-md-6' + }, + username: { + className: 'col-md-6' + }, + provider: { + className: 'd-none' + }, + resetPasswordToken: { + className: 'd-none' + }, + role: { + className: 'd-none' + } } } }; diff --git a/packages/strapi-plugin-users-permissions/models/User.js b/packages/strapi-plugin-users-permissions/models/User.js index 9e2a4dcb3a..419cfc7c51 100644 --- a/packages/strapi-plugin-users-permissions/models/User.js +++ b/packages/strapi-plugin-users-permissions/models/User.js @@ -8,9 +8,8 @@ module.exports = { // Before saving a value. // Fired before an `insert` or `update` query. - // beforeSave: function (next) { - // // Use `this` to get your current object - // next(); + // beforeSave: (model) => { + // return Promise.resolve(); // }, // After saving a value. @@ -21,10 +20,11 @@ module.exports = { // Before fetching all values. // Fired before a `fetchAll` operation. - // beforeFetchAll: function (next) { - // // Use `this` to get your current object - // next(); - // }, + beforeFetchAll: (model) => { + // Use `this` to get your current object + console.log(model); + return Promise.resolve(); + }, // After fetching all values. // Fired after a `fetchAll` operation. diff --git a/packages/strapi/lib/utils/index.js b/packages/strapi/lib/utils/index.js index 7f4b2bb695..e6e3ad2c46 100755 --- a/packages/strapi/lib/utils/index.js +++ b/packages/strapi/lib/utils/index.js @@ -84,7 +84,8 @@ module.exports = { p.indexOf('hook') !== -1 || p.indexOf('middleware') !== -1 || p.indexOf('language') !== -1 || - p.indexOf('queries') !== -1 + p.indexOf('queries') !== -1 || + p.indexOf('layout') !== -1 ); const optional = difference(files, aggregate);