Problem/Motivation

If the user resource is marked as internal, then the entry point tries to generate a link for an non-existing route: jsonapi.user--user.individual

Proposed resolution

Detect if the route does not exist and skip the link generation if that happens.

Comments

e0ipso created an issue. See original summary.

e0ipso’s picture

Status: Active » Needs review
StatusFileSize
new1.81 KB

Simple fix. I prefer this over detecting if the resource is internal because the route not existing is the real problem, the resource being internal is only one (the most common) of the possible explanations.

Status: Needs review » Needs work

The last submitted patch, 2: 3016866--me-link-breaks-entry-point--2.patch, failed testing. View results

wim leers’s picture

Priority: Normal » Minor
Status: Needs work » Reviewed & tested by the community
Issue tags: +API-First Initiative
StatusFileSize
new861 bytes
new1.81 KB

Great catch!

Just one silly CS violation that caused it to not be green. Fixing, RTBC'ing, committing when it comes back green.

wim leers’s picture

Actually, leaving RTBC to let @gabsullice also +1 this approach.

gabesullice’s picture

Status: Reviewed & tested by the community » Active

I'm fine with a try/catch vs. detecting if the route is not defined. However, the promise of the me link is mostly that it communicates the consumer's authentication state, i.e. the presence of the me links tells the client that it is authenticated vs anonymous.

I'd rather not remove this feature simply because the user is internal. I wonder if there's something else we could do...

gabesullice’s picture

Status: Active » Needs review
StatusFileSize
new2.2 KB

Here's an alternative approach that won't break the signaling effect of me, the link will just resolve to a 404.

Status: Needs review » Needs work

The last submitted patch, 7: 3016866-7.patch, failed testing. View results

gabesullice’s picture

Status: Needs work » Needs review
StatusFileSize
new631 bytes
new2.81 KB

Easy fix.

e0ipso’s picture

I find that #7 will lead to confusion. As an API user I don't want to get links that don't exist. I don't think that people will disable the user resource type and be furious because the "me" link is missing.

I think that adding a "me" link that leads to a 404 is not the correct approach. We should not serve links that will always 404.

gabesullice’s picture

I agree that it's weird to point to a missing URL. I tried to think of something else, but nothing seemed cleaner (like a null href or pointing to a different URL). This is the least disruptive change I could think of.

The me link has three functions, to point you to the resource that represents the current user, to indicate that the client is authenticated and to communicate the current user's UUID (so that you can filter to get a list "My Articles", for example). If we go with #4, we're killing all three of those functions. If we go with #7, we're only killing 1 of those functions.

I find that #7 will lead to confusion. As an API user I don't want to get links that don't exist. I don't think that people will disable the user resource type and be furious because the "me" link is missing.

I'd ask, isn't it more confusing that the me link disappears because you disabled the user resource type than it is for it to be 404?

If you follow the link and get a 404, I think it's a smaller mental leap to think "oh, it's 404 because I disabled the resource type" than it is when you're looking at the me link to see if you're authenticated and it's gone because you disabled a resource type.

I think most developers in that scenario would start looking at their headers and cookies and such first, only to slap their head when they finally realize it's just because they made the user resource type internal.

In essence, I don't think that people will disable the user resource type and be furious because the "me" link is missing404.

e0ipso’s picture

I'd ask, isn't it more confusing that the me link disappears because you disabled the user resource type than it is for it to be 404?

I don't think so. I actually think it's expected.

When we disable a resource type, the link for that resource in the entry point disappears, that's what you expect. The "me" link is part of that resource, so it should disappear too.

I think most developers in that scenario would start looking at their headers and cookies and such first, only to slap their head when they finally realize it's just because they made the user resource type internal.

I don't really see that happening. But if I did, I would argue that the same level of headscratching would happen due to a 404.


I think that manually constructing URLs (because there are no supporting routes) is a red flag.


Finally, remember that 4XX is a Client error. But in this case the client was not wrong, the server was.

wim leers’s picture

Who's glad he didn't just go ahead and commit this? ✋

😃


I think it's a great point that this removes the ability to get the current client's User UUID, which is essential for certain operations (filtering to "my content"). Isn't that a concern of yours, @e0ipso?
I suspect you think that if a particular site chooses to disable User, that its data model and hence clients don't care about users/ownership at all?

gabesullice’s picture

@e0ipso, hmm, it seems we need to find a way that this won't throw an exception and end up in head-scratching.

What if we add a meta.id member to the me link object. So when the route is present we have:

{
  "links": {
    "me: {
      "href": "/jsonapi/user/user/{uuid}",
      "meta": {
        "id": "{uuid}"
      }
    }
  }
}

but when it's not, we have:

{
  "links": {
    "me: {
      "meta": {
        "id": "{uuid}"
      }
    }
  }
}

That's technically okay by the spec (but I really think only because of an oversight): "[A link object] can contain the following members [href</code and <code>meta"

Alternatively, we could change the me structure a little bit. Right now, it's a link under meta, but it could be a resource object under meta instead:

{
  "meta": {
    "me": {
      "type": "user--user",
      "id": "{uuid}",
      "links: {
        "self": {
          "href": "/jsonapi/user/user/{uuid}"
        }
      }
    }
  }
}
wim leers’s picture

Interesting proposals. I could live with either. I defer to @e0ipso to pick a direction. Or perhaps he has a different proposal still.

e0ipso’s picture

Issue tags: +blocker

We can have whatever data structure in meta, but I agree that a resource identifier object makes the most sense. However, note that this resource identifier will point to a non-existing resource…

I would like to not have a link to a 404 when the resource type is disabled and not to break the entry point.


Adding the blocker tag. This is blocking the adoption of 2.x by Contenta CMS.

I'll get a fix for this soon.

wim leers’s picture

I would like to not have a link to a 404

+1

This is blocking the adoption of 2.x by Contenta CMS.

Interesting! Is Contenta CMS disabling the user--user resource type by default?

e0ipso’s picture

Interesting! Is Contenta CMS disabling the user--user resource type by default?

Yes. But even if it didn't, since we ship with JSON:API Extras enabled it'd be a blocker anyways.

wim leers’s picture

But even if it didn't, since we ship with JSON:API Extras enabled it'd be a blocker anyways.

How does this issue and the "me" link in general relate to JSON:API Extras? It feels like I'm missing something here! 🤔

e0ipso’s picture

JSON:API Extras is the UI for disabling resources. However, that's not the main focus. I think we have to fix it regardless.

wim leers’s picture

Ahhhh, now I get what you meant! Thanks for clarifying :)

wim leers’s picture

@e0ipso So, which in the proposals of #14 do you prefer?

e0ipso’s picture

@Wim Leers I'm going to go with the first proposal of #14.

e0ipso’s picture

Let's kick off the tests.

Status: Needs review » Needs work

The last submitted patch, 24: 3016866--me-link-breaks-entry-point--24.patch, failed testing. View results

e0ipso’s picture

I'm pretty sure the failures in #24 are due to a broken HEAD.

e0ipso’s picture

Status: Needs work » Needs review
wim leers’s picture

Assigned: e0ipso » wim leers
Status: Needs review » Postponed
Related issues: +#3019389: MediaTest fails on 8.7 since #2956368

#26: on it!

wim leers’s picture

Assigned: wim leers » gabesullice

#3019389 has a green patch on 8.6 and 8.7, but a red one on 8.5, due to another commit having broken JSON:API in 8.5. Blocked on that.

In the mean time, this could already be reviewed by @gabesullice, who had strong opinions about this than I did I think.

gabesullice’s picture

#24 LGTM. Thanks for pushing forward on this despite the frustration of a seemingly minor thing growing much bigger 🤗

RTBC, once all tests pass (this should happen when HEAD is unbroken).

wim leers’s picture

Yay!

wim leers’s picture

Assigned: gabesullice » Unassigned
Status: Postponed » Reviewed & tested by the community

Blockers have landed. Retesting.

  • Wim Leers committed bebc78f on 8.x-2.x authored by e0ipso
    Issue #3016866 by e0ipso, gabesullice, Wim Leers: The "me" link breaks...
wim leers’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.