2014-12-08 17:25:11 +09:00
|
|
|
// accept either an ID or a slug
|
|
|
|
Meteor.publish('singleUser', function(idOrSlug) {
|
|
|
|
var findById = Meteor.users.findOne(idOrSlug);
|
2015-05-08 11:45:09 +09:00
|
|
|
var findBySlug = Meteor.users.findOne({"telescope.slug": idOrSlug});
|
2014-12-08 17:25:11 +09:00
|
|
|
var user = typeof findById !== 'undefined' ? findById : findBySlug;
|
2015-04-27 17:14:07 +09:00
|
|
|
var options = Users.is.adminById(this.userId) ? {} : {fields: Users.pubsub.publicProperties};
|
2014-12-31 10:38:07 +09:00
|
|
|
if (user) {
|
|
|
|
return Meteor.users.find({_id: user._id}, options);
|
|
|
|
}
|
|
|
|
return [];
|
2014-12-08 17:25:11 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
Meteor.publish('userPosts', function(terms) {
|
2015-04-20 13:57:37 +09:00
|
|
|
var parameters = Posts.getSubParams(terms);
|
2014-12-08 17:25:11 +09:00
|
|
|
var posts = Posts.find(parameters.find, parameters.options);
|
|
|
|
return posts;
|
|
|
|
});
|
|
|
|
|
|
|
|
Meteor.publish('userUpvotedPosts', function(terms) {
|
2015-04-20 13:57:37 +09:00
|
|
|
var parameters = Posts.getSubParams(terms);
|
2014-12-08 17:25:11 +09:00
|
|
|
var posts = Posts.find(parameters.find, parameters.options);
|
|
|
|
return posts;
|
|
|
|
});
|
2014-09-03 09:56:38 +09:00
|
|
|
|
2014-12-08 17:25:11 +09:00
|
|
|
Meteor.publish('userDownvotedPosts', function(terms) {
|
2015-04-20 13:57:37 +09:00
|
|
|
var parameters = Posts.getSubParams(terms);
|
2014-12-08 17:25:11 +09:00
|
|
|
var posts = Posts.find(parameters.find, parameters.options);
|
|
|
|
return posts;
|
2014-12-08 14:53:26 +09:00
|
|
|
});
|
|
|
|
|
2015-04-22 08:31:11 +09:00
|
|
|
// Publish the current user
|
|
|
|
|
|
|
|
Meteor.publish('currentUser', function() {
|
2015-04-27 09:55:29 +09:00
|
|
|
var user = Meteor.users.find({_id: this.userId}, {fields: Users.pubsub.hiddenProperties});
|
2015-04-22 08:31:11 +09:00
|
|
|
return user;
|
|
|
|
});
|
|
|
|
|
|
|
|
// publish all users for admins to make autocomplete work
|
|
|
|
// TODO: find a better way
|
|
|
|
|
|
|
|
Meteor.publish('allUsersAdmin', function() {
|
|
|
|
var selector = Settings.get('requirePostInvite') ? {isInvited: true} : {}; // only users that can post
|
2015-04-27 17:14:07 +09:00
|
|
|
if (Users.is.adminById(this.userId)) {
|
2015-04-22 08:31:11 +09:00
|
|
|
return Meteor.users.find(selector, {fields: {
|
|
|
|
_id: true,
|
|
|
|
profile: true,
|
|
|
|
slug: true
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
});
|
|
|
|
|
|
|
|
// Publish all users to reactive-table (if admin)
|
|
|
|
// Limit, filter, and sort handled by reactive-table.
|
|
|
|
// https://github.com/aslagle/reactive-table#server-side-pagination-and-filtering-beta
|
|
|
|
|
|
|
|
ReactiveTable.publish("all-users", function() {
|
2015-04-27 17:14:07 +09:00
|
|
|
if(Users.is.adminById(this.userId)){
|
2015-04-22 08:31:11 +09:00
|
|
|
return Meteor.users;
|
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
});
|