Skip to content

Commit

Permalink
owners can write to some fields
Browse files Browse the repository at this point in the history
  • Loading branch information
gschmidt committed Oct 16, 2012
1 parent 8d46cae commit 0c9268c
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions examples/parties/model.js
Expand Up @@ -14,10 +14,24 @@ Parties.allow({
return false; // use createParty method instead
},
update: function (userId, parties, fields, modifier) {
return false; // use rsvp method instead
return _.all(parties, function (party) {
if (userId !== party.owner)
return false; // not the owner
var allowed = ["title", "description", "x", "y"];
if (_.difference(fields, allowed).length)
return false; // tried to write to forbidden field

// XXX validate that they keep the right types, and don't write
// stupidly long strings to the database. since all we have is a
// modifier that take a little logic.

return true;
});
},
remove: function (userId, parties) {
return true; // deny is called later
return ! _.any(parties, function (party) {
return party.owner !== userId || attending(party) > 0;
});
}
});

Expand All @@ -30,14 +44,6 @@ var attending = function (party) {
}, 0);
};

Parties.deny({
remove: function (userId, parties) {
return _.any(parties, function (party) {
return party.owner !== userId || attending(party) > 0;
});
}
});

var displayName = function (user) {
if (user.profile && user.profile.name)
return user.profile.name;
Expand Down

0 comments on commit 0c9268c

Please sign in to comment.