Skip to content

Align MCP ability capability checks - #1302

Merged
sandyfzu merged 7 commits into
developfrom
fix/6777-abilities-caps
Oct 30, 2026
Merged

sandyfzu merged 7 commits into
developfrom
fix/6777-abilities-caps

Conversation

@remyperona

@remyperona remyperona commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

Aligns the capability checks of some MCP abilities with the context capability abstraction already used by the rest of the plugin. Details are in the linked issue.

Type of change

  • Bug fix (non-breaking change which fixes an issue).

Detailed scenario

What was tested

Automated: composer test-unit, the Abilities integration group (single-site and multisite), composer phpcs, composer run-stan, all passing.

How to test

Run the Abilities integration group, also with WP_MULTISITE=1.

Affected Features & Quality Assurance Scope

MCP abilities. See the linked issue.

Technical description

Documentation

See the linked issue.

New dependencies

None.

Risks

See the linked issue.

Mandatory Checklist

Code validation

  • I validated all the Acceptance Criteria. If possible, provide screenshots or videos.
  • I triggered all changed lines of code at least once without new errors/warnings/notices.
  • I implemented built-in tests to cover the new/changed code.

Code style

  • I wrote a self-explanatory code about what it does.
  • I protected entry points against unexpected inputs.
  • I did not introduce unnecessary complexity.
  • Output messages (errors, notices, logs) are explicit enough for users to understand the issue and are actionnable.

Unticked items justification

Not applicable.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codacy-production

codacy-production Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 5 complexity · 0 duplication

Metric Results
Complexity 5
Duplication 0

View in Codacy

🟢 Coverage 52.17% diff coverage

Metric Results
Coverage variation Report missing for fcc39a21
Diff coverage ✅ 52.17% diff coverage (50.00%)

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (fcc39a2) Report Missing Report Missing Report Missing
Head commit (b1c6f4c) 20563 1663 8.09%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#1302) 23 12 52.17%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

1 Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@remyperona remyperona changed the title Closes wp-media/wp-rocket.me#6777: align MCP ability capability checks Align MCP ability capability checks Oct 26, 2026
remyperona and others added 2 commits October 26, 2026 11:42
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@remyperona
remyperona requested a review from a team October 26, 2026 16:14
@mostafa-hisham

Copy link
Copy Markdown
Contributor

Note

Generated by the AI delivery pipeline (lead-reviewer · Claude Sonnet 5.5).

Review: CHANGES REQUESTED (2 MEDIUM, no security or logic blockers)

I could not find the linked issue (#6777 does not exist in this repo), so I judged the PR on: shared capability abstraction, single-site/multisite behaviour, privilege escalation, test coverage, and conventions. I did not run PHPUnit, PHPCS or PHPStan.

Verdict on the criteria

  1. Capability checks go through the shared abstraction: yes, for the three abilities changed. BulkOptimize, GenerateMissingNextgen and RestoreMedia now use imagify_get_context(...)->current_user_can(...) instead of raw manage_options. After this PR no ability in classes/Abilities uses a raw capability check.
  2. Single-site and multisite: correct and consistent with the legacy AJAX paths. manage resolves to manage_network_options when Imagify is network-activated. Custom-folders bulk-optimize, manual-restore and manual-optimize resolve to manage_network_options on any multisite, so a subsite admin can no longer run custom-folder operations through MCP.
  3. Privilege escalation: none introduced. Every check is stricter than before. RestoreMedia now checks manual-restore with the media_id (edit_post on the specific attachment for library media). GenerateMissingNextgen is all-or-nothing across contexts, so a subsite admin is denied entirely, even for the library. I read this as intentional parity with the legacy handler; please confirm.
  4. Tests: reasonable coverage, with a multisite gap (see below).
  5. Conventions: fixture-driven data-provider style followed. Codacy's "UnusedCode" is most likely the unused $input in the default AbstractAbility::has_input_permission().

Blockers

  • [MEDIUM] docs/api/mcp.md (~lines 191-480, not in the diff): imagify/bulk-optimize, imagify/generate-missing-nextgen and imagify/restore-media are still documented as requiring manage_options. Update them to the Imagify manage capability plus the per-context bulk-optimize / manual-restore requirement, noting that manage is manage_network_options when network-activated and that custom folders need manage_network_options on multisite. The required capability is an observable behaviour change.
  • [MEDIUM] Tests/Integration/classes/Abilities/*/CheckPermissionsTest.php and fixtures: multisite coverage never exercises the network-activated branch (imagify_is_active_for_network() true), where manage becomes manage_network_options. Current cases only toggle super admin and the imagify_capacity filter, and the unit tests mock the contexts so they never evaluate real capabilities. Add at least one case (e.g. BulkOptimize, wp context, network-active) asserting a subsite admin is denied and a super admin allowed, with matching fixture rows.

Nice-to-haves

  • AbstractAbility::check_permissions(): a denial from has_input_permission() still fires imagify_mcp_permission_denied with get_required_capability() (manage), and the new unit tests enshrine this (e.g. shouldDenyCustomFoldersWithoutTheirCapability). The replaced code had guards so analytics reported the capability actually checked. Consider reporting bulk-optimize / manual-restore, or documenting the limitation.
  • AbilitiesInterface::check_permissions(): bool (line ~33): update the signature and docblock to accept the optional input, matching AbstractAbility and RestoreMedia.
  • OptimizeMedia (unchanged, line ~128): the docblock says check_permissions() receives no media_id, which this PR makes false. Either check manual-optimize per media like RestoreMedia, or reword.
  • RestoreMedia: get_process() runs in both check_permissions() and execute(). Acceptable, but could be memoized.
  • AbstractAbility::has_input_permission( array $input ): unused parameter in the default implementation. Add a targeted suppression to quiet Codacy.

Spec compliance (derived)

Item Status
BulkOptimize: manage in wp context, then bulk-optimize in the requested context Done
GenerateMissingNextgen: manage plus bulk-optimize on every context in Bulk::get_contexts() Done
RestoreMedia: manage plus manual-restore on the media's context, with media_id Done
Remaining abilities already use the abstraction Done
Network-activated multisite path tested Partial
Docs updated Missing

remyperona and others added 3 commits October 27, 2026 02:07
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread classes/Abilities/AbstractAbility.php Resolved
…t input check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sandyfzu
sandyfzu self-requested a review October 29, 2026 16:55
@sandyfzu
sandyfzu added this pull request to the merge queue Oct 30, 2026
Merged via the queue into develop with commit dd0523c Oct 30, 2026
14 checks passed
@sandyfzu
sandyfzu deleted the fix/6777-abilities-caps branch October 30, 2026 02:46
@remyperona remyperona mentioned this pull request Oct 30, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants