mirror of
https://github.com/vale981/Vulcan
synced 2025-03-09 12:16:37 -04:00
113 lines
2.7 KiB
JavaScript
113 lines
2.7 KiB
JavaScript
![]() |
////////////////////////////////////
|
||
|
// Publications and Subscriptions //
|
||
|
////////////////////////////////////
|
||
|
|
||
|
/**
|
||
|
* Users pub/sub configs and methods
|
||
|
* @namespace Users.pubsub
|
||
|
*/
|
||
|
Users.pubsub = {};
|
||
|
|
||
|
/**
|
||
|
* Default user object fields in publication
|
||
|
* @type {Object}
|
||
|
*/
|
||
|
Users.pubsub.privacyOptions = { // true means exposed
|
||
|
_id: true,
|
||
|
commentCount: true,
|
||
|
createdAt: true,
|
||
|
email_hash: true,
|
||
|
isInvited: true,
|
||
|
karma: true,
|
||
|
postCount: true,
|
||
|
slug: true,
|
||
|
username: true,
|
||
|
'profile.username': true,
|
||
|
'profile.notifications': true,
|
||
|
'profile.bio': true,
|
||
|
'profile.github': true,
|
||
|
'profile.site': true,
|
||
|
'profile.twitter': true,
|
||
|
'services.twitter.profile_image_url': true,
|
||
|
'services.twitter.profile_image_url_https': true,
|
||
|
'services.facebook.id': true,
|
||
|
'services.twitter.screenName': true,
|
||
|
'services.github.screenName': true, // Github is not really used, but there are some mentions to it in the code
|
||
|
'votes.downvotedComments': true,
|
||
|
'votes.downvotedPosts': true,
|
||
|
'votes.upvotedComments': true,
|
||
|
'votes.upvotedPosts': true
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Options for your own user account (for security reasons, block certain properties)
|
||
|
* @type {Object}
|
||
|
*/
|
||
|
Users.pubsub.ownUserOptions = {
|
||
|
'services.password.bcrypt': false
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Minimum required properties to display avatars
|
||
|
* @type {Object}
|
||
|
*/
|
||
|
Users.pubsub.avatarOptions = {
|
||
|
_id: true,
|
||
|
email_hash: true,
|
||
|
slug: true,
|
||
|
username: true,
|
||
|
'profile.username': true,
|
||
|
'profile.github': true,
|
||
|
'profile.twitter': true,
|
||
|
'services.twitter.profile_image_url': true,
|
||
|
'services.twitter.profile_image_url_https': true,
|
||
|
'services.facebook.id': true,
|
||
|
'services.twitter.screenName': true,
|
||
|
'services.github.screenName': true, // Github is not really used, but there are some mentions to it in the code
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Build Users subscription with filter, sort, and limit args.
|
||
|
* @param {String} filterBy
|
||
|
* @param {String} sortBy
|
||
|
* @param {Number} limit
|
||
|
*/
|
||
|
Users.pubsub.getSubParams = function(filterBy, sortBy, limit) {
|
||
|
var find = {},
|
||
|
sort = {createdAt: -1};
|
||
|
|
||
|
switch(filterBy){
|
||
|
case 'invited':
|
||
|
// consider admins as invited
|
||
|
find = { $or: [{ isInvited: true }, { isAdmin: true }]};
|
||
|
break;
|
||
|
case 'uninvited':
|
||
|
find = { $and: [{ isInvited: false }, { isAdmin: false }]};
|
||
|
break;
|
||
|
case 'admin':
|
||
|
find = { isAdmin: true };
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
switch(sortBy){
|
||
|
case 'username':
|
||
|
sort = { username: 1 };
|
||
|
break;
|
||
|
case 'karma':
|
||
|
sort = { karma: -1 };
|
||
|
break;
|
||
|
case 'postCount':
|
||
|
sort = { postCount: -1 };
|
||
|
break;
|
||
|
case 'commentCount':
|
||
|
sort = { commentCount: -1 };
|
||
|
case 'invitedCount':
|
||
|
sort = { invitedCount: -1 };
|
||
|
}
|
||
|
return {
|
||
|
find: find,
|
||
|
options: { sort: sort, limit: limit }
|
||
|
};
|
||
|
};
|