소스 검색

Commit 7-7: Enforce post URL uniqueness.

Frederic G. MARAND 9 년 전
부모
커밋
45bb8d2a61
2개의 변경된 파일13개의 추가작업 그리고 0개의 파일을 삭제
  1. 3 0
      client/templates/posts/post_submit.js
  2. 10 0
      lib/collections/posts.js

+ 3 - 0
client/templates/posts/post_submit.js

@@ -21,6 +21,9 @@ Template.postSubmit.events({
       if (error) {
         return alert(error);
       }
+      if (result.postExists) {
+        alert("This link has already been posted");
+      }
 
       Router.go('postPage', { _id: result._id });
     });

+ 10 - 0
lib/collections/posts.js

@@ -20,6 +20,16 @@ Meteor.methods({
       title: String,
       url: String
     });
+
+    var postWithSameLink = Posts.findOne({ url: postAttributes.url });
+    if (postWithSameLink) {
+      // Return to skip the insert.
+      return {
+        postExists: true,
+        _id: postWithSameLink._id
+      }
+    }
+
     var user = Meteor.user();
     var post = _.extend(postAttributes, {
       userId: user._id,