Skip to content

Commit

Permalink
Step 10.14: Changes in the method implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha authored and Dotan Simha committed Nov 22, 2016
1 parent 87a0c1d commit 957b736
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions imports/api/lists/methods.js
Expand Up @@ -14,7 +14,7 @@ export const insert = new ValidatedMethod({
name: 'lists.insert',
validate: new SimpleSchema({}).validator(),
run() {
return Lists.insert({});
return Lists.collection.insert({});
},
});

Expand All @@ -27,14 +27,14 @@ export const makePrivate = new ValidatedMethod({
'Must be logged in to make private lists.');
}

const list = Lists.findOne(listId);
const list = Lists.collection.findOne(listId);

if (list.isLastPublicList()) {
throw new Meteor.Error('lists.makePrivate.lastPublicList',
'Cannot make the last public list private.');
}

Lists.update(listId, {
Lists.collection.update(listId, {
$set: { userId: this.userId },
});
},
Expand All @@ -49,7 +49,7 @@ export const makePublic = new ValidatedMethod({
'Must be logged in.');
}

const list = Lists.findOne(listId);
const list = Lists.collection.findOne(listId);

if (!list.editableBy(this.userId)) {
throw new Meteor.Error('lists.makePublic.accessDenied',
Expand All @@ -58,7 +58,7 @@ export const makePublic = new ValidatedMethod({

// XXX the security check above is not atomic, so in theory a race condition could
// result in exposing private data
Lists.update(listId, {
Lists.collection.update(listId, {
$unset: { userId: true },
});
},
Expand All @@ -71,7 +71,7 @@ export const updateName = new ValidatedMethod({
newName: { type: String },
}).validator(),
run({ listId, newName }) {
const list = Lists.findOne(listId);
const list = Lists.collection.findOne(listId);

if (!list.editableBy(this.userId)) {
throw new Meteor.Error('lists.updateName.accessDenied',
Expand All @@ -81,7 +81,7 @@ export const updateName = new ValidatedMethod({
// XXX the security check above is not atomic, so in theory a race condition could
// result in exposing private data

Lists.update(listId, {
Lists.collection.update(listId, {
$set: { name: newName },
});
},
Expand All @@ -91,7 +91,7 @@ export const remove = new ValidatedMethod({
name: 'lists.remove',
validate: LIST_ID_ONLY,
run({ listId }) {
const list = Lists.findOne(listId);
const list = Lists.collection.findOne(listId);

if (!list.editableBy(this.userId)) {
throw new Meteor.Error('lists.remove.accessDenied',
Expand All @@ -106,7 +106,7 @@ export const remove = new ValidatedMethod({
'Cannot delete the last public list.');
}

Lists.remove(listId);
Lists.collection.remove(listId);
},
});

Expand Down

0 comments on commit 957b736

Please sign in to comment.