Problem/Motivation

See #2293697-174: EntityResource POST routes all use the confusing default: use entity types' https://www.drupal.org/link-relations/create link template if available. Blocked on #2822190: PathValidator validates based on a RequestContext leaked from the current request, resulting in false negatives during CLI requests and POST submissions.

As of #2293697: EntityResource POST routes all use the confusing default: use entity types' https://www.drupal.org/link-relations/create link template if available, it's possible to POST to /node instead of /entity/node, to /taxonomy/term instead of /entity/taxonomy_term, and so on.

A notable exception: for creating User entities, you still have to POST to /entity/user, not /user.

The tricky thing is that /user is also a non-REST route: user.page, which accepts POST requests in any format, and therefore interferes with the REST route that's also registered at /user. We cannot make the non-REST route GET-only, because there might be forms there, e.g. in blocks (see @dawehner in #13).

Proposed resolution

Enable POSTing to /user by:

  1. adding a create link relation type to User's annotation
  2. figuring out a feasible fix/solution/work-around to actually make this work as expected

Remaining tasks

TBD

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

Wim Leers created an issue. See original summary.

wim leers’s picture

StatusFileSize
new4.03 KB
wim leers’s picture

Title: [PP-1] Add "https://drupal.org/link-relations/create" link template to User entity type » Add "https://drupal.org/link-relations/create" link template to User entity type
Status: Postponed » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: 2851984-2.patch, failed testing.

wim leers’s picture

Assigned: Unassigned » wim leers
Status: Needs work » Needs review
StatusFileSize
new4.08 KB

#2 didn't apply anymore; rebased.

wim leers’s picture

From #2293697-168: EntityResource POST routes all use the confusing default: use entity types' https://www.drupal.org/link-relations/create link template if available:

An alternative could be to not block this on #2822190: PathValidator validates based on a RequestContext leaked from the current request, resulting in false negatives during CLI requests and POST submissions and just modify ContactSitewideTest. This is the line that's causing a failure:

    $this->updateContactForm($id, $label = $this->randomMachineName(16), $recipients_str = implode(',', array($recipients[0], $recipients[1])), $reply = $this->randomMachineName(30), FALSE, 'Your message has been sent.', '/user');

Specifically, the /user parameter at the end. That's filling out a "contact form" config entity configuration form to set the redirect path to be /user. This then causes problems because […]

Since #2822190: PathValidator validates based on a RequestContext leaked from the current request, resulting in false negatives during CLI requests and POST submissions has landed (but gained a follow-up: #2852107: PathValidator::getUrlIfValid() does not support non-HTML/non-GET routes), we should be able to remove the changes to ContactSitewideTest.

The last submitted patch, 5: 2851984-4.patch, failed testing.

wim leers’s picture

Assigned: wim leers » Unassigned
StatusFileSize
new529 bytes
new2.93 KB

Turns out that Symfony has deprecated setting

requirements:
  _method: [GET]

You actually need to do this now:

methods: [GET]

Fixing that makes tests pass :)

wim leers’s picture

The last submitted patch, 6: 2851984-6.patch, failed testing.

dawehner’s picture

As said on IRC, we are fucked, given that any forms can appear on those routes, so they need to support POST.

wim leers’s picture

Status: Needs review » Needs work

Yes, so:

+++ b/core/modules/user/user.routing.yml
@@ -116,6 +116,7 @@ user.page:
   defaults:
     _controller: '\Drupal\user\Controller\UserController::userPage'
     _title: 'My account'
+  methods: [GET]
   requirements:
     _user_is_logged_in: 'TRUE'

this is unacceptable, because there may be a method="post" form on this page, which then won't work due to this change.

This is because our rendering + routing system are intertangled.

dawehner’s picture

Could we introduce a /form route which allows to take an actual path, so like /form?path=user, which we use inside the form rendering process?

Later on we could then have form specific routes for a more optimized POST processing.

wim leers’s picture

Yep. We've been needing that for years.

wim leers’s picture

berdir’s picture

Hm. What exactly is special about /user?

/node also exists in the form of the default frontpage view that uses that path. So if you create the same contact form and configure it to point to /node, then you get the same probem? Or any other path?

I suspect the only difference is that only /user happens to have test coverage in HEAD, but it could affect other routes as well on sites?

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wim leers’s picture

Title: Add "https://drupal.org/link-relations/create" link template to User entity type » Add "create" link template to User entity type annotation, to allow POSTing to /user instead of /entity/user
Issue summary: View changes

Updated IS title + summary.

wim leers’s picture

#16 is asking great questions.

Hm. What exactly is special about /user?

It exists always and accepts POST requests. Then when you make a POST request when you're not logged in, it redirects to somewhere else, which causes the HTTP client to repeat its POST request, at which point multiple routes match, some match is selected, and you get a very unexpected and quite illogical 200 response.
See the details at #2293697-150: EntityResource POST routes all use the confusing default: use entity types' https://www.drupal.org/link-relations/create link template if available + #2293697-157: EntityResource POST routes all use the confusing default: use entity types' https://www.drupal.org/link-relations/create link template if available + later.

/node also exists in the form of the default frontpage view that uses that path. So if you create the same contact form and configure it to point to /node, then you get the same probem? Or any other path?

No, see above.

wim leers’s picture

Status: Needs work » Closed (won't fix)

I think a key question here is Is the benefit worth our time?

In other words: how important is it that we make this work in the nice way? So then the question becomes: is it common to create User entities?

To which I think the answer is: quite uncommon. So let's "won't fix" this.