when decorating terms with current user id, call it currentUserId and not userId (which conflicts with userId from posts, comments, etc.)

This commit is contained in:
Sacha Greif 2016-02-06 12:30:29 +09:00
parent f14df077b4
commit 60e0f61813
7 changed files with 31 additions and 12 deletions

View file

@ -7,6 +7,10 @@ Meteor.publish('commentsList', function(terms) {
this.unblock();
if (this.userId) { // add currentUserId to terms if a user is logged in
terms.currentUserId = this.userId;
}
if(Users.can.viewById(this.userId)){
var parameters = Comments.parameters.get(terms);
var comments = Comments.find(parameters.find, parameters.options);

View file

@ -11,7 +11,7 @@ Template.main_posts_list.helpers({
// if user is logged in, add their id to terms
if (Meteor.userId()) {
terms.userId = Meteor.userId();
terms.currentUserId = Meteor.userId();
}
if (!terms.view) {

View file

@ -3,9 +3,13 @@ Posts._ensureIndex({"status": 1, "postedAt": 1});
// Publish a list of posts
Meteor.publish('postsList', function(terms) {
this.unblock();
terms.userId = this.userId; // add userId to terms
if (this.userId) { // add currentUserId to terms if a user is logged in
terms.currentUserId = this.userId;
}
if(Users.can.viewById(this.userId)){
var parameters = Posts.parameters.get(terms),
posts = Posts.find(parameters.find, parameters.options);
@ -21,8 +25,11 @@ Meteor.publish('postsList', function(terms) {
Meteor.publish('postsListUsers', function(terms) {
this.unblock();
terms.userId = this.userId; // add userId to terms
if (this.userId) {
terms.currentUserId = this.userId; // add userId to terms
}
if(Users.can.viewById(this.userId)){
var parameters = Posts.parameters.get(terms),
posts = Posts.find(parameters.find, parameters.options),
@ -47,10 +54,15 @@ Meteor.publish('singlePost', function(postId) {
check(postId, String);
this.unblock();
if (Users.can.viewById(this.userId)){
var user = Meteor.users.findOne(this.userId);
var post = Posts.findOne(postId);
if (Users.can.viewPost(user, post)){
return Posts.find(postId);
} else {
return [];
}
return [];
});
// Publish author of the current post, authors of its comments, and upvoters of the post

View file

@ -1,6 +1,8 @@
Meteor.publish('userSubscribedPosts', function(terms) {
terms.userId = this.userId; // add userId to terms
if (this.userId) {
terms.currentUserId = this.userId; // add userId to terms
}
var parameters = Posts.parameters.get(terms);
var posts = Posts.find(parameters.find, parameters.options);

View file

@ -1,7 +1,7 @@
Template.user_posts.helpers({
arguments: function () {
var user = this;
return {
var args = {
template: "posts_list_compact",
options: {
currentUser: user,
@ -18,5 +18,6 @@ Template.user_posts.helpers({
subscribeToUsers: false
}
};
return args;
}
});

View file

@ -9,8 +9,8 @@ Template.user_controller.helpers({
var idOrSlug = FlowRouter.getParam("_idOrSlug");
var findById = Meteor.users.findOne(idOrSlug);
var findBySlug = Meteor.users.findOne({"telescope.slug": idOrSlug});
return {user: findById || findBySlug};
var user = findById || findBySlug;
return {user: user};
}
});

View file

@ -17,7 +17,7 @@ Meteor.publish('userPosts', function(terms) {
this.unblock();
terms.userId = this.userId; // add userId to terms
terms.currentUserId = this.userId; // add userId to terms
var parameters = Posts.parameters.get(terms);
var posts = Posts.find(parameters.find, parameters.options);
@ -28,7 +28,7 @@ Meteor.publish('userUpvotedPosts', function(terms) {
this.unblock();
terms.userId = this.userId; // add userId to terms
terms.currentUserId = this.userId; // add userId to terms
var parameters = Posts.parameters.get(terms);
var posts = Posts.find(parameters.find, parameters.options);
@ -39,7 +39,7 @@ Meteor.publish('userDownvotedPosts', function(terms) {
this.unblock();
terms.userId = this.userId; // add userId to terms
terms.currentUserId = this.userId; // add userId to terms
var parameters = Posts.parameters.get(terms);
var posts = Posts.find(parameters.find, parameters.options);