mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 10:55:37 +00:00
Merge branch 'feature/private-s3-bucket' into private-s3-bucket/non-mutating-signing
This commit is contained in:
commit
f159f150f2
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const { assoc, has, prop, omit } = require('lodash/fp');
|
const { assoc, has, prop, omit } = require('lodash/fp');
|
||||||
const strapiUtils = require('@strapi/utils');
|
const strapiUtils = require('@strapi/utils');
|
||||||
|
const { mapAsync } = require('@strapi/utils');
|
||||||
const { ApplicationError } = require('@strapi/utils').errors;
|
const { ApplicationError } = require('@strapi/utils').errors;
|
||||||
const { getDeepPopulate, getDeepPopulateDraftCount } = require('./utils/populate');
|
const { getDeepPopulate, getDeepPopulateDraftCount } = require('./utils/populate');
|
||||||
const { getDeepRelationsCount } = require('./utils/count');
|
const { getDeepRelationsCount } = require('./utils/count');
|
||||||
@ -72,36 +73,57 @@ module.exports = ({ strapi }) => ({
|
|||||||
return assoc(`${CREATED_BY_ATTRIBUTE}.roles`, roles, entity);
|
return assoc(`${CREATED_BY_ATTRIBUTE}.roles`, roles, entity);
|
||||||
},
|
},
|
||||||
|
|
||||||
find(opts, uid) {
|
/**
|
||||||
|
* Extend this function from other plugins to add custom mapping of entity
|
||||||
|
* responses
|
||||||
|
* @param {Object} entity
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
mapEntity(entity) {
|
||||||
|
return entity;
|
||||||
|
},
|
||||||
|
|
||||||
|
async find(opts, uid) {
|
||||||
const params = { ...opts, populate: getDeepPopulate(uid) };
|
const params = { ...opts, populate: getDeepPopulate(uid) };
|
||||||
|
|
||||||
return strapi.entityService.findMany(uid, params);
|
const entities = await strapi.entityService.findMany(uid, params);
|
||||||
|
await mapAsync(entities.results, async (entity) => this.mapEntity(entity, uid));
|
||||||
|
return entities;
|
||||||
},
|
},
|
||||||
|
|
||||||
findPage(opts, uid) {
|
async findPage(opts, uid) {
|
||||||
const params = { ...opts, populate: getDeepPopulate(uid, { maxLevel: 1 }) };
|
const params = { ...opts, populate: getDeepPopulate(uid, { maxLevel: 1 }) };
|
||||||
|
|
||||||
return strapi.entityService.findPage(uid, params);
|
const entities = await strapi.entityService.findPage(uid, params);
|
||||||
|
await mapAsync(entities.results, async (entity) => this.mapEntity(entity, uid));
|
||||||
|
return entities;
|
||||||
},
|
},
|
||||||
|
|
||||||
findWithRelationCountsPage(opts, uid) {
|
async findWithRelationCountsPage(opts, uid) {
|
||||||
const counterPopulate = getDeepPopulate(uid, { countMany: true, maxLevel: 1 });
|
const counterPopulate = getDeepPopulate(uid, { countMany: true, maxLevel: 1 });
|
||||||
const params = { ...opts, populate: addCreatedByRolesPopulate(counterPopulate) };
|
const params = { ...opts, populate: addCreatedByRolesPopulate(counterPopulate) };
|
||||||
|
|
||||||
return strapi.entityService.findWithRelationCountsPage(uid, params);
|
const entities = await strapi.entityService.findWithRelationCountsPage(uid, params);
|
||||||
|
await mapAsync(entities.results, async (entity) => this.mapEntity(entity, uid));
|
||||||
|
|
||||||
|
return entities;
|
||||||
},
|
},
|
||||||
|
|
||||||
findOneWithCreatorRolesAndCount(id, uid) {
|
async findOneWithCreatorRolesAndCount(id, uid) {
|
||||||
const counterPopulate = getDeepPopulate(uid, { countMany: true, countOne: true });
|
const counterPopulate = getDeepPopulate(uid, { countMany: true, countOne: true });
|
||||||
const params = { populate: addCreatedByRolesPopulate(counterPopulate) };
|
const params = { populate: addCreatedByRolesPopulate(counterPopulate) };
|
||||||
|
|
||||||
return strapi.entityService.findOne(uid, id, params);
|
const entities = await strapi.entityService.findOne(uid, id, params);
|
||||||
|
await mapAsync(entities.results, async (entity) => this.mapEntity(entity, uid));
|
||||||
|
|
||||||
|
return entities;
|
||||||
},
|
},
|
||||||
|
|
||||||
async findOne(id, uid) {
|
async findOne(id, uid) {
|
||||||
const params = { populate: getDeepPopulate(uid) };
|
const params = { populate: getDeepPopulate(uid) };
|
||||||
|
|
||||||
return strapi.entityService.findOne(uid, id, params);
|
const entity = await strapi.entityService.findOne(uid, id, params);
|
||||||
|
return this.mapEntity(entity, uid);
|
||||||
},
|
},
|
||||||
|
|
||||||
async findOneWithCreatorRoles(id, uid) {
|
async findOneWithCreatorRoles(id, uid) {
|
||||||
@ -137,7 +159,7 @@ module.exports = ({ strapi }) => ({
|
|||||||
return getDeepRelationsCount(entity, uid);
|
return getDeepRelationsCount(entity, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return entity;
|
return this.mapEntity(entity, uid);
|
||||||
},
|
},
|
||||||
|
|
||||||
async update(entity, body, uid) {
|
async update(entity, body, uid) {
|
||||||
@ -158,7 +180,7 @@ module.exports = ({ strapi }) => ({
|
|||||||
return getDeepRelationsCount(updatedEntity, uid);
|
return getDeepRelationsCount(updatedEntity, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return updatedEntity;
|
return this.mapEntity(updatedEntity, uid);
|
||||||
},
|
},
|
||||||
|
|
||||||
async delete(entity, uid) {
|
async delete(entity, uid) {
|
||||||
@ -219,7 +241,7 @@ module.exports = ({ strapi }) => ({
|
|||||||
return getDeepRelationsCount(updatedEntity, uid);
|
return getDeepRelationsCount(updatedEntity, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return updatedEntity;
|
return this.mapEntity(updatedEntity, uid);
|
||||||
},
|
},
|
||||||
|
|
||||||
async unpublish(entity, body = {}, uid) {
|
async unpublish(entity, body = {}, uid) {
|
||||||
@ -246,7 +268,7 @@ module.exports = ({ strapi }) => ({
|
|||||||
return getDeepRelationsCount(updatedEntity, uid);
|
return getDeepRelationsCount(updatedEntity, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return updatedEntity;
|
return this.mapEntity(updatedEntity, uid);
|
||||||
},
|
},
|
||||||
|
|
||||||
async getNumberOfDraftRelations(id, uid) {
|
async getNumberOfDraftRelations(id, uid) {
|
||||||
|
|||||||
@ -76,45 +76,16 @@ const addSignedFileUrlsToAdmin = () => {
|
|||||||
// Documentation
|
// Documentation
|
||||||
strapi.container
|
strapi.container
|
||||||
.get('services')
|
.get('services')
|
||||||
.extend(`plugin::content-manager.entity-manager`, (entityManager) => {
|
.extend('plugin::content-manager.entity-manager', (entityManager) => {
|
||||||
const update = async (entity, body, uid) => {
|
/**
|
||||||
const updatedEntity = await entityManager.update(entity, body, uid);
|
* Map entity manager responses to sign private media URLs
|
||||||
return signEntityMedia(updatedEntity, uid);
|
* @param {Object} entity
|
||||||
};
|
* @param {string} uid
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
const mapEntity = async (entity, uid) => signEntityMedia(entity, uid);
|
||||||
|
|
||||||
const publish = async (entity, body, uid) => {
|
return { ...entityManager, mapEntity };
|
||||||
const publishedEntity = await entityManager.publish(entity, body, uid);
|
|
||||||
return signEntityMedia(publishedEntity, uid);
|
|
||||||
};
|
|
||||||
|
|
||||||
const unpublish = async (entity, body, uid) => {
|
|
||||||
const unpublishedEntity = await entityManager.unpublish(entity, body, uid);
|
|
||||||
return signEntityMedia(unpublishedEntity, uid);
|
|
||||||
};
|
|
||||||
|
|
||||||
const findOneWithCreatorRolesAndCount = async (id, uid) => {
|
|
||||||
// TODO: What if the entity is not found?
|
|
||||||
const entity = await entityManager.findOneWithCreatorRolesAndCount(id, uid);
|
|
||||||
return signEntityMedia(entity, uid);
|
|
||||||
};
|
|
||||||
|
|
||||||
const findWithRelationCountsPage = async (opts, uid) => {
|
|
||||||
const entities = await entityManager.findWithRelationCountsPage(opts, uid);
|
|
||||||
const results = await mapAsync(entities.results, async (entity) =>
|
|
||||||
signEntityMedia(entity, uid)
|
|
||||||
);
|
|
||||||
|
|
||||||
return { ...entities, results };
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
...entityManager,
|
|
||||||
findOneWithCreatorRolesAndCount,
|
|
||||||
findWithRelationCountsPage,
|
|
||||||
update,
|
|
||||||
publish,
|
|
||||||
unpublish,
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user