Meteor publication Exception: Did not check() all arguments during publisher when using aldeed:tabular

301 Views Asked by At

I have the following publication:

Meteor.publish( 'usersadmin', function() {
  return Meteor.users.find( {}, { fields: { "emails": 1, "roles": 1, "profile": 1 } } )
});

and I'm displaying the publication in the following table using aldeed:tabular:

TabularTables.UsersAdmin = new Tabular.Table({
      name: "User List",
      collection: Meteor.users,
      pub: "usersadmin",
      allow: function(userId) {
        return Roles.userIsInRole(userId, 'admin');
      },
      columns: [{
        data: "emails",
        title: "Email",
        render: function(val, type, doc) {
          return val[0].address;
        }
      }, {
        data: "roles",
        title: "Roles",
        render: function(val, type, doc) {
          return val[0]._id;
        }
      }]);

The table displays fine, but in the server terminal the following exception shows up:

 Exception from sub usersadmin id 2d7NFjgRXFBZ2s44R Error: Did not check() all arguments during publisher 'usersadmin'

What causes this?

1

There are 1 best solutions below

0
Matthias A. Eckhart On BEST ANSWER

You receive this error because you need to check the arguments passed to your usersadmin publish function by using check(value, pattern).

The reactive DataTables, implemented in the aldeed:tabular package, pass the arguments tableName, ids and fields to the publish function; that's why an exception is thrown.

According to the documentation, you need to take care of the following requirements:

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

This should fix the error:

Meteor.publish('usersadmin', function(tableName, ids, fields) {
  check(tableName, String);
  check(ids, Array);
  check(fields, Match.Optional(Object));
  return Meteor.users.find({}, {fields: {"emails": 1, "roles": 1, "profile": 1}});
});