Vulcan/packages/nova-users/lib/server/publications.js

53 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-02-17 12:54:18 +09:00
/**
* @summary Publish a single user
2016-02-17 12:54:18 +09:00
* @param {String} idOrSlug
*/
2016-02-23 11:34:40 +09:00
Meteor.publish('users.single', function (terms) {
2016-02-17 12:54:18 +09:00
var idOrSlug = terms._id || terms['telescope.slug'];
var findById = Meteor.users.findOne(idOrSlug);
var findBySlug = Meteor.users.findOne({"telescope.slug": idOrSlug});
var user = typeof findById !== 'undefined' ? findById : findBySlug;
2016-02-17 12:54:18 +09:00
var options = Users.is.adminById(this.userId) ? {} : {fields: Users.publishedFields.public};
2016-01-02 18:40:49 +01:00
2016-02-17 12:54:18 +09:00
return user ? Meteor.users.find({_id: user._id}, options) : [];
});
2016-02-17 12:54:18 +09:00
/**
* @summary Publish the current user
2016-02-17 12:54:18 +09:00
*/
Meteor.publish('users.current', function () {
const user = Meteor.users.find({_id: this.userId}, {fields: {'services.password.bcrypt': false}});
return user || [];
2014-12-08 14:53:26 +09:00
});
2016-02-17 12:54:18 +09:00
// // publish all users for admins to make autocomplete work
// // TODO: find a better way
2016-01-02 18:40:49 +01:00
2016-02-17 12:54:18 +09:00
// Meteor.publish('allUsersAdmin', function() {
2016-01-02 18:40:49 +01:00
2016-02-17 17:46:34 +09:00
//
2016-02-17 12:54:18 +09:00
// var selector = Settings.get('requirePostInvite') ? {isInvited: true} : {}; // only users that can post
// if (Users.is.adminById(this.userId)) {
// return Meteor.users.find(selector, {fields: Users.pubsub.avatarProperties});
// }
// return [];
// });
2016-02-17 12:54:18 +09:00
// // 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
2016-01-02 18:40:49 +01:00
2016-02-17 12:54:18 +09:00
// ReactiveTable.publish("all-users", function() {
2016-01-02 18:40:49 +01:00
2016-02-17 17:46:34 +09:00
//
2016-01-02 18:40:49 +01:00
2016-02-17 12:54:18 +09:00
// if(Users.is.adminById(this.userId)){
// return Meteor.users;
// } else {
// return [];
// }
// });