<commit_before>Posts = new Mongo.Collection('posts');

Posts.allow({
    update: function (userId, post) { return ownsDocument(userId, post); },
    remove: function (userId, post) { return ownsDocument(userId, post); }
});

/**
 * The deny update callback, verifies only url or title are being modified,
 * else prevents the update action from occurring.
 *
 *  (using underscore, without returns the difference of fieldNames and the
 *  listed fields, in an array. If there are fields remaining (length > 0),
 *  the deny returns true, meaning to deny the operation request.
 */
Posts.deny({
    update: function (userId, post, fieldNames) {
        return (_.without(fieldNames, 'url', 'title').length > 0);
    }
});

Meteor.methods({
    postInsert: function (postAttributes) {
        check(Meteor.userId(), String);
        check(postAttributes, {
            title: String,
            url: String
        });

        var postWithSameLink = Posts.findOne({ url: postAttributes.url });
        if (postWithSameLink) {
            return {
                postExists: true,
                _id: postWithSameLink._id
            }
        }

        var user = Meteor.user();
        var post = _.extend(postAttributes, {
            userId: user._id,
            author: user.username,<commit_msg>server side post submit validation<commit_after>Posts = new Mongo.Collection('posts');

Posts.allow({
    update: function (userId, post) { return ownsDocument(userId, post); },
    remove: function (userId, post) { return ownsDocument(userId, post); }
});

/**
 * The deny update callback, verifies only url or title are being modified,
 * else prevents the update action from occurring.
 *
 *  (using underscore, without returns the difference of fieldNames and the
 *  listed fields, in an array. If there are fields remaining (length > 0),
 *  the deny returns true, meaning to deny the operation request.
 */
Posts.deny({
    update: function (userId, post, fieldNames) {
        return (_.without(fieldNames, 'url', 'title').length > 0);
    }
});

Meteor.methods({
    postInsert: function (postAttributes) {
        check(Meteor.userId(), String);
        check(postAttributes, {
            title: String,
            url: String
        });

        var errors = validatePost(postAttributes);
        if (errors.title || errors.url) {
            throw new Meteor.Error('invalid-post', "You must set a title and URL for your post");
        }

        var postWithSameLink = Posts.findOne({ url: postAttributes.url });
        if (postWithSameLink) {
            return {
                postExists: true,
                _id: postWithSameLink._id
            }
        }

        var user = Meteor.user();
        var post = _.extend(postAttributes, {
            userId: user._id,
            author: user.username,
{'fraction_non_alphanumeric': 0.11091487107029319, 'fraction_numerical': 0.001412928293889085, 'mean_word_length': 2.474846625766871, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2849477', 'n_tokens_mistral': 773, 'n_tokens_neox': 756, 'n_words': 248}