Vulcan/server/publish.js

130 lines
2.7 KiB
JavaScript
Raw Normal View History

2012-10-18 14:24:36 +09:00
Meteor.publish('currentUser', function() {
return Meteor.users.find(this.userId);
2012-10-18 14:24:36 +09:00
});
Meteor.publish('allUsers', function() {
if (this.userId && isAdminById(this.userId)) {
// if user is admin, publish all fields
return Meteor.users.find();
}else{
2012-10-18 14:24:36 +09:00
// else, filter out sensitive info
return Meteor.users.find({}, {fields: {
2012-10-08 10:44:13 +09:00
secret_id: false,
isAdmin: false,
emails: false,
notifications: false,
'profile.email': false,
'services.twitter.accessToken': false,
'services.twitter.accessTokenSecret': false,
'services.twitter.id': false,
'services.password': false
}});
}
2012-09-06 15:28:58 +09:00
});
2012-09-19 09:03:25 +09:00
Meteor.startup(function(){
Meteor.users.allow({
insert: function(userId, doc){
return true;
}
, update: function(userId, doc, fields, modifier){
return isAdminById(userId) || (doc._id && doc._id === userId);
2012-09-19 09:03:25 +09:00
}
, remove: function(userId, doc){
return isAdminById(userId) || (doc._id && doc._id === userId);
2012-09-19 09:03:25 +09:00
}
});
});
2012-08-22 23:24:33 -04:00
// Posts
2012-08-22 21:27:22 -04:00
Posts = new Meteor.Collection('posts');
// a single post, identified by id
Meteor.publish('post', function(id) {
return Posts.find(id);
});
Meteor.publish('paginatedPosts', function(find, options, limit) {
options = options || {};
options.limit = limit;
2013-03-14 19:44:15 -03:00
return Posts.find(find || {}, options);
});
2012-08-22 23:24:33 -04:00
Meteor.startup(function(){
Posts.allow({
insert: canPostById
, update: canEditById
, remove: canEditById
2012-08-22 23:24:33 -04:00
});
});
// Comments
Comments = new Meteor.Collection('comments');
Meteor.publish('comments', function(query) {
return Comments.find(query);
2012-08-22 23:24:33 -04:00
});
Meteor.startup(function(){
Comments.allow({
insert: canCommentById
, update: canEditById
, remove: canEditById
2012-08-30 21:35:48 -04: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: isAdminById
, update: isAdminById
, remove: isAdminById
2012-09-06 11:34:05 +09:00
});
});
// Notifications
Notifications = new Meteor.Collection('notifications');
Meteor.publish('notifications', function() {
// only publish notifications belonging to the current user
2012-11-19 15:41:44 +09:00
return Notifications.find({userId:this.userId});
});
Meteor.startup(function(){
Notifications.allow({
insert: function(userId, doc){
2013-03-19 15:06:34 +09:00
// new notifications can only be created via a Meteor method
return false;
}
, update: canEditById
, remove: canEditById
});
});
// Categories
Categories = new Meteor.Collection('categories');
Meteor.publish('categories', function() {
return Categories.find();
});
Meteor.startup(function(){
Categories.allow({
insert: isAdminById
, update: isAdminById
, remove: isAdminById
});
2012-09-06 11:34:05 +09:00
});