Meteor Iron Router 重新订阅使用 meteor-roles 的权限更改
Meteor Iron Router resubscribe on Rights change with meteor-roles
我正在编写一个带有用户角色系统的流星应用程序 (alanning:roles
) 我的角色是基于组的。当用户知道我的组 url 时,允许访问该组并在该组中获得角色 "defaultUser"。
允许本地用户订阅群组的所有本地内容。
根据群ID,我也发布了一些内容
问题是:订阅没有重新订阅。
工作流程:
- 用户访问应用,
- 调用 meteor-method 获取默认角色
- 获得默认角色
- 订阅了 publication
- 如果用户有合适的角色publication(完整组)发布内容
我的出版物看起来像:
Meteor.publish "thisGroupPublic", (id) ->
return db.groups.find({_id: id}, {fields: {onlypublicones...}}
Meteor.publishComposite "thisGroupReactive", (id) ->
return {
find: () ->
if !Roles.userIsInRole(@userId, "defaultUser", id)
@ready()
console.log("[thisGroupReactive] => No Rights")
return;
return db.groups.find({_id: id});
children: [
{
find: (group) ->
return db.contents.find({groups: {$in: [group._id]}}, {fields: {apikey: 0}})
}
]
}
用户在登录页面上订阅订阅 "thisGroupPublic",并在首次以登录用户身份访问群组时获得角色 "defaultUser"。但是我需要如何配置 iron:router
才能
重新订阅此订阅以显示内容,而不仅仅是 public 内容?
说用户在路线上/something
您有一些数据发生变化并创建了一个会话变量:
Session.set("someDataThatChanges", myChangedData)
您的发布函数接受某种输入,用于return来自集合的不同数据:
Meteor.publish("myCollection", function(input){
return myCollection.find(
// do something here based on 'input'
);
});
Iron Router 有一个与 Meteor.subscribe
相同的 .subscribe
方法,还有一个带有函数的 subscriptions
键。您可以将 Tracker.autorun
包裹在您的 .subscribe
中并放入您的会话变量以根据该会话变量的变化值自动重新订阅某些内容。
Router.route("/something", {
name: "templateName",
// a place to put your subscriptions
subscriptions: function() {
console.log("this in router ", this);
Tracker.autorun(function(){
this.subscribe('myCollection', Session.get("someDataThatChanges");
});
},
});
我正在编写一个带有用户角色系统的流星应用程序 (alanning:roles
) 我的角色是基于组的。当用户知道我的组 url 时,允许访问该组并在该组中获得角色 "defaultUser"。
允许本地用户订阅群组的所有本地内容。
根据群ID,我也发布了一些内容
问题是:订阅没有重新订阅。
工作流程:
- 用户访问应用,
- 调用 meteor-method 获取默认角色
- 获得默认角色
- 订阅了 publication
- 如果用户有合适的角色publication(完整组)发布内容
我的出版物看起来像:
Meteor.publish "thisGroupPublic", (id) ->
return db.groups.find({_id: id}, {fields: {onlypublicones...}}
Meteor.publishComposite "thisGroupReactive", (id) ->
return {
find: () ->
if !Roles.userIsInRole(@userId, "defaultUser", id)
@ready()
console.log("[thisGroupReactive] => No Rights")
return;
return db.groups.find({_id: id});
children: [
{
find: (group) ->
return db.contents.find({groups: {$in: [group._id]}}, {fields: {apikey: 0}})
}
]
}
用户在登录页面上订阅订阅 "thisGroupPublic",并在首次以登录用户身份访问群组时获得角色 "defaultUser"。但是我需要如何配置 iron:router
才能
重新订阅此订阅以显示内容,而不仅仅是 public 内容?
说用户在路线上/something
您有一些数据发生变化并创建了一个会话变量:
Session.set("someDataThatChanges", myChangedData)
您的发布函数接受某种输入,用于return来自集合的不同数据:
Meteor.publish("myCollection", function(input){
return myCollection.find(
// do something here based on 'input'
);
});
Iron Router 有一个与 Meteor.subscribe
相同的 .subscribe
方法,还有一个带有函数的 subscriptions
键。您可以将 Tracker.autorun
包裹在您的 .subscribe
中并放入您的会话变量以根据该会话变量的变化值自动重新订阅某些内容。
Router.route("/something", {
name: "templateName",
// a place to put your subscriptions
subscriptions: function() {
console.log("this in router ", this);
Tracker.autorun(function(){
this.subscribe('myCollection', Session.get("someDataThatChanges");
});
},
});