Vulcan/server/publish.js

104 lines
2.3 KiB
JavaScript
Raw Normal View History

2012-09-06 15:28:58 +09:00
// Users
Meteor.publish('users', function() {
return Meteor.users.find({}, {fields: {emails: false}});
});
2012-08-22 23:24:33 -04:00
// Posts
2012-08-22 21:27:22 -04:00
Posts = new Meteor.Collection('posts');
Meteor.publish('posts', function() {
2012-09-11 15:32:25 +10:00
return Posts.find({}, {sort: {score: -1}});
2012-08-22 21:27:22 -04:00
});
2012-08-22 23:24:33 -04:00
2012-09-11 18:52:01 +10:00
// FIXME -- check all docs, not just the first one.
2012-08-22 23:24:33 -04:00
Meteor.startup(function(){
Posts.allow({
2012-09-06 15:28:58 +09:00
insert: function(userId, doc){
console.log(userId);
if(userId){
2012-09-11 18:52:01 +10:00
doc.userId = userId;
2012-09-06 15:28:58 +09:00
return true;
}
return false;
2012-09-06 11:34:05 +09:00
}
2012-09-06 11:09:24 +09:00
, update: function(userId, docs, fields, modifier){
2012-09-11 18:52:01 +10:00
console.log("Document's user: "+docs[0].userId+" | Current user: "+userId);
if(docs[0].userId && docs[0].userId==userId){
2012-09-06 11:09:24 +09:00
return true;
}
return false;
}
2012-09-06 11:34:05 +09:00
, remove: function(userId, docs){
2012-09-11 18:52:01 +10:00
if(docs[0].userId && docs[0].userId==userId){
2012-09-06 11:34:05 +09:00
return true;
}
return false; }
2012-08-22 23:24:33 -04:00
});
});
// Comments
Comments = new Meteor.Collection('comments');
Meteor.publish('comments', function() {
return Comments.find();
});
Meteor.startup(function(){
Comments.allow({
2012-09-06 15:28:58 +09:00
insert: function(userId, doc){
console.log(userId);
if(userId){
return true;
}
return false;
2012-09-06 11:34:05 +09:00
}
, update: function(userId, docs, fields, modifier){
console.log("Document's user: "+docs[0].user_id+" | Current user: "+userId);
if(docs[0].user_id && docs[0].user_id==userId){
return true;
}
return false;
}
, remove: function(userId, docs){
if(docs[0].user_id && docs[0].user_id==userId){
return true;
}
return false;
}
2012-08-30 21:35:48 -04:00
});
});
// MyVotes
MyVotes = new Meteor.Collection('myvotes');
Meteor.publish('myvotes', function() {
return MyVotes.find();
});
Meteor.startup(function(){
MyVotes.allow({
insert: function(){ return false; }
, update: function(){ return false; }
, remove: function(){ return false; }
2012-08-22 23:24:33 -04:00
});
});
2012-09-06 11:34:05 +09:00
2012-09-06 19:42:11 +09:00
// Settings
2012-09-06 11:34:05 +09:00
2012-09-06 19:42:11 +09:00
Settings = new Meteor.Collection('settings');
2012-09-06 11:34:05 +09:00
2012-09-06 19:42:11 +09:00
Meteor.publish('settings', function() {
return Settings.find();
2012-09-06 11:34:05 +09:00
});
Meteor.startup(function(){
2012-09-06 19:42:11 +09:00
Settings.allow({
insert: function(){ return true; }
, update: function(){ return true; }
, remove: function(){ return true; }
2012-09-06 11:34:05 +09:00
});
});