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

Ability to select authors has vanished #3010

Closed
karmatosed opened this issue Oct 12, 2017 · 21 comments
Closed

Ability to select authors has vanished #3010

karmatosed opened this issue Oct 12, 2017 · 21 comments
Assignees
Labels
Core REST API Task Task for Core REST API efforts REST API Interaction Related to REST API [Type] Bug An existing feature does not function as intended [Type] WP Core Ticket Requires an upstream change from WordPress. Core Trac ticket should be linked.

Comments

@karmatosed
Copy link
Member

This was reported on the support forums. The ability to change the author of a post has disappeared.

@karmatosed karmatosed added the [Type] Bug An existing feature does not function as intended label Oct 12, 2017
@karmatosed karmatosed added this to the Beta 1.5 milestone Oct 12, 2017
@ellatrix
Copy link
Member

ellatrix commented Oct 12, 2017

This should probably not be edit context, as we only want to select users, not edit them.

users: '/wp/v2/users?context=edit&per_page=100',

@aduth
Copy link
Member

aduth commented Oct 12, 2017

Specifically, this appears to be an issue in environments where the user does not have permission to request from:

/wp-json/wp/v2/users?context=edit

This should probably not be edit context, as we only want to select users, not edit them.

This is really only considering the symptom of the problem. Also, the edit context adds the capabilities property to a user entity which we use to determine whether a user should be shown in the dropdown:

getAuthors() {
// While User Levels are officially deprecated, the behavior of the
// existing users dropdown on `who=authors` tests `user_level != 0`
//
// See: https://github.com/WordPress/WordPress/blob/a193916/wp-includes/class-wp-user-query.php#L322-L327
// See: https://codex.wordpress.org/Roles_and_Capabilities#User_Levels
const { users } = this.props;
return filter( users.data, ( user ) => {
return user.capabilities.level_1;
} );
}

https://github.com/WordPress/WordPress/blob/a1879766ed4e95eab66ac4694aea3a5d4a9c9030/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php#L1247-L1252

@ellatrix
Copy link
Member

ellatrix commented Oct 12, 2017

@ellatrix
Copy link
Member

Only admins have the list_users capability, unless roles are changed by a plugin.

@aduth
Copy link
Member

aduth commented Oct 12, 2017

I mean in the sense that it didn't offer an explanation to why the issue exists.

With consideration of #3010 (comment), one could argue this is "working as intended" so far as the REST API intends. Obviously leaves us in a bad situation for building an editor though...

@ellatrix
Copy link
Member

I'm not sure what you mean? This seems to be working as intended indeed, and also for Gutenberg. If you don't have right capabilities, you shouldn't be able to access the users in edit context. They should be retrieved in normal/view content, and be filtered server side. In this case the right approach seems to be removing the context argument and adding the role (author) argument.

https://developer.wordpress.org/rest-api/reference/users/#arguments

@aduth
Copy link
Member

aduth commented Oct 12, 2017

Role is not sufficient for querying the users which should be included in the dropdown. Related: #2157

@ellatrix
Copy link
Member

ellatrix commented Oct 12, 2017

You're totally right, somehow I thought that was equivalent to who and would show higher roles too. I guess ideally the API should let us query by capability (publish_posts)? How about using roles=author,editor,administrator for now? Also not ideal since plugins could add new roles and change caps.

@ellatrix
Copy link
Member

Well, I guess we should also create a core ticket for it, otherwise it will always stay a hack.

@ellatrix
Copy link
Member

Created https://core.trac.wordpress.org/ticket/42202.

@ellatrix ellatrix added the Core REST API Task Task for Core REST API efforts label Oct 12, 2017
@pento pento modified the milestones: Beta 1.5, Needs API Oct 18, 2017
@aduth
Copy link
Member

aduth commented Dec 13, 2017

Noting that this can also be an issue for sites which have configured plain permalinks.

Related:

@bobbingwide
Copy link
Contributor

Actual output

This is the Status & Visibility block when permalinks are plain.
image

Expected output

This is how the Status & Visibility block appears when permalinks are set to post name ( /%postname%/ ).
image

Note: For the author selection drop down to appear there need to be at least two users with the capability to edit the post.

Workaround

  • Use pretty permalinks

@bobbingwide
Copy link
Contributor

Just to summarise the ability to select Authors based on the editing user's role

User's role Classic Block editor
Contributor n/a n/a
Author works 403 response
Editor works 403 response
Administrator works works - up to a point- see below

The response message for the 403 is

{"code":"rest_forbidden_context","message":"Sorry, you are not allowed to list users.","data":{"status":403}}

Note: The data in the drop down information has changed.

Was "display name (username)". Now just "display name".
image
image

@mtias mtias modified the milestones: Merge Proposal, Core API Mar 7, 2018
@mtias mtias added the [Type] WP Core Ticket Requires an upstream change from WordPress. Core Trac ticket should be linked. label Mar 7, 2018
@danielbachhuber danielbachhuber added the REST API Interaction Related to REST API label Apr 4, 2018
@danielbachhuber danielbachhuber self-assigned this Apr 11, 2018
@danielbachhuber
Copy link
Member

In addition to https://core.trac.wordpress.org/ticket/42202, the underlying problem here is that the REST API limits GET wp/v2/users?context=edit to WordPress users with the list_users capability.

However... WordPress' UI permits Editors to see other WordPress users when assigning the post author in Edit Post. Furthermore, Contributors and Authors can see (i.e. discover the existence of) other WordPress users in the Manage Posts view.

We can't grant list_users to Editors though, because that would expose email addresses where they aren't currently exposed. Unless we decide it's acceptable to do.

I don't have a great suggestion at this point. One idea, which I don't particularly like, is to permit GET GET wp/v2/users?context=editfor all users withedit_posts, but nullify the private information (email address, role, etc.) unless they have list_userstoo. Then, furthermore,capabilities` and other super private information would be nullified unless the user could edit the viewed user.

@bobbingwide
Copy link
Contributor

We can't grant list_users to Editors though, because that would expose email addresses where they aren't currently exposed. Unless we decide it's acceptable to do.

Could exposing email addresses be an issue requiring GDPR consideration?

@danielbachhuber
Copy link
Member

I don't have a great suggestion at this point.

With #6515 and #6529, I think we can get away with GET /wp/v2/users?who=authors&context=view for our immediate need.

Although, in principle, we should be using context=edit, I don't think it makes a difference in practice. Our current alternatives (nullifying values or introducing some context=admin with a limited subset of context=edit data) are more complex and don't offer any significant benefit.

@lizkarkoski
Copy link

There's a request to add this feature from the Gutenberg forums:

https://wordpress.org/support/topic/how-to-change-post-author-2/

@danielbachhuber
Copy link
Member

@lizkarkoski This was already sorted out with Gutenberg, so the forum thread may be a plugin conflict, etc.

@lizkarkoski
Copy link

lizkarkoski commented Aug 16, 2018 via email

@rilwis
Copy link

rilwis commented Sep 10, 2019

Hey guys,

I see this issue is marked as closed, but I've just trying to create a post in the latest version of WordPress and still don't see any author dropdown? I'm on localhost with admin role.

This is my screenshot:

@paulshryock
Copy link

Any traction on this? Still seems like there's no way to change a post author from within the post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core REST API Task Task for Core REST API efforts REST API Interaction Related to REST API [Type] Bug An existing feature does not function as intended [Type] WP Core Ticket Requires an upstream change from WordPress. Core Trac ticket should be linked.
Projects
None yet
Development

No branches or pull requests

10 participants