passes id of document to access operations where required

This commit is contained in:
James
2020-08-24 17:02:03 -04:00
parent 45da1369ca
commit b197d780c1
6 changed files with 14 additions and 7 deletions

View File

@@ -28,7 +28,7 @@ async function update(args) {
// 1. Execute access
// /////////////////////////////////////
const accessResults = !overrideAccess ? await executeAccess({ req }, collectionConfig.access.update) : true;
const accessResults = !overrideAccess ? await executeAccess({ req, id }, collectionConfig.access.update) : true;
const hasWhereAccess = typeof accessResults === 'object';
// /////////////////////////////////////
@@ -91,6 +91,7 @@ async function update(args) {
data = await this.performFieldOperations(collectionConfig, {
data,
req,
id,
hook: 'beforeChange',
operation: 'update',
originalDoc,
@@ -149,6 +150,7 @@ async function update(args) {
hook: 'afterRead',
operation: 'read',
req,
id,
depth,
overrideAccess,
});

View File

@@ -100,6 +100,7 @@ async function find(args) {
depth,
data,
req,
id: doc.id,
hook: 'afterRead',
operation: 'read',
overrideAccess,

View File

@@ -24,7 +24,7 @@ async function findByID(args) {
// 1. Retrieve and execute access
// /////////////////////////////////////
const accessResults = !overrideAccess ? await executeAccess({ req, disableErrors }, collectionConfig.access.read) : true;
const accessResults = !overrideAccess ? await executeAccess({ req, disableErrors, id }, collectionConfig.access.read) : true;
const hasWhereAccess = typeof accessResults === 'object';
const queryToBuild = {
@@ -81,6 +81,7 @@ async function findByID(args) {
result = await this.performFieldOperations(collectionConfig, {
depth,
req,
id,
data: result,
hook: 'afterRead',
operation: 'read',

View File

@@ -33,7 +33,7 @@ async function update(args) {
// 1. Execute access
// /////////////////////////////////////
const accessResults = !overrideAccess ? await executeAccess({ req }, collectionConfig.access.update) : true;
const accessResults = !overrideAccess ? await executeAccess({ req, id }, collectionConfig.access.update) : true;
const hasWherePolicy = typeof accessResults === 'object';
// /////////////////////////////////////
@@ -96,6 +96,7 @@ async function update(args) {
data = await this.performFieldOperations(collectionConfig, {
data,
req,
id,
originalDoc,
hook: 'beforeChange',
operation: 'update',
@@ -185,6 +186,7 @@ async function update(args) {
hook: 'afterRead',
operation: 'read',
req,
id,
depth,
overrideAccess,
});

View File

@@ -8,6 +8,7 @@ async function performFieldOperations(entityConfig, args) {
operation,
hook,
req,
id,
req: {
payloadAPI,
},
@@ -31,7 +32,7 @@ async function performFieldOperations(entityConfig, args) {
const relatedCollection = this.collections[relation];
if (relatedCollection) {
const accessResult = !overrideAccess ? await executeAccess({ req, disableErrors: true }, relatedCollection.config.access.read) : true;
const accessResult = !overrideAccess ? await executeAccess({ req, disableErrors: true, id }, relatedCollection.config.access.read) : true;
let populatedRelationship = null;
@@ -117,7 +118,7 @@ async function performFieldOperations(entityConfig, args) {
const resultingData = data;
if (field.access && field.access[operation]) {
const result = overrideAccess ? true : await field.access[operation]({ req });
const result = overrideAccess ? true : await field.access[operation]({ req, id });
if (!result && operation === 'update' && originalDoc[field.name] !== undefined) {
resultingData[field.name] = originalDoc[field.name];

View File

@@ -1,6 +1,6 @@
const HtmlWebpackPlugin = require('html-webpack-plugin');
const Dotenv = require('dotenv-webpack');
// const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const webpack = require('webpack');
const path = require('path');
const getStyleLoaders = require('./getStyleLoaders');
@@ -115,7 +115,7 @@ module.exports = (config) => {
};
const plugins = [
// new BundleAnalyzerPlugin(),
new BundleAnalyzerPlugin(),
new HtmlWebpackPlugin({
template: config.admin && config.admin.indexHTML ? config.admin.indexHTML : path.resolve(__dirname, '../client/index.html'),
filename: './index.html',