Add reason when denied access to `api.config.get`

Created on 2 July 2025, 5 days ago

Overview

When access to `api.config.get` is denied (e.g. /xb/api/v0/config/js_component/xxxx) there is no reason shown in the errors array.

Proposed resolution

Add reason when denied access to `api.config.get`.

\Drupal\experience_builder\EntityHandlers\VisibleWhenDisabledXbConfigEntityAccessControlHandler::checkAccess

      'view' => AccessResult::allowedIf($account->isAuthenticated())->addCacheContexts(['user.roles:authenticated'])->setReason('....'),

User interface changes

📌 Task
Status

Active

Version

0.0

Component

Internal HTTP API

Created by

🇪🇸Spain penyaskito Seville 💃, Spain 🇪🇸, UTC+2 🇪🇺

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @penyaskito
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    👍

  • First commit to issue fork.
  • Pipeline finished with Failed
    5 days ago
    Total: 1131s
    #537173
  • 🇮🇳India libbna New Delhi, India

    I initially tried this code:

    'view' => AccessResult::allowedIf($account->isAuthenticated())
      ->addCacheContexts(['user.roles:authenticated'])
      ->setReason('....'),

    However, when accessing the path /xb/api/v0/config/js_component/xxxx as an authenticated user, it threw the following error: Call to undefined method Drupal\Core\Access\AccessResultAllowed::setReason()

    After checking, I realized that setReason() only works with AccessResult::forbidden(), not with AccessResultAllowed.

    I then updated the code to apply setReason() only when access is denied. After this change, I tested the api.config.get endpoint as an anonymous user and was able to see the error message with the reason.

    Please let me know if the message shown is appropriate or if any further changes are needed.

  • 🇮🇳India libbna New Delhi, India
  • Pipeline finished with Failed
    5 days ago
    Total: 1835s
    #537211
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
Production build 0.71.5 2024