diff --git a/README.md b/README.md index f91a0e382c..41c8629b0a 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Complete installation requirements can be found in the documentation under + sanitizeEntity(entity, { model: strapi.models.article }) + ); + }, +}; +``` + +And now the data is back on `GET /articles` + +## Apply our changes + +Here we want force to fetch articles that have status equal to `published`. + +The way to do that is to set `ctx.query.status` to `published`. +It will force the filter of the query. + +**Path —** `./api/restaurant/controller/Restaurant.js` + +```js +const { sanitizeEntity } = require('strapi-utils'); + +module.exports = { + async find(ctx) { + let entities; + + ctx.query = { + ...ctx.query, + status: 'published + }; + + if (ctx.query._q) { + entities = await strapi.services.article.search(ctx.query); + } else { + entities = await strapi.services.article.find(ctx.query); + } + + return entities.map(entity => + sanitizeEntity(entity, { model: strapi.models.article }) + ); + }, +}; +``` + +And tada! Draft and archived articles disapeared. + +::: tip +This guide can be applied to any other controller action. +::: + diff --git a/docs/3.0.0-beta.x/plugins/upload.md b/docs/3.0.0-beta.x/plugins/upload.md index 090eb04c64..2cd257ee06 100644 --- a/docs/3.0.0-beta.x/plugins/upload.md +++ b/docs/3.0.0-beta.x/plugins/upload.md @@ -76,7 +76,7 @@ You have to send FormData in your request body ## Upload files related to an entry -To upload files that will be liked to an specific entry. +To upload files that will be linked to an specific entry. ### Request parameters diff --git a/packages/strapi-generate-model/templates/mongoose/model.template b/packages/strapi-generate-model/templates/mongoose/model.template index 300dc5a200..30172b433f 100644 --- a/packages/strapi-generate-model/templates/mongoose/model.template +++ b/packages/strapi-generate-model/templates/mongoose/model.template @@ -6,11 +6,11 @@ module.exports = { // Before saving a value. - // Fired before an `insert` or `update` query. + // Fired before an `insert`. // beforeSave: async (model) => {}, // After saving a value. - // Fired after an `insert` or `update` query. + // Fired after an `insert`. // afterSave: async (model, result) => {}, // Before fetching all values. diff --git a/packages/strapi-hook-bookshelf/lib/queries.js b/packages/strapi-hook-bookshelf/lib/queries.js index 7048967927..3361160713 100644 --- a/packages/strapi-hook-bookshelf/lib/queries.js +++ b/packages/strapi-hook-bookshelf/lib/queries.js @@ -546,8 +546,8 @@ const buildSearchQuery = (qb, model, params) => { case 'pg': { const searchQuery = searchText.map(attribute => _.toLower(attribute) === attribute - ? `to_tsvector(${attribute})` - : `to_tsvector("${attribute}")` + ? `to_tsvector(coalesce(${attribute}, ''))` + : `to_tsvector(coalesce("${attribute}", ''))` ); qb.orWhereRaw(`${searchQuery.join(' || ')} @@ plainto_tsquery(?)`, query); diff --git a/packages/strapi-plugin-users-permissions/config/policies/permissions.js b/packages/strapi-plugin-users-permissions/config/policies/permissions.js index 55ae6bf4ad..e4fd13b294 100644 --- a/packages/strapi-plugin-users-permissions/config/policies/permissions.js +++ b/packages/strapi-plugin-users-permissions/config/policies/permissions.js @@ -16,11 +16,11 @@ module.exports = async (ctx, next) => { if (isAdmin) { ctx.state.admin = await strapi .query('administrator', 'admin') - .findOne({ id }); + .findOne({ id }, ['role']); } else { ctx.state.user = await strapi .query('user', 'users-permissions') - .findOne({ id }); + .findOne({ id }, ['role']); } } catch (err) { return handleErrors(ctx, err, 'unauthorized');