Search code examples
meteoruser-roles

Publishing role names into a table Meteor alanning:roles and aldeed:tabular


I'm having trouble displaying the created roles in a table. I'm using alanning:roles and aldeed:tabular. To create the table I have:

TabularTables.RolesAdmin = new Tabular.Table({
   name: "Roles",
   collection: Meteor.roles,
   pub:"rolesadmin",
   allow: function (userId) {
     return Roles.userIsInRole(userId, 'admin');
   },
   columns: [
     { 
       data: "name",
       title: "Role Name",
     },
   ],
});

And the publication looks like this:

Meteor.publish( 'rolesadmin', function() {
  return Meteor.roles.find( {}, { fields: { "name": 1 } } );
});

When running the app the table only displays "Processing..." thus there is an error and it is not able at access/find the data?

I'm getting the following exception in the server terminal:

Exception from sub rolesadmin id 6c6x3mDzweP8MbB9A 
Error: Did not check() all arguments during publisher 'rolesadmin'

If I check in mongo db.roles.find(), there is no role with 6c6x3mDzweP8MbB9A id. What does this error refer to?


Solution

  • From the meteor-tabular docs:

    To tell Tabular to use your custom publish function, pass the publication name as the pub option. Your function:

    MUST accept and check three arguments: tableName, ids, and fields

    MUST publish all the documents where _id is in the ids array.

    MUST do any necessary security checks

    SHOULD publish only the fields listed in the fields object, if one is > provided.

    MAY also publish other data necessary for your table

    So it looks like you'll need to account for those three arguments mentioned in the documentation appropriately. I'm not sure you actually need a custom pub for this, though, based on what you are publishing.