I have created custom module through module Builder But custom module 's security group sub panel not display and when I check in relationship , the relationship already there

I have created custom module through module Builder But custom module 's security group sub panel not display and when I check in relationship , the relationship already there .

Please look screen shot.

Hi @nilesh2323pal,

Worth trying to run a Quick Repair and Rebuild from the Admin menu to see if that will build the relationship or correct any issues.

Head to administration > Repair > Quick Repair and Rebuild and hit Execute on the code at the bottom!

Thanks!
Mac

I did everything like repair build and repair relationship also . But the sub-panel of Security group is not display . @Mac-Rae Can you create custom module and checked it ?

Thanks

Hi @nilesh2323pal Try Repairing “Roles” via the Admin Panel > Repair

This should add Access Roles to the new module.

It doesn’t work by default. You have to “massage” the code a bit. I’ll try and cut and paste it below. But if you PM me I’ll send you my own PDF notes.

How to add Security Groups to Custom Modules

When you add a custom module, you can mass assign from list view, and it does functionally work in that users will only see what they are assigned. However, in the detail view, the subpanel is not populated. Even if you do populate it, it has no effect on the actual security group??? Problem!

Solution is to add a relationship between the module and security groups and also to modify the relationship meta.

  1. Go to Admin→Studio and open your custom module

  2. Click Relationships then Add Relationship

  3. Configure the options so that it mimics the image below

  4. Click Save

  5. Find the generated relationship file in the custom/metadata directory and replace with the following code

(file name formatted YOURCUSTOMMODULE_securitygroupsMetaData.php):

<?php
$dictionary["YOURCUSTOMMODULE_securitygroups"] = array (
 'true_relationship_type' => 'many-to-many',
 'relationships' =>
 array (
 ' YOURCUSTOMMODULE _securitygroups' =>
 array (
 'lhs_module' => 'SecurityGroups',
 'lhs_table' => 'securitygroups',
 'lhs_key' => 'id',
 'rhs_module' => 'YOURMODULENAME',
 'rhs_table' => 'YOURCUSTOMMODULE',
 'rhs_key' => 'id',
 'join_table' => 'securitygroups_records',
 'join_key_lhs' => 'securitygroup_id',
 'join_key_rhs' => 'record_id',
 'relationship_type' => 'many-to-many',
 'relationship_role_column' => 'module',
 'relationship_role_column_value' => ' YOURMODULENAME',
 ),

 ),
);
?> 

YOU MUST CLEAR THE ENTIRE FILE AND REPLACE WITH THE ABOVE OR IT WILL NOT WORK!!!

  1. Replace YOURCUSTOMMODULE with the first part of the metadata file name.

  2. Replace YOURMODULENAME with the name of your module. (lhs_module in the original file)

  3. Run Admin→Repair→Repair Relationships

  4. Make sure that the appropriate role(s) have your custom module Enabled

You should now see the Mass Assign panel on the list view as well as the Security Groups subpanel on the detail view.

1 Like

Just an FYI on this one. While it does work, when adding a new record to a custom module it doesn’t inherit the security group of the user. Still working on this one, if anyone has any suggestions.

Check under Admin → Display Modules and Subpanels and ensure that Security groups is in the Displayed Subpanels, not hidden.

@pstevens I don’t know if you have achieved the functionality of inheriting the user security group but I had the following Idea in my mind.

In an after save logic hook

  1. Use the following piece of code to get the current users security group.
global $current_user;
$sg = SecurityGroup::getUserSecurityGroups($current_user->id);
  1. Here the sg array will have the Security group details of current user and you can add it to the new record with the following piece of code:
$bean->load_relationship('SecurityGroups'); 
foreach ($sg as $key => $group) {
   $bean->SecurityGroups->add($key); 
}
$bean->save();

I hope this helps you and if you achieved it with a more efficient method then please do share.

If memory serves me correctly, actually, it does inherit the security group with with the code I provided above.

1 Like