Skip to content

Instantly share code, notes, and snippets.

@dai-shi
Created March 28, 2016 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dai-shi/519b49f2da5d282bbb52 to your computer and use it in GitHub Desktop.
Save dai-shi/519b49f2da5d282bbb52 to your computer and use it in GitHub Desktop.
diff --git a/imports/api/tasks.js b/imports/api/tasks.js
index 441feee..9d5b56a 100644
--- a/imports/api/tasks.js
+++ b/imports/api/tasks.js
@@ -36,12 +36,24 @@ Meteor.methods({
'tasks.remove'(taskId) {
check(taskId, String);
+ const task = Tasks.findOne(taskId);
+ if (task.private && task.owner !== Meteor.userId()) {
+ // If the task is private, make sure only the owner can delete it
+ throw new Meteor.Error('not-authorized');
+ }
+
Tasks.remove(taskId);
},
'tasks.setChecked'(taskId, setChecked) {
check(taskId, String);
check(setChecked, Boolean);
+ const task = Tasks.findOne(taskId);
+ if (task.private && task.owner !== Meteor.userId()) {
+ // If the task is private, make sure only the owner can check it off
+ throw new Meteor.Error('not-authorized');
+ }
+
Tasks.update(taskId, { $set: { checked: setChecked } });
},
'tasks.setPrivate'(taskId, setToPrivate) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment