<commit_before>/**
 * This middleware will validate if a user has a high enough user role to perform a task. The passed in role is
 * the required role and the required role is compaired to the user's role that is in the kontx.
 * @param role
 * @returns {Function}
 */
module.exports = function(role){
    'use strict';

    var _ = require('underscore'),
        roles = require('../security/roles'),
        Strings = require('../strings'),
        strings = new Strings('en');

    if(!_.isNumber(role)){
        role = roles[role.toUpperCase()];
    }

    return function validateRole(kontx, next){
        var userPrivLevel = roles[kontx.user.role.toUpperCase()],
            err = new Error(strings.group('errors').user_privileges_exceeded);

        err.errorCode = strings.group('codes').forbidden;

        //If user has enough priviliges then keep going
        if (userPrivLevel <= parseInt(role, 10)){<commit_msg>Updated how the errors were sent back through our central module.<commit_after>/**
 * This middleware will validate if a user has a high enough user role to perform a task. The passed in role is
 * the required role and the required role is compaired to the user's role that is in the kontx.
 * @param role
 * @returns {Function}
 */
module.exports = function(role){
    'use strict';

    var _ = require('underscore'),
        roles = require('../security/roles'),
        Strings = require('../strings'),
        strings = new Strings(),
        createError = require('../utils/error');

    if(!_.isNumber(role)){
        role = roles[role.toUpperCase()];
    }

    return function validateRole(kontx, next){
        var userPrivLevel = roles[kontx.user.role.toUpperCase()],
            err = createError(strings.group('codes').forbidden, strings.group('errors').user_privileges_exceeded);

        //If user has enough priviliges then keep going
        if (userPrivLevel <= parseInt(role, 10)){
{'fraction_non_alphanumeric': 0.1229253112033195, 'fraction_numerical': 0.002074688796680498, 'mean_word_length': 3.052521008403361, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4786235', 'n_tokens_mistral': 545, 'n_tokens_neox': 531, 'n_words': 179}