How to use the strapi-utils.policy function in strapi-utils

To help you get started, we’ve selected a few strapi-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github strapi / strapi / packages / strapi / lib / middlewares / router / utils / routerChecker.js View on Github external
'use strict';

/**
 * Module dependencies
 */

// Public node modules.
const _ = require('lodash');

// Strapi utilities.
const finder = require('strapi-utils').finder;
const regex = require('strapi-utils').regex;
const policyUtils = require('strapi-utils').policy;

module.exports = strapi =>
  function routerChecker(value, endpoint, plugin) {
    const route = regex.detectRoute(endpoint);

    // Define controller and action names.
    const [controllerName, actionName] = _.trim(value.handler).split('.');
    const controllerKey = _.toLower(controllerName);

    let controller;

    if (plugin) {
      controller = strapi.plugins[plugin].controllers[controllerKey];
    } else {
      controller =
        strapi.controllers[controllerKey] ||
github strapi / strapi / packages / strapi-plugin-graphql / services / GraphQL.js View on Github external
/**
 * GraphQL.js service
 *
 * @description: A set of functions similar to controller's actions to avoid code duplication.
 */


const fs = require('fs');
const path = require('path');
const _ = require('lodash');
const pluralize = require('pluralize');
const graphql = require('graphql');
const { makeExecutableSchema } = require('graphql-tools');
const GraphQLJSON = require('graphql-type-json');
const GraphQLDateTime = require('graphql-type-datetime');
const policyUtils = require('strapi-utils').policy;

module.exports = {

  /**
   * Receive an Object and return a string which is following the GraphQL specs.
   *
   * @return String
   */

  formatGQL: function (fields, description = {}, model = {}, type = 'field') {
    const typeFields = JSON.stringify(fields, null, 2).replace(/['",]+/g, '');
    const lines = typeFields.split('\n');

    // Try to add description for field.
    if (type === 'field') {
      return lines
github strapi / strapi / packages / strapi-plugin-graphql / services / Mutation.js View on Github external
'use strict';

/**
 * Mutation.js service
 *
 * @description: A set of functions similar to controller's actions to avoid code duplication.
 */

const _ = require('lodash');
const pluralize = require('pluralize');
const compose = require('koa-compose');
const policyUtils = require('strapi-utils').policy;
const Query = require('./Query.js');

module.exports = {
  /**
   * Execute policies before the specified resolver.
   *
   * @return Promise or Error.
   */

  composeMutationResolver: function({ _schema, plugin, name, action }) {
    // Extract custom resolver or type description.
    const { resolver: handler = {} } = _schema;

    let queryName;
    if (_.has(handler, `Mutation.${action}`)) {
      queryName = action;
github strapi / strapi-examples / nuxt-strapi-deliveroo-clone-tutorial / server / plugins / graphql / services / Query.js View on Github external
'use strict';

/**
 * Query.js service
 *
 * @description: A set of functions similar to controller's actions to avoid code duplication.
 */

const _ = require('lodash');
const pluralize = require('pluralize');
const policyUtils = require('strapi-utils').policy;

module.exports = {
  /**
   * Convert parameters to valid filters parameters.
   *
   * @return Object
   */

  convertToParams: params => {
    return Object.keys(params).reduce((acc, current) => {
      return Object.assign(acc, {
        [`_${current}`]: params[current],
      });
    }, {});
  },
github strapi / strapi / packages / strapi-plugin-graphql / services / Query.js View on Github external
'use strict';

/**
 * Query.js service
 *
 * @description: A set of functions similar to controller's actions to avoid code duplication.
 */

const _ = require('lodash');
const pluralize = require('pluralize');
const policyUtils = require('strapi-utils').policy;
const compose = require('koa-compose');

module.exports = {
  /**
   * Convert parameters to valid filters parameters.
   *
   * @return Object
   */

  convertToParams: params => {
    return Object.keys(params).reduce((acc, current) => {
      const key = current === 'id' ? 'id' : `_${current}`;
      acc[key] = params[current];
      return acc;
    }, {});
  },