CRM-13644 Apply Permission Check for Group API 4.6
authorSeamus Lee <seamuslee001@gmail.com>
Wed, 5 Aug 2015 23:56:20 +0000 (23:56 +0000)
committerSeamus Lee <seamuslee001@gmail.com>
Wed, 5 Aug 2015 23:59:18 +0000 (23:59 +0000)
CRM/ACL/API.php
CRM/Mailing/Info.php
api/v3/Group.php

index f3681b3fa8702eb91c056b0150f1f95fd82cb7d1..675beb80de3fa91c5d0b105446936a7c269e4fb8 100644 (file)
@@ -227,6 +227,9 @@ class CRM_ACL_API {
       $groups = self::group($type, $contactID, $tableName, $allGroups, $includedGroups);
       $cache[$key] = $groups;
     }
+    if (empty($groups)) {
+      return FALSE;
+    }
 
     return in_array($groupID, $groups) ? TRUE : FALSE;
   }
index 1905d16ed0dc47b8fc8cee0b4d5fa547d8c5740d..b38946c9dfe66ae5d9867e1b1c09adafd58eda6a 100644 (file)
@@ -117,6 +117,7 @@ class CRM_Mailing_Info extends CRM_Core_Component_Info {
 
     $groupNames = civicrm_api3('Group', 'get', $params + array(
       'is_active' => 1,
+      'check_permissions' => TRUE,
       'return' => array('title', 'visibility', 'group_type', 'is_hidden'),
     ));
     $headerfooterList = civicrm_api3('MailingComponent', 'get', $params + array(
index a5d7cfeb231af4c72448fba2800e3003cbc7f6da..d0fe9e99ad65c690887d232f2d88ec4fc4fbfe42 100644 (file)
@@ -71,13 +71,18 @@ function _civicrm_api3_group_create_spec(&$params) {
  */
 function civicrm_api3_group_get($params) {
   $options = _civicrm_api3_get_options_from_params($params, TRUE, 'Group', 'get');
-  if (empty($options['return']) || !in_array('member_count', $options['return'])) {
+  if ((empty($options['return']) || !in_array('member_count', $options['return'])) && empty($params['check_permissions'])) {
     return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Group');
   }
 
   $groups = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE, 'Group');
   foreach ($groups as $id => $group) {
-    $groups[$id]['member_count'] = CRM_Contact_BAO_Group::memberCount($id);
+    if(!empty($params['check_permissions']) && !CRM_Contact_BAO_Group::checkPermission($group['id'])) {
+      unset($groups[$id]);
+    }
+    elseif (!empty($options['return']) && in_array('member_count', $options['return'])) {
+      $groups[$id]['member_count'] = CRM_Contact_BAO_Group::memberCount($id);
+    }
   }
   return civicrm_api3_create_success($groups, $params, 'Group', 'get');
 }