Skip to content

Fix #1313: extra_capabilities parsing issue in the /wp/v2/users response#1314

Merged
crazytonyli merged 4 commits intotrunkfrom
bugfix/1313-user-extra-cap
May 4, 2026
Merged

Fix #1313: extra_capabilities parsing issue in the /wp/v2/users response#1314
crazytonyli merged 4 commits intotrunkfrom
bugfix/1313-user-extra-cap

Conversation

@crazytonyli
Copy link
Copy Markdown
Contributor

Description

Use the same approach in #1263, with integration tests for #1313 and #1263

@wpmobilebot
Copy link
Copy Markdown
Collaborator

wpmobilebot commented May 3, 2026

XCFramework Build

This PR's XCFramework is available for testing. Add to your Package.swift:

.package(url: "https://github.com/automattic/wordpress-rs", branch: "pr-build/1314")

Built from dc1932e

@crazytonyli crazytonyli enabled auto-merge (squash) May 4, 2026 20:54
Add two fixture admin users to the integration test setup whose
`wp_capabilities` usermeta is poisoned via `wp eval` to exercise the two
non-bool shapes that break clients today:

- `legacy_admin` carries `{"administrator": "1"}`, mimicking pre-2012 WP
  sites whose role assignments were written as the string `"1"`. This is
  the exact failure mode reported in #1313 — the iOS app cannot parse
  `users/me?context=edit` for these users.
- `wpbakery_admin` carries
  `{"administrator": true, "vc_access_rules_post_types": "custom"}`,
  mimicking plugins that call `WP_User::add_cap($cap, $grant)` with
  non-bool grants. PR #1263 already fixed this on `capabilities` with a
  unit test; this gives it integration coverage too.

Tests fetch each user by ID via the default admin client and rely on
`assert_response()` to surface deserialization failures. Both fail
today on `extra_capabilities`, which is still typed
`Option<HashMap<String, bool>>`. The fix follows in the next commit.
Switch `SparseUser::extra_capabilities` from
`Option<HashMap<String, bool>>` to `Option<UserCapabilitiesMap>`,
mirroring the wrapper PR #1263 introduced for the sibling `capabilities`
field. The underlying `HashMap<UserCapability, JsonValue>` tolerates the
non-bool shapes that legacy WordPress and plugins like WPBakery write
into `wp_capabilities` usermeta, and the existing `has_cap()` helper
preserves the boolean-check semantics callers expect.

Tighten the integration tests added in the previous commit to assert
both the raw map contents and `has_cap()` behavior on the now-rich
wrapper type.

This is a Swift/Kotlin binding change consistent with PR #1263:
`UserWithEditContext.extraCapabilities` becomes `UserCapabilitiesMap`
instead of `[String: Bool]`.

Fixes #1313.
Document the breaking type change and the underlying bug fix from the
preceding commit. Mirrors the conventions used for the analogous
breaking changes elsewhere in the Unreleased section.
The fixture admin users `legacy_admin` and `wpbakery_admin` introduced
earlier in this branch raise the total user count on the test site from
4 to 6, which broke `UsersEndpointTest.testUserListRequest` and
`testFilterUserListRequest`.

Bump `NUMBER_OF_USERS` to 6 and split out
`NUMBER_OF_USERS_WITH_PUBLISHED_POSTS` so the
`testUserListRequestWithHasPublishedPostsParam` assertion no longer
relies on the incidental `NUMBER_OF_USERS - 1` arithmetic — adding more
non-publishing fixture users in the future no longer silently desyncs
that test.
@crazytonyli crazytonyli force-pushed the bugfix/1313-user-extra-cap branch from abf7a41 to dc1932e Compare May 4, 2026 22:45
@crazytonyli crazytonyli merged commit 3dcbb19 into trunk May 4, 2026
34 checks passed
@crazytonyli crazytonyli deleted the bugfix/1313-user-extra-cap branch May 4, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants