<commit_before>'use strict';

const
  _ = require('lodash'),
  Promise = require('bluebird'),
  async = require('async'),
  vm = require('vm'),
  BadRequestError = require('kuzzle-common-objects').errors.BadRequestError,
  InternalError = require('kuzzle-common-objects').errors.InternalError,
  ParseError = require('kuzzle-common-objects').errors.ParseError,
  Request = require('kuzzle-common-objects').Request,
  Sandbox = require('../../sandbox');

/**
 * @constructor
 */
function Role () {
  this.controllers = {};

  // closures and restrictedTo are computed for internal use only.
  this.closures = {};

  // Injected by Profile.getRoles, contains a profile's policies
  this.restrictedTo = [];
}

function doesIndexExist(index, indexes) {
  return indexes && indexes[index] !== undefined;
}

function doesCollectionExist(index, collection, indexes) {
  return doesIndexExist(index, indexes) && _.includes(indexes[index], collection);
}

/**
 * @param {Request} request
 * @param {Kuzzle} kuzzle
 * @return Promise
 */
Role.prototype.isActionAllowed = function roleIsActionAllowed (request, kuzzle) {
  var
    controllerRights,
    actionRights,
    promises = [],
    path = [];

  // explicit actions on internalIndex must be denied:
  if (request.input.resource.index === kuzzle.internalEngine.index) {
    return Promise.resolve(false);
  }

  if (this.controllers === undefined) {
    return Promise.resolve(false);
  }

  if (this.controllers[request.input.controller] !== undefined) {
    controllerRights = this.controllers[request.input.controller];<commit_msg>remove rights check on internal Index (already done witithin storageEngine since  #538<commit_after>'use strict';

const
  _ = require('lodash'),
  Promise = require('bluebird'),
  async = require('async'),
  vm = require('vm'),
  BadRequestError = require('kuzzle-common-objects').errors.BadRequestError,
  InternalError = require('kuzzle-common-objects').errors.InternalError,
  ParseError = require('kuzzle-common-objects').errors.ParseError,
  Request = require('kuzzle-common-objects').Request,
  Sandbox = require('../../sandbox');

/**
 * @constructor
 */
function Role () {
  this.controllers = {};

  // closures and restrictedTo are computed for internal use only.
  this.closures = {};

  // Injected by Profile.getRoles, contains a profile's policies
  this.restrictedTo = [];
}

function doesIndexExist(index, indexes) {
  return indexes && indexes[index] !== undefined;
}

function doesCollectionExist(index, collection, indexes) {
  return doesIndexExist(index, indexes) && _.includes(indexes[index], collection);
}

/**
 * @param {Request} request
 * @param {Kuzzle} kuzzle
 * @return Promise
 */
Role.prototype.isActionAllowed = function roleIsActionAllowed (request, kuzzle) {
  var
    controllerRights,
    actionRights,
    promises = [],
    path = [];

  if (this.controllers === undefined) {
    return Promise.resolve(false);
  }

  if (this.controllers[request.input.controller] !== undefined) {
    controllerRights = this.controllers[request.input.controller];
{'fraction_non_alphanumeric': 0.1424380704041721, 'fraction_numerical': 0.0009778357235984355, 'mean_word_length': 4.460854092526691, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6522974', 'n_tokens_mistral': 925, 'n_tokens_neox': 880, 'n_words': 194}