<commit_before>// Fill infractions block info
//
'use strict';


const _ = require('lodash');


module.exports = function (N) {

  // Fill infractions
  //
  N.wire.after('server:users.member', function* fill_infractions(env) {
    let can_see_infractions = yield env.extras.settings.fetch('can_see_infractions');

    // Allow if permitted and if owner
    if (!can_see_infractions && String(env.data.user._id) !== env.user_info.user_id) return;

    let infractions = yield N.models.users.Infraction.find()
                                .where('for').equals(env.data.user._id)
                                .where('exists').equals(true)
                                .sort({ ts: -1 })
                                .lean(true);

    // Hide infractions older than half year for owner
    if (!can_see_infractions) {
      let hide = Date.now() - 6 * 30 * 24 * 60 * 60 * 1000;

      infractions = infractions.filter(infraction => {
        if (!infraction.expire) return true;
        return infraction.expire > hide;
      });
    }

    let users_mod_can_add_infractions = yield env.extras.settings.fetch('users_mod_can_add_infractions');

    let params = {
      user_id: env.data.user._id,
      usergroup_ids: env.data.user.usergroups
    };
    let can_receive_infractions = yield N.settings.get('can_receive_infractions', params, {});

    let data = {
      list: infractions,
      settings: {
        users_mod_can_add_infractions,
        can_receive_infractions
      },
      urls: {}
    };

    // Subcall to fill urls to content (forum posts, blog entries, etc.)
    yield N.wire.emit('internal:users.infractions.fill_content_urls', data);


    // Fetch moderators info
    //
    env.data.users = env.data.users || [];
    infractions.forEach(i => env.data.users.push(i.from));


    if (infractions.length || (users_mod_can_add_infractions && can_receive_infractions)) {
      _.set(env.res, 'blocks.infractions', data);
    }
  });
};
<commit_msg>Infractions: fetch urls by more universal way<commit_after>// Fill infractions block info
//
'use strict';


const _ = require('lodash');
const userInfo = require('nodeca.users/lib/user_info');


module.exports = function (N) {

  // Fill infractions
  //
  N.wire.after('server:users.member', function* fill_infractions(env) {
    let can_see_infractions = yield env.extras.settings.fetch('can_see_infractions');

    // Allow if permitted and if owner
    if (!can_see_infractions && String(env.data.user._id) !== env.user_info.user_id) return;

    let infractions = yield N.models.users.Infraction.find()
                                .where('for').equals(env.data.user._id)
                                .where('exists').equals(true)
                                .sort({ ts: -1 })
                                .lean(true);


    // Hide infractions older than half year for owner
    //
    if (!can_see_infractions) {
      let hide = Date.now() - 6 * 30 * 24 * 60 * 60 * 1000;

      infractions = infractions.filter(infraction => {
        if (!infraction.expire) return true;
        return infraction.expire > hide;
      });
    }


    // Subcall to fill urls to content (forum posts, blog entries, etc.)
    //
    let user_info = yield userInfo(N, env.data.user._id);
    let params = { items: infractions.map(i => ({ id: i.src_id, type: i.src_type })), user_info };

    yield N.wire.emit('internal:common.fill_content_urls', params);


    // Fetch moderators info
    //
    env.data.users = env.data.users || [];
    infractions.forEach(i => env.data.users.push(i.from));


    // Fetch settings
    //
    let users_mod_can_add_infractions = yield env.extras.settings.fetch('users_mod_can_add_infractions');
    let can_receive_infractions = yield N.settings.get('can_receive_infractions', {
      user_id: env.data.user._id,
      usergroup_ids: env.data.user.usergroups
    }, {});


    if (infractions.length || (users_mod_can_add_infractions && can_receive_infractions)) {
      _.set(env.res, 'blocks.infractions', {
        list: infractions,
        settings: {
          users_mod_can_add_infractions,
          can_receive_infractions
        },
        urls: params.urls || {}
      });
    }
  });
};

{'fraction_non_alphanumeric': 0.13080568720379146, 'fraction_numerical': 0.006635071090047393, 'mean_word_length': 2.3903614457831326, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '2555422', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1293, 'n_words': 262}