Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.
This repository was archived by the owner on Sep 24, 2018. It is now read-only.

Ensure consistent contexts across controllers #1845

Closed

Description

@danielbachhuber

Most endpoints default to context=view, but GET /wp/v2/users/<id> defaults to embed: 2d4cdbc

Some endpoints only have view, the meta endpoint only has edit, and other endpoints have edit.

For a client trying to making requests, these inconsistencies are really confusing. We should make sure we have consistent default contexts across controllers, and each controller supports similar context names.

Related #1797, #1796

Rediscovered in #1838

Previously #702

Activity

  1. added this to the 2.0 milestone on Dec 11, 2015
  2. danielbachhuber commented on Dec 11, 2015

    @danielbachhuber
    MemberAuthor

    I put together a little script to audit our contexts: https://gist.github.com/danielbachhuber/cdc34b82b4a2815fb718

    As of #1838, here's the result:

    +---------------------------------------------------------------+-----------------+-------------------+
    | route                                                         | default_context | enum              |
    +---------------------------------------------------------------+-----------------+-------------------+
    | /                                                             | view            |                   |
    | /wp/v2                                                        | view            |                   |
    | /wp/v2/posts                                                  | view            | view, embed, edit |
    | /wp/v2/posts/(?P<id>[\d]+)                                    | view            | view, embed, edit |
    | /wp/v2/posts/(?P<parent_id>[\d]+)/meta                        | edit            | edit              |
    | /wp/v2/posts/(?P<parent_id>[\d]+)/meta/(?P<id>[\d]+)          | edit            | edit              |
    | /wp/v2/posts/(?P<parent_id>[\d]+)/revisions                   | view            | view              |
    | /wp/v2/posts/(?P<parent_id>[\d]+)/revisions/(?P<id>[\d]+)     | view            | view              |
    | /wp/v2/posts/(?P<post_id>[\d]+)/categories                    | view            | view, embed       |
    | /wp/v2/posts/(?P<post_id>[\d]+)/categories/(?P<term_id>[\d]+) | view            | view, embed       |
    | /wp/v2/posts/(?P<post_id>[\d]+)/tags                          | view            | view, embed       |
    | /wp/v2/posts/(?P<post_id>[\d]+)/tags/(?P<term_id>[\d]+)       | view            | view, embed       |
    | /wp/v2/pages                                                  | view            | view, embed, edit |
    | /wp/v2/pages/(?P<id>[\d]+)                                    | view            | view, embed, edit |
    | /wp/v2/pages/(?P<parent_id>[\d]+)/meta                        | edit            | edit              |
    | /wp/v2/pages/(?P<parent_id>[\d]+)/meta/(?P<id>[\d]+)          | edit            | edit              |
    | /wp/v2/pages/(?P<parent_id>[\d]+)/revisions                   | view            | view              |
    | /wp/v2/pages/(?P<parent_id>[\d]+)/revisions/(?P<id>[\d]+)     | view            | view              |
    | /wp/v2/media                                                  | view            | view, embed, edit |
    | /wp/v2/media/(?P<id>[\d]+)                                    | view            | view, embed, edit |
    | /wp/v2/types                                                  | view            | view              |
    | /wp/v2/types/(?P<type>[\w-]+)                                 | view            | view              |
    | /wp/v2/statuses                                               | view            | view              |
    | /wp/v2/statuses/(?P<status>[\w-]+)                            | view            | view              |
    | /wp/v2/taxonomies                                             | view            | view              |
    | /wp/v2/taxonomies/(?P<taxonomy>[\w-]+)                        | view            | view              |
    | /wp/v2/categories                                             | view            | view, embed       |
    | /wp/v2/categories/(?P<id>[\d]+)                               | view            | view, embed       |
    | /wp/v2/tags                                                   | view            | view, embed       |
    | /wp/v2/tags/(?P<id>[\d]+)                                     | view            | view, embed       |
    | /wp/v2/users                                                  | view            | view, embed, edit |
    | /wp/v2/users/(?P<id>[\d]+)                                    | embed           | view, embed, edit |
    | /wp/v2/users/me                                               |                 |                   |
    | /wp/v2/comments                                               | view            | view, embed, edit |
    | /wp/v2/comments/(?P<id>[\d]+)                                 | view            | view, embed, edit |
    | /oembed/1.0                                                   | view            |                   |
    +---------------------------------------------------------------+-----------------+-------------------+
    
  3. danielbachhuber commented on Dec 15, 2015

    @danielbachhuber
    MemberAuthor

    @joehoyle and I discussed #1864 some:

    joehoyle [7:08 AM] hmm
    ​[7:08] why is labels not part of the view context?
    ​[7:09] for example, I'd want the search_items label it build view-only UI
    danielbachhuber [7:10 AM] core doesn't expose search_items on the frontend
    ​[7:10] historically, our distinction between view and edit is backend and frontend
    joehoyle [7:10 AM] I thought it was "I want to get this data to perform an edit on it"
    ​[7:10] that's how I've always thought about it anyway
    ​[7:11] I'd expect a read-only admin user to be able to ​_see_​ everything using context=view
    danielbachhuber [7:12 AM] well, I suppose this is yet another problem with the context abstraction
    ​[7:12] meta only has edit context
    joehoyle [7:12 AM] interesting
    ​[7:12] I don't know what that is. to me, context=edit implies authorization(edited)
    danielbachhuber [7:14 AM] that is true, and in this pull request context=edit requires authorization
    joehoyle [7:19 AM] so, for taxonomy labels, I don't think there's a private data issue, i think it should be in view
    ​[7:19] infact, context=edit doesn't make any sense for taxonomies, as you can't edit them
    ​[7:19] IMO
    danielbachhuber [7:21 AM] ok. pretty sure that's different than how we've been operating
    joehoyle [7:22 AM] hmm yeah sounds like we need to get on the same page with that context means - do we have docs written for it?
    danielbachhuber [7:22 AM] nope

  4. rmccue commented on Dec 17, 2015

    @rmccue
    Member

    context=edit doesn't make any sense for taxonomies

    I don't know that'd I'd agree with this necessarily; edit is just the context you're in right now, i.e. an editor. It doesn't necessarily mean you're editing that item.

    I'd expect that editor contexts (i.e. desktop/mobile admin clients) would always send context=edit with requests, and that view contexts (i.e. the site, or mobile applications which view the data) would always send context=view (i.e. default).

  5. danielbachhuber commented on Jan 30, 2016

    @danielbachhuber
    MemberAuthor
    +-----------------------------------------------------------+-----------------+-------------------+
    | route                                                     | default_context | enum              |
    +-----------------------------------------------------------+-----------------+-------------------+
    | /                                                         | view            |                   |
    | /wp/v2                                                    | view            |                   |
    | /wp/v2/posts                                              | view            | view, embed, edit |
    | /wp/v2/posts/(?P<id>[\d]+)                                | view            | view, embed, edit |
    | /wp/v2/posts/(?P<parent_id>[\d]+)/revisions               | view            | view              |
    | /wp/v2/posts/(?P<parent_id>[\d]+)/revisions/(?P<id>[\d]+) | view            | view              |
    | /wp/v2/pages                                              | view            | view, embed, edit |
    | /wp/v2/pages/(?P<id>[\d]+)                                | view            | view, embed, edit |
    | /wp/v2/pages/(?P<parent_id>[\d]+)/revisions               | view            | view              |
    | /wp/v2/pages/(?P<parent_id>[\d]+)/revisions/(?P<id>[\d]+) | view            | view              |
    | /wp/v2/media                                              | view            | view, embed, edit |
    | /wp/v2/media/(?P<id>[\d]+)                                | view            | view, embed, edit |
    | /wp/v2/types                                              | view            | view, edit        |
    | /wp/v2/types/(?P<type>[\w-]+)                             | view            | view, edit        |
    | /wp/v2/statuses                                           | view            | view              |
    | /wp/v2/statuses/(?P<status>[\w-]+)                        | view            | view              |
    | /wp/v2/taxonomies                                         | view            | view, edit        |
    | /wp/v2/taxonomies/(?P<taxonomy>[\w-]+)                    | view            | view, edit        |
    | /wp/v2/categories                                         | view            | view, embed       |
    | /wp/v2/categories/(?P<id>[\d]+)                           | view            | view, embed       |
    | /wp/v2/tags                                               | view            | view, embed       |
    | /wp/v2/tags/(?P<id>[\d]+)                                 | view            | view, embed       |
    | /wp/v2/users                                              | view            | view, embed, edit |
    | /wp/v2/users/(?P<id>[\d]+)                                | embed           | view, embed, edit |
    | /wp/v2/users/me                                           |                 |                   |
    | /wp/v2/comments                                           | view            | view, embed, edit |
    | /wp/v2/comments/(?P<id>[\d]+)                             | view            | view, embed, edit |
    | /oembed/1.0                                               | view            |                   |
    +-----------------------------------------------------------+-----------------+-------------------+
    
  6. danielbachhuber commented on Jan 30, 2016

    @danielbachhuber
    MemberAuthor

    Need to introduce embed, view, or edit on the contexts that don't have them.

  7. danielbachhuber commented on Feb 4, 2016

    @danielbachhuber
    MemberAuthor

    So close!

    +-----------------------------------------------------------+-----------------+-------------------+
    | route                                                     | default_context | enum              |
    +-----------------------------------------------------------+-----------------+-------------------+
    | /                                                         | view            |                   |
    | /wp/v2                                                    | view            |                   |
    | /wp/v2/posts                                              | view            | view, embed, edit |
    | /wp/v2/posts/(?P<id>[\d]+)                                | view            | view, embed, edit |
    | /wp/v2/posts/(?P<parent_id>[\d]+)/revisions               | view            | view              |
    | /wp/v2/posts/(?P<parent_id>[\d]+)/revisions/(?P<id>[\d]+) | view            | view              |
    | /wp/v2/pages                                              | view            | view, embed, edit |
    | /wp/v2/pages/(?P<id>[\d]+)                                | view            | view, embed, edit |
    | /wp/v2/pages/(?P<parent_id>[\d]+)/revisions               | view            | view              |
    | /wp/v2/pages/(?P<parent_id>[\d]+)/revisions/(?P<id>[\d]+) | view            | view              |
    | /wp/v2/media                                              | view            | view, embed, edit |
    | /wp/v2/media/(?P<id>[\d]+)                                | view            | view, embed, edit |
    | /wp/v2/types                                              | view            | view, embed, edit |
    | /wp/v2/types/(?P<type>[\w-]+)                             | view            | view, embed, edit |
    | /wp/v2/statuses                                           | view            | view, embed, edit |
    | /wp/v2/statuses/(?P<status>[\w-]+)                        | view            | view, embed, edit |
    | /wp/v2/taxonomies                                         | view            | view, embed, edit |
    | /wp/v2/taxonomies/(?P<taxonomy>[\w-]+)                    | view            | view, embed, edit |
    | /wp/v2/categories                                         | view            | view, embed, edit |
    | /wp/v2/categories/(?P<id>[\d]+)                           | view            | view, embed, edit |
    | /wp/v2/tags                                               | view            | view, embed, edit |
    | /wp/v2/tags/(?P<id>[\d]+)                                 | view            | view, embed, edit |
    | /wp/v2/users                                              | view            | view, embed, edit |
    | /wp/v2/users/(?P<id>[\d]+)                                | view            | view, embed, edit |
    | /wp/v2/users/me                                           |                 |                   |
    | /wp/v2/comments                                           | view            | view, embed, edit |
    | /wp/v2/comments/(?P<id>[\d]+)                             | view            | view, embed, edit |
    | /oembed/1.0                                               | view            |                   |
    +-----------------------------------------------------------+-----------------+-------------------+
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Sponsor
    SponsoredKunjungi sekarang
    Promo