by eggsurplus

Control what your users can access and save time, money, and frustrations. Lock down sensitive data in SugarCRM or SuiteCRM to specific groups or teams. Supports unlimited assigned users, unlimited group assignments to records, custom layouts for each group, login/sudo capabilities and much more.

Free Trial

By clicking you consent to be contacted by the developer

#4527 - Inheritance from parent record not work on code

In Progress Bug? created by juanchamizo a year ago

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

  1. eggsurplus member avatar

    eggsurplus Provider Affiliate

    a year 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

  2. juanchamizo member avatar

    juanchamizo

    a year 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:

            ~~~
             /* need to find relate fields...for example for Cases look to see if account_id is set */
            //allow inheritance for all relate field types....iterate through and inherit each related field
            foreach ($focus->field_name_map as $name => $def) {
                echo '';
                if ((!isset($def['type']) || ($def['type'] == 'relate' && isset($def['id_name'])))
                    && isset($def['module']) && strtolower($def['module']) != 'users'
                ) {
                    if (isset($_REQUEST[$def['id_name']])) {
                        $relate_parent_id = $_REQUEST[$def['id_name']];
                        $relate_parent_type = $def['module'];
    
                        self::inherit_parentQuery(
                            $focus,
                            $relate_parent_type,
                            $relate_parent_id,
                            $focus_id,
                            $focus_module_dir
                        );
                    } elseif (isset($_SESSION['portal_id']) && isset($_SESSION[$def['id_name']])) { //soap account
                        $relate_parent_id = $_SESSION[$def['id_name']];
                        $relate_parent_type = $def['module'];
    
                        self::inherit_parentQuery(
                            $focus,
                            $relate_parent_type,
                            $relate_parent_id,
                            $focus_id,
                            $focus_module_dir
                        );
                    }
                    // ###############################ADDED CODE##################################
                    // If the relationship with the main record is being created directly via code, it will not enter any of the previous ifs, to ensure that in this case the inherit_parentQuery() function is also called
                    elseif($def['type'] == 'relate' && isset($focus->{$def['id_name']})) {
    
                    $relate_parent_id = $focus->{$def['id_name']};
                    $relate_parent_type = $def['module'];
    
                    self::inherit_parentQuery(
                            $focus,
                            $relate_parent_type,
                            $relate_parent_id,
                            $focus_id,
                            $focus_module_dir
                        );
    
                }
                     // ###############################ADDED 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!

    • eggsurplus member avatar

      eggsurplus Provider Affiliate

      a year 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.

This case is public. Please leave out any sensitive information such as URLs, passwords, etc.
Saving Comment Saving Comment...
Rating
Rating
  • "The features are exactly what is needed to turn a SugarCRM CE into a Teams based CRM."

    Read More Reviews