ObjectModified event for Dexterity types seems to be intercepted too early

I have an add-on product that I am developing for Plone 5. It subscribes to the ObjectModified event so that it can determine if the editor who made the change is in a particular group. If the editor is a substance editor by being in the group Substance Editors, then a second substancemodified date is updated along with the usual content modification date. I have attempted to determine the last editor by listening for ObjectModified and then checking the full history view of the content. After iterating over the action log, I have found that the ObjectModified event must happen before updating the full history. The last actor evaluates to the previous actor before the current modification and not the editor who is actively editing the page. Does anyone know how one could ensure that the ObjectModified handler is run after all other handlers, or is there a better way to extract the editor who made the actual modification?

Thanks in advance for any insight!

Hi Jonathan,

I'm not sure what it is what's off according to you?
The last person who modified, is the current user (self.request.AUTHENTICATED_USER or api.user.get_current()).
If you need the previous person, then that would the last entry in the action log - you already found that one.

groups = api.group.get_groups(user=api.user.get_current())
would give you a list of groups for this user, so you can check if 'Substance Editors' is in there.

Or you can introduce a specific permission for this action and use api.user.has_permission('permissioname') to check if you need to update substancemodified as well.
The group 'Substance Editors' would have that permission, other wouldn't.

Thanks so much for the info. I didn't realize that I could get the current user while handling the event. Does the event object pass the request through somehow?

Thanks a million, Roel. It would seem I was overthinking that one. I did not think I had access to a user context from the event handler, but just as you say, I do. I was trying to determine the last actor and assuming that since I am handling the event that the full history will have already populated with the last (current) edit. I am now assuming that the full history gets updated by another event handler that is handled subsequent to this one. Either way, it was as easy as using plone.api to get the current user context. My apologies for overthinking that one and asking such a base question. Thanks again for your insight!

Not a problem at all, always a pleasure to help!