Reputation: 1449
I am able to set setPublicReadAccess
using the code below however I would like to lock the ACL
to the user only.
Parse.Cloud.beforeSave("Programme", function(request, response) {
Parse.Cloud.useMasterKey();
var publicReadACL = new Parse.ACL();
publicReadACL.setPublicReadAccess(true);
request.object.setACL(publicReadACL);
response.success();
});
I have also tried
Parse.Cloud.afterSave("Programme", function(request) {
var user = Parse.User.current();
if(typeof request.object.getACL() === "undefined") {
var newACL = new Parse.ACL();
newACL.setReadAccess(user.id,true);
newACL.setWriteAccess(user.id,true);
request.object.setACL(newACL);
request.object.save();
}
});
Which does not work either.
Upvotes: 1
Views: 1455
Reputation: 101
The ACL of your ParseObject might have been already initialized, so you should userequest.object.existed() == false
instead of typeof request.object.getACL() === "undefined"
.
Also if you don't want your object to be public you have to newACL.setPublicReadAccess(false);
and newACL.setPublicWriteAccess(false);
It works for me
Parse.Cloud.afterSave("YourObject", function(request) {
var user = Parse.User.current();
// check if the object was just created
if(request.object.existed() == false){
var newACL = new Parse.ACL();
newACL.setPublicReadAccess(false);
newACL.setPublicWriteAccess(false);
newACL.setReadAccess(user.id,true);
newACL.setWriteAccess(user.id,true);
request.object.setACL(newACL);
request.object.save();
}
});
Upvotes: 3