How to filter a list per role on Meteor for a Ticket System


#1

I am working a Ticket System on Meteor. And I am trying to make a dashboard with the amount of tickets per status (# Open, # In Progress and # Closed). However I have to filter it out per role [Client and Administrator]. Screenshot: http://screencast.com/t/1IteIss0

Let’s say an example:

I am a client and I should only see tickets that I have created.
And I am an administrator but I have to be able to see all tickets created for all clients.
Then I have the following code created. However I would like your help in order to how can I filter the tickets per role.

Client Site

> Template.dashboard.onCreated(function(){
>     this.subscribe('getStatus');
> });

> Template.dashboard.helpers({
>      tickets: function() {
>       return Status.find({});
>      }
> });

Server Site

> Meteor.publish("getStatus", function(args) {
> var sub = this;

> var db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;

> var pipeline = [
>     { "$group": {
>         "_id": "$status", 
>         "count": { "$sum": 1}
>     }}
> ];

> db.collection("Tickets").aggregate(        
>     pipeline,
>     // Need to wrap the callback so it gets called in a Fiber.
>     Meteor.bindEnvironment(
>         function(err, result) {
>             // Add each of the results to the subscription.
>             _.each(result, function(e) {
>                 // Generate a random disposable id for aggregated documents
>                 sub.added("Status", Random.id(), {
>                     "Status": e._id,
>                     "value": e.count
>                 });
>             });
>             sub.ready();
>         },
>         function(error) {
>             Meteor._debug( "Error doing aggregation: " + error);
>         }
>     )
> );
> });

I really appreciate all your help on this matter.

If you have any question just let me know. I have been fighting with this but I couldn’t find an answer.

Thanks in advance,

Best Regards.