<commit_before>// *******************************
// Transactions manager for Meteor
// by <NAME>
// <EMAIL>
// MIT Licence 2015
// *******************************
  
// This package adds one new mongo collection to your app
// It is exposed to the app via `tx.Transactions`, not via `Transactions`
// In much the same way that we have `Meteor.users` rather than `Users`

Transactions = new Mongo.Collection("transactions");

if (Meteor.isServer) {
  Transactions.allow({
    insert: function(userId, doc) { return (_.has(doc,"items") || doc.user_id !== userId) ? false : true; },
    update: function(userId, doc, fields, modifier) { 
      if (userId !== doc.user_id) {
        // TODO -- this condition will need to be modified to allow an admin to look through transactions and undo/redo them from the client
        // That said, an admin interface shouldn't really be messing with the transactions collection from the client anyway, so ignoring this for now
        return false;
      }
      else {
        if (tx._validateModifier(modifier,doc._id)) {
          return true;
        }
        else {
          Transactions.remove({_id:doc._id});
          return false; 
        }
      }
    },
    remove: function(userId, doc) {
      var fullDoc = Transactions.findOne({_id:doc._id});
      return fullDoc && fullDoc.user_id === userId;
    }
  });
}

Transact = function() {
  
  // ************************************************************************************************************
  // YOU CAN OPTINALLY OVERWRITE tx.collectionIndex TO MAKE THE TRANSACTIONS WORK FOR CERTAIN COLLECTIONS ONLY
  // ************************************************************************************************************
  
  // e.g. in a file shared by client and server, write:
  // tx.collectionIndex = {posts:Posts,comments:Comments, etc...}
  // where the key is the name of the database collection (e.g. 'posts') and the value is the actual Meteor Mongo.Collection object (e.g. Posts)
  // by default, all collections are added to tx.collectionIndex on startup in a "Meteor.startup(function(){ Meteor.defer(function() { ..." block
  // so if you are planning to overwrite tx.collectionIndex, you'll also need to wrap your code in "Meteor.startup(function(){ Meteor.defer(function() { ..." block
  // there's no real need to do this for most applications though
  
  this.collectionIndex = {};
  
  // ***********************************************************************************************  <commit_msg>Don't remove transactions that aren't validated on client updates<commit_after>// *******************************
// Transactions manager for Meteor
// by <NAME>
// <EMAIL>
// MIT Licence 2015
// *******************************
  
// This package adds one new mongo collection to your app
// It is exposed to the app via `tx.Transactions`, not via `Transactions`
// In much the same way that we have `Meteor.users` rather than `Users`

Transactions = new Mongo.Collection("transactions");

if (Meteor.isServer) {
  Transactions.allow({
    insert: function(userId, doc) { return (_.has(doc,"items") || doc.user_id !== userId) ? false : true; },
    update: function(userId, doc, fields, modifier) { 
      if (userId !== doc.user_id) {
        // TODO -- this condition will need to be modified to allow an admin to look through transactions and undo/redo them from the client
        // That said, an admin interface shouldn't really be messing with the transactions collection from the client anyway, so ignoring this for now
        return false;
      }
      else {
        if (tx._validateModifier(modifier,doc._id)) {
          return true;
        }
        else {
          // Transactions.remove({_id:doc._id});
          return false; 
        }
      }
    },
    remove: function(userId, doc) {
      var fullDoc = Transactions.findOne({_id:doc._id});
      return fullDoc && fullDoc.user_id === userId;
    }
  });
}

Transact = function() {
  
  // ************************************************************************************************************
  // YOU CAN OPTINALLY OVERWRITE tx.collectionIndex TO MAKE THE TRANSACTIONS WORK FOR CERTAIN COLLECTIONS ONLY
  // ************************************************************************************************************
  
  // e.g. in a file shared by client and server, write:
  // tx.collectionIndex = {posts:Posts,comments:Comments, etc...}
  // where the key is the name of the database collection (e.g. 'posts') and the value is the actual Meteor Mongo.Collection object (e.g. Posts)
  // by default, all collections are added to tx.collectionIndex on startup in a "Meteor.startup(function(){ Meteor.defer(function() { ..." block
  // so if you are planning to overwrite tx.collectionIndex, you'll also need to wrap your code in "Meteor.startup(function(){ Meteor.defer(function() { ..." block
  // there's no real need to do this for most applications though
  
  this.collectionIndex = {};
  
  // ***********************************************************************************************  
{'fraction_non_alphanumeric': 0.24202075582533777, 'fraction_numerical': 0.0015664773839827687, 'mean_word_length': 3.4728546409807355, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5599454', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1281, 'n_words': 468}