<commit_before>var dpdSync = require('dpd-sync');
var user = requireApp('user.js');

var self = this;

var processFn = function () {
    if (!user.isAuthorized(me, 'languages', 'U'))
        cancel('access denied', 500);

    var matched = dpdSync.call(dpd.languages.get, { code: self.code, id: { $nin: [self.id] } });
    if (matched.length > 0)
        cancel('language code already exists', 400);

    emit('languageUpdated', self);
};

dpdSync.wrap(processFn);<commit_msg>language active and default validation<commit_after>var dpdSync = require('dpd-sync');
var user = requireApp('user.js');

var self = this;

var processFn = function () {
    if (!user.isAuthorized(me, 'languages', 'U'))
        cancel('access denied', 500);

    if (changed('code')) {
        var matched = dpdSync.call(dpd.languages.get, { code: self.code, id: { $nin: [self.id] } });
        if (matched.length > 0)
            cancel('language code already exists', 400);
    }

    if (changed('active')) {
        if(!self.active && self.default)
            error('active', 'cannot inactivate while default');
    }

    if (changed('default')) {
        if (!self.default) {
            var defaults = dpdSync.call(dpd.languages.get, { active: true, 'default': true, id: { $nin: [self.id] } });
            if (defaults.length === 0)
                error('default', 'cannot set to false as there are no other active default languages');
        }
    }

    emit('languageUpdated', self);
};

dpdSync.wrap(processFn);
{'fraction_non_alphanumeric': 0.16711051930758988, 'fraction_numerical': 0.009986684420772303, 'mean_word_length': 2.986737400530504, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1538602', 'n_tokens_mistral': 491, 'n_tokens_neox': 466, 'n_words': 122}