<commit_before>const models = require('../../models');
const common = require('../../lib/common');
const mega = require('../../services/mega');

module.exports = {
    docName: 'email_preview',

    read: {
        options: [
            'fields'
        ],
        validation: {
            options: {
                fields: ['html', 'plaintext', 'subject']
            }
        },
        data: [
            'id',
            'status'
        ],
        permissions: true,
        query(frame) {
            const options = Object.assign(frame.options, {formats: 'html,plaintext'});
            return models.Post.findOne(frame.data, options)
                .then((model) => {
                    if (!model) {
                        throw new common.errors.NotFoundError({
                            message: common.i18n.t('errors.api.posts.postNotFound')
                        });
                    }

                    const post = model.toJSON(options);

                    return mega.postEmailSerializer.serialize(post);
                });
        }
    },
    sendTestEmail: {
        statusCode: 200,
        headers: {},
        options: [
            'id'
        ],
        validation: {
            options: {
                id: {
                    required: true
                }
            }
        },
        permissions: false,
        async query(frame) {
            let model = await models.Post.findOne(frame.options);
            if (!model) {
                throw new common.errors.NotFoundError({
                    message: common.i18n.t('errors.api.posts.postNotFound')
                });
            }
            const post = model.toJSON();
            const {emails = []} = frame.data;
            return mega.mega.sendTestEmail(post, emails);
        }<commit_msg>Fixed permission for test email API<commit_after>const models = require('../../models');
const common = require('../../lib/common');
const mega = require('../../services/mega');

module.exports = {
    docName: 'email_preview',

    read: {
        options: [
            'fields'
        ],
        validation: {
            options: {
                fields: ['html', 'plaintext', 'subject']
            }
        },
        data: [
            'id',
            'status'
        ],
        permissions: true,
        query(frame) {
            const options = Object.assign(frame.options, {formats: 'html,plaintext'});
            return models.Post.findOne(frame.data, options)
                .then((model) => {
                    if (!model) {
                        throw new common.errors.NotFoundError({
                            message: common.i18n.t('errors.api.posts.postNotFound')
                        });
                    }

                    const post = model.toJSON(options);

                    return mega.postEmailSerializer.serialize(post);
                });
        }
    },
    sendTestEmail: {
        statusCode: 200,
        headers: {},
        options: [
            'id'
        ],
        validation: {
            options: {
                id: {
                    required: true
                }
            }
        },
        permissions: true,
        async query(frame) {
            let model = await models.Post.findOne(frame.options);
            if (!model) {
                throw new common.errors.NotFoundError({
                    message: common.i18n.t('errors.api.posts.postNotFound')
                });
            }
            const post = model.toJSON();
            const {emails = []} = frame.data;
            return mega.mega.sendTestEmail(post, emails);
        }
{'fraction_non_alphanumeric': 0.12626400655916917, 'fraction_numerical': 0.0038261820169445205, 'mean_word_length': 1.165680473372781, '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': '4027590', 'n_tokens_mistral': 946, 'n_tokens_neox': 894, 'n_words': 171}