foreach ($fullPath as $link) {
$target = $link->getTargetTable();
$alias = $link->getAlias();
- $conditions = $link->getConditionsForJoin($baseTable);
+ $bao = \CRM_Core_DAO_AllCoreTables::getBAOClassName(\CRM_Core_DAO_AllCoreTables::getClassForTable($target));
+ $conditions = array_merge(
+ $link->getConditionsForJoin($baseTable),
+ $query->getAclClause($alias, $bao, explode('.', $joinPath))
+ );
$query->join($side, $target, $alias, $conditions);
}
+ /**
+ * @param int $version
+ * @dataProvider versionThreeAndFour
+ */
+ public function testContactGetViaJoin($version) {
+ $this->_apiversion = $version;
+ $this->createLoggedInUser();
+ $main = $this->individualCreate(['first_name' => 'Main']);
+ $other = $this->individualCreate(['first_name' => 'Other'], 1);
+ $tag1 = $this->tagCreate(['name' => uniqid('created'), 'created_id' => $main])['id'];
+ $tag2 = $this->tagCreate(['name' => uniqid('other'), 'created_id' => $other])['id'];
+ $this->setPermissions(['access CiviCRM']);
+ $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereHookAllResults']);
+ $createdFirstName = $version == 4 ? 'created.first_name' : 'created_id.first_name';
+ $result = $this->callAPISuccess('Tag', 'get', [
+ 'check_permissions' => 1,
+ 'return' => ['id', $createdFirstName],
+ 'id' => ['IN' => [$tag1, $tag2]],
+ ]);
+ $this->assertEquals('Main', $result['values'][$tag1][$createdFirstName]);
+ $this->assertEquals('Other', $result['values'][$tag2][$createdFirstName]);
+ $this->allowedContactId = $main;
+ $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereOnlyOne']);
+ $this->cleanupCachedPermissions();
+ $result = $this->callAPISuccess('Tag', 'get', [
+ 'check_permissions' => 1,
+ 'return' => ['id', $createdFirstName],
+ 'id' => ['IN' => [$tag1, $tag2]],
+ ]);
+ $this->assertEquals('Main', $result['values'][$tag1][$createdFirstName]);
+ $this->assertEquals($tag2, $result['values'][$tag2]['id']);
+ $this->assertFalse(isset($result['values'][$tag2][$createdFirstName]));
+ }
+
}