Skip to content

fix: Request taxonomies with view context for Author/Editor roles - #23291

Open
dcalhoun wants to merge 3 commits into
trunkfrom
fix/cmm-2398-author-category-picker
Open

fix: Request taxonomies with view context for Author/Editor roles#23291
dcalhoun wants to merge 3 commits into
trunkfrom
fix/cmm-2398-author-category-picker

Conversation

@dcalhoun

@dcalhoun dcalhoun commented Sep 3, 2026

Copy link
Copy Markdown
Member

Description

Fix CMM-2398.

An Author or Contributor on an Atomic or self-hosted site got a blocking "Category refresh error" when opening the category picker in the post editor, and could not assign categories at all. Switching the user to Editor cleared it.

Root cause. TaxonomyRsApiRestClient.fetchTerms listed terms with listWithEditContext, i.e. GET /wp/v2/categories?context=edit. WP core gates that context on the taxonomy's edit_terms capability — manage_categories for category, manage_post_tags for post_tag — which Authors and Contributors do not hold, so the API answered 403 rest_forbidden_context. The client turned that into a generic error and the picker reported a refresh failure instead of listing the site's terms.

Listing terms is a read, and the view context returns every field this client maps (no term field is edit-only, and name/description are identical across contexts), so it now requests context=view.

Scope. The taxonomies_rest_api_migration flag is rolled out to 50% of users on 26.9+, so this affects Authors and Contributors on Atomic and self-hosted sites, for both categories and tags. The tags breakage was silent: TagsFragment ignores fetch errors, so tag suggestions simply came back empty.

Testing instructions

Note

Requires a test user set to Author on an Atomic site. The taxonomies_rest_api_migration feature flag must be enabled in the dev menu.

Note that SelectCategoriesActivity only fetches when its list is empty, so clear app storage or sign out and back in before each cold-cache run — a warm cache hides the bug.

Categories (the reported issue):

  1. On trunk, as the Author, open a post → Post Settings → Categories.
  • Verify the blocking "Category refresh error" appears and no categories are listed
  1. Switch to this branch, clear app storage, sign in as the same Author, and repeat.
  • Verify the category list loads
  • Verify selecting categories persists back to the post

Tags (same fix, no cache clearing needed):

  1. As the Author, open a post → Post Settings → Tags and type a letter.
  • Verify existing tag suggestions appear (on trunk they are silently empty)

Refresh failure handling (unchanged from trunk):

  1. With categories already loaded, use a proxy to fail */categories* with a 500, then pull to refresh.
  • Verify the cached list stays on screen and a "Category refresh error" toast appears

Regressions:

  1. As an Editor or Admin on the same Atomic site, open the category picker and create a category from the "+" menu.
  • Verify the list loads and creation still works
  1. Open Site Settings → Categories.
  • Verify create, rename and delete still work1
  1. Repeat the category picker check on a WP.com Simple site and on a self-hosted site with an application password.
  • Verify both still list categories

🤖 Generated with Claude Code

https://claude.ai/code/session_01Y3eKPoHZwqK4AP3GQBSgEG

Footnotes

  1. Deleting is broken: https://github.com/wordpress-mobile/WordPress-Android/issues/23293

@dcalhoun dcalhoun changed the title CMM-2398: Request taxonomy terms in the view context fix: Request taxonomies with view context for Author/Editor roles Sep 3, 2026
@wpmobilebot

wpmobilebot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in WordPress Android by scanning the QR code below to install the corresponding build.

App NameWordPress Android
Build TypeDebug
Versionpr23291-6fdfbfe
Build Number1498
Application IDorg.wordpress.android.prealpha
Commit6fdfbfe
Installation URL10v12f7f51mbo
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in Jetpack Android by scanning the QR code below to install the corresponding build.

App NameJetpack Android
Build TypeDebug
Versionpr23291-6fdfbfe
Build Number1498
Application IDcom.jetpack.android.prealpha
Commit6fdfbfe
Installation URL5u3muj5a21mj0
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.93%. Comparing base (b8157ff) to head (6fdfbfe).

Files with missing lines Patch % Lines
...ork/rest/wpapi/taxonomy/TaxonomyRsApiRestClient.kt 81.81% 2 Missing and 4 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            trunk   #23291   +/-   ##
=======================================
  Coverage   37.93%   37.93%           
=======================================
  Files        2352     2352           
  Lines      128925   128938   +13     
  Branches    17940    17948    +8     
=======================================
+ Hits        48907    48916    +9     
  Misses      76012    76012           
- Partials     4006     4010    +4     

☔ 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.

@dcalhoun
dcalhoun force-pushed the fix/cmm-2398-author-category-picker branch from 26fd45e to 08a3f76 Compare September 3, 2026 19:15
dcalhoun and others added 3 commits September 3, 2026 15:34
Listing categories and tags over wordpress-rs used context=edit, which WP
core gates on the taxonomy's edit_terms capability (manage_categories /
manage_post_tags). Authors and Contributors hold neither, so the REST API
answered 403 rest_forbidden_context and the post editor's picker reported
a refresh error instead of listing the site's terms. The listing is a read
and the view context carries every field this client maps, so request that
instead.

Term failures now also map 401 and 403 to TaxonomyErrorType.UNAUTHORIZED,
keeping the parity TaxonomyXMLRPCClient already has as the wp-rs path
replaces it. No caller branches on the type yet, so this shows up only in
the taxonomy log lines. Failures are logged through toLogErrorString()
rather than interpolating the raw result, which put response bodies in the
log.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y3eKPoHZwqK4AP3GQBSgEG
notifyFailedDeleting() wrote one line for two different failures, and once it
took the request result it logged a literal null for the case where the request
succeeded and the API reported the term as not deleted. Log at the call sites
instead, where the result is still in scope, so the two are distinguishable,
and let the function take the error it dispatches.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y3eKPoHZwqK4AP3GQBSgEG
createTestAnyTermWithViewContext() was a field-for-field copy of
createTestAnyTermWithEditContext(), so every change to the term under test had
to be made twice and a test updating only one would assert against divergent
data. The generated edit and view types share no supertype, so keep the values
in one place and build each type from them.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y3eKPoHZwqK4AP3GQBSgEG
@dcalhoun
dcalhoun force-pushed the fix/cmm-2398-author-category-picker branch from 08a3f76 to 6fdfbfe Compare September 3, 2026 19:35
@dcalhoun
dcalhoun marked this pull request as ready for review September 3, 2026 19:48
@dcalhoun
dcalhoun requested a review from adalpari September 3, 2026 19:48
@dcalhoun dcalhoun added this to the 27.2 milestone Sep 3, 2026
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.

2 participants