解析服务器上的SetACL [英] SetACLs on Parse Server
问题描述
我正在AWS上使用Parse Server,并且运行良好.但是,我无法像在parse.com云代码中那样分配ACL.
I'm using Parse Server on AWS and its been going well. However I am unable to assign ACL as I did in the parse.com cloud code.
I have read The Compatibility Notes, Docs and Git Read me however there is very little mention of ACL.
尝试了以下答案,但不适用于我.
The following answer has been tried, however it is not working for me.
我的旧代码是这样的:
Parse.Cloud.afterSave("Favourites", function(request) {
var user = request.user;
var newACL = new Parse.ACL(Parse.User.current())
newACL.setReadAccess(user, true);
newACL.setWriteAccess(user, true);
request.object.setACL(newACL);
request.object.save();
});
很明显,不能使用Parse.User.current()
,这使我想到了这一点:
Obviously Parse.User.current()
cannot be used which has brought me to this:
Parse.Cloud.beforeSave("Favourites", function(request, res) {
var acl = new Parse.ACL();
acl.setReadAccess(request.object.id, true);
acl.setWriteAccess(request.object.id, true);
request.object.setACL(acl);
res.success();
});
但是,这对我不起作用.
However, this is not working for me.
我还尝试使用以下设置在保存ACL的同时进行设置,但是它仍然对我不起作用.
I have also tried setting the ACL at the same time as saving using the following, however it still doesn't work for me.
var favourites = new Favourites();
var acl = new Parse.ACL();
acl.setReadAccess('request.object.id', true);
acl.setWriteAccess('request.object.id', true);
favourites.setACL(acl);
favourites.save({
user: request.user,
favourites: request.params.favourites
}, {
success: function(favourites) {
console.log('Great!')
},
error: function(favourites, error) {
console.log('The save failed');
}
});
编辑
我刚刚尝试使用Javascript文档来做事:
I have just tried doing things using the Javascript Docs:
var favourites = new Favourites();
var acl = new Parse.ACL(request.user);
acl.setReadAccess(request.user, true);
acl.setWriteAccess(request.user, true);
acl.setPublicWriteAccess(false);
acl.setPublicReadAccess(false);
favourites.setACL(acl);
favourites.set("favourites", request.params.favourites);
favourites.set("userId", request.user.id);
favourites.set("user", request.user);
favourites.save({}, { useMasterKey: true });
仍然无效!
文档中似乎严重缺乏node.js云代码示例.
It seems there is a serious lack of node.js cloud code examples in the Docs.
任何帮助将不胜感激.
Any help would be greatly appreciated.
推荐答案
这是您需要做的所有事情.我还向公众添加了拒绝访问权限,因为您不清楚自己想要什么.
This is all you need to do. I have add deny access fir the public, since it isn't totally clear what you want.
Parse.Cloud.afterSave("Favourites", function(request) {
var newACL = new Parse.ACL();
// Are you sure you don't need to disable public access?
newACL.setPublicReadAccess(false);
newACL.setPublicWriteAccess(false);
// Give access to user
newACL.setReadAccess(request.user, true);
newACL.setWriteAccess(request.user, true);
// Assign ACL to object
request.object.setACL(newACL);
// Use master key
request.object.save(null, {useMasterKey: true});
});
这篇关于解析服务器上的SetACL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!