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 30 day trial
Try it Now

#3225 - Logic Hook How to know if a User is in a specific group

Closed General Question created by Lion Solution Verified Purchase 2 years ago

Hi,
how can i test in a Logic Hook if a user "U1" is assigned to a Group "G1"?

  1. MayerElyashiv member avatar

    Lion Solution Verified Purchase

    2 years ago

    actually i mean the current user

  2. eggsurplus member avatar

    eggsurplus Provider Affiliate

    2 years ago

    There's a function in /modules/SecurityGroups/SecurityGroup.php called getUserSecurityGroups. If you pass the current user ID to it it will return all groups that the user is assigned to. You can then loop through those to see if in G1.

  3. MayerElyashiv member avatar

    Lion Solution Verified Purchase

    2 years ago

    Thank you Jason.
    I did it with

    require_once ('modules/SecurityGroups/SecurityGroup.php');
    global $current_user; 
    $user_id = $current_user->id;
    $groupArray = array();
    $groupArray = getUserSecurityGroups($user_id);
    foreach($groupArray as $group){
    

    ...

    • eggsurplus member avatar

      eggsurplus Provider Affiliate

      2 years ago

      Perfect. Did you mean SecurityGroup::getUserSecurityGroups($user_id)?

      Got it to work as needed?

    • MayerElyashiv member avatar

      Lion Solution Verified Purchase

      2 years ago

      exactly. Thanks. This solved me an issue,

    • eggsurplus member avatar

      eggsurplus Provider Affiliate

      2 years ago

      Great! I'll close this out for now.

This case is public. Please leave out any sensitive information such as URLs, passwords, etc.
Saving Comment Saving Comment...
Rating
Rating
  • "The perfect solution for managing security. Very stable and easy to implement. Must-have add-on for every CE implementation!"

    Read More Reviews

Keep up to date on the latest additions

We'll send you an email every month with handpicked add-ons, reviews, tricks and tips. Don't worry, we hate spam as much as you do.