Skip to content

Commit

Permalink
Merge pull request #24186 from colemanw/groupContactPerm
Browse files Browse the repository at this point in the history
APIv4 - Fix GroupContact permission to use standard ACLs
  • Loading branch information
colemanw authored Aug 17, 2022
2 parents feb3bed + 3e11a43 commit e73b274
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CRM/Contact/BAO/GroupContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact implements HookInterface {
use CRM_Contact_AccessTrait;

/**
* Deprecated add function
Expand Down
4 changes: 3 additions & 1 deletion CRM/Core/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,9 @@ public static function getEntityActionPermissions() {
$permissions['group_nesting'] = $permissions['group'];
$permissions['group_organization'] = $permissions['group'];

//Group Contact permission
// Note: The v3 GroupContact API is nonstandard and not easy to fix, so these permissions
// are unnecessarily strict for v3. The v4 API overrides them.
// @see Civi\Api4\GroupContact::permissions
$permissions['group_contact'] = [
'get' => [
'access CiviCRM',
Expand Down
12 changes: 12 additions & 0 deletions Civi/Api4/GroupContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,16 @@ public static function getInfo() {
return $info;
}

/**
* Returns a list of permissions needed to access the various actions in this api.
*
* @return array
*/
public static function permissions() {
// Override CRM_Core_Permission::getEntityActionPermissions() because the v3 API is nonstandard
return [
'default' => ['access CiviCRM'],
];
}

}
4 changes: 4 additions & 0 deletions tests/phpunit/api/v3/ACLPermissionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ public function testRelatedEntityPermissions(int $version): void {
'location_type_id' => 1,
],
];
// v3 GroupContact API is nonstandard
if ($version === 4) {
$testEntities['GroupContact'] = ['group_id' => $this->groupCreate()];
}
foreach ($testEntities as $entity => $params) {
$params += [
'contact_id' => $disallowedContact,
Expand Down

0 comments on commit e73b274

Please sign in to comment.