Skip to content

Commit

Permalink
Fix permission for SubscriptionHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
wmortada committed Oct 12, 2022
1 parent 1b878aa commit c76ec9f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Civi/Api4/SubscriptionHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,15 @@
*/
class SubscriptionHistory extends Generic\DAOEntity {

/**
* @see \Civi\Api4\Generic\AbstractEntity::permissions()
* @return array
*/
public static function permissions() {
// get permission is managed by ACLs
return [
'get' => [],
];
}

}
39 changes: 39 additions & 0 deletions tests/phpunit/api/v4/Entity/SubscriptionHistoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,43 @@ public function testGet() {
$this->assertLessThanOrEqual(time(), strtotime($historyRemoved->single()['date']));
}

public function testGetPermissions() {
$this->createLoggedInUser();

$contact = $this->createTestRecord('Contact');
$group = $this->createTestRecord('Group');
$groupContact = $this->createTestRecord('GroupContact', [
'group_id' => $group['id'],
'contact_id' => $contact['id'],
]);

\CRM_Core_Config::singleton()->userPermissionClass->permissions = [
'access CiviCRM',
'view all contacts',
];

$historyAdded = SubscriptionHistory::get()
->addSelect('*')
->addWhere('group_id', '=', $group['id'])
->addWhere('status', '=', 'Added')
->addWhere('contact_id', '=', $contact['id'])
->execute();
$this->assertCount(1, $historyAdded);

\CRM_Core_Config::singleton()->userPermissionClass->permissions = [];

try {
$historyAdded = SubscriptionHistory::get()
->addSelect('*')
->addWhere('group_id', '=', $group['id'])
->addWhere('status', '=', 'Added')
->addWhere('contact_id', '=', $contact['id'])
->execute();
$this->assertCount(0, $historyAdded);
}
catch (UnauthorizedException $e) {
}

}

}

0 comments on commit c76ec9f

Please sign in to comment.