<commit_before>var _ = require('lodash');
var async = require('async');
var path = require('path');
var I18NHelper = require('cp-i18n-lib');
var i18nHelper = new I18NHelper({
  poFilePath: path.resolve('web/locale/'),
  poFileName: 'messages.po',
  domain: 'coder-dojo-platform'
});
var sanitizeHtml = require('sanitize-html');
/**
 * Send a customized email to a specified list of members
 * @param  {Array}    userIds   List of users to contact
 * @param  {Object}   data      Object containing subject and content of the email
 */
module.exports = function (args, done) {
  var seneca = this;
  var so = seneca.options;
  var plugin = args.role;
  var dest = args.userIds;
  var payload = args.data;
  var dojoId = args.dojoId;
  payload.bypassTranslation = true;
  payload.content = {content: sanitizeHtml(payload.content, so.sanitizeTextArea)};
  payload.code = 'notify-empty-';
  async.waterfall([
    function getDojoData (wfCb) {
      seneca.act({role: plugin, cmd: 'load', id: dojoId}, function (err, dojo) {
        if (err) return done(err);
        payload.from = dojo.email;
        payload.replyTo = dojo.email;
        payload.locality = args.locality || 'en_US';
        payload.content.dojoName = dojo.name;
        return wfCb(null, dojo);
      });
    },
    function getDojoUsers (dojo, wfCb) {
      seneca.act({role: plugin, cmd: 'load_dojo_users', dojoId: dojoId}, function (err, usersDojo) {
        if (err) return done(err);
        return wfCb(null, dojo, usersDojo);
      });
    },
    function getUsersData (dojo, usersDojo, wfCb) {
      seneca.act({role: 'cd-profiles', cmd: 'search', query: {userId: {in$: dest}}},
        function (err, profiles) {
          if (err) return done(err);
          return wfCb(null, dojo, usersDojo, profiles);
        });
    },
    // We cannot optimize to only 1 profiles loop as we need to aggregate parents profile (multiple kids)
    function getParentsData (dojo, usersDojo, profiles, wfCb) {
      var userDojoIds = _.map(usersDojo.response, 'userId');
      var parents = {};
      async.map(profiles, function (profile, mCb) {
        if (profile.parents) {
          async.eachSeries(profile.parents, function (parentUserId, eCb) {<commit_msg>Fix faulty query which wasn't filtering anything<commit_after>var _ = require('lodash');
var async = require('async');
var path = require('path');
var I18NHelper = require('cp-i18n-lib');
var i18nHelper = new I18NHelper({
  poFilePath: path.resolve('web/locale/'),
  poFileName: 'messages.po',
  domain: 'coder-dojo-platform'
});
var sanitizeHtml = require('sanitize-html');
/**
 * Send a customized email to a specified list of members
 * @param  {Array}    userIds   List of users to contact
 * @param  {Object}   data      Object containing subject and content of the email
 */
module.exports = function (args, done) {
  var seneca = this;
  var so = seneca.options;
  var plugin = args.role;
  var dest = args.userIds;
  var payload = args.data;
  var dojoId = args.dojoId;
  payload.bypassTranslation = true;
  payload.content = {content: sanitizeHtml(payload.content, so.sanitizeTextArea)};
  payload.code = 'notify-empty-';
  async.waterfall([
    function getDojoData (wfCb) {
      seneca.act({role: plugin, cmd: 'load', id: dojoId}, function (err, dojo) {
        if (err) return done(err);
        payload.from = dojo.email;
        payload.replyTo = dojo.email;
        payload.locality = args.locality || 'en_US';
        payload.content.dojoName = dojo.name;
        return wfCb(null, dojo);
      });
    },
    function getDojoUsers (dojo, wfCb) {
      seneca.act({role: plugin, cmd: 'load_dojo_users', query: { dojoId: dojoId }}, function (err, usersDojo) {
        if (err) return done(err);
        return wfCb(null, dojo, usersDojo);
      });
    },
    function getUsersData (dojo, usersDojo, wfCb) {
      seneca.act({role: 'cd-profiles', cmd: 'search', query: {userId: {in$: dest}}},
        function (err, profiles) {
          if (err) return done(err);
          return wfCb(null, dojo, usersDojo, profiles);
        });
    },
    // We cannot optimize to only 1 profiles loop as we need to aggregate parents profile (multiple kids)
    function getParentsData (dojo, usersDojo, profiles, wfCb) {
      var userDojoIds = _.map(usersDojo.response, 'userId');
      var parents = {};
      async.map(profiles, function (profile, mCb) {
        if (profile.parents) {
          async.eachSeries(profile.parents, function (parentUserId, eCb) {
{'fraction_non_alphanumeric': 0.13452115812917595, 'fraction_numerical': 0.004008908685968819, 'mean_word_length': 3.173791821561338, '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': '4118757', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1465, 'n_words': 403}