| 
														
															@@ -1,17 +1,6 @@ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-/** 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- * @file 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- * 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- * 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- * User: marand 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- * Date: 30/08/15 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- * Time: 10:48 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- */ 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 // Not a "var", to make it global. 
														 | 
														
														 | 
														
															 // Not a "var", to make it global. 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 Posts = new Mongo.Collection('posts'); 
														 | 
														
														 | 
														
															 Posts = new Mongo.Collection('posts'); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															-// Removed Posts.allow : we no longer trigger inserts from client. 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 Posts.allow({ 
														 | 
														
														 | 
														
															 Posts.allow({ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   update: function (userId, post) { 
														 | 
														
														 | 
														
															   update: function (userId, post) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     return ownsDocument(userId, post); 
														 | 
														
														 | 
														
															     return ownsDocument(userId, post); 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -24,6 +13,7 @@ Posts.allow({ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 Posts.deny({ 
														 | 
														
														 | 
														
															 Posts.deny({ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   update: function (userId, post, fieldNames) { 
														 | 
														
														 | 
														
															   update: function (userId, post, fieldNames) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     // _.without() is like PHP array_diff($source, ...$keys). 
														 | 
														
														 | 
														
															     // _.without() is like PHP array_diff($source, ...$keys). 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    // May only edit the following two fields: 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     return (_.without(fieldNames, "url", "title").length > 0); 
														 | 
														
														 | 
														
															     return (_.without(fieldNames, "url", "title").length > 0); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   } 
														 | 
														
														 | 
														
															   } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 }); 
														 | 
														
														 | 
														
															 }); 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -38,11 +28,23 @@ Posts.deny({ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   } 
														 | 
														
														 | 
														
															   } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 }); 
														 | 
														
														 | 
														
															 }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+validatePost = function (post) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  var errors = {}; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  if (!post.title) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    errors.title = "Please fill in a headline"; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  if (!post.url) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    errors.url = "Please fill in a URL"; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  return errors; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+}; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 // This is in lib/ instead of server/ for latency compensation. 
														 | 
														
														 | 
														
															 // This is in lib/ instead of server/ for latency compensation. 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 Meteor.methods({ 
														 | 
														
														 | 
														
															 Meteor.methods({ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   postInsert: function(postAttributes) { 
														 | 
														
														 | 
														
															   postInsert: function(postAttributes) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     "use strict"; 
														 | 
														
														 | 
														
															     "use strict"; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    check(Meteor.userId(), String); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    check(this.userId, String); // Or Meteor.userId() ? 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     check(postAttributes, { 
														 | 
														
														 | 
														
															     check(postAttributes, { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       title: String, 
														 | 
														
														 | 
														
															       title: String, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       url: String 
														 | 
														
														 | 
														
															       url: String 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -70,21 +72,11 @@ Meteor.methods({ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       submitted: new Date(), 
														 | 
														
														 | 
														
															       submitted: new Date(), 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       commentsCount: 0 
														 | 
														
														 | 
														
															       commentsCount: 0 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     }); 
														 | 
														
														 | 
														
															     }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     var postId =  Posts.insert(post); 
														 | 
														
														 | 
														
															     var postId =  Posts.insert(post); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     return { 
														 | 
														
														 | 
														
															     return { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       _id: postId 
														 | 
														
														 | 
														
															       _id: postId 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     }; 
														 | 
														
														 | 
														
															     }; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   } 
														 | 
														
														 | 
														
															   } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 }); 
														 | 
														
														 | 
														
															 }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-validatePost = function (post) { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  var errors = {}; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  if (!post.title) { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    errors.title = "Please fill in a headline"; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  } 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  if (!post.url) { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    errors.url = "Please fill in a URL"; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  } 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  return errors; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-}; 
														 | 
														
														 | 
														
															 
														 |