Fix dev/core#4971 - Skip redundant permission checks in CRM_Admin_Form_ScheduleReminders
authorcolemanw <coleman@civicrm.org>
Wed, 7 Feb 2024 03:15:14 +0000 (22:15 -0500)
committercolemanw <coleman@civicrm.org>
Wed, 7 Feb 2024 03:15:14 +0000 (22:15 -0500)
Temporary override to solve https://lab.civicrm.org/dev/core/-/issues/4971
This regressed in https://github.com/civicrm/civicrm-core/pull/27003 which
switched $this->retrieveMethod to 'api' - this had the unintended effect of checking
permissions during retrieveValues(), but the API is not sophisticated enough: we need to
add
a `CRM_Core_BAO_ActionSchedule::addSelectWhereClause()` function that can handle the logic
of "if the reminder is for an event, check user has edit permission for that specific
event".

Meanwhile we can skip permission checks in the form layer, because that logic is
implemented here,
specifically in `\CRM_Event_ActionMapping::checkAccess()`.

CRM/Admin/Form/ScheduleReminders.php

index eee74938962da301ef7816baca9a21f18672b6ca..034b96fef3c2fcf034ed8b686d76d402c0d17100 100644 (file)
@@ -24,6 +24,30 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form {
 
   protected $retrieveMethod = 'api4';
 
+  /**
+   * Temporary override to solve https://lab.civicrm.org/dev/core/-/issues/4971
+   * This regressed in https://github.com/civicrm/civicrm-core/pull/27003 which
+   * switched $this->retrieveMethod to 'api' - this had the unintended effect of checking
+   * permissions during retrieveValues(), but the API is not sophisticated enough: we need to add
+   * a `CRM_Core_BAO_ActionSchedule::addSelectWhereClause()` function that can handle the logic
+   * of "if the reminder is for an event, check user has edit permission for that specific event".
+   *
+   * Meanwhile we can skip permission checks in the form layer, because that logic is implemented here,
+   * specifically in `\CRM_Event_ActionMapping::checkAccess()`.
+   *
+   * @return array
+   */
+  protected function retrieveValues(): array {
+    $this->_values = [];
+    if (isset($this->_id) && CRM_Utils_Rule::positiveInteger($this->_id)) {
+      $this->_values = civicrm_api4($this->getDefaultEntity(), 'get', [
+        'checkPermissions' => FALSE,
+        'where' => [['id', '=', $this->_id]],
+      ])->single();
+    }
+    return $this->_values;
+  }
+
   /**
    * @return string
    */