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

Subscriber to prevent overriding values with outdated content #1110

Open
masipcat opened this issue Mar 8, 2021 · 2 comments
Open

Subscriber to prevent overriding values with outdated content #1110

masipcat opened this issue Mar 8, 2021 · 2 comments
Assignees
Labels
enhancement GIP Guillotina Improvement Proposal

Comments

@masipcat
Copy link
Contributor

masipcat commented Mar 8, 2021

The following code is something we use in conjunction with #1025 to prevent patching an object with outdated info:

from dateutil.parser import isoparse
from guillotina import configure
from guillotina.events import IBeforeObjectModifiedEvent
from guillotina.interfaces import IResource
from guillotina.response import HTTPForbidden
from guillotina.utils import get_current_request


@configure.subscriber(for_=(IResource, IBeforeObjectModifiedEvent), priority=1)
async def check_modifing_latest_version(obj, event):
    request = get_current_request()

    if last_mod_date := request.headers.get("last-mod-date"):
        last_mod_date = isoparse(last_mod_date)
        if last_mod_date != obj.modification_date:
            raise HTTPForbidden(
                content={
                    "error": f"Provided version {last_mod_date} is behind {obj.modification_date}"
                }
            )

@bloodbare @vangheem do we want to add this to guillotina in a contrib like the linked issue #1025? I'm asking because @aralroca would like to move our implementation to Guillotina React.

@masipcat masipcat added enhancement GIP Guillotina Improvement Proposal labels Mar 8, 2021
@masipcat masipcat self-assigned this Mar 8, 2021
@runyaga
Copy link
Member

runyaga commented Apr 15, 2021

would etag's work?

@masipcat
Copy link
Contributor Author

Ohh, I didn't know ETag could be used to avoid collisions! We need to add ETag support to Guillotina first but I like the idea of using the ETag header instead of a custom one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement GIP Guillotina Improvement Proposal
Projects
None yet
Development

No branches or pull requests

2 participants