mirror of
				https://github.com/strapi/strapi.git
				synced 2025-11-04 03:43:34 +00:00 
			
		
		
		
	Hotfix mongo aggregate policy verifications
This commit is contained in:
		
							parent
							
								
									f36a5cf096
								
							
						
					
					
						commit
						7a3b64016c
					
				@ -7,6 +7,8 @@
 | 
				
			|||||||
const _ = require('lodash');
 | 
					const _ = require('lodash');
 | 
				
			||||||
const pluralize = require('pluralize');
 | 
					const pluralize = require('pluralize');
 | 
				
			||||||
const { convertRestQueryParams, buildQuery } = require('strapi-utils');
 | 
					const { convertRestQueryParams, buildQuery } = require('strapi-utils');
 | 
				
			||||||
 | 
					const policyUtils = require('strapi-utils').policy;
 | 
				
			||||||
 | 
					const compose = require('koa-compose');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const Schema = require('./Schema.js');
 | 
					const Schema = require('./Schema.js');
 | 
				
			||||||
const GraphQLQuery = require('./Query.js');
 | 
					const GraphQLQuery = require('./Query.js');
 | 
				
			||||||
@ -470,7 +472,13 @@ const formatConnectionAggregator = function(fields, model, modelName) {
 | 
				
			|||||||
 *  }
 | 
					 *  }
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
const formatModelConnectionsGQL = function(fields, model, name, modelResolver) {
 | 
					const formatModelConnectionsGQL = function(
 | 
				
			||||||
 | 
					  fields,
 | 
				
			||||||
 | 
					  model,
 | 
				
			||||||
 | 
					  name,
 | 
				
			||||||
 | 
					  modelResolver,
 | 
				
			||||||
 | 
					  plugin
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
  const { globalId } = model;
 | 
					  const { globalId } = model;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const connectionGlobalId = `${globalId}Connection`;
 | 
					  const connectionGlobalId = `${globalId}Connection`;
 | 
				
			||||||
@ -501,7 +509,50 @@ const formatModelConnectionsGQL = function(fields, model, name, modelResolver) {
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
    resolver: {
 | 
					    resolver: {
 | 
				
			||||||
      Query: {
 | 
					      Query: {
 | 
				
			||||||
        [`${pluralName}Connection`](obj, options, context) {
 | 
					        async [`${pluralName}Connection`](obj, options, { context }) {
 | 
				
			||||||
 | 
					          // need to check
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          const ctx = Object.assign(_.clone(context), {
 | 
				
			||||||
 | 
					            request: Object.assign(_.clone(context.request), {
 | 
				
			||||||
 | 
					              graphql: null,
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          const policiesFn = [
 | 
				
			||||||
 | 
					            policyUtils.globalPolicy(
 | 
				
			||||||
 | 
					              undefined,
 | 
				
			||||||
 | 
					              {
 | 
				
			||||||
 | 
					                handler: `${name}.find`,
 | 
				
			||||||
 | 
					              },
 | 
				
			||||||
 | 
					              undefined,
 | 
				
			||||||
 | 
					              plugin
 | 
				
			||||||
 | 
					            ),
 | 
				
			||||||
 | 
					          ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          policyUtils.get(
 | 
				
			||||||
 | 
					            'plugins.users-permissions.permissions',
 | 
				
			||||||
 | 
					            plugin,
 | 
				
			||||||
 | 
					            policiesFn,
 | 
				
			||||||
 | 
					            `GraphQL connection "${name}" `,
 | 
				
			||||||
 | 
					            name
 | 
				
			||||||
 | 
					          );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          // Execute policies stack.
 | 
				
			||||||
 | 
					          const policy = await compose(policiesFn)(ctx);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          // Policy doesn't always return errors but they update the current context.
 | 
				
			||||||
 | 
					          if (
 | 
				
			||||||
 | 
					            _.isError(ctx.request.graphql) ||
 | 
				
			||||||
 | 
					            _.get(ctx.request.graphql, 'isBoom')
 | 
				
			||||||
 | 
					          ) {
 | 
				
			||||||
 | 
					            return ctx.request.graphql;
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          // Something went wrong in the policy.
 | 
				
			||||||
 | 
					          if (policy) {
 | 
				
			||||||
 | 
					            return policy;
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          return options;
 | 
					          return options;
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
 | 
				
			|||||||
@ -167,7 +167,8 @@ const buildAssocResolvers = (model, name, { plugin }) => {
 | 
				
			|||||||
              };
 | 
					              };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
              if (
 | 
					              if (
 | 
				
			||||||
              ((association.nature === 'manyToMany' && association.dominant) ||
 | 
					                ((association.nature === 'manyToMany' &&
 | 
				
			||||||
 | 
					                  association.dominant) ||
 | 
				
			||||||
                  association.nature === 'manyWay') &&
 | 
					                  association.nature === 'manyWay') &&
 | 
				
			||||||
                _.has(obj, association.alias) // if populated
 | 
					                _.has(obj, association.alias) // if populated
 | 
				
			||||||
              ) {
 | 
					              ) {
 | 
				
			||||||
@ -181,7 +182,11 @@ const buildAssocResolvers = (model, name, { plugin }) => {
 | 
				
			|||||||
                    : []
 | 
					                    : []
 | 
				
			||||||
                );
 | 
					                );
 | 
				
			||||||
              } else {
 | 
					              } else {
 | 
				
			||||||
              _.set(queryOpts, ['query', association.via], obj[ref.primaryKey]);
 | 
					                _.set(
 | 
				
			||||||
 | 
					                  queryOpts,
 | 
				
			||||||
 | 
					                  ['query', association.via],
 | 
				
			||||||
 | 
					                  obj[ref.primaryKey]
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -190,12 +195,16 @@ const buildAssocResolvers = (model, name, { plugin }) => {
 | 
				
			|||||||
              : params.model;
 | 
					              : params.model;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return association.model
 | 
					            return association.model
 | 
				
			||||||
            ? strapi.plugins.graphql.services.loaders.loaders[loaderName].load({
 | 
					              ? strapi.plugins.graphql.services.loaders.loaders[
 | 
				
			||||||
 | 
					                  loaderName
 | 
				
			||||||
 | 
					                ].load({
 | 
				
			||||||
                  params,
 | 
					                  params,
 | 
				
			||||||
                  options: queryOpts,
 | 
					                  options: queryOpts,
 | 
				
			||||||
                  single: true,
 | 
					                  single: true,
 | 
				
			||||||
                })
 | 
					                })
 | 
				
			||||||
            : strapi.plugins.graphql.services.loaders.loaders[loaderName].load({
 | 
					              : strapi.plugins.graphql.services.loaders.loaders[
 | 
				
			||||||
 | 
					                  loaderName
 | 
				
			||||||
 | 
					                ].load({
 | 
				
			||||||
                  options: queryOpts,
 | 
					                  options: queryOpts,
 | 
				
			||||||
                  association,
 | 
					                  association,
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
@ -475,7 +484,8 @@ const buildShadowCRUD = (models, plugin) => {
 | 
				
			|||||||
        attributes,
 | 
					        attributes,
 | 
				
			||||||
        model,
 | 
					        model,
 | 
				
			||||||
        name,
 | 
					        name,
 | 
				
			||||||
        queries.plural
 | 
					        queries.plural,
 | 
				
			||||||
 | 
					        plugin
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
      if (modelAggregator) {
 | 
					      if (modelAggregator) {
 | 
				
			||||||
        acc.definition += modelAggregator.type;
 | 
					        acc.definition += modelAggregator.type;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user