As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
Example for editing ACL on a presave collection hook
A
A B
started a topic
about 9 years ago
Hi. I would like to add a reader and a writer group to an entity, on presave
Can you please show me a business logic code example for how we can intercept the save and add the groups to the acl (so they are added when the save is actioned)
I can't an example in the docs nor anything in the forums (except for advice that it is possible)
Hey AB, We'd love to create a sample like this, it's just a matter of having the time to do so. I'll pitch it to the team and see if we can get someone to take a deeper dive on a sample. In the meantime, perhaps some other community members have some examples of what they've done to handle similar use cases.
A
A B
said
almost 9 years ago
Even a hint on the code would be helpful! E.g. how do we access the _acl value and then overwrite it? (I can then do the actual code)
P
Pete
said
almost 9 years ago
Hi @"A B"
Here's a very simple sample that should get you moving in the right direction
function onPreSave(request, response, modules) {
var acl = request.body._acl;
if(!acl.groups) {
acl.groups = {}
}
if(!acl.groups.r) {
acl.r = [];
}
if(!acl.groups.w) {
acl.w = []
}
acl.r.push 'my_group'
acl.w.push 'my_group'
response.continue();
}
For reference, the documentation about the structure of ACLs is [here](http://devcenter.kinvey.com/rest/guides/security#entityanduserpermissions) and the documentation for the Request object is [here](http://devcenter.kinvey.com/rest/reference/business-logic/reference.html#request).
A B
Can you please show me a business logic code example for how we can intercept the save and add the groups to the acl (so they are added when the save is actioned)
I can't an example in the docs nor anything in the forums (except for advice that it is possible)
Thanks!