Parcourir la source

Step 11.10: Add extra security to methods.

Frederic G. MARAND il y a 8 ans
Parent
commit
5fcc946853
1 fichiers modifiés avec 10 ajouts et 4 suppressions
  1. 10 4
      simple-todos-react.jsx

+ 10 - 4
simple-todos-react.jsx

@@ -42,14 +42,20 @@ Meteor.methods({
   },
 
   removeTask(taskId) {
-    // Without checking user ?
-    Meteor._debug("removing", taskId);
+    const task = Tasks.find(taskId);
+    if (task.private && task.owner !== Meteor.userId) {
+      throw new Meteor.Error("not-authorized");
+    }
+
     Tasks.remove(taskId);
   },
 
   setChecked(taskId, setChecked) {
-    // Without checking user ?
-    Meteor._debug("setCheck", taskId, setChecked);
+    const task = Tasks.find(taskId);
+
+    if (task.private && task.owner != Meteor.userId) {
+      throw new Meteor.Error("not-authorized");
+    }
     Tasks.update(taskId, { $set: { checked: setChecked }});
   },