Search code examples
parse-platformacl

Parse Platform default ACL


Story: I'm developing simple Angular web-app using Parse Platform for backend and straight API calls (no parse platform libraries). I have couple of tables and login - everything is working. However it came time to restrict access via Access Controls such that one user can't access data of another and here we I hit a problem.

Question: Given user is logged in, how to default newly created/updated object to have ACL specifically to the creator (currently logged-in user)?

Additionally:

  • I would assume there is a way to set parse platform to do it by default (and docs mention it) but I can't find out how.
  • I want to void manually pass ACL settings in each request

Solution

  • The easiest way is through beforeSave trigger. It would be something like this:

    Parse.Cloud.beforeSave('MyClass', ({ original, object, user }) => {
      if (!original) { // New object is being created
        object.setACL(new Parse.ACL(user));
      }
    });