70576

Display only users with a specific role in meteor-tabular table

Question:

My site allows users to apply by connecting their google account, as soon as an account is created they're given a "pending" role (using <a href="https://github.com/alanning/meteor-roles" rel="nofollow">alanning:roles</a> package). I would like to have a <a href="https://github.com/aldeed/meteor-tabular" rel="nofollow">table</a> for admins to see when new applicants have applied, from there the admin can properly manage the users application (change role to accepted, declined, etc.). So, I have created my table, but it's showing all users, I'm wondering if someone knows a way to make it so only users with the "pending" role are shown in my table?

Here is what I have so far:

TabularTables.ManageApplications = new Tabular.Table({ name: 'ManageApplications', collection: Meteor.users, allow: function (userId) { return Roles.userIsInRole(userId, 'admin'); }, autoWidth: false, oLanguage: { "sSearch": "Search: " }, columns: [ { data: //column details here }, { data: //column details here }, { data: //column details here }, { data: //column details here }, { data: //column details here }, ], });

This works, but it shows every user (not just users with the "pending" role).

I then created this to try and publish only data for pending users:

Meteor.publish("pendingUsers", function() { var isAdmin = Roles.userIsInRole(this.userId, 'admin'); if (isAdmin) { return Roles.getUsersInRole('pending').fetch(); } else { return null; } });

and subscribed by adding pub: "pendingUsers", to my table. This somewhat works, it makes it so it only shows data in the columns for "pending" role users, but, it still lists every user and just has blank spaces where the data would be.

If anyone knows how I can achieve this it would be greatly appreciated if you could give some insight as I've been stuck on this for quite a while... I believe it may have to do with "<a href="https://github.com/aldeed/meteor-tabular#displaying-only-part-of-a-collections-data-set" rel="nofollow">Displaying Only Part of a Collection's Data Set</a>" in the Tabular readme, but I'm very unsure of how to set this up. Any examples or help is extremely appreciated.

Answer1:

Given the way that publications work it's more than likely that you have another publication and subscription which is giving you the rest of the users but with a different set of keys/fields. Since multiple publications can be running on the same collection at the same time you want to perform the same .find() on the client that your publication is giving you.

Go ahead and add a <a href="https://github.com/aldeed/meteor-tabular#displaying-only-part-of-a-collections-data-set" rel="nofollow">selector</a> to your table definition as follows:

selector: function( userId ) { return Roles.getUsersInRole('pending'); }

You don't need the .fetch() in your publication btw, Roles.getUsersInRole() already returns a <em>cursor</em> of Meteor.users.

Answer2:

This has been solved by adding the following to my table:

selector: function(userId) { return { _id: {$in: Roles.getUsersInRole('pending') .map(function(user){ return user._id} ) } } },

Answer3:

Use Selector: <a href="https://github.com/aldeed/meteor-tabular#modifying-the-selector" rel="nofollow">https://github.com/aldeed/meteor-tabular#modifying-the-selector</a>

If you want to check all the rules of such a group:

     selector: function (userId) {        return 'roles.myrole': {$exists: true}};      },

Or with just a few:

     selector: function (userId) {        return 'roles.myrole': {$in: ['viewer', 'editor']}};      },

Recommend

  • JqGrid InlineEdit With editUrl: 'clientArray' Can Not Save
  • Datatables sorting time column
  • aoData is null when using multiple instances of jquery datatable
  • JQGrid able to pass ValidateAntiForgeryToken through the main CRUD controls?
  • jqgrid/ how to create selectbox dynamically loading select options
  • How to make FlowRouter wait for users collection on the client
  • Problems with sorting by date (dd.mm.YYYY) in Datatable using Moment.js and Ordering Plugin
  • What is the variable scope in Meteor client side?
  • Meteor.js mongodb version
  • jsf security-contraint to protect link when the user is not signed in?
  • HTMLcollection 0 list length, [n] returns undefined, converting to an array returns an empty array
  • How to remove a product from a category magento 1.5
  • What are “Java EE 7 API Library” and “Java EE Web 7 API Library” and when to use them?
  • Delphi TCollection - Possible to prevent changing items in run-time?
  • Operation not supported on read-only collection
  • Detaching entity along with referenced entities
  • get data from firestore firebase
  • Regarding Static class in c# [duplicate]
  • How to convert Neo4j Result to GraphJSON
  • Bind collection of objects to ListBox
  • Create an Event Handler whenever a new Node is added in treeview
  • Java Garbage collection, setting reference to null
  • Updating and removing unique join relationships in CakePHP
  • Many to Many in Linq using Dapper
  • Accessing Rows In A LINQ Result Without A Foreach Loop?
  • Where these are stored?
  • abstracting over a collection
  • How can I tell a form not to dispose a particular control when it closes?
  • R convert summary result (statistics with all dataframe columns) into dataframe
  • Breaking out column by groups in Pandas
  • Unable to get column index with table.getColumn method using custom table Model
  • Meteor helpers not available in Angular template
  • Insert into database using onclick function
  • What is Eclipse's Declaration View used for?
  • Can I make an Android app that runs a web view in Chrome 39?
  • retrieve vertices with no linked edge in arangodb
  • Bitwise OR returns boolean when one of operands is nil
  • sending mail using smtp is too slow
  • costura.fody for a dll that references another dll
  • Binding checkboxes to object values in AngularJs