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

Collection creation issue from batch requests #203

Closed
leplatrem opened this issue Apr 12, 2022 · 0 comments · Fixed by #204
Closed

Collection creation issue from batch requests #203

leplatrem opened this issue Apr 12, 2022 · 0 comments · Fixed by #204

Comments

@leplatrem
Copy link
Contributor

leplatrem commented Apr 12, 2022

Steps to reproduce

  • Collection a exists
  • A batch request is sent, in which we create a collection b and update the collection a
POST /batch
{
    "requests": [
        {
            "method": "PUT",
            "path": "/buckets/main-workspace/collections/b",
        },
        {
            "method": "PATCH",
            "path": "/buckets/main-workspace/collections/a",
            "body": {"data": {"foo": 42}},
        },
    ],
}

Expected result

  • The server creates the collection b
  • The server updates the colllection a

Actual result

  • The server responds 400 Invalid Request, Cannot set status to 'signed'

Explanations

  • When a collection is created, we receive a ResourceChanged event, and we use an event listener to sign it right away (here)

  • When we sign a collection, we update the source attributes to set its status to signed. In order to keep track of this change, we emit a ResourceChanged event. We call this a cascade event, since it's sent from an event listener.

  • When several events are sent for the same action and resource name, we merge them together. There will be one event, but with several impacted_objects.

  • In the batch request example above, when we process the collection b creation, and its initial signing, a ResourceChanged event is sent for the status switch to signed. This event gets merged with the ResourceChanged event emitted for the PATCH update of collection a.

  • The issuer of the event for the PATCH update is a normal user (author of the batch request). However, the one for the signed status event is the signer code itself (user id = plugin:signer)

  • When events get merged, we «loose» some information about the merged one, including its issuer.

  • The check that we have in place to make sure that no user can manually set a collection status to signed ignores update events that were issued by the signer code. But since the signer event was merged into the user event, the check code raises an invalid request Cannot set status to 'signed', assuming the status change was performed by a user and not by the signer code.

Possible solutions

  • Prevent event merging when their issuer differs
  • Prevent event merging of cascade events with upstream events
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant