使用此ACL作为模型,我想避免创建新模型,该模型具有指向其他用户(而不是实际所有者)的访问令牌的所有者(userId)。我不希望userId 4发布新模型,并将该模型的所有者设置为5,即另一个userId。但这现在不起作用,因为数据库上没有要检查的模型,那我该怎么办?这是我上次检查删除时有效的方法。但是我需要发布...
答案 0 :(得分:1)
我认为这可以做到。
server/boot/01-add-user.js
module.exports = (server) => {
// Before each create request, assign the userId property to the userId of the accessToken
const addUser = async (ctx) => {
function assignUserId(o) {
o.userId = ctx.req.accessToken.userId;
}
// You can post arrays of objects to loopback
if (Array.isArray(ctx.req.body)){
ctx.req.body.forEach(assignUserId);
} else {
assignUserId(ctx.req.body);
}
};
server.models.MY_MODEL.beforeRemote('create', addUser);
}
为您的ACL尝试
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
},
{
"accessType": "WRITE",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
},
{
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW",
"property": "create"
}
],