我正在使用yogiben:admin包 meteor ,我希望当前登录的用户能够仅看到每个集合中他们自己的对象。
如何将订阅集成到管理中?它是自动成型的一部分吗?
最佳答案
所以我开始弄清楚了。
我使用此处描述的技术克隆了该包:https://stackoverflow.com/a/30864393/55124
现在我正在查看 lib/server/publish.coffee 文件来编辑出版物。
Meteor.publishComposite 'adminCollectionDoc', (collection, id) ->
check collection, String
check id, Match.OneOf(String, Mongo.ObjectID)
if Roles.userIsInRole this.userId, ['admin']
find: ->
adminCollectionObject(collection).find(id)
children: AdminConfig?.collections?[collection]?.children or []
else
@ready()
Meteor.publish 'adminUsers', ->
if Roles.userIsInRole @userId, ['admin']
Meteor.users.find()
else
@ready()
Meteor.publish 'adminUser', ->
Meteor.users.find @userId
Meteor.publish 'adminCollectionsCount', ->
handles = []
self = @
_.each AdminTables, (table, name) ->
id = new Mongo.ObjectID
count = 0
table = AdminTables[name]
ready = false
selector = if table.selector then table.selector(self.userId) else {}
handles.push table.collection.find().observeChanges
added: ->
count += 1
ready and self.changed 'adminCollectionsCount', id, {count: count}
removed: ->
count -= 1
ready and self.changed 'adminCollectionsCount', id, {count: count}
ready = true
self.added 'adminCollectionsCount', id, {collection: name, count: count}
self.onStop ->
_.each handles, (handle) -> handle.stop()
self.ready()
Meteor.publish null, ->
Meteor.roles.find({})
但事实证明,这就像更改 lib/both/startup.js 中的 a 行一样简单
return AdminTables[name] = new Tabular.Table({
name: name,
collection: adminCollectionObject(name),
pub: collection.children && adminTablePubName(name),
sub: collection.sub,
columns: columns,
extraFields: collection.extraFields,
dom: adminTablesDom,
selector: collection.selector || function( userId ) {
return { owner: userId };
}
有一个空的选择器函数,我添加了返回所有者:userId。
关于 meteor Yaga 本 :Admin Filtering by Logged in User,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38986452/