aimeos / ai-client-jsonapi

Aimeos frontend JSON API
GNU Lesser General Public License v3.0
28 stars 6 forks source link

Bad Links for Customer Included Relationships #15

Closed exemplari closed 2 years ago

exemplari commented 2 years ago

Adding an "include" to the customer get create bad links to access the sub domains (address).

  1. Get the customer with an 'include' curl -b cookies.txt -c cookies.txt \ -X GET 'http://localhost:8000/jsonapi/customer?site=default&include=customer/address'

sample response from the included array

{
  "id": "45",
  "type": "customer/address",
  "attributes": {
    "customer.address.id": "45",
    "customer.address.address1": "Test street",
    "customer.address.address2": "1",
    "customer.address.address3": "",
    "customer.address.birthday": null,
    "customer.address.position": 1
  },
  "links": {
    "self": {
      "href": "http://localhost:8000/jsonapi/customer?id=492&related=customer%2Faddress&relatedid=45&site=default",
      "allow": [
        "DELETE",
        "GET",
        "PATCH"
      ]
    },
    "basket/address": {
      "href": "http://localhost:8000/jsonapi/basket?id=default&related=address&relatedid=payment&site=default",
      "allow": [
        "POST"
      ]
    }
  }
}
  1. Delete the provided links.self.href curl -b cookies.txt -c cookies.txt \ -X DELETE 'http://localhost:8000/jsonapi/customer?id=492&related=customer%2Faddress&relatedid=45&site=default'

{ "errors": [ { "title": "Not allowed for this resource" } ] }



Delete is working fine. http://localhost:8000/jsonapi/customer?id=492&related=address&relatedid=45&site=default
aimeos commented 2 years ago

We have to check that in more detail because it's not obvious why this error message is returned

aimeos commented 2 years ago

Think we've fixed the problem. Can you please execute

composer req aimeos/ai-client-jsonapi:2021.07.x-dev

and check if it works for you too?

exemplari commented 2 years ago

Does not seem fixed. The links for included.$addressItem.links.self is still prefixing with "customer/" and sending patch or delete there is "Not allowed for this resource"

"aimeos/ai-client-jsonapi", "version": "2021.07.x-dev", 0c764ae0f58ad43abdf65c00d0fa4712ead1e704


{
  "meta": {
   ...
  },
  "links": {
    "self": "http://www.mysite.com/jsonapi/customer?include=customer%2Faddress&site=default",
    "customer/address": {
      "href": "http://www.mysite.com/jsonapi/customer?id=466&related=address&site=default",
      "allow": ["GET", "POST"]
    },
    ...
  },
  "data": {
    "id": "466",
    "type": "customer",
    "links": {
      "self": {
        "href": "http://www.mysite.com/jsonapi/customer?id=466&site=default",
        "allow": ["DELETE", "GET", "PATCH"]
      }
    },
    "attributes": {
      ...
    },
    "relationships": {
      "customer/address": {
        "data": [
          { "id": "3", "type": "customer/address" },
          { "id": "4", "type": "customer/address" }
        ]
      }
    }
  },
  "included": [
    {
      "id": "3",
      "type": "customer/address",
      "attributes": {
        ...
      },
      "links": {
        "self": {
          "href": "http://www.mysite.com/jsonapi/customer?id=466&related=customer%2Faddress&relatedid=3&site=default",
          "allow": ["DELETE", "GET", "PATCH"]
        },
        "basket/address": {
          "href": "http://www.mysite.com/jsonapi/basket?id=default&related=address&relatedid=payment&site=default",
          "allow": ["POST"]
        }
      }
    },
    {
      "id": "4",
      "type": "customer/address",
      "attributes": {
        ...
      },
      "links": {
        "self": {
          "href": "http://www.mysite.com/jsonapi/customer?id=466&related=customer%2Faddress&relatedid=4&site=default",
          "allow": ["DELETE", "GET", "PATCH"]
        },
        "basket/address": {
          "href": "http://www.mysite.com/jsonapi/basket?id=default&related=address&relatedid=payment&site=default",
          "allow": ["POST"]
        }
      }
    }
  ]
}
aimeos commented 2 years ago

Thanks to the hint, it's fixed now for customer address and property entries too: https://github.com/aimeos/ai-client-jsonapi/commit/76815ba5e3626e90da3abbb910b45730246f7004