我的应用中有2个角色。用户和医生。 我希望医生可以在医生的额外个人资料页面上编辑额外的字段,如图片和文本字段。
如何将这些字段添加到配置文件中,但可以添加到用户集合的额外部分,然后将其作为配置文件页面/ doctor / _id公开提供
我现在正在尝试使用meteorkitchen,这很棒,但是当我添加profile.doctor.field1并在user_settings / profile / doctor这样的页面上显示并更新它时,配置文件的其他字段会被空值覆盖。我假设它假定在一个表单上编辑所有配置文件属性,并且当一个字段为空时删除它们。但这不是我想要的。
(有人可以添加标签meteorkitchen。我的名声不够。谢谢)
修改 这是路由器的设置
var roleMap = [
...
{ route: "user_settings.doctor", roles: ["doctor","admin"] }
];
并附上此部分的表格
"name": "edit_form",
"type": "form",
"mode": "update",
"title": "Edit your doctor profile",
"submit_route": "user_settings.profile.doctor",
"query": {
"name": "current_user_data",
"collection": "users",
"filter": {
"_id": "Meteor.userId()"
},
"find_one": true,
"options": {},
"params": []
},
"fields": [
{
"name": "profile.doctor.quote",
"title": "Favorite quote",
"type": "string",
"required": true
}
]
问题是在更新某些配置文件值时会删除其他配置文件。
答案 0 :(得分:1)
如果你想坚持Meteor Kitchen,我将继续这样做。
client/views/router.js
或使用设计器的角色地图中执行此操作。编辑以下评论中的讨论是更新:
您可以直接在设计器的“编辑源”部分中更改集合名称。您转到您的页面,在查询中设置
"query": {
"name": "doctor_user",
"collection": "users",
"filter": {
"_id": ":userId"
},
"find_one": false,
"options": {},
"params": []
},
问题是,即使您这样做,只有管理员可以更新用户集合。因此,您需要从perak下载用户角色包,将其放入项目中(仅放置文件夹)并删除用户角色预安装包(meteor remove perak:user-roles
)。
完成后,转到server/collections
并将update
users.js
部分替换为:
update: function (userId, doc, fieldNames, modifier) {
return Users.isInRole ("admin")|| (Users.isInRole ("doctor") &&
!_.contains(fieldNames,'roles')));
允许具有医生角色的用户更新除“角色”字段之外的任何用户字段。
最后一步,您编辑server\publications\users.js
文件并将其添加到其中:
Meteor.publish("doctor_user", function(_id){
return Users.isInRoles ({"doctor", "admin"}) ? Users.find({_id: _id}) : this.ready();
});