From da9dfd3a2843163e20a786e4d695dfefa8c4e1b1 Mon Sep 17 00:00:00 2001
From: Seamus Lee <seamuslee001@gmail.com>
Date: Sat, 15 Jul 2023 11:15:30 +1000
Subject: [PATCH] Ensure that we only check permissions if we want to in
 getActions follow up to #26823

Make it more readable as per coleman
---
 Civi/Api4/Action/GetActions.php                | 4 ++--
 tests/phpunit/api/v4/Action/GetActionsTest.php | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/Civi/Api4/Action/GetActions.php b/Civi/Api4/Action/GetActions.php
index 1705a10b26..1442543308 100644
--- a/Civi/Api4/Action/GetActions.php
+++ b/Civi/Api4/Action/GetActions.php
@@ -79,8 +79,8 @@ class GetActions extends BasicGetAction {
     try {
       if (!isset($this->_actions[$actionName]) && (!$this->_actionsToGet || in_array($actionName, $this->_actionsToGet))) {
         $action = \Civi\API\Request::create($this->getEntityName(), $actionName, ['version' => 4]);
-        $authorized = \Civi::service('civi_api_kernel')->runAuthorize($this->getEntityName(), $actionName, ['version' => 4]);
-        if (is_object($action) && (!$this->checkPermissions || $authorized)) {
+        $authorized = !$this->checkPermissions || \Civi::service('civi_api_kernel')->runAuthorize($this->getEntityName(), $actionName, ['version' => 4]);
+        if (is_object($action) && $authorized) {
           $this->_actions[$actionName] = ['name' => $actionName];
           if ($this->_isFieldSelected('description', 'comment', 'see')) {
             $vars = ['entity' => $this->getEntityName(), 'action' => $actionName];
diff --git a/tests/phpunit/api/v4/Action/GetActionsTest.php b/tests/phpunit/api/v4/Action/GetActionsTest.php
index f251aa65b7..69a7cd99b1 100644
--- a/tests/phpunit/api/v4/Action/GetActionsTest.php
+++ b/tests/phpunit/api/v4/Action/GetActionsTest.php
@@ -43,7 +43,7 @@ class GetActionsTest extends Api4TestBase implements HookInterface, Transactiona
     }
   }
 
-  public function testContactIconAutocomplete(): void {
+  public function testActionPermissionsOverride(): void {
     $contact = $this->createTestRecord('Contact', [
       'first_name' => 'GetActions',
       'last_name' => 'testContact',
-- 
2.25.1