Ok so I had in mind that it would be better for my case to hide the tab for everyone but the Admin security group (This is the name of that security group in my case). This changes things a little bit as I can’t just get the role, which would have been a little bit easier as shown here:
$isEnabledRole = in_array("Privileged", ACLRole::getUserRoleNames($current_user->id));
So I had to make a little function to see if the user is actually part of that security group. I’ve put this function under custom/modules/Leads/views/view.detail.php
/**
* isOnSecurityGroup
* Check if the user is on given Security Group. The first argument must be a string with the
* name of the security group. Second argument will be the array with security groups given
* from getUserSecurityGroups(). Used on custom/modules/Leads/metadata/detailviewdefs.php
*/
public function isOnSecurityGroup ($security_group_name, $security_group_list) {
foreach ($security_group_list as $security_group) {
if (($security_group['name'] === $security_group_name || $security_group['name'] == $security_group_name) || (is_array($security_group) && isOnSecurityGroup($security_group_name, $security_group))) {
return True;
}
}
return False;
}
Very simple function just to check whether or not a given user is part of a security group. Then, as this function is under a class CustomLeadsViewDetail that extends LeadsViewDetail I had to use the following code to use it inside custom/modules/Leads/metadata/detailviewdefs.php
global $current_user; // This is necessary in order to see the id for the current user
$current_security_groups = SecurityGroup::getUserSecurityGroups($current_user->id); // Get current user security groups, gives an array
$isEnabledSecurityGroup = CustomLeadsViewDetail::isOnSecurityGroup("Admin", $current_security_groups); // Here we call our new function
if (!$isEnabledSecurityGroup) {
unset($viewdefs['Leads']['DetailView']['panels']['lbl_detailview_panel3']); // Unset tab if the user hasn't got the Admin Security Group on his array
}
?>
I hope this helps someone. Good luck guys.
Edit: Also this code from @cherub-chum helped me on that last part. Just wanted to give you credit for that.