APIv4 - Map specific action names to more generic versions
authorColeman Watts <coleman@civicrm.org>
Sat, 12 Sep 2020 01:03:36 +0000 (21:03 -0400)
committerColeman Watts <coleman@civicrm.org>
Sat, 12 Sep 2020 15:10:15 +0000 (11:10 -0400)
Civi/Api4/Generic/AbstractAction.php

index 8d0111e6b35dccafc9fda3949ca5ad8ec4b11a7a..fa995ce0d8d4acf2e7728940e85d1d824a928af6 100644 (file)
@@ -407,13 +407,15 @@ abstract class AbstractAction implements \ArrayAccess {
       'default' => ['administer CiviCRM'],
     ];
     $action = $this->getActionName();
-    if (isset($permissions[$action])) {
-      return $permissions[$action];
-    }
-    elseif (in_array($action, ['getActions', 'getFields'])) {
-      return $permissions['meta'];
-    }
-    return $permissions['default'];
+    // Map specific action names to more generic versions
+    $map = [
+      'getActions' => 'meta',
+      'getFields' => 'meta',
+      'replace' => 'delete',
+      'save' => 'create',
+    ];
+    $generic = $map[$action] ?? 'default';
+    return $permissions[$action] ?? $permissions[$generic] ?? $permissions['default'];
   }
 
   /**