Reputation: 62
I've been struggling with a problem with Parse Objects for a while and I'm not sure what the best implementation is.
I have a PFObject that is created by another user, a message, and this user has given me Read access so I can read this message. I do not want to see this message any more but I don't want to delete it because it's not my message.
If I adjust the ACL permission to remove my Read access
object.ACL setReadAccess:NO forUser:[PFUser currentUser]];
And then go to save the object
object saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
I receive the error
Error: object not found for update (Code: 101, Version: 1.2.15)
This is obviously because I only have read access and not write access to update the object.
I was thinking possibly having a block message object for each user but this feels a bit messy.
Can anyone think of a better implementation for my issue?
All ideas are great, just want to bounce ideas off fellow iOS programmers.
Upvotes: 0
Views: 364
Reputation: 62
I ended up working it out by creating cloud code that I call to remove a user from a Message. Using the Parse.Cloud.UseMasterKey() you can do anything you want without permissions.
Parse.Cloud.define("RemoveUserFromMessage", function(request, response) {
Parse.Cloud.useMasterKey();
var query = new Parse.Query("Notes");
query.get(request.params.noteId, {
success: function(note) {
var noteACL = note.getACL();
noteACL.setReadAccess(request.params.userId, false);
noteACL.setWriteAccess(request.params.userId, false);
note.setACL(noteACL);
note.save();
response.success();
},
error: function() {
response.error("can’t find note");
}
});
});
Upvotes: 1