#4527 - Inheritance from parent record not work on code
Hello, I am a Security Suite user at SuiteCRM 7.11.15, I have observed that the inheritance of the parent record works correctly when you create a record in any module (stock or custom) using the SuiteCRM interface (editview, quickcreateview ...). Occurs as expected, the new record inherits the security groups from the related records at creation time.
However, when doing the same operation through code (in a logic_hook, controller, scheduler task, etc.) the inheritance mechanism of the parent record does not work.
I have seen that in the code of the SecurityGroups/SecurityGroup.php file, in the inherit_parent() function, $_REQUEST ['relate_to'] and $_REQUEST ['relate_id'] are required, but these variables never exist when a record is created by code.
Is it a bug? o Is it the intended behavior?
Thanks,
Juan Chamizo
3 years ago
Hi Juan,
Yes, SuiteCRM intends for it to work like that when saving outside of the typical save process to give you finer control.
All security group inheritance logic gets triggered if doing a save() call on a bean. This eventually goes to SecurityGroup::inherit_parent(). Here, you can see what data it is expecting in order to process the inheritance logic. The function tries to pull based off of request parameters and related fields within the record being saved to get a parent_id/parent_type pair that it can then use to do the inheritance. Whatever custom logic you are using can mimic this to get the inheritance to work as you are expecting.
Let me know if you have any questions.
Cheers, Jason
3 years ago
Hi Jason, thanks for your reply
I have many processes in different modules that create records using schedulers and logic_hooks. I would like the inheritance of the parent record to work just by calling $bean-save(), just like it does in the interface.
With this little modification into inherit_parent() function, inheritance from the parent record works anywhere in the code:
~~~
This works, and the just created record inherits all the security groups from the related records, but I don't know if this code might cause problem at some other point that I am not able to see at the moment.
I understand that it is not appropriate to make these changes directly in the file "modules/SecurityGroups/SecurityGroup.php" , but I would like to know your opinion on whether this could cause other major problems.
Thanks!
3 years ago
Awesome! I'll take a look at this and add to the package if it holds up. Looks great upon initial review.
No, it shouldn't mess anything up. Worst case is that groups get inherited when not expecting them to, but that seems like a non-issue.