mirror of
https://github.com/vale981/Vulcan
synced 2025-03-07 02:21:43 -05:00
cleaning up user subscriptions
This commit is contained in:
parent
491ed441e2
commit
ddb65f8ec5
4 changed files with 36 additions and 24 deletions
|
@ -223,9 +223,9 @@ Router.map(function() {
|
||||||
|
|
||||||
this.route('user_profile', {
|
this.route('user_profile', {
|
||||||
path: '/users/:_id',
|
path: '/users/:_id',
|
||||||
// waitOn: function() {
|
waitOn: function() {
|
||||||
// TODO: subscribe to the correct user
|
return Meteor.subscribe('singleUser', this.params._id);
|
||||||
// },
|
},
|
||||||
data: function() {
|
data: function() {
|
||||||
return {
|
return {
|
||||||
user: Meteor.users.findOne(this.params._id)
|
user: Meteor.users.findOne(this.params._id)
|
||||||
|
@ -237,9 +237,9 @@ Router.map(function() {
|
||||||
|
|
||||||
this.route('user_edit', {
|
this.route('user_edit', {
|
||||||
path: '/users/:_id/edit',
|
path: '/users/:_id/edit',
|
||||||
// waitOn: function() {
|
waitOn: function() {
|
||||||
// TODO: subscribe to the correct user
|
return Meteor.subscribe('singleUser', this.params._id);
|
||||||
// },
|
},
|
||||||
data: function() {
|
data: function() {
|
||||||
return {
|
return {
|
||||||
user: Meteor.users.findOne(this.params._id)
|
user: Meteor.users.findOne(this.params._id)
|
||||||
|
@ -265,7 +265,16 @@ Router.map(function() {
|
||||||
|
|
||||||
// All Users
|
// All Users
|
||||||
|
|
||||||
this.route('users');
|
this.route('users', {
|
||||||
|
waitOn: function() {
|
||||||
|
return Meteor.subscribe('allUsers');
|
||||||
|
},
|
||||||
|
data: function() {
|
||||||
|
return {
|
||||||
|
users: Meteor.users.find({}, {sort: {createdAt: -1}})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Unsubscribe (from notifications)
|
// Unsubscribe (from notifications)
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,16 @@ Session.set('currentDate', new Date());
|
||||||
Session.set('categorySlug', null);
|
Session.set('categorySlug', null);
|
||||||
Session.set('singlePostReady', false);
|
Session.set('singlePostReady', false);
|
||||||
|
|
||||||
|
// Subscriptions
|
||||||
|
|
||||||
|
// note: here we only subscribe to subscriptions that we need to be available all the time.
|
||||||
|
// For subscriptions depending on specific pages, see the router.
|
||||||
|
|
||||||
|
// TODO: add session variable that tracks once all subscriptions here have loaded
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
Meteor.subscribe('settings', function(){
|
Meteor.subscribe('settings', function(){
|
||||||
// runs once on site load
|
// runs once after settings have loaded
|
||||||
analyticsInit();
|
analyticsInit();
|
||||||
Session.set('settingsLoaded',true);
|
Session.set('settingsLoaded',true);
|
||||||
});
|
});
|
||||||
|
@ -14,9 +21,10 @@ Meteor.subscribe('settings', function(){
|
||||||
// Categories
|
// Categories
|
||||||
Meteor.subscribe('categories');
|
Meteor.subscribe('categories');
|
||||||
|
|
||||||
// Users
|
// Current User
|
||||||
|
// we need to subscribe to the currentUser subscription because by default,
|
||||||
|
//Meteor doesn't send all the user properties that we need
|
||||||
Meteor.subscribe('currentUser');
|
Meteor.subscribe('currentUser');
|
||||||
Meteor.subscribe('allUsers');
|
|
||||||
|
|
||||||
// Notifications - only load if user is logged in
|
// Notifications - only load if user is logged in
|
||||||
if(Meteor.userId() != null){
|
if(Meteor.userId() != null){
|
||||||
|
@ -78,15 +86,3 @@ selectPending = function() {
|
||||||
return selectPosts({name: 'pending', status: STATUS_PENDING, slug: Session.get('categorySlug')});
|
return selectPosts({name: 'pending', status: STATUS_PENDING, slug: Session.get('categorySlug')});
|
||||||
}
|
}
|
||||||
pendingPostsHandle = postListSubscription(selectPending, sortPosts('createdAt'), 10);
|
pendingPostsHandle = postListSubscription(selectPending, sortPosts('createdAt'), 10);
|
||||||
|
|
||||||
// Comments
|
|
||||||
// Collection depends on selectedPostId and selectedCommentId session variable
|
|
||||||
|
|
||||||
// Session.set('selectedPostId', null);
|
|
||||||
|
|
||||||
// Meteor.autosubscribe(function() {
|
|
||||||
// var query = { $or : [ { post : Session.get('selectedPostId') } , { _id : Session.get('selectedCommentId') } ] };
|
|
||||||
// Meteor.subscribe('comments', query, function() {
|
|
||||||
// Session.set('singleCommentReady', true);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
isAdminById=function(userId){
|
isAdminById=function(userId){
|
||||||
var user = Meteor.users.findOne(userId);
|
var user = Meteor.users.findOne(userId);
|
||||||
return user && isAdmin(user);
|
return !!(user && isAdmin(user));
|
||||||
}
|
}
|
||||||
isAdmin=function(user){
|
isAdmin=function(user){
|
||||||
if(!user || typeof user === 'undefined')
|
if(!user || typeof user === 'undefined')
|
||||||
|
|
|
@ -3,8 +3,15 @@
|
||||||
Meteor.publish('currentUser', function() {
|
Meteor.publish('currentUser', function() {
|
||||||
return Meteor.users.find(this.userId);
|
return Meteor.users.find(this.userId);
|
||||||
});
|
});
|
||||||
|
Meteor.publish('singleUser', function(userId) {
|
||||||
|
console.log(isAdminById(this.userId))
|
||||||
|
if(!isAdminById(this.userId))
|
||||||
|
throw new Meteor.Error("You do not have the rights to view this user profile");
|
||||||
|
|
||||||
|
return Meteor.users.find(userId);
|
||||||
|
});
|
||||||
Meteor.publish('allUsers', function() {
|
Meteor.publish('allUsers', function() {
|
||||||
if (this.userId && isAdminById(this.userId)) {
|
if (isAdminById(this.userId)) {
|
||||||
// if user is admin, publish all fields
|
// if user is admin, publish all fields
|
||||||
return Meteor.users.find();
|
return Meteor.users.find();
|
||||||
}else{
|
}else{
|
||||||
|
|
Loading…
Add table
Reference in a new issue