TL;DR
Setting an ACL with a role permission fails sometimes because the role's name is interpreted as the permission type.
The setup
In a Cloud Code function, I create an ACL object and use setRoleReadAccess to grant read access to a role:
const roleName = 'foo'; // this string is actualy calculated, but always non-nil and non-empty
const acl = new Parse.ACL();
acl.setRoleReadAccess(roleName, true);
Then I set that ACL to a new (unsaved) object:
const myObject = new MyObject()
myObject.setACL(acl);
The error
The setACL call causes an exception with the error message Tried to create an ACL with an invalid permission type. which seems strange since I didn't provide a custom permission type.
What I tried so far
- I tried to set the role as a
Roleobject instead of a string, but that didn't make a difference. - After some debugging I found that the error originates in ParseACL.js (line 85), where the
permissionstring must either matchreadorwrite; however, in my case that string matches the role name (in the example above"foo").
I have similar ACL/role code in other parts of my app, so I'm sure this should work. Now I'm looking for hints -- what might cause the weird behavior that the role name is interpreted as permission type -- and tips on how to further debug this issue.
(Using parse-server version 2.3.3 and node.js 6.4.0; I'm currently locked to that Parse version.)