CRM-16796 - Add ACL support for profile related api's
authorjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Fri, 3 Jul 2015 13:34:20 +0000 (19:04 +0530)
committerjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Fri, 10 Jul 2015 04:46:06 +0000 (10:16 +0530)
Civi/API/Subscriber/PermissionCheck.php

index 49caac2ddcb916746ea059539013848a4df39be8..b427fa0a05b3e19db1f78a304dd4bbd26e1aaa80 100644 (file)
@@ -73,7 +73,7 @@ class PermissionCheck implements EventSubscriberInterface {
         return;
       }
 
-      if (!\CRM_Core_Permission::check($permissions)) {
+      if (!\CRM_Core_Permission::check($permissions) and !self::checkACLPermission($apiRequest)) {
         if (is_array($permissions)) {
           $permissions = implode(' and ', $permissions);
         }
@@ -87,4 +87,26 @@ class PermissionCheck implements EventSubscriberInterface {
     }
   }
 
+  /**
+   * check API for ACL permission.
+   * @param $apiRequest
+   * @return boolean
+   */
+  public function checkACLPermission($apiRequest) {
+    switch($apiRequest['entity']) {
+      case 'UFGroup':
+      case 'UFField':
+        $ufGroups = \CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id');
+        $aclCreate = \CRM_ACL_API::group(\CRM_Core_Permission::CREATE, NULL, 'civicrm_uf_group', $ufGroups);
+        $aclEdit = \CRM_ACL_API::group(\CRM_Core_Permission::EDIT, NULL, 'civicrm_uf_group', $ufGroups);
+        $ufGroupId = $apiRequest['entity'] == 'UFGroup' ? $apiRequest['params']['id'] : $apiRequest['params']['uf_group_id'];
+        if (in_array($ufGroupId, $aclEdit) or $aclCreate) {
+          return TRUE;
+        }
+        break;
+    }
+
+    return FALSE;
+  }
+
 }