vicusbass
vicusbass

Reputation: 1804

Reactive-table: Unable to display data for all objects in Meteor.users

I am trying to use reactive-table (reactive-table) in Meteor to display users and to edit. I have a major problem: - I am creating the users with Accounts.createUser() method and I have an extra field "profile" (using meteor-roles package). I am defining the table format using the following code:

Template.adminusers.helpers({
    usersCol: function() {
        return Meteor.users;
    },
    settings: function() {
        return {
            rowsPerPage: 10,
            showFilter: true,
            fields: [{
                key: 'profile.lastname',
                label: 'Last name'
            }, {
                key: 'profile.firstname',
                label: 'First name'
            }, {
                key: 'roles',
                label: 'Role'
            }, {
                key: 'emails.0.address',
                label: 'Email'
            }, {
                key: 'edit',
                label: '',
                sortable: false,
                fn: function() {
                    var html = '<button class="btn btn-info btn-xs" type="button"><i class="fa fa-paste"></i> Edit</button>'
                    return new Spacebars.SafeString(html);
                }
            }]
        };
    }
});

The problem is that roles and email are displayed only for the current user. I have no idea why...

Upvotes: 1

Views: 475

Answers (1)

Ethaan
Ethaan

Reputation: 11376

The profile fields its published to the client by default.

Now in order to get all the user objects, you should do something like this (using allaning roles).

For example you have an user with the rol of Admin, this is how the publish should look and the subscribe.

if(Meteor.isClient){
 Tracker.autorun(function(){
   Meteor.subscribe('Admin')
 })
}else if(Meteor.isServer){
 Meteor.publish("Admin", function () {
  var user = Meteor.users.findOne({_id:this.userId});

  if (Roles.userIsInRole(user, ["Admin"])) {
    return Meteor.users.find({}, {fields: {emails: 1, profile: 1, roles: 1}});
  } 
}

Witht his the Admin user will get all the users, also use a helper like this.

Template.example.helpers({
 userList:function(){
   return Meteor.users.find();
 }
})

Upvotes: 3

Related Questions