在流星表中仅显示具有特定角色的用户 [英] Display only users with a specific role in meteor-tabular table

查看:239
本文介绍了在流星表中仅显示具有特定角色的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站允许用户通过连接他们的Google帐户申请,一旦创建了一个帐户,他们被赋予了一个待定角色(使用 alanning:roles 包)。我想为管理员提供一个表格,以查看新申请人申请的时间,从那里管理员可以正确管理用户应用程序(更改角色接受,拒绝等)。所以,我创建了我的表,但它显示所有用户,我想知道如果有人知道一个方法,使只有具有待定角色的用户在我的表中显示?



这是我到目前为止所有的:

  TabularTables.ManageApplications = new Tabular.Table({
name:'ManageApplications',
collection:Meteor.users,
allow:function(userId){
return Roles.userIsInRole(userId,
},
autoWidth:false,
oLanguage:{
sSearch:搜索:
},
列:[
{data://这里的列详细信息},
{data://列详细信息},
{data://列详细信息},
{data: / column details here},
{data://列详细信息},
],
});

这样做可以显示每个用户(不只是具有待定角色的用户) / p>

然后,我创建了这个,只尝试发布待处理用户的数据:

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

并通过添加 pub:pendingUsers订阅,到我的桌子这有点有用,它使它只显示待定角色用户的列中的数据,但它仍然列出每个用户,并且只有空白的数据将是。



如果有人知道如何实现这一点,将非常感激,如果你能给出一些洞察力,因为我被困在这一段时间...我相信它可能与仅显示集合数据集的一部分在表格自述中,但我不确定如何设置这个。

解决方案

已经通过将以下内容添加到表中来解决:

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


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 alanning:roles package). I would like to have a table 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 "Displaying Only Part of a Collection's Data Set" in the Tabular readme, but I'm very unsure of how to set this up. Any examples or help is extremely appreciated.

解决方案

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} ) }
    }
},

这篇关于在流星表中仅显示具有特定角色的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆