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

Only extract author info on a new Post / Page if the user can query for authors. #16870

Merged
merged 1 commit into from
Jul 16, 2021

Conversation

twstokes
Copy link
Contributor

@twstokes twstokes commented Jul 14, 2021

Fixes #16858

This change addresses a bug where Atomic site users who had limited permissions (e.g. Authors, Contributors) couldn't create new Posts or Pages. This occurred because we were always passing the blog.account.userID to the API as the author value on new Post and Page API requests. We learned that for Atomic sites this ID - which is their wp.com user ID - is not accepted by the backend. We should have instead been sending their ID that is local to the Atomic site.

This fix drops sending the author's user ID unless the user has permissions to query for other authors on the site, and can populate blog.authors. In the blog.authors array, the user ID is always the correct ID for the site, e.g. the ID for a user on the Atomic site and not necessarily always their wp.com user ID.

To test:

Note: If the app's logged in user's role is downgraded, leftover state (e.g. previously downloaded authors) may remain, resulting in failures of the tests below. It's recommended to test user role changes by going from lowest up, or by wiping the app state clean each time. This should be considered a bug and an issue will be created.

Prerequisites for all test sites

  • Add multiple authors: At least one Administrator role and one Author role

Non-Jetpack self-hosted sites

There is a discrepancy for the Editor role. On web, an Editor can choose new authors. On WPiOS, the client cannot query for the list of users, and thus can't populate the authors, so the user will not have the Author option. In other words, for self-hosted sites the user role must be Administrator to use this feature.

Administrator role

  • Creating a new Post.
  • Creating a new Post and setting a different author.
  • Creating a new Page.
  • Creating a new Page and setting a different author.
  • Updating an existing Post.
  • Updating an existing Page.
  • Updating an existing Post and changing the author.
  • Updating an existing Page and changing the author.

Author role

  • Creating a new Post.
  • Updating an existing Post.

Jetpack self-hosted sites

There is a discrepancy for the Editor role. On web, an Editor can choose new authors. On WPiOS, the client cannot query for the list of users, and thus can't populate the authors, so the user will not have the Author option. In other words, for self-hosted sites the user role must be Administrator to use this feature.

Administrator role

  • Creating a new Post.
  • Creating a new Post and setting a different author.
  • Creating a new Page.
  • Creating a new Page and setting a different author.
  • Updating an existing Post.
  • Updating an existing Page.
  • Updating an existing Post and changing the author.
  • Updating an existing Page and changing the author.

Author role

  • Creating a new Post.
  • Updating an existing Post.

WordPress.com Simple sites

Administrator role

  • Creating a new Post.
  • Creating a new Post and setting a different author.
  • Creating a new Page.
  • Creating a new Page and setting a different author.
  • Updating an existing Post.
  • Updating an existing Page.
  • Updating an existing Post and changing the author.
  • Updating an existing Page and changing the author.

Author role

  • Creating a new Post.
  • Updating an existing Post.

WordPress.com Atomic sites

Administrator role

  • Creating a new Post.
  • Creating a new Post and setting a different author.
  • Creating a new Page.
  • Creating a new Page and setting a different author.
  • Updating an existing Post.
  • Updating an existing Page.
  • Updating an existing Post and changing the author.
  • Updating an existing Page and changing the author.

Author role

  • Creating a new Post.
  • Updating an existing Post.

Creating with author change

  1. Create a new Post or Page on a site that has multiple users.
  2. Access the Post or Page settings by tapping the horizontal ellipses (More Options) icon at the top right and choosing Settings.
  3. Observe that "Author" appears as the top row under the "Publish" section.
  4. Tap on the row and observe that authors are shown by their Display Name sorted alphabetically.
  5. Select a new author and publish or save the Post or Page.
  6. Observe in the app and on the web that the new Post or Page has the chosen author.

Updating with author change

  1. Select an existing Post or Page on a site that has multiple users.
  2. Access the Post or Page settings by tapping the horizontal ellipses (More Options) icon at the top right and choosing Settings.
  3. Observe that "Author" appears as the top row under the "Publish" section.
  4. Tap on the row and observe that authors are shown by their Display Name sorted alphabetically.
  5. Select a new author and update the Post or Page.
  6. Observe in the app and on the web that the new Post or Page has the chosen author.

Creating without author change

  1. Create a new Post or Page on a site that has multiple users.
  2. Fill in test content
  3. Publish the Post or Page
  4. Observe in the app and on the web that the new Post or Page has the author that created it.

Updating without author change

  1. Select an existing Post or Page by the author that is logged in.
  2. Edit content on the Post or Page
  3. Update the Post or Page
  4. Observe in the app and on the web that the Post or Page reflects the updated content.

Regression Notes

  1. Potential unintended areas of impact
  • Creating a new post
  • Creating a new page
  • Creating a new post with a different author
  • Creating a new page with a different author
  • Updating an existing post
  • Updating an existing page
  • Choosing a new author for an existing post
  • Choosing a new author for an existing page
  1. What I did to test those areas of impact (or what existing automated tests I relied on)
    Worked with @guarani to complete the test cases provided in this PR.

  2. What automated tests I added (or what prevented me from doing so)
    No new tests were added for this change.

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented Jul 14, 2021

You can trigger an installable build for these changes by visiting CircleCI here.

@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented Jul 14, 2021

You can trigger optional UI/connected tests for these changes by visiting CircleCI here.

@twstokes twstokes self-assigned this Jul 15, 2021
@twstokes twstokes requested a review from guarani July 15, 2021 00:12
@twstokes twstokes linked an issue Jul 15, 2021 that may be closed by this pull request
@mokagio mokagio added this to the 17.8 ❄️ milestone Jul 15, 2021
@twstokes twstokes force-pushed the hotfix/post-publishing-author branch from 7be31c4 to d2b017f Compare July 15, 2021 12:47
@twstokes twstokes changed the title Don't send the author ID when it doesn't differ from the account's Only extract author information on a new Post / Page if the user can query for authors. Jul 15, 2021
@twstokes twstokes changed the title Only extract author information on a new Post / Page if the user can query for authors. Only extract author info on a new Post / Page if the user can query for authors. Jul 15, 2021
@@ -54,8 +54,8 @@ - (Post *)createPostForBlog:(Blog *)blog {
post.postType = Post.typeDefaultIdentifier;

BlogAuthor *author = [blog getAuthorWithId:blog.userID];
post.authorID = author.userID ?: blog.account.userID;
post.author = author.displayName ?: blog.account.displayName;
post.authorID = author.userID;
Copy link
Contributor Author

@twstokes twstokes Jul 15, 2021

Choose a reason for hiding this comment

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

Originally we fell back on the blog.account.userID if we had no hit with getAuthorWithId, but I don't believe this was necessary. Tracking the author ID and display name is only needed to have for the UI to switch authors.

Therefore if we don't have authors to choose from, we won't be doing any switching. When authorID is nil here, it won't be passed to the API and the update will be done "as the current user".

@guarani
Copy link
Contributor

guarani commented Jul 15, 2021

Testing d2b017f:

Non-Jetpack self-hosted sites

Administrator role

  • Creating a new Post.
  • Creating a new Post and setting a different author.
  • Creating a new Page.
  • Creating a new Page and setting a different author.
  • Updating an existing Post.
  • Updating an existing Page.
  • Updating an existing Post and changing the author.
  • Updating an existing Page and changing the author.

⚠️ Note: The last two points above couldn't be completed because I'm seeing a separate issue where tapping on the Author cell in Post Settings sometimes opens the Location picker instead. Will add a link to the issue here later.
Update 27 Aug 2021: I couldn't reproduce this bug so I think it's a non-issue.

Author role

  • Creating a new Post.
  • Updating an existing Post.

Jetpack self-hosted sites

Administrator role

Admin user: paulvonschrottky

  • Creating a new Post.
  • Creating a new Post and setting a different author.
  • Creating a new Page.
  • Creating a new Page and setting a different author.
  • Updating an existing Post.
  • Updating an existing Page.
  • Updating an existing Post and changing the author.
  • Updating an existing Page and changing the author.

Author role

Author user: p8ya8c

  • Creating a new Post.
  • Updating an existing Post.

WordPress.com Simple sites

Site: paulvonschrottky.wordpress.com

Administrator role

Admin user: paulvonschrottky

  • Creating a new Post.
  • Creating a new Post and setting a different author.
  • Creating a new Page.
  • Creating a new Page and setting a different author.
  • Updating an existing Post.
  • Updating an existing Page.
  • Updating an existing Post and changing the author.
  • Updating an existing Page and changing the author.

Author role

Author user: p8ya8c

  • Creating a new Post.
  • Updating an existing Post.

WordPress.com Atomic sites

Site: pschrottkyunsupportedblockatomic.wpcomstaging.com

Administrator role

Admin user: paulvonschrottky

  • Creating a new Post.
  • Creating a new Post and setting a different author.
  • Creating a new Page.
  • Creating a new Page and setting a different author.
  • Updating an existing Post.
  • Updating an existing Page.
  • Updating an existing Post and changing the author.
  • Updating an existing Page and changing the author.

Author role

Author user: p8ya8c

  • Creating a new Post.
  • Updating an existing Post.

Copy link
Contributor

@guarani guarani left a comment

Choose a reason for hiding this comment

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

Tested thoroughly and looks good! Great to see a fix involving deleted code! ❤️
:shipit:

@twstokes
Copy link
Contributor Author

Thank you @guarani!

@twstokes twstokes marked this pull request as ready for review July 16, 2021 01:12
@twstokes twstokes merged commit b8bd96f into release/17.8 Jul 16, 2021
@twstokes twstokes deleted the hotfix/post-publishing-author branch July 16, 2021 01:38
@mokagio mokagio mentioned this pull request Jul 16, 2021
4 tasks
@mokagio
Copy link
Contributor

mokagio commented Jul 16, 2021

@twstokes this has been bundled as part of 17.8 beta 2 (17.8.0.2).

Thanks for your work 🙌

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.

Cannot post to Atomic Site as an author
4 participants