/**
  * Override - Called from process(). This method will display subpanels.
  * include/MVC/View/SugarView.php
  */
 protected function _displaySubPanels()
 {
     if (isset($this->bean) && !empty($this->bean->id) && (file_exists("modules/" . $this->module . "/metadata/subpaneldefs.php") || file_exists("custom/modules/" . $this->module . "/Ext/Layoutdefs/layoutdefs.ext.php"))) {
         $GLOBALS["focus"] = $this->bean;
         require_once 'include/SubPanel/SubPanelTiles.php';
         $subpanel = new SubPanelTiles($this->bean, $this->module);
         //Dependent Logic
         global $current_user;
         require_once 'modules/ACLRoles/ACLRole.php';
         $role = new ACLRole();
         $user_id = $current_user->id;
         $roles = $role->getUserRoleNames($user_id);
         if (in_array("Technical support", $roles)) {
             //Subpanels to hide
             $hide_subpanels = array("bugs");
             if (isset($subpanel->subpanel_definitions->layout_defs['subpanel_setup']["bugs"])) {
                 unset($subpanel->subpanel_definitions->layout_defs['subpanel_setup']["bugs"]);
             }
         }
         echo $subpanel->display();
     }
 }
예제 #2
0
 public function testgetUserRoleNames()
 {
     $aclRole = new ACLRole();
     //test with empty value
     $result = $aclRole->getUserRoleNames('');
     $this->assertTrue(is_array($result));
     //test with non empty but non existing role id value
     $result = $aclRole->getUserRoleNames('1');
     $this->assertTrue(is_array($result));
 }
예제 #3
0
 /**
  * @return boolean true if the user is a member of the role_name, false otherwise
  * @param string $role_name - Must be the exact name of the acl_role
  * @param string $user_id - The user id to check for the role membership, empty string if current user
  * @desc Determine whether or not a user is a member of an ACL Role. This function caches the
  *       results in the session or to prevent running queries after the first time executed.
  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
  * All Rights Reserved..
  * Contributor(s): ______________________________________..
  */
 function check_role_membership($role_name, $user_id = '')
 {
     global $current_user;
     if (empty($user_id)) {
         $user_id = $current_user->id;
     }
     // Check the Sugar External Cache to see if this users memberships were cached
     $role_array = sugar_cache_retrieve("RoleMemberships_" . $user_id);
     // If we are pulling the roles for the current user
     if ($user_id == $current_user->id) {
         // If the Session doesn't contain the values
         if (!isset($_SESSION['role_memberships'])) {
             // This means the external cache already had it loaded
             if (!empty($role_array)) {
                 $_SESSION['role_memberships'] = $role_array;
             } else {
                 $_SESSION['role_memberships'] = ACLRole::getUserRoleNames($user_id);
                 $role_array = $_SESSION['role_memberships'];
             }
         } else {
             $role_array = $_SESSION['role_memberships'];
         }
     } else {
         // If the external cache didn't contain the values, we get them and put them in cache
         if (!$role_array) {
             $role_array = ACLRole::getUserRoleNames($user_id);
             sugar_cache_put("RoleMemberships_" . $user_id, $role_array);
         }
     }
     // If the role doesn't exist in the list of the user's roles
     if (!empty($role_array) && in_array($role_name, $role_array)) {
         return true;
     } else {
         return false;
     }
 }