diff --git a/common/post.js b/common/post.js index 5fd5cfccf..222564d66 100644 --- a/common/post.js +++ b/common/post.js @@ -32,12 +32,15 @@ Meteor.methods({ throw new Meteor.Error(603, 'This link has already been posted', postWithSameLink._id); } - // check that user waits more than 30 seconds between posts - if(!this.isSimulation && timeSinceLastPost < postInterval) - throw new Meteor.Error(604, 'Please wait '+(postInterval-timeSinceLastPost)+' seconds before posting again'); + if(!isAdmin(Meteor.user())){ + // check that user waits more than X seconds between posts + if(!this.isSimulation && timeSinceLastPost < postInterval) + throw new Meteor.Error(604, 'Please wait '+(postInterval-timeSinceLastPost)+' seconds before posting again'); - if(!this.isSimulation && numberOfPostsInPast24Hours > maxPostsPer24Hours) - throw new Meteor.Error(605, 'Sorry, you cannot submit more than '+maxPostsPer24Hours+' posts per day'); + // check that the user doesn't post more than Y posts per day + if(!this.isSimulation && numberOfPostsInPast24Hours > maxPostsPer24Hours) + throw new Meteor.Error(605, 'Sorry, you cannot submit more than '+maxPostsPer24Hours+' posts per day'); + } post = _.extend(post, { headline: headline, diff --git a/common/users.js b/common/users.js index caa150779..42bd04999 100644 --- a/common/users.js +++ b/common/users.js @@ -49,20 +49,20 @@ userProfileComplete = function(user) { } findLast = function(user, collection){ - return collection.findOne({userId: user._id}, {sort: {submitted: -1}}); + return collection.findOne({userId: user._id}, {sort: {createdAt: -1}}); } timeSinceLast = function(user, collection){ var now = new Date().getTime(); var last = findLast(user, collection); if(!last) return 999; // if this is the user's first post or comment ever, stop here - return Math.abs(Math.floor((now-last.submitted)/1000)); + return Math.abs(Math.floor((now-last.createdAt)/1000)); } numberOfItemsInPast24Hours = function(user, collection){ var mDate = moment(new Date()); var items=collection.find({ userId: user._id, - submitted: { + createdAt: { $gte: mDate.subtract('hours',24).valueOf() } });