Beispiel #1
0
 /**
  * Get field access level
  * @param string $field Field name
  * @param array $context
  * @return int Access level
  */
 public function ACLFieldGet($field, $context = array())
 {
     if (empty($context['bean'])) {
         $context['bean'] = $this;
     }
     return SugarACL::getFieldAccess($this->getACLCategory(), $field, $context);
 }
Beispiel #2
0
 /**
  * Filter fields list by ACLs
  * NOTE: works with global ACLs
  * @internal
  * @param array $list Field list. Will be modified.
  * @param string $category Module for ACL
  * @param string $user_id
  * @param bool $is_owner Should owner-only ACLs be counted?
  * @param bool $by_key use list keys
  * @param int $min_access Minimal access level to require
  * @param bool $blank_value Put blank string in place of removed fields?
  * @param bool $addACLParam Add 'acl' key with acl access value?
  * @param string $suffix Field suffix to strip from the list.
  */
 function listFilter(&$list, $category, $user_id, $is_owner, $by_key = true, $min_access = 1, $blank_value = false, $addACLParam = false, $suffix = '')
 {
     foreach ($list as $key => $value) {
         if ($by_key) {
             $field = $key;
             if (is_array($value) && !empty($value['group'])) {
                 $field = $value['group'];
             }
         } else {
             if (is_array($value)) {
                 if (!empty($value['group'])) {
                     $value = $value['group'];
                 } else {
                     if (!empty($value['name'])) {
                         $value = $value['name'];
                     } else {
                         $value = '';
                     }
                 }
             }
             $field = $value;
         }
         if (isset(self::$field_cache['lower'][$field])) {
             $field = self::$field_cache['lower'][$field];
         } else {
             $oField = $field;
             $field = strtolower($field);
             if (!empty($suffix)) {
                 $field = str_replace($suffix, '', $field);
             }
             self::$field_cache['lower'][$oField] = $field;
         }
         if (!isset(self::$field_cache[$is_owner][$field])) {
             $context = array("user_id" => $user_id);
             if ($is_owner) {
                 $context['owner_override'] = true;
             }
             $access = SugarACL::getFieldAccess($category, $field, $context);
             self::$field_cache[$is_owner][$field] = $access;
         } else {
             $access = self::$field_cache[$is_owner][$field];
         }
         if ($addACLParam) {
             $list[$key]['acl'] = $access;
         } else {
             if ($access < $min_access) {
                 if ($blank_value) {
                     $list[$key] = '';
                 } else {
                     unset($list[$key]);
                 }
             }
         }
     }
 }