Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disambiguate WP users vs. guest authors with same ID #1143

Merged
merged 1 commit into from
May 31, 2022

Conversation

dkoo
Copy link
Contributor

@dkoo dkoo commented May 26, 2022

All Submissions:

Changes proposed in this Pull Request:

Accounts for a previously unhandled edge case where a CAP guest author and a WP user might have the same numeric ID in the DB. In this case, master will always choose the guest author over the WP user because we can't tell which type of author to fetch with only the ID.

This PR fixes the above issue by storing a new block attribute isGuestAuthor as part of the Author Profile block. If this is true (the default), the block's behavior will behave as it currently does (search guest authors first, and if none found, fall back to WP users). If it's false, it will only search WP users. This ensures that if a WP user is chosen which has the same ID as a CAP guest author, the WP user will be displayed in the editor and the front-end.

Note that this doesn't fix pre-existing instances of the Author Profile block affected by this issue, as there is no way to disambiguate the numeric IDs without the new isGuestAuthor attribute. These blocks will need to be manually rebuilt in the editor.

This PR also standardizes REST API parameters as snake case and properly lists and sanitizes all possible param values in the REST route registration. Otherwise, the Author List and Author Profile behavior should remain the same.

Closes #1134.

How to test the changes in this Pull Request:

  1. On a brand new site with no posts and Co-Authors Plus and Newspack Blocks (current release) installed, create enough WP users and CAP guest authors so that you have at least one guest author with the same ID as a WP user. Hint: if you run wp site empty --yes at CLI and then create a guest author, the ID will be 1 and the same as the main admin user.
  2. Create some Author List blocks with various settings (for testing after the plugin upgrade).
  3. Create an Author Profile block and attempt to select the WP user with an ID that overlaps with a guest author. Observe that the guest author is displayed in the editor and on the front-end despite your selection.
  4. Install the Blocks plugin from this branch.
  5. Recreate the Author Profile block in step 3 and confirm that it now displays the correct WP user in the editor and on the front-end.
  6. Confirm that the Author List blocks still behave as before, and that both Author Profile and Author List blocks continue to behave as expected.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@dkoo dkoo added bug Something isn't working [Status] Needs Review labels May 26, 2022
@dkoo dkoo requested a review from a team as a code owner May 26, 2022 19:20
@dkoo dkoo self-assigned this May 26, 2022
Copy link
Member

@adekbadek adekbadek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the issue. Noting that the Author List block should also be updated – added #1150

@dkoo dkoo merged commit d3c5920 into master May 31, 2022
@dkoo dkoo deleted the fix/author-profile-disambiguation branch May 31, 2022 21:12
matticbot pushed a commit that referenced this pull request Jun 2, 2022
# [1.52.0-alpha.1](v1.51.0...v1.52.0-alpha.1) (2022-06-02)

### Bug Fixes

* correct donate block tab spacing in editor ([#1153](#1153)) ([c17221f](c17221f))
* disambiguate WP users vs. guest authors with same ID ([#1143](#1143)) ([d3c5920](d3c5920))
* echo closing link tags on sponsor bylines ([#1152](#1152)) ([f80893f](f80893f))
* remove custom column block styles ([#1133](#1133)) ([bd79783](bd79783))
* skipped linked images when navigating blocks by keyboard ([#1144](#1144)) ([8975787](8975787))

### Features

* add new subscribe pattern ([#1142](#1142)) ([97d632e](97d632e))
* remove support for the Aside post format ([#1139](#1139)) ([9f9cdf4](9f9cdf4))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.52.0-alpha.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Jun 13, 2022
# [1.52.0](v1.51.0...v1.52.0) (2022-06-13)

### Bug Fixes

* correct donate block tab spacing in editor ([#1153](#1153)) ([c17221f](c17221f))
* disambiguate WP users vs. guest authors with same ID ([#1143](#1143)) ([d3c5920](d3c5920))
* echo closing link tags on sponsor bylines ([#1152](#1152)) ([f80893f](f80893f))
* remove custom column block styles ([#1133](#1133)) ([bd79783](bd79783))
* skipped linked images when navigating blocks by keyboard ([#1144](#1144)) ([8975787](8975787))

### Features

* add new subscribe pattern ([#1142](#1142)) ([97d632e](97d632e))
* remove support for the Aside post format ([#1139](#1139)) ([9f9cdf4](9f9cdf4))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.52.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

Author Profile: Guest author ID overrides user ID
3 participants