Skip to content

Scoped the paragraph create-access opinion to non-HTML requests. - #294

Merged
AlexSkrypnyk merged 1 commit into
developfrom
feature/paragraph-access
Aug 5, 2026
Merged

Scoped the paragraph create-access opinion to non-HTML requests.#294
AlexSkrypnyk merged 1 commit into
developfrom
feature/paragraph-access

Conversation

@AlexSkrypnyk

Copy link
Copy Markdown
Member

Checklist before requesting a review

  • Subject includes ticket number as [#123] Verb in past tense.
  • Ticket number #123 added to description
  • Added context in Changed section
  • Self-reviewed code and commented in commented complex areas.
  • Added tests for fix/feature.
  • Relevant tests run and passed locally.

Changed

  1. Injected RequestStack into EntityCreateAccessHook and returned AccessResult::neutral() whenever the current request format is html, before the API allow-list is evaluated - so the hook only opines on non-HTML (API) requests, which is the gap it was written to close.
  2. Added the request_format cache context to every return path in the hook, since the outcome now depends on it.
  3. Registered EntityCreateAccessHook in do_content_api.services.yml with the @request_stack argument, following the existing ModerationPolicyHook service pattern.
  4. Extended EntityCreateAccessHookTest's data provider with a $request_format dimension and three new cases: HTML request with a disallowed bundle (neutral), HTML request with an allowed bundle (neutral), and no current request at all (still forbidden).

Screenshots

Page content type Components dropdown listing all 17 paragraph types after the fix

Before / After

BEFORE
──────
Administrator adds a paragraph on an HTML admin form (e.g. Page > Components)
                            │
                            ▼
        EntityCreateAccessHook::entityCreateAccess()
        $account->hasPermission('use content authoring api')
                            │
              administrator is_admin => TRUE (misidentified as API client)
                            │
                            ▼
              bundle in ALLOWED_PARAGRAPH_BUNDLES?
                    │                    │
                   yes                   no
                    │                    │
                    ▼                    ▼
                allowed              forbidden
                                         │
                                         ▼
                          short-circuits createAccess() -
                          ParagraphAccessControlHandler's
                          "allow on HTML requests" rule never runs
                                         │
                                         ▼
                     Components dropdown: 7 of 17 options

AFTER
─────
Administrator adds a paragraph on an HTML admin form (e.g. Page > Components)
                            │
                            ▼
        EntityCreateAccessHook::entityCreateAccess()
        $requestStack->getCurrentRequest()?->getRequestFormat()
                            │
                     === 'html' => neutral()
                            │
                            ▼
        ParagraphAccessControlHandler::checkCreateAccess()
        applies its "allow on HTML requests" rule
                            │
                            ▼
                     Components dropdown: 17 of 17 options

        (Non-HTML / API requests are unaffected - the allow-list in
        EntityCreateAccessHook still governs them exactly as before.)

The 'use content authoring api' gate also matched every role with 'is_admin', so administrators were treated as API clients and denied create access to 19 of 35 paragraph bundles in the node forms.
@AlexSkrypnyk AlexSkrypnyk added the AUTOMERGE Pull request has been approved and set to automerge label Aug 5, 2026
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 11 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 57cdd57c-ba09-4aa0-8206-25715e87b8b9

📥 Commits

Reviewing files that changed from the base of the PR and between cb38d59 and 97d4932.

📒 Files selected for processing (3)
  • web/modules/custom/do_content_api/do_content_api.services.yml
  • web/modules/custom/do_content_api/src/Hook/EntityCreateAccessHook.php
  • web/modules/custom/do_content_api/tests/src/Unit/Hook/EntityCreateAccessHookTest.php

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

Code coverage (threshold: 80%)

  Classes: 45.45% (10/22)
  Methods: 70.97% (44/62)
  Lines:   86.48% (518/599)
Per-class coverage
Drupal\do_ai_alt_text\AltTextGenerator
  Methods:  85.71% ( 6/ 7)   Lines:  98.72% ( 77/ 78)
Drupal\do_ai_alt_text\Plugin\Action\RegenerateImageAltText
  Methods: 100.00% ( 8/ 8)   Lines: 100.00% ( 63/ 63)
Drupal\do_base\EventSubscriber\PreviewLinkCacheSubscriber
  Methods:  33.33% ( 1/ 3)   Lines:  11.11% (  1/  9)
Drupal\do_base\EventSubscriber\ThemeColorSubscriber
  Methods:  66.67% ( 2/ 3)   Lines:  40.00% (  4/ 10)
Drupal\do_content_api\EventSubscriber\JsonApiWriteGateSubscriber
  Methods:  66.67% ( 2/ 3)   Lines:  88.89% (  8/  9)
Drupal\do_content_api\Hook\EntityCreateAccessHook
  Methods: 100.00% ( 2/ 2)   Lines: 100.00% ( 12/ 12)
Drupal\do_content_api\Hook\ModerationPolicyHook
  Methods:  50.00% ( 1/ 2)   Lines:  93.75% ( 15/ 16)
Drupal\do_content_api\Routing\RouteSubscriber
  Methods: 100.00% ( 1/ 1)   Lines: 100.00% (  6/  6)
Drupal\do_feed\FeedUrlBuilder
  Methods: 100.00% ( 4/ 4)   Lines: 100.00% ( 18/ 18)
Drupal\do_feed\Form\FeedSettingsForm
  Methods: 100.00% ( 4/ 4)   Lines: 100.00% ( 15/ 15)
Drupal\do_feed\Hook\EntityDeleteHook
  Methods:  50.00% ( 1/ 2)   Lines:  92.31% ( 12/ 13)
Drupal\do_feed\Hook\EntityPresaveHook
  Methods: 100.00% ( 4/ 4)   Lines: 100.00% ( 54/ 54)
Drupal\do_feed\Hook\PreprocessParagraphHook
  Methods: 100.00% ( 2/ 2)   Lines: 100.00% ( 14/ 14)
Drupal\do_feed\Hook\PreprocessViewsViewRowRssHook
  Methods: 100.00% ( 1/ 1)   Lines: 100.00% (  3/  3)
Drupal\do_feed\Hook\ViewsPreViewHook
  Methods:  50.00% ( 1/ 2)   Lines:  96.43% ( 27/ 28)
Drupal\do_generated_content\Generator\CaseMatrix
  Methods: 100.00% ( 3/ 3)   Lines: 100.00% ( 12/ 12)
Drupal\do_generated_content\Generator\RelativeDate
  Methods: 100.00% ( 1/ 1)   Lines: 100.00% (  1/  1)

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.62%. Comparing base (cb38d59) to head (97d4932).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #294      +/-   ##
===========================================
+ Coverage    81.49%   81.62%   +0.13%     
===========================================
  Files           23       23              
  Lines          416      419       +3     
===========================================
+ Hits           339      342       +3     
  Misses          77       77              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@AlexSkrypnyk AlexSkrypnyk added the Needs review Pull request needs a review from assigned developers label Aug 5, 2026
@AlexSkrypnyk
AlexSkrypnyk merged commit fbf2590 into develop Aug 5, 2026
10 checks passed
@AlexSkrypnyk
AlexSkrypnyk deleted the feature/paragraph-access branch August 5, 2026 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AUTOMERGE Pull request has been approved and set to automerge Needs review Pull request needs a review from assigned developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants