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.
The following code is something we use in conjunction with #1025 to prevent patching an object with outdated info:
@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.